1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay do? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking an iterator structure (struct it)
126 Iteration over things to be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator.
128 Calls to get_next_display_element fill the iterator structure with
129 relevant information about the next thing to display. Calls to
130 set_iterator_to_next move the iterator to the next thing.
132 Besides this, an iterator also contains information about the
133 display environment in which glyphs for display elements are to be
134 produced. It has fields for the width and height of the display,
135 the information whether long lines are truncated or continued, a
136 current X and Y position, and lots of other stuff you can better
139 Glyphs in a desired matrix are normally constructed in a loop
140 calling get_next_display_element and then produce_glyphs. The call
141 to produce_glyphs will fill the iterator structure with pixel
142 information about the element being displayed and at the same time
143 produce glyphs for it. If the display element fits on the line
144 being displayed, set_iterator_to_next is called next, otherwise the
145 glyphs produced are discarded.
150 That just couldn't be all, could it? What about terminal types not
151 supporting operations on sub-windows of the screen? To update the
152 display on such a terminal, window-based glyph matrices are not
153 well suited. To be able to reuse part of the display (scrolling
154 lines up and down), we must instead have a view of the whole
155 screen. This is what `frame matrices' are for. They are a trick.
157 Frames on terminals like above have a glyph pool. Windows on such
158 a frame sub-allocate their glyph memory from their frame's glyph
159 pool. The frame itself is given its own glyph matrices. By
160 coincidence---or maybe something else---rows in window glyph
161 matrices are slices of corresponding rows in frame matrices. Thus
162 writing to window matrices implicitly updates a frame matrix which
163 provides us with the view of the whole screen that we originally
164 wanted to have without having to move many bytes around. To be
165 honest, there is a little bit more done, but not much more. If you
166 plan to extend that code, take a look at dispnew.c. The function
167 build_frame_matrix is a good starting point. */
173 #include "keyboard.h"
176 #include "termchar.h"
177 #include "dispextern.h"
179 #include "character.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
;
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
*));
739 static enum prop_handled handle_auto_composed_prop
P_ ((struct it
*));
741 /* Properties handled by iterators. */
743 static struct props it_props
[] =
745 {&Qauto_composed
, AUTO_COMPOSED_PROP_IDX
, handle_auto_composed_prop
},
746 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
747 /* Handle `face' before `display' because some sub-properties of
748 `display' need to know the face. */
749 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
750 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
751 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
752 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
756 /* Value is the position described by X. If X is a marker, value is
757 the marker_position of X. Otherwise, value is X. */
759 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
761 /* Enumeration returned by some move_it_.* functions internally. */
765 /* Not used. Undefined value. */
768 /* Move ended at the requested buffer position or ZV. */
769 MOVE_POS_MATCH_OR_ZV
,
771 /* Move ended at the requested X pixel position. */
774 /* Move within a line ended at the end of a line that must be
778 /* Move within a line ended at the end of a line that would
779 be displayed truncated. */
782 /* Move within a line ended at a line end. */
786 /* This counter is used to clear the face cache every once in a while
787 in redisplay_internal. It is incremented for each redisplay.
788 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
791 #define CLEAR_FACE_CACHE_COUNT 500
792 static int clear_face_cache_count
;
794 /* Similarly for the image cache. */
796 #ifdef HAVE_WINDOW_SYSTEM
797 #define CLEAR_IMAGE_CACHE_COUNT 101
798 static int clear_image_cache_count
;
801 /* Record the previous terminal frame we displayed. */
803 static struct frame
*previous_terminal_frame
;
805 /* Non-zero while redisplay_internal is in progress. */
809 /* Non-zero means don't free realized faces. Bound while freeing
810 realized faces is dangerous because glyph matrices might still
813 int inhibit_free_realized_faces
;
814 Lisp_Object Qinhibit_free_realized_faces
;
816 /* If a string, XTread_socket generates an event to display that string.
817 (The display is done in read_char.) */
819 Lisp_Object help_echo_string
;
820 Lisp_Object help_echo_window
;
821 Lisp_Object help_echo_object
;
824 /* Temporary variable for XTread_socket. */
826 Lisp_Object previous_help_echo_string
;
828 /* Null glyph slice */
830 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
833 /* Function prototypes. */
835 static void setup_for_ellipsis
P_ ((struct it
*, int));
836 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
837 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
838 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
839 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
840 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
841 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
844 static int invisible_text_between_p
P_ ((struct it
*, int, int));
847 static void pint2str
P_ ((char *, int, int));
848 static void pint2hrstr
P_ ((char *, int, int));
849 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
851 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
852 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
853 static void store_mode_line_noprop_char
P_ ((char));
854 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
855 static void x_consider_frame_title
P_ ((Lisp_Object
));
856 static void handle_stop
P_ ((struct it
*));
857 static int tool_bar_lines_needed
P_ ((struct frame
*));
858 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
859 static void ensure_echo_area_buffers
P_ ((void));
860 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
861 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
862 static int with_echo_area_buffer
P_ ((struct window
*, int,
863 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
864 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
865 static void clear_garbaged_frames
P_ ((void));
866 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
867 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
868 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
869 static int display_echo_area
P_ ((struct window
*));
870 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
871 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
872 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
873 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
874 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
876 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
877 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
878 static void insert_left_trunc_glyphs
P_ ((struct it
*));
879 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
881 static void extend_face_to_end_of_line
P_ ((struct it
*));
882 static int append_space_for_newline
P_ ((struct it
*, int));
883 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
884 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
885 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
886 static int trailing_whitespace_p
P_ ((int));
887 static int message_log_check_duplicate
P_ ((int, int, int, int));
888 static void push_it
P_ ((struct it
*));
889 static void pop_it
P_ ((struct it
*));
890 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
891 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
892 static void redisplay_internal
P_ ((int));
893 static int echo_area_display
P_ ((int));
894 static void redisplay_windows
P_ ((Lisp_Object
));
895 static void redisplay_window
P_ ((Lisp_Object
, int));
896 static Lisp_Object
redisplay_window_error ();
897 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
898 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
899 static void update_menu_bar
P_ ((struct frame
*, int));
900 static int try_window_reusing_current_matrix
P_ ((struct window
*));
901 static int try_window_id
P_ ((struct window
*));
902 static int display_line
P_ ((struct it
*));
903 static int display_mode_lines
P_ ((struct window
*));
904 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
905 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
906 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
907 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
908 static void display_menu_bar
P_ ((struct window
*));
909 static int display_count_lines
P_ ((int, int, int, int, int *));
910 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
911 int, int, struct it
*, int, int, int, int));
912 static void compute_line_metrics
P_ ((struct it
*));
913 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
914 static int get_overlay_strings
P_ ((struct it
*, int));
915 static void next_overlay_string
P_ ((struct it
*));
916 static void reseat
P_ ((struct it
*, struct text_pos
, int));
917 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
918 static void back_to_previous_visible_line_start
P_ ((struct it
*));
919 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
920 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
921 static int next_element_from_ellipsis
P_ ((struct it
*));
922 static int next_element_from_display_vector
P_ ((struct it
*));
923 static int next_element_from_string
P_ ((struct it
*));
924 static int next_element_from_c_string
P_ ((struct it
*));
925 static int next_element_from_buffer
P_ ((struct it
*));
926 static int next_element_from_composition
P_ ((struct it
*));
927 static int next_element_from_image
P_ ((struct it
*));
928 static int next_element_from_stretch
P_ ((struct it
*));
929 static void load_overlay_strings
P_ ((struct it
*, int));
930 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
931 struct display_pos
*));
932 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
933 Lisp_Object
, int, int, int, int));
934 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
936 void move_it_vertically_backward
P_ ((struct it
*, int));
937 static void init_to_row_start
P_ ((struct it
*, struct window
*,
938 struct glyph_row
*));
939 static int init_to_row_end
P_ ((struct it
*, struct window
*,
940 struct glyph_row
*));
941 static void back_to_previous_line_start
P_ ((struct it
*));
942 static int forward_to_next_line_start
P_ ((struct it
*, int *));
943 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
945 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
946 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
947 static int number_of_chars
P_ ((unsigned char *, int));
948 static void compute_stop_pos
P_ ((struct it
*));
949 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
951 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
952 static int next_overlay_change
P_ ((int));
953 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
954 Lisp_Object
, struct text_pos
*,
956 static int underlying_face_id
P_ ((struct it
*));
957 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
960 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
961 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
963 #ifdef HAVE_WINDOW_SYSTEM
965 static void update_tool_bar
P_ ((struct frame
*, int));
966 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
967 static int redisplay_tool_bar
P_ ((struct frame
*));
968 static void display_tool_bar_line
P_ ((struct it
*));
969 static void notice_overwritten_cursor
P_ ((struct window
*,
971 int, int, int, int));
975 #endif /* HAVE_WINDOW_SYSTEM */
978 /***********************************************************************
979 Window display dimensions
980 ***********************************************************************/
982 /* Return the bottom boundary y-position for text lines in window W.
983 This is the first y position at which a line cannot start.
984 It is relative to the top of the window.
986 This is the height of W minus the height of a mode line, if any. */
989 window_text_bottom_y (w
)
992 int height
= WINDOW_TOTAL_HEIGHT (w
);
994 if (WINDOW_WANTS_MODELINE_P (w
))
995 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
999 /* Return the pixel width of display area AREA of window W. AREA < 0
1000 means return the total width of W, not including fringes to
1001 the left and right of the window. */
1004 window_box_width (w
, area
)
1008 int cols
= XFASTINT (w
->total_cols
);
1011 if (!w
->pseudo_window_p
)
1013 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1015 if (area
== TEXT_AREA
)
1017 if (INTEGERP (w
->left_margin_cols
))
1018 cols
-= XFASTINT (w
->left_margin_cols
);
1019 if (INTEGERP (w
->right_margin_cols
))
1020 cols
-= XFASTINT (w
->right_margin_cols
);
1021 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1023 else if (area
== LEFT_MARGIN_AREA
)
1025 cols
= (INTEGERP (w
->left_margin_cols
)
1026 ? XFASTINT (w
->left_margin_cols
) : 0);
1029 else if (area
== RIGHT_MARGIN_AREA
)
1031 cols
= (INTEGERP (w
->right_margin_cols
)
1032 ? XFASTINT (w
->right_margin_cols
) : 0);
1037 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1041 /* Return the pixel height of the display area of window W, not
1042 including mode lines of W, if any. */
1045 window_box_height (w
)
1048 struct frame
*f
= XFRAME (w
->frame
);
1049 int height
= WINDOW_TOTAL_HEIGHT (w
);
1051 xassert (height
>= 0);
1053 /* Note: the code below that determines the mode-line/header-line
1054 height is essentially the same as that contained in the macro
1055 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1056 the appropriate glyph row has its `mode_line_p' flag set,
1057 and if it doesn't, uses estimate_mode_line_height instead. */
1059 if (WINDOW_WANTS_MODELINE_P (w
))
1061 struct glyph_row
*ml_row
1062 = (w
->current_matrix
&& w
->current_matrix
->rows
1063 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1065 if (ml_row
&& ml_row
->mode_line_p
)
1066 height
-= ml_row
->height
;
1068 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1071 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1073 struct glyph_row
*hl_row
1074 = (w
->current_matrix
&& w
->current_matrix
->rows
1075 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1077 if (hl_row
&& hl_row
->mode_line_p
)
1078 height
-= hl_row
->height
;
1080 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1083 /* With a very small font and a mode-line that's taller than
1084 default, we might end up with a negative height. */
1085 return max (0, height
);
1088 /* Return the window-relative coordinate of the left edge of display
1089 area AREA of window W. AREA < 0 means return the left edge of the
1090 whole window, to the right of the left fringe of W. */
1093 window_box_left_offset (w
, area
)
1099 if (w
->pseudo_window_p
)
1102 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1104 if (area
== TEXT_AREA
)
1105 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1106 + window_box_width (w
, LEFT_MARGIN_AREA
));
1107 else if (area
== RIGHT_MARGIN_AREA
)
1108 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1109 + window_box_width (w
, LEFT_MARGIN_AREA
)
1110 + window_box_width (w
, TEXT_AREA
)
1111 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1113 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1114 else if (area
== LEFT_MARGIN_AREA
1115 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1116 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1122 /* Return the window-relative coordinate of the right edge of display
1123 area AREA of window W. AREA < 0 means return the left edge of the
1124 whole window, to the left of the right fringe of W. */
1127 window_box_right_offset (w
, area
)
1131 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1134 /* Return the frame-relative coordinate of the left edge of display
1135 area AREA of window W. AREA < 0 means return the left edge of the
1136 whole window, to the right of the left fringe of W. */
1139 window_box_left (w
, area
)
1143 struct frame
*f
= XFRAME (w
->frame
);
1146 if (w
->pseudo_window_p
)
1147 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1149 x
= (WINDOW_LEFT_EDGE_X (w
)
1150 + window_box_left_offset (w
, area
));
1156 /* Return the frame-relative coordinate of the right edge of display
1157 area AREA of window W. AREA < 0 means return the left edge of the
1158 whole window, to the left of the right fringe of W. */
1161 window_box_right (w
, area
)
1165 return window_box_left (w
, area
) + window_box_width (w
, area
);
1168 /* Get the bounding box of the display area AREA of window W, without
1169 mode lines, in frame-relative coordinates. AREA < 0 means the
1170 whole window, not including the left and right fringes of
1171 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1172 coordinates of the upper-left corner of the box. Return in
1173 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1176 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1179 int *box_x
, *box_y
, *box_width
, *box_height
;
1182 *box_width
= window_box_width (w
, area
);
1184 *box_height
= window_box_height (w
);
1186 *box_x
= window_box_left (w
, area
);
1189 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1190 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1191 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1196 /* Get the bounding box of the display area AREA of window W, without
1197 mode lines. AREA < 0 means the whole window, not including the
1198 left and right fringe of the window. Return in *TOP_LEFT_X
1199 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1200 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1201 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1205 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1206 bottom_right_x
, bottom_right_y
)
1209 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1211 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1213 *bottom_right_x
+= *top_left_x
;
1214 *bottom_right_y
+= *top_left_y
;
1219 /***********************************************************************
1221 ***********************************************************************/
1223 /* Return the bottom y-position of the line the iterator IT is in.
1224 This can modify IT's settings. */
1230 int line_height
= it
->max_ascent
+ it
->max_descent
;
1231 int line_top_y
= it
->current_y
;
1233 if (line_height
== 0)
1236 line_height
= last_height
;
1237 else if (IT_CHARPOS (*it
) < ZV
)
1239 move_it_by_lines (it
, 1, 1);
1240 line_height
= (it
->max_ascent
|| it
->max_descent
1241 ? it
->max_ascent
+ it
->max_descent
1246 struct glyph_row
*row
= it
->glyph_row
;
1248 /* Use the default character height. */
1249 it
->glyph_row
= NULL
;
1250 it
->what
= IT_CHARACTER
;
1253 PRODUCE_GLYPHS (it
);
1254 line_height
= it
->ascent
+ it
->descent
;
1255 it
->glyph_row
= row
;
1259 return line_top_y
+ line_height
;
1263 /* Return 1 if position CHARPOS is visible in window W.
1264 If visible, set *X and *Y to pixel coordinates of top left corner.
1265 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1266 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1267 and header-lines heights. */
1270 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, exact_mode_line_heights_p
)
1272 int charpos
, *x
, *y
, *rtop
, *rbot
, exact_mode_line_heights_p
;
1275 struct text_pos top
;
1277 struct buffer
*old_buffer
= NULL
;
1282 if (XBUFFER (w
->buffer
) != current_buffer
)
1284 old_buffer
= current_buffer
;
1285 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1288 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1290 /* Compute exact mode line heights, if requested. */
1291 if (exact_mode_line_heights_p
)
1293 if (WINDOW_WANTS_MODELINE_P (w
))
1294 current_mode_line_height
1295 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1296 current_buffer
->mode_line_format
);
1298 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1299 current_header_line_height
1300 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1301 current_buffer
->header_line_format
);
1304 start_display (&it
, w
, top
);
1305 move_it_to (&it
, charpos
, -1, it
.last_visible_y
, -1,
1306 MOVE_TO_POS
| MOVE_TO_Y
);
1308 /* Note that we may overshoot because of invisible text. */
1309 if (IT_CHARPOS (it
) >= charpos
)
1311 int top_x
= it
.current_x
;
1312 int top_y
= it
.current_y
;
1313 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1314 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1316 if (top_y
< window_top_y
)
1317 visible_p
= bottom_y
> window_top_y
;
1318 else if (top_y
< it
.last_visible_y
)
1323 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1324 *rtop
= max (0, window_top_y
- top_y
);
1325 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1333 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1334 move_it_by_lines (&it
, 1, 0);
1335 if (charpos
< IT_CHARPOS (it
))
1338 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1340 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1341 *rtop
= max (0, -it2
.current_y
);
1342 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1343 - it
.last_visible_y
));
1348 set_buffer_internal_1 (old_buffer
);
1350 current_header_line_height
= current_mode_line_height
= -1;
1356 /* Return the next character from STR which is MAXLEN bytes long.
1357 Return in *LEN the length of the character. This is like
1358 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1359 we find one, we return a `?', but with the length of the invalid
1363 string_char_and_length (str
, maxlen
, len
)
1364 const unsigned char *str
;
1369 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1370 if (!CHAR_VALID_P (c
, 1))
1371 /* We may not change the length here because other places in Emacs
1372 don't use this function, i.e. they silently accept invalid
1381 /* Given a position POS containing a valid character and byte position
1382 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1384 static struct text_pos
1385 string_pos_nchars_ahead (pos
, string
, nchars
)
1386 struct text_pos pos
;
1390 xassert (STRINGP (string
) && nchars
>= 0);
1392 if (STRING_MULTIBYTE (string
))
1394 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1395 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1400 string_char_and_length (p
, rest
, &len
);
1401 p
+= len
, rest
-= len
;
1402 xassert (rest
>= 0);
1404 BYTEPOS (pos
) += len
;
1408 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1414 /* Value is the text position, i.e. character and byte position,
1415 for character position CHARPOS in STRING. */
1417 static INLINE
struct text_pos
1418 string_pos (charpos
, string
)
1422 struct text_pos pos
;
1423 xassert (STRINGP (string
));
1424 xassert (charpos
>= 0);
1425 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1430 /* Value is a text position, i.e. character and byte position, for
1431 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1432 means recognize multibyte characters. */
1434 static struct text_pos
1435 c_string_pos (charpos
, s
, multibyte_p
)
1440 struct text_pos pos
;
1442 xassert (s
!= NULL
);
1443 xassert (charpos
>= 0);
1447 int rest
= strlen (s
), len
;
1449 SET_TEXT_POS (pos
, 0, 0);
1452 string_char_and_length (s
, rest
, &len
);
1453 s
+= len
, rest
-= len
;
1454 xassert (rest
>= 0);
1456 BYTEPOS (pos
) += len
;
1460 SET_TEXT_POS (pos
, charpos
, charpos
);
1466 /* Value is the number of characters in C string S. MULTIBYTE_P
1467 non-zero means recognize multibyte characters. */
1470 number_of_chars (s
, multibyte_p
)
1478 int rest
= strlen (s
), len
;
1479 unsigned char *p
= (unsigned char *) s
;
1481 for (nchars
= 0; rest
> 0; ++nchars
)
1483 string_char_and_length (p
, rest
, &len
);
1484 rest
-= len
, p
+= len
;
1488 nchars
= strlen (s
);
1494 /* Compute byte position NEWPOS->bytepos corresponding to
1495 NEWPOS->charpos. POS is a known position in string STRING.
1496 NEWPOS->charpos must be >= POS.charpos. */
1499 compute_string_pos (newpos
, pos
, string
)
1500 struct text_pos
*newpos
, pos
;
1503 xassert (STRINGP (string
));
1504 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1506 if (STRING_MULTIBYTE (string
))
1507 *newpos
= string_pos_nchars_ahead (pos
, string
,
1508 CHARPOS (*newpos
) - CHARPOS (pos
));
1510 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1514 Return an estimation of the pixel height of mode or top lines on
1515 frame F. FACE_ID specifies what line's height to estimate. */
1518 estimate_mode_line_height (f
, face_id
)
1520 enum face_id face_id
;
1522 #ifdef HAVE_WINDOW_SYSTEM
1523 if (FRAME_WINDOW_P (f
))
1525 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1527 /* This function is called so early when Emacs starts that the face
1528 cache and mode line face are not yet initialized. */
1529 if (FRAME_FACE_CACHE (f
))
1531 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1535 height
= FONT_HEIGHT (face
->font
);
1536 if (face
->box_line_width
> 0)
1537 height
+= 2 * face
->box_line_width
;
1548 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1549 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1550 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1551 not force the value into range. */
1554 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1556 register int pix_x
, pix_y
;
1558 NativeRectangle
*bounds
;
1562 #ifdef HAVE_WINDOW_SYSTEM
1563 if (FRAME_WINDOW_P (f
))
1565 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1566 even for negative values. */
1568 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1570 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1572 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1573 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1576 STORE_NATIVE_RECT (*bounds
,
1577 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1578 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1579 FRAME_COLUMN_WIDTH (f
) - 1,
1580 FRAME_LINE_HEIGHT (f
) - 1);
1586 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1587 pix_x
= FRAME_TOTAL_COLS (f
);
1591 else if (pix_y
> FRAME_LINES (f
))
1592 pix_y
= FRAME_LINES (f
);
1602 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1603 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1604 can't tell the positions because W's display is not up to date,
1608 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1611 int *frame_x
, *frame_y
;
1613 #ifdef HAVE_WINDOW_SYSTEM
1614 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1618 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1619 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1621 if (display_completed
)
1623 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1624 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1625 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1631 hpos
+= glyph
->pixel_width
;
1635 /* If first glyph is partially visible, its first visible position is still 0. */
1647 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1648 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1659 #ifdef HAVE_WINDOW_SYSTEM
1661 /* Find the glyph under window-relative coordinates X/Y in window W.
1662 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1663 strings. Return in *HPOS and *VPOS the row and column number of
1664 the glyph found. Return in *AREA the glyph area containing X.
1665 Value is a pointer to the glyph found or null if X/Y is not on
1666 text, or we can't tell because W's current matrix is not up to
1669 static struct glyph
*
1670 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1673 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1675 struct glyph
*glyph
, *end
;
1676 struct glyph_row
*row
= NULL
;
1679 /* Find row containing Y. Give up if some row is not enabled. */
1680 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1682 row
= MATRIX_ROW (w
->current_matrix
, i
);
1683 if (!row
->enabled_p
)
1685 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1692 /* Give up if Y is not in the window. */
1693 if (i
== w
->current_matrix
->nrows
)
1696 /* Get the glyph area containing X. */
1697 if (w
->pseudo_window_p
)
1704 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1706 *area
= LEFT_MARGIN_AREA
;
1707 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1709 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1712 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1716 *area
= RIGHT_MARGIN_AREA
;
1717 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1721 /* Find glyph containing X. */
1722 glyph
= row
->glyphs
[*area
];
1723 end
= glyph
+ row
->used
[*area
];
1725 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1727 x
-= glyph
->pixel_width
;
1737 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1740 *hpos
= glyph
- row
->glyphs
[*area
];
1746 Convert frame-relative x/y to coordinates relative to window W.
1747 Takes pseudo-windows into account. */
1750 frame_to_window_pixel_xy (w
, x
, y
)
1754 if (w
->pseudo_window_p
)
1756 /* A pseudo-window is always full-width, and starts at the
1757 left edge of the frame, plus a frame border. */
1758 struct frame
*f
= XFRAME (w
->frame
);
1759 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1760 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1764 *x
-= WINDOW_LEFT_EDGE_X (w
);
1765 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1770 Return in *R the clipping rectangle for glyph string S. */
1773 get_glyph_string_clip_rect (s
, nr
)
1774 struct glyph_string
*s
;
1775 NativeRectangle
*nr
;
1779 if (s
->row
->full_width_p
)
1781 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1782 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1783 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1785 /* Unless displaying a mode or menu bar line, which are always
1786 fully visible, clip to the visible part of the row. */
1787 if (s
->w
->pseudo_window_p
)
1788 r
.height
= s
->row
->visible_height
;
1790 r
.height
= s
->height
;
1794 /* This is a text line that may be partially visible. */
1795 r
.x
= window_box_left (s
->w
, s
->area
);
1796 r
.width
= window_box_width (s
->w
, s
->area
);
1797 r
.height
= s
->row
->visible_height
;
1801 if (r
.x
< s
->clip_head
->x
)
1803 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1804 r
.width
-= s
->clip_head
->x
- r
.x
;
1807 r
.x
= s
->clip_head
->x
;
1810 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1812 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1813 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1818 /* If S draws overlapping rows, it's sufficient to use the top and
1819 bottom of the window for clipping because this glyph string
1820 intentionally draws over other lines. */
1821 if (s
->for_overlaps_p
)
1823 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1824 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1828 /* Don't use S->y for clipping because it doesn't take partially
1829 visible lines into account. For example, it can be negative for
1830 partially visible lines at the top of a window. */
1831 if (!s
->row
->full_width_p
1832 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1833 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1835 r
.y
= max (0, s
->row
->y
);
1837 /* If drawing a tool-bar window, draw it over the internal border
1838 at the top of the window. */
1839 if (WINDOWP (s
->f
->tool_bar_window
)
1840 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1841 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1844 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1846 /* If drawing the cursor, don't let glyph draw outside its
1847 advertised boundaries. Cleartype does this under some circumstances. */
1848 if (s
->hl
== DRAW_CURSOR
)
1850 struct glyph
*glyph
= s
->first_glyph
;
1855 r
.width
-= s
->x
- r
.x
;
1858 r
.width
= min (r
.width
, glyph
->pixel_width
);
1860 /* If r.y is below window bottom, ensure that we still see a cursor. */
1861 height
= min (glyph
->ascent
+ glyph
->descent
,
1862 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1863 max_y
= window_text_bottom_y (s
->w
) - height
;
1864 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1865 if (s
->ybase
- glyph
->ascent
> max_y
)
1872 /* Don't draw cursor glyph taller than our actual glyph. */
1873 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1874 if (height
< r
.height
)
1876 max_y
= r
.y
+ r
.height
;
1877 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1878 r
.height
= min (max_y
- r
.y
, height
);
1883 #ifdef CONVERT_FROM_XRECT
1884 CONVERT_FROM_XRECT (r
, *nr
);
1892 Return the position and height of the phys cursor in window W.
1893 Set w->phys_cursor_width to width of phys cursor.
1897 get_phys_cursor_geometry (w
, row
, glyph
, heightp
)
1899 struct glyph_row
*row
;
1900 struct glyph
*glyph
;
1903 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1904 int y
, wd
, h
, h0
, y0
;
1906 /* Compute the width of the rectangle to draw. If on a stretch
1907 glyph, and `x-stretch-block-cursor' is nil, don't draw a
1908 rectangle as wide as the glyph, but use a canonical character
1910 wd
= glyph
->pixel_width
- 1;
1914 if (glyph
->type
== STRETCH_GLYPH
1915 && !x_stretch_cursor_p
)
1916 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
1917 w
->phys_cursor_width
= wd
;
1919 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
1921 /* If y is below window bottom, ensure that we still see a cursor. */
1922 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
1924 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
1925 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
1927 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
1930 h
= max (h
- (y0
- y
) + 1, h0
);
1935 y0
= window_text_bottom_y (w
) - h0
;
1944 return WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
1948 #endif /* HAVE_WINDOW_SYSTEM */
1951 /***********************************************************************
1952 Lisp form evaluation
1953 ***********************************************************************/
1955 /* Error handler for safe_eval and safe_call. */
1958 safe_eval_handler (arg
)
1961 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1966 /* Evaluate SEXPR and return the result, or nil if something went
1967 wrong. Prevent redisplay during the evaluation. */
1975 if (inhibit_eval_during_redisplay
)
1979 int count
= SPECPDL_INDEX ();
1980 struct gcpro gcpro1
;
1983 specbind (Qinhibit_redisplay
, Qt
);
1984 /* Use Qt to ensure debugger does not run,
1985 so there is no possibility of wanting to redisplay. */
1986 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1989 val
= unbind_to (count
, val
);
1996 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1997 Return the result, or nil if something went wrong. Prevent
1998 redisplay during the evaluation. */
2001 safe_call (nargs
, args
)
2007 if (inhibit_eval_during_redisplay
)
2011 int count
= SPECPDL_INDEX ();
2012 struct gcpro gcpro1
;
2015 gcpro1
.nvars
= nargs
;
2016 specbind (Qinhibit_redisplay
, Qt
);
2017 /* Use Qt to ensure debugger does not run,
2018 so there is no possibility of wanting to redisplay. */
2019 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2022 val
= unbind_to (count
, val
);
2029 /* Call function FN with one argument ARG.
2030 Return the result, or nil if something went wrong. */
2033 safe_call1 (fn
, arg
)
2034 Lisp_Object fn
, arg
;
2036 Lisp_Object args
[2];
2039 return safe_call (2, args
);
2044 /***********************************************************************
2046 ***********************************************************************/
2050 /* Define CHECK_IT to perform sanity checks on iterators.
2051 This is for debugging. It is too slow to do unconditionally. */
2057 if (it
->method
== GET_FROM_STRING
)
2059 xassert (STRINGP (it
->string
));
2060 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2064 xassert (IT_STRING_CHARPOS (*it
) < 0);
2065 if (it
->method
== GET_FROM_BUFFER
)
2067 /* Check that character and byte positions agree. */
2068 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2073 xassert (it
->current
.dpvec_index
>= 0);
2075 xassert (it
->current
.dpvec_index
< 0);
2078 #define CHECK_IT(IT) check_it ((IT))
2082 #define CHECK_IT(IT) (void) 0
2089 /* Check that the window end of window W is what we expect it
2090 to be---the last row in the current matrix displaying text. */
2093 check_window_end (w
)
2096 if (!MINI_WINDOW_P (w
)
2097 && !NILP (w
->window_end_valid
))
2099 struct glyph_row
*row
;
2100 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2101 XFASTINT (w
->window_end_vpos
)),
2103 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2104 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2108 #define CHECK_WINDOW_END(W) check_window_end ((W))
2110 #else /* not GLYPH_DEBUG */
2112 #define CHECK_WINDOW_END(W) (void) 0
2114 #endif /* not GLYPH_DEBUG */
2118 /***********************************************************************
2119 Iterator initialization
2120 ***********************************************************************/
2122 /* Initialize IT for displaying current_buffer in window W, starting
2123 at character position CHARPOS. CHARPOS < 0 means that no buffer
2124 position is specified which is useful when the iterator is assigned
2125 a position later. BYTEPOS is the byte position corresponding to
2126 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2128 If ROW is not null, calls to produce_glyphs with IT as parameter
2129 will produce glyphs in that row.
2131 BASE_FACE_ID is the id of a base face to use. It must be one of
2132 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2133 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2134 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2136 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2137 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2138 will be initialized to use the corresponding mode line glyph row of
2139 the desired matrix of W. */
2142 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2145 int charpos
, bytepos
;
2146 struct glyph_row
*row
;
2147 enum face_id base_face_id
;
2149 int highlight_region_p
;
2151 /* Some precondition checks. */
2152 xassert (w
!= NULL
&& it
!= NULL
);
2153 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2156 /* If face attributes have been changed since the last redisplay,
2157 free realized faces now because they depend on face definitions
2158 that might have changed. Don't free faces while there might be
2159 desired matrices pending which reference these faces. */
2160 if (face_change_count
&& !inhibit_free_realized_faces
)
2162 face_change_count
= 0;
2163 free_all_realized_faces (Qnil
);
2166 /* Use one of the mode line rows of W's desired matrix if
2170 if (base_face_id
== MODE_LINE_FACE_ID
2171 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2172 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2173 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2174 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2178 bzero (it
, sizeof *it
);
2179 it
->current
.overlay_string_index
= -1;
2180 it
->current
.dpvec_index
= -1;
2181 it
->base_face_id
= base_face_id
;
2183 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2185 /* The window in which we iterate over current_buffer: */
2186 XSETWINDOW (it
->window
, w
);
2188 it
->f
= XFRAME (w
->frame
);
2190 /* Extra space between lines (on window systems only). */
2191 if (base_face_id
== DEFAULT_FACE_ID
2192 && FRAME_WINDOW_P (it
->f
))
2194 if (NATNUMP (current_buffer
->extra_line_spacing
))
2195 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2196 else if (FLOATP (current_buffer
->extra_line_spacing
))
2197 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2198 * FRAME_LINE_HEIGHT (it
->f
));
2199 else if (it
->f
->extra_line_spacing
> 0)
2200 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2201 it
->max_extra_line_spacing
= 0;
2204 /* If realized faces have been removed, e.g. because of face
2205 attribute changes of named faces, recompute them. When running
2206 in batch mode, the face cache of Vterminal_frame is null. If
2207 we happen to get called, make a dummy face cache. */
2208 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2209 init_frame_faces (it
->f
);
2210 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2211 recompute_basic_faces (it
->f
);
2213 /* Current value of the `slice', `space-width', and 'height' properties. */
2214 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2215 it
->space_width
= Qnil
;
2216 it
->font_height
= Qnil
;
2217 it
->override_ascent
= -1;
2219 /* Are control characters displayed as `^C'? */
2220 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2222 /* -1 means everything between a CR and the following line end
2223 is invisible. >0 means lines indented more than this value are
2225 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2226 ? XFASTINT (current_buffer
->selective_display
)
2227 : (!NILP (current_buffer
->selective_display
)
2229 it
->selective_display_ellipsis_p
2230 = !NILP (current_buffer
->selective_display_ellipses
);
2232 /* Display table to use. */
2233 it
->dp
= window_display_table (w
);
2235 /* Are multibyte characters enabled in current_buffer? */
2236 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2238 /* Non-zero if we should highlight the region. */
2240 = (!NILP (Vtransient_mark_mode
)
2241 && !NILP (current_buffer
->mark_active
)
2242 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2244 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2245 start and end of a visible region in window IT->w. Set both to
2246 -1 to indicate no region. */
2247 if (highlight_region_p
2248 /* Maybe highlight only in selected window. */
2249 && (/* Either show region everywhere. */
2250 highlight_nonselected_windows
2251 /* Or show region in the selected window. */
2252 || w
== XWINDOW (selected_window
)
2253 /* Or show the region if we are in the mini-buffer and W is
2254 the window the mini-buffer refers to. */
2255 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2256 && WINDOWP (minibuf_selected_window
)
2257 && w
== XWINDOW (minibuf_selected_window
))))
2259 int charpos
= marker_position (current_buffer
->mark
);
2260 it
->region_beg_charpos
= min (PT
, charpos
);
2261 it
->region_end_charpos
= max (PT
, charpos
);
2264 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2266 /* Get the position at which the redisplay_end_trigger hook should
2267 be run, if it is to be run at all. */
2268 if (MARKERP (w
->redisplay_end_trigger
)
2269 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2270 it
->redisplay_end_trigger_charpos
2271 = marker_position (w
->redisplay_end_trigger
);
2272 else if (INTEGERP (w
->redisplay_end_trigger
))
2273 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2275 /* Correct bogus values of tab_width. */
2276 it
->tab_width
= XINT (current_buffer
->tab_width
);
2277 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2280 /* Are lines in the display truncated? */
2281 it
->truncate_lines_p
2282 = (base_face_id
!= DEFAULT_FACE_ID
2283 || XINT (it
->w
->hscroll
)
2284 || (truncate_partial_width_windows
2285 && !WINDOW_FULL_WIDTH_P (it
->w
))
2286 || !NILP (current_buffer
->truncate_lines
));
2288 /* Get dimensions of truncation and continuation glyphs. These are
2289 displayed as fringe bitmaps under X, so we don't need them for such
2291 if (!FRAME_WINDOW_P (it
->f
))
2293 if (it
->truncate_lines_p
)
2295 /* We will need the truncation glyph. */
2296 xassert (it
->glyph_row
== NULL
);
2297 produce_special_glyphs (it
, IT_TRUNCATION
);
2298 it
->truncation_pixel_width
= it
->pixel_width
;
2302 /* We will need the continuation glyph. */
2303 xassert (it
->glyph_row
== NULL
);
2304 produce_special_glyphs (it
, IT_CONTINUATION
);
2305 it
->continuation_pixel_width
= it
->pixel_width
;
2308 /* Reset these values to zero because the produce_special_glyphs
2309 above has changed them. */
2310 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2311 it
->phys_ascent
= it
->phys_descent
= 0;
2314 /* Set this after getting the dimensions of truncation and
2315 continuation glyphs, so that we don't produce glyphs when calling
2316 produce_special_glyphs, above. */
2317 it
->glyph_row
= row
;
2318 it
->area
= TEXT_AREA
;
2320 /* Get the dimensions of the display area. The display area
2321 consists of the visible window area plus a horizontally scrolled
2322 part to the left of the window. All x-values are relative to the
2323 start of this total display area. */
2324 if (base_face_id
!= DEFAULT_FACE_ID
)
2326 /* Mode lines, menu bar in terminal frames. */
2327 it
->first_visible_x
= 0;
2328 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2333 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2334 it
->last_visible_x
= (it
->first_visible_x
2335 + window_box_width (w
, TEXT_AREA
));
2337 /* If we truncate lines, leave room for the truncator glyph(s) at
2338 the right margin. Otherwise, leave room for the continuation
2339 glyph(s). Truncation and continuation glyphs are not inserted
2340 for window-based redisplay. */
2341 if (!FRAME_WINDOW_P (it
->f
))
2343 if (it
->truncate_lines_p
)
2344 it
->last_visible_x
-= it
->truncation_pixel_width
;
2346 it
->last_visible_x
-= it
->continuation_pixel_width
;
2349 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2350 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2353 /* Leave room for a border glyph. */
2354 if (!FRAME_WINDOW_P (it
->f
)
2355 && !WINDOW_RIGHTMOST_P (it
->w
))
2356 it
->last_visible_x
-= 1;
2358 it
->last_visible_y
= window_text_bottom_y (w
);
2360 /* For mode lines and alike, arrange for the first glyph having a
2361 left box line if the face specifies a box. */
2362 if (base_face_id
!= DEFAULT_FACE_ID
)
2366 it
->face_id
= base_face_id
;
2368 /* If we have a boxed mode line, make the first character appear
2369 with a left box line. */
2370 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2371 if (face
->box
!= FACE_NO_BOX
)
2372 it
->start_of_box_run_p
= 1;
2375 /* If a buffer position was specified, set the iterator there,
2376 getting overlays and face properties from that position. */
2377 if (charpos
>= BUF_BEG (current_buffer
))
2379 it
->end_charpos
= ZV
;
2381 IT_CHARPOS (*it
) = charpos
;
2383 /* Compute byte position if not specified. */
2384 if (bytepos
< charpos
)
2385 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2387 IT_BYTEPOS (*it
) = bytepos
;
2389 it
->start
= it
->current
;
2391 /* Compute faces etc. */
2392 reseat (it
, it
->current
.pos
, 1);
2399 /* Initialize IT for the display of window W with window start POS. */
2402 start_display (it
, w
, pos
)
2405 struct text_pos pos
;
2407 struct glyph_row
*row
;
2408 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2410 row
= w
->desired_matrix
->rows
+ first_vpos
;
2411 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2412 it
->first_vpos
= first_vpos
;
2414 if (!it
->truncate_lines_p
)
2416 int start_at_line_beg_p
;
2417 int first_y
= it
->current_y
;
2419 /* If window start is not at a line start, skip forward to POS to
2420 get the correct continuation lines width. */
2421 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2422 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2423 if (!start_at_line_beg_p
)
2427 reseat_at_previous_visible_line_start (it
);
2428 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2430 new_x
= it
->current_x
+ it
->pixel_width
;
2432 /* If lines are continued, this line may end in the middle
2433 of a multi-glyph character (e.g. a control character
2434 displayed as \003, or in the middle of an overlay
2435 string). In this case move_it_to above will not have
2436 taken us to the start of the continuation line but to the
2437 end of the continued line. */
2438 if (it
->current_x
> 0
2439 && !it
->truncate_lines_p
/* Lines are continued. */
2440 && (/* And glyph doesn't fit on the line. */
2441 new_x
> it
->last_visible_x
2442 /* Or it fits exactly and we're on a window
2444 || (new_x
== it
->last_visible_x
2445 && FRAME_WINDOW_P (it
->f
))))
2447 if (it
->current
.dpvec_index
>= 0
2448 || it
->current
.overlay_string_index
>= 0)
2450 set_iterator_to_next (it
, 1);
2451 move_it_in_display_line_to (it
, -1, -1, 0);
2454 it
->continuation_lines_width
+= it
->current_x
;
2457 /* We're starting a new display line, not affected by the
2458 height of the continued line, so clear the appropriate
2459 fields in the iterator structure. */
2460 it
->max_ascent
= it
->max_descent
= 0;
2461 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2463 it
->current_y
= first_y
;
2465 it
->current_x
= it
->hpos
= 0;
2469 #if 0 /* Don't assert the following because start_display is sometimes
2470 called intentionally with a window start that is not at a
2471 line start. Please leave this code in as a comment. */
2473 /* Window start should be on a line start, now. */
2474 xassert (it
->continuation_lines_width
2475 || IT_CHARPOS (it
) == BEGV
2476 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2481 /* Return 1 if POS is a position in ellipses displayed for invisible
2482 text. W is the window we display, for text property lookup. */
2485 in_ellipses_for_invisible_text_p (pos
, w
)
2486 struct display_pos
*pos
;
2489 Lisp_Object prop
, window
;
2491 int charpos
= CHARPOS (pos
->pos
);
2493 /* If POS specifies a position in a display vector, this might
2494 be for an ellipsis displayed for invisible text. We won't
2495 get the iterator set up for delivering that ellipsis unless
2496 we make sure that it gets aware of the invisible text. */
2497 if (pos
->dpvec_index
>= 0
2498 && pos
->overlay_string_index
< 0
2499 && CHARPOS (pos
->string_pos
) < 0
2501 && (XSETWINDOW (window
, w
),
2502 prop
= Fget_char_property (make_number (charpos
),
2503 Qinvisible
, window
),
2504 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2506 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2508 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2515 /* Initialize IT for stepping through current_buffer in window W,
2516 starting at position POS that includes overlay string and display
2517 vector/ control character translation position information. Value
2518 is zero if there are overlay strings with newlines at POS. */
2521 init_from_display_pos (it
, w
, pos
)
2524 struct display_pos
*pos
;
2526 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2527 int i
, overlay_strings_with_newlines
= 0;
2529 /* If POS specifies a position in a display vector, this might
2530 be for an ellipsis displayed for invisible text. We won't
2531 get the iterator set up for delivering that ellipsis unless
2532 we make sure that it gets aware of the invisible text. */
2533 if (in_ellipses_for_invisible_text_p (pos
, w
))
2539 /* Keep in mind: the call to reseat in init_iterator skips invisible
2540 text, so we might end up at a position different from POS. This
2541 is only a problem when POS is a row start after a newline and an
2542 overlay starts there with an after-string, and the overlay has an
2543 invisible property. Since we don't skip invisible text in
2544 display_line and elsewhere immediately after consuming the
2545 newline before the row start, such a POS will not be in a string,
2546 but the call to init_iterator below will move us to the
2548 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2550 /* This only scans the current chunk -- it should scan all chunks.
2551 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2552 to 16 in 22.1 to make this a lesser problem. */
2553 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2555 const char *s
= SDATA (it
->overlay_strings
[i
]);
2556 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2558 while (s
< e
&& *s
!= '\n')
2563 overlay_strings_with_newlines
= 1;
2568 /* If position is within an overlay string, set up IT to the right
2570 if (pos
->overlay_string_index
>= 0)
2574 /* If the first overlay string happens to have a `display'
2575 property for an image, the iterator will be set up for that
2576 image, and we have to undo that setup first before we can
2577 correct the overlay string index. */
2578 if (it
->method
== GET_FROM_IMAGE
)
2581 /* We already have the first chunk of overlay strings in
2582 IT->overlay_strings. Load more until the one for
2583 pos->overlay_string_index is in IT->overlay_strings. */
2584 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2586 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2587 it
->current
.overlay_string_index
= 0;
2590 load_overlay_strings (it
, 0);
2591 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2595 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2596 relative_index
= (it
->current
.overlay_string_index
2597 % OVERLAY_STRING_CHUNK_SIZE
);
2598 it
->string
= it
->overlay_strings
[relative_index
];
2599 xassert (STRINGP (it
->string
));
2600 it
->current
.string_pos
= pos
->string_pos
;
2601 it
->method
= GET_FROM_STRING
;
2604 #if 0 /* This is bogus because POS not having an overlay string
2605 position does not mean it's after the string. Example: A
2606 line starting with a before-string and initialization of IT
2607 to the previous row's end position. */
2608 else if (it
->current
.overlay_string_index
>= 0)
2610 /* If POS says we're already after an overlay string ending at
2611 POS, make sure to pop the iterator because it will be in
2612 front of that overlay string. When POS is ZV, we've thereby
2613 also ``processed'' overlay strings at ZV. */
2616 it
->current
.overlay_string_index
= -1;
2617 it
->method
= GET_FROM_BUFFER
;
2618 if (CHARPOS (pos
->pos
) == ZV
)
2619 it
->overlay_strings_at_end_processed_p
= 1;
2623 if (CHARPOS (pos
->string_pos
) >= 0)
2625 /* Recorded position is not in an overlay string, but in another
2626 string. This can only be a string from a `display' property.
2627 IT should already be filled with that string. */
2628 it
->current
.string_pos
= pos
->string_pos
;
2629 xassert (STRINGP (it
->string
));
2632 /* Restore position in display vector translations, control
2633 character translations or ellipses. */
2634 if (pos
->dpvec_index
>= 0)
2636 if (it
->dpvec
== NULL
)
2637 get_next_display_element (it
);
2638 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2639 it
->current
.dpvec_index
= pos
->dpvec_index
;
2643 return !overlay_strings_with_newlines
;
2647 /* Initialize IT for stepping through current_buffer in window W
2648 starting at ROW->start. */
2651 init_to_row_start (it
, w
, row
)
2654 struct glyph_row
*row
;
2656 init_from_display_pos (it
, w
, &row
->start
);
2657 it
->start
= row
->start
;
2658 it
->continuation_lines_width
= row
->continuation_lines_width
;
2663 /* Initialize IT for stepping through current_buffer in window W
2664 starting in the line following ROW, i.e. starting at ROW->end.
2665 Value is zero if there are overlay strings with newlines at ROW's
2669 init_to_row_end (it
, w
, row
)
2672 struct glyph_row
*row
;
2676 if (init_from_display_pos (it
, w
, &row
->end
))
2678 if (row
->continued_p
)
2679 it
->continuation_lines_width
2680 = row
->continuation_lines_width
+ row
->pixel_width
;
2691 /***********************************************************************
2693 ***********************************************************************/
2695 /* Called when IT reaches IT->stop_charpos. Handle text property and
2696 overlay changes. Set IT->stop_charpos to the next position where
2703 enum prop_handled handled
;
2704 int handle_overlay_change_p
= 1;
2708 it
->current
.dpvec_index
= -1;
2710 /* Use face of preceding text for ellipsis (if invisible) */
2711 if (it
->selective_display_ellipsis_p
)
2712 it
->saved_face_id
= it
->face_id
;
2716 handled
= HANDLED_NORMALLY
;
2718 /* Call text property handlers. */
2719 for (p
= it_props
; p
->handler
; ++p
)
2721 handled
= p
->handler (it
);
2723 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2725 else if (handled
== HANDLED_RETURN
)
2727 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2728 handle_overlay_change_p
= 0;
2731 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2733 /* Don't check for overlay strings below when set to deliver
2734 characters from a display vector. */
2735 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
2736 handle_overlay_change_p
= 0;
2738 /* Handle overlay changes. */
2739 if (handle_overlay_change_p
)
2740 handled
= handle_overlay_change (it
);
2742 /* Determine where to stop next. */
2743 if (handled
== HANDLED_NORMALLY
)
2744 compute_stop_pos (it
);
2747 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2751 /* Compute IT->stop_charpos from text property and overlay change
2752 information for IT's current position. */
2755 compute_stop_pos (it
)
2758 register INTERVAL iv
, next_iv
;
2759 Lisp_Object object
, limit
, position
;
2761 /* If nowhere else, stop at the end. */
2762 it
->stop_charpos
= it
->end_charpos
;
2764 if (STRINGP (it
->string
))
2766 /* Strings are usually short, so don't limit the search for
2768 object
= it
->string
;
2770 position
= make_number (IT_STRING_CHARPOS (*it
));
2776 /* If next overlay change is in front of the current stop pos
2777 (which is IT->end_charpos), stop there. Note: value of
2778 next_overlay_change is point-max if no overlay change
2780 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2781 if (charpos
< it
->stop_charpos
)
2782 it
->stop_charpos
= charpos
;
2784 /* If showing the region, we have to stop at the region
2785 start or end because the face might change there. */
2786 if (it
->region_beg_charpos
> 0)
2788 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2789 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2790 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2791 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2794 /* Set up variables for computing the stop position from text
2795 property changes. */
2796 XSETBUFFER (object
, current_buffer
);
2797 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2798 position
= make_number (IT_CHARPOS (*it
));
2802 /* Get the interval containing IT's position. Value is a null
2803 interval if there isn't such an interval. */
2804 iv
= validate_interval_range (object
, &position
, &position
, 0);
2805 if (!NULL_INTERVAL_P (iv
))
2807 Lisp_Object values_here
[LAST_PROP_IDX
];
2810 /* Get properties here. */
2811 for (p
= it_props
; p
->handler
; ++p
)
2812 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2814 /* Look for an interval following iv that has different
2816 for (next_iv
= next_interval (iv
);
2817 (!NULL_INTERVAL_P (next_iv
)
2819 || XFASTINT (limit
) > next_iv
->position
));
2820 next_iv
= next_interval (next_iv
))
2822 for (p
= it_props
; p
->handler
; ++p
)
2824 Lisp_Object new_value
;
2826 new_value
= textget (next_iv
->plist
, *p
->name
);
2827 if (!EQ (values_here
[p
->idx
], new_value
))
2835 if (!NULL_INTERVAL_P (next_iv
))
2837 if (INTEGERP (limit
)
2838 && next_iv
->position
>= XFASTINT (limit
))
2839 /* No text property change up to limit. */
2840 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2842 /* Text properties change in next_iv. */
2843 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2847 xassert (STRINGP (it
->string
)
2848 || (it
->stop_charpos
>= BEGV
2849 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2853 /* Return the position of the next overlay change after POS in
2854 current_buffer. Value is point-max if no overlay change
2855 follows. This is like `next-overlay-change' but doesn't use
2859 next_overlay_change (pos
)
2864 Lisp_Object
*overlays
;
2867 /* Get all overlays at the given position. */
2868 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
2870 /* If any of these overlays ends before endpos,
2871 use its ending point instead. */
2872 for (i
= 0; i
< noverlays
; ++i
)
2877 oend
= OVERLAY_END (overlays
[i
]);
2878 oendpos
= OVERLAY_POSITION (oend
);
2879 endpos
= min (endpos
, oendpos
);
2887 /***********************************************************************
2889 ***********************************************************************/
2891 /* Handle changes in the `fontified' property of the current buffer by
2892 calling hook functions from Qfontification_functions to fontify
2895 static enum prop_handled
2896 handle_fontified_prop (it
)
2899 Lisp_Object prop
, pos
;
2900 enum prop_handled handled
= HANDLED_NORMALLY
;
2902 /* Get the value of the `fontified' property at IT's current buffer
2903 position. (The `fontified' property doesn't have a special
2904 meaning in strings.) If the value is nil, call functions from
2905 Qfontification_functions. */
2906 if (!STRINGP (it
->string
)
2908 && !NILP (Vfontification_functions
)
2909 && !NILP (Vrun_hooks
)
2910 && (pos
= make_number (IT_CHARPOS (*it
)),
2911 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2914 int count
= SPECPDL_INDEX ();
2917 val
= Vfontification_functions
;
2918 specbind (Qfontification_functions
, Qnil
);
2920 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2921 safe_call1 (val
, pos
);
2924 Lisp_Object globals
, fn
;
2925 struct gcpro gcpro1
, gcpro2
;
2928 GCPRO2 (val
, globals
);
2930 for (; CONSP (val
); val
= XCDR (val
))
2936 /* A value of t indicates this hook has a local
2937 binding; it means to run the global binding too.
2938 In a global value, t should not occur. If it
2939 does, we must ignore it to avoid an endless
2941 for (globals
= Fdefault_value (Qfontification_functions
);
2943 globals
= XCDR (globals
))
2945 fn
= XCAR (globals
);
2947 safe_call1 (fn
, pos
);
2951 safe_call1 (fn
, pos
);
2957 unbind_to (count
, Qnil
);
2959 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2960 something. This avoids an endless loop if they failed to
2961 fontify the text for which reason ever. */
2962 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2963 handled
= HANDLED_RECOMPUTE_PROPS
;
2971 /***********************************************************************
2973 ***********************************************************************/
2975 /* Set up iterator IT from face properties at its current position.
2976 Called from handle_stop. */
2978 static enum prop_handled
2979 handle_face_prop (it
)
2982 int new_face_id
, next_stop
;
2984 if (!STRINGP (it
->string
))
2987 = face_at_buffer_position (it
->w
,
2989 it
->region_beg_charpos
,
2990 it
->region_end_charpos
,
2993 + TEXT_PROP_DISTANCE_LIMIT
),
2996 /* Is this a start of a run of characters with box face?
2997 Caveat: this can be called for a freshly initialized
2998 iterator; face_id is -1 in this case. We know that the new
2999 face will not change until limit, i.e. if the new face has a
3000 box, all characters up to limit will have one. But, as
3001 usual, we don't know whether limit is really the end. */
3002 if (new_face_id
!= it
->face_id
)
3004 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3006 /* If new face has a box but old face has not, this is
3007 the start of a run of characters with box, i.e. it has
3008 a shadow on the left side. The value of face_id of the
3009 iterator will be -1 if this is the initial call that gets
3010 the face. In this case, we have to look in front of IT's
3011 position and see whether there is a face != new_face_id. */
3012 it
->start_of_box_run_p
3013 = (new_face
->box
!= FACE_NO_BOX
3014 && (it
->face_id
>= 0
3015 || IT_CHARPOS (*it
) == BEG
3016 || new_face_id
!= face_before_it_pos (it
)));
3017 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3022 int base_face_id
, bufpos
;
3024 if (it
->current
.overlay_string_index
>= 0)
3025 bufpos
= IT_CHARPOS (*it
);
3029 /* For strings from a buffer, i.e. overlay strings or strings
3030 from a `display' property, use the face at IT's current
3031 buffer position as the base face to merge with, so that
3032 overlay strings appear in the same face as surrounding
3033 text, unless they specify their own faces. */
3034 base_face_id
= underlying_face_id (it
);
3036 new_face_id
= face_at_string_position (it
->w
,
3038 IT_STRING_CHARPOS (*it
),
3040 it
->region_beg_charpos
,
3041 it
->region_end_charpos
,
3045 #if 0 /* This shouldn't be neccessary. Let's check it. */
3046 /* If IT is used to display a mode line we would really like to
3047 use the mode line face instead of the frame's default face. */
3048 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3049 && new_face_id
== DEFAULT_FACE_ID
)
3050 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3053 /* Is this a start of a run of characters with box? Caveat:
3054 this can be called for a freshly allocated iterator; face_id
3055 is -1 is this case. We know that the new face will not
3056 change until the next check pos, i.e. if the new face has a
3057 box, all characters up to that position will have a
3058 box. But, as usual, we don't know whether that position
3059 is really the end. */
3060 if (new_face_id
!= it
->face_id
)
3062 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3063 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3065 /* If new face has a box but old face hasn't, this is the
3066 start of a run of characters with box, i.e. it has a
3067 shadow on the left side. */
3068 it
->start_of_box_run_p
3069 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3070 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3074 it
->face_id
= new_face_id
;
3075 return HANDLED_NORMALLY
;
3079 /* Return the ID of the face ``underlying'' IT's current position,
3080 which is in a string. If the iterator is associated with a
3081 buffer, return the face at IT's current buffer position.
3082 Otherwise, use the iterator's base_face_id. */
3085 underlying_face_id (it
)
3088 int face_id
= it
->base_face_id
, i
;
3090 xassert (STRINGP (it
->string
));
3092 for (i
= it
->sp
- 1; i
>= 0; --i
)
3093 if (NILP (it
->stack
[i
].string
))
3094 face_id
= it
->stack
[i
].face_id
;
3100 /* Compute the face one character before or after the current position
3101 of IT. BEFORE_P non-zero means get the face in front of IT's
3102 position. Value is the id of the face. */
3105 face_before_or_after_it_pos (it
, before_p
)
3110 int next_check_charpos
;
3111 struct text_pos pos
;
3113 xassert (it
->s
== NULL
);
3115 if (STRINGP (it
->string
))
3117 int bufpos
, base_face_id
;
3119 /* No face change past the end of the string (for the case
3120 we are padding with spaces). No face change before the
3122 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3123 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3126 /* Set pos to the position before or after IT's current position. */
3128 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3130 /* For composition, we must check the character after the
3132 pos
= (it
->what
== IT_COMPOSITION
3133 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3134 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3136 if (it
->current
.overlay_string_index
>= 0)
3137 bufpos
= IT_CHARPOS (*it
);
3141 base_face_id
= underlying_face_id (it
);
3143 /* Get the face for ASCII, or unibyte. */
3144 face_id
= face_at_string_position (it
->w
,
3148 it
->region_beg_charpos
,
3149 it
->region_end_charpos
,
3150 &next_check_charpos
,
3153 /* Correct the face for charsets different from ASCII. Do it
3154 for the multibyte case only. The face returned above is
3155 suitable for unibyte text if IT->string is unibyte. */
3156 if (STRING_MULTIBYTE (it
->string
))
3158 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3159 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3161 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3163 c
= string_char_and_length (p
, rest
, &len
);
3164 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3169 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3170 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3173 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3174 pos
= it
->current
.pos
;
3177 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3180 if (it
->what
== IT_COMPOSITION
)
3181 /* For composition, we must check the position after the
3183 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3185 INC_TEXT_POS (pos
, it
->multibyte_p
);
3188 /* Determine face for CHARSET_ASCII, or unibyte. */
3189 face_id
= face_at_buffer_position (it
->w
,
3191 it
->region_beg_charpos
,
3192 it
->region_end_charpos
,
3193 &next_check_charpos
,
3196 /* Correct the face for charsets different from ASCII. Do it
3197 for the multibyte case only. The face returned above is
3198 suitable for unibyte text if current_buffer is unibyte. */
3199 if (it
->multibyte_p
)
3201 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3202 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3203 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3212 /***********************************************************************
3214 ***********************************************************************/
3216 /* Set up iterator IT from invisible properties at its current
3217 position. Called from handle_stop. */
3219 static enum prop_handled
3220 handle_invisible_prop (it
)
3223 enum prop_handled handled
= HANDLED_NORMALLY
;
3225 if (STRINGP (it
->string
))
3227 extern Lisp_Object Qinvisible
;
3228 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3230 /* Get the value of the invisible text property at the
3231 current position. Value will be nil if there is no such
3233 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3234 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3237 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3239 handled
= HANDLED_RECOMPUTE_PROPS
;
3241 /* Get the position at which the next change of the
3242 invisible text property can be found in IT->string.
3243 Value will be nil if the property value is the same for
3244 all the rest of IT->string. */
3245 XSETINT (limit
, SCHARS (it
->string
));
3246 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3249 /* Text at current position is invisible. The next
3250 change in the property is at position end_charpos.
3251 Move IT's current position to that position. */
3252 if (INTEGERP (end_charpos
)
3253 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3255 struct text_pos old
;
3256 old
= it
->current
.string_pos
;
3257 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3258 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3262 /* The rest of the string is invisible. If this is an
3263 overlay string, proceed with the next overlay string
3264 or whatever comes and return a character from there. */
3265 if (it
->current
.overlay_string_index
>= 0)
3267 next_overlay_string (it
);
3268 /* Don't check for overlay strings when we just
3269 finished processing them. */
3270 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3274 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3275 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3282 int invis_p
, newpos
, next_stop
, start_charpos
;
3283 Lisp_Object pos
, prop
, overlay
;
3285 /* First of all, is there invisible text at this position? */
3286 start_charpos
= IT_CHARPOS (*it
);
3287 pos
= make_number (IT_CHARPOS (*it
));
3288 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3290 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3292 /* If we are on invisible text, skip over it. */
3293 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3295 /* Record whether we have to display an ellipsis for the
3297 int display_ellipsis_p
= invis_p
== 2;
3299 handled
= HANDLED_RECOMPUTE_PROPS
;
3301 /* Loop skipping over invisible text. The loop is left at
3302 ZV or with IT on the first char being visible again. */
3305 /* Try to skip some invisible text. Return value is the
3306 position reached which can be equal to IT's position
3307 if there is nothing invisible here. This skips both
3308 over invisible text properties and overlays with
3309 invisible property. */
3310 newpos
= skip_invisible (IT_CHARPOS (*it
),
3311 &next_stop
, ZV
, it
->window
);
3313 /* If we skipped nothing at all we weren't at invisible
3314 text in the first place. If everything to the end of
3315 the buffer was skipped, end the loop. */
3316 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3320 /* We skipped some characters but not necessarily
3321 all there are. Check if we ended up on visible
3322 text. Fget_char_property returns the property of
3323 the char before the given position, i.e. if we
3324 get invis_p = 0, this means that the char at
3325 newpos is visible. */
3326 pos
= make_number (newpos
);
3327 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3328 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3331 /* If we ended up on invisible text, proceed to
3332 skip starting with next_stop. */
3334 IT_CHARPOS (*it
) = next_stop
;
3338 /* The position newpos is now either ZV or on visible text. */
3339 IT_CHARPOS (*it
) = newpos
;
3340 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3342 /* If there are before-strings at the start of invisible
3343 text, and the text is invisible because of a text
3344 property, arrange to show before-strings because 20.x did
3345 it that way. (If the text is invisible because of an
3346 overlay property instead of a text property, this is
3347 already handled in the overlay code.) */
3349 && get_overlay_strings (it
, start_charpos
))
3351 handled
= HANDLED_RECOMPUTE_PROPS
;
3352 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3354 else if (display_ellipsis_p
)
3355 setup_for_ellipsis (it
, 0);
3363 /* Make iterator IT return `...' next.
3364 Replaces LEN characters from buffer. */
3367 setup_for_ellipsis (it
, len
)
3371 /* Use the display table definition for `...'. Invalid glyphs
3372 will be handled by the method returning elements from dpvec. */
3373 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3375 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3376 it
->dpvec
= v
->contents
;
3377 it
->dpend
= v
->contents
+ v
->size
;
3381 /* Default `...'. */
3382 it
->dpvec
= default_invis_vector
;
3383 it
->dpend
= default_invis_vector
+ 3;
3386 it
->dpvec_char_len
= len
;
3387 it
->current
.dpvec_index
= 0;
3388 it
->dpvec_face_id
= -1;
3390 /* Remember the current face id in case glyphs specify faces.
3391 IT's face is restored in set_iterator_to_next.
3392 saved_face_id was set to preceding char's face in handle_stop. */
3393 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3394 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3396 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3402 /***********************************************************************
3404 ***********************************************************************/
3406 /* Set up iterator IT from `display' property at its current position.
3407 Called from handle_stop.
3408 We return HANDLED_RETURN if some part of the display property
3409 overrides the display of the buffer text itself.
3410 Otherwise we return HANDLED_NORMALLY. */
3412 static enum prop_handled
3413 handle_display_prop (it
)
3416 Lisp_Object prop
, object
;
3417 struct text_pos
*position
;
3418 /* Nonzero if some property replaces the display of the text itself. */
3419 int display_replaced_p
= 0;
3421 if (STRINGP (it
->string
))
3423 object
= it
->string
;
3424 position
= &it
->current
.string_pos
;
3428 object
= it
->w
->buffer
;
3429 position
= &it
->current
.pos
;
3432 /* Reset those iterator values set from display property values. */
3433 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3434 it
->space_width
= Qnil
;
3435 it
->font_height
= Qnil
;
3438 /* We don't support recursive `display' properties, i.e. string
3439 values that have a string `display' property, that have a string
3440 `display' property etc. */
3441 if (!it
->string_from_display_prop_p
)
3442 it
->area
= TEXT_AREA
;
3444 prop
= Fget_char_property (make_number (position
->charpos
),
3447 return HANDLED_NORMALLY
;
3450 /* Simple properties. */
3451 && !EQ (XCAR (prop
), Qimage
)
3452 && !EQ (XCAR (prop
), Qspace
)
3453 && !EQ (XCAR (prop
), Qwhen
)
3454 && !EQ (XCAR (prop
), Qslice
)
3455 && !EQ (XCAR (prop
), Qspace_width
)
3456 && !EQ (XCAR (prop
), Qheight
)
3457 && !EQ (XCAR (prop
), Qraise
)
3458 /* Marginal area specifications. */
3459 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3460 && !EQ (XCAR (prop
), Qleft_fringe
)
3461 && !EQ (XCAR (prop
), Qright_fringe
)
3462 && !NILP (XCAR (prop
)))
3464 for (; CONSP (prop
); prop
= XCDR (prop
))
3466 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3467 position
, display_replaced_p
))
3468 display_replaced_p
= 1;
3471 else if (VECTORP (prop
))
3474 for (i
= 0; i
< ASIZE (prop
); ++i
)
3475 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3476 position
, display_replaced_p
))
3477 display_replaced_p
= 1;
3481 int ret
= handle_single_display_spec (it
, prop
, object
, position
, 0);
3482 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3483 return HANDLED_RECOMPUTE_PROPS
;
3485 display_replaced_p
= 1;
3488 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3492 /* Value is the position of the end of the `display' property starting
3493 at START_POS in OBJECT. */
3495 static struct text_pos
3496 display_prop_end (it
, object
, start_pos
)
3499 struct text_pos start_pos
;
3502 struct text_pos end_pos
;
3504 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3505 Qdisplay
, object
, Qnil
);
3506 CHARPOS (end_pos
) = XFASTINT (end
);
3507 if (STRINGP (object
))
3508 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3510 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3516 /* Set up IT from a single `display' specification PROP. OBJECT
3517 is the object in which the `display' property was found. *POSITION
3518 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3519 means that we previously saw a display specification which already
3520 replaced text display with something else, for example an image;
3521 we ignore such properties after the first one has been processed.
3523 If PROP is a `space' or `image' specification, and in some other
3524 cases too, set *POSITION to the position where the `display'
3527 Value is non-zero if something was found which replaces the display
3528 of buffer or string text. Specifically, the value is -1 if that
3529 "something" is "nothing". */
3532 handle_single_display_spec (it
, spec
, object
, position
,
3533 display_replaced_before_p
)
3537 struct text_pos
*position
;
3538 int display_replaced_before_p
;
3541 Lisp_Object location
, value
;
3542 struct text_pos start_pos
;
3545 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3546 If the result is non-nil, use VALUE instead of SPEC. */
3548 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3557 if (!NILP (form
) && !EQ (form
, Qt
))
3559 int count
= SPECPDL_INDEX ();
3560 struct gcpro gcpro1
;
3562 /* Bind `object' to the object having the `display' property, a
3563 buffer or string. Bind `position' to the position in the
3564 object where the property was found, and `buffer-position'
3565 to the current position in the buffer. */
3566 specbind (Qobject
, object
);
3567 specbind (Qposition
, make_number (CHARPOS (*position
)));
3568 specbind (Qbuffer_position
,
3569 make_number (STRINGP (object
)
3570 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3572 form
= safe_eval (form
);
3574 unbind_to (count
, Qnil
);
3580 /* Handle `(height HEIGHT)' specifications. */
3582 && EQ (XCAR (spec
), Qheight
)
3583 && CONSP (XCDR (spec
)))
3585 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3588 it
->font_height
= XCAR (XCDR (spec
));
3589 if (!NILP (it
->font_height
))
3591 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3592 int new_height
= -1;
3594 if (CONSP (it
->font_height
)
3595 && (EQ (XCAR (it
->font_height
), Qplus
)
3596 || EQ (XCAR (it
->font_height
), Qminus
))
3597 && CONSP (XCDR (it
->font_height
))
3598 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3600 /* `(+ N)' or `(- N)' where N is an integer. */
3601 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3602 if (EQ (XCAR (it
->font_height
), Qplus
))
3604 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3606 else if (FUNCTIONP (it
->font_height
))
3608 /* Call function with current height as argument.
3609 Value is the new height. */
3611 height
= safe_call1 (it
->font_height
,
3612 face
->lface
[LFACE_HEIGHT_INDEX
]);
3613 if (NUMBERP (height
))
3614 new_height
= XFLOATINT (height
);
3616 else if (NUMBERP (it
->font_height
))
3618 /* Value is a multiple of the canonical char height. */
3621 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3622 new_height
= (XFLOATINT (it
->font_height
)
3623 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3627 /* Evaluate IT->font_height with `height' bound to the
3628 current specified height to get the new height. */
3629 int count
= SPECPDL_INDEX ();
3631 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3632 value
= safe_eval (it
->font_height
);
3633 unbind_to (count
, Qnil
);
3635 if (NUMBERP (value
))
3636 new_height
= XFLOATINT (value
);
3640 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3646 /* Handle `(space_width WIDTH)'. */
3648 && EQ (XCAR (spec
), Qspace_width
)
3649 && CONSP (XCDR (spec
)))
3651 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3654 value
= XCAR (XCDR (spec
));
3655 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3656 it
->space_width
= value
;
3661 /* Handle `(slice X Y WIDTH HEIGHT)'. */
3663 && EQ (XCAR (spec
), Qslice
))
3667 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3670 if (tem
= XCDR (spec
), CONSP (tem
))
3672 it
->slice
.x
= XCAR (tem
);
3673 if (tem
= XCDR (tem
), CONSP (tem
))
3675 it
->slice
.y
= XCAR (tem
);
3676 if (tem
= XCDR (tem
), CONSP (tem
))
3678 it
->slice
.width
= XCAR (tem
);
3679 if (tem
= XCDR (tem
), CONSP (tem
))
3680 it
->slice
.height
= XCAR (tem
);
3688 /* Handle `(raise FACTOR)'. */
3690 && EQ (XCAR (spec
), Qraise
)
3691 && CONSP (XCDR (spec
)))
3693 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3696 #ifdef HAVE_WINDOW_SYSTEM
3697 value
= XCAR (XCDR (spec
));
3698 if (NUMBERP (value
))
3700 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3701 it
->voffset
= - (XFLOATINT (value
)
3702 * (FONT_HEIGHT (face
->font
)));
3704 #endif /* HAVE_WINDOW_SYSTEM */
3709 /* Don't handle the other kinds of display specifications
3710 inside a string that we got from a `display' property. */
3711 if (it
->string_from_display_prop_p
)
3714 /* Characters having this form of property are not displayed, so
3715 we have to find the end of the property. */
3716 start_pos
= *position
;
3717 *position
= display_prop_end (it
, object
, start_pos
);
3720 /* Stop the scan at that end position--we assume that all
3721 text properties change there. */
3722 it
->stop_charpos
= position
->charpos
;
3724 /* Handle `(left-fringe BITMAP [FACE])'
3725 and `(right-fringe BITMAP [FACE])'. */
3727 && (EQ (XCAR (spec
), Qleft_fringe
)
3728 || EQ (XCAR (spec
), Qright_fringe
))
3729 && CONSP (XCDR (spec
)))
3731 int face_id
= DEFAULT_FACE_ID
;
3734 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3735 /* If we return here, POSITION has been advanced
3736 across the text with this property. */
3739 #ifdef HAVE_WINDOW_SYSTEM
3740 value
= XCAR (XCDR (spec
));
3741 if (!SYMBOLP (value
)
3742 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
3743 /* If we return here, POSITION has been advanced
3744 across the text with this property. */
3747 if (CONSP (XCDR (XCDR (spec
))))
3749 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
3750 int face_id2
= lookup_derived_face (it
->f
, face_name
,
3756 /* Save current settings of IT so that we can restore them
3757 when we are finished with the glyph property value. */
3761 it
->area
= TEXT_AREA
;
3762 it
->what
= IT_IMAGE
;
3763 it
->image_id
= -1; /* no image */
3764 it
->position
= start_pos
;
3765 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3766 it
->method
= GET_FROM_IMAGE
;
3767 it
->face_id
= face_id
;
3769 /* Say that we haven't consumed the characters with
3770 `display' property yet. The call to pop_it in
3771 set_iterator_to_next will clean this up. */
3772 *position
= start_pos
;
3774 if (EQ (XCAR (spec
), Qleft_fringe
))
3776 it
->left_user_fringe_bitmap
= fringe_bitmap
;
3777 it
->left_user_fringe_face_id
= face_id
;
3781 it
->right_user_fringe_bitmap
= fringe_bitmap
;
3782 it
->right_user_fringe_face_id
= face_id
;
3784 #endif /* HAVE_WINDOW_SYSTEM */
3788 /* Prepare to handle `((margin left-margin) ...)',
3789 `((margin right-margin) ...)' and `((margin nil) ...)'
3790 prefixes for display specifications. */
3791 location
= Qunbound
;
3792 if (CONSP (spec
) && CONSP (XCAR (spec
)))
3796 value
= XCDR (spec
);
3798 value
= XCAR (value
);
3801 if (EQ (XCAR (tem
), Qmargin
)
3802 && (tem
= XCDR (tem
),
3803 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3805 || EQ (tem
, Qleft_margin
)
3806 || EQ (tem
, Qright_margin
))))
3810 if (EQ (location
, Qunbound
))
3816 /* After this point, VALUE is the property after any
3817 margin prefix has been stripped. It must be a string,
3818 an image specification, or `(space ...)'.
3820 LOCATION specifies where to display: `left-margin',
3821 `right-margin' or nil. */
3823 valid_p
= (STRINGP (value
)
3824 #ifdef HAVE_WINDOW_SYSTEM
3825 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
3826 #endif /* not HAVE_WINDOW_SYSTEM */
3827 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
3829 if (valid_p
&& !display_replaced_before_p
)
3831 /* Save current settings of IT so that we can restore them
3832 when we are finished with the glyph property value. */
3835 if (NILP (location
))
3836 it
->area
= TEXT_AREA
;
3837 else if (EQ (location
, Qleft_margin
))
3838 it
->area
= LEFT_MARGIN_AREA
;
3840 it
->area
= RIGHT_MARGIN_AREA
;
3842 if (STRINGP (value
))
3844 if (SCHARS (value
) == 0)
3847 return -1; /* Replaced by "", i.e. nothing. */
3850 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3851 it
->current
.overlay_string_index
= -1;
3852 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3853 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3854 it
->method
= GET_FROM_STRING
;
3855 it
->stop_charpos
= 0;
3856 it
->string_from_display_prop_p
= 1;
3857 /* Say that we haven't consumed the characters with
3858 `display' property yet. The call to pop_it in
3859 set_iterator_to_next will clean this up. */
3860 *position
= start_pos
;
3862 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3864 it
->method
= GET_FROM_STRETCH
;
3866 it
->current
.pos
= it
->position
= start_pos
;
3868 #ifdef HAVE_WINDOW_SYSTEM
3871 it
->what
= IT_IMAGE
;
3872 it
->image_id
= lookup_image (it
->f
, value
);
3873 it
->position
= start_pos
;
3874 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3875 it
->method
= GET_FROM_IMAGE
;
3877 /* Say that we haven't consumed the characters with
3878 `display' property yet. The call to pop_it in
3879 set_iterator_to_next will clean this up. */
3880 *position
= start_pos
;
3882 #endif /* HAVE_WINDOW_SYSTEM */
3887 /* Invalid property or property not supported. Restore
3888 POSITION to what it was before. */
3889 *position
= start_pos
;
3894 /* Check if SPEC is a display specification value whose text should be
3895 treated as intangible. */
3898 single_display_spec_intangible_p (prop
)
3901 /* Skip over `when FORM'. */
3902 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3916 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3917 we don't need to treat text as intangible. */
3918 if (EQ (XCAR (prop
), Qmargin
))
3926 || EQ (XCAR (prop
), Qleft_margin
)
3927 || EQ (XCAR (prop
), Qright_margin
))
3931 return (CONSP (prop
)
3932 && (EQ (XCAR (prop
), Qimage
)
3933 || EQ (XCAR (prop
), Qspace
)));
3937 /* Check if PROP is a display property value whose text should be
3938 treated as intangible. */
3941 display_prop_intangible_p (prop
)
3945 && CONSP (XCAR (prop
))
3946 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3948 /* A list of sub-properties. */
3949 while (CONSP (prop
))
3951 if (single_display_spec_intangible_p (XCAR (prop
)))
3956 else if (VECTORP (prop
))
3958 /* A vector of sub-properties. */
3960 for (i
= 0; i
< ASIZE (prop
); ++i
)
3961 if (single_display_spec_intangible_p (AREF (prop
, i
)))
3965 return single_display_spec_intangible_p (prop
);
3971 /* Return 1 if PROP is a display sub-property value containing STRING. */
3974 single_display_spec_string_p (prop
, string
)
3975 Lisp_Object prop
, string
;
3977 if (EQ (string
, prop
))
3980 /* Skip over `when FORM'. */
3981 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3990 /* Skip over `margin LOCATION'. */
3991 if (EQ (XCAR (prop
), Qmargin
))
4002 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4006 /* Return 1 if STRING appears in the `display' property PROP. */
4009 display_prop_string_p (prop
, string
)
4010 Lisp_Object prop
, string
;
4013 && CONSP (XCAR (prop
))
4014 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4016 /* A list of sub-properties. */
4017 while (CONSP (prop
))
4019 if (single_display_spec_string_p (XCAR (prop
), string
))
4024 else if (VECTORP (prop
))
4026 /* A vector of sub-properties. */
4028 for (i
= 0; i
< ASIZE (prop
); ++i
)
4029 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4033 return single_display_spec_string_p (prop
, string
);
4039 /* Determine from which buffer position in W's buffer STRING comes
4040 from. AROUND_CHARPOS is an approximate position where it could
4041 be from. Value is the buffer position or 0 if it couldn't be
4044 W's buffer must be current.
4046 This function is necessary because we don't record buffer positions
4047 in glyphs generated from strings (to keep struct glyph small).
4048 This function may only use code that doesn't eval because it is
4049 called asynchronously from note_mouse_highlight. */
4052 string_buffer_position (w
, string
, around_charpos
)
4057 Lisp_Object limit
, prop
, pos
;
4058 const int MAX_DISTANCE
= 1000;
4061 pos
= make_number (around_charpos
);
4062 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4063 while (!found
&& !EQ (pos
, limit
))
4065 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4066 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4069 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4074 pos
= make_number (around_charpos
);
4075 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4076 while (!found
&& !EQ (pos
, limit
))
4078 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4079 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4082 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4087 return found
? XINT (pos
) : 0;
4092 /***********************************************************************
4093 `composition' property
4094 ***********************************************************************/
4096 static enum prop_handled
4097 handle_auto_composed_prop (it
)
4100 enum prop_handled handled
= HANDLED_NORMALLY
;
4102 if (FUNCTIONP (Vauto_composition_function
))
4105 EMACS_INT pos
, this_pos
;
4107 if (STRINGP (it
->string
))
4108 pos
= IT_STRING_CHARPOS (*it
);
4110 pos
= IT_CHARPOS (*it
);
4113 val
=Fget_char_property (make_number (pos
), Qauto_composed
, it
->string
);
4116 Lisp_Object limit
= Qnil
, next
;
4118 /* As Fnext_single_char_property_change is very slow, we
4119 limit the search to the current line. */
4120 if (STRINGP (it
->string
))
4121 limit
= make_number (SCHARS (it
->string
));
4123 limit
= make_number (find_next_newline_no_quit (pos
, 1));
4125 next
= (Fnext_single_property_change
4126 (make_number (pos
), Qauto_composed
, it
->string
, limit
));
4127 if (XINT (next
) < XINT (limit
))
4129 /* The current point is auto-composed, but there exist
4130 characters not yet composed beyond the auto-composed
4131 region. There's a possiblity that the last
4132 characters in the region may be newly composed. */
4133 int charpos
= XINT (next
) - 1, bytepos
, c
;
4135 if (STRINGP (it
->string
))
4137 bytepos
= string_char_to_byte (it
->string
, charpos
);
4138 c
= SDATA (it
->string
)[bytepos
];
4142 bytepos
= CHAR_TO_BYTE (charpos
);
4143 c
= FETCH_BYTE (bytepos
);
4146 /* If the last character is not newline, it may be
4147 composed with the following characters. */
4148 val
= Qnil
, pos
= charpos
+ 1;
4153 int count
= SPECPDL_INDEX ();
4154 Lisp_Object args
[3];
4156 args
[0] = Vauto_composition_function
;
4157 specbind (Qauto_composition_function
, Qnil
);
4158 args
[1] = make_number (pos
);
4159 args
[2] = it
->string
;
4160 safe_call (3, args
);
4161 unbind_to (count
, Qnil
);
4163 if (this_pos
== pos
)
4165 val
= Fget_char_property (args
[1], Qauto_composed
, it
->string
);
4166 /* Return HANDLED_RECOMPUTE_PROPS only if function composed
4167 something. This avoids an endless loop if they failed to
4168 fontify the text for which reason ever. */
4170 handled
= HANDLED_RECOMPUTE_PROPS
;
4173 handled
= HANDLED_RECOMPUTE_PROPS
;
4180 /* Set up iterator IT from `composition' property at its current
4181 position. Called from handle_stop. */
4183 static enum prop_handled
4184 handle_composition_prop (it
)
4187 Lisp_Object prop
, string
;
4188 EMACS_INT pos
, pos_byte
, start
, end
;
4189 enum prop_handled handled
= HANDLED_NORMALLY
;
4191 if (STRINGP (it
->string
))
4193 pos
= IT_STRING_CHARPOS (*it
);
4194 pos_byte
= IT_STRING_BYTEPOS (*it
);
4195 string
= it
->string
;
4199 pos
= IT_CHARPOS (*it
);
4200 pos_byte
= IT_BYTEPOS (*it
);
4204 /* If there's a valid composition and point is not inside of the
4205 composition (in the case that the composition is from the current
4206 buffer), draw a glyph composed from the composition components. */
4207 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4208 && COMPOSITION_VALID_P (start
, end
, prop
)
4209 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4215 if (STRINGP (it
->string
))
4216 pos_byte
= string_char_to_byte (it
->string
, start
);
4218 pos_byte
= CHAR_TO_BYTE (start
);
4220 id
= get_composition_id (start
, pos_byte
, end
- start
, prop
, string
);
4224 it
->method
= GET_FROM_COMPOSITION
;
4226 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4227 /* For a terminal, draw only the first character of the
4229 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4230 it
->len
= (STRINGP (it
->string
)
4231 ? string_char_to_byte (it
->string
, end
)
4232 : CHAR_TO_BYTE (end
)) - pos_byte
;
4233 it
->stop_charpos
= end
;
4234 handled
= HANDLED_RETURN
;
4243 /***********************************************************************
4245 ***********************************************************************/
4247 /* The following structure is used to record overlay strings for
4248 later sorting in load_overlay_strings. */
4250 struct overlay_entry
4252 Lisp_Object overlay
;
4259 /* Set up iterator IT from overlay strings at its current position.
4260 Called from handle_stop. */
4262 static enum prop_handled
4263 handle_overlay_change (it
)
4266 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4267 return HANDLED_RECOMPUTE_PROPS
;
4269 return HANDLED_NORMALLY
;
4273 /* Set up the next overlay string for delivery by IT, if there is an
4274 overlay string to deliver. Called by set_iterator_to_next when the
4275 end of the current overlay string is reached. If there are more
4276 overlay strings to display, IT->string and
4277 IT->current.overlay_string_index are set appropriately here.
4278 Otherwise IT->string is set to nil. */
4281 next_overlay_string (it
)
4284 ++it
->current
.overlay_string_index
;
4285 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4287 /* No more overlay strings. Restore IT's settings to what
4288 they were before overlay strings were processed, and
4289 continue to deliver from current_buffer. */
4290 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4293 xassert (it
->stop_charpos
>= BEGV
4294 && it
->stop_charpos
<= it
->end_charpos
);
4296 it
->current
.overlay_string_index
= -1;
4297 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4298 it
->n_overlay_strings
= 0;
4299 it
->method
= GET_FROM_BUFFER
;
4301 /* If we're at the end of the buffer, record that we have
4302 processed the overlay strings there already, so that
4303 next_element_from_buffer doesn't try it again. */
4304 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4305 it
->overlay_strings_at_end_processed_p
= 1;
4307 /* If we have to display `...' for invisible text, set
4308 the iterator up for that. */
4309 if (display_ellipsis_p
)
4310 setup_for_ellipsis (it
, 0);
4314 /* There are more overlay strings to process. If
4315 IT->current.overlay_string_index has advanced to a position
4316 where we must load IT->overlay_strings with more strings, do
4318 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4320 if (it
->current
.overlay_string_index
&& i
== 0)
4321 load_overlay_strings (it
, 0);
4323 /* Initialize IT to deliver display elements from the overlay
4325 it
->string
= it
->overlay_strings
[i
];
4326 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4327 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4328 it
->method
= GET_FROM_STRING
;
4329 it
->stop_charpos
= 0;
4336 /* Compare two overlay_entry structures E1 and E2. Used as a
4337 comparison function for qsort in load_overlay_strings. Overlay
4338 strings for the same position are sorted so that
4340 1. All after-strings come in front of before-strings, except
4341 when they come from the same overlay.
4343 2. Within after-strings, strings are sorted so that overlay strings
4344 from overlays with higher priorities come first.
4346 2. Within before-strings, strings are sorted so that overlay
4347 strings from overlays with higher priorities come last.
4349 Value is analogous to strcmp. */
4353 compare_overlay_entries (e1
, e2
)
4356 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4357 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4360 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4362 /* Let after-strings appear in front of before-strings if
4363 they come from different overlays. */
4364 if (EQ (entry1
->overlay
, entry2
->overlay
))
4365 result
= entry1
->after_string_p
? 1 : -1;
4367 result
= entry1
->after_string_p
? -1 : 1;
4369 else if (entry1
->after_string_p
)
4370 /* After-strings sorted in order of decreasing priority. */
4371 result
= entry2
->priority
- entry1
->priority
;
4373 /* Before-strings sorted in order of increasing priority. */
4374 result
= entry1
->priority
- entry2
->priority
;
4380 /* Load the vector IT->overlay_strings with overlay strings from IT's
4381 current buffer position, or from CHARPOS if that is > 0. Set
4382 IT->n_overlays to the total number of overlay strings found.
4384 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4385 a time. On entry into load_overlay_strings,
4386 IT->current.overlay_string_index gives the number of overlay
4387 strings that have already been loaded by previous calls to this
4390 IT->add_overlay_start contains an additional overlay start
4391 position to consider for taking overlay strings from, if non-zero.
4392 This position comes into play when the overlay has an `invisible'
4393 property, and both before and after-strings. When we've skipped to
4394 the end of the overlay, because of its `invisible' property, we
4395 nevertheless want its before-string to appear.
4396 IT->add_overlay_start will contain the overlay start position
4399 Overlay strings are sorted so that after-string strings come in
4400 front of before-string strings. Within before and after-strings,
4401 strings are sorted by overlay priority. See also function
4402 compare_overlay_entries. */
4405 load_overlay_strings (it
, charpos
)
4409 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4410 Lisp_Object overlay
, window
, str
, invisible
;
4411 struct Lisp_Overlay
*ov
;
4414 int n
= 0, i
, j
, invis_p
;
4415 struct overlay_entry
*entries
4416 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4419 charpos
= IT_CHARPOS (*it
);
4421 /* Append the overlay string STRING of overlay OVERLAY to vector
4422 `entries' which has size `size' and currently contains `n'
4423 elements. AFTER_P non-zero means STRING is an after-string of
4425 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4428 Lisp_Object priority; \
4432 int new_size = 2 * size; \
4433 struct overlay_entry *old = entries; \
4435 (struct overlay_entry *) alloca (new_size \
4436 * sizeof *entries); \
4437 bcopy (old, entries, size * sizeof *entries); \
4441 entries[n].string = (STRING); \
4442 entries[n].overlay = (OVERLAY); \
4443 priority = Foverlay_get ((OVERLAY), Qpriority); \
4444 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4445 entries[n].after_string_p = (AFTER_P); \
4450 /* Process overlay before the overlay center. */
4451 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4453 XSETMISC (overlay
, ov
);
4454 xassert (OVERLAYP (overlay
));
4455 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4456 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4461 /* Skip this overlay if it doesn't start or end at IT's current
4463 if (end
!= charpos
&& start
!= charpos
)
4466 /* Skip this overlay if it doesn't apply to IT->w. */
4467 window
= Foverlay_get (overlay
, Qwindow
);
4468 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4471 /* If the text ``under'' the overlay is invisible, both before-
4472 and after-strings from this overlay are visible; start and
4473 end position are indistinguishable. */
4474 invisible
= Foverlay_get (overlay
, Qinvisible
);
4475 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4477 /* If overlay has a non-empty before-string, record it. */
4478 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4479 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4481 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4483 /* If overlay has a non-empty after-string, record it. */
4484 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4485 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4487 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4490 /* Process overlays after the overlay center. */
4491 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4493 XSETMISC (overlay
, ov
);
4494 xassert (OVERLAYP (overlay
));
4495 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4496 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4498 if (start
> charpos
)
4501 /* Skip this overlay if it doesn't start or end at IT's current
4503 if (end
!= charpos
&& start
!= charpos
)
4506 /* Skip this overlay if it doesn't apply to IT->w. */
4507 window
= Foverlay_get (overlay
, Qwindow
);
4508 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4511 /* If the text ``under'' the overlay is invisible, it has a zero
4512 dimension, and both before- and after-strings apply. */
4513 invisible
= Foverlay_get (overlay
, Qinvisible
);
4514 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4516 /* If overlay has a non-empty before-string, record it. */
4517 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4518 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4520 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4522 /* If overlay has a non-empty after-string, record it. */
4523 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4524 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4526 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4529 #undef RECORD_OVERLAY_STRING
4533 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4535 /* Record the total number of strings to process. */
4536 it
->n_overlay_strings
= n
;
4538 /* IT->current.overlay_string_index is the number of overlay strings
4539 that have already been consumed by IT. Copy some of the
4540 remaining overlay strings to IT->overlay_strings. */
4542 j
= it
->current
.overlay_string_index
;
4543 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4544 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4550 /* Get the first chunk of overlay strings at IT's current buffer
4551 position, or at CHARPOS if that is > 0. Value is non-zero if at
4552 least one overlay string was found. */
4555 get_overlay_strings (it
, charpos
)
4559 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4560 process. This fills IT->overlay_strings with strings, and sets
4561 IT->n_overlay_strings to the total number of strings to process.
4562 IT->pos.overlay_string_index has to be set temporarily to zero
4563 because load_overlay_strings needs this; it must be set to -1
4564 when no overlay strings are found because a zero value would
4565 indicate a position in the first overlay string. */
4566 it
->current
.overlay_string_index
= 0;
4567 load_overlay_strings (it
, charpos
);
4569 /* If we found overlay strings, set up IT to deliver display
4570 elements from the first one. Otherwise set up IT to deliver
4571 from current_buffer. */
4572 if (it
->n_overlay_strings
)
4574 /* Make sure we know settings in current_buffer, so that we can
4575 restore meaningful values when we're done with the overlay
4577 compute_stop_pos (it
);
4578 xassert (it
->face_id
>= 0);
4580 /* Save IT's settings. They are restored after all overlay
4581 strings have been processed. */
4582 xassert (it
->sp
== 0);
4585 /* Set up IT to deliver display elements from the first overlay
4587 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4588 it
->string
= it
->overlay_strings
[0];
4589 it
->stop_charpos
= 0;
4590 xassert (STRINGP (it
->string
));
4591 it
->end_charpos
= SCHARS (it
->string
);
4592 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4593 it
->method
= GET_FROM_STRING
;
4598 it
->current
.overlay_string_index
= -1;
4599 it
->method
= GET_FROM_BUFFER
;
4604 /* Value is non-zero if we found at least one overlay string. */
4605 return STRINGP (it
->string
);
4610 /***********************************************************************
4611 Saving and restoring state
4612 ***********************************************************************/
4614 /* Save current settings of IT on IT->stack. Called, for example,
4615 before setting up IT for an overlay string, to be able to restore
4616 IT's settings to what they were after the overlay string has been
4623 struct iterator_stack_entry
*p
;
4625 xassert (it
->sp
< 2);
4626 p
= it
->stack
+ it
->sp
;
4628 p
->stop_charpos
= it
->stop_charpos
;
4629 xassert (it
->face_id
>= 0);
4630 p
->face_id
= it
->face_id
;
4631 p
->string
= it
->string
;
4632 p
->pos
= it
->current
;
4633 p
->end_charpos
= it
->end_charpos
;
4634 p
->string_nchars
= it
->string_nchars
;
4636 p
->multibyte_p
= it
->multibyte_p
;
4637 p
->slice
= it
->slice
;
4638 p
->space_width
= it
->space_width
;
4639 p
->font_height
= it
->font_height
;
4640 p
->voffset
= it
->voffset
;
4641 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4642 p
->display_ellipsis_p
= 0;
4647 /* Restore IT's settings from IT->stack. Called, for example, when no
4648 more overlay strings must be processed, and we return to delivering
4649 display elements from a buffer, or when the end of a string from a
4650 `display' property is reached and we return to delivering display
4651 elements from an overlay string, or from a buffer. */
4657 struct iterator_stack_entry
*p
;
4659 xassert (it
->sp
> 0);
4661 p
= it
->stack
+ it
->sp
;
4662 it
->stop_charpos
= p
->stop_charpos
;
4663 it
->face_id
= p
->face_id
;
4664 it
->string
= p
->string
;
4665 it
->current
= p
->pos
;
4666 it
->end_charpos
= p
->end_charpos
;
4667 it
->string_nchars
= p
->string_nchars
;
4669 it
->multibyte_p
= p
->multibyte_p
;
4670 it
->slice
= p
->slice
;
4671 it
->space_width
= p
->space_width
;
4672 it
->font_height
= p
->font_height
;
4673 it
->voffset
= p
->voffset
;
4674 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4679 /***********************************************************************
4681 ***********************************************************************/
4683 /* Set IT's current position to the previous line start. */
4686 back_to_previous_line_start (it
)
4689 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4690 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4694 /* Move IT to the next line start.
4696 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4697 we skipped over part of the text (as opposed to moving the iterator
4698 continuously over the text). Otherwise, don't change the value
4701 Newlines may come from buffer text, overlay strings, or strings
4702 displayed via the `display' property. That's the reason we can't
4703 simply use find_next_newline_no_quit.
4705 Note that this function may not skip over invisible text that is so
4706 because of text properties and immediately follows a newline. If
4707 it would, function reseat_at_next_visible_line_start, when called
4708 from set_iterator_to_next, would effectively make invisible
4709 characters following a newline part of the wrong glyph row, which
4710 leads to wrong cursor motion. */
4713 forward_to_next_line_start (it
, skipped_p
)
4717 int old_selective
, newline_found_p
, n
;
4718 const int MAX_NEWLINE_DISTANCE
= 500;
4720 /* If already on a newline, just consume it to avoid unintended
4721 skipping over invisible text below. */
4722 if (it
->what
== IT_CHARACTER
4724 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4726 set_iterator_to_next (it
, 0);
4731 /* Don't handle selective display in the following. It's (a)
4732 unnecessary because it's done by the caller, and (b) leads to an
4733 infinite recursion because next_element_from_ellipsis indirectly
4734 calls this function. */
4735 old_selective
= it
->selective
;
4738 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4739 from buffer text. */
4740 for (n
= newline_found_p
= 0;
4741 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4742 n
+= STRINGP (it
->string
) ? 0 : 1)
4744 if (!get_next_display_element (it
))
4746 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4747 set_iterator_to_next (it
, 0);
4750 /* If we didn't find a newline near enough, see if we can use a
4752 if (!newline_found_p
)
4754 int start
= IT_CHARPOS (*it
);
4755 int limit
= find_next_newline_no_quit (start
, 1);
4758 xassert (!STRINGP (it
->string
));
4760 /* If there isn't any `display' property in sight, and no
4761 overlays, we can just use the position of the newline in
4763 if (it
->stop_charpos
>= limit
4764 || ((pos
= Fnext_single_property_change (make_number (start
),
4766 Qnil
, make_number (limit
)),
4768 && next_overlay_change (start
) == ZV
))
4770 IT_CHARPOS (*it
) = limit
;
4771 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4772 *skipped_p
= newline_found_p
= 1;
4776 while (get_next_display_element (it
)
4777 && !newline_found_p
)
4779 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4780 set_iterator_to_next (it
, 0);
4785 it
->selective
= old_selective
;
4786 return newline_found_p
;
4790 /* Set IT's current position to the previous visible line start. Skip
4791 invisible text that is so either due to text properties or due to
4792 selective display. Caution: this does not change IT->current_x and
4796 back_to_previous_visible_line_start (it
)
4799 while (IT_CHARPOS (*it
) > BEGV
)
4801 back_to_previous_line_start (it
);
4802 if (IT_CHARPOS (*it
) <= BEGV
)
4805 /* If selective > 0, then lines indented more than that values
4807 if (it
->selective
> 0
4808 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4809 (double) it
->selective
)) /* iftc */
4812 /* Check the newline before point for invisibility. */
4815 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
4816 Qinvisible
, it
->window
);
4817 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4821 /* If newline has a display property that replaces the newline with something
4822 else (image or text), find start of overlay or interval and continue search
4824 if (IT_CHARPOS (*it
) > BEGV
)
4826 struct it it2
= *it
;
4829 Lisp_Object val
, overlay
;
4831 pos
= --IT_CHARPOS (it2
);
4834 if (handle_display_prop (&it2
) == HANDLED_RETURN
4835 && !NILP (val
= get_char_property_and_overlay
4836 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
4837 && (OVERLAYP (overlay
)
4838 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
4839 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
4843 IT_CHARPOS (*it
) = beg
;
4844 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
4852 xassert (IT_CHARPOS (*it
) >= BEGV
);
4853 xassert (IT_CHARPOS (*it
) == BEGV
4854 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4859 /* Reseat iterator IT at the previous visible line start. Skip
4860 invisible text that is so either due to text properties or due to
4861 selective display. At the end, update IT's overlay information,
4862 face information etc. */
4865 reseat_at_previous_visible_line_start (it
)
4868 back_to_previous_visible_line_start (it
);
4869 reseat (it
, it
->current
.pos
, 1);
4874 /* Reseat iterator IT on the next visible line start in the current
4875 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4876 preceding the line start. Skip over invisible text that is so
4877 because of selective display. Compute faces, overlays etc at the
4878 new position. Note that this function does not skip over text that
4879 is invisible because of text properties. */
4882 reseat_at_next_visible_line_start (it
, on_newline_p
)
4886 int newline_found_p
, skipped_p
= 0;
4888 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4890 /* Skip over lines that are invisible because they are indented
4891 more than the value of IT->selective. */
4892 if (it
->selective
> 0)
4893 while (IT_CHARPOS (*it
) < ZV
4894 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4895 (double) it
->selective
)) /* iftc */
4897 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4898 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4901 /* Position on the newline if that's what's requested. */
4902 if (on_newline_p
&& newline_found_p
)
4904 if (STRINGP (it
->string
))
4906 if (IT_STRING_CHARPOS (*it
) > 0)
4908 --IT_STRING_CHARPOS (*it
);
4909 --IT_STRING_BYTEPOS (*it
);
4912 else if (IT_CHARPOS (*it
) > BEGV
)
4916 reseat (it
, it
->current
.pos
, 0);
4920 reseat (it
, it
->current
.pos
, 0);
4927 /***********************************************************************
4928 Changing an iterator's position
4929 ***********************************************************************/
4931 /* Change IT's current position to POS in current_buffer. If FORCE_P
4932 is non-zero, always check for text properties at the new position.
4933 Otherwise, text properties are only looked up if POS >=
4934 IT->check_charpos of a property. */
4937 reseat (it
, pos
, force_p
)
4939 struct text_pos pos
;
4942 int original_pos
= IT_CHARPOS (*it
);
4944 reseat_1 (it
, pos
, 0);
4946 /* Determine where to check text properties. Avoid doing it
4947 where possible because text property lookup is very expensive. */
4949 || CHARPOS (pos
) > it
->stop_charpos
4950 || CHARPOS (pos
) < original_pos
)
4957 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4958 IT->stop_pos to POS, also. */
4961 reseat_1 (it
, pos
, set_stop_p
)
4963 struct text_pos pos
;
4966 /* Don't call this function when scanning a C string. */
4967 xassert (it
->s
== NULL
);
4969 /* POS must be a reasonable value. */
4970 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4972 it
->current
.pos
= it
->position
= pos
;
4973 XSETBUFFER (it
->object
, current_buffer
);
4974 it
->end_charpos
= ZV
;
4976 it
->current
.dpvec_index
= -1;
4977 it
->current
.overlay_string_index
= -1;
4978 IT_STRING_CHARPOS (*it
) = -1;
4979 IT_STRING_BYTEPOS (*it
) = -1;
4981 it
->method
= GET_FROM_BUFFER
;
4982 /* RMS: I added this to fix a bug in move_it_vertically_backward
4983 where it->area continued to relate to the starting point
4984 for the backward motion. Bug report from
4985 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
4986 However, I am not sure whether reseat still does the right thing
4987 in general after this change. */
4988 it
->area
= TEXT_AREA
;
4989 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4991 it
->face_before_selective_p
= 0;
4994 it
->stop_charpos
= CHARPOS (pos
);
4998 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4999 If S is non-null, it is a C string to iterate over. Otherwise,
5000 STRING gives a Lisp string to iterate over.
5002 If PRECISION > 0, don't return more then PRECISION number of
5003 characters from the string.
5005 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5006 characters have been returned. FIELD_WIDTH < 0 means an infinite
5009 MULTIBYTE = 0 means disable processing of multibyte characters,
5010 MULTIBYTE > 0 means enable it,
5011 MULTIBYTE < 0 means use IT->multibyte_p.
5013 IT must be initialized via a prior call to init_iterator before
5014 calling this function. */
5017 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5022 int precision
, field_width
, multibyte
;
5024 /* No region in strings. */
5025 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5027 /* No text property checks performed by default, but see below. */
5028 it
->stop_charpos
= -1;
5030 /* Set iterator position and end position. */
5031 bzero (&it
->current
, sizeof it
->current
);
5032 it
->current
.overlay_string_index
= -1;
5033 it
->current
.dpvec_index
= -1;
5034 xassert (charpos
>= 0);
5036 /* If STRING is specified, use its multibyteness, otherwise use the
5037 setting of MULTIBYTE, if specified. */
5039 it
->multibyte_p
= multibyte
> 0;
5043 xassert (STRINGP (string
));
5044 it
->string
= string
;
5046 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5047 it
->method
= GET_FROM_STRING
;
5048 it
->current
.string_pos
= string_pos (charpos
, string
);
5055 /* Note that we use IT->current.pos, not it->current.string_pos,
5056 for displaying C strings. */
5057 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5058 if (it
->multibyte_p
)
5060 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5061 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5065 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5066 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5069 it
->method
= GET_FROM_C_STRING
;
5072 /* PRECISION > 0 means don't return more than PRECISION characters
5074 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5075 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5077 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5078 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5079 FIELD_WIDTH < 0 means infinite field width. This is useful for
5080 padding with `-' at the end of a mode line. */
5081 if (field_width
< 0)
5082 field_width
= INFINITY
;
5083 if (field_width
> it
->end_charpos
- charpos
)
5084 it
->end_charpos
= charpos
+ field_width
;
5086 /* Use the standard display table for displaying strings. */
5087 if (DISP_TABLE_P (Vstandard_display_table
))
5088 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5090 it
->stop_charpos
= charpos
;
5096 /***********************************************************************
5098 ***********************************************************************/
5100 /* Map enum it_method value to corresponding next_element_from_* function. */
5102 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5104 next_element_from_buffer
,
5105 next_element_from_display_vector
,
5106 next_element_from_composition
,
5107 next_element_from_string
,
5108 next_element_from_c_string
,
5109 next_element_from_image
,
5110 next_element_from_stretch
5114 /* Load IT's display element fields with information about the next
5115 display element from the current position of IT. Value is zero if
5116 end of buffer (or C string) is reached. */
5119 get_next_display_element (it
)
5122 /* Non-zero means that we found a display element. Zero means that
5123 we hit the end of what we iterate over. Performance note: the
5124 function pointer `method' used here turns out to be faster than
5125 using a sequence of if-statements. */
5129 success_p
= (*get_next_element
[it
->method
]) (it
);
5131 if (it
->what
== IT_CHARACTER
)
5133 /* Map via display table or translate control characters.
5134 IT->c, IT->len etc. have been set to the next character by
5135 the function call above. If we have a display table, and it
5136 contains an entry for IT->c, translate it. Don't do this if
5137 IT->c itself comes from a display table, otherwise we could
5138 end up in an infinite recursion. (An alternative could be to
5139 count the recursion depth of this function and signal an
5140 error when a certain maximum depth is reached.) Is it worth
5142 if (success_p
&& it
->dpvec
== NULL
)
5147 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5150 struct Lisp_Vector
*v
= XVECTOR (dv
);
5152 /* Return the first character from the display table
5153 entry, if not empty. If empty, don't display the
5154 current character. */
5157 it
->dpvec_char_len
= it
->len
;
5158 it
->dpvec
= v
->contents
;
5159 it
->dpend
= v
->contents
+ v
->size
;
5160 it
->current
.dpvec_index
= 0;
5161 it
->dpvec_face_id
= -1;
5162 it
->saved_face_id
= it
->face_id
;
5163 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5168 set_iterator_to_next (it
, 0);
5173 /* Translate control characters into `\003' or `^C' form.
5174 Control characters coming from a display table entry are
5175 currently not translated because we use IT->dpvec to hold
5176 the translation. This could easily be changed but I
5177 don't believe that it is worth doing.
5179 If it->multibyte_p is nonzero, non-printable non-ASCII
5180 characters are also translated to octal form.
5182 If it->multibyte_p is zero, eight-bit characters that
5183 don't have corresponding multibyte char code are also
5184 translated to octal form. */
5185 else if ((it
->c
< ' '
5186 ? (it
->area
!= TEXT_AREA
5187 /* In mode line, treat \n, \t like other crl chars. */
5189 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5190 || (it
->c
!= '\n' && it
->c
!= '\t'))
5192 ? (!CHAR_PRINTABLE_P (it
->c
)
5193 || (!NILP (Vnobreak_char_display
)
5194 && (it
->c
== 0xA0 /* NO-BREAK SPACE */
5195 || it
->c
== 0xAD /* SOFT HYPHEN */)))
5197 && (! unibyte_display_via_language_environment
5198 || (UNIBYTE_CHAR_HAS_MULTIBYTE_P (it
->c
)))))))
5200 /* IT->c is a control character which must be displayed
5201 either as '\003' or as `^C' where the '\\' and '^'
5202 can be defined in the display table. Fill
5203 IT->ctl_chars with glyphs for what we have to
5204 display. Then, set IT->dpvec to these glyphs. */
5207 int face_id
, lface_id
= 0 ;
5210 /* Handle control characters with ^. */
5212 if (it
->c
< 128 && it
->ctl_arrow_p
)
5214 g
= '^'; /* default glyph for Control */
5215 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5217 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5218 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5220 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5221 lface_id
= FAST_GLYPH_FACE (g
);
5225 g
= FAST_GLYPH_CHAR (g
);
5226 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5231 /* Merge the escape-glyph face into the current face. */
5232 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5236 XSETINT (it
->ctl_chars
[0], g
);
5238 XSETINT (it
->ctl_chars
[1], g
);
5240 goto display_control
;
5243 /* Handle non-break space in the mode where it only gets
5246 if (EQ (Vnobreak_char_display
, Qt
)
5249 /* Merge the no-break-space face into the current face. */
5250 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5254 XSETINT (it
->ctl_chars
[0], g
);
5256 goto display_control
;
5259 /* Handle sequences that start with the "escape glyph". */
5261 /* the default escape glyph is \. */
5262 escape_glyph
= '\\';
5265 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5266 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5268 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5269 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5273 /* The display table specified a face.
5274 Merge it into face_id and also into escape_glyph. */
5275 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5276 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5281 /* Merge the escape-glyph face into the current face. */
5282 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5286 /* Handle soft hyphens in the mode where they only get
5289 if (EQ (Vnobreak_char_display
, Qt
)
5293 XSETINT (it
->ctl_chars
[0], g
);
5295 goto display_control
;
5298 /* Handle non-break space and soft hyphen
5299 with the escape glyph. */
5301 if (it
->c
== 0xA0 || it
->c
== 0xAD)
5303 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5304 g
= it
->c
= (it
->c
== 0xA0 ? ' ' : '-');
5305 XSETINT (it
->ctl_chars
[1], g
);
5307 goto display_control
;
5311 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5315 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5316 if (CHAR_BYTE8_P (it
->c
))
5318 str
[0] = CHAR_TO_BYTE8 (it
->c
);
5321 else if (it
->c
< 256)
5328 /* It's an invalid character, which shouldn't
5329 happen actually, but due to bugs it may
5330 happen. Let's print the char as is, there's
5331 not much meaningful we can do with it. */
5333 str
[1] = it
->c
>> 8;
5334 str
[2] = it
->c
>> 16;
5335 str
[3] = it
->c
>> 24;
5339 for (i
= 0; i
< len
; i
++)
5341 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5342 /* Insert three more glyphs into IT->ctl_chars for
5343 the octal display of the character. */
5344 g
= ((str
[i
] >> 6) & 7) + '0';
5345 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5346 g
= ((str
[i
] >> 3) & 7) + '0';
5347 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5348 g
= (str
[i
] & 7) + '0';
5349 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5355 /* Set up IT->dpvec and return first character from it. */
5356 it
->dpvec_char_len
= it
->len
;
5357 it
->dpvec
= it
->ctl_chars
;
5358 it
->dpend
= it
->dpvec
+ ctl_len
;
5359 it
->current
.dpvec_index
= 0;
5360 it
->dpvec_face_id
= face_id
;
5361 it
->saved_face_id
= it
->face_id
;
5362 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5368 /* Adjust face id for a multibyte character. There are no
5369 multibyte character in unibyte text. */
5372 && FRAME_WINDOW_P (it
->f
))
5374 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5375 int pos
= (it
->s
? -1
5376 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
5377 : IT_CHARPOS (*it
));
5379 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
, pos
, it
->string
);
5383 /* Is this character the last one of a run of characters with
5384 box? If yes, set IT->end_of_box_run_p to 1. */
5391 it
->end_of_box_run_p
5392 = ((face_id
= face_after_it_pos (it
),
5393 face_id
!= it
->face_id
)
5394 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5395 face
->box
== FACE_NO_BOX
));
5398 /* Value is 0 if end of buffer or string reached. */
5403 /* Move IT to the next display element.
5405 RESEAT_P non-zero means if called on a newline in buffer text,
5406 skip to the next visible line start.
5408 Functions get_next_display_element and set_iterator_to_next are
5409 separate because I find this arrangement easier to handle than a
5410 get_next_display_element function that also increments IT's
5411 position. The way it is we can first look at an iterator's current
5412 display element, decide whether it fits on a line, and if it does,
5413 increment the iterator position. The other way around we probably
5414 would either need a flag indicating whether the iterator has to be
5415 incremented the next time, or we would have to implement a
5416 decrement position function which would not be easy to write. */
5419 set_iterator_to_next (it
, reseat_p
)
5423 /* Reset flags indicating start and end of a sequence of characters
5424 with box. Reset them at the start of this function because
5425 moving the iterator to a new position might set them. */
5426 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5430 case GET_FROM_BUFFER
:
5431 /* The current display element of IT is a character from
5432 current_buffer. Advance in the buffer, and maybe skip over
5433 invisible lines that are so because of selective display. */
5434 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5435 reseat_at_next_visible_line_start (it
, 0);
5438 xassert (it
->len
!= 0);
5439 IT_BYTEPOS (*it
) += it
->len
;
5440 IT_CHARPOS (*it
) += 1;
5441 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5445 case GET_FROM_COMPOSITION
:
5446 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5447 if (STRINGP (it
->string
))
5449 IT_STRING_BYTEPOS (*it
) += it
->len
;
5450 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5451 it
->method
= GET_FROM_STRING
;
5452 goto consider_string_end
;
5456 IT_BYTEPOS (*it
) += it
->len
;
5457 IT_CHARPOS (*it
) += it
->cmp_len
;
5458 it
->method
= GET_FROM_BUFFER
;
5462 case GET_FROM_C_STRING
:
5463 /* Current display element of IT is from a C string. */
5464 IT_BYTEPOS (*it
) += it
->len
;
5465 IT_CHARPOS (*it
) += 1;
5468 case GET_FROM_DISPLAY_VECTOR
:
5469 /* Current display element of IT is from a display table entry.
5470 Advance in the display table definition. Reset it to null if
5471 end reached, and continue with characters from buffers/
5473 ++it
->current
.dpvec_index
;
5475 /* Restore face of the iterator to what they were before the
5476 display vector entry (these entries may contain faces). */
5477 it
->face_id
= it
->saved_face_id
;
5479 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5482 it
->method
= GET_FROM_C_STRING
;
5483 else if (STRINGP (it
->string
))
5484 it
->method
= GET_FROM_STRING
;
5486 it
->method
= GET_FROM_BUFFER
;
5489 it
->current
.dpvec_index
= -1;
5491 /* Skip over characters which were displayed via IT->dpvec. */
5492 if (it
->dpvec_char_len
< 0)
5493 reseat_at_next_visible_line_start (it
, 1);
5494 else if (it
->dpvec_char_len
> 0)
5496 it
->len
= it
->dpvec_char_len
;
5497 set_iterator_to_next (it
, reseat_p
);
5500 /* Recheck faces after display vector */
5501 it
->stop_charpos
= IT_CHARPOS (*it
);
5505 case GET_FROM_STRING
:
5506 /* Current display element is a character from a Lisp string. */
5507 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5508 IT_STRING_BYTEPOS (*it
) += it
->len
;
5509 IT_STRING_CHARPOS (*it
) += 1;
5511 consider_string_end
:
5513 if (it
->current
.overlay_string_index
>= 0)
5515 /* IT->string is an overlay string. Advance to the
5516 next, if there is one. */
5517 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5518 next_overlay_string (it
);
5522 /* IT->string is not an overlay string. If we reached
5523 its end, and there is something on IT->stack, proceed
5524 with what is on the stack. This can be either another
5525 string, this time an overlay string, or a buffer. */
5526 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5530 if (STRINGP (it
->string
))
5531 goto consider_string_end
;
5532 it
->method
= GET_FROM_BUFFER
;
5537 case GET_FROM_IMAGE
:
5538 case GET_FROM_STRETCH
:
5539 /* The position etc with which we have to proceed are on
5540 the stack. The position may be at the end of a string,
5541 if the `display' property takes up the whole string. */
5542 xassert (it
->sp
> 0);
5545 if (STRINGP (it
->string
))
5547 it
->method
= GET_FROM_STRING
;
5548 goto consider_string_end
;
5550 it
->method
= GET_FROM_BUFFER
;
5554 /* There are no other methods defined, so this should be a bug. */
5558 xassert (it
->method
!= GET_FROM_STRING
5559 || (STRINGP (it
->string
)
5560 && IT_STRING_CHARPOS (*it
) >= 0));
5563 /* Load IT's display element fields with information about the next
5564 display element which comes from a display table entry or from the
5565 result of translating a control character to one of the forms `^C'
5568 IT->dpvec holds the glyphs to return as characters.
5569 IT->saved_face_id holds the face id before the display vector--
5570 it is restored into IT->face_idin set_iterator_to_next. */
5573 next_element_from_display_vector (it
)
5577 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5579 it
->face_id
= it
->saved_face_id
;
5581 if (INTEGERP (*it
->dpvec
)
5582 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5586 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5587 it
->c
= FAST_GLYPH_CHAR (g
);
5588 it
->len
= CHAR_BYTES (it
->c
);
5590 /* The entry may contain a face id to use. Such a face id is
5591 the id of a Lisp face, not a realized face. A face id of
5592 zero means no face is specified. */
5593 if (it
->dpvec_face_id
>= 0)
5594 it
->face_id
= it
->dpvec_face_id
;
5597 int lface_id
= FAST_GLYPH_FACE (g
);
5599 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5604 /* Display table entry is invalid. Return a space. */
5605 it
->c
= ' ', it
->len
= 1;
5607 /* Don't change position and object of the iterator here. They are
5608 still the values of the character that had this display table
5609 entry or was translated, and that's what we want. */
5610 it
->what
= IT_CHARACTER
;
5615 /* Load IT with the next display element from Lisp string IT->string.
5616 IT->current.string_pos is the current position within the string.
5617 If IT->current.overlay_string_index >= 0, the Lisp string is an
5621 next_element_from_string (it
)
5624 struct text_pos position
;
5626 xassert (STRINGP (it
->string
));
5627 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5628 position
= it
->current
.string_pos
;
5630 /* Time to check for invisible text? */
5631 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5632 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5636 /* Since a handler may have changed IT->method, we must
5638 return get_next_display_element (it
);
5641 if (it
->current
.overlay_string_index
>= 0)
5643 /* Get the next character from an overlay string. In overlay
5644 strings, There is no field width or padding with spaces to
5646 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5651 else if (STRING_MULTIBYTE (it
->string
))
5653 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5654 const unsigned char *s
= (SDATA (it
->string
)
5655 + IT_STRING_BYTEPOS (*it
));
5656 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5660 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5666 /* Get the next character from a Lisp string that is not an
5667 overlay string. Such strings come from the mode line, for
5668 example. We may have to pad with spaces, or truncate the
5669 string. See also next_element_from_c_string. */
5670 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5675 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5677 /* Pad with spaces. */
5678 it
->c
= ' ', it
->len
= 1;
5679 CHARPOS (position
) = BYTEPOS (position
) = -1;
5681 else if (STRING_MULTIBYTE (it
->string
))
5683 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5684 const unsigned char *s
= (SDATA (it
->string
)
5685 + IT_STRING_BYTEPOS (*it
));
5686 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5690 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5695 /* Record what we have and where it came from. Note that we store a
5696 buffer position in IT->position although it could arguably be a
5698 it
->what
= IT_CHARACTER
;
5699 it
->object
= it
->string
;
5700 it
->position
= position
;
5705 /* Load IT with next display element from C string IT->s.
5706 IT->string_nchars is the maximum number of characters to return
5707 from the string. IT->end_charpos may be greater than
5708 IT->string_nchars when this function is called, in which case we
5709 may have to return padding spaces. Value is zero if end of string
5710 reached, including padding spaces. */
5713 next_element_from_c_string (it
)
5719 it
->what
= IT_CHARACTER
;
5720 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5723 /* IT's position can be greater IT->string_nchars in case a field
5724 width or precision has been specified when the iterator was
5726 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5728 /* End of the game. */
5732 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5734 /* Pad with spaces. */
5735 it
->c
= ' ', it
->len
= 1;
5736 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5738 else if (it
->multibyte_p
)
5740 /* Implementation note: The calls to strlen apparently aren't a
5741 performance problem because there is no noticeable performance
5742 difference between Emacs running in unibyte or multibyte mode. */
5743 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5744 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5748 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5754 /* Set up IT to return characters from an ellipsis, if appropriate.
5755 The definition of the ellipsis glyphs may come from a display table
5756 entry. This function Fills IT with the first glyph from the
5757 ellipsis if an ellipsis is to be displayed. */
5760 next_element_from_ellipsis (it
)
5763 if (it
->selective_display_ellipsis_p
)
5764 setup_for_ellipsis (it
, it
->len
);
5767 /* The face at the current position may be different from the
5768 face we find after the invisible text. Remember what it
5769 was in IT->saved_face_id, and signal that it's there by
5770 setting face_before_selective_p. */
5771 it
->saved_face_id
= it
->face_id
;
5772 it
->method
= GET_FROM_BUFFER
;
5773 reseat_at_next_visible_line_start (it
, 1);
5774 it
->face_before_selective_p
= 1;
5777 return get_next_display_element (it
);
5781 /* Deliver an image display element. The iterator IT is already
5782 filled with image information (done in handle_display_prop). Value
5787 next_element_from_image (it
)
5790 it
->what
= IT_IMAGE
;
5795 /* Fill iterator IT with next display element from a stretch glyph
5796 property. IT->object is the value of the text property. Value is
5800 next_element_from_stretch (it
)
5803 it
->what
= IT_STRETCH
;
5808 /* Load IT with the next display element from current_buffer. Value
5809 is zero if end of buffer reached. IT->stop_charpos is the next
5810 position at which to stop and check for text properties or buffer
5814 next_element_from_buffer (it
)
5819 /* Check this assumption, otherwise, we would never enter the
5820 if-statement, below. */
5821 xassert (IT_CHARPOS (*it
) >= BEGV
5822 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
5824 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
5826 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5828 int overlay_strings_follow_p
;
5830 /* End of the game, except when overlay strings follow that
5831 haven't been returned yet. */
5832 if (it
->overlay_strings_at_end_processed_p
)
5833 overlay_strings_follow_p
= 0;
5836 it
->overlay_strings_at_end_processed_p
= 1;
5837 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
5840 if (overlay_strings_follow_p
)
5841 success_p
= get_next_display_element (it
);
5845 it
->position
= it
->current
.pos
;
5852 return get_next_display_element (it
);
5857 /* No face changes, overlays etc. in sight, so just return a
5858 character from current_buffer. */
5861 /* Maybe run the redisplay end trigger hook. Performance note:
5862 This doesn't seem to cost measurable time. */
5863 if (it
->redisplay_end_trigger_charpos
5865 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
5866 run_redisplay_end_trigger_hook (it
);
5868 /* Get the next character, maybe multibyte. */
5869 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
5870 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
5872 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
5873 - IT_BYTEPOS (*it
));
5874 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
5877 it
->c
= *p
, it
->len
= 1;
5879 /* Record what we have and where it came from. */
5880 it
->what
= IT_CHARACTER
;;
5881 it
->object
= it
->w
->buffer
;
5882 it
->position
= it
->current
.pos
;
5884 /* Normally we return the character found above, except when we
5885 really want to return an ellipsis for selective display. */
5890 /* A value of selective > 0 means hide lines indented more
5891 than that number of columns. */
5892 if (it
->selective
> 0
5893 && IT_CHARPOS (*it
) + 1 < ZV
5894 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
5895 IT_BYTEPOS (*it
) + 1,
5896 (double) it
->selective
)) /* iftc */
5898 success_p
= next_element_from_ellipsis (it
);
5899 it
->dpvec_char_len
= -1;
5902 else if (it
->c
== '\r' && it
->selective
== -1)
5904 /* A value of selective == -1 means that everything from the
5905 CR to the end of the line is invisible, with maybe an
5906 ellipsis displayed for it. */
5907 success_p
= next_element_from_ellipsis (it
);
5908 it
->dpvec_char_len
= -1;
5913 /* Value is zero if end of buffer reached. */
5914 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
5919 /* Run the redisplay end trigger hook for IT. */
5922 run_redisplay_end_trigger_hook (it
)
5925 Lisp_Object args
[3];
5927 /* IT->glyph_row should be non-null, i.e. we should be actually
5928 displaying something, or otherwise we should not run the hook. */
5929 xassert (it
->glyph_row
);
5931 /* Set up hook arguments. */
5932 args
[0] = Qredisplay_end_trigger_functions
;
5933 args
[1] = it
->window
;
5934 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
5935 it
->redisplay_end_trigger_charpos
= 0;
5937 /* Since we are *trying* to run these functions, don't try to run
5938 them again, even if they get an error. */
5939 it
->w
->redisplay_end_trigger
= Qnil
;
5940 Frun_hook_with_args (3, args
);
5942 /* Notice if it changed the face of the character we are on. */
5943 handle_face_prop (it
);
5947 /* Deliver a composition display element. The iterator IT is already
5948 filled with composition information (done in
5949 handle_composition_prop). Value is always 1. */
5952 next_element_from_composition (it
)
5955 it
->what
= IT_COMPOSITION
;
5956 it
->position
= (STRINGP (it
->string
)
5957 ? it
->current
.string_pos
5964 /***********************************************************************
5965 Moving an iterator without producing glyphs
5966 ***********************************************************************/
5968 /* Move iterator IT to a specified buffer or X position within one
5969 line on the display without producing glyphs.
5971 OP should be a bit mask including some or all of these bits:
5972 MOVE_TO_X: Stop on reaching x-position TO_X.
5973 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5974 Regardless of OP's value, stop in reaching the end of the display line.
5976 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5977 This means, in particular, that TO_X includes window's horizontal
5980 The return value has several possible values that
5981 say what condition caused the scan to stop:
5983 MOVE_POS_MATCH_OR_ZV
5984 - when TO_POS or ZV was reached.
5987 -when TO_X was reached before TO_POS or ZV were reached.
5990 - when we reached the end of the display area and the line must
5994 - when we reached the end of the display area and the line is
5998 - when we stopped at a line end, i.e. a newline or a CR and selective
6001 static enum move_it_result
6002 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
6004 int to_charpos
, to_x
, op
;
6006 enum move_it_result result
= MOVE_UNDEFINED
;
6007 struct glyph_row
*saved_glyph_row
;
6009 /* Don't produce glyphs in produce_glyphs. */
6010 saved_glyph_row
= it
->glyph_row
;
6011 it
->glyph_row
= NULL
;
6013 #define BUFFER_POS_REACHED_P() \
6014 ((op & MOVE_TO_POS) != 0 \
6015 && BUFFERP (it->object) \
6016 && IT_CHARPOS (*it) >= to_charpos \
6017 && (it->method == GET_FROM_BUFFER \
6018 || (it->method == GET_FROM_DISPLAY_VECTOR \
6019 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6024 int x
, i
, ascent
= 0, descent
= 0;
6026 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
6027 if ((op
& MOVE_TO_POS
) != 0
6028 && BUFFERP (it
->object
)
6029 && it
->method
== GET_FROM_BUFFER
6030 && IT_CHARPOS (*it
) > to_charpos
)
6032 result
= MOVE_POS_MATCH_OR_ZV
;
6036 /* Stop when ZV reached.
6037 We used to stop here when TO_CHARPOS reached as well, but that is
6038 too soon if this glyph does not fit on this line. So we handle it
6039 explicitly below. */
6040 if (!get_next_display_element (it
)
6041 || (it
->truncate_lines_p
6042 && BUFFER_POS_REACHED_P ()))
6044 result
= MOVE_POS_MATCH_OR_ZV
;
6048 /* The call to produce_glyphs will get the metrics of the
6049 display element IT is loaded with. We record in x the
6050 x-position before this display element in case it does not
6054 /* Remember the line height so far in case the next element doesn't
6056 if (!it
->truncate_lines_p
)
6058 ascent
= it
->max_ascent
;
6059 descent
= it
->max_descent
;
6062 PRODUCE_GLYPHS (it
);
6064 if (it
->area
!= TEXT_AREA
)
6066 set_iterator_to_next (it
, 1);
6070 /* The number of glyphs we get back in IT->nglyphs will normally
6071 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6072 character on a terminal frame, or (iii) a line end. For the
6073 second case, IT->nglyphs - 1 padding glyphs will be present
6074 (on X frames, there is only one glyph produced for a
6075 composite character.
6077 The behavior implemented below means, for continuation lines,
6078 that as many spaces of a TAB as fit on the current line are
6079 displayed there. For terminal frames, as many glyphs of a
6080 multi-glyph character are displayed in the current line, too.
6081 This is what the old redisplay code did, and we keep it that
6082 way. Under X, the whole shape of a complex character must
6083 fit on the line or it will be completely displayed in the
6086 Note that both for tabs and padding glyphs, all glyphs have
6090 /* More than one glyph or glyph doesn't fit on line. All
6091 glyphs have the same width. */
6092 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6095 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6097 new_x
= x
+ single_glyph_width
;
6099 /* We want to leave anything reaching TO_X to the caller. */
6100 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6102 if (BUFFER_POS_REACHED_P ())
6103 goto buffer_pos_reached
;
6105 result
= MOVE_X_REACHED
;
6108 else if (/* Lines are continued. */
6109 !it
->truncate_lines_p
6110 && (/* And glyph doesn't fit on the line. */
6111 new_x
> it
->last_visible_x
6112 /* Or it fits exactly and we're on a window
6114 || (new_x
== it
->last_visible_x
6115 && FRAME_WINDOW_P (it
->f
))))
6117 if (/* IT->hpos == 0 means the very first glyph
6118 doesn't fit on the line, e.g. a wide image. */
6120 || (new_x
== it
->last_visible_x
6121 && FRAME_WINDOW_P (it
->f
)))
6124 it
->current_x
= new_x
;
6125 if (i
== it
->nglyphs
- 1)
6127 set_iterator_to_next (it
, 1);
6128 #ifdef HAVE_WINDOW_SYSTEM
6129 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6131 if (!get_next_display_element (it
))
6133 result
= MOVE_POS_MATCH_OR_ZV
;
6136 if (BUFFER_POS_REACHED_P ())
6138 if (ITERATOR_AT_END_OF_LINE_P (it
))
6139 result
= MOVE_POS_MATCH_OR_ZV
;
6141 result
= MOVE_LINE_CONTINUED
;
6144 if (ITERATOR_AT_END_OF_LINE_P (it
))
6146 result
= MOVE_NEWLINE_OR_CR
;
6150 #endif /* HAVE_WINDOW_SYSTEM */
6156 it
->max_ascent
= ascent
;
6157 it
->max_descent
= descent
;
6160 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6162 result
= MOVE_LINE_CONTINUED
;
6165 else if (BUFFER_POS_REACHED_P ())
6166 goto buffer_pos_reached
;
6167 else if (new_x
> it
->first_visible_x
)
6169 /* Glyph is visible. Increment number of glyphs that
6170 would be displayed. */
6175 /* Glyph is completely off the left margin of the display
6176 area. Nothing to do. */
6180 if (result
!= MOVE_UNDEFINED
)
6183 else if (BUFFER_POS_REACHED_P ())
6187 it
->max_ascent
= ascent
;
6188 it
->max_descent
= descent
;
6189 result
= MOVE_POS_MATCH_OR_ZV
;
6192 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6194 /* Stop when TO_X specified and reached. This check is
6195 necessary here because of lines consisting of a line end,
6196 only. The line end will not produce any glyphs and we
6197 would never get MOVE_X_REACHED. */
6198 xassert (it
->nglyphs
== 0);
6199 result
= MOVE_X_REACHED
;
6203 /* Is this a line end? If yes, we're done. */
6204 if (ITERATOR_AT_END_OF_LINE_P (it
))
6206 result
= MOVE_NEWLINE_OR_CR
;
6210 /* The current display element has been consumed. Advance
6212 set_iterator_to_next (it
, 1);
6214 /* Stop if lines are truncated and IT's current x-position is
6215 past the right edge of the window now. */
6216 if (it
->truncate_lines_p
6217 && it
->current_x
>= it
->last_visible_x
)
6219 #ifdef HAVE_WINDOW_SYSTEM
6220 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6222 if (!get_next_display_element (it
)
6223 || BUFFER_POS_REACHED_P ())
6225 result
= MOVE_POS_MATCH_OR_ZV
;
6228 if (ITERATOR_AT_END_OF_LINE_P (it
))
6230 result
= MOVE_NEWLINE_OR_CR
;
6234 #endif /* HAVE_WINDOW_SYSTEM */
6235 result
= MOVE_LINE_TRUNCATED
;
6240 #undef BUFFER_POS_REACHED_P
6242 /* Restore the iterator settings altered at the beginning of this
6244 it
->glyph_row
= saved_glyph_row
;
6249 /* Move IT forward until it satisfies one or more of the criteria in
6250 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6252 OP is a bit-mask that specifies where to stop, and in particular,
6253 which of those four position arguments makes a difference. See the
6254 description of enum move_operation_enum.
6256 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6257 screen line, this function will set IT to the next position >
6261 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6263 int to_charpos
, to_x
, to_y
, to_vpos
;
6266 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6272 if (op
& MOVE_TO_VPOS
)
6274 /* If no TO_CHARPOS and no TO_X specified, stop at the
6275 start of the line TO_VPOS. */
6276 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6278 if (it
->vpos
== to_vpos
)
6284 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6288 /* TO_VPOS >= 0 means stop at TO_X in the line at
6289 TO_VPOS, or at TO_POS, whichever comes first. */
6290 if (it
->vpos
== to_vpos
)
6296 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6298 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6303 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6305 /* We have reached TO_X but not in the line we want. */
6306 skip
= move_it_in_display_line_to (it
, to_charpos
,
6308 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6316 else if (op
& MOVE_TO_Y
)
6318 struct it it_backup
;
6320 /* TO_Y specified means stop at TO_X in the line containing
6321 TO_Y---or at TO_CHARPOS if this is reached first. The
6322 problem is that we can't really tell whether the line
6323 contains TO_Y before we have completely scanned it, and
6324 this may skip past TO_X. What we do is to first scan to
6327 If TO_X is not specified, use a TO_X of zero. The reason
6328 is to make the outcome of this function more predictable.
6329 If we didn't use TO_X == 0, we would stop at the end of
6330 the line which is probably not what a caller would expect
6332 skip
= move_it_in_display_line_to (it
, to_charpos
,
6336 | (op
& MOVE_TO_POS
)));
6338 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6339 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6345 /* If TO_X was reached, we would like to know whether TO_Y
6346 is in the line. This can only be said if we know the
6347 total line height which requires us to scan the rest of
6349 if (skip
== MOVE_X_REACHED
)
6351 /* Wait! We can conclude that TO_Y is in the line if
6352 the already scanned glyphs make the line tall enough
6353 because further scanning doesn't make it shorter. */
6354 line_height
= it
->max_ascent
+ it
->max_descent
;
6355 if (to_y
>= it
->current_y
6356 && to_y
< it
->current_y
+ line_height
)
6362 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6363 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6365 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6368 /* Now, decide whether TO_Y is in this line. */
6369 line_height
= it
->max_ascent
+ it
->max_descent
;
6370 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6372 if (to_y
>= it
->current_y
6373 && to_y
< it
->current_y
+ line_height
)
6375 if (skip
== MOVE_X_REACHED
)
6376 /* If TO_Y is in this line and TO_X was reached above,
6377 we scanned too far. We have to restore IT's settings
6378 to the ones before skipping. */
6382 else if (skip
== MOVE_X_REACHED
)
6385 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6393 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6397 case MOVE_POS_MATCH_OR_ZV
:
6401 case MOVE_NEWLINE_OR_CR
:
6402 set_iterator_to_next (it
, 1);
6403 it
->continuation_lines_width
= 0;
6406 case MOVE_LINE_TRUNCATED
:
6407 it
->continuation_lines_width
= 0;
6408 reseat_at_next_visible_line_start (it
, 0);
6409 if ((op
& MOVE_TO_POS
) != 0
6410 && IT_CHARPOS (*it
) > to_charpos
)
6417 case MOVE_LINE_CONTINUED
:
6418 it
->continuation_lines_width
+= it
->current_x
;
6425 /* Reset/increment for the next run. */
6426 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6427 it
->current_x
= it
->hpos
= 0;
6428 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6430 last_height
= it
->max_ascent
+ it
->max_descent
;
6431 last_max_ascent
= it
->max_ascent
;
6432 it
->max_ascent
= it
->max_descent
= 0;
6437 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6441 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6443 If DY > 0, move IT backward at least that many pixels. DY = 0
6444 means move IT backward to the preceding line start or BEGV. This
6445 function may move over more than DY pixels if IT->current_y - DY
6446 ends up in the middle of a line; in this case IT->current_y will be
6447 set to the top of the line moved to. */
6450 move_it_vertically_backward (it
, dy
)
6461 start_pos
= IT_CHARPOS (*it
);
6463 /* Estimate how many newlines we must move back. */
6464 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6466 /* Set the iterator's position that many lines back. */
6467 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6468 back_to_previous_visible_line_start (it
);
6470 /* Reseat the iterator here. When moving backward, we don't want
6471 reseat to skip forward over invisible text, set up the iterator
6472 to deliver from overlay strings at the new position etc. So,
6473 use reseat_1 here. */
6474 reseat_1 (it
, it
->current
.pos
, 1);
6476 /* We are now surely at a line start. */
6477 it
->current_x
= it
->hpos
= 0;
6478 it
->continuation_lines_width
= 0;
6480 /* Move forward and see what y-distance we moved. First move to the
6481 start of the next line so that we get its height. We need this
6482 height to be able to tell whether we reached the specified
6485 it2
.max_ascent
= it2
.max_descent
= 0;
6486 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6487 MOVE_TO_POS
| MOVE_TO_VPOS
);
6488 xassert (IT_CHARPOS (*it
) >= BEGV
);
6491 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6492 xassert (IT_CHARPOS (*it
) >= BEGV
);
6493 /* H is the actual vertical distance from the position in *IT
6494 and the starting position. */
6495 h
= it2
.current_y
- it
->current_y
;
6496 /* NLINES is the distance in number of lines. */
6497 nlines
= it2
.vpos
- it
->vpos
;
6499 /* Correct IT's y and vpos position
6500 so that they are relative to the starting point. */
6506 /* DY == 0 means move to the start of the screen line. The
6507 value of nlines is > 0 if continuation lines were involved. */
6509 move_it_by_lines (it
, nlines
, 1);
6511 /* I think this assert is bogus if buffer contains
6512 invisible text or images. KFS. */
6513 xassert (IT_CHARPOS (*it
) <= start_pos
);
6518 /* The y-position we try to reach, relative to *IT.
6519 Note that H has been subtracted in front of the if-statement. */
6520 int target_y
= it
->current_y
+ h
- dy
;
6521 int y0
= it3
.current_y
;
6522 int y1
= line_bottom_y (&it3
);
6523 int line_height
= y1
- y0
;
6525 /* If we did not reach target_y, try to move further backward if
6526 we can. If we moved too far backward, try to move forward. */
6527 if (target_y
< it
->current_y
6528 /* This is heuristic. In a window that's 3 lines high, with
6529 a line height of 13 pixels each, recentering with point
6530 on the bottom line will try to move -39/2 = 19 pixels
6531 backward. Try to avoid moving into the first line. */
6532 && (it
->current_y
- target_y
6533 > min (window_box_height (it
->w
), line_height
* 2 / 3))
6534 && IT_CHARPOS (*it
) > BEGV
)
6536 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6537 target_y
- it
->current_y
));
6538 dy
= it
->current_y
- target_y
;
6539 goto move_further_back
;
6541 else if (target_y
>= it
->current_y
+ line_height
6542 && IT_CHARPOS (*it
) < ZV
)
6544 /* Should move forward by at least one line, maybe more.
6546 Note: Calling move_it_by_lines can be expensive on
6547 terminal frames, where compute_motion is used (via
6548 vmotion) to do the job, when there are very long lines
6549 and truncate-lines is nil. That's the reason for
6550 treating terminal frames specially here. */
6552 if (!FRAME_WINDOW_P (it
->f
))
6553 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6558 move_it_by_lines (it
, 1, 1);
6560 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6564 /* I think this assert is bogus if buffer contains
6565 invisible text or images. KFS. */
6566 xassert (IT_CHARPOS (*it
) >= BEGV
);
6573 /* Move IT by a specified amount of pixel lines DY. DY negative means
6574 move backwards. DY = 0 means move to start of screen line. At the
6575 end, IT will be on the start of a screen line. */
6578 move_it_vertically (it
, dy
)
6583 move_it_vertically_backward (it
, -dy
);
6586 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6587 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6588 MOVE_TO_POS
| MOVE_TO_Y
);
6589 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6591 /* If buffer ends in ZV without a newline, move to the start of
6592 the line to satisfy the post-condition. */
6593 if (IT_CHARPOS (*it
) == ZV
6594 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6595 move_it_by_lines (it
, 0, 0);
6600 /* Move iterator IT past the end of the text line it is in. */
6603 move_it_past_eol (it
)
6606 enum move_it_result rc
;
6608 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6609 if (rc
== MOVE_NEWLINE_OR_CR
)
6610 set_iterator_to_next (it
, 0);
6614 #if 0 /* Currently not used. */
6616 /* Return non-zero if some text between buffer positions START_CHARPOS
6617 and END_CHARPOS is invisible. IT->window is the window for text
6621 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6623 int start_charpos
, end_charpos
;
6625 Lisp_Object prop
, limit
;
6626 int invisible_found_p
;
6628 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6630 /* Is text at START invisible? */
6631 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6633 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6634 invisible_found_p
= 1;
6637 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6639 make_number (end_charpos
));
6640 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6643 return invisible_found_p
;
6649 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6650 negative means move up. DVPOS == 0 means move to the start of the
6651 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6652 NEED_Y_P is zero, IT->current_y will be left unchanged.
6654 Further optimization ideas: If we would know that IT->f doesn't use
6655 a face with proportional font, we could be faster for
6656 truncate-lines nil. */
6659 move_it_by_lines (it
, dvpos
, need_y_p
)
6661 int dvpos
, need_y_p
;
6663 struct position pos
;
6665 if (!FRAME_WINDOW_P (it
->f
))
6667 struct text_pos textpos
;
6669 /* We can use vmotion on frames without proportional fonts. */
6670 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6671 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6672 reseat (it
, textpos
, 1);
6673 it
->vpos
+= pos
.vpos
;
6674 it
->current_y
+= pos
.vpos
;
6676 else if (dvpos
== 0)
6678 /* DVPOS == 0 means move to the start of the screen line. */
6679 move_it_vertically_backward (it
, 0);
6680 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6681 /* Let next call to line_bottom_y calculate real line height */
6685 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6689 int start_charpos
, i
;
6691 /* Start at the beginning of the screen line containing IT's
6693 move_it_vertically_backward (it
, 0);
6695 /* Go back -DVPOS visible lines and reseat the iterator there. */
6696 start_charpos
= IT_CHARPOS (*it
);
6697 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
6698 back_to_previous_visible_line_start (it
);
6699 reseat (it
, it
->current
.pos
, 1);
6700 it
->current_x
= it
->hpos
= 0;
6702 /* Above call may have moved too far if continuation lines
6703 are involved. Scan forward and see if it did. */
6705 it2
.vpos
= it2
.current_y
= 0;
6706 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6707 it
->vpos
-= it2
.vpos
;
6708 it
->current_y
-= it2
.current_y
;
6709 it
->current_x
= it
->hpos
= 0;
6711 /* If we moved too far back, move IT some lines forward. */
6712 if (it2
.vpos
> -dvpos
)
6714 int delta
= it2
.vpos
+ dvpos
;
6716 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6717 /* Move back again if we got too far ahead. */
6718 if (IT_CHARPOS (*it
) >= start_charpos
)
6724 /* Return 1 if IT points into the middle of a display vector. */
6727 in_display_vector_p (it
)
6730 return (it
->method
== GET_FROM_DISPLAY_VECTOR
6731 && it
->current
.dpvec_index
> 0
6732 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6736 /***********************************************************************
6738 ***********************************************************************/
6741 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6745 add_to_log (format
, arg1
, arg2
)
6747 Lisp_Object arg1
, arg2
;
6749 Lisp_Object args
[3];
6750 Lisp_Object msg
, fmt
;
6753 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6756 /* Do nothing if called asynchronously. Inserting text into
6757 a buffer may call after-change-functions and alike and
6758 that would means running Lisp asynchronously. */
6759 if (handling_signal
)
6763 GCPRO4 (fmt
, msg
, arg1
, arg2
);
6765 args
[0] = fmt
= build_string (format
);
6768 msg
= Fformat (3, args
);
6770 len
= SBYTES (msg
) + 1;
6771 SAFE_ALLOCA (buffer
, char *, len
);
6772 bcopy (SDATA (msg
), buffer
, len
);
6774 message_dolog (buffer
, len
- 1, 1, 0);
6781 /* Output a newline in the *Messages* buffer if "needs" one. */
6784 message_log_maybe_newline ()
6786 if (message_log_need_newline
)
6787 message_dolog ("", 0, 1, 0);
6791 /* Add a string M of length NBYTES to the message log, optionally
6792 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
6793 nonzero, means interpret the contents of M as multibyte. This
6794 function calls low-level routines in order to bypass text property
6795 hooks, etc. which might not be safe to run. */
6798 message_dolog (m
, nbytes
, nlflag
, multibyte
)
6800 int nbytes
, nlflag
, multibyte
;
6802 if (!NILP (Vmemory_full
))
6805 if (!NILP (Vmessage_log_max
))
6807 struct buffer
*oldbuf
;
6808 Lisp_Object oldpoint
, oldbegv
, oldzv
;
6809 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6810 int point_at_end
= 0;
6812 Lisp_Object old_deactivate_mark
, tem
;
6813 struct gcpro gcpro1
;
6815 old_deactivate_mark
= Vdeactivate_mark
;
6816 oldbuf
= current_buffer
;
6817 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
6818 current_buffer
->undo_list
= Qt
;
6820 oldpoint
= message_dolog_marker1
;
6821 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
6822 oldbegv
= message_dolog_marker2
;
6823 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
6824 oldzv
= message_dolog_marker3
;
6825 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
6826 GCPRO1 (old_deactivate_mark
);
6834 BEGV_BYTE
= BEG_BYTE
;
6837 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6839 /* Insert the string--maybe converting multibyte to single byte
6840 or vice versa, so that all the text fits the buffer. */
6842 && NILP (current_buffer
->enable_multibyte_characters
))
6844 int i
, c
, char_bytes
;
6845 unsigned char work
[1];
6847 /* Convert a multibyte string to single-byte
6848 for the *Message* buffer. */
6849 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
6851 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
6852 work
[0] = (ASCII_CHAR_P (c
)
6854 : multibyte_char_to_unibyte (c
, Qnil
));
6855 insert_1_both (work
, 1, 1, 1, 0, 0);
6858 else if (! multibyte
6859 && ! NILP (current_buffer
->enable_multibyte_characters
))
6861 int i
, c
, char_bytes
;
6862 unsigned char *msg
= (unsigned char *) m
;
6863 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6864 /* Convert a single-byte string to multibyte
6865 for the *Message* buffer. */
6866 for (i
= 0; i
< nbytes
; i
++)
6869 c
= unibyte_char_to_multibyte (c
);
6870 char_bytes
= CHAR_STRING (c
, str
);
6871 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
6875 insert_1 (m
, nbytes
, 1, 0, 0);
6879 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
6880 insert_1 ("\n", 1, 1, 0, 0);
6882 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6884 this_bol_byte
= PT_BYTE
;
6886 /* See if this line duplicates the previous one.
6887 If so, combine duplicates. */
6890 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6892 prev_bol_byte
= PT_BYTE
;
6894 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
6895 this_bol
, this_bol_byte
);
6898 del_range_both (prev_bol
, prev_bol_byte
,
6899 this_bol
, this_bol_byte
, 0);
6905 /* If you change this format, don't forget to also
6906 change message_log_check_duplicate. */
6907 sprintf (dupstr
, " [%d times]", dup
);
6908 duplen
= strlen (dupstr
);
6909 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
6910 insert_1 (dupstr
, duplen
, 1, 0, 1);
6915 /* If we have more than the desired maximum number of lines
6916 in the *Messages* buffer now, delete the oldest ones.
6917 This is safe because we don't have undo in this buffer. */
6919 if (NATNUMP (Vmessage_log_max
))
6921 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
6922 -XFASTINT (Vmessage_log_max
) - 1, 0);
6923 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
6926 BEGV
= XMARKER (oldbegv
)->charpos
;
6927 BEGV_BYTE
= marker_byte_position (oldbegv
);
6936 ZV
= XMARKER (oldzv
)->charpos
;
6937 ZV_BYTE
= marker_byte_position (oldzv
);
6941 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6943 /* We can't do Fgoto_char (oldpoint) because it will run some
6945 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
6946 XMARKER (oldpoint
)->bytepos
);
6949 unchain_marker (XMARKER (oldpoint
));
6950 unchain_marker (XMARKER (oldbegv
));
6951 unchain_marker (XMARKER (oldzv
));
6953 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
6954 set_buffer_internal (oldbuf
);
6956 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6957 message_log_need_newline
= !nlflag
;
6958 Vdeactivate_mark
= old_deactivate_mark
;
6963 /* We are at the end of the buffer after just having inserted a newline.
6964 (Note: We depend on the fact we won't be crossing the gap.)
6965 Check to see if the most recent message looks a lot like the previous one.
6966 Return 0 if different, 1 if the new one should just replace it, or a
6967 value N > 1 if we should also append " [N times]". */
6970 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
6971 int prev_bol
, this_bol
;
6972 int prev_bol_byte
, this_bol_byte
;
6975 int len
= Z_BYTE
- 1 - this_bol_byte
;
6977 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
6978 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
6980 for (i
= 0; i
< len
; i
++)
6982 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
6990 if (*p1
++ == ' ' && *p1
++ == '[')
6993 while (*p1
>= '0' && *p1
<= '9')
6994 n
= n
* 10 + *p1
++ - '0';
6995 if (strncmp (p1
, " times]\n", 8) == 0)
7002 /* Display an echo area message M with a specified length of NBYTES
7003 bytes. The string may include null characters. If M is 0, clear
7004 out any existing message, and let the mini-buffer text show
7007 The buffer M must continue to exist until after the echo area gets
7008 cleared or some other message gets displayed there. This means do
7009 not pass text that is stored in a Lisp string; do not pass text in
7010 a buffer that was alloca'd. */
7013 message2 (m
, nbytes
, multibyte
)
7018 /* First flush out any partial line written with print. */
7019 message_log_maybe_newline ();
7021 message_dolog (m
, nbytes
, 1, multibyte
);
7022 message2_nolog (m
, nbytes
, multibyte
);
7026 /* The non-logging counterpart of message2. */
7029 message2_nolog (m
, nbytes
, multibyte
)
7031 int nbytes
, multibyte
;
7033 struct frame
*sf
= SELECTED_FRAME ();
7034 message_enable_multibyte
= multibyte
;
7038 if (noninteractive_need_newline
)
7039 putc ('\n', stderr
);
7040 noninteractive_need_newline
= 0;
7042 fwrite (m
, nbytes
, 1, stderr
);
7043 if (cursor_in_echo_area
== 0)
7044 fprintf (stderr
, "\n");
7047 /* A null message buffer means that the frame hasn't really been
7048 initialized yet. Error messages get reported properly by
7049 cmd_error, so this must be just an informative message; toss it. */
7050 else if (INTERACTIVE
7051 && sf
->glyphs_initialized_p
7052 && FRAME_MESSAGE_BUF (sf
))
7054 Lisp_Object mini_window
;
7057 /* Get the frame containing the mini-buffer
7058 that the selected frame is using. */
7059 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7060 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7062 FRAME_SAMPLE_VISIBILITY (f
);
7063 if (FRAME_VISIBLE_P (sf
)
7064 && ! FRAME_VISIBLE_P (f
))
7065 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7069 set_message (m
, Qnil
, nbytes
, multibyte
);
7070 if (minibuffer_auto_raise
)
7071 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7074 clear_message (1, 1);
7076 do_pending_window_change (0);
7077 echo_area_display (1);
7078 do_pending_window_change (0);
7079 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7080 (*frame_up_to_date_hook
) (f
);
7085 /* Display an echo area message M with a specified length of NBYTES
7086 bytes. The string may include null characters. If M is not a
7087 string, clear out any existing message, and let the mini-buffer
7090 This function cancels echoing. */
7093 message3 (m
, nbytes
, multibyte
)
7098 struct gcpro gcpro1
;
7101 clear_message (1,1);
7104 /* First flush out any partial line written with print. */
7105 message_log_maybe_newline ();
7107 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
7108 message3_nolog (m
, nbytes
, multibyte
);
7114 /* The non-logging version of message3.
7115 This does not cancel echoing, because it is used for echoing.
7116 Perhaps we need to make a separate function for echoing
7117 and make this cancel echoing. */
7120 message3_nolog (m
, nbytes
, multibyte
)
7122 int nbytes
, multibyte
;
7124 struct frame
*sf
= SELECTED_FRAME ();
7125 message_enable_multibyte
= multibyte
;
7129 if (noninteractive_need_newline
)
7130 putc ('\n', stderr
);
7131 noninteractive_need_newline
= 0;
7133 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7134 if (cursor_in_echo_area
== 0)
7135 fprintf (stderr
, "\n");
7138 /* A null message buffer means that the frame hasn't really been
7139 initialized yet. Error messages get reported properly by
7140 cmd_error, so this must be just an informative message; toss it. */
7141 else if (INTERACTIVE
7142 && sf
->glyphs_initialized_p
7143 && FRAME_MESSAGE_BUF (sf
))
7145 Lisp_Object mini_window
;
7149 /* Get the frame containing the mini-buffer
7150 that the selected frame is using. */
7151 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7152 frame
= XWINDOW (mini_window
)->frame
;
7155 FRAME_SAMPLE_VISIBILITY (f
);
7156 if (FRAME_VISIBLE_P (sf
)
7157 && !FRAME_VISIBLE_P (f
))
7158 Fmake_frame_visible (frame
);
7160 if (STRINGP (m
) && SCHARS (m
) > 0)
7162 set_message (NULL
, m
, nbytes
, multibyte
);
7163 if (minibuffer_auto_raise
)
7164 Fraise_frame (frame
);
7167 clear_message (1, 1);
7169 do_pending_window_change (0);
7170 echo_area_display (1);
7171 do_pending_window_change (0);
7172 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7173 (*frame_up_to_date_hook
) (f
);
7178 /* Display a null-terminated echo area message M. If M is 0, clear
7179 out any existing message, and let the mini-buffer text show through.
7181 The buffer M must continue to exist until after the echo area gets
7182 cleared or some other message gets displayed there. Do not pass
7183 text that is stored in a Lisp string. Do not pass text in a buffer
7184 that was alloca'd. */
7190 message2 (m
, (m
? strlen (m
) : 0), 0);
7194 /* The non-logging counterpart of message1. */
7200 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7203 /* Display a message M which contains a single %s
7204 which gets replaced with STRING. */
7207 message_with_string (m
, string
, log
)
7212 CHECK_STRING (string
);
7218 if (noninteractive_need_newline
)
7219 putc ('\n', stderr
);
7220 noninteractive_need_newline
= 0;
7221 fprintf (stderr
, m
, SDATA (string
));
7222 if (cursor_in_echo_area
== 0)
7223 fprintf (stderr
, "\n");
7227 else if (INTERACTIVE
)
7229 /* The frame whose minibuffer we're going to display the message on.
7230 It may be larger than the selected frame, so we need
7231 to use its buffer, not the selected frame's buffer. */
7232 Lisp_Object mini_window
;
7233 struct frame
*f
, *sf
= SELECTED_FRAME ();
7235 /* Get the frame containing the minibuffer
7236 that the selected frame is using. */
7237 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7238 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7240 /* A null message buffer means that the frame hasn't really been
7241 initialized yet. Error messages get reported properly by
7242 cmd_error, so this must be just an informative message; toss it. */
7243 if (FRAME_MESSAGE_BUF (f
))
7245 Lisp_Object args
[2], message
;
7246 struct gcpro gcpro1
, gcpro2
;
7248 args
[0] = build_string (m
);
7249 args
[1] = message
= string
;
7250 GCPRO2 (args
[0], message
);
7253 message
= Fformat (2, args
);
7256 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7258 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7262 /* Print should start at the beginning of the message
7263 buffer next time. */
7264 message_buf_print
= 0;
7270 /* Dump an informative message to the minibuf. If M is 0, clear out
7271 any existing message, and let the mini-buffer text show through. */
7275 message (m
, a1
, a2
, a3
)
7277 EMACS_INT a1
, a2
, a3
;
7283 if (noninteractive_need_newline
)
7284 putc ('\n', stderr
);
7285 noninteractive_need_newline
= 0;
7286 fprintf (stderr
, m
, a1
, a2
, a3
);
7287 if (cursor_in_echo_area
== 0)
7288 fprintf (stderr
, "\n");
7292 else if (INTERACTIVE
)
7294 /* The frame whose mini-buffer we're going to display the message
7295 on. It may be larger than the selected frame, so we need to
7296 use its buffer, not the selected frame's buffer. */
7297 Lisp_Object mini_window
;
7298 struct frame
*f
, *sf
= SELECTED_FRAME ();
7300 /* Get the frame containing the mini-buffer
7301 that the selected frame is using. */
7302 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7303 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7305 /* A null message buffer means that the frame hasn't really been
7306 initialized yet. Error messages get reported properly by
7307 cmd_error, so this must be just an informative message; toss
7309 if (FRAME_MESSAGE_BUF (f
))
7320 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7321 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7323 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7324 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7326 #endif /* NO_ARG_ARRAY */
7328 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7333 /* Print should start at the beginning of the message
7334 buffer next time. */
7335 message_buf_print
= 0;
7341 /* The non-logging version of message. */
7344 message_nolog (m
, a1
, a2
, a3
)
7346 EMACS_INT a1
, a2
, a3
;
7348 Lisp_Object old_log_max
;
7349 old_log_max
= Vmessage_log_max
;
7350 Vmessage_log_max
= Qnil
;
7351 message (m
, a1
, a2
, a3
);
7352 Vmessage_log_max
= old_log_max
;
7356 /* Display the current message in the current mini-buffer. This is
7357 only called from error handlers in process.c, and is not time
7363 if (!NILP (echo_area_buffer
[0]))
7366 string
= Fcurrent_message ();
7367 message3 (string
, SBYTES (string
),
7368 !NILP (current_buffer
->enable_multibyte_characters
));
7373 /* Make sure echo area buffers in `echo_buffers' are live.
7374 If they aren't, make new ones. */
7377 ensure_echo_area_buffers ()
7381 for (i
= 0; i
< 2; ++i
)
7382 if (!BUFFERP (echo_buffer
[i
])
7383 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7386 Lisp_Object old_buffer
;
7389 old_buffer
= echo_buffer
[i
];
7390 sprintf (name
, " *Echo Area %d*", i
);
7391 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7392 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7394 for (j
= 0; j
< 2; ++j
)
7395 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7396 echo_area_buffer
[j
] = echo_buffer
[i
];
7401 /* Call FN with args A1..A4 with either the current or last displayed
7402 echo_area_buffer as current buffer.
7404 WHICH zero means use the current message buffer
7405 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7406 from echo_buffer[] and clear it.
7408 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7409 suitable buffer from echo_buffer[] and clear it.
7411 Value is what FN returns. */
7414 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7417 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7423 int this_one
, the_other
, clear_buffer_p
, rc
;
7424 int count
= SPECPDL_INDEX ();
7426 /* If buffers aren't live, make new ones. */
7427 ensure_echo_area_buffers ();
7432 this_one
= 0, the_other
= 1;
7434 this_one
= 1, the_other
= 0;
7436 /* Choose a suitable buffer from echo_buffer[] is we don't
7438 if (NILP (echo_area_buffer
[this_one
]))
7440 echo_area_buffer
[this_one
]
7441 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7442 ? echo_buffer
[the_other
]
7443 : echo_buffer
[this_one
]);
7447 buffer
= echo_area_buffer
[this_one
];
7449 /* Don't get confused by reusing the buffer used for echoing
7450 for a different purpose. */
7451 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7454 record_unwind_protect (unwind_with_echo_area_buffer
,
7455 with_echo_area_buffer_unwind_data (w
));
7457 /* Make the echo area buffer current. Note that for display
7458 purposes, it is not necessary that the displayed window's buffer
7459 == current_buffer, except for text property lookup. So, let's
7460 only set that buffer temporarily here without doing a full
7461 Fset_window_buffer. We must also change w->pointm, though,
7462 because otherwise an assertions in unshow_buffer fails, and Emacs
7464 set_buffer_internal_1 (XBUFFER (buffer
));
7468 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7471 current_buffer
->undo_list
= Qt
;
7472 current_buffer
->read_only
= Qnil
;
7473 specbind (Qinhibit_read_only
, Qt
);
7474 specbind (Qinhibit_modification_hooks
, Qt
);
7476 if (clear_buffer_p
&& Z
> BEG
)
7479 xassert (BEGV
>= BEG
);
7480 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7482 rc
= fn (a1
, a2
, a3
, a4
);
7484 xassert (BEGV
>= BEG
);
7485 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7487 unbind_to (count
, Qnil
);
7492 /* Save state that should be preserved around the call to the function
7493 FN called in with_echo_area_buffer. */
7496 with_echo_area_buffer_unwind_data (w
)
7502 /* Reduce consing by keeping one vector in
7503 Vwith_echo_area_save_vector. */
7504 vector
= Vwith_echo_area_save_vector
;
7505 Vwith_echo_area_save_vector
= Qnil
;
7508 vector
= Fmake_vector (make_number (7), Qnil
);
7510 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7511 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7512 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7516 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7517 AREF (vector
, i
) = w
->buffer
; ++i
;
7518 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7519 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7524 for (; i
< end
; ++i
)
7525 AREF (vector
, i
) = Qnil
;
7528 xassert (i
== ASIZE (vector
));
7533 /* Restore global state from VECTOR which was created by
7534 with_echo_area_buffer_unwind_data. */
7537 unwind_with_echo_area_buffer (vector
)
7540 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7541 Vdeactivate_mark
= AREF (vector
, 1);
7542 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7544 if (WINDOWP (AREF (vector
, 3)))
7547 Lisp_Object buffer
, charpos
, bytepos
;
7549 w
= XWINDOW (AREF (vector
, 3));
7550 buffer
= AREF (vector
, 4);
7551 charpos
= AREF (vector
, 5);
7552 bytepos
= AREF (vector
, 6);
7555 set_marker_both (w
->pointm
, buffer
,
7556 XFASTINT (charpos
), XFASTINT (bytepos
));
7559 Vwith_echo_area_save_vector
= vector
;
7564 /* Set up the echo area for use by print functions. MULTIBYTE_P
7565 non-zero means we will print multibyte. */
7568 setup_echo_area_for_printing (multibyte_p
)
7571 /* If we can't find an echo area any more, exit. */
7572 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7575 ensure_echo_area_buffers ();
7577 if (!message_buf_print
)
7579 /* A message has been output since the last time we printed.
7580 Choose a fresh echo area buffer. */
7581 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7582 echo_area_buffer
[0] = echo_buffer
[1];
7584 echo_area_buffer
[0] = echo_buffer
[0];
7586 /* Switch to that buffer and clear it. */
7587 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7588 current_buffer
->truncate_lines
= Qnil
;
7592 int count
= SPECPDL_INDEX ();
7593 specbind (Qinhibit_read_only
, Qt
);
7594 /* Note that undo recording is always disabled. */
7596 unbind_to (count
, Qnil
);
7598 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7600 /* Set up the buffer for the multibyteness we need. */
7602 != !NILP (current_buffer
->enable_multibyte_characters
))
7603 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7605 /* Raise the frame containing the echo area. */
7606 if (minibuffer_auto_raise
)
7608 struct frame
*sf
= SELECTED_FRAME ();
7609 Lisp_Object mini_window
;
7610 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7611 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7614 message_log_maybe_newline ();
7615 message_buf_print
= 1;
7619 if (NILP (echo_area_buffer
[0]))
7621 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7622 echo_area_buffer
[0] = echo_buffer
[1];
7624 echo_area_buffer
[0] = echo_buffer
[0];
7627 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7629 /* Someone switched buffers between print requests. */
7630 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7631 current_buffer
->truncate_lines
= Qnil
;
7637 /* Display an echo area message in window W. Value is non-zero if W's
7638 height is changed. If display_last_displayed_message_p is
7639 non-zero, display the message that was last displayed, otherwise
7640 display the current message. */
7643 display_echo_area (w
)
7646 int i
, no_message_p
, window_height_changed_p
, count
;
7648 /* Temporarily disable garbage collections while displaying the echo
7649 area. This is done because a GC can print a message itself.
7650 That message would modify the echo area buffer's contents while a
7651 redisplay of the buffer is going on, and seriously confuse
7653 count
= inhibit_garbage_collection ();
7655 /* If there is no message, we must call display_echo_area_1
7656 nevertheless because it resizes the window. But we will have to
7657 reset the echo_area_buffer in question to nil at the end because
7658 with_echo_area_buffer will sets it to an empty buffer. */
7659 i
= display_last_displayed_message_p
? 1 : 0;
7660 no_message_p
= NILP (echo_area_buffer
[i
]);
7662 window_height_changed_p
7663 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7664 display_echo_area_1
,
7665 (EMACS_INT
) w
, Qnil
, 0, 0);
7668 echo_area_buffer
[i
] = Qnil
;
7670 unbind_to (count
, Qnil
);
7671 return window_height_changed_p
;
7675 /* Helper for display_echo_area. Display the current buffer which
7676 contains the current echo area message in window W, a mini-window,
7677 a pointer to which is passed in A1. A2..A4 are currently not used.
7678 Change the height of W so that all of the message is displayed.
7679 Value is non-zero if height of W was changed. */
7682 display_echo_area_1 (a1
, a2
, a3
, a4
)
7687 struct window
*w
= (struct window
*) a1
;
7689 struct text_pos start
;
7690 int window_height_changed_p
= 0;
7692 /* Do this before displaying, so that we have a large enough glyph
7693 matrix for the display. */
7694 window_height_changed_p
= resize_mini_window (w
, 0);
7697 clear_glyph_matrix (w
->desired_matrix
);
7698 XSETWINDOW (window
, w
);
7699 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
7700 try_window (window
, start
, 0);
7702 return window_height_changed_p
;
7706 /* Resize the echo area window to exactly the size needed for the
7707 currently displayed message, if there is one. If a mini-buffer
7708 is active, don't shrink it. */
7711 resize_echo_area_exactly ()
7713 if (BUFFERP (echo_area_buffer
[0])
7714 && WINDOWP (echo_area_window
))
7716 struct window
*w
= XWINDOW (echo_area_window
);
7718 Lisp_Object resize_exactly
;
7720 if (minibuf_level
== 0)
7721 resize_exactly
= Qt
;
7723 resize_exactly
= Qnil
;
7725 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7726 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7729 ++windows_or_buffers_changed
;
7730 ++update_mode_lines
;
7731 redisplay_internal (0);
7737 /* Callback function for with_echo_area_buffer, when used from
7738 resize_echo_area_exactly. A1 contains a pointer to the window to
7739 resize, EXACTLY non-nil means resize the mini-window exactly to the
7740 size of the text displayed. A3 and A4 are not used. Value is what
7741 resize_mini_window returns. */
7744 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
7746 Lisp_Object exactly
;
7749 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
7753 /* Resize mini-window W to fit the size of its contents. EXACT:P
7754 means size the window exactly to the size needed. Otherwise, it's
7755 only enlarged until W's buffer is empty. Value is non-zero if
7756 the window height has been changed. */
7759 resize_mini_window (w
, exact_p
)
7763 struct frame
*f
= XFRAME (w
->frame
);
7764 int window_height_changed_p
= 0;
7766 xassert (MINI_WINDOW_P (w
));
7768 /* Don't resize windows while redisplaying a window; it would
7769 confuse redisplay functions when the size of the window they are
7770 displaying changes from under them. Such a resizing can happen,
7771 for instance, when which-func prints a long message while
7772 we are running fontification-functions. We're running these
7773 functions with safe_call which binds inhibit-redisplay to t. */
7774 if (!NILP (Vinhibit_redisplay
))
7777 /* Nil means don't try to resize. */
7778 if (NILP (Vresize_mini_windows
)
7779 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
7782 if (!FRAME_MINIBUF_ONLY_P (f
))
7785 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7786 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
7787 int height
, max_height
;
7788 int unit
= FRAME_LINE_HEIGHT (f
);
7789 struct text_pos start
;
7790 struct buffer
*old_current_buffer
= NULL
;
7792 if (current_buffer
!= XBUFFER (w
->buffer
))
7794 old_current_buffer
= current_buffer
;
7795 set_buffer_internal (XBUFFER (w
->buffer
));
7798 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
7800 /* Compute the max. number of lines specified by the user. */
7801 if (FLOATP (Vmax_mini_window_height
))
7802 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
7803 else if (INTEGERP (Vmax_mini_window_height
))
7804 max_height
= XINT (Vmax_mini_window_height
);
7806 max_height
= total_height
/ 4;
7808 /* Correct that max. height if it's bogus. */
7809 max_height
= max (1, max_height
);
7810 max_height
= min (total_height
, max_height
);
7812 /* Find out the height of the text in the window. */
7813 if (it
.truncate_lines_p
)
7818 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
7819 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
7820 height
= it
.current_y
+ last_height
;
7822 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
7823 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
7824 height
= (height
+ unit
- 1) / unit
;
7827 /* Compute a suitable window start. */
7828 if (height
> max_height
)
7830 height
= max_height
;
7831 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
7832 move_it_vertically_backward (&it
, (height
- 1) * unit
);
7833 start
= it
.current
.pos
;
7836 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
7837 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
7839 if (EQ (Vresize_mini_windows
, Qgrow_only
))
7841 /* Let it grow only, until we display an empty message, in which
7842 case the window shrinks again. */
7843 if (height
> WINDOW_TOTAL_LINES (w
))
7845 int old_height
= WINDOW_TOTAL_LINES (w
);
7846 freeze_window_starts (f
, 1);
7847 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7848 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7850 else if (height
< WINDOW_TOTAL_LINES (w
)
7851 && (exact_p
|| BEGV
== ZV
))
7853 int old_height
= WINDOW_TOTAL_LINES (w
);
7854 freeze_window_starts (f
, 0);
7855 shrink_mini_window (w
);
7856 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7861 /* Always resize to exact size needed. */
7862 if (height
> WINDOW_TOTAL_LINES (w
))
7864 int old_height
= WINDOW_TOTAL_LINES (w
);
7865 freeze_window_starts (f
, 1);
7866 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7867 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7869 else if (height
< WINDOW_TOTAL_LINES (w
))
7871 int old_height
= WINDOW_TOTAL_LINES (w
);
7872 freeze_window_starts (f
, 0);
7873 shrink_mini_window (w
);
7877 freeze_window_starts (f
, 1);
7878 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7881 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7885 if (old_current_buffer
)
7886 set_buffer_internal (old_current_buffer
);
7889 return window_height_changed_p
;
7893 /* Value is the current message, a string, or nil if there is no
7901 if (NILP (echo_area_buffer
[0]))
7905 with_echo_area_buffer (0, 0, current_message_1
,
7906 (EMACS_INT
) &msg
, Qnil
, 0, 0);
7908 echo_area_buffer
[0] = Qnil
;
7916 current_message_1 (a1
, a2
, a3
, a4
)
7921 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
7924 *msg
= make_buffer_string (BEG
, Z
, 1);
7931 /* Push the current message on Vmessage_stack for later restauration
7932 by restore_message. Value is non-zero if the current message isn't
7933 empty. This is a relatively infrequent operation, so it's not
7934 worth optimizing. */
7940 msg
= current_message ();
7941 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
7942 return STRINGP (msg
);
7946 /* Restore message display from the top of Vmessage_stack. */
7953 xassert (CONSP (Vmessage_stack
));
7954 msg
= XCAR (Vmessage_stack
);
7956 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
7958 message3_nolog (msg
, 0, 0);
7962 /* Handler for record_unwind_protect calling pop_message. */
7965 pop_message_unwind (dummy
)
7972 /* Pop the top-most entry off Vmessage_stack. */
7977 xassert (CONSP (Vmessage_stack
));
7978 Vmessage_stack
= XCDR (Vmessage_stack
);
7982 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
7983 exits. If the stack is not empty, we have a missing pop_message
7987 check_message_stack ()
7989 if (!NILP (Vmessage_stack
))
7994 /* Truncate to NCHARS what will be displayed in the echo area the next
7995 time we display it---but don't redisplay it now. */
7998 truncate_echo_area (nchars
)
8002 echo_area_buffer
[0] = Qnil
;
8003 /* A null message buffer means that the frame hasn't really been
8004 initialized yet. Error messages get reported properly by
8005 cmd_error, so this must be just an informative message; toss it. */
8006 else if (!noninteractive
8008 && !NILP (echo_area_buffer
[0]))
8010 struct frame
*sf
= SELECTED_FRAME ();
8011 if (FRAME_MESSAGE_BUF (sf
))
8012 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8017 /* Helper function for truncate_echo_area. Truncate the current
8018 message to at most NCHARS characters. */
8021 truncate_message_1 (nchars
, a2
, a3
, a4
)
8026 if (BEG
+ nchars
< Z
)
8027 del_range (BEG
+ nchars
, Z
);
8029 echo_area_buffer
[0] = Qnil
;
8034 /* Set the current message to a substring of S or STRING.
8036 If STRING is a Lisp string, set the message to the first NBYTES
8037 bytes from STRING. NBYTES zero means use the whole string. If
8038 STRING is multibyte, the message will be displayed multibyte.
8040 If S is not null, set the message to the first LEN bytes of S. LEN
8041 zero means use the whole string. MULTIBYTE_P non-zero means S is
8042 multibyte. Display the message multibyte in that case. */
8045 set_message (s
, string
, nbytes
, multibyte_p
)
8048 int nbytes
, multibyte_p
;
8050 message_enable_multibyte
8051 = ((s
&& multibyte_p
)
8052 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8054 with_echo_area_buffer (0, 0, set_message_1
,
8055 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8056 message_buf_print
= 0;
8057 help_echo_showing_p
= 0;
8061 /* Helper function for set_message. Arguments have the same meaning
8062 as there, with A1 corresponding to S and A2 corresponding to STRING
8063 This function is called with the echo area buffer being
8067 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8070 EMACS_INT nbytes
, multibyte_p
;
8072 const char *s
= (const char *) a1
;
8073 Lisp_Object string
= a2
;
8075 /* Change multibyteness of the echo buffer appropriately. */
8076 if (message_enable_multibyte
8077 != !NILP (current_buffer
->enable_multibyte_characters
))
8078 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8080 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8082 /* Insert new message at BEG. */
8083 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8086 if (STRINGP (string
))
8091 nbytes
= SBYTES (string
);
8092 nchars
= string_byte_to_char (string
, nbytes
);
8094 /* This function takes care of single/multibyte conversion. We
8095 just have to ensure that the echo area buffer has the right
8096 setting of enable_multibyte_characters. */
8097 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8102 nbytes
= strlen (s
);
8104 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8106 /* Convert from multi-byte to single-byte. */
8108 unsigned char work
[1];
8110 /* Convert a multibyte string to single-byte. */
8111 for (i
= 0; i
< nbytes
; i
+= n
)
8113 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8114 work
[0] = (ASCII_CHAR_P (c
)
8116 : multibyte_char_to_unibyte (c
, Qnil
));
8117 insert_1_both (work
, 1, 1, 1, 0, 0);
8120 else if (!multibyte_p
8121 && !NILP (current_buffer
->enable_multibyte_characters
))
8123 /* Convert from single-byte to multi-byte. */
8125 const unsigned char *msg
= (const unsigned char *) s
;
8126 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8128 /* Convert a single-byte string to multibyte. */
8129 for (i
= 0; i
< nbytes
; i
++)
8132 c
= unibyte_char_to_multibyte (c
);
8133 n
= CHAR_STRING (c
, str
);
8134 insert_1_both (str
, 1, n
, 1, 0, 0);
8138 insert_1 (s
, nbytes
, 1, 0, 0);
8145 /* Clear messages. CURRENT_P non-zero means clear the current
8146 message. LAST_DISPLAYED_P non-zero means clear the message
8150 clear_message (current_p
, last_displayed_p
)
8151 int current_p
, last_displayed_p
;
8155 echo_area_buffer
[0] = Qnil
;
8156 message_cleared_p
= 1;
8159 if (last_displayed_p
)
8160 echo_area_buffer
[1] = Qnil
;
8162 message_buf_print
= 0;
8165 /* Clear garbaged frames.
8167 This function is used where the old redisplay called
8168 redraw_garbaged_frames which in turn called redraw_frame which in
8169 turn called clear_frame. The call to clear_frame was a source of
8170 flickering. I believe a clear_frame is not necessary. It should
8171 suffice in the new redisplay to invalidate all current matrices,
8172 and ensure a complete redisplay of all windows. */
8175 clear_garbaged_frames ()
8179 Lisp_Object tail
, frame
;
8180 int changed_count
= 0;
8182 FOR_EACH_FRAME (tail
, frame
)
8184 struct frame
*f
= XFRAME (frame
);
8186 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8190 Fredraw_frame (frame
);
8191 f
->force_flush_display_p
= 1;
8193 clear_current_matrices (f
);
8202 ++windows_or_buffers_changed
;
8207 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8208 is non-zero update selected_frame. Value is non-zero if the
8209 mini-windows height has been changed. */
8212 echo_area_display (update_frame_p
)
8215 Lisp_Object mini_window
;
8218 int window_height_changed_p
= 0;
8219 struct frame
*sf
= SELECTED_FRAME ();
8221 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8222 w
= XWINDOW (mini_window
);
8223 f
= XFRAME (WINDOW_FRAME (w
));
8225 /* Don't display if frame is invisible or not yet initialized. */
8226 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8229 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8231 #ifdef HAVE_WINDOW_SYSTEM
8232 /* When Emacs starts, selected_frame may be a visible terminal
8233 frame, even if we run under a window system. If we let this
8234 through, a message would be displayed on the terminal. */
8235 if (EQ (selected_frame
, Vterminal_frame
)
8236 && !NILP (Vwindow_system
))
8238 #endif /* HAVE_WINDOW_SYSTEM */
8241 /* Redraw garbaged frames. */
8243 clear_garbaged_frames ();
8245 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8247 echo_area_window
= mini_window
;
8248 window_height_changed_p
= display_echo_area (w
);
8249 w
->must_be_updated_p
= 1;
8251 /* Update the display, unless called from redisplay_internal.
8252 Also don't update the screen during redisplay itself. The
8253 update will happen at the end of redisplay, and an update
8254 here could cause confusion. */
8255 if (update_frame_p
&& !redisplaying_p
)
8259 /* If the display update has been interrupted by pending
8260 input, update mode lines in the frame. Due to the
8261 pending input, it might have been that redisplay hasn't
8262 been called, so that mode lines above the echo area are
8263 garbaged. This looks odd, so we prevent it here. */
8264 if (!display_completed
)
8265 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8267 if (window_height_changed_p
8268 /* Don't do this if Emacs is shutting down. Redisplay
8269 needs to run hooks. */
8270 && !NILP (Vrun_hooks
))
8272 /* Must update other windows. Likewise as in other
8273 cases, don't let this update be interrupted by
8275 int count
= SPECPDL_INDEX ();
8276 specbind (Qredisplay_dont_pause
, Qt
);
8277 windows_or_buffers_changed
= 1;
8278 redisplay_internal (0);
8279 unbind_to (count
, Qnil
);
8281 else if (FRAME_WINDOW_P (f
) && n
== 0)
8283 /* Window configuration is the same as before.
8284 Can do with a display update of the echo area,
8285 unless we displayed some mode lines. */
8286 update_single_window (w
, 1);
8287 rif
->flush_display (f
);
8290 update_frame (f
, 1, 1);
8292 /* If cursor is in the echo area, make sure that the next
8293 redisplay displays the minibuffer, so that the cursor will
8294 be replaced with what the minibuffer wants. */
8295 if (cursor_in_echo_area
)
8296 ++windows_or_buffers_changed
;
8299 else if (!EQ (mini_window
, selected_window
))
8300 windows_or_buffers_changed
++;
8302 /* The current message is now also the last one displayed. */
8303 echo_area_buffer
[1] = echo_area_buffer
[0];
8305 /* Prevent redisplay optimization in redisplay_internal by resetting
8306 this_line_start_pos. This is done because the mini-buffer now
8307 displays the message instead of its buffer text. */
8308 if (EQ (mini_window
, selected_window
))
8309 CHARPOS (this_line_start_pos
) = 0;
8311 return window_height_changed_p
;
8316 /***********************************************************************
8317 Mode Lines and Frame Titles
8318 ***********************************************************************/
8320 /* A buffer for constructing non-propertized mode-line strings and
8321 frame titles in it; allocated from the heap in init_xdisp and
8322 resized as needed in store_mode_line_noprop_char. */
8324 static char *mode_line_noprop_buf
;
8326 /* The buffer's end, and a current output position in it. */
8328 static char *mode_line_noprop_buf_end
;
8329 static char *mode_line_noprop_ptr
;
8331 #define MODE_LINE_NOPROP_LEN(start) \
8332 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8335 MODE_LINE_DISPLAY
= 0,
8341 /* Alist that caches the results of :propertize.
8342 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8343 static Lisp_Object mode_line_proptrans_alist
;
8345 /* List of strings making up the mode-line. */
8346 static Lisp_Object mode_line_string_list
;
8348 /* Base face property when building propertized mode line string. */
8349 static Lisp_Object mode_line_string_face
;
8350 static Lisp_Object mode_line_string_face_prop
;
8353 /* Unwind data for mode line strings */
8355 static Lisp_Object Vmode_line_unwind_vector
;
8358 format_mode_line_unwind_data (obuf
)
8359 struct buffer
*obuf
;
8363 /* Reduce consing by keeping one vector in
8364 Vwith_echo_area_save_vector. */
8365 vector
= Vmode_line_unwind_vector
;
8366 Vmode_line_unwind_vector
= Qnil
;
8369 vector
= Fmake_vector (make_number (7), Qnil
);
8371 AREF (vector
, 0) = make_number (mode_line_target
);
8372 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8373 AREF (vector
, 2) = mode_line_string_list
;
8374 AREF (vector
, 3) = mode_line_proptrans_alist
;
8375 AREF (vector
, 4) = mode_line_string_face
;
8376 AREF (vector
, 5) = mode_line_string_face_prop
;
8379 XSETBUFFER (AREF (vector
, 6), obuf
);
8381 AREF (vector
, 6) = Qnil
;
8387 unwind_format_mode_line (vector
)
8390 mode_line_target
= XINT (AREF (vector
, 0));
8391 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8392 mode_line_string_list
= AREF (vector
, 2);
8393 mode_line_proptrans_alist
= AREF (vector
, 3);
8394 mode_line_string_face
= AREF (vector
, 4);
8395 mode_line_string_face_prop
= AREF (vector
, 5);
8397 if (!NILP (AREF (vector
, 6)))
8399 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8400 AREF (vector
, 6) = Qnil
;
8403 Vmode_line_unwind_vector
= vector
;
8408 /* Store a single character C for the frame title in mode_line_noprop_buf.
8409 Re-allocate mode_line_noprop_buf if necessary. */
8413 store_mode_line_noprop_char (char c
)
8415 store_mode_line_noprop_char (c
)
8419 /* If output position has reached the end of the allocated buffer,
8420 double the buffer's size. */
8421 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8423 int len
= MODE_LINE_NOPROP_LEN (0);
8424 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8425 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8426 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8427 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8430 *mode_line_noprop_ptr
++ = c
;
8434 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8435 mode_line_noprop_ptr. STR is the string to store. Do not copy
8436 characters that yield more columns than PRECISION; PRECISION <= 0
8437 means copy the whole string. Pad with spaces until FIELD_WIDTH
8438 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8439 pad. Called from display_mode_element when it is used to build a
8443 store_mode_line_noprop (str
, field_width
, precision
)
8444 const unsigned char *str
;
8445 int field_width
, precision
;
8450 /* Copy at most PRECISION chars from STR. */
8451 nbytes
= strlen (str
);
8452 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8454 store_mode_line_noprop_char (*str
++);
8456 /* Fill up with spaces until FIELD_WIDTH reached. */
8457 while (field_width
> 0
8460 store_mode_line_noprop_char (' ');
8467 /***********************************************************************
8469 ***********************************************************************/
8471 #ifdef HAVE_WINDOW_SYSTEM
8473 /* Set the title of FRAME, if it has changed. The title format is
8474 Vicon_title_format if FRAME is iconified, otherwise it is
8475 frame_title_format. */
8478 x_consider_frame_title (frame
)
8481 struct frame
*f
= XFRAME (frame
);
8483 if (FRAME_WINDOW_P (f
)
8484 || FRAME_MINIBUF_ONLY_P (f
)
8485 || f
->explicit_name
)
8487 /* Do we have more than one visible frame on this X display? */
8494 int count
= SPECPDL_INDEX ();
8496 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8498 Lisp_Object other_frame
= XCAR (tail
);
8499 struct frame
*tf
= XFRAME (other_frame
);
8502 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8503 && !FRAME_MINIBUF_ONLY_P (tf
)
8504 && !EQ (other_frame
, tip_frame
)
8505 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8509 /* Set global variable indicating that multiple frames exist. */
8510 multiple_frames
= CONSP (tail
);
8512 /* Switch to the buffer of selected window of the frame. Set up
8513 mode_line_target so that display_mode_element will output into
8514 mode_line_noprop_buf; then display the title. */
8515 record_unwind_protect (unwind_format_mode_line
,
8516 format_mode_line_unwind_data (current_buffer
));
8518 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8519 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8521 mode_line_target
= MODE_LINE_TITLE
;
8522 title_start
= MODE_LINE_NOPROP_LEN (0);
8523 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8524 NULL
, DEFAULT_FACE_ID
);
8525 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8526 len
= MODE_LINE_NOPROP_LEN (title_start
);
8527 title
= mode_line_noprop_buf
+ title_start
;
8528 unbind_to (count
, Qnil
);
8530 /* Set the title only if it's changed. This avoids consing in
8531 the common case where it hasn't. (If it turns out that we've
8532 already wasted too much time by walking through the list with
8533 display_mode_element, then we might need to optimize at a
8534 higher level than this.) */
8535 if (! STRINGP (f
->name
)
8536 || SBYTES (f
->name
) != len
8537 || bcmp (title
, SDATA (f
->name
), len
) != 0)
8538 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
8542 #endif /* not HAVE_WINDOW_SYSTEM */
8547 /***********************************************************************
8549 ***********************************************************************/
8552 /* Prepare for redisplay by updating menu-bar item lists when
8553 appropriate. This can call eval. */
8556 prepare_menu_bars ()
8559 struct gcpro gcpro1
, gcpro2
;
8561 Lisp_Object tooltip_frame
;
8563 #ifdef HAVE_WINDOW_SYSTEM
8564 tooltip_frame
= tip_frame
;
8566 tooltip_frame
= Qnil
;
8569 /* Update all frame titles based on their buffer names, etc. We do
8570 this before the menu bars so that the buffer-menu will show the
8571 up-to-date frame titles. */
8572 #ifdef HAVE_WINDOW_SYSTEM
8573 if (windows_or_buffers_changed
|| update_mode_lines
)
8575 Lisp_Object tail
, frame
;
8577 FOR_EACH_FRAME (tail
, frame
)
8580 if (!EQ (frame
, tooltip_frame
)
8581 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8582 x_consider_frame_title (frame
);
8585 #endif /* HAVE_WINDOW_SYSTEM */
8587 /* Update the menu bar item lists, if appropriate. This has to be
8588 done before any actual redisplay or generation of display lines. */
8589 all_windows
= (update_mode_lines
8590 || buffer_shared
> 1
8591 || windows_or_buffers_changed
);
8594 Lisp_Object tail
, frame
;
8595 int count
= SPECPDL_INDEX ();
8597 record_unwind_save_match_data ();
8599 FOR_EACH_FRAME (tail
, frame
)
8603 /* Ignore tooltip frame. */
8604 if (EQ (frame
, tooltip_frame
))
8607 /* If a window on this frame changed size, report that to
8608 the user and clear the size-change flag. */
8609 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8611 Lisp_Object functions
;
8613 /* Clear flag first in case we get an error below. */
8614 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8615 functions
= Vwindow_size_change_functions
;
8616 GCPRO2 (tail
, functions
);
8618 while (CONSP (functions
))
8620 call1 (XCAR (functions
), frame
);
8621 functions
= XCDR (functions
);
8627 update_menu_bar (f
, 0);
8628 #ifdef HAVE_WINDOW_SYSTEM
8629 update_tool_bar (f
, 0);
8634 unbind_to (count
, Qnil
);
8638 struct frame
*sf
= SELECTED_FRAME ();
8639 update_menu_bar (sf
, 1);
8640 #ifdef HAVE_WINDOW_SYSTEM
8641 update_tool_bar (sf
, 1);
8645 /* Motif needs this. See comment in xmenu.c. Turn it off when
8646 pending_menu_activation is not defined. */
8647 #ifdef USE_X_TOOLKIT
8648 pending_menu_activation
= 0;
8653 /* Update the menu bar item list for frame F. This has to be done
8654 before we start to fill in any display lines, because it can call
8657 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8660 update_menu_bar (f
, save_match_data
)
8662 int save_match_data
;
8665 register struct window
*w
;
8667 /* If called recursively during a menu update, do nothing. This can
8668 happen when, for instance, an activate-menubar-hook causes a
8670 if (inhibit_menubar_update
)
8673 window
= FRAME_SELECTED_WINDOW (f
);
8674 w
= XWINDOW (window
);
8676 #if 0 /* The if statement below this if statement used to include the
8677 condition !NILP (w->update_mode_line), rather than using
8678 update_mode_lines directly, and this if statement may have
8679 been added to make that condition work. Now the if
8680 statement below matches its comment, this isn't needed. */
8681 if (update_mode_lines
)
8682 w
->update_mode_line
= Qt
;
8685 if (FRAME_WINDOW_P (f
)
8687 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8688 || defined (USE_GTK)
8689 FRAME_EXTERNAL_MENU_BAR (f
)
8691 FRAME_MENU_BAR_LINES (f
) > 0
8693 : FRAME_MENU_BAR_LINES (f
) > 0)
8695 /* If the user has switched buffers or windows, we need to
8696 recompute to reflect the new bindings. But we'll
8697 recompute when update_mode_lines is set too; that means
8698 that people can use force-mode-line-update to request
8699 that the menu bar be recomputed. The adverse effect on
8700 the rest of the redisplay algorithm is about the same as
8701 windows_or_buffers_changed anyway. */
8702 if (windows_or_buffers_changed
8703 /* This used to test w->update_mode_line, but we believe
8704 there is no need to recompute the menu in that case. */
8705 || update_mode_lines
8706 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8707 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8708 != !NILP (w
->last_had_star
))
8709 || ((!NILP (Vtransient_mark_mode
)
8710 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8711 != !NILP (w
->region_showing
)))
8713 struct buffer
*prev
= current_buffer
;
8714 int count
= SPECPDL_INDEX ();
8716 specbind (Qinhibit_menubar_update
, Qt
);
8718 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8719 if (save_match_data
)
8720 record_unwind_save_match_data ();
8721 if (NILP (Voverriding_local_map_menu_flag
))
8723 specbind (Qoverriding_terminal_local_map
, Qnil
);
8724 specbind (Qoverriding_local_map
, Qnil
);
8727 /* Run the Lucid hook. */
8728 safe_run_hooks (Qactivate_menubar_hook
);
8730 /* If it has changed current-menubar from previous value,
8731 really recompute the menu-bar from the value. */
8732 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8733 call0 (Qrecompute_lucid_menubar
);
8735 safe_run_hooks (Qmenu_bar_update_hook
);
8736 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
8738 /* Redisplay the menu bar in case we changed it. */
8739 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8740 || defined (USE_GTK)
8741 if (FRAME_WINDOW_P (f
)
8742 #if defined (MAC_OS)
8743 /* All frames on Mac OS share the same menubar. So only the
8744 selected frame should be allowed to set it. */
8745 && f
== SELECTED_FRAME ()
8748 set_frame_menubar (f
, 0, 0);
8750 /* On a terminal screen, the menu bar is an ordinary screen
8751 line, and this makes it get updated. */
8752 w
->update_mode_line
= Qt
;
8753 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8754 /* In the non-toolkit version, the menu bar is an ordinary screen
8755 line, and this makes it get updated. */
8756 w
->update_mode_line
= Qt
;
8757 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8759 unbind_to (count
, Qnil
);
8760 set_buffer_internal_1 (prev
);
8767 /***********************************************************************
8769 ***********************************************************************/
8771 #ifdef HAVE_WINDOW_SYSTEM
8774 Nominal cursor position -- where to draw output.
8775 HPOS and VPOS are window relative glyph matrix coordinates.
8776 X and Y are window relative pixel coordinates. */
8778 struct cursor_pos output_cursor
;
8782 Set the global variable output_cursor to CURSOR. All cursor
8783 positions are relative to updated_window. */
8786 set_output_cursor (cursor
)
8787 struct cursor_pos
*cursor
;
8789 output_cursor
.hpos
= cursor
->hpos
;
8790 output_cursor
.vpos
= cursor
->vpos
;
8791 output_cursor
.x
= cursor
->x
;
8792 output_cursor
.y
= cursor
->y
;
8797 Set a nominal cursor position.
8799 HPOS and VPOS are column/row positions in a window glyph matrix. X
8800 and Y are window text area relative pixel positions.
8802 If this is done during an update, updated_window will contain the
8803 window that is being updated and the position is the future output
8804 cursor position for that window. If updated_window is null, use
8805 selected_window and display the cursor at the given position. */
8808 x_cursor_to (vpos
, hpos
, y
, x
)
8809 int vpos
, hpos
, y
, x
;
8813 /* If updated_window is not set, work on selected_window. */
8817 w
= XWINDOW (selected_window
);
8819 /* Set the output cursor. */
8820 output_cursor
.hpos
= hpos
;
8821 output_cursor
.vpos
= vpos
;
8822 output_cursor
.x
= x
;
8823 output_cursor
.y
= y
;
8825 /* If not called as part of an update, really display the cursor.
8826 This will also set the cursor position of W. */
8827 if (updated_window
== NULL
)
8830 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8831 if (rif
->flush_display_optional
)
8832 rif
->flush_display_optional (SELECTED_FRAME ());
8837 #endif /* HAVE_WINDOW_SYSTEM */
8840 /***********************************************************************
8842 ***********************************************************************/
8844 #ifdef HAVE_WINDOW_SYSTEM
8846 /* Where the mouse was last time we reported a mouse event. */
8848 FRAME_PTR last_mouse_frame
;
8850 /* Tool-bar item index of the item on which a mouse button was pressed
8853 int last_tool_bar_item
;
8856 /* Update the tool-bar item list for frame F. This has to be done
8857 before we start to fill in any display lines. Called from
8858 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8859 and restore it here. */
8862 update_tool_bar (f
, save_match_data
)
8864 int save_match_data
;
8867 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
8869 int do_update
= WINDOWP (f
->tool_bar_window
)
8870 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
8878 window
= FRAME_SELECTED_WINDOW (f
);
8879 w
= XWINDOW (window
);
8881 /* If the user has switched buffers or windows, we need to
8882 recompute to reflect the new bindings. But we'll
8883 recompute when update_mode_lines is set too; that means
8884 that people can use force-mode-line-update to request
8885 that the menu bar be recomputed. The adverse effect on
8886 the rest of the redisplay algorithm is about the same as
8887 windows_or_buffers_changed anyway. */
8888 if (windows_or_buffers_changed
8889 || !NILP (w
->update_mode_line
)
8890 || update_mode_lines
8891 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8892 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8893 != !NILP (w
->last_had_star
))
8894 || ((!NILP (Vtransient_mark_mode
)
8895 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8896 != !NILP (w
->region_showing
)))
8898 struct buffer
*prev
= current_buffer
;
8899 int count
= SPECPDL_INDEX ();
8900 Lisp_Object new_tool_bar
;
8902 struct gcpro gcpro1
;
8904 /* Set current_buffer to the buffer of the selected
8905 window of the frame, so that we get the right local
8907 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8909 /* Save match data, if we must. */
8910 if (save_match_data
)
8911 record_unwind_save_match_data ();
8913 /* Make sure that we don't accidentally use bogus keymaps. */
8914 if (NILP (Voverriding_local_map_menu_flag
))
8916 specbind (Qoverriding_terminal_local_map
, Qnil
);
8917 specbind (Qoverriding_local_map
, Qnil
);
8920 GCPRO1 (new_tool_bar
);
8922 /* Build desired tool-bar items from keymaps. */
8923 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
8926 /* Redisplay the tool-bar if we changed it. */
8927 if (NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
8929 /* Redisplay that happens asynchronously due to an expose event
8930 may access f->tool_bar_items. Make sure we update both
8931 variables within BLOCK_INPUT so no such event interrupts. */
8933 f
->tool_bar_items
= new_tool_bar
;
8934 f
->n_tool_bar_items
= new_n_tool_bar
;
8935 w
->update_mode_line
= Qt
;
8941 unbind_to (count
, Qnil
);
8942 set_buffer_internal_1 (prev
);
8948 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8949 F's desired tool-bar contents. F->tool_bar_items must have
8950 been set up previously by calling prepare_menu_bars. */
8953 build_desired_tool_bar_string (f
)
8956 int i
, size
, size_needed
;
8957 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8958 Lisp_Object image
, plist
, props
;
8960 image
= plist
= props
= Qnil
;
8961 GCPRO3 (image
, plist
, props
);
8963 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
8964 Otherwise, make a new string. */
8966 /* The size of the string we might be able to reuse. */
8967 size
= (STRINGP (f
->desired_tool_bar_string
)
8968 ? SCHARS (f
->desired_tool_bar_string
)
8971 /* We need one space in the string for each image. */
8972 size_needed
= f
->n_tool_bar_items
;
8974 /* Reuse f->desired_tool_bar_string, if possible. */
8975 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
8976 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
8980 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
8981 Fremove_text_properties (make_number (0), make_number (size
),
8982 props
, f
->desired_tool_bar_string
);
8985 /* Put a `display' property on the string for the images to display,
8986 put a `menu_item' property on tool-bar items with a value that
8987 is the index of the item in F's tool-bar item vector. */
8988 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
8990 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
8992 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8993 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8994 int hmargin
, vmargin
, relief
, idx
, end
;
8995 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
8997 /* If image is a vector, choose the image according to the
8999 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9000 if (VECTORP (image
))
9004 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9005 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9008 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9009 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9011 xassert (ASIZE (image
) >= idx
);
9012 image
= AREF (image
, idx
);
9017 /* Ignore invalid image specifications. */
9018 if (!valid_image_p (image
))
9021 /* Display the tool-bar button pressed, or depressed. */
9022 plist
= Fcopy_sequence (XCDR (image
));
9024 /* Compute margin and relief to draw. */
9025 relief
= (tool_bar_button_relief
>= 0
9026 ? tool_bar_button_relief
9027 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9028 hmargin
= vmargin
= relief
;
9030 if (INTEGERP (Vtool_bar_button_margin
)
9031 && XINT (Vtool_bar_button_margin
) > 0)
9033 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9034 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9036 else if (CONSP (Vtool_bar_button_margin
))
9038 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9039 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9040 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9042 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9043 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9044 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9047 if (auto_raise_tool_bar_buttons_p
)
9049 /* Add a `:relief' property to the image spec if the item is
9053 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9060 /* If image is selected, display it pressed, i.e. with a
9061 negative relief. If it's not selected, display it with a
9063 plist
= Fplist_put (plist
, QCrelief
,
9065 ? make_number (-relief
)
9066 : make_number (relief
)));
9071 /* Put a margin around the image. */
9072 if (hmargin
|| vmargin
)
9074 if (hmargin
== vmargin
)
9075 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9077 plist
= Fplist_put (plist
, QCmargin
,
9078 Fcons (make_number (hmargin
),
9079 make_number (vmargin
)));
9082 /* If button is not enabled, and we don't have special images
9083 for the disabled state, make the image appear disabled by
9084 applying an appropriate algorithm to it. */
9085 if (!enabled_p
&& idx
< 0)
9086 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9088 /* Put a `display' text property on the string for the image to
9089 display. Put a `menu-item' property on the string that gives
9090 the start of this item's properties in the tool-bar items
9092 image
= Fcons (Qimage
, plist
);
9093 props
= list4 (Qdisplay
, image
,
9094 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9096 /* Let the last image hide all remaining spaces in the tool bar
9097 string. The string can be longer than needed when we reuse a
9099 if (i
+ 1 == f
->n_tool_bar_items
)
9100 end
= SCHARS (f
->desired_tool_bar_string
);
9103 Fadd_text_properties (make_number (i
), make_number (end
),
9104 props
, f
->desired_tool_bar_string
);
9112 /* Display one line of the tool-bar of frame IT->f. */
9115 display_tool_bar_line (it
)
9118 struct glyph_row
*row
= it
->glyph_row
;
9119 int max_x
= it
->last_visible_x
;
9122 prepare_desired_row (row
);
9123 row
->y
= it
->current_y
;
9125 /* Note that this isn't made use of if the face hasn't a box,
9126 so there's no need to check the face here. */
9127 it
->start_of_box_run_p
= 1;
9129 while (it
->current_x
< max_x
)
9131 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
9133 /* Get the next display element. */
9134 if (!get_next_display_element (it
))
9137 /* Produce glyphs. */
9138 x_before
= it
->current_x
;
9139 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
9140 PRODUCE_GLYPHS (it
);
9142 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
9147 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9149 if (x
+ glyph
->pixel_width
> max_x
)
9151 /* Glyph doesn't fit on line. */
9152 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
9158 x
+= glyph
->pixel_width
;
9162 /* Stop at line ends. */
9163 if (ITERATOR_AT_END_OF_LINE_P (it
))
9166 set_iterator_to_next (it
, 1);
9171 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9172 extend_face_to_end_of_line (it
);
9173 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9174 last
->right_box_line_p
= 1;
9175 if (last
== row
->glyphs
[TEXT_AREA
])
9176 last
->left_box_line_p
= 1;
9177 compute_line_metrics (it
);
9179 /* If line is empty, make it occupy the rest of the tool-bar. */
9180 if (!row
->displays_text_p
)
9182 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9183 row
->ascent
= row
->phys_ascent
= 0;
9184 row
->extra_line_spacing
= 0;
9187 row
->full_width_p
= 1;
9188 row
->continued_p
= 0;
9189 row
->truncated_on_left_p
= 0;
9190 row
->truncated_on_right_p
= 0;
9192 it
->current_x
= it
->hpos
= 0;
9193 it
->current_y
+= row
->height
;
9199 /* Value is the number of screen lines needed to make all tool-bar
9200 items of frame F visible. */
9203 tool_bar_lines_needed (f
)
9206 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9209 /* Initialize an iterator for iteration over
9210 F->desired_tool_bar_string in the tool-bar window of frame F. */
9211 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9212 it
.first_visible_x
= 0;
9213 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9214 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9216 while (!ITERATOR_AT_END_P (&it
))
9218 it
.glyph_row
= w
->desired_matrix
->rows
;
9219 clear_glyph_row (it
.glyph_row
);
9220 display_tool_bar_line (&it
);
9223 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9227 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9229 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9238 frame
= selected_frame
;
9240 CHECK_FRAME (frame
);
9243 if (WINDOWP (f
->tool_bar_window
)
9244 || (w
= XWINDOW (f
->tool_bar_window
),
9245 WINDOW_TOTAL_LINES (w
) > 0))
9247 update_tool_bar (f
, 1);
9248 if (f
->n_tool_bar_items
)
9250 build_desired_tool_bar_string (f
);
9251 nlines
= tool_bar_lines_needed (f
);
9255 return make_number (nlines
);
9259 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9260 height should be changed. */
9263 redisplay_tool_bar (f
)
9268 struct glyph_row
*row
;
9269 int change_height_p
= 0;
9272 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9273 update_frame_tool_bar (f
);
9277 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9278 do anything. This means you must start with tool-bar-lines
9279 non-zero to get the auto-sizing effect. Or in other words, you
9280 can turn off tool-bars by specifying tool-bar-lines zero. */
9281 if (!WINDOWP (f
->tool_bar_window
)
9282 || (w
= XWINDOW (f
->tool_bar_window
),
9283 WINDOW_TOTAL_LINES (w
) == 0))
9286 /* Set up an iterator for the tool-bar window. */
9287 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9288 it
.first_visible_x
= 0;
9289 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9292 /* Build a string that represents the contents of the tool-bar. */
9293 build_desired_tool_bar_string (f
);
9294 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9296 /* Display as many lines as needed to display all tool-bar items. */
9297 while (it
.current_y
< it
.last_visible_y
)
9298 display_tool_bar_line (&it
);
9300 /* It doesn't make much sense to try scrolling in the tool-bar
9301 window, so don't do it. */
9302 w
->desired_matrix
->no_scrolling_p
= 1;
9303 w
->must_be_updated_p
= 1;
9305 if (auto_resize_tool_bars_p
)
9309 /* If we couldn't display everything, change the tool-bar's
9311 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
9312 change_height_p
= 1;
9314 /* If there are blank lines at the end, except for a partially
9315 visible blank line at the end that is smaller than
9316 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9317 row
= it
.glyph_row
- 1;
9318 if (!row
->displays_text_p
9319 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9320 change_height_p
= 1;
9322 /* If row displays tool-bar items, but is partially visible,
9323 change the tool-bar's height. */
9324 if (row
->displays_text_p
9325 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
9326 change_height_p
= 1;
9328 /* Resize windows as needed by changing the `tool-bar-lines'
9331 && (nlines
= tool_bar_lines_needed (f
),
9332 nlines
!= WINDOW_TOTAL_LINES (w
)))
9334 extern Lisp_Object Qtool_bar_lines
;
9336 int old_height
= WINDOW_TOTAL_LINES (w
);
9338 XSETFRAME (frame
, f
);
9339 clear_glyph_matrix (w
->desired_matrix
);
9340 Fmodify_frame_parameters (frame
,
9341 Fcons (Fcons (Qtool_bar_lines
,
9342 make_number (nlines
)),
9344 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9345 fonts_changed_p
= 1;
9349 return change_height_p
;
9353 /* Get information about the tool-bar item which is displayed in GLYPH
9354 on frame F. Return in *PROP_IDX the index where tool-bar item
9355 properties start in F->tool_bar_items. Value is zero if
9356 GLYPH doesn't display a tool-bar item. */
9359 tool_bar_item_info (f
, glyph
, prop_idx
)
9361 struct glyph
*glyph
;
9368 /* This function can be called asynchronously, which means we must
9369 exclude any possibility that Fget_text_property signals an
9371 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
9372 charpos
= max (0, charpos
);
9374 /* Get the text property `menu-item' at pos. The value of that
9375 property is the start index of this item's properties in
9376 F->tool_bar_items. */
9377 prop
= Fget_text_property (make_number (charpos
),
9378 Qmenu_item
, f
->current_tool_bar_string
);
9379 if (INTEGERP (prop
))
9381 *prop_idx
= XINT (prop
);
9391 /* Get information about the tool-bar item at position X/Y on frame F.
9392 Return in *GLYPH a pointer to the glyph of the tool-bar item in
9393 the current matrix of the tool-bar window of F, or NULL if not
9394 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
9395 item in F->tool_bar_items. Value is
9397 -1 if X/Y is not on a tool-bar item
9398 0 if X/Y is on the same item that was highlighted before.
9402 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
9405 struct glyph
**glyph
;
9406 int *hpos
, *vpos
, *prop_idx
;
9408 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9409 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9412 /* Find the glyph under X/Y. */
9413 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
9417 /* Get the start of this tool-bar item's properties in
9418 f->tool_bar_items. */
9419 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
9422 /* Is mouse on the highlighted item? */
9423 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
9424 && *vpos
>= dpyinfo
->mouse_face_beg_row
9425 && *vpos
<= dpyinfo
->mouse_face_end_row
9426 && (*vpos
> dpyinfo
->mouse_face_beg_row
9427 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
9428 && (*vpos
< dpyinfo
->mouse_face_end_row
9429 || *hpos
< dpyinfo
->mouse_face_end_col
9430 || dpyinfo
->mouse_face_past_end
))
9438 Handle mouse button event on the tool-bar of frame F, at
9439 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
9440 0 for button release. MODIFIERS is event modifiers for button
9444 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
9447 unsigned int modifiers
;
9449 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9450 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9451 int hpos
, vpos
, prop_idx
;
9452 struct glyph
*glyph
;
9453 Lisp_Object enabled_p
;
9455 /* If not on the highlighted tool-bar item, return. */
9456 frame_to_window_pixel_xy (w
, &x
, &y
);
9457 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
9460 /* If item is disabled, do nothing. */
9461 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9462 if (NILP (enabled_p
))
9467 /* Show item in pressed state. */
9468 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
9469 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
9470 last_tool_bar_item
= prop_idx
;
9474 Lisp_Object key
, frame
;
9475 struct input_event event
;
9478 /* Show item in released state. */
9479 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
9480 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
9482 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
9484 XSETFRAME (frame
, f
);
9485 event
.kind
= TOOL_BAR_EVENT
;
9486 event
.frame_or_window
= frame
;
9488 kbd_buffer_store_event (&event
);
9490 event
.kind
= TOOL_BAR_EVENT
;
9491 event
.frame_or_window
= frame
;
9493 event
.modifiers
= modifiers
;
9494 kbd_buffer_store_event (&event
);
9495 last_tool_bar_item
= -1;
9500 /* Possibly highlight a tool-bar item on frame F when mouse moves to
9501 tool-bar window-relative coordinates X/Y. Called from
9502 note_mouse_highlight. */
9505 note_tool_bar_highlight (f
, x
, y
)
9509 Lisp_Object window
= f
->tool_bar_window
;
9510 struct window
*w
= XWINDOW (window
);
9511 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9513 struct glyph
*glyph
;
9514 struct glyph_row
*row
;
9516 Lisp_Object enabled_p
;
9518 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9519 int mouse_down_p
, rc
;
9521 /* Function note_mouse_highlight is called with negative x(y
9522 values when mouse moves outside of the frame. */
9523 if (x
<= 0 || y
<= 0)
9525 clear_mouse_face (dpyinfo
);
9529 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9532 /* Not on tool-bar item. */
9533 clear_mouse_face (dpyinfo
);
9537 /* On same tool-bar item as before. */
9540 clear_mouse_face (dpyinfo
);
9542 /* Mouse is down, but on different tool-bar item? */
9543 mouse_down_p
= (dpyinfo
->grabbed
9544 && f
== last_mouse_frame
9545 && FRAME_LIVE_P (f
));
9547 && last_tool_bar_item
!= prop_idx
)
9550 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9551 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9553 /* If tool-bar item is not enabled, don't highlight it. */
9554 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9555 if (!NILP (enabled_p
))
9557 /* Compute the x-position of the glyph. In front and past the
9558 image is a space. We include this in the highlighted area. */
9559 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9560 for (i
= x
= 0; i
< hpos
; ++i
)
9561 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9563 /* Record this as the current active region. */
9564 dpyinfo
->mouse_face_beg_col
= hpos
;
9565 dpyinfo
->mouse_face_beg_row
= vpos
;
9566 dpyinfo
->mouse_face_beg_x
= x
;
9567 dpyinfo
->mouse_face_beg_y
= row
->y
;
9568 dpyinfo
->mouse_face_past_end
= 0;
9570 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9571 dpyinfo
->mouse_face_end_row
= vpos
;
9572 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9573 dpyinfo
->mouse_face_end_y
= row
->y
;
9574 dpyinfo
->mouse_face_window
= window
;
9575 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9577 /* Display it as active. */
9578 show_mouse_face (dpyinfo
, draw
);
9579 dpyinfo
->mouse_face_image_state
= draw
;
9584 /* Set help_echo_string to a help string to display for this tool-bar item.
9585 XTread_socket does the rest. */
9586 help_echo_object
= help_echo_window
= Qnil
;
9588 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9589 if (NILP (help_echo_string
))
9590 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9593 #endif /* HAVE_WINDOW_SYSTEM */
9597 /************************************************************************
9598 Horizontal scrolling
9599 ************************************************************************/
9601 static int hscroll_window_tree
P_ ((Lisp_Object
));
9602 static int hscroll_windows
P_ ((Lisp_Object
));
9604 /* For all leaf windows in the window tree rooted at WINDOW, set their
9605 hscroll value so that PT is (i) visible in the window, and (ii) so
9606 that it is not within a certain margin at the window's left and
9607 right border. Value is non-zero if any window's hscroll has been
9611 hscroll_window_tree (window
)
9614 int hscrolled_p
= 0;
9615 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9616 int hscroll_step_abs
= 0;
9617 double hscroll_step_rel
= 0;
9619 if (hscroll_relative_p
)
9621 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9622 if (hscroll_step_rel
< 0)
9624 hscroll_relative_p
= 0;
9625 hscroll_step_abs
= 0;
9628 else if (INTEGERP (Vhscroll_step
))
9630 hscroll_step_abs
= XINT (Vhscroll_step
);
9631 if (hscroll_step_abs
< 0)
9632 hscroll_step_abs
= 0;
9635 hscroll_step_abs
= 0;
9637 while (WINDOWP (window
))
9639 struct window
*w
= XWINDOW (window
);
9641 if (WINDOWP (w
->hchild
))
9642 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9643 else if (WINDOWP (w
->vchild
))
9644 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9645 else if (w
->cursor
.vpos
>= 0)
9648 int text_area_width
;
9649 struct glyph_row
*current_cursor_row
9650 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9651 struct glyph_row
*desired_cursor_row
9652 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9653 struct glyph_row
*cursor_row
9654 = (desired_cursor_row
->enabled_p
9655 ? desired_cursor_row
9656 : current_cursor_row
);
9658 text_area_width
= window_box_width (w
, TEXT_AREA
);
9660 /* Scroll when cursor is inside this scroll margin. */
9661 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9663 if ((XFASTINT (w
->hscroll
)
9664 && w
->cursor
.x
<= h_margin
)
9665 || (cursor_row
->enabled_p
9666 && cursor_row
->truncated_on_right_p
9667 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9671 struct buffer
*saved_current_buffer
;
9675 /* Find point in a display of infinite width. */
9676 saved_current_buffer
= current_buffer
;
9677 current_buffer
= XBUFFER (w
->buffer
);
9679 if (w
== XWINDOW (selected_window
))
9680 pt
= BUF_PT (current_buffer
);
9683 pt
= marker_position (w
->pointm
);
9684 pt
= max (BEGV
, pt
);
9688 /* Move iterator to pt starting at cursor_row->start in
9689 a line with infinite width. */
9690 init_to_row_start (&it
, w
, cursor_row
);
9691 it
.last_visible_x
= INFINITY
;
9692 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9693 current_buffer
= saved_current_buffer
;
9695 /* Position cursor in window. */
9696 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9697 hscroll
= max (0, (it
.current_x
9698 - (ITERATOR_AT_END_OF_LINE_P (&it
)
9699 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
9700 : (text_area_width
/ 2))))
9701 / FRAME_COLUMN_WIDTH (it
.f
);
9702 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9704 if (hscroll_relative_p
)
9705 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9708 wanted_x
= text_area_width
9709 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9712 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9716 if (hscroll_relative_p
)
9717 wanted_x
= text_area_width
* hscroll_step_rel
9720 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9723 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9725 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9727 /* Don't call Fset_window_hscroll if value hasn't
9728 changed because it will prevent redisplay
9730 if (XFASTINT (w
->hscroll
) != hscroll
)
9732 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9733 w
->hscroll
= make_number (hscroll
);
9742 /* Value is non-zero if hscroll of any leaf window has been changed. */
9747 /* Set hscroll so that cursor is visible and not inside horizontal
9748 scroll margins for all windows in the tree rooted at WINDOW. See
9749 also hscroll_window_tree above. Value is non-zero if any window's
9750 hscroll has been changed. If it has, desired matrices on the frame
9751 of WINDOW are cleared. */
9754 hscroll_windows (window
)
9759 if (automatic_hscrolling_p
)
9761 hscrolled_p
= hscroll_window_tree (window
);
9763 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9772 /************************************************************************
9774 ************************************************************************/
9776 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9777 to a non-zero value. This is sometimes handy to have in a debugger
9782 /* First and last unchanged row for try_window_id. */
9784 int debug_first_unchanged_at_end_vpos
;
9785 int debug_last_unchanged_at_beg_vpos
;
9787 /* Delta vpos and y. */
9789 int debug_dvpos
, debug_dy
;
9791 /* Delta in characters and bytes for try_window_id. */
9793 int debug_delta
, debug_delta_bytes
;
9795 /* Values of window_end_pos and window_end_vpos at the end of
9798 EMACS_INT debug_end_pos
, debug_end_vpos
;
9800 /* Append a string to W->desired_matrix->method. FMT is a printf
9801 format string. A1...A9 are a supplement for a variable-length
9802 argument list. If trace_redisplay_p is non-zero also printf the
9803 resulting string to stderr. */
9806 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9809 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9812 char *method
= w
->desired_matrix
->method
;
9813 int len
= strlen (method
);
9814 int size
= sizeof w
->desired_matrix
->method
;
9815 int remaining
= size
- len
- 1;
9817 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9818 if (len
&& remaining
)
9824 strncpy (method
+ len
, buffer
, remaining
);
9826 if (trace_redisplay_p
)
9827 fprintf (stderr
, "%p (%s): %s\n",
9829 ((BUFFERP (w
->buffer
)
9830 && STRINGP (XBUFFER (w
->buffer
)->name
))
9831 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9836 #endif /* GLYPH_DEBUG */
9839 /* Value is non-zero if all changes in window W, which displays
9840 current_buffer, are in the text between START and END. START is a
9841 buffer position, END is given as a distance from Z. Used in
9842 redisplay_internal for display optimization. */
9845 text_outside_line_unchanged_p (w
, start
, end
)
9849 int unchanged_p
= 1;
9851 /* If text or overlays have changed, see where. */
9852 if (XFASTINT (w
->last_modified
) < MODIFF
9853 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9855 /* Gap in the line? */
9856 if (GPT
< start
|| Z
- GPT
< end
)
9859 /* Changes start in front of the line, or end after it? */
9861 && (BEG_UNCHANGED
< start
- 1
9862 || END_UNCHANGED
< end
))
9865 /* If selective display, can't optimize if changes start at the
9866 beginning of the line. */
9868 && INTEGERP (current_buffer
->selective_display
)
9869 && XINT (current_buffer
->selective_display
) > 0
9870 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9873 /* If there are overlays at the start or end of the line, these
9874 may have overlay strings with newlines in them. A change at
9875 START, for instance, may actually concern the display of such
9876 overlay strings as well, and they are displayed on different
9877 lines. So, quickly rule out this case. (For the future, it
9878 might be desirable to implement something more telling than
9879 just BEG/END_UNCHANGED.) */
9882 if (BEG
+ BEG_UNCHANGED
== start
9883 && overlay_touches_p (start
))
9885 if (END_UNCHANGED
== end
9886 && overlay_touches_p (Z
- end
))
9895 /* Do a frame update, taking possible shortcuts into account. This is
9896 the main external entry point for redisplay.
9898 If the last redisplay displayed an echo area message and that message
9899 is no longer requested, we clear the echo area or bring back the
9900 mini-buffer if that is in use. */
9905 redisplay_internal (0);
9910 overlay_arrow_string_or_property (var
)
9915 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
9918 return Voverlay_arrow_string
;
9921 /* Return 1 if there are any overlay-arrows in current_buffer. */
9923 overlay_arrow_in_current_buffer_p ()
9927 for (vlist
= Voverlay_arrow_variable_list
;
9929 vlist
= XCDR (vlist
))
9931 Lisp_Object var
= XCAR (vlist
);
9936 val
= find_symbol_value (var
);
9938 && current_buffer
== XMARKER (val
)->buffer
)
9945 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
9949 overlay_arrows_changed_p ()
9953 for (vlist
= Voverlay_arrow_variable_list
;
9955 vlist
= XCDR (vlist
))
9957 Lisp_Object var
= XCAR (vlist
);
9958 Lisp_Object val
, pstr
;
9962 val
= find_symbol_value (var
);
9965 if (! EQ (COERCE_MARKER (val
),
9966 Fget (var
, Qlast_arrow_position
))
9967 || ! (pstr
= overlay_arrow_string_or_property (var
),
9968 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
9974 /* Mark overlay arrows to be updated on next redisplay. */
9977 update_overlay_arrows (up_to_date
)
9982 for (vlist
= Voverlay_arrow_variable_list
;
9984 vlist
= XCDR (vlist
))
9986 Lisp_Object var
= XCAR (vlist
);
9993 Lisp_Object val
= find_symbol_value (var
);
9994 Fput (var
, Qlast_arrow_position
,
9995 COERCE_MARKER (val
));
9996 Fput (var
, Qlast_arrow_string
,
9997 overlay_arrow_string_or_property (var
));
9999 else if (up_to_date
< 0
10000 || !NILP (Fget (var
, Qlast_arrow_position
)))
10002 Fput (var
, Qlast_arrow_position
, Qt
);
10003 Fput (var
, Qlast_arrow_string
, Qt
);
10009 /* Return overlay arrow string to display at row.
10010 Return integer (bitmap number) for arrow bitmap in left fringe.
10011 Return nil if no overlay arrow. */
10014 overlay_arrow_at_row (it
, row
)
10016 struct glyph_row
*row
;
10020 for (vlist
= Voverlay_arrow_variable_list
;
10022 vlist
= XCDR (vlist
))
10024 Lisp_Object var
= XCAR (vlist
);
10027 if (!SYMBOLP (var
))
10030 val
= find_symbol_value (var
);
10033 && current_buffer
== XMARKER (val
)->buffer
10034 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10036 if (FRAME_WINDOW_P (it
->f
)
10037 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10039 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10042 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10043 return make_number (fringe_bitmap
);
10045 return make_number (-1); /* Use default arrow bitmap */
10047 return overlay_arrow_string_or_property (var
);
10054 /* Return 1 if point moved out of or into a composition. Otherwise
10055 return 0. PREV_BUF and PREV_PT are the last point buffer and
10056 position. BUF and PT are the current point buffer and position. */
10059 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10060 struct buffer
*prev_buf
, *buf
;
10063 EMACS_INT start
, end
;
10065 Lisp_Object buffer
;
10067 XSETBUFFER (buffer
, buf
);
10068 /* Check a composition at the last point if point moved within the
10070 if (prev_buf
== buf
)
10073 /* Point didn't move. */
10076 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10077 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10078 && COMPOSITION_VALID_P (start
, end
, prop
)
10079 && start
< prev_pt
&& end
> prev_pt
)
10080 /* The last point was within the composition. Return 1 iff
10081 point moved out of the composition. */
10082 return (pt
<= start
|| pt
>= end
);
10085 /* Check a composition at the current point. */
10086 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10087 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10088 && COMPOSITION_VALID_P (start
, end
, prop
)
10089 && start
< pt
&& end
> pt
);
10093 /* Reconsider the setting of B->clip_changed which is displayed
10097 reconsider_clip_changes (w
, b
)
10101 if (b
->clip_changed
10102 && !NILP (w
->window_end_valid
)
10103 && w
->current_matrix
->buffer
== b
10104 && w
->current_matrix
->zv
== BUF_ZV (b
)
10105 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10106 b
->clip_changed
= 0;
10108 /* If display wasn't paused, and W is not a tool bar window, see if
10109 point has been moved into or out of a composition. In that case,
10110 we set b->clip_changed to 1 to force updating the screen. If
10111 b->clip_changed has already been set to 1, we can skip this
10113 if (!b
->clip_changed
10114 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10118 if (w
== XWINDOW (selected_window
))
10119 pt
= BUF_PT (current_buffer
);
10121 pt
= marker_position (w
->pointm
);
10123 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10124 || pt
!= XINT (w
->last_point
))
10125 && check_point_in_composition (w
->current_matrix
->buffer
,
10126 XINT (w
->last_point
),
10127 XBUFFER (w
->buffer
), pt
))
10128 b
->clip_changed
= 1;
10133 /* Select FRAME to forward the values of frame-local variables into C
10134 variables so that the redisplay routines can access those values
10138 select_frame_for_redisplay (frame
)
10141 Lisp_Object tail
, sym
, val
;
10142 Lisp_Object old
= selected_frame
;
10144 selected_frame
= frame
;
10146 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10147 if (CONSP (XCAR (tail
))
10148 && (sym
= XCAR (XCAR (tail
)),
10150 && (sym
= indirect_variable (sym
),
10151 val
= SYMBOL_VALUE (sym
),
10152 (BUFFER_LOCAL_VALUEP (val
)
10153 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10154 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10155 Fsymbol_value (sym
);
10157 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10158 if (CONSP (XCAR (tail
))
10159 && (sym
= XCAR (XCAR (tail
)),
10161 && (sym
= indirect_variable (sym
),
10162 val
= SYMBOL_VALUE (sym
),
10163 (BUFFER_LOCAL_VALUEP (val
)
10164 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10165 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10166 Fsymbol_value (sym
);
10170 #define STOP_POLLING \
10171 do { if (! polling_stopped_here) stop_polling (); \
10172 polling_stopped_here = 1; } while (0)
10174 #define RESUME_POLLING \
10175 do { if (polling_stopped_here) start_polling (); \
10176 polling_stopped_here = 0; } while (0)
10179 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10180 response to any user action; therefore, we should preserve the echo
10181 area. (Actually, our caller does that job.) Perhaps in the future
10182 avoid recentering windows if it is not necessary; currently that
10183 causes some problems. */
10186 redisplay_internal (preserve_echo_area
)
10187 int preserve_echo_area
;
10189 struct window
*w
= XWINDOW (selected_window
);
10190 struct frame
*f
= XFRAME (w
->frame
);
10192 int must_finish
= 0;
10193 struct text_pos tlbufpos
, tlendpos
;
10194 int number_of_visible_frames
;
10196 struct frame
*sf
= SELECTED_FRAME ();
10197 int polling_stopped_here
= 0;
10199 /* Non-zero means redisplay has to consider all windows on all
10200 frames. Zero means, only selected_window is considered. */
10201 int consider_all_windows_p
;
10203 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10205 /* No redisplay if running in batch mode or frame is not yet fully
10206 initialized, or redisplay is explicitly turned off by setting
10207 Vinhibit_redisplay. */
10209 || !NILP (Vinhibit_redisplay
)
10210 || !f
->glyphs_initialized_p
)
10213 /* The flag redisplay_performed_directly_p is set by
10214 direct_output_for_insert when it already did the whole screen
10215 update necessary. */
10216 if (redisplay_performed_directly_p
)
10218 redisplay_performed_directly_p
= 0;
10219 if (!hscroll_windows (selected_window
))
10223 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
10224 if (popup_activated ())
10228 /* I don't think this happens but let's be paranoid. */
10229 if (redisplaying_p
)
10232 /* Record a function that resets redisplaying_p to its old value
10233 when we leave this function. */
10234 count
= SPECPDL_INDEX ();
10235 record_unwind_protect (unwind_redisplay
,
10236 Fcons (make_number (redisplaying_p
), selected_frame
));
10238 specbind (Qinhibit_free_realized_faces
, Qnil
);
10242 reconsider_clip_changes (w
, current_buffer
);
10244 /* If new fonts have been loaded that make a glyph matrix adjustment
10245 necessary, do it. */
10246 if (fonts_changed_p
)
10248 adjust_glyphs (NULL
);
10249 ++windows_or_buffers_changed
;
10250 fonts_changed_p
= 0;
10253 /* If face_change_count is non-zero, init_iterator will free all
10254 realized faces, which includes the faces referenced from current
10255 matrices. So, we can't reuse current matrices in this case. */
10256 if (face_change_count
)
10257 ++windows_or_buffers_changed
;
10259 if (! FRAME_WINDOW_P (sf
)
10260 && previous_terminal_frame
!= sf
)
10262 /* Since frames on an ASCII terminal share the same display
10263 area, displaying a different frame means redisplay the whole
10265 windows_or_buffers_changed
++;
10266 SET_FRAME_GARBAGED (sf
);
10267 XSETFRAME (Vterminal_frame
, sf
);
10269 previous_terminal_frame
= sf
;
10271 /* Set the visible flags for all frames. Do this before checking
10272 for resized or garbaged frames; they want to know if their frames
10273 are visible. See the comment in frame.h for
10274 FRAME_SAMPLE_VISIBILITY. */
10276 Lisp_Object tail
, frame
;
10278 number_of_visible_frames
= 0;
10280 FOR_EACH_FRAME (tail
, frame
)
10282 struct frame
*f
= XFRAME (frame
);
10284 FRAME_SAMPLE_VISIBILITY (f
);
10285 if (FRAME_VISIBLE_P (f
))
10286 ++number_of_visible_frames
;
10287 clear_desired_matrices (f
);
10291 /* Notice any pending interrupt request to change frame size. */
10292 do_pending_window_change (1);
10294 /* Clear frames marked as garbaged. */
10295 if (frame_garbaged
)
10296 clear_garbaged_frames ();
10298 /* Build menubar and tool-bar items. */
10299 prepare_menu_bars ();
10301 if (windows_or_buffers_changed
)
10302 update_mode_lines
++;
10304 /* Detect case that we need to write or remove a star in the mode line. */
10305 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10307 w
->update_mode_line
= Qt
;
10308 if (buffer_shared
> 1)
10309 update_mode_lines
++;
10312 /* If %c is in the mode line, update it if needed. */
10313 if (!NILP (w
->column_number_displayed
)
10314 /* This alternative quickly identifies a common case
10315 where no change is needed. */
10316 && !(PT
== XFASTINT (w
->last_point
)
10317 && XFASTINT (w
->last_modified
) >= MODIFF
10318 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10319 && (XFASTINT (w
->column_number_displayed
)
10320 != (int) current_column ())) /* iftc */
10321 w
->update_mode_line
= Qt
;
10323 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10325 /* The variable buffer_shared is set in redisplay_window and
10326 indicates that we redisplay a buffer in different windows. See
10328 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10329 || cursor_type_changed
);
10331 /* If specs for an arrow have changed, do thorough redisplay
10332 to ensure we remove any arrow that should no longer exist. */
10333 if (overlay_arrows_changed_p ())
10334 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10336 /* Normally the message* functions will have already displayed and
10337 updated the echo area, but the frame may have been trashed, or
10338 the update may have been preempted, so display the echo area
10339 again here. Checking message_cleared_p captures the case that
10340 the echo area should be cleared. */
10341 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10342 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10343 || (message_cleared_p
10344 && minibuf_level
== 0
10345 /* If the mini-window is currently selected, this means the
10346 echo-area doesn't show through. */
10347 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10349 int window_height_changed_p
= echo_area_display (0);
10352 /* If we don't display the current message, don't clear the
10353 message_cleared_p flag, because, if we did, we wouldn't clear
10354 the echo area in the next redisplay which doesn't preserve
10356 if (!display_last_displayed_message_p
)
10357 message_cleared_p
= 0;
10359 if (fonts_changed_p
)
10361 else if (window_height_changed_p
)
10363 consider_all_windows_p
= 1;
10364 ++update_mode_lines
;
10365 ++windows_or_buffers_changed
;
10367 /* If window configuration was changed, frames may have been
10368 marked garbaged. Clear them or we will experience
10369 surprises wrt scrolling. */
10370 if (frame_garbaged
)
10371 clear_garbaged_frames ();
10374 else if (EQ (selected_window
, minibuf_window
)
10375 && (current_buffer
->clip_changed
10376 || XFASTINT (w
->last_modified
) < MODIFF
10377 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10378 && resize_mini_window (w
, 0))
10380 /* Resized active mini-window to fit the size of what it is
10381 showing if its contents might have changed. */
10383 consider_all_windows_p
= 1;
10384 ++windows_or_buffers_changed
;
10385 ++update_mode_lines
;
10387 /* If window configuration was changed, frames may have been
10388 marked garbaged. Clear them or we will experience
10389 surprises wrt scrolling. */
10390 if (frame_garbaged
)
10391 clear_garbaged_frames ();
10395 /* If showing the region, and mark has changed, we must redisplay
10396 the whole window. The assignment to this_line_start_pos prevents
10397 the optimization directly below this if-statement. */
10398 if (((!NILP (Vtransient_mark_mode
)
10399 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10400 != !NILP (w
->region_showing
))
10401 || (!NILP (w
->region_showing
)
10402 && !EQ (w
->region_showing
,
10403 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
10404 CHARPOS (this_line_start_pos
) = 0;
10406 /* Optimize the case that only the line containing the cursor in the
10407 selected window has changed. Variables starting with this_ are
10408 set in display_line and record information about the line
10409 containing the cursor. */
10410 tlbufpos
= this_line_start_pos
;
10411 tlendpos
= this_line_end_pos
;
10412 if (!consider_all_windows_p
10413 && CHARPOS (tlbufpos
) > 0
10414 && NILP (w
->update_mode_line
)
10415 && !current_buffer
->clip_changed
10416 && !current_buffer
->prevent_redisplay_optimizations_p
10417 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
10418 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
10419 /* Make sure recorded data applies to current buffer, etc. */
10420 && this_line_buffer
== current_buffer
10421 && current_buffer
== XBUFFER (w
->buffer
)
10422 && NILP (w
->force_start
)
10423 && NILP (w
->optional_new_start
)
10424 /* Point must be on the line that we have info recorded about. */
10425 && PT
>= CHARPOS (tlbufpos
)
10426 && PT
<= Z
- CHARPOS (tlendpos
)
10427 /* All text outside that line, including its final newline,
10428 must be unchanged */
10429 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
10430 CHARPOS (tlendpos
)))
10432 if (CHARPOS (tlbufpos
) > BEGV
10433 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
10434 && (CHARPOS (tlbufpos
) == ZV
10435 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
10436 /* Former continuation line has disappeared by becoming empty */
10438 else if (XFASTINT (w
->last_modified
) < MODIFF
10439 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
10440 || MINI_WINDOW_P (w
))
10442 /* We have to handle the case of continuation around a
10443 wide-column character (See the comment in indent.c around
10446 For instance, in the following case:
10448 -------- Insert --------
10449 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
10450 J_I_ ==> J_I_ `^^' are cursors.
10454 As we have to redraw the line above, we should goto cancel. */
10457 int line_height_before
= this_line_pixel_height
;
10459 /* Note that start_display will handle the case that the
10460 line starting at tlbufpos is a continuation lines. */
10461 start_display (&it
, w
, tlbufpos
);
10463 /* Implementation note: It this still necessary? */
10464 if (it
.current_x
!= this_line_start_x
)
10467 TRACE ((stderr
, "trying display optimization 1\n"));
10468 w
->cursor
.vpos
= -1;
10469 overlay_arrow_seen
= 0;
10470 it
.vpos
= this_line_vpos
;
10471 it
.current_y
= this_line_y
;
10472 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10473 display_line (&it
);
10475 /* If line contains point, is not continued,
10476 and ends at same distance from eob as before, we win */
10477 if (w
->cursor
.vpos
>= 0
10478 /* Line is not continued, otherwise this_line_start_pos
10479 would have been set to 0 in display_line. */
10480 && CHARPOS (this_line_start_pos
)
10481 /* Line ends as before. */
10482 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10483 /* Line has same height as before. Otherwise other lines
10484 would have to be shifted up or down. */
10485 && this_line_pixel_height
== line_height_before
)
10487 /* If this is not the window's last line, we must adjust
10488 the charstarts of the lines below. */
10489 if (it
.current_y
< it
.last_visible_y
)
10491 struct glyph_row
*row
10492 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10493 int delta
, delta_bytes
;
10495 if (Z
- CHARPOS (tlendpos
) == ZV
)
10497 /* This line ends at end of (accessible part of)
10498 buffer. There is no newline to count. */
10500 - CHARPOS (tlendpos
)
10501 - MATRIX_ROW_START_CHARPOS (row
));
10502 delta_bytes
= (Z_BYTE
10503 - BYTEPOS (tlendpos
)
10504 - MATRIX_ROW_START_BYTEPOS (row
));
10508 /* This line ends in a newline. Must take
10509 account of the newline and the rest of the
10510 text that follows. */
10512 - CHARPOS (tlendpos
)
10513 - MATRIX_ROW_START_CHARPOS (row
));
10514 delta_bytes
= (Z_BYTE
10515 - BYTEPOS (tlendpos
)
10516 - MATRIX_ROW_START_BYTEPOS (row
));
10519 increment_matrix_positions (w
->current_matrix
,
10520 this_line_vpos
+ 1,
10521 w
->current_matrix
->nrows
,
10522 delta
, delta_bytes
);
10525 /* If this row displays text now but previously didn't,
10526 or vice versa, w->window_end_vpos may have to be
10528 if ((it
.glyph_row
- 1)->displays_text_p
)
10530 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10531 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10533 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10534 && this_line_vpos
> 0)
10535 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10536 w
->window_end_valid
= Qnil
;
10538 /* Update hint: No need to try to scroll in update_window. */
10539 w
->desired_matrix
->no_scrolling_p
= 1;
10542 *w
->desired_matrix
->method
= 0;
10543 debug_method_add (w
, "optimization 1");
10545 #ifdef HAVE_WINDOW_SYSTEM
10546 update_window_fringes (w
, 0);
10553 else if (/* Cursor position hasn't changed. */
10554 PT
== XFASTINT (w
->last_point
)
10555 /* Make sure the cursor was last displayed
10556 in this window. Otherwise we have to reposition it. */
10557 && 0 <= w
->cursor
.vpos
10558 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10562 do_pending_window_change (1);
10564 /* We used to always goto end_of_redisplay here, but this
10565 isn't enough if we have a blinking cursor. */
10566 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10567 goto end_of_redisplay
;
10571 /* If highlighting the region, or if the cursor is in the echo area,
10572 then we can't just move the cursor. */
10573 else if (! (!NILP (Vtransient_mark_mode
)
10574 && !NILP (current_buffer
->mark_active
))
10575 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10576 || highlight_nonselected_windows
)
10577 && NILP (w
->region_showing
)
10578 && NILP (Vshow_trailing_whitespace
)
10579 && !cursor_in_echo_area
)
10582 struct glyph_row
*row
;
10584 /* Skip from tlbufpos to PT and see where it is. Note that
10585 PT may be in invisible text. If so, we will end at the
10586 next visible position. */
10587 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10588 NULL
, DEFAULT_FACE_ID
);
10589 it
.current_x
= this_line_start_x
;
10590 it
.current_y
= this_line_y
;
10591 it
.vpos
= this_line_vpos
;
10593 /* The call to move_it_to stops in front of PT, but
10594 moves over before-strings. */
10595 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10597 if (it
.vpos
== this_line_vpos
10598 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10601 xassert (this_line_vpos
== it
.vpos
);
10602 xassert (this_line_y
== it
.current_y
);
10603 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10605 *w
->desired_matrix
->method
= 0;
10606 debug_method_add (w
, "optimization 3");
10615 /* Text changed drastically or point moved off of line. */
10616 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10619 CHARPOS (this_line_start_pos
) = 0;
10620 consider_all_windows_p
|= buffer_shared
> 1;
10621 ++clear_face_cache_count
;
10622 #ifdef HAVE_WINDOW_SYSTEM
10623 ++clear_image_cache_count
;
10626 /* Build desired matrices, and update the display. If
10627 consider_all_windows_p is non-zero, do it for all windows on all
10628 frames. Otherwise do it for selected_window, only. */
10630 if (consider_all_windows_p
)
10632 Lisp_Object tail
, frame
;
10633 int i
, n
= 0, size
= 50;
10634 struct frame
**updated
10635 = (struct frame
**) alloca (size
* sizeof *updated
);
10637 /* Recompute # windows showing selected buffer. This will be
10638 incremented each time such a window is displayed. */
10641 FOR_EACH_FRAME (tail
, frame
)
10643 struct frame
*f
= XFRAME (frame
);
10645 if (FRAME_WINDOW_P (f
) || f
== sf
)
10647 if (! EQ (frame
, selected_frame
))
10648 /* Select the frame, for the sake of frame-local
10650 select_frame_for_redisplay (frame
);
10652 /* Mark all the scroll bars to be removed; we'll redeem
10653 the ones we want when we redisplay their windows. */
10654 if (condemn_scroll_bars_hook
)
10655 condemn_scroll_bars_hook (f
);
10657 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10658 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10660 /* Any scroll bars which redisplay_windows should have
10661 nuked should now go away. */
10662 if (judge_scroll_bars_hook
)
10663 judge_scroll_bars_hook (f
);
10665 /* If fonts changed, display again. */
10666 /* ??? rms: I suspect it is a mistake to jump all the way
10667 back to retry here. It should just retry this frame. */
10668 if (fonts_changed_p
)
10671 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10673 /* See if we have to hscroll. */
10674 if (hscroll_windows (f
->root_window
))
10677 /* Prevent various kinds of signals during display
10678 update. stdio is not robust about handling
10679 signals, which can cause an apparent I/O
10681 if (interrupt_input
)
10682 unrequest_sigio ();
10685 /* Update the display. */
10686 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10687 pause
|= update_frame (f
, 0, 0);
10688 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10695 int nbytes
= size
* sizeof *updated
;
10696 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
10697 bcopy (updated
, p
, nbytes
);
10708 /* Do the mark_window_display_accurate after all windows have
10709 been redisplayed because this call resets flags in buffers
10710 which are needed for proper redisplay. */
10711 for (i
= 0; i
< n
; ++i
)
10713 struct frame
*f
= updated
[i
];
10714 mark_window_display_accurate (f
->root_window
, 1);
10715 if (frame_up_to_date_hook
)
10716 frame_up_to_date_hook (f
);
10720 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10722 Lisp_Object mini_window
;
10723 struct frame
*mini_frame
;
10725 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10726 /* Use list_of_error, not Qerror, so that
10727 we catch only errors and don't run the debugger. */
10728 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10730 redisplay_window_error
);
10732 /* Compare desired and current matrices, perform output. */
10735 /* If fonts changed, display again. */
10736 if (fonts_changed_p
)
10739 /* Prevent various kinds of signals during display update.
10740 stdio is not robust about handling signals,
10741 which can cause an apparent I/O error. */
10742 if (interrupt_input
)
10743 unrequest_sigio ();
10746 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10748 if (hscroll_windows (selected_window
))
10751 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10752 pause
= update_frame (sf
, 0, 0);
10755 /* We may have called echo_area_display at the top of this
10756 function. If the echo area is on another frame, that may
10757 have put text on a frame other than the selected one, so the
10758 above call to update_frame would not have caught it. Catch
10760 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10761 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10763 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10765 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10766 pause
|= update_frame (mini_frame
, 0, 0);
10767 if (!pause
&& hscroll_windows (mini_window
))
10772 /* If display was paused because of pending input, make sure we do a
10773 thorough update the next time. */
10776 /* Prevent the optimization at the beginning of
10777 redisplay_internal that tries a single-line update of the
10778 line containing the cursor in the selected window. */
10779 CHARPOS (this_line_start_pos
) = 0;
10781 /* Let the overlay arrow be updated the next time. */
10782 update_overlay_arrows (0);
10784 /* If we pause after scrolling, some rows in the current
10785 matrices of some windows are not valid. */
10786 if (!WINDOW_FULL_WIDTH_P (w
)
10787 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10788 update_mode_lines
= 1;
10792 if (!consider_all_windows_p
)
10794 /* This has already been done above if
10795 consider_all_windows_p is set. */
10796 mark_window_display_accurate_1 (w
, 1);
10798 /* Say overlay arrows are up to date. */
10799 update_overlay_arrows (1);
10801 if (frame_up_to_date_hook
!= 0)
10802 frame_up_to_date_hook (sf
);
10805 update_mode_lines
= 0;
10806 windows_or_buffers_changed
= 0;
10807 cursor_type_changed
= 0;
10810 /* Start SIGIO interrupts coming again. Having them off during the
10811 code above makes it less likely one will discard output, but not
10812 impossible, since there might be stuff in the system buffer here.
10813 But it is much hairier to try to do anything about that. */
10814 if (interrupt_input
)
10818 /* If a frame has become visible which was not before, redisplay
10819 again, so that we display it. Expose events for such a frame
10820 (which it gets when becoming visible) don't call the parts of
10821 redisplay constructing glyphs, so simply exposing a frame won't
10822 display anything in this case. So, we have to display these
10823 frames here explicitly. */
10826 Lisp_Object tail
, frame
;
10829 FOR_EACH_FRAME (tail
, frame
)
10831 int this_is_visible
= 0;
10833 if (XFRAME (frame
)->visible
)
10834 this_is_visible
= 1;
10835 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10836 if (XFRAME (frame
)->visible
)
10837 this_is_visible
= 1;
10839 if (this_is_visible
)
10843 if (new_count
!= number_of_visible_frames
)
10844 windows_or_buffers_changed
++;
10847 /* Change frame size now if a change is pending. */
10848 do_pending_window_change (1);
10850 /* If we just did a pending size change, or have additional
10851 visible frames, redisplay again. */
10852 if (windows_or_buffers_changed
&& !pause
)
10855 /* Clear the face cache eventually. */
10856 if (consider_all_windows_p
)
10858 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
10860 clear_face_cache (0);
10861 clear_face_cache_count
= 0;
10863 #ifdef HAVE_WINDOW_SYSTEM
10864 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
10866 Lisp_Object tail
, frame
;
10867 FOR_EACH_FRAME (tail
, frame
)
10869 struct frame
*f
= XFRAME (frame
);
10870 if (FRAME_WINDOW_P (f
))
10871 clear_image_cache (f
, 0);
10873 clear_image_cache_count
= 0;
10875 #endif /* HAVE_WINDOW_SYSTEM */
10879 unbind_to (count
, Qnil
);
10884 /* Redisplay, but leave alone any recent echo area message unless
10885 another message has been requested in its place.
10887 This is useful in situations where you need to redisplay but no
10888 user action has occurred, making it inappropriate for the message
10889 area to be cleared. See tracking_off and
10890 wait_reading_process_output for examples of these situations.
10892 FROM_WHERE is an integer saying from where this function was
10893 called. This is useful for debugging. */
10896 redisplay_preserve_echo_area (from_where
)
10899 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10901 if (!NILP (echo_area_buffer
[1]))
10903 /* We have a previously displayed message, but no current
10904 message. Redisplay the previous message. */
10905 display_last_displayed_message_p
= 1;
10906 redisplay_internal (1);
10907 display_last_displayed_message_p
= 0;
10910 redisplay_internal (1);
10912 if (rif
!= NULL
&& rif
->flush_display_optional
)
10913 rif
->flush_display_optional (NULL
);
10917 /* Function registered with record_unwind_protect in
10918 redisplay_internal. Reset redisplaying_p to the value it had
10919 before redisplay_internal was called, and clear
10920 prevent_freeing_realized_faces_p. It also selects the previously
10924 unwind_redisplay (val
)
10927 Lisp_Object old_redisplaying_p
, old_frame
;
10929 old_redisplaying_p
= XCAR (val
);
10930 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10931 old_frame
= XCDR (val
);
10932 if (! EQ (old_frame
, selected_frame
))
10933 select_frame_for_redisplay (old_frame
);
10938 /* Mark the display of window W as accurate or inaccurate. If
10939 ACCURATE_P is non-zero mark display of W as accurate. If
10940 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10941 redisplay_internal is called. */
10944 mark_window_display_accurate_1 (w
, accurate_p
)
10948 if (BUFFERP (w
->buffer
))
10950 struct buffer
*b
= XBUFFER (w
->buffer
);
10953 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
10954 w
->last_overlay_modified
10955 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
10957 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
10961 b
->clip_changed
= 0;
10962 b
->prevent_redisplay_optimizations_p
= 0;
10964 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
10965 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
10966 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
10967 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
10969 w
->current_matrix
->buffer
= b
;
10970 w
->current_matrix
->begv
= BUF_BEGV (b
);
10971 w
->current_matrix
->zv
= BUF_ZV (b
);
10973 w
->last_cursor
= w
->cursor
;
10974 w
->last_cursor_off_p
= w
->cursor_off_p
;
10976 if (w
== XWINDOW (selected_window
))
10977 w
->last_point
= make_number (BUF_PT (b
));
10979 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
10985 w
->window_end_valid
= w
->buffer
;
10986 #if 0 /* This is incorrect with variable-height lines. */
10987 xassert (XINT (w
->window_end_vpos
)
10988 < (WINDOW_TOTAL_LINES (w
)
10989 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
10991 w
->update_mode_line
= Qnil
;
10996 /* Mark the display of windows in the window tree rooted at WINDOW as
10997 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
10998 windows as accurate. If ACCURATE_P is zero, arrange for windows to
10999 be redisplayed the next time redisplay_internal is called. */
11002 mark_window_display_accurate (window
, accurate_p
)
11003 Lisp_Object window
;
11008 for (; !NILP (window
); window
= w
->next
)
11010 w
= XWINDOW (window
);
11011 mark_window_display_accurate_1 (w
, accurate_p
);
11013 if (!NILP (w
->vchild
))
11014 mark_window_display_accurate (w
->vchild
, accurate_p
);
11015 if (!NILP (w
->hchild
))
11016 mark_window_display_accurate (w
->hchild
, accurate_p
);
11021 update_overlay_arrows (1);
11025 /* Force a thorough redisplay the next time by setting
11026 last_arrow_position and last_arrow_string to t, which is
11027 unequal to any useful value of Voverlay_arrow_... */
11028 update_overlay_arrows (-1);
11033 /* Return value in display table DP (Lisp_Char_Table *) for character
11034 C. Since a display table doesn't have any parent, we don't have to
11035 follow parent. Do not call this function directly but use the
11036 macro DISP_CHAR_VECTOR. */
11039 disp_char_vector (dp
, c
)
11040 struct Lisp_Char_Table
*dp
;
11045 if (ASCII_CHAR_P (c
))
11048 if (SUB_CHAR_TABLE_P (val
))
11049 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
11055 XSETCHAR_TABLE (table
, dp
);
11056 val
= char_table_ref (table
, c
);
11065 /***********************************************************************
11067 ***********************************************************************/
11069 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11072 redisplay_windows (window
)
11073 Lisp_Object window
;
11075 while (!NILP (window
))
11077 struct window
*w
= XWINDOW (window
);
11079 if (!NILP (w
->hchild
))
11080 redisplay_windows (w
->hchild
);
11081 else if (!NILP (w
->vchild
))
11082 redisplay_windows (w
->vchild
);
11085 displayed_buffer
= XBUFFER (w
->buffer
);
11086 /* Use list_of_error, not Qerror, so that
11087 we catch only errors and don't run the debugger. */
11088 internal_condition_case_1 (redisplay_window_0
, window
,
11090 redisplay_window_error
);
11098 redisplay_window_error ()
11100 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11105 redisplay_window_0 (window
)
11106 Lisp_Object window
;
11108 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11109 redisplay_window (window
, 0);
11114 redisplay_window_1 (window
)
11115 Lisp_Object window
;
11117 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11118 redisplay_window (window
, 1);
11123 /* Increment GLYPH until it reaches END or CONDITION fails while
11124 adding (GLYPH)->pixel_width to X. */
11126 #define SKIP_GLYPHS(glyph, end, x, condition) \
11129 (x) += (glyph)->pixel_width; \
11132 while ((glyph) < (end) && (condition))
11135 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11136 DELTA is the number of bytes by which positions recorded in ROW
11137 differ from current buffer positions. */
11140 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11142 struct glyph_row
*row
;
11143 struct glyph_matrix
*matrix
;
11144 int delta
, delta_bytes
, dy
, dvpos
;
11146 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11147 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11148 struct glyph
*cursor
= NULL
;
11149 /* The first glyph that starts a sequence of glyphs from string. */
11150 struct glyph
*string_start
;
11151 /* The X coordinate of string_start. */
11152 int string_start_x
;
11153 /* The last known character position. */
11154 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11155 /* The last known character position before string_start. */
11156 int string_before_pos
;
11159 int cursor_from_overlay_pos
= 0;
11160 int pt_old
= PT
- delta
;
11162 /* Skip over glyphs not having an object at the start of the row.
11163 These are special glyphs like truncation marks on terminal
11165 if (row
->displays_text_p
)
11167 && INTEGERP (glyph
->object
)
11168 && glyph
->charpos
< 0)
11170 x
+= glyph
->pixel_width
;
11174 string_start
= NULL
;
11176 && !INTEGERP (glyph
->object
)
11177 && (!BUFFERP (glyph
->object
)
11178 || (last_pos
= glyph
->charpos
) < pt_old
))
11180 if (! STRINGP (glyph
->object
))
11182 string_start
= NULL
;
11183 x
+= glyph
->pixel_width
;
11185 if (cursor_from_overlay_pos
11186 && last_pos
> cursor_from_overlay_pos
)
11188 cursor_from_overlay_pos
= 0;
11194 string_before_pos
= last_pos
;
11195 string_start
= glyph
;
11196 string_start_x
= x
;
11197 /* Skip all glyphs from string. */
11201 if ((cursor
== NULL
|| glyph
> cursor
)
11202 && !NILP (Fget_char_property (make_number ((glyph
)->charpos
),
11203 Qcursor
, (glyph
)->object
))
11204 && (pos
= string_buffer_position (w
, glyph
->object
,
11205 string_before_pos
),
11206 (pos
== 0 /* From overlay */
11207 || pos
== pt_old
)))
11209 /* Estimate overlay buffer position from the buffer
11210 positions of the glyphs before and after the overlay.
11211 Add 1 to last_pos so that if point corresponds to the
11212 glyph right after the overlay, we still use a 'cursor'
11213 property found in that overlay. */
11214 cursor_from_overlay_pos
= pos
== 0 ? last_pos
+1 : 0;
11218 x
+= glyph
->pixel_width
;
11221 while (glyph
< end
&& STRINGP (glyph
->object
));
11225 if (cursor
!= NULL
)
11230 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
11232 /* Scan back over the ellipsis glyphs, decrementing positions. */
11233 while (glyph
> row
->glyphs
[TEXT_AREA
]
11234 && (glyph
- 1)->charpos
== last_pos
)
11235 glyph
--, x
-= glyph
->pixel_width
;
11236 /* That loop always goes one position too far,
11237 including the glyph before the ellipsis.
11238 So scan forward over that one. */
11239 x
+= glyph
->pixel_width
;
11242 else if (string_start
11243 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11245 /* We may have skipped over point because the previous glyphs
11246 are from string. As there's no easy way to know the
11247 character position of the current glyph, find the correct
11248 glyph on point by scanning from string_start again. */
11250 Lisp_Object string
;
11253 limit
= make_number (pt_old
+ 1);
11255 glyph
= string_start
;
11256 x
= string_start_x
;
11257 string
= glyph
->object
;
11258 pos
= string_buffer_position (w
, string
, string_before_pos
);
11259 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11260 because we always put cursor after overlay strings. */
11261 while (pos
== 0 && glyph
< end
)
11263 string
= glyph
->object
;
11264 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11266 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11269 while (glyph
< end
)
11271 pos
= XINT (Fnext_single_char_property_change
11272 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11275 /* Skip glyphs from the same string. */
11276 string
= glyph
->object
;
11277 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11278 /* Skip glyphs from an overlay. */
11280 && ! string_buffer_position (w
, glyph
->object
, pos
))
11282 string
= glyph
->object
;
11283 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11288 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11290 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11291 w
->cursor
.y
= row
->y
+ dy
;
11293 if (w
== XWINDOW (selected_window
))
11295 if (!row
->continued_p
11296 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11299 this_line_buffer
= XBUFFER (w
->buffer
);
11301 CHARPOS (this_line_start_pos
)
11302 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11303 BYTEPOS (this_line_start_pos
)
11304 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
11306 CHARPOS (this_line_end_pos
)
11307 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
11308 BYTEPOS (this_line_end_pos
)
11309 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
11311 this_line_y
= w
->cursor
.y
;
11312 this_line_pixel_height
= row
->height
;
11313 this_line_vpos
= w
->cursor
.vpos
;
11314 this_line_start_x
= row
->x
;
11317 CHARPOS (this_line_start_pos
) = 0;
11322 /* Run window scroll functions, if any, for WINDOW with new window
11323 start STARTP. Sets the window start of WINDOW to that position.
11325 We assume that the window's buffer is really current. */
11327 static INLINE
struct text_pos
11328 run_window_scroll_functions (window
, startp
)
11329 Lisp_Object window
;
11330 struct text_pos startp
;
11332 struct window
*w
= XWINDOW (window
);
11333 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
11335 if (current_buffer
!= XBUFFER (w
->buffer
))
11338 if (!NILP (Vwindow_scroll_functions
))
11340 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
11341 make_number (CHARPOS (startp
)));
11342 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11343 /* In case the hook functions switch buffers. */
11344 if (current_buffer
!= XBUFFER (w
->buffer
))
11345 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11352 /* Make sure the line containing the cursor is fully visible.
11353 A value of 1 means there is nothing to be done.
11354 (Either the line is fully visible, or it cannot be made so,
11355 or we cannot tell.)
11357 If FORCE_P is non-zero, return 0 even if partial visible cursor row
11358 is higher than window.
11360 A value of 0 means the caller should do scrolling
11361 as if point had gone off the screen. */
11364 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
11368 struct glyph_matrix
*matrix
;
11369 struct glyph_row
*row
;
11372 if (!make_cursor_line_fully_visible_p
)
11375 /* It's not always possible to find the cursor, e.g, when a window
11376 is full of overlay strings. Don't do anything in that case. */
11377 if (w
->cursor
.vpos
< 0)
11380 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
11381 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
11383 /* If the cursor row is not partially visible, there's nothing to do. */
11384 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
11387 /* If the row the cursor is in is taller than the window's height,
11388 it's not clear what to do, so do nothing. */
11389 window_height
= window_box_height (w
);
11390 if (row
->height
>= window_height
)
11392 if (!force_p
|| w
->vscroll
)
11398 /* This code used to try to scroll the window just enough to make
11399 the line visible. It returned 0 to say that the caller should
11400 allocate larger glyph matrices. */
11402 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
11404 int dy
= row
->height
- row
->visible_height
;
11407 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11409 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
11411 int dy
= - (row
->height
- row
->visible_height
);
11414 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11417 /* When we change the cursor y-position of the selected window,
11418 change this_line_y as well so that the display optimization for
11419 the cursor line of the selected window in redisplay_internal uses
11420 the correct y-position. */
11421 if (w
== XWINDOW (selected_window
))
11422 this_line_y
= w
->cursor
.y
;
11424 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
11425 redisplay with larger matrices. */
11426 if (matrix
->nrows
< required_matrix_height (w
))
11428 fonts_changed_p
= 1;
11437 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
11438 non-zero means only WINDOW is redisplayed in redisplay_internal.
11439 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
11440 in redisplay_window to bring a partially visible line into view in
11441 the case that only the cursor has moved.
11443 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
11444 last screen line's vertical height extends past the end of the screen.
11448 1 if scrolling succeeded
11450 0 if scrolling didn't find point.
11452 -1 if new fonts have been loaded so that we must interrupt
11453 redisplay, adjust glyph matrices, and try again. */
11459 SCROLLING_NEED_LARGER_MATRICES
11463 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
11464 scroll_step
, temp_scroll_step
, last_line_misfit
)
11465 Lisp_Object window
;
11466 int just_this_one_p
;
11467 EMACS_INT scroll_conservatively
, scroll_step
;
11468 int temp_scroll_step
;
11469 int last_line_misfit
;
11471 struct window
*w
= XWINDOW (window
);
11472 struct frame
*f
= XFRAME (w
->frame
);
11473 struct text_pos scroll_margin_pos
;
11474 struct text_pos pos
;
11475 struct text_pos startp
;
11477 Lisp_Object window_end
;
11478 int this_scroll_margin
;
11482 int amount_to_scroll
= 0;
11483 Lisp_Object aggressive
;
11485 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
11488 debug_method_add (w
, "try_scrolling");
11491 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11493 /* Compute scroll margin height in pixels. We scroll when point is
11494 within this distance from the top or bottom of the window. */
11495 if (scroll_margin
> 0)
11497 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11498 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11501 this_scroll_margin
= 0;
11503 /* Force scroll_conservatively to have a reasonable value so it doesn't
11504 cause an overflow while computing how much to scroll. */
11505 if (scroll_conservatively
)
11506 scroll_conservatively
= min (scroll_conservatively
,
11507 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
11509 /* Compute how much we should try to scroll maximally to bring point
11511 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11512 scroll_max
= max (scroll_step
,
11513 max (scroll_conservatively
, temp_scroll_step
));
11514 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11515 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11516 /* We're trying to scroll because of aggressive scrolling
11517 but no scroll_step is set. Choose an arbitrary one. Maybe
11518 there should be a variable for this. */
11522 scroll_max
*= FRAME_LINE_HEIGHT (f
);
11524 /* Decide whether we have to scroll down. Start at the window end
11525 and move this_scroll_margin up to find the position of the scroll
11527 window_end
= Fwindow_end (window
, Qt
);
11531 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
11532 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
11534 if (this_scroll_margin
|| extra_scroll_margin_lines
)
11536 start_display (&it
, w
, scroll_margin_pos
);
11537 if (this_scroll_margin
)
11538 move_it_vertically_backward (&it
, this_scroll_margin
);
11539 if (extra_scroll_margin_lines
)
11540 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
11541 scroll_margin_pos
= it
.current
.pos
;
11544 if (PT
>= CHARPOS (scroll_margin_pos
))
11548 /* Point is in the scroll margin at the bottom of the window, or
11549 below. Compute a new window start that makes point visible. */
11551 /* Compute the distance from the scroll margin to PT.
11552 Give up if the distance is greater than scroll_max. */
11553 start_display (&it
, w
, scroll_margin_pos
);
11555 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11556 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11558 /* To make point visible, we have to move the window start
11559 down so that the line the cursor is in is visible, which
11560 means we have to add in the height of the cursor line. */
11561 dy
= line_bottom_y (&it
) - y0
;
11563 if (dy
> scroll_max
)
11564 return SCROLLING_FAILED
;
11566 /* Move the window start down. If scrolling conservatively,
11567 move it just enough down to make point visible. If
11568 scroll_step is set, move it down by scroll_step. */
11569 start_display (&it
, w
, startp
);
11571 if (scroll_conservatively
)
11572 /* Set AMOUNT_TO_SCROLL to at least one line,
11573 and at most scroll_conservatively lines. */
11575 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11576 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11577 else if (scroll_step
|| temp_scroll_step
)
11578 amount_to_scroll
= scroll_max
;
11581 aggressive
= current_buffer
->scroll_up_aggressively
;
11582 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11583 if (NUMBERP (aggressive
))
11585 double float_amount
= XFLOATINT (aggressive
) * height
;
11586 amount_to_scroll
= float_amount
;
11587 if (amount_to_scroll
== 0 && float_amount
> 0)
11588 amount_to_scroll
= 1;
11592 if (amount_to_scroll
<= 0)
11593 return SCROLLING_FAILED
;
11595 /* If moving by amount_to_scroll leaves STARTP unchanged,
11596 move it down one screen line. */
11598 move_it_vertically (&it
, amount_to_scroll
);
11599 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
11600 move_it_by_lines (&it
, 1, 1);
11601 startp
= it
.current
.pos
;
11605 /* See if point is inside the scroll margin at the top of the
11607 scroll_margin_pos
= startp
;
11608 if (this_scroll_margin
)
11610 start_display (&it
, w
, startp
);
11611 move_it_vertically (&it
, this_scroll_margin
);
11612 scroll_margin_pos
= it
.current
.pos
;
11615 if (PT
< CHARPOS (scroll_margin_pos
))
11617 /* Point is in the scroll margin at the top of the window or
11618 above what is displayed in the window. */
11621 /* Compute the vertical distance from PT to the scroll
11622 margin position. Give up if distance is greater than
11624 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
11625 start_display (&it
, w
, pos
);
11627 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11628 it
.last_visible_y
, -1,
11629 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11630 dy
= it
.current_y
- y0
;
11631 if (dy
> scroll_max
)
11632 return SCROLLING_FAILED
;
11634 /* Compute new window start. */
11635 start_display (&it
, w
, startp
);
11637 if (scroll_conservatively
)
11639 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11640 else if (scroll_step
|| temp_scroll_step
)
11641 amount_to_scroll
= scroll_max
;
11644 aggressive
= current_buffer
->scroll_down_aggressively
;
11645 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11646 if (NUMBERP (aggressive
))
11648 double float_amount
= XFLOATINT (aggressive
) * height
;
11649 amount_to_scroll
= float_amount
;
11650 if (amount_to_scroll
== 0 && float_amount
> 0)
11651 amount_to_scroll
= 1;
11655 if (amount_to_scroll
<= 0)
11656 return SCROLLING_FAILED
;
11658 move_it_vertically_backward (&it
, amount_to_scroll
);
11659 startp
= it
.current
.pos
;
11663 /* Run window scroll functions. */
11664 startp
= run_window_scroll_functions (window
, startp
);
11666 /* Display the window. Give up if new fonts are loaded, or if point
11668 if (!try_window (window
, startp
, 0))
11669 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11670 else if (w
->cursor
.vpos
< 0)
11672 clear_glyph_matrix (w
->desired_matrix
);
11673 rc
= SCROLLING_FAILED
;
11677 /* Maybe forget recorded base line for line number display. */
11678 if (!just_this_one_p
11679 || current_buffer
->clip_changed
11680 || BEG_UNCHANGED
< CHARPOS (startp
))
11681 w
->base_line_number
= Qnil
;
11683 /* If cursor ends up on a partially visible line,
11684 treat that as being off the bottom of the screen. */
11685 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
11687 clear_glyph_matrix (w
->desired_matrix
);
11688 ++extra_scroll_margin_lines
;
11691 rc
= SCROLLING_SUCCESS
;
11698 /* Compute a suitable window start for window W if display of W starts
11699 on a continuation line. Value is non-zero if a new window start
11702 The new window start will be computed, based on W's width, starting
11703 from the start of the continued line. It is the start of the
11704 screen line with the minimum distance from the old start W->start. */
11707 compute_window_start_on_continuation_line (w
)
11710 struct text_pos pos
, start_pos
;
11711 int window_start_changed_p
= 0;
11713 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
11715 /* If window start is on a continuation line... Window start may be
11716 < BEGV in case there's invisible text at the start of the
11717 buffer (M-x rmail, for example). */
11718 if (CHARPOS (start_pos
) > BEGV
11719 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
11722 struct glyph_row
*row
;
11724 /* Handle the case that the window start is out of range. */
11725 if (CHARPOS (start_pos
) < BEGV
)
11726 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
11727 else if (CHARPOS (start_pos
) > ZV
)
11728 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
11730 /* Find the start of the continued line. This should be fast
11731 because scan_buffer is fast (newline cache). */
11732 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
11733 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
11734 row
, DEFAULT_FACE_ID
);
11735 reseat_at_previous_visible_line_start (&it
);
11737 /* If the line start is "too far" away from the window start,
11738 say it takes too much time to compute a new window start. */
11739 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
11740 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
11742 int min_distance
, distance
;
11744 /* Move forward by display lines to find the new window
11745 start. If window width was enlarged, the new start can
11746 be expected to be > the old start. If window width was
11747 decreased, the new window start will be < the old start.
11748 So, we're looking for the display line start with the
11749 minimum distance from the old window start. */
11750 pos
= it
.current
.pos
;
11751 min_distance
= INFINITY
;
11752 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
11753 distance
< min_distance
)
11755 min_distance
= distance
;
11756 pos
= it
.current
.pos
;
11757 move_it_by_lines (&it
, 1, 0);
11760 /* Set the window start there. */
11761 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
11762 window_start_changed_p
= 1;
11766 return window_start_changed_p
;
11770 /* Try cursor movement in case text has not changed in window WINDOW,
11771 with window start STARTP. Value is
11773 CURSOR_MOVEMENT_SUCCESS if successful
11775 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
11777 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
11778 display. *SCROLL_STEP is set to 1, under certain circumstances, if
11779 we want to scroll as if scroll-step were set to 1. See the code.
11781 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
11782 which case we have to abort this redisplay, and adjust matrices
11787 CURSOR_MOVEMENT_SUCCESS
,
11788 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11789 CURSOR_MOVEMENT_MUST_SCROLL
,
11790 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11794 try_cursor_movement (window
, startp
, scroll_step
)
11795 Lisp_Object window
;
11796 struct text_pos startp
;
11799 struct window
*w
= XWINDOW (window
);
11800 struct frame
*f
= XFRAME (w
->frame
);
11801 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11804 if (inhibit_try_cursor_movement
)
11808 /* Handle case where text has not changed, only point, and it has
11809 not moved off the frame. */
11810 if (/* Point may be in this window. */
11811 PT
>= CHARPOS (startp
)
11812 /* Selective display hasn't changed. */
11813 && !current_buffer
->clip_changed
11814 /* Function force-mode-line-update is used to force a thorough
11815 redisplay. It sets either windows_or_buffers_changed or
11816 update_mode_lines. So don't take a shortcut here for these
11818 && !update_mode_lines
11819 && !windows_or_buffers_changed
11820 && !cursor_type_changed
11821 /* Can't use this case if highlighting a region. When a
11822 region exists, cursor movement has to do more than just
11824 && !(!NILP (Vtransient_mark_mode
)
11825 && !NILP (current_buffer
->mark_active
))
11826 && NILP (w
->region_showing
)
11827 && NILP (Vshow_trailing_whitespace
)
11828 /* Right after splitting windows, last_point may be nil. */
11829 && INTEGERP (w
->last_point
)
11830 /* This code is not used for mini-buffer for the sake of the case
11831 of redisplaying to replace an echo area message; since in
11832 that case the mini-buffer contents per se are usually
11833 unchanged. This code is of no real use in the mini-buffer
11834 since the handling of this_line_start_pos, etc., in redisplay
11835 handles the same cases. */
11836 && !EQ (window
, minibuf_window
)
11837 /* When splitting windows or for new windows, it happens that
11838 redisplay is called with a nil window_end_vpos or one being
11839 larger than the window. This should really be fixed in
11840 window.c. I don't have this on my list, now, so we do
11841 approximately the same as the old redisplay code. --gerd. */
11842 && INTEGERP (w
->window_end_vpos
)
11843 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11844 && (FRAME_WINDOW_P (f
)
11845 || !overlay_arrow_in_current_buffer_p ()))
11847 int this_scroll_margin
, top_scroll_margin
;
11848 struct glyph_row
*row
= NULL
;
11851 debug_method_add (w
, "cursor movement");
11854 /* Scroll if point within this distance from the top or bottom
11855 of the window. This is a pixel value. */
11856 this_scroll_margin
= max (0, scroll_margin
);
11857 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11858 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11860 top_scroll_margin
= this_scroll_margin
;
11861 if (WINDOW_WANTS_HEADER_LINE_P (w
))
11862 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
11864 /* Start with the row the cursor was displayed during the last
11865 not paused redisplay. Give up if that row is not valid. */
11866 if (w
->last_cursor
.vpos
< 0
11867 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11868 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11871 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11872 if (row
->mode_line_p
)
11874 if (!row
->enabled_p
)
11875 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11878 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11881 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11883 if (PT
> XFASTINT (w
->last_point
))
11885 /* Point has moved forward. */
11886 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11887 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11889 xassert (row
->enabled_p
);
11893 /* The end position of a row equals the start position
11894 of the next row. If PT is there, we would rather
11895 display it in the next line. */
11896 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11897 && MATRIX_ROW_END_CHARPOS (row
) == PT
11898 && !cursor_row_p (w
, row
))
11901 /* If within the scroll margin, scroll. Note that
11902 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11903 the next line would be drawn, and that
11904 this_scroll_margin can be zero. */
11905 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11906 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11907 /* Line is completely visible last line in window
11908 and PT is to be set in the next line. */
11909 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11910 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11911 && !row
->ends_at_zv_p
11912 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11915 else if (PT
< XFASTINT (w
->last_point
))
11917 /* Cursor has to be moved backward. Note that PT >=
11918 CHARPOS (startp) because of the outer if-statement. */
11919 while (!row
->mode_line_p
11920 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11921 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11922 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
11923 && (row
->y
> top_scroll_margin
11924 || CHARPOS (startp
) == BEGV
))
11926 xassert (row
->enabled_p
);
11930 /* Consider the following case: Window starts at BEGV,
11931 there is invisible, intangible text at BEGV, so that
11932 display starts at some point START > BEGV. It can
11933 happen that we are called with PT somewhere between
11934 BEGV and START. Try to handle that case. */
11935 if (row
< w
->current_matrix
->rows
11936 || row
->mode_line_p
)
11938 row
= w
->current_matrix
->rows
;
11939 if (row
->mode_line_p
)
11943 /* Due to newlines in overlay strings, we may have to
11944 skip forward over overlay strings. */
11945 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11946 && MATRIX_ROW_END_CHARPOS (row
) == PT
11947 && !cursor_row_p (w
, row
))
11950 /* If within the scroll margin, scroll. */
11951 if (row
->y
< top_scroll_margin
11952 && CHARPOS (startp
) != BEGV
)
11957 /* Cursor did not move. So don't scroll even if cursor line
11958 is partially visible, as it was so before. */
11959 rc
= CURSOR_MOVEMENT_SUCCESS
;
11962 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
11963 || PT
> MATRIX_ROW_END_CHARPOS (row
))
11965 /* if PT is not in the glyph row, give up. */
11966 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11968 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
11969 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
11970 && make_cursor_line_fully_visible_p
)
11972 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
11973 && !row
->ends_at_zv_p
11974 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11975 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11976 else if (row
->height
> window_box_height (w
))
11978 /* If we end up in a partially visible line, let's
11979 make it fully visible, except when it's taller
11980 than the window, in which case we can't do much
11983 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11987 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11988 if (!cursor_row_fully_visible_p (w
, 0, 1))
11989 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11991 rc
= CURSOR_MOVEMENT_SUCCESS
;
11995 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11998 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11999 rc
= CURSOR_MOVEMENT_SUCCESS
;
12008 set_vertical_scroll_bar (w
)
12011 int start
, end
, whole
;
12013 /* Calculate the start and end positions for the current window.
12014 At some point, it would be nice to choose between scrollbars
12015 which reflect the whole buffer size, with special markers
12016 indicating narrowing, and scrollbars which reflect only the
12019 Note that mini-buffers sometimes aren't displaying any text. */
12020 if (!MINI_WINDOW_P (w
)
12021 || (w
== XWINDOW (minibuf_window
)
12022 && NILP (echo_area_buffer
[0])))
12024 struct buffer
*buf
= XBUFFER (w
->buffer
);
12025 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12026 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12027 /* I don't think this is guaranteed to be right. For the
12028 moment, we'll pretend it is. */
12029 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12033 if (whole
< (end
- start
))
12034 whole
= end
- start
;
12037 start
= end
= whole
= 0;
12039 /* Indicate what this scroll bar ought to be displaying now. */
12040 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
12044 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12045 selected_window is redisplayed.
12047 We can return without actually redisplaying the window if
12048 fonts_changed_p is nonzero. In that case, redisplay_internal will
12052 redisplay_window (window
, just_this_one_p
)
12053 Lisp_Object window
;
12054 int just_this_one_p
;
12056 struct window
*w
= XWINDOW (window
);
12057 struct frame
*f
= XFRAME (w
->frame
);
12058 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12059 struct buffer
*old
= current_buffer
;
12060 struct text_pos lpoint
, opoint
, startp
;
12061 int update_mode_line
;
12064 /* Record it now because it's overwritten. */
12065 int current_matrix_up_to_date_p
= 0;
12066 int used_current_matrix_p
= 0;
12067 /* This is less strict than current_matrix_up_to_date_p.
12068 It indictes that the buffer contents and narrowing are unchanged. */
12069 int buffer_unchanged_p
= 0;
12070 int temp_scroll_step
= 0;
12071 int count
= SPECPDL_INDEX ();
12073 int centering_position
= -1;
12074 int last_line_misfit
= 0;
12076 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12079 /* W must be a leaf window here. */
12080 xassert (!NILP (w
->buffer
));
12082 *w
->desired_matrix
->method
= 0;
12085 specbind (Qinhibit_point_motion_hooks
, Qt
);
12087 reconsider_clip_changes (w
, buffer
);
12089 /* Has the mode line to be updated? */
12090 update_mode_line
= (!NILP (w
->update_mode_line
)
12091 || update_mode_lines
12092 || buffer
->clip_changed
12093 || buffer
->prevent_redisplay_optimizations_p
);
12095 if (MINI_WINDOW_P (w
))
12097 if (w
== XWINDOW (echo_area_window
)
12098 && !NILP (echo_area_buffer
[0]))
12100 if (update_mode_line
)
12101 /* We may have to update a tty frame's menu bar or a
12102 tool-bar. Example `M-x C-h C-h C-g'. */
12103 goto finish_menu_bars
;
12105 /* We've already displayed the echo area glyphs in this window. */
12106 goto finish_scroll_bars
;
12108 else if ((w
!= XWINDOW (minibuf_window
)
12109 || minibuf_level
== 0)
12110 /* When buffer is nonempty, redisplay window normally. */
12111 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12112 /* Quail displays non-mini buffers in minibuffer window.
12113 In that case, redisplay the window normally. */
12114 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12116 /* W is a mini-buffer window, but it's not active, so clear
12118 int yb
= window_text_bottom_y (w
);
12119 struct glyph_row
*row
;
12122 for (y
= 0, row
= w
->desired_matrix
->rows
;
12124 y
+= row
->height
, ++row
)
12125 blank_row (w
, row
, y
);
12126 goto finish_scroll_bars
;
12129 clear_glyph_matrix (w
->desired_matrix
);
12132 /* Otherwise set up data on this window; select its buffer and point
12134 /* Really select the buffer, for the sake of buffer-local
12136 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12137 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12139 current_matrix_up_to_date_p
12140 = (!NILP (w
->window_end_valid
)
12141 && !current_buffer
->clip_changed
12142 && !current_buffer
->prevent_redisplay_optimizations_p
12143 && XFASTINT (w
->last_modified
) >= MODIFF
12144 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12147 = (!NILP (w
->window_end_valid
)
12148 && !current_buffer
->clip_changed
12149 && XFASTINT (w
->last_modified
) >= MODIFF
12150 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12152 /* When windows_or_buffers_changed is non-zero, we can't rely on
12153 the window end being valid, so set it to nil there. */
12154 if (windows_or_buffers_changed
)
12156 /* If window starts on a continuation line, maybe adjust the
12157 window start in case the window's width changed. */
12158 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12159 compute_window_start_on_continuation_line (w
);
12161 w
->window_end_valid
= Qnil
;
12164 /* Some sanity checks. */
12165 CHECK_WINDOW_END (w
);
12166 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12168 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12171 /* If %c is in mode line, update it if needed. */
12172 if (!NILP (w
->column_number_displayed
)
12173 /* This alternative quickly identifies a common case
12174 where no change is needed. */
12175 && !(PT
== XFASTINT (w
->last_point
)
12176 && XFASTINT (w
->last_modified
) >= MODIFF
12177 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12178 && (XFASTINT (w
->column_number_displayed
)
12179 != (int) current_column ())) /* iftc */
12180 update_mode_line
= 1;
12182 /* Count number of windows showing the selected buffer. An indirect
12183 buffer counts as its base buffer. */
12184 if (!just_this_one_p
)
12186 struct buffer
*current_base
, *window_base
;
12187 current_base
= current_buffer
;
12188 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12189 if (current_base
->base_buffer
)
12190 current_base
= current_base
->base_buffer
;
12191 if (window_base
->base_buffer
)
12192 window_base
= window_base
->base_buffer
;
12193 if (current_base
== window_base
)
12197 /* Point refers normally to the selected window. For any other
12198 window, set up appropriate value. */
12199 if (!EQ (window
, selected_window
))
12201 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12202 int new_pt_byte
= marker_byte_position (w
->pointm
);
12206 new_pt_byte
= BEGV_BYTE
;
12207 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
12209 else if (new_pt
> (ZV
- 1))
12212 new_pt_byte
= ZV_BYTE
;
12213 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
12216 /* We don't use SET_PT so that the point-motion hooks don't run. */
12217 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
12220 /* If any of the character widths specified in the display table
12221 have changed, invalidate the width run cache. It's true that
12222 this may be a bit late to catch such changes, but the rest of
12223 redisplay goes (non-fatally) haywire when the display table is
12224 changed, so why should we worry about doing any better? */
12225 if (current_buffer
->width_run_cache
)
12227 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
12229 if (! disptab_matches_widthtab (disptab
,
12230 XVECTOR (current_buffer
->width_table
)))
12232 invalidate_region_cache (current_buffer
,
12233 current_buffer
->width_run_cache
,
12235 recompute_width_table (current_buffer
, disptab
);
12239 /* If window-start is screwed up, choose a new one. */
12240 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12243 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12245 /* If someone specified a new starting point but did not insist,
12246 check whether it can be used. */
12247 if (!NILP (w
->optional_new_start
)
12248 && CHARPOS (startp
) >= BEGV
12249 && CHARPOS (startp
) <= ZV
)
12251 w
->optional_new_start
= Qnil
;
12252 start_display (&it
, w
, startp
);
12253 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12254 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12255 if (IT_CHARPOS (it
) == PT
)
12256 w
->force_start
= Qt
;
12257 /* IT may overshoot PT if text at PT is invisible. */
12258 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12259 w
->force_start
= Qt
;
12264 /* Handle case where place to start displaying has been specified,
12265 unless the specified location is outside the accessible range. */
12266 if (!NILP (w
->force_start
)
12267 || w
->frozen_window_start_p
)
12269 /* We set this later on if we have to adjust point. */
12273 w
->force_start
= Qnil
;
12275 w
->window_end_valid
= Qnil
;
12277 /* Forget any recorded base line for line number display. */
12278 if (!buffer_unchanged_p
)
12279 w
->base_line_number
= Qnil
;
12281 /* Redisplay the mode line. Select the buffer properly for that.
12282 Also, run the hook window-scroll-functions
12283 because we have scrolled. */
12284 /* Note, we do this after clearing force_start because
12285 if there's an error, it is better to forget about force_start
12286 than to get into an infinite loop calling the hook functions
12287 and having them get more errors. */
12288 if (!update_mode_line
12289 || ! NILP (Vwindow_scroll_functions
))
12291 update_mode_line
= 1;
12292 w
->update_mode_line
= Qt
;
12293 startp
= run_window_scroll_functions (window
, startp
);
12296 w
->last_modified
= make_number (0);
12297 w
->last_overlay_modified
= make_number (0);
12298 if (CHARPOS (startp
) < BEGV
)
12299 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
12300 else if (CHARPOS (startp
) > ZV
)
12301 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12303 /* Redisplay, then check if cursor has been set during the
12304 redisplay. Give up if new fonts were loaded. */
12305 val
= try_window (window
, startp
, 1);
12308 w
->force_start
= Qt
;
12309 clear_glyph_matrix (w
->desired_matrix
);
12310 goto need_larger_matrices
;
12312 /* Point was outside the scroll margins. */
12314 new_vpos
= window_box_height (w
) / 2;
12316 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12318 /* If point does not appear, try to move point so it does
12319 appear. The desired matrix has been built above, so we
12320 can use it here. */
12321 new_vpos
= window_box_height (w
) / 2;
12324 if (!cursor_row_fully_visible_p (w
, 0, 0))
12326 /* Point does appear, but on a line partly visible at end of window.
12327 Move it back to a fully-visible line. */
12328 new_vpos
= window_box_height (w
);
12331 /* If we need to move point for either of the above reasons,
12332 now actually do it. */
12335 struct glyph_row
*row
;
12337 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
12338 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
12341 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
12342 MATRIX_ROW_START_BYTEPOS (row
));
12344 if (w
!= XWINDOW (selected_window
))
12345 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
12346 else if (current_buffer
== old
)
12347 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12349 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
12351 /* If we are highlighting the region, then we just changed
12352 the region, so redisplay to show it. */
12353 if (!NILP (Vtransient_mark_mode
)
12354 && !NILP (current_buffer
->mark_active
))
12356 clear_glyph_matrix (w
->desired_matrix
);
12357 if (!try_window (window
, startp
, 0))
12358 goto need_larger_matrices
;
12363 debug_method_add (w
, "forced window start");
12368 /* Handle case where text has not changed, only point, and it has
12369 not moved off the frame, and we are not retrying after hscroll.
12370 (current_matrix_up_to_date_p is nonzero when retrying.) */
12371 if (current_matrix_up_to_date_p
12372 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
12373 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
12377 case CURSOR_MOVEMENT_SUCCESS
:
12378 used_current_matrix_p
= 1;
12381 #if 0 /* try_cursor_movement never returns this value. */
12382 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
12383 goto need_larger_matrices
;
12386 case CURSOR_MOVEMENT_MUST_SCROLL
:
12387 goto try_to_scroll
;
12393 /* If current starting point was originally the beginning of a line
12394 but no longer is, find a new starting point. */
12395 else if (!NILP (w
->start_at_line_beg
)
12396 && !(CHARPOS (startp
) <= BEGV
12397 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
12400 debug_method_add (w
, "recenter 1");
12405 /* Try scrolling with try_window_id. Value is > 0 if update has
12406 been done, it is -1 if we know that the same window start will
12407 not work. It is 0 if unsuccessful for some other reason. */
12408 else if ((tem
= try_window_id (w
)) != 0)
12411 debug_method_add (w
, "try_window_id %d", tem
);
12414 if (fonts_changed_p
)
12415 goto need_larger_matrices
;
12419 /* Otherwise try_window_id has returned -1 which means that we
12420 don't want the alternative below this comment to execute. */
12422 else if (CHARPOS (startp
) >= BEGV
12423 && CHARPOS (startp
) <= ZV
12424 && PT
>= CHARPOS (startp
)
12425 && (CHARPOS (startp
) < ZV
12426 /* Avoid starting at end of buffer. */
12427 || CHARPOS (startp
) == BEGV
12428 || (XFASTINT (w
->last_modified
) >= MODIFF
12429 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
12432 debug_method_add (w
, "same window start");
12435 /* Try to redisplay starting at same place as before.
12436 If point has not moved off frame, accept the results. */
12437 if (!current_matrix_up_to_date_p
12438 /* Don't use try_window_reusing_current_matrix in this case
12439 because a window scroll function can have changed the
12441 || !NILP (Vwindow_scroll_functions
)
12442 || MINI_WINDOW_P (w
)
12443 || !(used_current_matrix_p
12444 = try_window_reusing_current_matrix (w
)))
12446 IF_DEBUG (debug_method_add (w
, "1"));
12447 if (try_window (window
, startp
, 1) < 0)
12448 /* -1 means we need to scroll.
12449 0 means we need new matrices, but fonts_changed_p
12450 is set in that case, so we will detect it below. */
12451 goto try_to_scroll
;
12454 if (fonts_changed_p
)
12455 goto need_larger_matrices
;
12457 if (w
->cursor
.vpos
>= 0)
12459 if (!just_this_one_p
12460 || current_buffer
->clip_changed
12461 || BEG_UNCHANGED
< CHARPOS (startp
))
12462 /* Forget any recorded base line for line number display. */
12463 w
->base_line_number
= Qnil
;
12465 if (!cursor_row_fully_visible_p (w
, 1, 0))
12467 clear_glyph_matrix (w
->desired_matrix
);
12468 last_line_misfit
= 1;
12470 /* Drop through and scroll. */
12475 clear_glyph_matrix (w
->desired_matrix
);
12480 w
->last_modified
= make_number (0);
12481 w
->last_overlay_modified
= make_number (0);
12483 /* Redisplay the mode line. Select the buffer properly for that. */
12484 if (!update_mode_line
)
12486 update_mode_line
= 1;
12487 w
->update_mode_line
= Qt
;
12490 /* Try to scroll by specified few lines. */
12491 if ((scroll_conservatively
12493 || temp_scroll_step
12494 || NUMBERP (current_buffer
->scroll_up_aggressively
)
12495 || NUMBERP (current_buffer
->scroll_down_aggressively
))
12496 && !current_buffer
->clip_changed
12497 && CHARPOS (startp
) >= BEGV
12498 && CHARPOS (startp
) <= ZV
)
12500 /* The function returns -1 if new fonts were loaded, 1 if
12501 successful, 0 if not successful. */
12502 int rc
= try_scrolling (window
, just_this_one_p
,
12503 scroll_conservatively
,
12505 temp_scroll_step
, last_line_misfit
);
12508 case SCROLLING_SUCCESS
:
12511 case SCROLLING_NEED_LARGER_MATRICES
:
12512 goto need_larger_matrices
;
12514 case SCROLLING_FAILED
:
12522 /* Finally, just choose place to start which centers point */
12525 if (centering_position
< 0)
12526 centering_position
= window_box_height (w
) / 2;
12529 debug_method_add (w
, "recenter");
12532 /* w->vscroll = 0; */
12534 /* Forget any previously recorded base line for line number display. */
12535 if (!buffer_unchanged_p
)
12536 w
->base_line_number
= Qnil
;
12538 /* Move backward half the height of the window. */
12539 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12540 it
.current_y
= it
.last_visible_y
;
12541 move_it_vertically_backward (&it
, centering_position
);
12542 xassert (IT_CHARPOS (it
) >= BEGV
);
12544 /* The function move_it_vertically_backward may move over more
12545 than the specified y-distance. If it->w is small, e.g. a
12546 mini-buffer window, we may end up in front of the window's
12547 display area. Start displaying at the start of the line
12548 containing PT in this case. */
12549 if (it
.current_y
<= 0)
12551 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12552 move_it_vertically_backward (&it
, 0);
12554 /* I think this assert is bogus if buffer contains
12555 invisible text or images. KFS. */
12556 xassert (IT_CHARPOS (it
) <= PT
);
12561 it
.current_x
= it
.hpos
= 0;
12563 /* Set startp here explicitly in case that helps avoid an infinite loop
12564 in case the window-scroll-functions functions get errors. */
12565 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
12567 /* Run scroll hooks. */
12568 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
12570 /* Redisplay the window. */
12571 if (!current_matrix_up_to_date_p
12572 || windows_or_buffers_changed
12573 || cursor_type_changed
12574 /* Don't use try_window_reusing_current_matrix in this case
12575 because it can have changed the buffer. */
12576 || !NILP (Vwindow_scroll_functions
)
12577 || !just_this_one_p
12578 || MINI_WINDOW_P (w
)
12579 || !(used_current_matrix_p
12580 = try_window_reusing_current_matrix (w
)))
12581 try_window (window
, startp
, 0);
12583 /* If new fonts have been loaded (due to fontsets), give up. We
12584 have to start a new redisplay since we need to re-adjust glyph
12586 if (fonts_changed_p
)
12587 goto need_larger_matrices
;
12589 /* If cursor did not appear assume that the middle of the window is
12590 in the first line of the window. Do it again with the next line.
12591 (Imagine a window of height 100, displaying two lines of height
12592 60. Moving back 50 from it->last_visible_y will end in the first
12594 if (w
->cursor
.vpos
< 0)
12596 if (!NILP (w
->window_end_valid
)
12597 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
12599 clear_glyph_matrix (w
->desired_matrix
);
12600 move_it_by_lines (&it
, 1, 0);
12601 try_window (window
, it
.current
.pos
, 0);
12603 else if (PT
< IT_CHARPOS (it
))
12605 clear_glyph_matrix (w
->desired_matrix
);
12606 move_it_by_lines (&it
, -1, 0);
12607 try_window (window
, it
.current
.pos
, 0);
12611 /* Not much we can do about it. */
12615 /* Consider the following case: Window starts at BEGV, there is
12616 invisible, intangible text at BEGV, so that display starts at
12617 some point START > BEGV. It can happen that we are called with
12618 PT somewhere between BEGV and START. Try to handle that case. */
12619 if (w
->cursor
.vpos
< 0)
12621 struct glyph_row
*row
= w
->current_matrix
->rows
;
12622 if (row
->mode_line_p
)
12624 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12627 if (!cursor_row_fully_visible_p (w
, 0, 0))
12629 /* If vscroll is enabled, disable it and try again. */
12633 clear_glyph_matrix (w
->desired_matrix
);
12637 /* If centering point failed to make the whole line visible,
12638 put point at the top instead. That has to make the whole line
12639 visible, if it can be done. */
12640 if (centering_position
== 0)
12643 clear_glyph_matrix (w
->desired_matrix
);
12644 centering_position
= 0;
12650 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12651 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
12652 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
12655 /* Display the mode line, if we must. */
12656 if ((update_mode_line
12657 /* If window not full width, must redo its mode line
12658 if (a) the window to its side is being redone and
12659 (b) we do a frame-based redisplay. This is a consequence
12660 of how inverted lines are drawn in frame-based redisplay. */
12661 || (!just_this_one_p
12662 && !FRAME_WINDOW_P (f
)
12663 && !WINDOW_FULL_WIDTH_P (w
))
12664 /* Line number to display. */
12665 || INTEGERP (w
->base_line_pos
)
12666 /* Column number is displayed and different from the one displayed. */
12667 || (!NILP (w
->column_number_displayed
)
12668 && (XFASTINT (w
->column_number_displayed
)
12669 != (int) current_column ()))) /* iftc */
12670 /* This means that the window has a mode line. */
12671 && (WINDOW_WANTS_MODELINE_P (w
)
12672 || WINDOW_WANTS_HEADER_LINE_P (w
)))
12674 display_mode_lines (w
);
12676 /* If mode line height has changed, arrange for a thorough
12677 immediate redisplay using the correct mode line height. */
12678 if (WINDOW_WANTS_MODELINE_P (w
)
12679 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12681 fonts_changed_p
= 1;
12682 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12683 = DESIRED_MODE_LINE_HEIGHT (w
);
12686 /* If top line height has changed, arrange for a thorough
12687 immediate redisplay using the correct mode line height. */
12688 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12689 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
12691 fonts_changed_p
= 1;
12692 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
12693 = DESIRED_HEADER_LINE_HEIGHT (w
);
12696 if (fonts_changed_p
)
12697 goto need_larger_matrices
;
12700 if (!line_number_displayed
12701 && !BUFFERP (w
->base_line_pos
))
12703 w
->base_line_pos
= Qnil
;
12704 w
->base_line_number
= Qnil
;
12709 /* When we reach a frame's selected window, redo the frame's menu bar. */
12710 if (update_mode_line
12711 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
12713 int redisplay_menu_p
= 0;
12714 int redisplay_tool_bar_p
= 0;
12716 if (FRAME_WINDOW_P (f
))
12718 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
12719 || defined (USE_GTK)
12720 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
12722 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12726 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12728 if (redisplay_menu_p
)
12729 display_menu_bar (w
);
12731 #ifdef HAVE_WINDOW_SYSTEM
12733 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
12735 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
12736 && (FRAME_TOOL_BAR_LINES (f
) > 0
12737 || auto_resize_tool_bars_p
);
12741 if (redisplay_tool_bar_p
)
12742 redisplay_tool_bar (f
);
12746 #ifdef HAVE_WINDOW_SYSTEM
12747 if (FRAME_WINDOW_P (f
)
12748 && update_window_fringes (w
, 0)
12749 && !just_this_one_p
12750 && (used_current_matrix_p
|| overlay_arrow_seen
)
12751 && !w
->pseudo_window_p
)
12755 if (draw_window_fringes (w
, 1))
12756 x_draw_vertical_border (w
);
12760 #endif /* HAVE_WINDOW_SYSTEM */
12762 /* We go to this label, with fonts_changed_p nonzero,
12763 if it is necessary to try again using larger glyph matrices.
12764 We have to redeem the scroll bar even in this case,
12765 because the loop in redisplay_internal expects that. */
12766 need_larger_matrices
:
12768 finish_scroll_bars
:
12770 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
12772 /* Set the thumb's position and size. */
12773 set_vertical_scroll_bar (w
);
12775 /* Note that we actually used the scroll bar attached to this
12776 window, so it shouldn't be deleted at the end of redisplay. */
12777 redeem_scroll_bar_hook (w
);
12780 /* Restore current_buffer and value of point in it. */
12781 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
12782 set_buffer_internal_1 (old
);
12783 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12785 unbind_to (count
, Qnil
);
12789 /* Build the complete desired matrix of WINDOW with a window start
12790 buffer position POS.
12792 Value is 1 if successful. It is zero if fonts were loaded during
12793 redisplay which makes re-adjusting glyph matrices necessary, and -1
12794 if point would appear in the scroll margins.
12795 (We check that only if CHECK_MARGINS is nonzero. */
12798 try_window (window
, pos
, check_margins
)
12799 Lisp_Object window
;
12800 struct text_pos pos
;
12803 struct window
*w
= XWINDOW (window
);
12805 struct glyph_row
*last_text_row
= NULL
;
12807 /* Make POS the new window start. */
12808 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
12810 /* Mark cursor position as unknown. No overlay arrow seen. */
12811 w
->cursor
.vpos
= -1;
12812 overlay_arrow_seen
= 0;
12814 /* Initialize iterator and info to start at POS. */
12815 start_display (&it
, w
, pos
);
12817 /* Display all lines of W. */
12818 while (it
.current_y
< it
.last_visible_y
)
12820 if (display_line (&it
))
12821 last_text_row
= it
.glyph_row
- 1;
12822 if (fonts_changed_p
)
12826 /* Don't let the cursor end in the scroll margins. */
12829 int this_scroll_margin
, cursor_height
;
12831 this_scroll_margin
= max (0, scroll_margin
);
12832 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12833 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
12834 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
12836 if ((w
->cursor
.y
< this_scroll_margin
12837 && CHARPOS (pos
) > BEGV
)
12838 /* rms: considering make_cursor_line_fully_visible_p here
12839 seems to give wrong results. We don't want to recenter
12840 when the last line is partly visible, we want to allow
12841 that case to be handled in the usual way. */
12842 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
12844 w
->cursor
.vpos
= -1;
12845 clear_glyph_matrix (w
->desired_matrix
);
12850 /* If bottom moved off end of frame, change mode line percentage. */
12851 if (XFASTINT (w
->window_end_pos
) <= 0
12852 && Z
!= IT_CHARPOS (it
))
12853 w
->update_mode_line
= Qt
;
12855 /* Set window_end_pos to the offset of the last character displayed
12856 on the window from the end of current_buffer. Set
12857 window_end_vpos to its row number. */
12860 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
12861 w
->window_end_bytepos
12862 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12864 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12866 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12867 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12868 ->displays_text_p
);
12872 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12873 w
->window_end_pos
= make_number (Z
- ZV
);
12874 w
->window_end_vpos
= make_number (0);
12877 /* But that is not valid info until redisplay finishes. */
12878 w
->window_end_valid
= Qnil
;
12884 /************************************************************************
12885 Window redisplay reusing current matrix when buffer has not changed
12886 ************************************************************************/
12888 /* Try redisplay of window W showing an unchanged buffer with a
12889 different window start than the last time it was displayed by
12890 reusing its current matrix. Value is non-zero if successful.
12891 W->start is the new window start. */
12894 try_window_reusing_current_matrix (w
)
12897 struct frame
*f
= XFRAME (w
->frame
);
12898 struct glyph_row
*row
, *bottom_row
;
12901 struct text_pos start
, new_start
;
12902 int nrows_scrolled
, i
;
12903 struct glyph_row
*last_text_row
;
12904 struct glyph_row
*last_reused_text_row
;
12905 struct glyph_row
*start_row
;
12906 int start_vpos
, min_y
, max_y
;
12909 if (inhibit_try_window_reusing
)
12913 if (/* This function doesn't handle terminal frames. */
12914 !FRAME_WINDOW_P (f
)
12915 /* Don't try to reuse the display if windows have been split
12917 || windows_or_buffers_changed
12918 || cursor_type_changed
)
12921 /* Can't do this if region may have changed. */
12922 if ((!NILP (Vtransient_mark_mode
)
12923 && !NILP (current_buffer
->mark_active
))
12924 || !NILP (w
->region_showing
)
12925 || !NILP (Vshow_trailing_whitespace
))
12928 /* If top-line visibility has changed, give up. */
12929 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12930 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12933 /* Give up if old or new display is scrolled vertically. We could
12934 make this function handle this, but right now it doesn't. */
12935 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12936 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
12939 /* The variable new_start now holds the new window start. The old
12940 start `start' can be determined from the current matrix. */
12941 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
12942 start
= start_row
->start
.pos
;
12943 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12945 /* Clear the desired matrix for the display below. */
12946 clear_glyph_matrix (w
->desired_matrix
);
12948 if (CHARPOS (new_start
) <= CHARPOS (start
))
12952 /* Don't use this method if the display starts with an ellipsis
12953 displayed for invisible text. It's not easy to handle that case
12954 below, and it's certainly not worth the effort since this is
12955 not a frequent case. */
12956 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
12959 IF_DEBUG (debug_method_add (w
, "twu1"));
12961 /* Display up to a row that can be reused. The variable
12962 last_text_row is set to the last row displayed that displays
12963 text. Note that it.vpos == 0 if or if not there is a
12964 header-line; it's not the same as the MATRIX_ROW_VPOS! */
12965 start_display (&it
, w
, new_start
);
12966 first_row_y
= it
.current_y
;
12967 w
->cursor
.vpos
= -1;
12968 last_text_row
= last_reused_text_row
= NULL
;
12970 while (it
.current_y
< it
.last_visible_y
12971 && !fonts_changed_p
)
12973 /* If we have reached into the characters in the START row,
12974 that means the line boundaries have changed. So we
12975 can't start copying with the row START. Maybe it will
12976 work to start copying with the following row. */
12977 while (IT_CHARPOS (it
) > CHARPOS (start
))
12979 /* Advance to the next row as the "start". */
12981 start
= start_row
->start
.pos
;
12982 /* If there are no more rows to try, or just one, give up. */
12983 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
12984 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
12985 || CHARPOS (start
) == ZV
)
12987 clear_glyph_matrix (w
->desired_matrix
);
12991 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12993 /* If we have reached alignment,
12994 we can copy the rest of the rows. */
12995 if (IT_CHARPOS (it
) == CHARPOS (start
))
12998 if (display_line (&it
))
12999 last_text_row
= it
.glyph_row
- 1;
13002 /* A value of current_y < last_visible_y means that we stopped
13003 at the previous window start, which in turn means that we
13004 have at least one reusable row. */
13005 if (it
.current_y
< it
.last_visible_y
)
13007 /* IT.vpos always starts from 0; it counts text lines. */
13008 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13010 /* Find PT if not already found in the lines displayed. */
13011 if (w
->cursor
.vpos
< 0)
13013 int dy
= it
.current_y
- start_row
->y
;
13015 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13016 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13018 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13019 dy
, nrows_scrolled
);
13022 clear_glyph_matrix (w
->desired_matrix
);
13027 /* Scroll the display. Do it before the current matrix is
13028 changed. The problem here is that update has not yet
13029 run, i.e. part of the current matrix is not up to date.
13030 scroll_run_hook will clear the cursor, and use the
13031 current matrix to get the height of the row the cursor is
13033 run
.current_y
= start_row
->y
;
13034 run
.desired_y
= it
.current_y
;
13035 run
.height
= it
.last_visible_y
- it
.current_y
;
13037 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13040 rif
->update_window_begin_hook (w
);
13041 rif
->clear_window_mouse_face (w
);
13042 rif
->scroll_run_hook (w
, &run
);
13043 rif
->update_window_end_hook (w
, 0, 0);
13047 /* Shift current matrix down by nrows_scrolled lines. */
13048 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13049 rotate_matrix (w
->current_matrix
,
13051 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13054 /* Disable lines that must be updated. */
13055 for (i
= 0; i
< it
.vpos
; ++i
)
13056 (start_row
+ i
)->enabled_p
= 0;
13058 /* Re-compute Y positions. */
13059 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13060 max_y
= it
.last_visible_y
;
13061 for (row
= start_row
+ nrows_scrolled
;
13065 row
->y
= it
.current_y
;
13066 row
->visible_height
= row
->height
;
13068 if (row
->y
< min_y
)
13069 row
->visible_height
-= min_y
- row
->y
;
13070 if (row
->y
+ row
->height
> max_y
)
13071 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13072 row
->redraw_fringe_bitmaps_p
= 1;
13074 it
.current_y
+= row
->height
;
13076 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13077 last_reused_text_row
= row
;
13078 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13082 /* Disable lines in the current matrix which are now
13083 below the window. */
13084 for (++row
; row
< bottom_row
; ++row
)
13085 row
->enabled_p
= 0;
13088 /* Update window_end_pos etc.; last_reused_text_row is the last
13089 reused row from the current matrix containing text, if any.
13090 The value of last_text_row is the last displayed line
13091 containing text. */
13092 if (last_reused_text_row
)
13094 w
->window_end_bytepos
13095 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13097 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13099 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13100 w
->current_matrix
));
13102 else if (last_text_row
)
13104 w
->window_end_bytepos
13105 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13107 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13109 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13113 /* This window must be completely empty. */
13114 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13115 w
->window_end_pos
= make_number (Z
- ZV
);
13116 w
->window_end_vpos
= make_number (0);
13118 w
->window_end_valid
= Qnil
;
13120 /* Update hint: don't try scrolling again in update_window. */
13121 w
->desired_matrix
->no_scrolling_p
= 1;
13124 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13128 else if (CHARPOS (new_start
) > CHARPOS (start
))
13130 struct glyph_row
*pt_row
, *row
;
13131 struct glyph_row
*first_reusable_row
;
13132 struct glyph_row
*first_row_to_display
;
13134 int yb
= window_text_bottom_y (w
);
13136 /* Find the row starting at new_start, if there is one. Don't
13137 reuse a partially visible line at the end. */
13138 first_reusable_row
= start_row
;
13139 while (first_reusable_row
->enabled_p
13140 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13141 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13142 < CHARPOS (new_start
)))
13143 ++first_reusable_row
;
13145 /* Give up if there is no row to reuse. */
13146 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13147 || !first_reusable_row
->enabled_p
13148 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13149 != CHARPOS (new_start
)))
13152 /* We can reuse fully visible rows beginning with
13153 first_reusable_row to the end of the window. Set
13154 first_row_to_display to the first row that cannot be reused.
13155 Set pt_row to the row containing point, if there is any. */
13157 for (first_row_to_display
= first_reusable_row
;
13158 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13159 ++first_row_to_display
)
13161 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13162 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13163 pt_row
= first_row_to_display
;
13166 /* Start displaying at the start of first_row_to_display. */
13167 xassert (first_row_to_display
->y
< yb
);
13168 init_to_row_start (&it
, w
, first_row_to_display
);
13170 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
13172 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
13174 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
13175 + WINDOW_HEADER_LINE_HEIGHT (w
));
13177 /* Display lines beginning with first_row_to_display in the
13178 desired matrix. Set last_text_row to the last row displayed
13179 that displays text. */
13180 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
13181 if (pt_row
== NULL
)
13182 w
->cursor
.vpos
= -1;
13183 last_text_row
= NULL
;
13184 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
13185 if (display_line (&it
))
13186 last_text_row
= it
.glyph_row
- 1;
13188 /* Give up If point isn't in a row displayed or reused. */
13189 if (w
->cursor
.vpos
< 0)
13191 clear_glyph_matrix (w
->desired_matrix
);
13195 /* If point is in a reused row, adjust y and vpos of the cursor
13199 w
->cursor
.vpos
-= nrows_scrolled
;
13200 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
13203 /* Scroll the display. */
13204 run
.current_y
= first_reusable_row
->y
;
13205 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13206 run
.height
= it
.last_visible_y
- run
.current_y
;
13207 dy
= run
.current_y
- run
.desired_y
;
13212 rif
->update_window_begin_hook (w
);
13213 rif
->clear_window_mouse_face (w
);
13214 rif
->scroll_run_hook (w
, &run
);
13215 rif
->update_window_end_hook (w
, 0, 0);
13219 /* Adjust Y positions of reused rows. */
13220 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13221 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13222 max_y
= it
.last_visible_y
;
13223 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
13226 row
->visible_height
= row
->height
;
13227 if (row
->y
< min_y
)
13228 row
->visible_height
-= min_y
- row
->y
;
13229 if (row
->y
+ row
->height
> max_y
)
13230 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13231 row
->redraw_fringe_bitmaps_p
= 1;
13234 /* Scroll the current matrix. */
13235 xassert (nrows_scrolled
> 0);
13236 rotate_matrix (w
->current_matrix
,
13238 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13241 /* Disable rows not reused. */
13242 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
13243 row
->enabled_p
= 0;
13245 /* Point may have moved to a different line, so we cannot assume that
13246 the previous cursor position is valid; locate the correct row. */
13249 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
13250 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
13254 w
->cursor
.y
= row
->y
;
13256 if (row
< bottom_row
)
13258 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
13259 while (glyph
->charpos
< PT
)
13262 w
->cursor
.x
+= glyph
->pixel_width
;
13268 /* Adjust window end. A null value of last_text_row means that
13269 the window end is in reused rows which in turn means that
13270 only its vpos can have changed. */
13273 w
->window_end_bytepos
13274 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13276 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13278 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13283 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
13286 w
->window_end_valid
= Qnil
;
13287 w
->desired_matrix
->no_scrolling_p
= 1;
13290 debug_method_add (w
, "try_window_reusing_current_matrix 2");
13300 /************************************************************************
13301 Window redisplay reusing current matrix when buffer has changed
13302 ************************************************************************/
13304 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
13305 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
13307 static struct glyph_row
*
13308 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
13309 struct glyph_row
*));
13312 /* Return the last row in MATRIX displaying text. If row START is
13313 non-null, start searching with that row. IT gives the dimensions
13314 of the display. Value is null if matrix is empty; otherwise it is
13315 a pointer to the row found. */
13317 static struct glyph_row
*
13318 find_last_row_displaying_text (matrix
, it
, start
)
13319 struct glyph_matrix
*matrix
;
13321 struct glyph_row
*start
;
13323 struct glyph_row
*row
, *row_found
;
13325 /* Set row_found to the last row in IT->w's current matrix
13326 displaying text. The loop looks funny but think of partially
13329 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
13330 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13332 xassert (row
->enabled_p
);
13334 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
13343 /* Return the last row in the current matrix of W that is not affected
13344 by changes at the start of current_buffer that occurred since W's
13345 current matrix was built. Value is null if no such row exists.
13347 BEG_UNCHANGED us the number of characters unchanged at the start of
13348 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
13349 first changed character in current_buffer. Characters at positions <
13350 BEG + BEG_UNCHANGED are at the same buffer positions as they were
13351 when the current matrix was built. */
13353 static struct glyph_row
*
13354 find_last_unchanged_at_beg_row (w
)
13357 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
13358 struct glyph_row
*row
;
13359 struct glyph_row
*row_found
= NULL
;
13360 int yb
= window_text_bottom_y (w
);
13362 /* Find the last row displaying unchanged text. */
13363 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13364 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13365 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
13367 if (/* If row ends before first_changed_pos, it is unchanged,
13368 except in some case. */
13369 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
13370 /* When row ends in ZV and we write at ZV it is not
13372 && !row
->ends_at_zv_p
13373 /* When first_changed_pos is the end of a continued line,
13374 row is not unchanged because it may be no longer
13376 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
13377 && (row
->continued_p
13378 || row
->exact_window_width_line_p
)))
13381 /* Stop if last visible row. */
13382 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
13392 /* Find the first glyph row in the current matrix of W that is not
13393 affected by changes at the end of current_buffer since the
13394 time W's current matrix was built.
13396 Return in *DELTA the number of chars by which buffer positions in
13397 unchanged text at the end of current_buffer must be adjusted.
13399 Return in *DELTA_BYTES the corresponding number of bytes.
13401 Value is null if no such row exists, i.e. all rows are affected by
13404 static struct glyph_row
*
13405 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
13407 int *delta
, *delta_bytes
;
13409 struct glyph_row
*row
;
13410 struct glyph_row
*row_found
= NULL
;
13412 *delta
= *delta_bytes
= 0;
13414 /* Display must not have been paused, otherwise the current matrix
13415 is not up to date. */
13416 if (NILP (w
->window_end_valid
))
13419 /* A value of window_end_pos >= END_UNCHANGED means that the window
13420 end is in the range of changed text. If so, there is no
13421 unchanged row at the end of W's current matrix. */
13422 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
13425 /* Set row to the last row in W's current matrix displaying text. */
13426 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13428 /* If matrix is entirely empty, no unchanged row exists. */
13429 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13431 /* The value of row is the last glyph row in the matrix having a
13432 meaningful buffer position in it. The end position of row
13433 corresponds to window_end_pos. This allows us to translate
13434 buffer positions in the current matrix to current buffer
13435 positions for characters not in changed text. */
13436 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13437 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13438 int last_unchanged_pos
, last_unchanged_pos_old
;
13439 struct glyph_row
*first_text_row
13440 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13442 *delta
= Z
- Z_old
;
13443 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13445 /* Set last_unchanged_pos to the buffer position of the last
13446 character in the buffer that has not been changed. Z is the
13447 index + 1 of the last character in current_buffer, i.e. by
13448 subtracting END_UNCHANGED we get the index of the last
13449 unchanged character, and we have to add BEG to get its buffer
13451 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
13452 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
13454 /* Search backward from ROW for a row displaying a line that
13455 starts at a minimum position >= last_unchanged_pos_old. */
13456 for (; row
> first_text_row
; --row
)
13458 /* This used to abort, but it can happen.
13459 It is ok to just stop the search instead here. KFS. */
13460 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13463 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
13468 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
13475 /* Make sure that glyph rows in the current matrix of window W
13476 reference the same glyph memory as corresponding rows in the
13477 frame's frame matrix. This function is called after scrolling W's
13478 current matrix on a terminal frame in try_window_id and
13479 try_window_reusing_current_matrix. */
13482 sync_frame_with_window_matrix_rows (w
)
13485 struct frame
*f
= XFRAME (w
->frame
);
13486 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
13488 /* Preconditions: W must be a leaf window and full-width. Its frame
13489 must have a frame matrix. */
13490 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
13491 xassert (WINDOW_FULL_WIDTH_P (w
));
13492 xassert (!FRAME_WINDOW_P (f
));
13494 /* If W is a full-width window, glyph pointers in W's current matrix
13495 have, by definition, to be the same as glyph pointers in the
13496 corresponding frame matrix. Note that frame matrices have no
13497 marginal areas (see build_frame_matrix). */
13498 window_row
= w
->current_matrix
->rows
;
13499 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
13500 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
13501 while (window_row
< window_row_end
)
13503 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
13504 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
13506 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
13507 frame_row
->glyphs
[TEXT_AREA
] = start
;
13508 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
13509 frame_row
->glyphs
[LAST_AREA
] = end
;
13511 /* Disable frame rows whose corresponding window rows have
13512 been disabled in try_window_id. */
13513 if (!window_row
->enabled_p
)
13514 frame_row
->enabled_p
= 0;
13516 ++window_row
, ++frame_row
;
13521 /* Find the glyph row in window W containing CHARPOS. Consider all
13522 rows between START and END (not inclusive). END null means search
13523 all rows to the end of the display area of W. Value is the row
13524 containing CHARPOS or null. */
13527 row_containing_pos (w
, charpos
, start
, end
, dy
)
13530 struct glyph_row
*start
, *end
;
13533 struct glyph_row
*row
= start
;
13536 /* If we happen to start on a header-line, skip that. */
13537 if (row
->mode_line_p
)
13540 if ((end
&& row
>= end
) || !row
->enabled_p
)
13543 last_y
= window_text_bottom_y (w
) - dy
;
13547 /* Give up if we have gone too far. */
13548 if (end
&& row
>= end
)
13550 /* This formerly returned if they were equal.
13551 I think that both quantities are of a "last plus one" type;
13552 if so, when they are equal, the row is within the screen. -- rms. */
13553 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
13556 /* If it is in this row, return this row. */
13557 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
13558 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
13559 /* The end position of a row equals the start
13560 position of the next row. If CHARPOS is there, we
13561 would rather display it in the next line, except
13562 when this line ends in ZV. */
13563 && !row
->ends_at_zv_p
13564 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13565 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
13572 /* Try to redisplay window W by reusing its existing display. W's
13573 current matrix must be up to date when this function is called,
13574 i.e. window_end_valid must not be nil.
13578 1 if display has been updated
13579 0 if otherwise unsuccessful
13580 -1 if redisplay with same window start is known not to succeed
13582 The following steps are performed:
13584 1. Find the last row in the current matrix of W that is not
13585 affected by changes at the start of current_buffer. If no such row
13588 2. Find the first row in W's current matrix that is not affected by
13589 changes at the end of current_buffer. Maybe there is no such row.
13591 3. Display lines beginning with the row + 1 found in step 1 to the
13592 row found in step 2 or, if step 2 didn't find a row, to the end of
13595 4. If cursor is not known to appear on the window, give up.
13597 5. If display stopped at the row found in step 2, scroll the
13598 display and current matrix as needed.
13600 6. Maybe display some lines at the end of W, if we must. This can
13601 happen under various circumstances, like a partially visible line
13602 becoming fully visible, or because newly displayed lines are displayed
13603 in smaller font sizes.
13605 7. Update W's window end information. */
13611 struct frame
*f
= XFRAME (w
->frame
);
13612 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
13613 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
13614 struct glyph_row
*last_unchanged_at_beg_row
;
13615 struct glyph_row
*first_unchanged_at_end_row
;
13616 struct glyph_row
*row
;
13617 struct glyph_row
*bottom_row
;
13620 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
13621 struct text_pos start_pos
;
13623 int first_unchanged_at_end_vpos
= 0;
13624 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
13625 struct text_pos start
;
13626 int first_changed_charpos
, last_changed_charpos
;
13629 if (inhibit_try_window_id
)
13633 /* This is handy for debugging. */
13635 #define GIVE_UP(X) \
13637 fprintf (stderr, "try_window_id give up %d\n", (X)); \
13641 #define GIVE_UP(X) return 0
13644 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
13646 /* Don't use this for mini-windows because these can show
13647 messages and mini-buffers, and we don't handle that here. */
13648 if (MINI_WINDOW_P (w
))
13651 /* This flag is used to prevent redisplay optimizations. */
13652 if (windows_or_buffers_changed
|| cursor_type_changed
)
13655 /* Verify that narrowing has not changed.
13656 Also verify that we were not told to prevent redisplay optimizations.
13657 It would be nice to further
13658 reduce the number of cases where this prevents try_window_id. */
13659 if (current_buffer
->clip_changed
13660 || current_buffer
->prevent_redisplay_optimizations_p
)
13663 /* Window must either use window-based redisplay or be full width. */
13664 if (!FRAME_WINDOW_P (f
)
13665 && (!line_ins_del_ok
13666 || !WINDOW_FULL_WIDTH_P (w
)))
13669 /* Give up if point is not known NOT to appear in W. */
13670 if (PT
< CHARPOS (start
))
13673 /* Another way to prevent redisplay optimizations. */
13674 if (XFASTINT (w
->last_modified
) == 0)
13677 /* Verify that window is not hscrolled. */
13678 if (XFASTINT (w
->hscroll
) != 0)
13681 /* Verify that display wasn't paused. */
13682 if (NILP (w
->window_end_valid
))
13685 /* Can't use this if highlighting a region because a cursor movement
13686 will do more than just set the cursor. */
13687 if (!NILP (Vtransient_mark_mode
)
13688 && !NILP (current_buffer
->mark_active
))
13691 /* Likewise if highlighting trailing whitespace. */
13692 if (!NILP (Vshow_trailing_whitespace
))
13695 /* Likewise if showing a region. */
13696 if (!NILP (w
->region_showing
))
13699 /* Can use this if overlay arrow position and or string have changed. */
13700 if (overlay_arrows_changed_p ())
13704 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
13705 only if buffer has really changed. The reason is that the gap is
13706 initially at Z for freshly visited files. The code below would
13707 set end_unchanged to 0 in that case. */
13708 if (MODIFF
> SAVE_MODIFF
13709 /* This seems to happen sometimes after saving a buffer. */
13710 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
13712 if (GPT
- BEG
< BEG_UNCHANGED
)
13713 BEG_UNCHANGED
= GPT
- BEG
;
13714 if (Z
- GPT
< END_UNCHANGED
)
13715 END_UNCHANGED
= Z
- GPT
;
13718 /* The position of the first and last character that has been changed. */
13719 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
13720 last_changed_charpos
= Z
- END_UNCHANGED
;
13722 /* If window starts after a line end, and the last change is in
13723 front of that newline, then changes don't affect the display.
13724 This case happens with stealth-fontification. Note that although
13725 the display is unchanged, glyph positions in the matrix have to
13726 be adjusted, of course. */
13727 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13728 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13729 && ((last_changed_charpos
< CHARPOS (start
)
13730 && CHARPOS (start
) == BEGV
)
13731 || (last_changed_charpos
< CHARPOS (start
) - 1
13732 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
13734 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
13735 struct glyph_row
*r0
;
13737 /* Compute how many chars/bytes have been added to or removed
13738 from the buffer. */
13739 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13740 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13742 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13744 /* Give up if PT is not in the window. Note that it already has
13745 been checked at the start of try_window_id that PT is not in
13746 front of the window start. */
13747 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
13750 /* If window start is unchanged, we can reuse the whole matrix
13751 as is, after adjusting glyph positions. No need to compute
13752 the window end again, since its offset from Z hasn't changed. */
13753 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13754 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
13755 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
13756 /* PT must not be in a partially visible line. */
13757 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
13758 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13760 /* Adjust positions in the glyph matrix. */
13761 if (delta
|| delta_bytes
)
13763 struct glyph_row
*r1
13764 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13765 increment_matrix_positions (w
->current_matrix
,
13766 MATRIX_ROW_VPOS (r0
, current_matrix
),
13767 MATRIX_ROW_VPOS (r1
, current_matrix
),
13768 delta
, delta_bytes
);
13771 /* Set the cursor. */
13772 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13774 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13781 /* Handle the case that changes are all below what is displayed in
13782 the window, and that PT is in the window. This shortcut cannot
13783 be taken if ZV is visible in the window, and text has been added
13784 there that is visible in the window. */
13785 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
13786 /* ZV is not visible in the window, or there are no
13787 changes at ZV, actually. */
13788 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
13789 || first_changed_charpos
== last_changed_charpos
))
13791 struct glyph_row
*r0
;
13793 /* Give up if PT is not in the window. Note that it already has
13794 been checked at the start of try_window_id that PT is not in
13795 front of the window start. */
13796 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
13799 /* If window start is unchanged, we can reuse the whole matrix
13800 as is, without changing glyph positions since no text has
13801 been added/removed in front of the window end. */
13802 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13803 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
13804 /* PT must not be in a partially visible line. */
13805 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
13806 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13808 /* We have to compute the window end anew since text
13809 can have been added/removed after it. */
13811 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13812 w
->window_end_bytepos
13813 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13815 /* Set the cursor. */
13816 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13818 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13825 /* Give up if window start is in the changed area.
13827 The condition used to read
13829 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
13831 but why that was tested escapes me at the moment. */
13832 if (CHARPOS (start
) >= first_changed_charpos
13833 && CHARPOS (start
) <= last_changed_charpos
)
13836 /* Check that window start agrees with the start of the first glyph
13837 row in its current matrix. Check this after we know the window
13838 start is not in changed text, otherwise positions would not be
13840 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13841 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
13844 /* Give up if the window ends in strings. Overlay strings
13845 at the end are difficult to handle, so don't try. */
13846 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
13847 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
13850 /* Compute the position at which we have to start displaying new
13851 lines. Some of the lines at the top of the window might be
13852 reusable because they are not displaying changed text. Find the
13853 last row in W's current matrix not affected by changes at the
13854 start of current_buffer. Value is null if changes start in the
13855 first line of window. */
13856 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
13857 if (last_unchanged_at_beg_row
)
13859 /* Avoid starting to display in the moddle of a character, a TAB
13860 for instance. This is easier than to set up the iterator
13861 exactly, and it's not a frequent case, so the additional
13862 effort wouldn't really pay off. */
13863 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
13864 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
13865 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
13866 --last_unchanged_at_beg_row
;
13868 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
13871 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
13873 start_pos
= it
.current
.pos
;
13875 /* Start displaying new lines in the desired matrix at the same
13876 vpos we would use in the current matrix, i.e. below
13877 last_unchanged_at_beg_row. */
13878 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
13880 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13881 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
13883 xassert (it
.hpos
== 0 && it
.current_x
== 0);
13887 /* There are no reusable lines at the start of the window.
13888 Start displaying in the first text line. */
13889 start_display (&it
, w
, start
);
13890 it
.vpos
= it
.first_vpos
;
13891 start_pos
= it
.current
.pos
;
13894 /* Find the first row that is not affected by changes at the end of
13895 the buffer. Value will be null if there is no unchanged row, in
13896 which case we must redisplay to the end of the window. delta
13897 will be set to the value by which buffer positions beginning with
13898 first_unchanged_at_end_row have to be adjusted due to text
13900 first_unchanged_at_end_row
13901 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
13902 IF_DEBUG (debug_delta
= delta
);
13903 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
13905 /* Set stop_pos to the buffer position up to which we will have to
13906 display new lines. If first_unchanged_at_end_row != NULL, this
13907 is the buffer position of the start of the line displayed in that
13908 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
13909 that we don't stop at a buffer position. */
13911 if (first_unchanged_at_end_row
)
13913 xassert (last_unchanged_at_beg_row
== NULL
13914 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
13916 /* If this is a continuation line, move forward to the next one
13917 that isn't. Changes in lines above affect this line.
13918 Caution: this may move first_unchanged_at_end_row to a row
13919 not displaying text. */
13920 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
13921 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13922 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13923 < it
.last_visible_y
))
13924 ++first_unchanged_at_end_row
;
13926 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13927 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13928 >= it
.last_visible_y
))
13929 first_unchanged_at_end_row
= NULL
;
13932 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13934 first_unchanged_at_end_vpos
13935 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13936 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13939 else if (last_unchanged_at_beg_row
== NULL
)
13945 /* Either there is no unchanged row at the end, or the one we have
13946 now displays text. This is a necessary condition for the window
13947 end pos calculation at the end of this function. */
13948 xassert (first_unchanged_at_end_row
== NULL
13949 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
13951 debug_last_unchanged_at_beg_vpos
13952 = (last_unchanged_at_beg_row
13953 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
13955 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
13957 #endif /* GLYPH_DEBUG != 0 */
13960 /* Display new lines. Set last_text_row to the last new line
13961 displayed which has text on it, i.e. might end up as being the
13962 line where the window_end_vpos is. */
13963 w
->cursor
.vpos
= -1;
13964 last_text_row
= NULL
;
13965 overlay_arrow_seen
= 0;
13966 while (it
.current_y
< it
.last_visible_y
13967 && !fonts_changed_p
13968 && (first_unchanged_at_end_row
== NULL
13969 || IT_CHARPOS (it
) < stop_pos
))
13971 if (display_line (&it
))
13972 last_text_row
= it
.glyph_row
- 1;
13975 if (fonts_changed_p
)
13979 /* Compute differences in buffer positions, y-positions etc. for
13980 lines reused at the bottom of the window. Compute what we can
13982 if (first_unchanged_at_end_row
13983 /* No lines reused because we displayed everything up to the
13984 bottom of the window. */
13985 && it
.current_y
< it
.last_visible_y
)
13988 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
13990 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
13991 run
.current_y
= first_unchanged_at_end_row
->y
;
13992 run
.desired_y
= run
.current_y
+ dy
;
13993 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
13997 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
13998 first_unchanged_at_end_row
= NULL
;
14000 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14003 /* Find the cursor if not already found. We have to decide whether
14004 PT will appear on this window (it sometimes doesn't, but this is
14005 not a very frequent case.) This decision has to be made before
14006 the current matrix is altered. A value of cursor.vpos < 0 means
14007 that PT is either in one of the lines beginning at
14008 first_unchanged_at_end_row or below the window. Don't care for
14009 lines that might be displayed later at the window end; as
14010 mentioned, this is not a frequent case. */
14011 if (w
->cursor
.vpos
< 0)
14013 /* Cursor in unchanged rows at the top? */
14014 if (PT
< CHARPOS (start_pos
)
14015 && last_unchanged_at_beg_row
)
14017 row
= row_containing_pos (w
, PT
,
14018 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14019 last_unchanged_at_beg_row
+ 1, 0);
14021 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14024 /* Start from first_unchanged_at_end_row looking for PT. */
14025 else if (first_unchanged_at_end_row
)
14027 row
= row_containing_pos (w
, PT
- delta
,
14028 first_unchanged_at_end_row
, NULL
, 0);
14030 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14031 delta_bytes
, dy
, dvpos
);
14034 /* Give up if cursor was not found. */
14035 if (w
->cursor
.vpos
< 0)
14037 clear_glyph_matrix (w
->desired_matrix
);
14042 /* Don't let the cursor end in the scroll margins. */
14044 int this_scroll_margin
, cursor_height
;
14046 this_scroll_margin
= max (0, scroll_margin
);
14047 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14048 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14049 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14051 if ((w
->cursor
.y
< this_scroll_margin
14052 && CHARPOS (start
) > BEGV
)
14053 /* Old redisplay didn't take scroll margin into account at the bottom,
14054 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14055 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14056 ? cursor_height
+ this_scroll_margin
14057 : 1)) > it
.last_visible_y
)
14059 w
->cursor
.vpos
= -1;
14060 clear_glyph_matrix (w
->desired_matrix
);
14065 /* Scroll the display. Do it before changing the current matrix so
14066 that xterm.c doesn't get confused about where the cursor glyph is
14068 if (dy
&& run
.height
)
14072 if (FRAME_WINDOW_P (f
))
14074 rif
->update_window_begin_hook (w
);
14075 rif
->clear_window_mouse_face (w
);
14076 rif
->scroll_run_hook (w
, &run
);
14077 rif
->update_window_end_hook (w
, 0, 0);
14081 /* Terminal frame. In this case, dvpos gives the number of
14082 lines to scroll by; dvpos < 0 means scroll up. */
14083 int first_unchanged_at_end_vpos
14084 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14085 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14086 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14087 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14088 + window_internal_height (w
));
14090 /* Perform the operation on the screen. */
14093 /* Scroll last_unchanged_at_beg_row to the end of the
14094 window down dvpos lines. */
14095 set_terminal_window (end
);
14097 /* On dumb terminals delete dvpos lines at the end
14098 before inserting dvpos empty lines. */
14099 if (!scroll_region_ok
)
14100 ins_del_lines (end
- dvpos
, -dvpos
);
14102 /* Insert dvpos empty lines in front of
14103 last_unchanged_at_beg_row. */
14104 ins_del_lines (from
, dvpos
);
14106 else if (dvpos
< 0)
14108 /* Scroll up last_unchanged_at_beg_vpos to the end of
14109 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14110 set_terminal_window (end
);
14112 /* Delete dvpos lines in front of
14113 last_unchanged_at_beg_vpos. ins_del_lines will set
14114 the cursor to the given vpos and emit |dvpos| delete
14116 ins_del_lines (from
+ dvpos
, dvpos
);
14118 /* On a dumb terminal insert dvpos empty lines at the
14120 if (!scroll_region_ok
)
14121 ins_del_lines (end
+ dvpos
, -dvpos
);
14124 set_terminal_window (0);
14130 /* Shift reused rows of the current matrix to the right position.
14131 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14133 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14134 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14137 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14138 bottom_vpos
, dvpos
);
14139 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14142 else if (dvpos
> 0)
14144 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14145 bottom_vpos
, dvpos
);
14146 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14147 first_unchanged_at_end_vpos
+ dvpos
, 0);
14150 /* For frame-based redisplay, make sure that current frame and window
14151 matrix are in sync with respect to glyph memory. */
14152 if (!FRAME_WINDOW_P (f
))
14153 sync_frame_with_window_matrix_rows (w
);
14155 /* Adjust buffer positions in reused rows. */
14157 increment_matrix_positions (current_matrix
,
14158 first_unchanged_at_end_vpos
+ dvpos
,
14159 bottom_vpos
, delta
, delta_bytes
);
14161 /* Adjust Y positions. */
14163 shift_glyph_matrix (w
, current_matrix
,
14164 first_unchanged_at_end_vpos
+ dvpos
,
14167 if (first_unchanged_at_end_row
)
14169 first_unchanged_at_end_row
+= dvpos
;
14170 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14171 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
14172 first_unchanged_at_end_row
= NULL
;
14175 /* If scrolling up, there may be some lines to display at the end of
14177 last_text_row_at_end
= NULL
;
14180 /* Scrolling up can leave for example a partially visible line
14181 at the end of the window to be redisplayed. */
14182 /* Set last_row to the glyph row in the current matrix where the
14183 window end line is found. It has been moved up or down in
14184 the matrix by dvpos. */
14185 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
14186 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
14188 /* If last_row is the window end line, it should display text. */
14189 xassert (last_row
->displays_text_p
);
14191 /* If window end line was partially visible before, begin
14192 displaying at that line. Otherwise begin displaying with the
14193 line following it. */
14194 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
14196 init_to_row_start (&it
, w
, last_row
);
14197 it
.vpos
= last_vpos
;
14198 it
.current_y
= last_row
->y
;
14202 init_to_row_end (&it
, w
, last_row
);
14203 it
.vpos
= 1 + last_vpos
;
14204 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
14208 /* We may start in a continuation line. If so, we have to
14209 get the right continuation_lines_width and current_x. */
14210 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
14211 it
.hpos
= it
.current_x
= 0;
14213 /* Display the rest of the lines at the window end. */
14214 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14215 while (it
.current_y
< it
.last_visible_y
14216 && !fonts_changed_p
)
14218 /* Is it always sure that the display agrees with lines in
14219 the current matrix? I don't think so, so we mark rows
14220 displayed invalid in the current matrix by setting their
14221 enabled_p flag to zero. */
14222 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
14223 if (display_line (&it
))
14224 last_text_row_at_end
= it
.glyph_row
- 1;
14228 /* Update window_end_pos and window_end_vpos. */
14229 if (first_unchanged_at_end_row
14230 && !last_text_row_at_end
)
14232 /* Window end line if one of the preserved rows from the current
14233 matrix. Set row to the last row displaying text in current
14234 matrix starting at first_unchanged_at_end_row, after
14236 xassert (first_unchanged_at_end_row
->displays_text_p
);
14237 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
14238 first_unchanged_at_end_row
);
14239 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
14241 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14242 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14244 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
14245 xassert (w
->window_end_bytepos
>= 0);
14246 IF_DEBUG (debug_method_add (w
, "A"));
14248 else if (last_text_row_at_end
)
14251 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
14252 w
->window_end_bytepos
14253 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
14255 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
14256 xassert (w
->window_end_bytepos
>= 0);
14257 IF_DEBUG (debug_method_add (w
, "B"));
14259 else if (last_text_row
)
14261 /* We have displayed either to the end of the window or at the
14262 end of the window, i.e. the last row with text is to be found
14263 in the desired matrix. */
14265 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14266 w
->window_end_bytepos
14267 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14269 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
14270 xassert (w
->window_end_bytepos
>= 0);
14272 else if (first_unchanged_at_end_row
== NULL
14273 && last_text_row
== NULL
14274 && last_text_row_at_end
== NULL
)
14276 /* Displayed to end of window, but no line containing text was
14277 displayed. Lines were deleted at the end of the window. */
14278 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
14279 int vpos
= XFASTINT (w
->window_end_vpos
);
14280 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
14281 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
14284 row
== NULL
&& vpos
>= first_vpos
;
14285 --vpos
, --current_row
, --desired_row
)
14287 if (desired_row
->enabled_p
)
14289 if (desired_row
->displays_text_p
)
14292 else if (current_row
->displays_text_p
)
14296 xassert (row
!= NULL
);
14297 w
->window_end_vpos
= make_number (vpos
+ 1);
14298 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14299 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14300 xassert (w
->window_end_bytepos
>= 0);
14301 IF_DEBUG (debug_method_add (w
, "C"));
14306 #if 0 /* This leads to problems, for instance when the cursor is
14307 at ZV, and the cursor line displays no text. */
14308 /* Disable rows below what's displayed in the window. This makes
14309 debugging easier. */
14310 enable_glyph_matrix_rows (current_matrix
,
14311 XFASTINT (w
->window_end_vpos
) + 1,
14315 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
14316 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
14318 /* Record that display has not been completed. */
14319 w
->window_end_valid
= Qnil
;
14320 w
->desired_matrix
->no_scrolling_p
= 1;
14328 /***********************************************************************
14329 More debugging support
14330 ***********************************************************************/
14334 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
14335 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
14336 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
14339 /* Dump the contents of glyph matrix MATRIX on stderr.
14341 GLYPHS 0 means don't show glyph contents.
14342 GLYPHS 1 means show glyphs in short form
14343 GLYPHS > 1 means show glyphs in long form. */
14346 dump_glyph_matrix (matrix
, glyphs
)
14347 struct glyph_matrix
*matrix
;
14351 for (i
= 0; i
< matrix
->nrows
; ++i
)
14352 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
14356 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
14357 the glyph row and area where the glyph comes from. */
14360 dump_glyph (row
, glyph
, area
)
14361 struct glyph_row
*row
;
14362 struct glyph
*glyph
;
14365 if (glyph
->type
== CHAR_GLYPH
)
14368 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14369 glyph
- row
->glyphs
[TEXT_AREA
],
14372 (BUFFERP (glyph
->object
)
14374 : (STRINGP (glyph
->object
)
14377 glyph
->pixel_width
,
14379 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
14383 glyph
->left_box_line_p
,
14384 glyph
->right_box_line_p
);
14386 else if (glyph
->type
== STRETCH_GLYPH
)
14389 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14390 glyph
- row
->glyphs
[TEXT_AREA
],
14393 (BUFFERP (glyph
->object
)
14395 : (STRINGP (glyph
->object
)
14398 glyph
->pixel_width
,
14402 glyph
->left_box_line_p
,
14403 glyph
->right_box_line_p
);
14405 else if (glyph
->type
== IMAGE_GLYPH
)
14408 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14409 glyph
- row
->glyphs
[TEXT_AREA
],
14412 (BUFFERP (glyph
->object
)
14414 : (STRINGP (glyph
->object
)
14417 glyph
->pixel_width
,
14421 glyph
->left_box_line_p
,
14422 glyph
->right_box_line_p
);
14427 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
14428 GLYPHS 0 means don't show glyph contents.
14429 GLYPHS 1 means show glyphs in short form
14430 GLYPHS > 1 means show glyphs in long form. */
14433 dump_glyph_row (row
, vpos
, glyphs
)
14434 struct glyph_row
*row
;
14439 fprintf (stderr
, "Row Start End Used oEI><\\CTZFesm X Y W H V A P\n");
14440 fprintf (stderr
, "======================================================================\n");
14442 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
14443 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
14445 MATRIX_ROW_START_CHARPOS (row
),
14446 MATRIX_ROW_END_CHARPOS (row
),
14447 row
->used
[TEXT_AREA
],
14448 row
->contains_overlapping_glyphs_p
,
14450 row
->truncated_on_left_p
,
14451 row
->truncated_on_right_p
,
14453 MATRIX_ROW_CONTINUATION_LINE_P (row
),
14454 row
->displays_text_p
,
14457 row
->ends_in_middle_of_char_p
,
14458 row
->starts_in_middle_of_char_p
,
14464 row
->visible_height
,
14467 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
14468 row
->end
.overlay_string_index
,
14469 row
->continuation_lines_width
);
14470 fprintf (stderr
, "%9d %5d\n",
14471 CHARPOS (row
->start
.string_pos
),
14472 CHARPOS (row
->end
.string_pos
));
14473 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
14474 row
->end
.dpvec_index
);
14481 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14483 struct glyph
*glyph
= row
->glyphs
[area
];
14484 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
14486 /* Glyph for a line end in text. */
14487 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
14490 if (glyph
< glyph_end
)
14491 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
14493 for (; glyph
< glyph_end
; ++glyph
)
14494 dump_glyph (row
, glyph
, area
);
14497 else if (glyphs
== 1)
14501 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14503 char *s
= (char *) alloca (row
->used
[area
] + 1);
14506 for (i
= 0; i
< row
->used
[area
]; ++i
)
14508 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
14509 if (glyph
->type
== CHAR_GLYPH
14510 && glyph
->u
.ch
< 0x80
14511 && glyph
->u
.ch
>= ' ')
14512 s
[i
] = glyph
->u
.ch
;
14518 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
14524 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
14525 Sdump_glyph_matrix
, 0, 1, "p",
14526 doc
: /* Dump the current matrix of the selected window to stderr.
14527 Shows contents of glyph row structures. With non-nil
14528 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
14529 glyphs in short form, otherwise show glyphs in long form. */)
14531 Lisp_Object glyphs
;
14533 struct window
*w
= XWINDOW (selected_window
);
14534 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14536 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
14537 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
14538 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
14539 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
14540 fprintf (stderr
, "=============================================\n");
14541 dump_glyph_matrix (w
->current_matrix
,
14542 NILP (glyphs
) ? 0 : XINT (glyphs
));
14547 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
14548 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
14551 struct frame
*f
= XFRAME (selected_frame
);
14552 dump_glyph_matrix (f
->current_matrix
, 1);
14557 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
14558 doc
: /* Dump glyph row ROW to stderr.
14559 GLYPH 0 means don't dump glyphs.
14560 GLYPH 1 means dump glyphs in short form.
14561 GLYPH > 1 or omitted means dump glyphs in long form. */)
14563 Lisp_Object row
, glyphs
;
14565 struct glyph_matrix
*matrix
;
14568 CHECK_NUMBER (row
);
14569 matrix
= XWINDOW (selected_window
)->current_matrix
;
14571 if (vpos
>= 0 && vpos
< matrix
->nrows
)
14572 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
14574 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14579 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
14580 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
14581 GLYPH 0 means don't dump glyphs.
14582 GLYPH 1 means dump glyphs in short form.
14583 GLYPH > 1 or omitted means dump glyphs in long form. */)
14585 Lisp_Object row
, glyphs
;
14587 struct frame
*sf
= SELECTED_FRAME ();
14588 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
14591 CHECK_NUMBER (row
);
14593 if (vpos
>= 0 && vpos
< m
->nrows
)
14594 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
14595 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14600 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
14601 doc
: /* Toggle tracing of redisplay.
14602 With ARG, turn tracing on if and only if ARG is positive. */)
14607 trace_redisplay_p
= !trace_redisplay_p
;
14610 arg
= Fprefix_numeric_value (arg
);
14611 trace_redisplay_p
= XINT (arg
) > 0;
14618 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
14619 doc
: /* Like `format', but print result to stderr.
14620 usage: (trace-to-stderr STRING &rest OBJECTS) */)
14625 Lisp_Object s
= Fformat (nargs
, args
);
14626 fprintf (stderr
, "%s", SDATA (s
));
14630 #endif /* GLYPH_DEBUG */
14634 /***********************************************************************
14635 Building Desired Matrix Rows
14636 ***********************************************************************/
14638 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
14639 Used for non-window-redisplay windows, and for windows w/o left fringe. */
14641 static struct glyph_row
*
14642 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
14644 Lisp_Object overlay_arrow_string
;
14646 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14647 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14648 struct buffer
*old
= current_buffer
;
14649 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
14650 int arrow_len
= SCHARS (overlay_arrow_string
);
14651 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
14652 const unsigned char *p
;
14655 int n_glyphs_before
;
14657 set_buffer_temp (buffer
);
14658 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
14659 it
.glyph_row
->used
[TEXT_AREA
] = 0;
14660 SET_TEXT_POS (it
.position
, 0, 0);
14662 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
14664 while (p
< arrow_end
)
14666 Lisp_Object face
, ilisp
;
14668 /* Get the next character. */
14670 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
14672 it
.c
= *p
, it
.len
= 1;
14675 /* Get its face. */
14676 ilisp
= make_number (p
- arrow_string
);
14677 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
14678 it
.face_id
= compute_char_face (f
, it
.c
, face
);
14680 /* Compute its width, get its glyphs. */
14681 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
14682 SET_TEXT_POS (it
.position
, -1, -1);
14683 PRODUCE_GLYPHS (&it
);
14685 /* If this character doesn't fit any more in the line, we have
14686 to remove some glyphs. */
14687 if (it
.current_x
> it
.last_visible_x
)
14689 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14694 set_buffer_temp (old
);
14695 return it
.glyph_row
;
14699 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
14700 glyphs are only inserted for terminal frames since we can't really
14701 win with truncation glyphs when partially visible glyphs are
14702 involved. Which glyphs to insert is determined by
14703 produce_special_glyphs. */
14706 insert_left_trunc_glyphs (it
)
14709 struct it truncate_it
;
14710 struct glyph
*from
, *end
, *to
, *toend
;
14712 xassert (!FRAME_WINDOW_P (it
->f
));
14714 /* Get the truncation glyphs. */
14716 truncate_it
.current_x
= 0;
14717 truncate_it
.face_id
= DEFAULT_FACE_ID
;
14718 truncate_it
.glyph_row
= &scratch_glyph_row
;
14719 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
14720 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
14721 truncate_it
.object
= make_number (0);
14722 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
14724 /* Overwrite glyphs from IT with truncation glyphs. */
14725 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14726 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
14727 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
14728 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
14733 /* There may be padding glyphs left over. Overwrite them too. */
14734 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
14736 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14742 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
14746 /* Compute the pixel height and width of IT->glyph_row.
14748 Most of the time, ascent and height of a display line will be equal
14749 to the max_ascent and max_height values of the display iterator
14750 structure. This is not the case if
14752 1. We hit ZV without displaying anything. In this case, max_ascent
14753 and max_height will be zero.
14755 2. We have some glyphs that don't contribute to the line height.
14756 (The glyph row flag contributes_to_line_height_p is for future
14757 pixmap extensions).
14759 The first case is easily covered by using default values because in
14760 these cases, the line height does not really matter, except that it
14761 must not be zero. */
14764 compute_line_metrics (it
)
14767 struct glyph_row
*row
= it
->glyph_row
;
14770 if (FRAME_WINDOW_P (it
->f
))
14772 int i
, min_y
, max_y
;
14774 /* The line may consist of one space only, that was added to
14775 place the cursor on it. If so, the row's height hasn't been
14777 if (row
->height
== 0)
14779 if (it
->max_ascent
+ it
->max_descent
== 0)
14780 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
14781 row
->ascent
= it
->max_ascent
;
14782 row
->height
= it
->max_ascent
+ it
->max_descent
;
14783 row
->phys_ascent
= it
->max_phys_ascent
;
14784 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14785 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
14788 /* Compute the width of this line. */
14789 row
->pixel_width
= row
->x
;
14790 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
14791 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
14793 xassert (row
->pixel_width
>= 0);
14794 xassert (row
->ascent
>= 0 && row
->height
> 0);
14796 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
14797 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
14799 /* If first line's physical ascent is larger than its logical
14800 ascent, use the physical ascent, and make the row taller.
14801 This makes accented characters fully visible. */
14802 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
14803 && row
->phys_ascent
> row
->ascent
)
14805 row
->height
+= row
->phys_ascent
- row
->ascent
;
14806 row
->ascent
= row
->phys_ascent
;
14809 /* Compute how much of the line is visible. */
14810 row
->visible_height
= row
->height
;
14812 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
14813 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
14815 if (row
->y
< min_y
)
14816 row
->visible_height
-= min_y
- row
->y
;
14817 if (row
->y
+ row
->height
> max_y
)
14818 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14822 row
->pixel_width
= row
->used
[TEXT_AREA
];
14823 if (row
->continued_p
)
14824 row
->pixel_width
-= it
->continuation_pixel_width
;
14825 else if (row
->truncated_on_right_p
)
14826 row
->pixel_width
-= it
->truncation_pixel_width
;
14827 row
->ascent
= row
->phys_ascent
= 0;
14828 row
->height
= row
->phys_height
= row
->visible_height
= 1;
14829 row
->extra_line_spacing
= 0;
14832 /* Compute a hash code for this row. */
14834 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14835 for (i
= 0; i
< row
->used
[area
]; ++i
)
14836 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
14837 + row
->glyphs
[area
][i
].u
.val
14838 + row
->glyphs
[area
][i
].face_id
14839 + row
->glyphs
[area
][i
].padding_p
14840 + (row
->glyphs
[area
][i
].type
<< 2));
14842 it
->max_ascent
= it
->max_descent
= 0;
14843 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
14847 /* Append one space to the glyph row of iterator IT if doing a
14848 window-based redisplay. The space has the same face as
14849 IT->face_id. Value is non-zero if a space was added.
14851 This function is called to make sure that there is always one glyph
14852 at the end of a glyph row that the cursor can be set on under
14853 window-systems. (If there weren't such a glyph we would not know
14854 how wide and tall a box cursor should be displayed).
14856 At the same time this space let's a nicely handle clearing to the
14857 end of the line if the row ends in italic text. */
14860 append_space_for_newline (it
, default_face_p
)
14862 int default_face_p
;
14864 if (FRAME_WINDOW_P (it
->f
))
14866 int n
= it
->glyph_row
->used
[TEXT_AREA
];
14868 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
14869 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
14871 /* Save some values that must not be changed.
14872 Must save IT->c and IT->len because otherwise
14873 ITERATOR_AT_END_P wouldn't work anymore after
14874 append_space_for_newline has been called. */
14875 enum display_element_type saved_what
= it
->what
;
14876 int saved_c
= it
->c
, saved_len
= it
->len
;
14877 int saved_x
= it
->current_x
;
14878 int saved_face_id
= it
->face_id
;
14879 struct text_pos saved_pos
;
14880 Lisp_Object saved_object
;
14883 saved_object
= it
->object
;
14884 saved_pos
= it
->position
;
14886 it
->what
= IT_CHARACTER
;
14887 bzero (&it
->position
, sizeof it
->position
);
14888 it
->object
= make_number (0);
14892 if (default_face_p
)
14893 it
->face_id
= DEFAULT_FACE_ID
;
14894 else if (it
->face_before_selective_p
)
14895 it
->face_id
= it
->saved_face_id
;
14896 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14897 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
14899 PRODUCE_GLYPHS (it
);
14901 it
->override_ascent
= -1;
14902 it
->constrain_row_ascent_descent_p
= 0;
14903 it
->current_x
= saved_x
;
14904 it
->object
= saved_object
;
14905 it
->position
= saved_pos
;
14906 it
->what
= saved_what
;
14907 it
->face_id
= saved_face_id
;
14908 it
->len
= saved_len
;
14918 /* Extend the face of the last glyph in the text area of IT->glyph_row
14919 to the end of the display line. Called from display_line.
14920 If the glyph row is empty, add a space glyph to it so that we
14921 know the face to draw. Set the glyph row flag fill_line_p. */
14924 extend_face_to_end_of_line (it
)
14928 struct frame
*f
= it
->f
;
14930 /* If line is already filled, do nothing. */
14931 if (it
->current_x
>= it
->last_visible_x
)
14934 /* Face extension extends the background and box of IT->face_id
14935 to the end of the line. If the background equals the background
14936 of the frame, we don't have to do anything. */
14937 if (it
->face_before_selective_p
)
14938 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14940 face
= FACE_FROM_ID (f
, it
->face_id
);
14942 if (FRAME_WINDOW_P (f
)
14943 && face
->box
== FACE_NO_BOX
14944 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
14948 /* Set the glyph row flag indicating that the face of the last glyph
14949 in the text area has to be drawn to the end of the text area. */
14950 it
->glyph_row
->fill_line_p
= 1;
14952 /* If current character of IT is not ASCII, make sure we have the
14953 ASCII face. This will be automatically undone the next time
14954 get_next_display_element returns a multibyte character. Note
14955 that the character will always be single byte in unibyte text. */
14956 if (!ASCII_CHAR_P (it
->c
))
14958 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
14961 if (FRAME_WINDOW_P (f
))
14963 /* If the row is empty, add a space with the current face of IT,
14964 so that we know which face to draw. */
14965 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
14967 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
14968 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
14969 it
->glyph_row
->used
[TEXT_AREA
] = 1;
14974 /* Save some values that must not be changed. */
14975 int saved_x
= it
->current_x
;
14976 struct text_pos saved_pos
;
14977 Lisp_Object saved_object
;
14978 enum display_element_type saved_what
= it
->what
;
14979 int saved_face_id
= it
->face_id
;
14981 saved_object
= it
->object
;
14982 saved_pos
= it
->position
;
14984 it
->what
= IT_CHARACTER
;
14985 bzero (&it
->position
, sizeof it
->position
);
14986 it
->object
= make_number (0);
14989 it
->face_id
= face
->id
;
14991 PRODUCE_GLYPHS (it
);
14993 while (it
->current_x
<= it
->last_visible_x
)
14994 PRODUCE_GLYPHS (it
);
14996 /* Don't count these blanks really. It would let us insert a left
14997 truncation glyph below and make us set the cursor on them, maybe. */
14998 it
->current_x
= saved_x
;
14999 it
->object
= saved_object
;
15000 it
->position
= saved_pos
;
15001 it
->what
= saved_what
;
15002 it
->face_id
= saved_face_id
;
15007 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15008 trailing whitespace. */
15011 trailing_whitespace_p (charpos
)
15014 int bytepos
= CHAR_TO_BYTE (charpos
);
15017 while (bytepos
< ZV_BYTE
15018 && (c
= FETCH_CHAR (bytepos
),
15019 c
== ' ' || c
== '\t'))
15022 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15024 if (bytepos
!= PT_BYTE
)
15031 /* Highlight trailing whitespace, if any, in ROW. */
15034 highlight_trailing_whitespace (f
, row
)
15036 struct glyph_row
*row
;
15038 int used
= row
->used
[TEXT_AREA
];
15042 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15043 struct glyph
*glyph
= start
+ used
- 1;
15045 /* Skip over glyphs inserted to display the cursor at the
15046 end of a line, for extending the face of the last glyph
15047 to the end of the line on terminals, and for truncation
15048 and continuation glyphs. */
15049 while (glyph
>= start
15050 && glyph
->type
== CHAR_GLYPH
15051 && INTEGERP (glyph
->object
))
15054 /* If last glyph is a space or stretch, and it's trailing
15055 whitespace, set the face of all trailing whitespace glyphs in
15056 IT->glyph_row to `trailing-whitespace'. */
15058 && BUFFERP (glyph
->object
)
15059 && (glyph
->type
== STRETCH_GLYPH
15060 || (glyph
->type
== CHAR_GLYPH
15061 && glyph
->u
.ch
== ' '))
15062 && trailing_whitespace_p (glyph
->charpos
))
15064 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
15068 while (glyph
>= start
15069 && BUFFERP (glyph
->object
)
15070 && (glyph
->type
== STRETCH_GLYPH
15071 || (glyph
->type
== CHAR_GLYPH
15072 && glyph
->u
.ch
== ' ')))
15073 (glyph
--)->face_id
= face_id
;
15079 /* Value is non-zero if glyph row ROW in window W should be
15080 used to hold the cursor. */
15083 cursor_row_p (w
, row
)
15085 struct glyph_row
*row
;
15087 int cursor_row_p
= 1;
15089 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15091 /* If the row ends with a newline from a string, we don't want
15092 the cursor there (if the row is continued it doesn't end in a
15094 if (CHARPOS (row
->end
.string_pos
) >= 0)
15095 cursor_row_p
= row
->continued_p
;
15096 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15098 /* If the row ends in middle of a real character,
15099 and the line is continued, we want the cursor here.
15100 That's because MATRIX_ROW_END_CHARPOS would equal
15101 PT if PT is before the character. */
15102 if (!row
->ends_in_ellipsis_p
)
15103 cursor_row_p
= row
->continued_p
;
15105 /* If the row ends in an ellipsis, then
15106 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15107 We want that position to be displayed after the ellipsis. */
15110 /* If the row ends at ZV, display the cursor at the end of that
15111 row instead of at the start of the row below. */
15112 else if (row
->ends_at_zv_p
)
15118 return cursor_row_p
;
15122 /* Construct the glyph row IT->glyph_row in the desired matrix of
15123 IT->w from text at the current position of IT. See dispextern.h
15124 for an overview of struct it. Value is non-zero if
15125 IT->glyph_row displays text, as opposed to a line displaying ZV
15132 struct glyph_row
*row
= it
->glyph_row
;
15133 Lisp_Object overlay_arrow_string
;
15135 /* We always start displaying at hpos zero even if hscrolled. */
15136 xassert (it
->hpos
== 0 && it
->current_x
== 0);
15138 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
15139 >= it
->w
->desired_matrix
->nrows
)
15141 it
->w
->nrows_scale_factor
++;
15142 fonts_changed_p
= 1;
15146 /* Is IT->w showing the region? */
15147 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
15149 /* Clear the result glyph row and enable it. */
15150 prepare_desired_row (row
);
15152 row
->y
= it
->current_y
;
15153 row
->start
= it
->start
;
15154 row
->continuation_lines_width
= it
->continuation_lines_width
;
15155 row
->displays_text_p
= 1;
15156 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
15157 it
->starts_in_middle_of_char_p
= 0;
15159 /* Arrange the overlays nicely for our purposes. Usually, we call
15160 display_line on only one line at a time, in which case this
15161 can't really hurt too much, or we call it on lines which appear
15162 one after another in the buffer, in which case all calls to
15163 recenter_overlay_lists but the first will be pretty cheap. */
15164 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
15166 /* Move over display elements that are not visible because we are
15167 hscrolled. This may stop at an x-position < IT->first_visible_x
15168 if the first glyph is partially visible or if we hit a line end. */
15169 if (it
->current_x
< it
->first_visible_x
)
15171 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
15172 MOVE_TO_POS
| MOVE_TO_X
);
15175 /* Get the initial row height. This is either the height of the
15176 text hscrolled, if there is any, or zero. */
15177 row
->ascent
= it
->max_ascent
;
15178 row
->height
= it
->max_ascent
+ it
->max_descent
;
15179 row
->phys_ascent
= it
->max_phys_ascent
;
15180 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15181 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15183 /* Loop generating characters. The loop is left with IT on the next
15184 character to display. */
15187 int n_glyphs_before
, hpos_before
, x_before
;
15189 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
15191 /* Retrieve the next thing to display. Value is zero if end of
15193 if (!get_next_display_element (it
))
15195 /* Maybe add a space at the end of this line that is used to
15196 display the cursor there under X. Set the charpos of the
15197 first glyph of blank lines not corresponding to any text
15199 #ifdef HAVE_WINDOW_SYSTEM
15200 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15201 row
->exact_window_width_line_p
= 1;
15203 #endif /* HAVE_WINDOW_SYSTEM */
15204 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
15205 || row
->used
[TEXT_AREA
] == 0)
15207 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
15208 row
->displays_text_p
= 0;
15210 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
15211 && (!MINI_WINDOW_P (it
->w
)
15212 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
15213 row
->indicate_empty_line_p
= 1;
15216 it
->continuation_lines_width
= 0;
15217 row
->ends_at_zv_p
= 1;
15221 /* Now, get the metrics of what we want to display. This also
15222 generates glyphs in `row' (which is IT->glyph_row). */
15223 n_glyphs_before
= row
->used
[TEXT_AREA
];
15226 /* Remember the line height so far in case the next element doesn't
15227 fit on the line. */
15228 if (!it
->truncate_lines_p
)
15230 ascent
= it
->max_ascent
;
15231 descent
= it
->max_descent
;
15232 phys_ascent
= it
->max_phys_ascent
;
15233 phys_descent
= it
->max_phys_descent
;
15236 PRODUCE_GLYPHS (it
);
15238 /* If this display element was in marginal areas, continue with
15240 if (it
->area
!= TEXT_AREA
)
15242 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15243 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15244 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15245 row
->phys_height
= max (row
->phys_height
,
15246 it
->max_phys_ascent
+ it
->max_phys_descent
);
15247 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15248 it
->max_extra_line_spacing
);
15249 set_iterator_to_next (it
, 1);
15253 /* Does the display element fit on the line? If we truncate
15254 lines, we should draw past the right edge of the window. If
15255 we don't truncate, we want to stop so that we can display the
15256 continuation glyph before the right margin. If lines are
15257 continued, there are two possible strategies for characters
15258 resulting in more than 1 glyph (e.g. tabs): Display as many
15259 glyphs as possible in this line and leave the rest for the
15260 continuation line, or display the whole element in the next
15261 line. Original redisplay did the former, so we do it also. */
15262 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
15263 hpos_before
= it
->hpos
;
15266 if (/* Not a newline. */
15268 /* Glyphs produced fit entirely in the line. */
15269 && it
->current_x
< it
->last_visible_x
)
15271 it
->hpos
+= nglyphs
;
15272 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15273 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15274 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15275 row
->phys_height
= max (row
->phys_height
,
15276 it
->max_phys_ascent
+ it
->max_phys_descent
);
15277 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15278 it
->max_extra_line_spacing
);
15279 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
15280 row
->x
= x
- it
->first_visible_x
;
15285 struct glyph
*glyph
;
15287 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
15289 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15290 new_x
= x
+ glyph
->pixel_width
;
15292 if (/* Lines are continued. */
15293 !it
->truncate_lines_p
15294 && (/* Glyph doesn't fit on the line. */
15295 new_x
> it
->last_visible_x
15296 /* Or it fits exactly on a window system frame. */
15297 || (new_x
== it
->last_visible_x
15298 && FRAME_WINDOW_P (it
->f
))))
15300 /* End of a continued line. */
15303 || (new_x
== it
->last_visible_x
15304 && FRAME_WINDOW_P (it
->f
)))
15306 /* Current glyph is the only one on the line or
15307 fits exactly on the line. We must continue
15308 the line because we can't draw the cursor
15309 after the glyph. */
15310 row
->continued_p
= 1;
15311 it
->current_x
= new_x
;
15312 it
->continuation_lines_width
+= new_x
;
15314 if (i
== nglyphs
- 1)
15316 set_iterator_to_next (it
, 1);
15317 #ifdef HAVE_WINDOW_SYSTEM
15318 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15320 if (!get_next_display_element (it
))
15322 row
->exact_window_width_line_p
= 1;
15323 it
->continuation_lines_width
= 0;
15324 row
->continued_p
= 0;
15325 row
->ends_at_zv_p
= 1;
15327 else if (ITERATOR_AT_END_OF_LINE_P (it
))
15329 row
->continued_p
= 0;
15330 row
->exact_window_width_line_p
= 1;
15333 #endif /* HAVE_WINDOW_SYSTEM */
15336 else if (CHAR_GLYPH_PADDING_P (*glyph
)
15337 && !FRAME_WINDOW_P (it
->f
))
15339 /* A padding glyph that doesn't fit on this line.
15340 This means the whole character doesn't fit
15342 row
->used
[TEXT_AREA
] = n_glyphs_before
;
15344 /* Fill the rest of the row with continuation
15345 glyphs like in 20.x. */
15346 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
15347 < row
->glyphs
[1 + TEXT_AREA
])
15348 produce_special_glyphs (it
, IT_CONTINUATION
);
15350 row
->continued_p
= 1;
15351 it
->current_x
= x_before
;
15352 it
->continuation_lines_width
+= x_before
;
15354 /* Restore the height to what it was before the
15355 element not fitting on the line. */
15356 it
->max_ascent
= ascent
;
15357 it
->max_descent
= descent
;
15358 it
->max_phys_ascent
= phys_ascent
;
15359 it
->max_phys_descent
= phys_descent
;
15361 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
15363 /* A TAB that extends past the right edge of the
15364 window. This produces a single glyph on
15365 window system frames. We leave the glyph in
15366 this row and let it fill the row, but don't
15367 consume the TAB. */
15368 it
->continuation_lines_width
+= it
->last_visible_x
;
15369 row
->ends_in_middle_of_char_p
= 1;
15370 row
->continued_p
= 1;
15371 glyph
->pixel_width
= it
->last_visible_x
- x
;
15372 it
->starts_in_middle_of_char_p
= 1;
15376 /* Something other than a TAB that draws past
15377 the right edge of the window. Restore
15378 positions to values before the element. */
15379 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15381 /* Display continuation glyphs. */
15382 if (!FRAME_WINDOW_P (it
->f
))
15383 produce_special_glyphs (it
, IT_CONTINUATION
);
15384 row
->continued_p
= 1;
15386 it
->continuation_lines_width
+= x
;
15388 if (nglyphs
> 1 && i
> 0)
15390 row
->ends_in_middle_of_char_p
= 1;
15391 it
->starts_in_middle_of_char_p
= 1;
15394 /* Restore the height to what it was before the
15395 element not fitting on the line. */
15396 it
->max_ascent
= ascent
;
15397 it
->max_descent
= descent
;
15398 it
->max_phys_ascent
= phys_ascent
;
15399 it
->max_phys_descent
= phys_descent
;
15404 else if (new_x
> it
->first_visible_x
)
15406 /* Increment number of glyphs actually displayed. */
15409 if (x
< it
->first_visible_x
)
15410 /* Glyph is partially visible, i.e. row starts at
15411 negative X position. */
15412 row
->x
= x
- it
->first_visible_x
;
15416 /* Glyph is completely off the left margin of the
15417 window. This should not happen because of the
15418 move_it_in_display_line at the start of this
15419 function, unless the text display area of the
15420 window is empty. */
15421 xassert (it
->first_visible_x
<= it
->last_visible_x
);
15425 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15426 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15427 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15428 row
->phys_height
= max (row
->phys_height
,
15429 it
->max_phys_ascent
+ it
->max_phys_descent
);
15430 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15431 it
->max_extra_line_spacing
);
15433 /* End of this display line if row is continued. */
15434 if (row
->continued_p
|| row
->ends_at_zv_p
)
15439 /* Is this a line end? If yes, we're also done, after making
15440 sure that a non-default face is extended up to the right
15441 margin of the window. */
15442 if (ITERATOR_AT_END_OF_LINE_P (it
))
15444 int used_before
= row
->used
[TEXT_AREA
];
15446 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
15448 #ifdef HAVE_WINDOW_SYSTEM
15449 /* Add a space at the end of the line that is used to
15450 display the cursor there. */
15451 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15452 append_space_for_newline (it
, 0);
15453 #endif /* HAVE_WINDOW_SYSTEM */
15455 /* Extend the face to the end of the line. */
15456 extend_face_to_end_of_line (it
);
15458 /* Make sure we have the position. */
15459 if (used_before
== 0)
15460 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
15462 /* Consume the line end. This skips over invisible lines. */
15463 set_iterator_to_next (it
, 1);
15464 it
->continuation_lines_width
= 0;
15468 /* Proceed with next display element. Note that this skips
15469 over lines invisible because of selective display. */
15470 set_iterator_to_next (it
, 1);
15472 /* If we truncate lines, we are done when the last displayed
15473 glyphs reach past the right margin of the window. */
15474 if (it
->truncate_lines_p
15475 && (FRAME_WINDOW_P (it
->f
)
15476 ? (it
->current_x
>= it
->last_visible_x
)
15477 : (it
->current_x
> it
->last_visible_x
)))
15479 /* Maybe add truncation glyphs. */
15480 if (!FRAME_WINDOW_P (it
->f
))
15484 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15485 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15488 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15490 row
->used
[TEXT_AREA
] = i
;
15491 produce_special_glyphs (it
, IT_TRUNCATION
);
15494 #ifdef HAVE_WINDOW_SYSTEM
15497 /* Don't truncate if we can overflow newline into fringe. */
15498 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15500 if (!get_next_display_element (it
))
15502 it
->continuation_lines_width
= 0;
15503 row
->ends_at_zv_p
= 1;
15504 row
->exact_window_width_line_p
= 1;
15507 if (ITERATOR_AT_END_OF_LINE_P (it
))
15509 row
->exact_window_width_line_p
= 1;
15510 goto at_end_of_line
;
15514 #endif /* HAVE_WINDOW_SYSTEM */
15516 row
->truncated_on_right_p
= 1;
15517 it
->continuation_lines_width
= 0;
15518 reseat_at_next_visible_line_start (it
, 0);
15519 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
15520 it
->hpos
= hpos_before
;
15521 it
->current_x
= x_before
;
15526 /* If line is not empty and hscrolled, maybe insert truncation glyphs
15527 at the left window margin. */
15528 if (it
->first_visible_x
15529 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
15531 if (!FRAME_WINDOW_P (it
->f
))
15532 insert_left_trunc_glyphs (it
);
15533 row
->truncated_on_left_p
= 1;
15536 /* If the start of this line is the overlay arrow-position, then
15537 mark this glyph row as the one containing the overlay arrow.
15538 This is clearly a mess with variable size fonts. It would be
15539 better to let it be displayed like cursors under X. */
15540 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
15541 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
15542 !NILP (overlay_arrow_string
)))
15544 /* Overlay arrow in window redisplay is a fringe bitmap. */
15545 if (STRINGP (overlay_arrow_string
))
15547 struct glyph_row
*arrow_row
15548 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
15549 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
15550 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
15551 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
15552 struct glyph
*p2
, *end
;
15554 /* Copy the arrow glyphs. */
15555 while (glyph
< arrow_end
)
15558 /* Throw away padding glyphs. */
15560 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15561 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
15567 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
15572 xassert (INTEGERP (overlay_arrow_string
));
15573 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
15575 overlay_arrow_seen
= 1;
15578 /* Compute pixel dimensions of this line. */
15579 compute_line_metrics (it
);
15581 /* Remember the position at which this line ends. */
15582 row
->end
= it
->current
;
15584 /* Record whether this row ends inside an ellipsis. */
15585 row
->ends_in_ellipsis_p
15586 = (it
->method
== GET_FROM_DISPLAY_VECTOR
15587 && it
->ellipsis_p
);
15589 /* Save fringe bitmaps in this row. */
15590 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
15591 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
15592 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
15593 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
15595 it
->left_user_fringe_bitmap
= 0;
15596 it
->left_user_fringe_face_id
= 0;
15597 it
->right_user_fringe_bitmap
= 0;
15598 it
->right_user_fringe_face_id
= 0;
15600 /* Maybe set the cursor. */
15601 if (it
->w
->cursor
.vpos
< 0
15602 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
15603 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15604 && cursor_row_p (it
->w
, row
))
15605 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
15607 /* Highlight trailing whitespace. */
15608 if (!NILP (Vshow_trailing_whitespace
))
15609 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
15611 /* Prepare for the next line. This line starts horizontally at (X
15612 HPOS) = (0 0). Vertical positions are incremented. As a
15613 convenience for the caller, IT->glyph_row is set to the next
15615 it
->current_x
= it
->hpos
= 0;
15616 it
->current_y
+= row
->height
;
15619 it
->start
= it
->current
;
15620 return row
->displays_text_p
;
15625 /***********************************************************************
15627 ***********************************************************************/
15629 /* Redisplay the menu bar in the frame for window W.
15631 The menu bar of X frames that don't have X toolkit support is
15632 displayed in a special window W->frame->menu_bar_window.
15634 The menu bar of terminal frames is treated specially as far as
15635 glyph matrices are concerned. Menu bar lines are not part of
15636 windows, so the update is done directly on the frame matrix rows
15637 for the menu bar. */
15640 display_menu_bar (w
)
15643 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15648 /* Don't do all this for graphical frames. */
15650 if (!NILP (Vwindow_system
))
15653 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
15658 if (FRAME_MAC_P (f
))
15662 #ifdef USE_X_TOOLKIT
15663 xassert (!FRAME_WINDOW_P (f
));
15664 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
15665 it
.first_visible_x
= 0;
15666 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15667 #else /* not USE_X_TOOLKIT */
15668 if (FRAME_WINDOW_P (f
))
15670 /* Menu bar lines are displayed in the desired matrix of the
15671 dummy window menu_bar_window. */
15672 struct window
*menu_w
;
15673 xassert (WINDOWP (f
->menu_bar_window
));
15674 menu_w
= XWINDOW (f
->menu_bar_window
);
15675 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
15677 it
.first_visible_x
= 0;
15678 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15682 /* This is a TTY frame, i.e. character hpos/vpos are used as
15684 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
15686 it
.first_visible_x
= 0;
15687 it
.last_visible_x
= FRAME_COLS (f
);
15689 #endif /* not USE_X_TOOLKIT */
15691 if (! mode_line_inverse_video
)
15692 /* Force the menu-bar to be displayed in the default face. */
15693 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15695 /* Clear all rows of the menu bar. */
15696 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
15698 struct glyph_row
*row
= it
.glyph_row
+ i
;
15699 clear_glyph_row (row
);
15700 row
->enabled_p
= 1;
15701 row
->full_width_p
= 1;
15704 /* Display all items of the menu bar. */
15705 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
15706 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
15708 Lisp_Object string
;
15710 /* Stop at nil string. */
15711 string
= AREF (items
, i
+ 1);
15715 /* Remember where item was displayed. */
15716 AREF (items
, i
+ 3) = make_number (it
.hpos
);
15718 /* Display the item, pad with one space. */
15719 if (it
.current_x
< it
.last_visible_x
)
15720 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
15721 SCHARS (string
) + 1, 0, 0, -1);
15724 /* Fill out the line with spaces. */
15725 if (it
.current_x
< it
.last_visible_x
)
15726 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
15728 /* Compute the total height of the lines. */
15729 compute_line_metrics (&it
);
15734 /***********************************************************************
15736 ***********************************************************************/
15738 /* Redisplay mode lines in the window tree whose root is WINDOW. If
15739 FORCE is non-zero, redisplay mode lines unconditionally.
15740 Otherwise, redisplay only mode lines that are garbaged. Value is
15741 the number of windows whose mode lines were redisplayed. */
15744 redisplay_mode_lines (window
, force
)
15745 Lisp_Object window
;
15750 while (!NILP (window
))
15752 struct window
*w
= XWINDOW (window
);
15754 if (WINDOWP (w
->hchild
))
15755 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
15756 else if (WINDOWP (w
->vchild
))
15757 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
15759 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
15760 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
15762 struct text_pos lpoint
;
15763 struct buffer
*old
= current_buffer
;
15765 /* Set the window's buffer for the mode line display. */
15766 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15767 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15769 /* Point refers normally to the selected window. For any
15770 other window, set up appropriate value. */
15771 if (!EQ (window
, selected_window
))
15773 struct text_pos pt
;
15775 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
15776 if (CHARPOS (pt
) < BEGV
)
15777 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15778 else if (CHARPOS (pt
) > (ZV
- 1))
15779 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
15781 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
15784 /* Display mode lines. */
15785 clear_glyph_matrix (w
->desired_matrix
);
15786 if (display_mode_lines (w
))
15789 w
->must_be_updated_p
= 1;
15792 /* Restore old settings. */
15793 set_buffer_internal_1 (old
);
15794 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15804 /* Display the mode and/or top line of window W. Value is the number
15805 of mode lines displayed. */
15808 display_mode_lines (w
)
15811 Lisp_Object old_selected_window
, old_selected_frame
;
15814 old_selected_frame
= selected_frame
;
15815 selected_frame
= w
->frame
;
15816 old_selected_window
= selected_window
;
15817 XSETWINDOW (selected_window
, w
);
15819 /* These will be set while the mode line specs are processed. */
15820 line_number_displayed
= 0;
15821 w
->column_number_displayed
= Qnil
;
15823 if (WINDOW_WANTS_MODELINE_P (w
))
15825 struct window
*sel_w
= XWINDOW (old_selected_window
);
15827 /* Select mode line face based on the real selected window. */
15828 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
15829 current_buffer
->mode_line_format
);
15833 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15835 display_mode_line (w
, HEADER_LINE_FACE_ID
,
15836 current_buffer
->header_line_format
);
15840 selected_frame
= old_selected_frame
;
15841 selected_window
= old_selected_window
;
15846 /* Display mode or top line of window W. FACE_ID specifies which line
15847 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
15848 FORMAT is the mode line format to display. Value is the pixel
15849 height of the mode line displayed. */
15852 display_mode_line (w
, face_id
, format
)
15854 enum face_id face_id
;
15855 Lisp_Object format
;
15859 int count
= SPECPDL_INDEX ();
15861 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15862 prepare_desired_row (it
.glyph_row
);
15864 it
.glyph_row
->mode_line_p
= 1;
15866 if (! mode_line_inverse_video
)
15867 /* Force the mode-line to be displayed in the default face. */
15868 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15870 record_unwind_protect (unwind_format_mode_line
,
15871 format_mode_line_unwind_data (NULL
));
15873 mode_line_target
= MODE_LINE_DISPLAY
;
15875 /* Temporarily make frame's keyboard the current kboard so that
15876 kboard-local variables in the mode_line_format will get the right
15878 push_frame_kboard (it
.f
);
15879 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15880 pop_frame_kboard ();
15882 unbind_to (count
, Qnil
);
15884 /* Fill up with spaces. */
15885 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
15887 compute_line_metrics (&it
);
15888 it
.glyph_row
->full_width_p
= 1;
15889 it
.glyph_row
->continued_p
= 0;
15890 it
.glyph_row
->truncated_on_left_p
= 0;
15891 it
.glyph_row
->truncated_on_right_p
= 0;
15893 /* Make a 3D mode-line have a shadow at its right end. */
15894 face
= FACE_FROM_ID (it
.f
, face_id
);
15895 extend_face_to_end_of_line (&it
);
15896 if (face
->box
!= FACE_NO_BOX
)
15898 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
15899 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
15900 last
->right_box_line_p
= 1;
15903 return it
.glyph_row
->height
;
15906 /* Contribute ELT to the mode line for window IT->w. How it
15907 translates into text depends on its data type.
15909 IT describes the display environment in which we display, as usual.
15911 DEPTH is the depth in recursion. It is used to prevent
15912 infinite recursion here.
15914 FIELD_WIDTH is the number of characters the display of ELT should
15915 occupy in the mode line, and PRECISION is the maximum number of
15916 characters to display from ELT's representation. See
15917 display_string for details.
15919 Returns the hpos of the end of the text generated by ELT.
15921 PROPS is a property list to add to any string we encounter.
15923 If RISKY is nonzero, remove (disregard) any properties in any string
15924 we encounter, and ignore :eval and :propertize.
15926 The global variable `mode_line_target' determines whether the
15927 output is passed to `store_mode_line_noprop',
15928 `store_mode_line_string', or `display_string'. */
15931 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
15934 int field_width
, precision
;
15935 Lisp_Object elt
, props
;
15938 int n
= 0, field
, prec
;
15943 elt
= build_string ("*too-deep*");
15947 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
15951 /* A string: output it and check for %-constructs within it. */
15953 const unsigned char *this, *lisp_string
;
15955 if (!NILP (props
) || risky
)
15957 Lisp_Object oprops
, aelt
;
15958 oprops
= Ftext_properties_at (make_number (0), elt
);
15960 /* If the starting string's properties are not what
15961 we want, translate the string. Also, if the string
15962 is risky, do that anyway. */
15964 if (NILP (Fequal (props
, oprops
)) || risky
)
15966 /* If the starting string has properties,
15967 merge the specified ones onto the existing ones. */
15968 if (! NILP (oprops
) && !risky
)
15972 oprops
= Fcopy_sequence (oprops
);
15974 while (CONSP (tem
))
15976 oprops
= Fplist_put (oprops
, XCAR (tem
),
15977 XCAR (XCDR (tem
)));
15978 tem
= XCDR (XCDR (tem
));
15983 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
15984 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
15986 mode_line_proptrans_alist
15987 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
15994 elt
= Fcopy_sequence (elt
);
15995 Fset_text_properties (make_number (0), Flength (elt
),
15997 /* Add this item to mode_line_proptrans_alist. */
15998 mode_line_proptrans_alist
15999 = Fcons (Fcons (elt
, props
),
16000 mode_line_proptrans_alist
);
16001 /* Truncate mode_line_proptrans_alist
16002 to at most 50 elements. */
16003 tem
= Fnthcdr (make_number (50),
16004 mode_line_proptrans_alist
);
16006 XSETCDR (tem
, Qnil
);
16011 this = SDATA (elt
);
16012 lisp_string
= this;
16016 prec
= precision
- n
;
16017 switch (mode_line_target
)
16019 case MODE_LINE_NOPROP
:
16020 case MODE_LINE_TITLE
:
16021 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
16023 case MODE_LINE_STRING
:
16024 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
16026 case MODE_LINE_DISPLAY
:
16027 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
16028 0, prec
, 0, STRING_MULTIBYTE (elt
));
16035 while ((precision
<= 0 || n
< precision
)
16037 && (mode_line_target
!= MODE_LINE_DISPLAY
16038 || it
->current_x
< it
->last_visible_x
))
16040 const unsigned char *last
= this;
16042 /* Advance to end of string or next format specifier. */
16043 while ((c
= *this++) != '\0' && c
!= '%')
16046 if (this - 1 != last
)
16048 int nchars
, nbytes
;
16050 /* Output to end of string or up to '%'. Field width
16051 is length of string. Don't output more than
16052 PRECISION allows us. */
16055 prec
= c_string_width (last
, this - last
, precision
- n
,
16058 switch (mode_line_target
)
16060 case MODE_LINE_NOPROP
:
16061 case MODE_LINE_TITLE
:
16062 n
+= store_mode_line_noprop (last
, 0, prec
);
16064 case MODE_LINE_STRING
:
16066 int bytepos
= last
- lisp_string
;
16067 int charpos
= string_byte_to_char (elt
, bytepos
);
16068 int endpos
= (precision
<= 0
16069 ? string_byte_to_char (elt
,
16070 this - lisp_string
)
16071 : charpos
+ nchars
);
16073 n
+= store_mode_line_string (NULL
,
16074 Fsubstring (elt
, make_number (charpos
),
16075 make_number (endpos
)),
16079 case MODE_LINE_DISPLAY
:
16081 int bytepos
= last
- lisp_string
;
16082 int charpos
= string_byte_to_char (elt
, bytepos
);
16083 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
16085 STRING_MULTIBYTE (elt
));
16090 else /* c == '%' */
16092 const unsigned char *percent_position
= this;
16094 /* Get the specified minimum width. Zero means
16097 while ((c
= *this++) >= '0' && c
<= '9')
16098 field
= field
* 10 + c
- '0';
16100 /* Don't pad beyond the total padding allowed. */
16101 if (field_width
- n
> 0 && field
> field_width
- n
)
16102 field
= field_width
- n
;
16104 /* Note that either PRECISION <= 0 or N < PRECISION. */
16105 prec
= precision
- n
;
16108 n
+= display_mode_element (it
, depth
, field
, prec
,
16109 Vglobal_mode_string
, props
,
16114 int bytepos
, charpos
;
16115 unsigned char *spec
;
16117 bytepos
= percent_position
- lisp_string
;
16118 charpos
= (STRING_MULTIBYTE (elt
)
16119 ? string_byte_to_char (elt
, bytepos
)
16123 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
16125 switch (mode_line_target
)
16127 case MODE_LINE_NOPROP
:
16128 case MODE_LINE_TITLE
:
16129 n
+= store_mode_line_noprop (spec
, field
, prec
);
16131 case MODE_LINE_STRING
:
16133 int len
= strlen (spec
);
16134 Lisp_Object tem
= make_string (spec
, len
);
16135 props
= Ftext_properties_at (make_number (charpos
), elt
);
16136 /* Should only keep face property in props */
16137 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
16140 case MODE_LINE_DISPLAY
:
16142 int nglyphs_before
, nwritten
;
16144 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16145 nwritten
= display_string (spec
, Qnil
, elt
,
16150 /* Assign to the glyphs written above the
16151 string where the `%x' came from, position
16155 struct glyph
*glyph
16156 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
16160 for (i
= 0; i
< nwritten
; ++i
)
16162 glyph
[i
].object
= elt
;
16163 glyph
[i
].charpos
= charpos
;
16180 /* A symbol: process the value of the symbol recursively
16181 as if it appeared here directly. Avoid error if symbol void.
16182 Special case: if value of symbol is a string, output the string
16185 register Lisp_Object tem
;
16187 /* If the variable is not marked as risky to set
16188 then its contents are risky to use. */
16189 if (NILP (Fget (elt
, Qrisky_local_variable
)))
16192 tem
= Fboundp (elt
);
16195 tem
= Fsymbol_value (elt
);
16196 /* If value is a string, output that string literally:
16197 don't check for % within it. */
16201 if (!EQ (tem
, elt
))
16203 /* Give up right away for nil or t. */
16213 register Lisp_Object car
, tem
;
16215 /* A cons cell: five distinct cases.
16216 If first element is :eval or :propertize, do something special.
16217 If first element is a string or a cons, process all the elements
16218 and effectively concatenate them.
16219 If first element is a negative number, truncate displaying cdr to
16220 at most that many characters. If positive, pad (with spaces)
16221 to at least that many characters.
16222 If first element is a symbol, process the cadr or caddr recursively
16223 according to whether the symbol's value is non-nil or nil. */
16225 if (EQ (car
, QCeval
))
16227 /* An element of the form (:eval FORM) means evaluate FORM
16228 and use the result as mode line elements. */
16233 if (CONSP (XCDR (elt
)))
16236 spec
= safe_eval (XCAR (XCDR (elt
)));
16237 n
+= display_mode_element (it
, depth
, field_width
- n
,
16238 precision
- n
, spec
, props
,
16242 else if (EQ (car
, QCpropertize
))
16244 /* An element of the form (:propertize ELT PROPS...)
16245 means display ELT but applying properties PROPS. */
16250 if (CONSP (XCDR (elt
)))
16251 n
+= display_mode_element (it
, depth
, field_width
- n
,
16252 precision
- n
, XCAR (XCDR (elt
)),
16253 XCDR (XCDR (elt
)), risky
);
16255 else if (SYMBOLP (car
))
16257 tem
= Fboundp (car
);
16261 /* elt is now the cdr, and we know it is a cons cell.
16262 Use its car if CAR has a non-nil value. */
16265 tem
= Fsymbol_value (car
);
16272 /* Symbol's value is nil (or symbol is unbound)
16273 Get the cddr of the original list
16274 and if possible find the caddr and use that. */
16278 else if (!CONSP (elt
))
16283 else if (INTEGERP (car
))
16285 register int lim
= XINT (car
);
16289 /* Negative int means reduce maximum width. */
16290 if (precision
<= 0)
16293 precision
= min (precision
, -lim
);
16297 /* Padding specified. Don't let it be more than
16298 current maximum. */
16300 lim
= min (precision
, lim
);
16302 /* If that's more padding than already wanted, queue it.
16303 But don't reduce padding already specified even if
16304 that is beyond the current truncation point. */
16305 field_width
= max (lim
, field_width
);
16309 else if (STRINGP (car
) || CONSP (car
))
16311 register int limit
= 50;
16312 /* Limit is to protect against circular lists. */
16315 && (precision
<= 0 || n
< precision
))
16317 n
+= display_mode_element (it
, depth
,
16318 /* Do padding only after the last
16319 element in the list. */
16320 (! CONSP (XCDR (elt
))
16323 precision
- n
, XCAR (elt
),
16333 elt
= build_string ("*invalid*");
16337 /* Pad to FIELD_WIDTH. */
16338 if (field_width
> 0 && n
< field_width
)
16340 switch (mode_line_target
)
16342 case MODE_LINE_NOPROP
:
16343 case MODE_LINE_TITLE
:
16344 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
16346 case MODE_LINE_STRING
:
16347 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
16349 case MODE_LINE_DISPLAY
:
16350 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
16359 /* Store a mode-line string element in mode_line_string_list.
16361 If STRING is non-null, display that C string. Otherwise, the Lisp
16362 string LISP_STRING is displayed.
16364 FIELD_WIDTH is the minimum number of output glyphs to produce.
16365 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16366 with spaces. FIELD_WIDTH <= 0 means don't pad.
16368 PRECISION is the maximum number of characters to output from
16369 STRING. PRECISION <= 0 means don't truncate the string.
16371 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
16372 properties to the string.
16374 PROPS are the properties to add to the string.
16375 The mode_line_string_face face property is always added to the string.
16379 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
16381 Lisp_Object lisp_string
;
16390 if (string
!= NULL
)
16392 len
= strlen (string
);
16393 if (precision
> 0 && len
> precision
)
16395 lisp_string
= make_string (string
, len
);
16397 props
= mode_line_string_face_prop
;
16398 else if (!NILP (mode_line_string_face
))
16400 Lisp_Object face
= Fplist_get (props
, Qface
);
16401 props
= Fcopy_sequence (props
);
16403 face
= mode_line_string_face
;
16405 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16406 props
= Fplist_put (props
, Qface
, face
);
16408 Fadd_text_properties (make_number (0), make_number (len
),
16409 props
, lisp_string
);
16413 len
= XFASTINT (Flength (lisp_string
));
16414 if (precision
> 0 && len
> precision
)
16417 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
16420 if (!NILP (mode_line_string_face
))
16424 props
= Ftext_properties_at (make_number (0), lisp_string
);
16425 face
= Fplist_get (props
, Qface
);
16427 face
= mode_line_string_face
;
16429 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16430 props
= Fcons (Qface
, Fcons (face
, Qnil
));
16432 lisp_string
= Fcopy_sequence (lisp_string
);
16435 Fadd_text_properties (make_number (0), make_number (len
),
16436 props
, lisp_string
);
16441 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16445 if (field_width
> len
)
16447 field_width
-= len
;
16448 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
16450 Fadd_text_properties (make_number (0), make_number (field_width
),
16451 props
, lisp_string
);
16452 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16460 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
16462 doc
: /* Format a string out of a mode line format specification.
16463 First arg FORMAT specifies the mode line format (see `mode-line-format'
16464 for details) to use.
16466 Optional second arg FACE specifies the face property to put
16467 on all characters for which no face is specified.
16468 t means whatever face the window's mode line currently uses
16469 \(either `mode-line' or `mode-line-inactive', depending).
16470 nil means the default is no face property.
16471 If FACE is an integer, the value string has no text properties.
16473 Optional third and fourth args WINDOW and BUFFER specify the window
16474 and buffer to use as the context for the formatting (defaults
16475 are the selected window and the window's buffer). */)
16476 (format
, face
, window
, buffer
)
16477 Lisp_Object format
, face
, window
, buffer
;
16482 struct buffer
*old_buffer
= NULL
;
16484 int no_props
= INTEGERP (face
);
16485 int count
= SPECPDL_INDEX ();
16487 int string_start
= 0;
16490 window
= selected_window
;
16491 CHECK_WINDOW (window
);
16492 w
= XWINDOW (window
);
16495 buffer
= w
->buffer
;
16496 CHECK_BUFFER (buffer
);
16499 return build_string ("");
16507 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
16508 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
16512 face_id
= DEFAULT_FACE_ID
;
16514 if (XBUFFER (buffer
) != current_buffer
)
16515 old_buffer
= current_buffer
;
16517 record_unwind_protect (unwind_format_mode_line
,
16518 format_mode_line_unwind_data (old_buffer
));
16521 set_buffer_internal_1 (XBUFFER (buffer
));
16523 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16527 mode_line_target
= MODE_LINE_NOPROP
;
16528 mode_line_string_face_prop
= Qnil
;
16529 mode_line_string_list
= Qnil
;
16530 string_start
= MODE_LINE_NOPROP_LEN (0);
16534 mode_line_target
= MODE_LINE_STRING
;
16535 mode_line_string_list
= Qnil
;
16536 mode_line_string_face
= face
;
16537 mode_line_string_face_prop
16538 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
16541 push_frame_kboard (it
.f
);
16542 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16543 pop_frame_kboard ();
16547 len
= MODE_LINE_NOPROP_LEN (string_start
);
16548 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
16552 mode_line_string_list
= Fnreverse (mode_line_string_list
);
16553 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
16554 make_string ("", 0));
16557 unbind_to (count
, Qnil
);
16561 /* Write a null-terminated, right justified decimal representation of
16562 the positive integer D to BUF using a minimal field width WIDTH. */
16565 pint2str (buf
, width
, d
)
16566 register char *buf
;
16567 register int width
;
16570 register char *p
= buf
;
16578 *p
++ = d
% 10 + '0';
16583 for (width
-= (int) (p
- buf
); width
> 0; --width
)
16594 /* Write a null-terminated, right justified decimal and "human
16595 readable" representation of the nonnegative integer D to BUF using
16596 a minimal field width WIDTH. D should be smaller than 999.5e24. */
16598 static const char power_letter
[] =
16612 pint2hrstr (buf
, width
, d
)
16617 /* We aim to represent the nonnegative integer D as
16618 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
16621 /* -1 means: do not use TENTHS. */
16625 /* Length of QUOTIENT.TENTHS as a string. */
16631 if (1000 <= quotient
)
16633 /* Scale to the appropriate EXPONENT. */
16636 remainder
= quotient
% 1000;
16640 while (1000 <= quotient
);
16642 /* Round to nearest and decide whether to use TENTHS or not. */
16645 tenths
= remainder
/ 100;
16646 if (50 <= remainder
% 100)
16653 if (quotient
== 10)
16661 if (500 <= remainder
)
16663 if (quotient
< 999)
16674 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
16675 if (tenths
== -1 && quotient
<= 99)
16682 p
= psuffix
= buf
+ max (width
, length
);
16684 /* Print EXPONENT. */
16686 *psuffix
++ = power_letter
[exponent
];
16689 /* Print TENTHS. */
16692 *--p
= '0' + tenths
;
16696 /* Print QUOTIENT. */
16699 int digit
= quotient
% 10;
16700 *--p
= '0' + digit
;
16702 while ((quotient
/= 10) != 0);
16704 /* Print leading spaces. */
16709 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
16710 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
16711 type of CODING_SYSTEM. Return updated pointer into BUF. */
16713 static unsigned char invalid_eol_type
[] = "(*invalid*)";
16716 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
16717 Lisp_Object coding_system
;
16718 register char *buf
;
16722 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
16723 const unsigned char *eol_str
;
16725 /* The EOL conversion we are using. */
16726 Lisp_Object eoltype
;
16728 val
= CODING_SYSTEM_SPEC (coding_system
);
16731 if (!VECTORP (val
)) /* Not yet decided. */
16736 eoltype
= eol_mnemonic_undecided
;
16737 /* Don't mention EOL conversion if it isn't decided. */
16742 Lisp_Object eolvalue
;
16744 attrs
= AREF (val
, 0);
16745 eolvalue
= AREF (val
, 2);
16748 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
16752 /* The EOL conversion that is normal on this system. */
16754 if (NILP (eolvalue
)) /* Not yet decided. */
16755 eoltype
= eol_mnemonic_undecided
;
16756 else if (VECTORP (eolvalue
)) /* Not yet decided. */
16757 eoltype
= eol_mnemonic_undecided
;
16758 else /* eolvalue is Qunix, Qdos, or Qmac. */
16759 eoltype
= (EQ (eolvalue
, Qunix
)
16760 ? eol_mnemonic_unix
16761 : (EQ (eolvalue
, Qdos
) == 1
16762 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
16768 /* Mention the EOL conversion if it is not the usual one. */
16769 if (STRINGP (eoltype
))
16771 eol_str
= SDATA (eoltype
);
16772 eol_str_len
= SBYTES (eoltype
);
16774 else if (CHARACTERP (eoltype
))
16776 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
16777 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
16782 eol_str
= invalid_eol_type
;
16783 eol_str_len
= sizeof (invalid_eol_type
) - 1;
16785 bcopy (eol_str
, buf
, eol_str_len
);
16786 buf
+= eol_str_len
;
16792 /* Return a string for the output of a mode line %-spec for window W,
16793 generated by character C. PRECISION >= 0 means don't return a
16794 string longer than that value. FIELD_WIDTH > 0 means pad the
16795 string returned with spaces to that value. Return 1 in *MULTIBYTE
16796 if the result is multibyte text.
16798 Note we operate on the current buffer for most purposes,
16799 the exception being w->base_line_pos. */
16801 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
16804 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
16807 int field_width
, precision
;
16811 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16812 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
16813 struct buffer
*b
= current_buffer
;
16821 if (!NILP (b
->read_only
))
16823 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16828 /* This differs from %* only for a modified read-only buffer. */
16829 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16831 if (!NILP (b
->read_only
))
16836 /* This differs from %* in ignoring read-only-ness. */
16837 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16849 if (command_loop_level
> 5)
16851 p
= decode_mode_spec_buf
;
16852 for (i
= 0; i
< command_loop_level
; i
++)
16855 return decode_mode_spec_buf
;
16863 if (command_loop_level
> 5)
16865 p
= decode_mode_spec_buf
;
16866 for (i
= 0; i
< command_loop_level
; i
++)
16869 return decode_mode_spec_buf
;
16876 /* Let lots_of_dashes be a string of infinite length. */
16877 if (mode_line_target
== MODE_LINE_NOPROP
||
16878 mode_line_target
== MODE_LINE_STRING
)
16880 if (field_width
<= 0
16881 || field_width
> sizeof (lots_of_dashes
))
16883 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
16884 decode_mode_spec_buf
[i
] = '-';
16885 decode_mode_spec_buf
[i
] = '\0';
16886 return decode_mode_spec_buf
;
16889 return lots_of_dashes
;
16898 int col
= (int) current_column (); /* iftc */
16899 w
->column_number_displayed
= make_number (col
);
16900 pint2str (decode_mode_spec_buf
, field_width
, col
);
16901 return decode_mode_spec_buf
;
16905 /* %F displays the frame name. */
16906 if (!NILP (f
->title
))
16907 return (char *) SDATA (f
->title
);
16908 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
16909 return (char *) SDATA (f
->name
);
16918 int size
= ZV
- BEGV
;
16919 pint2str (decode_mode_spec_buf
, field_width
, size
);
16920 return decode_mode_spec_buf
;
16925 int size
= ZV
- BEGV
;
16926 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
16927 return decode_mode_spec_buf
;
16932 int startpos
= XMARKER (w
->start
)->charpos
;
16933 int startpos_byte
= marker_byte_position (w
->start
);
16934 int line
, linepos
, linepos_byte
, topline
;
16936 int height
= WINDOW_TOTAL_LINES (w
);
16938 /* If we decided that this buffer isn't suitable for line numbers,
16939 don't forget that too fast. */
16940 if (EQ (w
->base_line_pos
, w
->buffer
))
16942 /* But do forget it, if the window shows a different buffer now. */
16943 else if (BUFFERP (w
->base_line_pos
))
16944 w
->base_line_pos
= Qnil
;
16946 /* If the buffer is very big, don't waste time. */
16947 if (INTEGERP (Vline_number_display_limit
)
16948 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
16950 w
->base_line_pos
= Qnil
;
16951 w
->base_line_number
= Qnil
;
16955 if (!NILP (w
->base_line_number
)
16956 && !NILP (w
->base_line_pos
)
16957 && XFASTINT (w
->base_line_pos
) <= startpos
)
16959 line
= XFASTINT (w
->base_line_number
);
16960 linepos
= XFASTINT (w
->base_line_pos
);
16961 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
16966 linepos
= BUF_BEGV (b
);
16967 linepos_byte
= BUF_BEGV_BYTE (b
);
16970 /* Count lines from base line to window start position. */
16971 nlines
= display_count_lines (linepos
, linepos_byte
,
16975 topline
= nlines
+ line
;
16977 /* Determine a new base line, if the old one is too close
16978 or too far away, or if we did not have one.
16979 "Too close" means it's plausible a scroll-down would
16980 go back past it. */
16981 if (startpos
== BUF_BEGV (b
))
16983 w
->base_line_number
= make_number (topline
);
16984 w
->base_line_pos
= make_number (BUF_BEGV (b
));
16986 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
16987 || linepos
== BUF_BEGV (b
))
16989 int limit
= BUF_BEGV (b
);
16990 int limit_byte
= BUF_BEGV_BYTE (b
);
16992 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
16994 if (startpos
- distance
> limit
)
16996 limit
= startpos
- distance
;
16997 limit_byte
= CHAR_TO_BYTE (limit
);
17000 nlines
= display_count_lines (startpos
, startpos_byte
,
17002 - (height
* 2 + 30),
17004 /* If we couldn't find the lines we wanted within
17005 line_number_display_limit_width chars per line,
17006 give up on line numbers for this window. */
17007 if (position
== limit_byte
&& limit
== startpos
- distance
)
17009 w
->base_line_pos
= w
->buffer
;
17010 w
->base_line_number
= Qnil
;
17014 w
->base_line_number
= make_number (topline
- nlines
);
17015 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
17018 /* Now count lines from the start pos to point. */
17019 nlines
= display_count_lines (startpos
, startpos_byte
,
17020 PT_BYTE
, PT
, &junk
);
17022 /* Record that we did display the line number. */
17023 line_number_displayed
= 1;
17025 /* Make the string to show. */
17026 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
17027 return decode_mode_spec_buf
;
17030 char* p
= decode_mode_spec_buf
;
17031 int pad
= field_width
- 2;
17037 return decode_mode_spec_buf
;
17043 obj
= b
->mode_name
;
17047 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
17053 int pos
= marker_position (w
->start
);
17054 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17056 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
17058 if (pos
<= BUF_BEGV (b
))
17063 else if (pos
<= BUF_BEGV (b
))
17067 if (total
> 1000000)
17068 /* Do it differently for a large value, to avoid overflow. */
17069 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17071 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17072 /* We can't normally display a 3-digit number,
17073 so get us a 2-digit number that is close. */
17076 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17077 return decode_mode_spec_buf
;
17081 /* Display percentage of size above the bottom of the screen. */
17084 int toppos
= marker_position (w
->start
);
17085 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
17086 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17088 if (botpos
>= BUF_ZV (b
))
17090 if (toppos
<= BUF_BEGV (b
))
17097 if (total
> 1000000)
17098 /* Do it differently for a large value, to avoid overflow. */
17099 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17101 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17102 /* We can't normally display a 3-digit number,
17103 so get us a 2-digit number that is close. */
17106 if (toppos
<= BUF_BEGV (b
))
17107 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
17109 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17110 return decode_mode_spec_buf
;
17115 /* status of process */
17116 obj
= Fget_buffer_process (Fcurrent_buffer ());
17118 return "no process";
17119 #ifdef subprocesses
17120 obj
= Fsymbol_name (Fprocess_status (obj
));
17124 case 't': /* indicate TEXT or BINARY */
17125 #ifdef MODE_LINE_BINARY_TEXT
17126 return MODE_LINE_BINARY_TEXT (b
);
17132 /* coding-system (not including end-of-line format) */
17134 /* coding-system (including end-of-line type) */
17136 int eol_flag
= (c
== 'Z');
17137 char *p
= decode_mode_spec_buf
;
17139 if (! FRAME_WINDOW_P (f
))
17141 /* No need to mention EOL here--the terminal never needs
17142 to do EOL conversion. */
17143 p
= decode_mode_spec_coding (CODING_ID_NAME (keyboard_coding
.id
),
17145 p
= decode_mode_spec_coding (CODING_ID_NAME (terminal_coding
.id
),
17148 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
17151 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
17152 #ifdef subprocesses
17153 obj
= Fget_buffer_process (Fcurrent_buffer ());
17154 if (PROCESSP (obj
))
17156 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
17158 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
17161 #endif /* subprocesses */
17164 return decode_mode_spec_buf
;
17170 *multibyte
= STRING_MULTIBYTE (obj
);
17171 return (char *) SDATA (obj
);
17178 /* Count up to COUNT lines starting from START / START_BYTE.
17179 But don't go beyond LIMIT_BYTE.
17180 Return the number of lines thus found (always nonnegative).
17182 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
17185 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
17186 int start
, start_byte
, limit_byte
, count
;
17189 register unsigned char *cursor
;
17190 unsigned char *base
;
17192 register int ceiling
;
17193 register unsigned char *ceiling_addr
;
17194 int orig_count
= count
;
17196 /* If we are not in selective display mode,
17197 check only for newlines. */
17198 int selective_display
= (!NILP (current_buffer
->selective_display
)
17199 && !INTEGERP (current_buffer
->selective_display
));
17203 while (start_byte
< limit_byte
)
17205 ceiling
= BUFFER_CEILING_OF (start_byte
);
17206 ceiling
= min (limit_byte
- 1, ceiling
);
17207 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
17208 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
17211 if (selective_display
)
17212 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
17215 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
17218 if (cursor
!= ceiling_addr
)
17222 start_byte
+= cursor
- base
+ 1;
17223 *byte_pos_ptr
= start_byte
;
17227 if (++cursor
== ceiling_addr
)
17233 start_byte
+= cursor
- base
;
17238 while (start_byte
> limit_byte
)
17240 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
17241 ceiling
= max (limit_byte
, ceiling
);
17242 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
17243 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
17246 if (selective_display
)
17247 while (--cursor
!= ceiling_addr
17248 && *cursor
!= '\n' && *cursor
!= 015)
17251 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
17254 if (cursor
!= ceiling_addr
)
17258 start_byte
+= cursor
- base
+ 1;
17259 *byte_pos_ptr
= start_byte
;
17260 /* When scanning backwards, we should
17261 not count the newline posterior to which we stop. */
17262 return - orig_count
- 1;
17268 /* Here we add 1 to compensate for the last decrement
17269 of CURSOR, which took it past the valid range. */
17270 start_byte
+= cursor
- base
+ 1;
17274 *byte_pos_ptr
= limit_byte
;
17277 return - orig_count
+ count
;
17278 return orig_count
- count
;
17284 /***********************************************************************
17286 ***********************************************************************/
17288 /* Display a NUL-terminated string, starting with index START.
17290 If STRING is non-null, display that C string. Otherwise, the Lisp
17291 string LISP_STRING is displayed.
17293 If FACE_STRING is not nil, FACE_STRING_POS is a position in
17294 FACE_STRING. Display STRING or LISP_STRING with the face at
17295 FACE_STRING_POS in FACE_STRING:
17297 Display the string in the environment given by IT, but use the
17298 standard display table, temporarily.
17300 FIELD_WIDTH is the minimum number of output glyphs to produce.
17301 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17302 with spaces. If STRING has more characters, more than FIELD_WIDTH
17303 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
17305 PRECISION is the maximum number of characters to output from
17306 STRING. PRECISION < 0 means don't truncate the string.
17308 This is roughly equivalent to printf format specifiers:
17310 FIELD_WIDTH PRECISION PRINTF
17311 ----------------------------------------
17317 MULTIBYTE zero means do not display multibyte chars, > 0 means do
17318 display them, and < 0 means obey the current buffer's value of
17319 enable_multibyte_characters.
17321 Value is the number of glyphs produced. */
17324 display_string (string
, lisp_string
, face_string
, face_string_pos
,
17325 start
, it
, field_width
, precision
, max_x
, multibyte
)
17326 unsigned char *string
;
17327 Lisp_Object lisp_string
;
17328 Lisp_Object face_string
;
17329 int face_string_pos
;
17332 int field_width
, precision
, max_x
;
17335 int hpos_at_start
= it
->hpos
;
17336 int saved_face_id
= it
->face_id
;
17337 struct glyph_row
*row
= it
->glyph_row
;
17339 /* Initialize the iterator IT for iteration over STRING beginning
17340 with index START. */
17341 reseat_to_string (it
, string
, lisp_string
, start
,
17342 precision
, field_width
, multibyte
);
17344 /* If displaying STRING, set up the face of the iterator
17345 from LISP_STRING, if that's given. */
17346 if (STRINGP (face_string
))
17352 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
17353 0, it
->region_beg_charpos
,
17354 it
->region_end_charpos
,
17355 &endptr
, it
->base_face_id
, 0);
17356 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17357 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
17360 /* Set max_x to the maximum allowed X position. Don't let it go
17361 beyond the right edge of the window. */
17363 max_x
= it
->last_visible_x
;
17365 max_x
= min (max_x
, it
->last_visible_x
);
17367 /* Skip over display elements that are not visible. because IT->w is
17369 if (it
->current_x
< it
->first_visible_x
)
17370 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
17371 MOVE_TO_POS
| MOVE_TO_X
);
17373 row
->ascent
= it
->max_ascent
;
17374 row
->height
= it
->max_ascent
+ it
->max_descent
;
17375 row
->phys_ascent
= it
->max_phys_ascent
;
17376 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17377 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17379 /* This condition is for the case that we are called with current_x
17380 past last_visible_x. */
17381 while (it
->current_x
< max_x
)
17383 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
17385 /* Get the next display element. */
17386 if (!get_next_display_element (it
))
17389 /* Produce glyphs. */
17390 x_before
= it
->current_x
;
17391 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17392 PRODUCE_GLYPHS (it
);
17394 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
17397 while (i
< nglyphs
)
17399 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17401 if (!it
->truncate_lines_p
17402 && x
+ glyph
->pixel_width
> max_x
)
17404 /* End of continued line or max_x reached. */
17405 if (CHAR_GLYPH_PADDING_P (*glyph
))
17407 /* A wide character is unbreakable. */
17408 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17409 it
->current_x
= x_before
;
17413 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17418 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
17420 /* Glyph is at least partially visible. */
17422 if (x
< it
->first_visible_x
)
17423 it
->glyph_row
->x
= x
- it
->first_visible_x
;
17427 /* Glyph is off the left margin of the display area.
17428 Should not happen. */
17432 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17433 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17434 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17435 row
->phys_height
= max (row
->phys_height
,
17436 it
->max_phys_ascent
+ it
->max_phys_descent
);
17437 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17438 it
->max_extra_line_spacing
);
17439 x
+= glyph
->pixel_width
;
17443 /* Stop if max_x reached. */
17447 /* Stop at line ends. */
17448 if (ITERATOR_AT_END_OF_LINE_P (it
))
17450 it
->continuation_lines_width
= 0;
17454 set_iterator_to_next (it
, 1);
17456 /* Stop if truncating at the right edge. */
17457 if (it
->truncate_lines_p
17458 && it
->current_x
>= it
->last_visible_x
)
17460 /* Add truncation mark, but don't do it if the line is
17461 truncated at a padding space. */
17462 if (IT_CHARPOS (*it
) < it
->string_nchars
)
17464 if (!FRAME_WINDOW_P (it
->f
))
17468 if (it
->current_x
> it
->last_visible_x
)
17470 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17471 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17473 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17475 row
->used
[TEXT_AREA
] = i
;
17476 produce_special_glyphs (it
, IT_TRUNCATION
);
17479 produce_special_glyphs (it
, IT_TRUNCATION
);
17481 it
->glyph_row
->truncated_on_right_p
= 1;
17487 /* Maybe insert a truncation at the left. */
17488 if (it
->first_visible_x
17489 && IT_CHARPOS (*it
) > 0)
17491 if (!FRAME_WINDOW_P (it
->f
))
17492 insert_left_trunc_glyphs (it
);
17493 it
->glyph_row
->truncated_on_left_p
= 1;
17496 it
->face_id
= saved_face_id
;
17498 /* Value is number of columns displayed. */
17499 return it
->hpos
- hpos_at_start
;
17504 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
17505 appears as an element of LIST or as the car of an element of LIST.
17506 If PROPVAL is a list, compare each element against LIST in that
17507 way, and return 1/2 if any element of PROPVAL is found in LIST.
17508 Otherwise return 0. This function cannot quit.
17509 The return value is 2 if the text is invisible but with an ellipsis
17510 and 1 if it's invisible and without an ellipsis. */
17513 invisible_p (propval
, list
)
17514 register Lisp_Object propval
;
17517 register Lisp_Object tail
, proptail
;
17519 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17521 register Lisp_Object tem
;
17523 if (EQ (propval
, tem
))
17525 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
17526 return NILP (XCDR (tem
)) ? 1 : 2;
17529 if (CONSP (propval
))
17531 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
17533 Lisp_Object propelt
;
17534 propelt
= XCAR (proptail
);
17535 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17537 register Lisp_Object tem
;
17539 if (EQ (propelt
, tem
))
17541 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
17542 return NILP (XCDR (tem
)) ? 1 : 2;
17550 /* Calculate a width or height in pixels from a specification using
17551 the following elements:
17554 NUM - a (fractional) multiple of the default font width/height
17555 (NUM) - specifies exactly NUM pixels
17556 UNIT - a fixed number of pixels, see below.
17557 ELEMENT - size of a display element in pixels, see below.
17558 (NUM . SPEC) - equals NUM * SPEC
17559 (+ SPEC SPEC ...) - add pixel values
17560 (- SPEC SPEC ...) - subtract pixel values
17561 (- SPEC) - negate pixel value
17564 INT or FLOAT - a number constant
17565 SYMBOL - use symbol's (buffer local) variable binding.
17568 in - pixels per inch *)
17569 mm - pixels per 1/1000 meter *)
17570 cm - pixels per 1/100 meter *)
17571 width - width of current font in pixels.
17572 height - height of current font in pixels.
17574 *) using the ratio(s) defined in display-pixels-per-inch.
17578 left-fringe - left fringe width in pixels
17579 right-fringe - right fringe width in pixels
17581 left-margin - left margin width in pixels
17582 right-margin - right margin width in pixels
17584 scroll-bar - scroll-bar area width in pixels
17588 Pixels corresponding to 5 inches:
17591 Total width of non-text areas on left side of window (if scroll-bar is on left):
17592 '(space :width (+ left-fringe left-margin scroll-bar))
17594 Align to first text column (in header line):
17595 '(space :align-to 0)
17597 Align to middle of text area minus half the width of variable `my-image'
17598 containing a loaded image:
17599 '(space :align-to (0.5 . (- text my-image)))
17601 Width of left margin minus width of 1 character in the default font:
17602 '(space :width (- left-margin 1))
17604 Width of left margin minus width of 2 characters in the current font:
17605 '(space :width (- left-margin (2 . width)))
17607 Center 1 character over left-margin (in header line):
17608 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
17610 Different ways to express width of left fringe plus left margin minus one pixel:
17611 '(space :width (- (+ left-fringe left-margin) (1)))
17612 '(space :width (+ left-fringe left-margin (- (1))))
17613 '(space :width (+ left-fringe left-margin (-1)))
17617 #define NUMVAL(X) \
17618 ((INTEGERP (X) || FLOATP (X)) \
17623 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
17628 int width_p
, *align_to
;
17632 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
17633 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
17636 return OK_PIXELS (0);
17638 if (SYMBOLP (prop
))
17640 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
17642 char *unit
= SDATA (SYMBOL_NAME (prop
));
17644 if (unit
[0] == 'i' && unit
[1] == 'n')
17646 else if (unit
[0] == 'm' && unit
[1] == 'm')
17648 else if (unit
[0] == 'c' && unit
[1] == 'm')
17655 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
17656 || (CONSP (Vdisplay_pixels_per_inch
)
17658 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
17659 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
17661 return OK_PIXELS (ppi
/ pixels
);
17667 #ifdef HAVE_WINDOW_SYSTEM
17668 if (EQ (prop
, Qheight
))
17669 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
17670 if (EQ (prop
, Qwidth
))
17671 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
17673 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
17674 return OK_PIXELS (1);
17677 if (EQ (prop
, Qtext
))
17678 return OK_PIXELS (width_p
17679 ? window_box_width (it
->w
, TEXT_AREA
)
17680 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
17682 if (align_to
&& *align_to
< 0)
17685 if (EQ (prop
, Qleft
))
17686 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
17687 if (EQ (prop
, Qright
))
17688 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
17689 if (EQ (prop
, Qcenter
))
17690 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
17691 + window_box_width (it
->w
, TEXT_AREA
) / 2);
17692 if (EQ (prop
, Qleft_fringe
))
17693 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17694 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
17695 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
17696 if (EQ (prop
, Qright_fringe
))
17697 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17698 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17699 : window_box_right_offset (it
->w
, TEXT_AREA
));
17700 if (EQ (prop
, Qleft_margin
))
17701 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
17702 if (EQ (prop
, Qright_margin
))
17703 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
17704 if (EQ (prop
, Qscroll_bar
))
17705 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
17707 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17708 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17709 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
17714 if (EQ (prop
, Qleft_fringe
))
17715 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
17716 if (EQ (prop
, Qright_fringe
))
17717 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
17718 if (EQ (prop
, Qleft_margin
))
17719 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
17720 if (EQ (prop
, Qright_margin
))
17721 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
17722 if (EQ (prop
, Qscroll_bar
))
17723 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
17726 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
17729 if (INTEGERP (prop
) || FLOATP (prop
))
17731 int base_unit
= (width_p
17732 ? FRAME_COLUMN_WIDTH (it
->f
)
17733 : FRAME_LINE_HEIGHT (it
->f
));
17734 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
17739 Lisp_Object car
= XCAR (prop
);
17740 Lisp_Object cdr
= XCDR (prop
);
17744 #ifdef HAVE_WINDOW_SYSTEM
17745 if (valid_image_p (prop
))
17747 int id
= lookup_image (it
->f
, prop
);
17748 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
17750 return OK_PIXELS (width_p
? img
->width
: img
->height
);
17753 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
17759 while (CONSP (cdr
))
17761 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
17762 font
, width_p
, align_to
))
17765 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
17770 if (EQ (car
, Qminus
))
17772 return OK_PIXELS (pixels
);
17775 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
17778 if (INTEGERP (car
) || FLOATP (car
))
17781 pixels
= XFLOATINT (car
);
17783 return OK_PIXELS (pixels
);
17784 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
17785 font
, width_p
, align_to
))
17786 return OK_PIXELS (pixels
* fact
);
17797 /***********************************************************************
17799 ***********************************************************************/
17801 #ifdef HAVE_WINDOW_SYSTEM
17806 dump_glyph_string (s
)
17807 struct glyph_string
*s
;
17809 fprintf (stderr
, "glyph string\n");
17810 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
17811 s
->x
, s
->y
, s
->width
, s
->height
);
17812 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
17813 fprintf (stderr
, " hl = %d\n", s
->hl
);
17814 fprintf (stderr
, " left overhang = %d, right = %d\n",
17815 s
->left_overhang
, s
->right_overhang
);
17816 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
17817 fprintf (stderr
, " extends to end of line = %d\n",
17818 s
->extends_to_end_of_line_p
);
17819 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
17820 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
17823 #endif /* GLYPH_DEBUG */
17825 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
17826 of XChar2b structures for S; it can't be allocated in
17827 init_glyph_string because it must be allocated via `alloca'. W
17828 is the window on which S is drawn. ROW and AREA are the glyph row
17829 and area within the row from which S is constructed. START is the
17830 index of the first glyph structure covered by S. HL is a
17831 face-override for drawing S. */
17834 #define OPTIONAL_HDC(hdc) hdc,
17835 #define DECLARE_HDC(hdc) HDC hdc;
17836 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
17837 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
17840 #ifndef OPTIONAL_HDC
17841 #define OPTIONAL_HDC(hdc)
17842 #define DECLARE_HDC(hdc)
17843 #define ALLOCATE_HDC(hdc, f)
17844 #define RELEASE_HDC(hdc, f)
17848 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
17849 struct glyph_string
*s
;
17853 struct glyph_row
*row
;
17854 enum glyph_row_area area
;
17856 enum draw_glyphs_face hl
;
17858 bzero (s
, sizeof *s
);
17860 s
->f
= XFRAME (w
->frame
);
17864 s
->display
= FRAME_X_DISPLAY (s
->f
);
17865 s
->window
= FRAME_X_WINDOW (s
->f
);
17866 s
->char2b
= char2b
;
17870 s
->first_glyph
= row
->glyphs
[area
] + start
;
17871 s
->height
= row
->height
;
17872 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
17874 /* Display the internal border below the tool-bar window. */
17875 if (WINDOWP (s
->f
->tool_bar_window
)
17876 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
17877 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
17879 s
->ybase
= s
->y
+ row
->ascent
;
17883 /* Append the list of glyph strings with head H and tail T to the list
17884 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
17887 append_glyph_string_lists (head
, tail
, h
, t
)
17888 struct glyph_string
**head
, **tail
;
17889 struct glyph_string
*h
, *t
;
17903 /* Prepend the list of glyph strings with head H and tail T to the
17904 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
17908 prepend_glyph_string_lists (head
, tail
, h
, t
)
17909 struct glyph_string
**head
, **tail
;
17910 struct glyph_string
*h
, *t
;
17924 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
17925 Set *HEAD and *TAIL to the resulting list. */
17928 append_glyph_string (head
, tail
, s
)
17929 struct glyph_string
**head
, **tail
;
17930 struct glyph_string
*s
;
17932 s
->next
= s
->prev
= NULL
;
17933 append_glyph_string_lists (head
, tail
, s
, s
);
17937 /* Get face and two-byte form of character glyph GLYPH on frame F.
17938 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
17939 a pointer to a realized face that is ready for display. */
17941 static INLINE
struct face
*
17942 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
17944 struct glyph
*glyph
;
17950 xassert (glyph
->type
== CHAR_GLYPH
);
17951 face
= FACE_FROM_ID (f
, glyph
->face_id
);
17956 if (!glyph
->multibyte_p
)
17958 /* Unibyte case. We don't have to encode, but we have to make
17959 sure to use a face suitable for unibyte. */
17960 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17962 else if (glyph
->u
.ch
< 128
17963 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
17965 /* Case of ASCII in a face known to fit ASCII. */
17966 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17970 struct font_info
*font_info
17971 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17974 struct charset
*charset
= CHARSET_FROM_ID (font_info
->charset
);
17975 unsigned code
= ENCODE_CHAR (charset
, glyph
->u
.ch
);
17977 if (CHARSET_DIMENSION (charset
) == 1)
17978 STORE_XCHAR2B (char2b
, 0, code
);
17980 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
17982 /* Maybe encode the character in *CHAR2B. */
17983 if (CHARSET_ID (charset
) != charset_ascii
)
17986 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, charset
,
17992 /* Make sure X resources of the face are allocated. */
17993 xassert (face
!= NULL
);
17994 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17999 /* Fill glyph string S with composition components specified by S->cmp.
18001 FACES is an array of faces for all components of this composition.
18002 S->gidx is the index of the first component for S.
18003 OVERLAPS_P non-zero means S should draw the foreground only, and
18004 use its physical height for clipping.
18006 Value is the index of a component not in S. */
18009 fill_composite_glyph_string (s
, faces
, overlaps_p
)
18010 struct glyph_string
*s
;
18011 struct face
**faces
;
18018 s
->for_overlaps_p
= overlaps_p
;
18020 s
->face
= faces
[s
->gidx
];
18021 s
->font
= s
->face
->font
;
18022 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18024 /* For all glyphs of this composition, starting at the offset
18025 S->gidx, until we reach the end of the definition or encounter a
18026 glyph that requires the different face, add it to S. */
18028 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
18031 /* All glyph strings for the same composition has the same width,
18032 i.e. the width set for the first component of the composition. */
18034 s
->width
= s
->first_glyph
->pixel_width
;
18036 /* If the specified font could not be loaded, use the frame's
18037 default font, but record the fact that we couldn't load it in
18038 the glyph string so that we can draw rectangles for the
18039 characters of the glyph string. */
18040 if (s
->font
== NULL
)
18042 s
->font_not_found_p
= 1;
18043 s
->font
= FRAME_FONT (s
->f
);
18046 /* Adjust base line for subscript/superscript text. */
18047 s
->ybase
+= s
->first_glyph
->voffset
;
18049 xassert (s
->face
&& s
->face
->gc
);
18051 /* This glyph string must always be drawn with 16-bit functions. */
18054 return s
->gidx
+ s
->nchars
;
18058 /* Fill glyph string S from a sequence of character glyphs.
18060 FACE_ID is the face id of the string. START is the index of the
18061 first glyph to consider, END is the index of the last + 1.
18062 OVERLAPS_P non-zero means S should draw the foreground only, and
18063 use its physical height for clipping.
18065 Value is the index of the first glyph not in S. */
18068 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
18069 struct glyph_string
*s
;
18071 int start
, end
, overlaps_p
;
18073 struct glyph
*glyph
, *last
;
18075 int glyph_not_available_p
;
18077 xassert (s
->f
== XFRAME (s
->w
->frame
));
18078 xassert (s
->nchars
== 0);
18079 xassert (start
>= 0 && end
> start
);
18081 s
->for_overlaps_p
= overlaps_p
,
18082 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18083 last
= s
->row
->glyphs
[s
->area
] + end
;
18084 voffset
= glyph
->voffset
;
18086 glyph_not_available_p
= glyph
->glyph_not_available_p
;
18088 while (glyph
< last
18089 && glyph
->type
== CHAR_GLYPH
18090 && glyph
->voffset
== voffset
18091 /* Same face id implies same font, nowadays. */
18092 && glyph
->face_id
== face_id
18093 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
18097 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
18098 s
->char2b
+ s
->nchars
,
18100 s
->two_byte_p
= two_byte_p
;
18102 xassert (s
->nchars
<= end
- start
);
18103 s
->width
+= glyph
->pixel_width
;
18107 s
->font
= s
->face
->font
;
18108 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18110 /* If the specified font could not be loaded, use the frame's font,
18111 but record the fact that we couldn't load it in
18112 S->font_not_found_p so that we can draw rectangles for the
18113 characters of the glyph string. */
18114 if (s
->font
== NULL
|| glyph_not_available_p
)
18116 s
->font_not_found_p
= 1;
18117 s
->font
= FRAME_FONT (s
->f
);
18120 /* Adjust base line for subscript/superscript text. */
18121 s
->ybase
+= voffset
;
18123 xassert (s
->face
&& s
->face
->gc
);
18124 return glyph
- s
->row
->glyphs
[s
->area
];
18128 /* Fill glyph string S from image glyph S->first_glyph. */
18131 fill_image_glyph_string (s
)
18132 struct glyph_string
*s
;
18134 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
18135 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
18137 s
->slice
= s
->first_glyph
->slice
;
18138 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
18139 s
->font
= s
->face
->font
;
18140 s
->width
= s
->first_glyph
->pixel_width
;
18142 /* Adjust base line for subscript/superscript text. */
18143 s
->ybase
+= s
->first_glyph
->voffset
;
18147 /* Fill glyph string S from a sequence of stretch glyphs.
18149 ROW is the glyph row in which the glyphs are found, AREA is the
18150 area within the row. START is the index of the first glyph to
18151 consider, END is the index of the last + 1.
18153 Value is the index of the first glyph not in S. */
18156 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
18157 struct glyph_string
*s
;
18158 struct glyph_row
*row
;
18159 enum glyph_row_area area
;
18162 struct glyph
*glyph
, *last
;
18163 int voffset
, face_id
;
18165 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
18167 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18168 last
= s
->row
->glyphs
[s
->area
] + end
;
18169 face_id
= glyph
->face_id
;
18170 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
18171 s
->font
= s
->face
->font
;
18172 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18173 s
->width
= glyph
->pixel_width
;
18174 voffset
= glyph
->voffset
;
18178 && glyph
->type
== STRETCH_GLYPH
18179 && glyph
->voffset
== voffset
18180 && glyph
->face_id
== face_id
);
18182 s
->width
+= glyph
->pixel_width
;
18184 /* Adjust base line for subscript/superscript text. */
18185 s
->ybase
+= voffset
;
18187 /* The case that face->gc == 0 is handled when drawing the glyph
18188 string by calling PREPARE_FACE_FOR_DISPLAY. */
18190 return glyph
- s
->row
->glyphs
[s
->area
];
18195 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
18196 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
18197 assumed to be zero. */
18200 x_get_glyph_overhangs (glyph
, f
, left
, right
)
18201 struct glyph
*glyph
;
18205 *left
= *right
= 0;
18207 if (glyph
->type
== CHAR_GLYPH
)
18211 struct font_info
*font_info
;
18215 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
18217 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18218 if (font
/* ++KFS: Should this be font_info ? */
18219 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
18221 if (pcm
->rbearing
> pcm
->width
)
18222 *right
= pcm
->rbearing
- pcm
->width
;
18223 if (pcm
->lbearing
< 0)
18224 *left
= -pcm
->lbearing
;
18227 else if (glyph
->type
== COMPOSITE_GLYPH
)
18229 struct composition
*cmp
= composition_table
[glyph
->u
.cmp_id
];
18231 *right
= cmp
->rbearing
- cmp
->pixel_width
;
18232 *left
= - cmp
->lbearing
;
18237 /* Return the index of the first glyph preceding glyph string S that
18238 is overwritten by S because of S's left overhang. Value is -1
18239 if no glyphs are overwritten. */
18242 left_overwritten (s
)
18243 struct glyph_string
*s
;
18247 if (s
->left_overhang
)
18250 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18251 int first
= s
->first_glyph
- glyphs
;
18253 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
18254 x
-= glyphs
[i
].pixel_width
;
18265 /* Return the index of the first glyph preceding glyph string S that
18266 is overwriting S because of its right overhang. Value is -1 if no
18267 glyph in front of S overwrites S. */
18270 left_overwriting (s
)
18271 struct glyph_string
*s
;
18274 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18275 int first
= s
->first_glyph
- glyphs
;
18279 for (i
= first
- 1; i
>= 0; --i
)
18282 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18285 x
-= glyphs
[i
].pixel_width
;
18292 /* Return the index of the last glyph following glyph string S that is
18293 not overwritten by S because of S's right overhang. Value is -1 if
18294 no such glyph is found. */
18297 right_overwritten (s
)
18298 struct glyph_string
*s
;
18302 if (s
->right_overhang
)
18305 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18306 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18307 int end
= s
->row
->used
[s
->area
];
18309 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
18310 x
+= glyphs
[i
].pixel_width
;
18319 /* Return the index of the last glyph following glyph string S that
18320 overwrites S because of its left overhang. Value is negative
18321 if no such glyph is found. */
18324 right_overwriting (s
)
18325 struct glyph_string
*s
;
18328 int end
= s
->row
->used
[s
->area
];
18329 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18330 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18334 for (i
= first
; i
< end
; ++i
)
18337 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18340 x
+= glyphs
[i
].pixel_width
;
18347 /* Get face and two-byte form of character C in face FACE_ID on frame
18348 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
18349 means we want to display multibyte text. DISPLAY_P non-zero means
18350 make sure that X resources for the face returned are allocated.
18351 Value is a pointer to a realized face that is ready for display if
18352 DISPLAY_P is non-zero. */
18354 static INLINE
struct face
*
18355 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
18359 int multibyte_p
, display_p
;
18361 struct face
*face
= FACE_FROM_ID (f
, face_id
);
18365 /* Unibyte case. We don't have to encode, but we have to make
18366 sure to use a face suitable for unibyte. */
18367 STORE_XCHAR2B (char2b
, 0, c
);
18368 face_id
= FACE_FOR_CHAR (f
, face
, c
, -1, Qnil
);
18369 face
= FACE_FROM_ID (f
, face_id
);
18371 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
18373 /* Case of ASCII in a face known to fit ASCII. */
18374 STORE_XCHAR2B (char2b
, 0, c
);
18376 else if (face
->font
!= NULL
)
18378 struct font_info
*font_info
18379 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18380 struct charset
*charset
= CHARSET_FROM_ID (font_info
->charset
);
18381 unsigned code
= ENCODE_CHAR (charset
, c
);
18383 if (CHARSET_DIMENSION (charset
) == 1)
18384 STORE_XCHAR2B (char2b
, 0, code
);
18386 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
18387 /* Maybe encode the character in *CHAR2B. */
18388 rif
->encode_char (c
, char2b
, font_info
, charset
, NULL
);
18391 /* Make sure X resources of the face are allocated. */
18392 #ifdef HAVE_X_WINDOWS
18396 xassert (face
!= NULL
);
18397 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18404 /* Set background width of glyph string S. START is the index of the
18405 first glyph following S. LAST_X is the right-most x-position + 1
18406 in the drawing area. */
18409 set_glyph_string_background_width (s
, start
, last_x
)
18410 struct glyph_string
*s
;
18414 /* If the face of this glyph string has to be drawn to the end of
18415 the drawing area, set S->extends_to_end_of_line_p. */
18416 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
18418 if (start
== s
->row
->used
[s
->area
]
18419 && s
->area
== TEXT_AREA
18420 && ((s
->hl
== DRAW_NORMAL_TEXT
18421 && (s
->row
->fill_line_p
18422 || s
->face
->background
!= default_face
->background
18423 || s
->face
->stipple
!= default_face
->stipple
18424 || s
->row
->mouse_face_p
))
18425 || s
->hl
== DRAW_MOUSE_FACE
18426 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
18427 && s
->row
->fill_line_p
)))
18428 s
->extends_to_end_of_line_p
= 1;
18430 /* If S extends its face to the end of the line, set its
18431 background_width to the distance to the right edge of the drawing
18433 if (s
->extends_to_end_of_line_p
)
18434 s
->background_width
= last_x
- s
->x
+ 1;
18436 s
->background_width
= s
->width
;
18440 /* Compute overhangs and x-positions for glyph string S and its
18441 predecessors, or successors. X is the starting x-position for S.
18442 BACKWARD_P non-zero means process predecessors. */
18445 compute_overhangs_and_x (s
, x
, backward_p
)
18446 struct glyph_string
*s
;
18454 if (rif
->compute_glyph_string_overhangs
)
18455 rif
->compute_glyph_string_overhangs (s
);
18465 if (rif
->compute_glyph_string_overhangs
)
18466 rif
->compute_glyph_string_overhangs (s
);
18476 /* The following macros are only called from draw_glyphs below.
18477 They reference the following parameters of that function directly:
18478 `w', `row', `area', and `overlap_p'
18479 as well as the following local variables:
18480 `s', `f', and `hdc' (in W32) */
18483 /* On W32, silently add local `hdc' variable to argument list of
18484 init_glyph_string. */
18485 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18486 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
18488 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18489 init_glyph_string (s, char2b, w, row, area, start, hl)
18492 /* Add a glyph string for a stretch glyph to the list of strings
18493 between HEAD and TAIL. START is the index of the stretch glyph in
18494 row area AREA of glyph row ROW. END is the index of the last glyph
18495 in that glyph row area. X is the current output position assigned
18496 to the new glyph string constructed. HL overrides that face of the
18497 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18498 is the right-most x-position of the drawing area. */
18500 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
18501 and below -- keep them on one line. */
18502 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18505 s = (struct glyph_string *) alloca (sizeof *s); \
18506 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18507 START = fill_stretch_glyph_string (s, row, area, START, END); \
18508 append_glyph_string (&HEAD, &TAIL, s); \
18514 /* Add a glyph string for an image glyph to the list of strings
18515 between HEAD and TAIL. START is the index of the image glyph in
18516 row area AREA of glyph row ROW. END is the index of the last glyph
18517 in that glyph row area. X is the current output position assigned
18518 to the new glyph string constructed. HL overrides that face of the
18519 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18520 is the right-most x-position of the drawing area. */
18522 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18525 s = (struct glyph_string *) alloca (sizeof *s); \
18526 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18527 fill_image_glyph_string (s); \
18528 append_glyph_string (&HEAD, &TAIL, s); \
18535 /* Add a glyph string for a sequence of character glyphs to the list
18536 of strings between HEAD and TAIL. START is the index of the first
18537 glyph in row area AREA of glyph row ROW that is part of the new
18538 glyph string. END is the index of the last glyph in that glyph row
18539 area. X is the current output position assigned to the new glyph
18540 string constructed. HL overrides that face of the glyph; e.g. it
18541 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
18542 right-most x-position of the drawing area. */
18544 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18550 face_id = (row)->glyphs[area][START].face_id; \
18552 s = (struct glyph_string *) alloca (sizeof *s); \
18553 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
18554 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
18555 append_glyph_string (&HEAD, &TAIL, s); \
18557 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
18562 /* Add a glyph string for a composite sequence to the list of strings
18563 between HEAD and TAIL. START is the index of the first glyph in
18564 row area AREA of glyph row ROW that is part of the new glyph
18565 string. END is the index of the last glyph in that glyph row area.
18566 X is the current output position assigned to the new glyph string
18567 constructed. HL overrides that face of the glyph; e.g. it is
18568 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
18569 x-position of the drawing area. */
18571 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18573 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
18574 int face_id = (row)->glyphs[area][START].face_id; \
18575 struct face *base_face = FACE_FROM_ID (f, face_id); \
18576 struct composition *cmp = composition_table[cmp_id]; \
18577 int glyph_len = cmp->glyph_len; \
18579 struct face **faces; \
18580 struct glyph_string *first_s = NULL; \
18583 base_face = base_face->ascii_face; \
18584 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
18585 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
18586 /* At first, fill in `char2b' and `faces'. */ \
18587 for (n = 0; n < glyph_len; n++) \
18589 int c = COMPOSITION_GLYPH (cmp, n); \
18590 int this_face_id = FACE_FOR_CHAR (f, base_face, c, -1, Qnil); \
18591 faces[n] = FACE_FROM_ID (f, this_face_id); \
18592 get_char_face_and_encoding (f, c, this_face_id, \
18593 char2b + n, 1, 1); \
18596 /* Make glyph_strings for each glyph sequence that is drawable by \
18597 the same face, and append them to HEAD/TAIL. */ \
18598 for (n = 0; n < cmp->glyph_len;) \
18600 s = (struct glyph_string *) alloca (sizeof *s); \
18601 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
18602 append_glyph_string (&(HEAD), &(TAIL), s); \
18610 n = fill_composite_glyph_string (s, faces, overlaps_p); \
18618 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
18619 of AREA of glyph row ROW on window W between indices START and END.
18620 HL overrides the face for drawing glyph strings, e.g. it is
18621 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
18622 x-positions of the drawing area.
18624 This is an ugly monster macro construct because we must use alloca
18625 to allocate glyph strings (because draw_glyphs can be called
18626 asynchronously). */
18628 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18631 HEAD = TAIL = NULL; \
18632 while (START < END) \
18634 struct glyph *first_glyph = (row)->glyphs[area] + START; \
18635 switch (first_glyph->type) \
18638 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
18642 case COMPOSITE_GLYPH: \
18643 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
18647 case STRETCH_GLYPH: \
18648 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
18652 case IMAGE_GLYPH: \
18653 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
18663 set_glyph_string_background_width (s, START, LAST_X); \
18671 /* Draw glyphs between START and END in AREA of ROW on window W,
18672 starting at x-position X. X is relative to AREA in W. HL is a
18673 face-override with the following meaning:
18675 DRAW_NORMAL_TEXT draw normally
18676 DRAW_CURSOR draw in cursor face
18677 DRAW_MOUSE_FACE draw in mouse face.
18678 DRAW_INVERSE_VIDEO draw in mode line face
18679 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
18680 DRAW_IMAGE_RAISED draw an image with a raised relief around it
18682 If OVERLAPS_P is non-zero, draw only the foreground of characters
18683 and clip to the physical height of ROW.
18685 Value is the x-position reached, relative to AREA of W. */
18688 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
18691 struct glyph_row
*row
;
18692 enum glyph_row_area area
;
18693 EMACS_INT start
, end
;
18694 enum draw_glyphs_face hl
;
18697 struct glyph_string
*head
, *tail
;
18698 struct glyph_string
*s
;
18699 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
18700 int last_x
, area_width
;
18703 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18706 ALLOCATE_HDC (hdc
, f
);
18708 /* Let's rather be paranoid than getting a SEGV. */
18709 end
= min (end
, row
->used
[area
]);
18710 start
= max (0, start
);
18711 start
= min (end
, start
);
18713 /* Translate X to frame coordinates. Set last_x to the right
18714 end of the drawing area. */
18715 if (row
->full_width_p
)
18717 /* X is relative to the left edge of W, without scroll bars
18719 x
+= WINDOW_LEFT_EDGE_X (w
);
18720 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
18724 int area_left
= window_box_left (w
, area
);
18726 area_width
= window_box_width (w
, area
);
18727 last_x
= area_left
+ area_width
;
18730 /* Build a doubly-linked list of glyph_string structures between
18731 head and tail from what we have to draw. Note that the macro
18732 BUILD_GLYPH_STRINGS will modify its start parameter. That's
18733 the reason we use a separate variable `i'. */
18735 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
18737 x_reached
= tail
->x
+ tail
->background_width
;
18741 /* If there are any glyphs with lbearing < 0 or rbearing > width in
18742 the row, redraw some glyphs in front or following the glyph
18743 strings built above. */
18744 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
18747 struct glyph_string
*h
, *t
;
18749 /* Compute overhangs for all glyph strings. */
18750 if (rif
->compute_glyph_string_overhangs
)
18751 for (s
= head
; s
; s
= s
->next
)
18752 rif
->compute_glyph_string_overhangs (s
);
18754 /* Prepend glyph strings for glyphs in front of the first glyph
18755 string that are overwritten because of the first glyph
18756 string's left overhang. The background of all strings
18757 prepended must be drawn because the first glyph string
18759 i
= left_overwritten (head
);
18763 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
18764 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18766 compute_overhangs_and_x (t
, head
->x
, 1);
18767 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18771 /* Prepend glyph strings for glyphs in front of the first glyph
18772 string that overwrite that glyph string because of their
18773 right overhang. For these strings, only the foreground must
18774 be drawn, because it draws over the glyph string at `head'.
18775 The background must not be drawn because this would overwrite
18776 right overhangs of preceding glyphs for which no glyph
18778 i
= left_overwriting (head
);
18782 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
18783 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18784 for (s
= h
; s
; s
= s
->next
)
18785 s
->background_filled_p
= 1;
18786 compute_overhangs_and_x (t
, head
->x
, 1);
18787 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18790 /* Append glyphs strings for glyphs following the last glyph
18791 string tail that are overwritten by tail. The background of
18792 these strings has to be drawn because tail's foreground draws
18794 i
= right_overwritten (tail
);
18797 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18798 DRAW_NORMAL_TEXT
, x
, last_x
);
18799 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18800 append_glyph_string_lists (&head
, &tail
, h
, t
);
18804 /* Append glyph strings for glyphs following the last glyph
18805 string tail that overwrite tail. The foreground of such
18806 glyphs has to be drawn because it writes into the background
18807 of tail. The background must not be drawn because it could
18808 paint over the foreground of following glyphs. */
18809 i
= right_overwriting (tail
);
18813 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18814 DRAW_NORMAL_TEXT
, x
, last_x
);
18815 for (s
= h
; s
; s
= s
->next
)
18816 s
->background_filled_p
= 1;
18817 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18818 append_glyph_string_lists (&head
, &tail
, h
, t
);
18820 if (clip_head
|| clip_tail
)
18821 for (s
= head
; s
; s
= s
->next
)
18823 s
->clip_head
= clip_head
;
18824 s
->clip_tail
= clip_tail
;
18828 /* Draw all strings. */
18829 for (s
= head
; s
; s
= s
->next
)
18830 rif
->draw_glyph_string (s
);
18832 if (area
== TEXT_AREA
18833 && !row
->full_width_p
18834 /* When drawing overlapping rows, only the glyph strings'
18835 foreground is drawn, which doesn't erase a cursor
18839 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
18840 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
18841 : (tail
? tail
->x
+ tail
->background_width
: x
));
18843 int text_left
= window_box_left (w
, TEXT_AREA
);
18847 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
18848 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
18851 /* Value is the x-position up to which drawn, relative to AREA of W.
18852 This doesn't include parts drawn because of overhangs. */
18853 if (row
->full_width_p
)
18854 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
18856 x_reached
-= window_box_left (w
, area
);
18858 RELEASE_HDC (hdc
, f
);
18863 /* Expand row matrix if too narrow. Don't expand if area
18866 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
18868 if (!fonts_changed_p \
18869 && (it->glyph_row->glyphs[area] \
18870 < it->glyph_row->glyphs[area + 1])) \
18872 it->w->ncols_scale_factor++; \
18873 fonts_changed_p = 1; \
18877 /* Store one glyph for IT->char_to_display in IT->glyph_row.
18878 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18884 struct glyph
*glyph
;
18885 enum glyph_row_area area
= it
->area
;
18887 xassert (it
->glyph_row
);
18888 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
18890 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18891 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18893 glyph
->charpos
= CHARPOS (it
->position
);
18894 glyph
->object
= it
->object
;
18895 glyph
->pixel_width
= it
->pixel_width
;
18896 glyph
->ascent
= it
->ascent
;
18897 glyph
->descent
= it
->descent
;
18898 glyph
->voffset
= it
->voffset
;
18899 glyph
->type
= CHAR_GLYPH
;
18900 glyph
->multibyte_p
= it
->multibyte_p
;
18901 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18902 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18903 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18904 || it
->phys_descent
> it
->descent
);
18905 glyph
->padding_p
= 0;
18906 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
18907 glyph
->face_id
= it
->face_id
;
18908 glyph
->u
.ch
= it
->char_to_display
;
18909 glyph
->slice
= null_glyph_slice
;
18910 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18911 ++it
->glyph_row
->used
[area
];
18914 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18917 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
18918 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18921 append_composite_glyph (it
)
18924 struct glyph
*glyph
;
18925 enum glyph_row_area area
= it
->area
;
18927 xassert (it
->glyph_row
);
18929 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18930 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18932 glyph
->charpos
= CHARPOS (it
->position
);
18933 glyph
->object
= it
->object
;
18934 glyph
->pixel_width
= it
->pixel_width
;
18935 glyph
->ascent
= it
->ascent
;
18936 glyph
->descent
= it
->descent
;
18937 glyph
->voffset
= it
->voffset
;
18938 glyph
->type
= COMPOSITE_GLYPH
;
18939 glyph
->multibyte_p
= it
->multibyte_p
;
18940 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18941 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18942 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18943 || it
->phys_descent
> it
->descent
);
18944 glyph
->padding_p
= 0;
18945 glyph
->glyph_not_available_p
= 0;
18946 glyph
->face_id
= it
->face_id
;
18947 glyph
->u
.cmp_id
= it
->cmp_id
;
18948 glyph
->slice
= null_glyph_slice
;
18949 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18950 ++it
->glyph_row
->used
[area
];
18953 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18957 /* Change IT->ascent and IT->height according to the setting of
18961 take_vertical_position_into_account (it
)
18966 if (it
->voffset
< 0)
18967 /* Increase the ascent so that we can display the text higher
18969 it
->ascent
-= it
->voffset
;
18971 /* Increase the descent so that we can display the text lower
18973 it
->descent
+= it
->voffset
;
18978 /* Produce glyphs/get display metrics for the image IT is loaded with.
18979 See the description of struct display_iterator in dispextern.h for
18980 an overview of struct display_iterator. */
18983 produce_image_glyph (it
)
18989 struct glyph_slice slice
;
18991 xassert (it
->what
== IT_IMAGE
);
18993 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18995 /* Make sure X resources of the face is loaded. */
18996 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18998 if (it
->image_id
< 0)
19000 /* Fringe bitmap. */
19001 it
->ascent
= it
->phys_ascent
= 0;
19002 it
->descent
= it
->phys_descent
= 0;
19003 it
->pixel_width
= 0;
19008 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
19010 /* Make sure X resources of the image is loaded. */
19011 prepare_image_for_display (it
->f
, img
);
19013 slice
.x
= slice
.y
= 0;
19014 slice
.width
= img
->width
;
19015 slice
.height
= img
->height
;
19017 if (INTEGERP (it
->slice
.x
))
19018 slice
.x
= XINT (it
->slice
.x
);
19019 else if (FLOATP (it
->slice
.x
))
19020 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
19022 if (INTEGERP (it
->slice
.y
))
19023 slice
.y
= XINT (it
->slice
.y
);
19024 else if (FLOATP (it
->slice
.y
))
19025 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
19027 if (INTEGERP (it
->slice
.width
))
19028 slice
.width
= XINT (it
->slice
.width
);
19029 else if (FLOATP (it
->slice
.width
))
19030 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
19032 if (INTEGERP (it
->slice
.height
))
19033 slice
.height
= XINT (it
->slice
.height
);
19034 else if (FLOATP (it
->slice
.height
))
19035 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
19037 if (slice
.x
>= img
->width
)
19038 slice
.x
= img
->width
;
19039 if (slice
.y
>= img
->height
)
19040 slice
.y
= img
->height
;
19041 if (slice
.x
+ slice
.width
>= img
->width
)
19042 slice
.width
= img
->width
- slice
.x
;
19043 if (slice
.y
+ slice
.height
> img
->height
)
19044 slice
.height
= img
->height
- slice
.y
;
19046 if (slice
.width
== 0 || slice
.height
== 0)
19049 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
19051 it
->descent
= slice
.height
- glyph_ascent
;
19053 it
->descent
+= img
->vmargin
;
19054 if (slice
.y
+ slice
.height
== img
->height
)
19055 it
->descent
+= img
->vmargin
;
19056 it
->phys_descent
= it
->descent
;
19058 it
->pixel_width
= slice
.width
;
19060 it
->pixel_width
+= img
->hmargin
;
19061 if (slice
.x
+ slice
.width
== img
->width
)
19062 it
->pixel_width
+= img
->hmargin
;
19064 /* It's quite possible for images to have an ascent greater than
19065 their height, so don't get confused in that case. */
19066 if (it
->descent
< 0)
19069 #if 0 /* this breaks image tiling */
19070 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
19071 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
19072 if (face_ascent
> it
->ascent
)
19073 it
->ascent
= it
->phys_ascent
= face_ascent
;
19078 if (face
->box
!= FACE_NO_BOX
)
19080 if (face
->box_line_width
> 0)
19083 it
->ascent
+= face
->box_line_width
;
19084 if (slice
.y
+ slice
.height
== img
->height
)
19085 it
->descent
+= face
->box_line_width
;
19088 if (it
->start_of_box_run_p
&& slice
.x
== 0)
19089 it
->pixel_width
+= abs (face
->box_line_width
);
19090 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
19091 it
->pixel_width
+= abs (face
->box_line_width
);
19094 take_vertical_position_into_account (it
);
19098 struct glyph
*glyph
;
19099 enum glyph_row_area area
= it
->area
;
19101 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19102 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19104 glyph
->charpos
= CHARPOS (it
->position
);
19105 glyph
->object
= it
->object
;
19106 glyph
->pixel_width
= it
->pixel_width
;
19107 glyph
->ascent
= glyph_ascent
;
19108 glyph
->descent
= it
->descent
;
19109 glyph
->voffset
= it
->voffset
;
19110 glyph
->type
= IMAGE_GLYPH
;
19111 glyph
->multibyte_p
= it
->multibyte_p
;
19112 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19113 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19114 glyph
->overlaps_vertically_p
= 0;
19115 glyph
->padding_p
= 0;
19116 glyph
->glyph_not_available_p
= 0;
19117 glyph
->face_id
= it
->face_id
;
19118 glyph
->u
.img_id
= img
->id
;
19119 glyph
->slice
= slice
;
19120 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19121 ++it
->glyph_row
->used
[area
];
19124 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19129 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
19130 of the glyph, WIDTH and HEIGHT are the width and height of the
19131 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
19134 append_stretch_glyph (it
, object
, width
, height
, ascent
)
19136 Lisp_Object object
;
19140 struct glyph
*glyph
;
19141 enum glyph_row_area area
= it
->area
;
19143 xassert (ascent
>= 0 && ascent
<= height
);
19145 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19146 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19148 glyph
->charpos
= CHARPOS (it
->position
);
19149 glyph
->object
= object
;
19150 glyph
->pixel_width
= width
;
19151 glyph
->ascent
= ascent
;
19152 glyph
->descent
= height
- ascent
;
19153 glyph
->voffset
= it
->voffset
;
19154 glyph
->type
= STRETCH_GLYPH
;
19155 glyph
->multibyte_p
= it
->multibyte_p
;
19156 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19157 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19158 glyph
->overlaps_vertically_p
= 0;
19159 glyph
->padding_p
= 0;
19160 glyph
->glyph_not_available_p
= 0;
19161 glyph
->face_id
= it
->face_id
;
19162 glyph
->u
.stretch
.ascent
= ascent
;
19163 glyph
->u
.stretch
.height
= height
;
19164 glyph
->slice
= null_glyph_slice
;
19165 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19166 ++it
->glyph_row
->used
[area
];
19169 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19173 /* Produce a stretch glyph for iterator IT. IT->object is the value
19174 of the glyph property displayed. The value must be a list
19175 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
19178 1. `:width WIDTH' specifies that the space should be WIDTH *
19179 canonical char width wide. WIDTH may be an integer or floating
19182 2. `:relative-width FACTOR' specifies that the width of the stretch
19183 should be computed from the width of the first character having the
19184 `glyph' property, and should be FACTOR times that width.
19186 3. `:align-to HPOS' specifies that the space should be wide enough
19187 to reach HPOS, a value in canonical character units.
19189 Exactly one of the above pairs must be present.
19191 4. `:height HEIGHT' specifies that the height of the stretch produced
19192 should be HEIGHT, measured in canonical character units.
19194 5. `:relative-height FACTOR' specifies that the height of the
19195 stretch should be FACTOR times the height of the characters having
19196 the glyph property.
19198 Either none or exactly one of 4 or 5 must be present.
19200 6. `:ascent ASCENT' specifies that ASCENT percent of the height
19201 of the stretch should be used for the ascent of the stretch.
19202 ASCENT must be in the range 0 <= ASCENT <= 100. */
19205 produce_stretch_glyph (it
)
19208 /* (space :width WIDTH :height HEIGHT ...) */
19209 Lisp_Object prop
, plist
;
19210 int width
= 0, height
= 0, align_to
= -1;
19211 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
19214 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19215 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
19217 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19219 /* List should start with `space'. */
19220 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
19221 plist
= XCDR (it
->object
);
19223 /* Compute the width of the stretch. */
19224 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
19225 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
19227 /* Absolute width `:width WIDTH' specified and valid. */
19228 zero_width_ok_p
= 1;
19231 else if (prop
= Fplist_get (plist
, QCrelative_width
),
19234 /* Relative width `:relative-width FACTOR' specified and valid.
19235 Compute the width of the characters having the `glyph'
19238 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
19241 if (it
->multibyte_p
)
19243 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
19244 - IT_BYTEPOS (*it
));
19245 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
19248 it2
.c
= *p
, it2
.len
= 1;
19250 it2
.glyph_row
= NULL
;
19251 it2
.what
= IT_CHARACTER
;
19252 x_produce_glyphs (&it2
);
19253 width
= NUMVAL (prop
) * it2
.pixel_width
;
19255 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
19256 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
19258 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
19259 align_to
= (align_to
< 0
19261 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
19262 else if (align_to
< 0)
19263 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
19264 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
19265 zero_width_ok_p
= 1;
19268 /* Nothing specified -> width defaults to canonical char width. */
19269 width
= FRAME_COLUMN_WIDTH (it
->f
);
19271 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
19274 /* Compute height. */
19275 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
19276 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19279 zero_height_ok_p
= 1;
19281 else if (prop
= Fplist_get (plist
, QCrelative_height
),
19283 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
19285 height
= FONT_HEIGHT (font
);
19287 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
19290 /* Compute percentage of height used for ascent. If
19291 `:ascent ASCENT' is present and valid, use that. Otherwise,
19292 derive the ascent from the font in use. */
19293 if (prop
= Fplist_get (plist
, QCascent
),
19294 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
19295 ascent
= height
* NUMVAL (prop
) / 100.0;
19296 else if (!NILP (prop
)
19297 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19298 ascent
= min (max (0, (int)tem
), height
);
19300 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
19302 if (width
> 0 && height
> 0 && it
->glyph_row
)
19304 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
19305 if (!STRINGP (object
))
19306 object
= it
->w
->buffer
;
19307 append_stretch_glyph (it
, object
, width
, height
, ascent
);
19310 it
->pixel_width
= width
;
19311 it
->ascent
= it
->phys_ascent
= ascent
;
19312 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
19313 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
19315 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
19317 if (face
->box_line_width
> 0)
19319 it
->ascent
+= face
->box_line_width
;
19320 it
->descent
+= face
->box_line_width
;
19323 if (it
->start_of_box_run_p
)
19324 it
->pixel_width
+= abs (face
->box_line_width
);
19325 if (it
->end_of_box_run_p
)
19326 it
->pixel_width
+= abs (face
->box_line_width
);
19329 take_vertical_position_into_account (it
);
19332 /* Get line-height and line-spacing property at point.
19333 If line-height has format (HEIGHT TOTAL), return TOTAL
19334 in TOTAL_HEIGHT. */
19337 get_line_height_property (it
, prop
)
19341 Lisp_Object position
;
19343 if (STRINGP (it
->object
))
19344 position
= make_number (IT_STRING_CHARPOS (*it
));
19345 else if (BUFFERP (it
->object
))
19346 position
= make_number (IT_CHARPOS (*it
));
19350 return Fget_char_property (position
, prop
, it
->object
);
19353 /* Calculate line-height and line-spacing properties.
19354 An integer value specifies explicit pixel value.
19355 A float value specifies relative value to current face height.
19356 A cons (float . face-name) specifies relative value to
19357 height of specified face font.
19359 Returns height in pixels, or nil. */
19363 calc_line_height_property (it
, val
, font
, boff
, override
)
19367 int boff
, override
;
19369 Lisp_Object face_name
= Qnil
;
19370 int ascent
, descent
, height
;
19372 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
19377 face_name
= XCAR (val
);
19379 if (!NUMBERP (val
))
19380 val
= make_number (1);
19381 if (NILP (face_name
))
19383 height
= it
->ascent
+ it
->descent
;
19388 if (NILP (face_name
))
19390 font
= FRAME_FONT (it
->f
);
19391 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19393 else if (EQ (face_name
, Qt
))
19401 struct font_info
*font_info
;
19403 face_id
= lookup_named_face (it
->f
, face_name
, 0);
19405 return make_number (-1);
19407 face
= FACE_FROM_ID (it
->f
, face_id
);
19410 return make_number (-1);
19412 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19413 boff
= font_info
->baseline_offset
;
19414 if (font_info
->vertical_centering
)
19415 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19418 ascent
= FONT_BASE (font
) + boff
;
19419 descent
= FONT_DESCENT (font
) - boff
;
19423 it
->override_ascent
= ascent
;
19424 it
->override_descent
= descent
;
19425 it
->override_boff
= boff
;
19428 height
= ascent
+ descent
;
19432 height
= (int)(XFLOAT_DATA (val
) * height
);
19433 else if (INTEGERP (val
))
19434 height
*= XINT (val
);
19436 return make_number (height
);
19441 Produce glyphs/get display metrics for the display element IT is
19442 loaded with. See the description of struct display_iterator in
19443 dispextern.h for an overview of struct display_iterator. */
19446 x_produce_glyphs (it
)
19449 int extra_line_spacing
= it
->extra_line_spacing
;
19451 it
->glyph_not_available_p
= 0;
19453 if (it
->what
== IT_CHARACTER
)
19457 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19459 int font_not_found_p
;
19460 struct font_info
*font_info
;
19461 int boff
; /* baseline offset */
19462 /* We may change it->multibyte_p upon unibyte<->multibyte
19463 conversion. So, save the current value now and restore it
19466 Note: It seems that we don't have to record multibyte_p in
19467 struct glyph because the character code itself tells if or
19468 not the character is multibyte. Thus, in the future, we must
19469 consider eliminating the field `multibyte_p' in the struct
19471 int saved_multibyte_p
= it
->multibyte_p
;
19473 /* Maybe translate single-byte characters to multibyte, or the
19475 it
->char_to_display
= it
->c
;
19476 if (!ASCII_BYTE_P (it
->c
)
19477 && ! it
->multibyte_p
)
19479 if (SINGLE_BYTE_CHAR_P (it
->c
)
19480 && unibyte_display_via_language_environment
)
19481 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19482 if (! SINGLE_BYTE_CHAR_P (it
->c
))
19484 it
->multibyte_p
= 1;
19485 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
,
19487 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19491 /* Get font to use. Encode IT->char_to_display. */
19492 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19493 &char2b
, it
->multibyte_p
, 0);
19496 /* When no suitable font found, use the default font. */
19497 font_not_found_p
= font
== NULL
;
19498 if (font_not_found_p
)
19500 font
= FRAME_FONT (it
->f
);
19501 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19506 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19507 boff
= font_info
->baseline_offset
;
19508 if (font_info
->vertical_centering
)
19509 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19512 if (it
->char_to_display
>= ' '
19513 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
19515 /* Either unibyte or ASCII. */
19520 pcm
= rif
->per_char_metric (font
, &char2b
,
19521 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
19523 if (it
->override_ascent
>= 0)
19525 it
->ascent
= it
->override_ascent
;
19526 it
->descent
= it
->override_descent
;
19527 boff
= it
->override_boff
;
19531 it
->ascent
= FONT_BASE (font
) + boff
;
19532 it
->descent
= FONT_DESCENT (font
) - boff
;
19537 it
->phys_ascent
= pcm
->ascent
+ boff
;
19538 it
->phys_descent
= pcm
->descent
- boff
;
19539 it
->pixel_width
= pcm
->width
;
19543 it
->glyph_not_available_p
= 1;
19544 it
->phys_ascent
= it
->ascent
;
19545 it
->phys_descent
= it
->descent
;
19546 it
->pixel_width
= FONT_WIDTH (font
);
19549 if (it
->constrain_row_ascent_descent_p
)
19551 if (it
->descent
> it
->max_descent
)
19553 it
->ascent
+= it
->descent
- it
->max_descent
;
19554 it
->descent
= it
->max_descent
;
19556 if (it
->ascent
> it
->max_ascent
)
19558 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19559 it
->ascent
= it
->max_ascent
;
19561 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19562 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19563 extra_line_spacing
= 0;
19566 /* If this is a space inside a region of text with
19567 `space-width' property, change its width. */
19568 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
19570 it
->pixel_width
*= XFLOATINT (it
->space_width
);
19572 /* If face has a box, add the box thickness to the character
19573 height. If character has a box line to the left and/or
19574 right, add the box line width to the character's width. */
19575 if (face
->box
!= FACE_NO_BOX
)
19577 int thick
= face
->box_line_width
;
19581 it
->ascent
+= thick
;
19582 it
->descent
+= thick
;
19587 if (it
->start_of_box_run_p
)
19588 it
->pixel_width
+= thick
;
19589 if (it
->end_of_box_run_p
)
19590 it
->pixel_width
+= thick
;
19593 /* If face has an overline, add the height of the overline
19594 (1 pixel) and a 1 pixel margin to the character height. */
19595 if (face
->overline_p
)
19598 if (it
->constrain_row_ascent_descent_p
)
19600 if (it
->ascent
> it
->max_ascent
)
19601 it
->ascent
= it
->max_ascent
;
19602 if (it
->descent
> it
->max_descent
)
19603 it
->descent
= it
->max_descent
;
19606 take_vertical_position_into_account (it
);
19608 /* If we have to actually produce glyphs, do it. */
19613 /* Translate a space with a `space-width' property
19614 into a stretch glyph. */
19615 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
19616 / FONT_HEIGHT (font
));
19617 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19618 it
->ascent
+ it
->descent
, ascent
);
19623 /* If characters with lbearing or rbearing are displayed
19624 in this line, record that fact in a flag of the
19625 glyph row. This is used to optimize X output code. */
19626 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
19627 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19630 else if (it
->char_to_display
== '\n')
19632 /* A newline has no width but we need the height of the line.
19633 But if previous part of the line set a height, don't
19634 increase that height */
19636 Lisp_Object height
;
19637 Lisp_Object total_height
= Qnil
;
19639 it
->override_ascent
= -1;
19640 it
->pixel_width
= 0;
19643 height
= get_line_height_property(it
, Qline_height
);
19644 /* Split (line-height total-height) list */
19646 && CONSP (XCDR (height
))
19647 && NILP (XCDR (XCDR (height
))))
19649 total_height
= XCAR (XCDR (height
));
19650 height
= XCAR (height
);
19652 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
19654 if (it
->override_ascent
>= 0)
19656 it
->ascent
= it
->override_ascent
;
19657 it
->descent
= it
->override_descent
;
19658 boff
= it
->override_boff
;
19662 it
->ascent
= FONT_BASE (font
) + boff
;
19663 it
->descent
= FONT_DESCENT (font
) - boff
;
19666 if (EQ (height
, Qt
))
19668 if (it
->descent
> it
->max_descent
)
19670 it
->ascent
+= it
->descent
- it
->max_descent
;
19671 it
->descent
= it
->max_descent
;
19673 if (it
->ascent
> it
->max_ascent
)
19675 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19676 it
->ascent
= it
->max_ascent
;
19678 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19679 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19680 it
->constrain_row_ascent_descent_p
= 1;
19681 extra_line_spacing
= 0;
19685 Lisp_Object spacing
;
19687 it
->phys_ascent
= it
->ascent
;
19688 it
->phys_descent
= it
->descent
;
19690 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
19691 && face
->box
!= FACE_NO_BOX
19692 && face
->box_line_width
> 0)
19694 it
->ascent
+= face
->box_line_width
;
19695 it
->descent
+= face
->box_line_width
;
19698 && XINT (height
) > it
->ascent
+ it
->descent
)
19699 it
->ascent
= XINT (height
) - it
->descent
;
19701 if (!NILP (total_height
))
19702 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
19705 spacing
= get_line_height_property(it
, Qline_spacing
);
19706 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
19708 if (INTEGERP (spacing
))
19710 extra_line_spacing
= XINT (spacing
);
19711 if (!NILP (total_height
))
19712 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
19716 else if (it
->char_to_display
== '\t')
19718 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
19719 int x
= it
->current_x
+ it
->continuation_lines_width
;
19720 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
19722 /* If the distance from the current position to the next tab
19723 stop is less than a space character width, use the
19724 tab stop after that. */
19725 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
19726 next_tab_x
+= tab_width
;
19728 it
->pixel_width
= next_tab_x
- x
;
19730 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
19731 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19735 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19736 it
->ascent
+ it
->descent
, it
->ascent
);
19741 /* A multi-byte character. Assume that the display width of the
19742 character is the width of the character multiplied by the
19743 width of the font. */
19745 /* If we found a font, this font should give us the right
19746 metrics. If we didn't find a font, use the frame's
19747 default font and calculate the width of the character by
19748 multiplying the width of font by the width of the
19751 pcm
= rif
->per_char_metric (font
, &char2b
,
19752 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
19754 if (font_not_found_p
|| !pcm
)
19756 it
->glyph_not_available_p
= 1;
19757 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
19758 * CHAR_WIDTH (it
->char_to_display
));
19759 it
->phys_ascent
= FONT_BASE (font
) + boff
;
19760 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19764 it
->pixel_width
= pcm
->width
;
19765 it
->phys_ascent
= pcm
->ascent
+ boff
;
19766 it
->phys_descent
= pcm
->descent
- boff
;
19768 && (pcm
->lbearing
< 0
19769 || pcm
->rbearing
> pcm
->width
))
19770 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19773 it
->ascent
= FONT_BASE (font
) + boff
;
19774 it
->descent
= FONT_DESCENT (font
) - boff
;
19775 if (face
->box
!= FACE_NO_BOX
)
19777 int thick
= face
->box_line_width
;
19781 it
->ascent
+= thick
;
19782 it
->descent
+= thick
;
19787 if (it
->start_of_box_run_p
)
19788 it
->pixel_width
+= thick
;
19789 if (it
->end_of_box_run_p
)
19790 it
->pixel_width
+= thick
;
19793 /* If face has an overline, add the height of the overline
19794 (1 pixel) and a 1 pixel margin to the character height. */
19795 if (face
->overline_p
)
19798 take_vertical_position_into_account (it
);
19803 it
->multibyte_p
= saved_multibyte_p
;
19805 else if (it
->what
== IT_COMPOSITION
)
19807 /* Note: A composition is represented as one glyph in the
19808 glyph matrix. There are no padding glyphs. */
19811 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19813 int font_not_found_p
;
19814 struct font_info
*font_info
;
19815 int boff
; /* baseline offset */
19816 struct composition
*cmp
= composition_table
[it
->cmp_id
];
19819 /* Maybe translate single-byte characters to multibyte. */
19820 it
->char_to_display
= it
->c
;
19821 if (unibyte_display_via_language_environment
19824 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19827 /* Get face and font to use. Encode IT->char_to_display. */
19828 pos
= STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
) : IT_CHARPOS (*it
);
19829 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
,
19831 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19832 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19833 &char2b
, it
->multibyte_p
, 0);
19836 /* When no suitable font found, use the default font. */
19837 font_not_found_p
= font
== NULL
;
19838 if (font_not_found_p
)
19840 font
= FRAME_FONT (it
->f
);
19841 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19846 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19847 boff
= font_info
->baseline_offset
;
19848 if (font_info
->vertical_centering
)
19849 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19852 /* There are no padding glyphs, so there is only one glyph to
19853 produce for the composition. Important is that pixel_width,
19854 ascent and descent are the values of what is drawn by
19855 draw_glyphs (i.e. the values of the overall glyphs composed). */
19858 /* If we have not yet calculated pixel size data of glyphs of
19859 the composition for the current face font, calculate them
19860 now. Theoretically, we have to check all fonts for the
19861 glyphs, but that requires much time and memory space. So,
19862 here we check only the font of the first glyph. This leads
19863 to incorrect display, but it's very rare, and C-l (recenter)
19864 can correct the display anyway. */
19865 if (cmp
->glyph_len
== 0)
19867 cmp
->lbearing
= cmp
->rbearing
= 0;
19868 cmp
->pixel_width
= cmp
->ascent
= cmp
->descent
= 0;
19870 else if (cmp
->font
!= (void *) font
)
19872 /* Ascent and descent of the font of the first character of
19873 this composition (adjusted by baseline offset). Ascent
19874 and descent of overall glyphs should not be less than
19875 them respectively. */
19876 int font_ascent
= FONT_BASE (font
) + boff
;
19877 int font_descent
= FONT_DESCENT (font
) - boff
;
19878 int font_height
= FONT_HEIGHT (font
);
19879 /* Bounding box of the overall glyphs. */
19880 int leftmost
, rightmost
, lowest
, highest
;
19881 int lbearing
, rbearing
;
19882 int i
, width
, ascent
, descent
;
19884 cmp
->font
= (void *) font
;
19886 /* Initialize the bounding box. */
19888 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19889 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
19891 width
= pcm
->width
;
19892 ascent
= pcm
->ascent
;
19893 descent
= pcm
->descent
;
19894 lbearing
= pcm
->lbearing
;
19897 rbearing
= pcm
->rbearing
;
19898 if (rbearing
< width
)
19903 width
= FONT_WIDTH (font
);
19904 ascent
= FONT_BASE (font
);
19905 descent
= FONT_DESCENT (font
);
19911 lowest
= - descent
+ boff
;
19912 highest
= ascent
+ boff
;
19916 && font_info
->default_ascent
19917 && CHAR_TABLE_P (Vuse_default_ascent
)
19918 && !NILP (Faref (Vuse_default_ascent
,
19919 make_number (it
->char_to_display
))))
19920 highest
= font_info
->default_ascent
+ boff
;
19922 /* Draw the first glyph at the normal position. It may be
19923 shifted to right later if some other glyphs are drawn at
19925 cmp
->offsets
[0] = 0;
19926 cmp
->offsets
[1] = boff
;
19927 cmp
->lbearing
= lbearing
;
19928 cmp
->rbearing
= rbearing
;
19930 /* Set cmp->offsets for the remaining glyphs. */
19931 for (i
= 1; i
< cmp
->glyph_len
; i
++)
19933 int left
, right
, btm
, top
;
19934 int ch
= COMPOSITION_GLYPH (cmp
, i
);
19935 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
19937 face
= FACE_FROM_ID (it
->f
, face_id
);
19938 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
19939 &char2b
, it
->multibyte_p
, 0);
19943 font
= FRAME_FONT (it
->f
);
19944 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19950 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19951 boff
= font_info
->baseline_offset
;
19952 if (font_info
->vertical_centering
)
19953 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19957 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19958 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
19960 width
= pcm
->width
;
19961 ascent
= pcm
->ascent
;
19962 descent
= pcm
->descent
;
19963 lbearing
= pcm
->lbearing
;
19966 rbearing
= pcm
->rbearing
;
19967 if (rbearing
< width
)
19972 width
= FONT_WIDTH (font
);
19979 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
19981 /* Relative composition with or without
19982 alternate chars. */
19983 left
= (leftmost
+ rightmost
- width
) / 2;
19984 btm
= - descent
+ boff
;
19985 if (font_info
&& font_info
->relative_compose
19986 && (! CHAR_TABLE_P (Vignore_relative_composition
)
19987 || NILP (Faref (Vignore_relative_composition
,
19988 make_number (ch
)))))
19991 if (- descent
>= font_info
->relative_compose
)
19992 /* One extra pixel between two glyphs. */
19994 else if (ascent
<= 0)
19995 /* One extra pixel between two glyphs. */
19996 btm
= lowest
- 1 - ascent
- descent
;
20001 /* A composition rule is specified by an integer
20002 value that encodes global and new reference
20003 points (GREF and NREF). GREF and NREF are
20004 specified by numbers as below:
20006 0---1---2 -- ascent
20010 9--10--11 -- center
20012 ---3---4---5--- baseline
20014 6---7---8 -- descent
20016 int rule
= COMPOSITION_RULE (cmp
, i
);
20017 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
20019 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
20020 grefx
= gref
% 3, nrefx
= nref
% 3;
20021 grefy
= gref
/ 3, nrefy
= nref
/ 3;
20023 xoff
= font_height
* (xoff
- 128) / 256;
20025 yoff
= font_height
* (yoff
- 128) / 256;
20028 + grefx
* (rightmost
- leftmost
) / 2
20029 - nrefx
* width
/ 2
20032 btm
= ((grefy
== 0 ? highest
20034 : grefy
== 2 ? lowest
20035 : (highest
+ lowest
) / 2)
20036 - (nrefy
== 0 ? ascent
+ descent
20037 : nrefy
== 1 ? descent
- boff
20039 : (ascent
+ descent
) / 2)
20043 cmp
->offsets
[i
* 2] = left
;
20044 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
20046 /* Update the bounding box of the overall glyphs. */
20049 right
= left
+ width
;
20050 if (left
< leftmost
)
20052 if (right
> rightmost
)
20055 top
= btm
+ descent
+ ascent
;
20061 if (cmp
->lbearing
> left
+ lbearing
)
20062 cmp
->lbearing
= left
+ lbearing
;
20063 if (cmp
->rbearing
< left
+ rbearing
)
20064 cmp
->rbearing
= left
+ rbearing
;
20067 /* If there are glyphs whose x-offsets are negative,
20068 shift all glyphs to the right and make all x-offsets
20072 for (i
= 0; i
< cmp
->glyph_len
; i
++)
20073 cmp
->offsets
[i
* 2] -= leftmost
;
20074 rightmost
-= leftmost
;
20075 cmp
->lbearing
-= leftmost
;
20076 cmp
->rbearing
-= leftmost
;
20079 cmp
->pixel_width
= rightmost
;
20080 cmp
->ascent
= highest
;
20081 cmp
->descent
= - lowest
;
20082 if (cmp
->ascent
< font_ascent
)
20083 cmp
->ascent
= font_ascent
;
20084 if (cmp
->descent
< font_descent
)
20085 cmp
->descent
= font_descent
;
20089 && (cmp
->lbearing
< 0
20090 || cmp
->rbearing
> cmp
->pixel_width
))
20091 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20093 it
->pixel_width
= cmp
->pixel_width
;
20094 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
20095 it
->descent
= it
->phys_descent
= cmp
->descent
;
20097 if (face
->box
!= FACE_NO_BOX
)
20099 int thick
= face
->box_line_width
;
20103 it
->ascent
+= thick
;
20104 it
->descent
+= thick
;
20109 if (it
->start_of_box_run_p
)
20110 it
->pixel_width
+= thick
;
20111 if (it
->end_of_box_run_p
)
20112 it
->pixel_width
+= thick
;
20115 /* If face has an overline, add the height of the overline
20116 (1 pixel) and a 1 pixel margin to the character height. */
20117 if (face
->overline_p
)
20120 take_vertical_position_into_account (it
);
20123 append_composite_glyph (it
);
20125 else if (it
->what
== IT_IMAGE
)
20126 produce_image_glyph (it
);
20127 else if (it
->what
== IT_STRETCH
)
20128 produce_stretch_glyph (it
);
20130 /* Accumulate dimensions. Note: can't assume that it->descent > 0
20131 because this isn't true for images with `:ascent 100'. */
20132 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
20133 if (it
->area
== TEXT_AREA
)
20134 it
->current_x
+= it
->pixel_width
;
20136 if (extra_line_spacing
> 0)
20138 it
->descent
+= extra_line_spacing
;
20139 if (extra_line_spacing
> it
->max_extra_line_spacing
)
20140 it
->max_extra_line_spacing
= extra_line_spacing
;
20143 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
20144 it
->max_descent
= max (it
->max_descent
, it
->descent
);
20145 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
20146 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
20150 Output LEN glyphs starting at START at the nominal cursor position.
20151 Advance the nominal cursor over the text. The global variable
20152 updated_window contains the window being updated, updated_row is
20153 the glyph row being updated, and updated_area is the area of that
20154 row being updated. */
20157 x_write_glyphs (start
, len
)
20158 struct glyph
*start
;
20163 xassert (updated_window
&& updated_row
);
20166 /* Write glyphs. */
20168 hpos
= start
- updated_row
->glyphs
[updated_area
];
20169 x
= draw_glyphs (updated_window
, output_cursor
.x
,
20170 updated_row
, updated_area
,
20172 DRAW_NORMAL_TEXT
, 0);
20174 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
20175 if (updated_area
== TEXT_AREA
20176 && updated_window
->phys_cursor_on_p
20177 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
20178 && updated_window
->phys_cursor
.hpos
>= hpos
20179 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
20180 updated_window
->phys_cursor_on_p
= 0;
20184 /* Advance the output cursor. */
20185 output_cursor
.hpos
+= len
;
20186 output_cursor
.x
= x
;
20191 Insert LEN glyphs from START at the nominal cursor position. */
20194 x_insert_glyphs (start
, len
)
20195 struct glyph
*start
;
20200 int line_height
, shift_by_width
, shifted_region_width
;
20201 struct glyph_row
*row
;
20202 struct glyph
*glyph
;
20203 int frame_x
, frame_y
;
20206 xassert (updated_window
&& updated_row
);
20208 w
= updated_window
;
20209 f
= XFRAME (WINDOW_FRAME (w
));
20211 /* Get the height of the line we are in. */
20213 line_height
= row
->height
;
20215 /* Get the width of the glyphs to insert. */
20216 shift_by_width
= 0;
20217 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
20218 shift_by_width
+= glyph
->pixel_width
;
20220 /* Get the width of the region to shift right. */
20221 shifted_region_width
= (window_box_width (w
, updated_area
)
20226 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
20227 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
20229 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
20230 line_height
, shift_by_width
);
20232 /* Write the glyphs. */
20233 hpos
= start
- row
->glyphs
[updated_area
];
20234 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
20236 DRAW_NORMAL_TEXT
, 0);
20238 /* Advance the output cursor. */
20239 output_cursor
.hpos
+= len
;
20240 output_cursor
.x
+= shift_by_width
;
20246 Erase the current text line from the nominal cursor position
20247 (inclusive) to pixel column TO_X (exclusive). The idea is that
20248 everything from TO_X onward is already erased.
20250 TO_X is a pixel position relative to updated_area of
20251 updated_window. TO_X == -1 means clear to the end of this area. */
20254 x_clear_end_of_line (to_x
)
20258 struct window
*w
= updated_window
;
20259 int max_x
, min_y
, max_y
;
20260 int from_x
, from_y
, to_y
;
20262 xassert (updated_window
&& updated_row
);
20263 f
= XFRAME (w
->frame
);
20265 if (updated_row
->full_width_p
)
20266 max_x
= WINDOW_TOTAL_WIDTH (w
);
20268 max_x
= window_box_width (w
, updated_area
);
20269 max_y
= window_text_bottom_y (w
);
20271 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
20272 of window. For TO_X > 0, truncate to end of drawing area. */
20278 to_x
= min (to_x
, max_x
);
20280 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
20282 /* Notice if the cursor will be cleared by this operation. */
20283 if (!updated_row
->full_width_p
)
20284 notice_overwritten_cursor (w
, updated_area
,
20285 output_cursor
.x
, -1,
20287 MATRIX_ROW_BOTTOM_Y (updated_row
));
20289 from_x
= output_cursor
.x
;
20291 /* Translate to frame coordinates. */
20292 if (updated_row
->full_width_p
)
20294 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
20295 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
20299 int area_left
= window_box_left (w
, updated_area
);
20300 from_x
+= area_left
;
20304 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
20305 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
20306 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
20308 /* Prevent inadvertently clearing to end of the X window. */
20309 if (to_x
> from_x
&& to_y
> from_y
)
20312 rif
->clear_frame_area (f
, from_x
, from_y
,
20313 to_x
- from_x
, to_y
- from_y
);
20318 #endif /* HAVE_WINDOW_SYSTEM */
20322 /***********************************************************************
20324 ***********************************************************************/
20326 /* Value is the internal representation of the specified cursor type
20327 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
20328 of the bar cursor. */
20330 static enum text_cursor_kinds
20331 get_specified_cursor_type (arg
, width
)
20335 enum text_cursor_kinds type
;
20340 if (EQ (arg
, Qbox
))
20341 return FILLED_BOX_CURSOR
;
20343 if (EQ (arg
, Qhollow
))
20344 return HOLLOW_BOX_CURSOR
;
20346 if (EQ (arg
, Qbar
))
20353 && EQ (XCAR (arg
), Qbar
)
20354 && INTEGERP (XCDR (arg
))
20355 && XINT (XCDR (arg
)) >= 0)
20357 *width
= XINT (XCDR (arg
));
20361 if (EQ (arg
, Qhbar
))
20364 return HBAR_CURSOR
;
20368 && EQ (XCAR (arg
), Qhbar
)
20369 && INTEGERP (XCDR (arg
))
20370 && XINT (XCDR (arg
)) >= 0)
20372 *width
= XINT (XCDR (arg
));
20373 return HBAR_CURSOR
;
20376 /* Treat anything unknown as "hollow box cursor".
20377 It was bad to signal an error; people have trouble fixing
20378 .Xdefaults with Emacs, when it has something bad in it. */
20379 type
= HOLLOW_BOX_CURSOR
;
20384 /* Set the default cursor types for specified frame. */
20386 set_frame_cursor_types (f
, arg
)
20393 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
20394 FRAME_CURSOR_WIDTH (f
) = width
;
20396 /* By default, set up the blink-off state depending on the on-state. */
20398 tem
= Fassoc (arg
, Vblink_cursor_alist
);
20401 FRAME_BLINK_OFF_CURSOR (f
)
20402 = get_specified_cursor_type (XCDR (tem
), &width
);
20403 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
20406 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
20410 /* Return the cursor we want to be displayed in window W. Return
20411 width of bar/hbar cursor through WIDTH arg. Return with
20412 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
20413 (i.e. if the `system caret' should track this cursor).
20415 In a mini-buffer window, we want the cursor only to appear if we
20416 are reading input from this window. For the selected window, we
20417 want the cursor type given by the frame parameter or buffer local
20418 setting of cursor-type. If explicitly marked off, draw no cursor.
20419 In all other cases, we want a hollow box cursor. */
20421 static enum text_cursor_kinds
20422 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
20424 struct glyph
*glyph
;
20426 int *active_cursor
;
20428 struct frame
*f
= XFRAME (w
->frame
);
20429 struct buffer
*b
= XBUFFER (w
->buffer
);
20430 int cursor_type
= DEFAULT_CURSOR
;
20431 Lisp_Object alt_cursor
;
20432 int non_selected
= 0;
20434 *active_cursor
= 1;
20437 if (cursor_in_echo_area
20438 && FRAME_HAS_MINIBUF_P (f
)
20439 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
20441 if (w
== XWINDOW (echo_area_window
))
20443 *width
= FRAME_CURSOR_WIDTH (f
);
20444 return FRAME_DESIRED_CURSOR (f
);
20447 *active_cursor
= 0;
20451 /* Nonselected window or nonselected frame. */
20452 else if (w
!= XWINDOW (f
->selected_window
)
20453 #ifdef HAVE_WINDOW_SYSTEM
20454 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
20458 *active_cursor
= 0;
20460 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
20466 /* Never display a cursor in a window in which cursor-type is nil. */
20467 if (NILP (b
->cursor_type
))
20470 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
20473 alt_cursor
= XBUFFER (w
->buffer
)->cursor_in_non_selected_windows
;
20474 return get_specified_cursor_type (alt_cursor
, width
);
20477 /* Get the normal cursor type for this window. */
20478 if (EQ (b
->cursor_type
, Qt
))
20480 cursor_type
= FRAME_DESIRED_CURSOR (f
);
20481 *width
= FRAME_CURSOR_WIDTH (f
);
20484 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
20486 /* Use normal cursor if not blinked off. */
20487 if (!w
->cursor_off_p
)
20489 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
20490 if (cursor_type
== FILLED_BOX_CURSOR
)
20491 cursor_type
= HOLLOW_BOX_CURSOR
;
20493 return cursor_type
;
20496 /* Cursor is blinked off, so determine how to "toggle" it. */
20498 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
20499 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
20500 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
20502 /* Then see if frame has specified a specific blink off cursor type. */
20503 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
20505 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
20506 return FRAME_BLINK_OFF_CURSOR (f
);
20510 /* Some people liked having a permanently visible blinking cursor,
20511 while others had very strong opinions against it. So it was
20512 decided to remove it. KFS 2003-09-03 */
20514 /* Finally perform built-in cursor blinking:
20515 filled box <-> hollow box
20516 wide [h]bar <-> narrow [h]bar
20517 narrow [h]bar <-> no cursor
20518 other type <-> no cursor */
20520 if (cursor_type
== FILLED_BOX_CURSOR
)
20521 return HOLLOW_BOX_CURSOR
;
20523 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
20526 return cursor_type
;
20534 #ifdef HAVE_WINDOW_SYSTEM
20536 /* Notice when the text cursor of window W has been completely
20537 overwritten by a drawing operation that outputs glyphs in AREA
20538 starting at X0 and ending at X1 in the line starting at Y0 and
20539 ending at Y1. X coordinates are area-relative. X1 < 0 means all
20540 the rest of the line after X0 has been written. Y coordinates
20541 are window-relative. */
20544 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
20546 enum glyph_row_area area
;
20547 int x0
, y0
, x1
, y1
;
20549 int cx0
, cx1
, cy0
, cy1
;
20550 struct glyph_row
*row
;
20552 if (!w
->phys_cursor_on_p
)
20554 if (area
!= TEXT_AREA
)
20557 if (w
->phys_cursor
.vpos
< 0
20558 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
20559 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
20560 !(row
->enabled_p
&& row
->displays_text_p
)))
20563 if (row
->cursor_in_fringe_p
)
20565 row
->cursor_in_fringe_p
= 0;
20566 draw_fringe_bitmap (w
, row
, 0);
20567 w
->phys_cursor_on_p
= 0;
20571 cx0
= w
->phys_cursor
.x
;
20572 cx1
= cx0
+ w
->phys_cursor_width
;
20573 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
20576 /* The cursor image will be completely removed from the
20577 screen if the output area intersects the cursor area in
20578 y-direction. When we draw in [y0 y1[, and some part of
20579 the cursor is at y < y0, that part must have been drawn
20580 before. When scrolling, the cursor is erased before
20581 actually scrolling, so we don't come here. When not
20582 scrolling, the rows above the old cursor row must have
20583 changed, and in this case these rows must have written
20584 over the cursor image.
20586 Likewise if part of the cursor is below y1, with the
20587 exception of the cursor being in the first blank row at
20588 the buffer and window end because update_text_area
20589 doesn't draw that row. (Except when it does, but
20590 that's handled in update_text_area.) */
20592 cy0
= w
->phys_cursor
.y
;
20593 cy1
= cy0
+ w
->phys_cursor_height
;
20594 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
20597 w
->phys_cursor_on_p
= 0;
20600 #endif /* HAVE_WINDOW_SYSTEM */
20603 /************************************************************************
20605 ************************************************************************/
20607 #ifdef HAVE_WINDOW_SYSTEM
20610 Fix the display of area AREA of overlapping row ROW in window W. */
20613 x_fix_overlapping_area (w
, row
, area
)
20615 struct glyph_row
*row
;
20616 enum glyph_row_area area
;
20623 for (i
= 0; i
< row
->used
[area
];)
20625 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
20627 int start
= i
, start_x
= x
;
20631 x
+= row
->glyphs
[area
][i
].pixel_width
;
20634 while (i
< row
->used
[area
]
20635 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
20637 draw_glyphs (w
, start_x
, row
, area
,
20639 DRAW_NORMAL_TEXT
, 1);
20643 x
+= row
->glyphs
[area
][i
].pixel_width
;
20653 Draw the cursor glyph of window W in glyph row ROW. See the
20654 comment of draw_glyphs for the meaning of HL. */
20657 draw_phys_cursor_glyph (w
, row
, hl
)
20659 struct glyph_row
*row
;
20660 enum draw_glyphs_face hl
;
20662 /* If cursor hpos is out of bounds, don't draw garbage. This can
20663 happen in mini-buffer windows when switching between echo area
20664 glyphs and mini-buffer. */
20665 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
20667 int on_p
= w
->phys_cursor_on_p
;
20669 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
20670 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
20672 w
->phys_cursor_on_p
= on_p
;
20674 if (hl
== DRAW_CURSOR
)
20675 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
20676 /* When we erase the cursor, and ROW is overlapped by other
20677 rows, make sure that these overlapping parts of other rows
20679 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
20681 if (row
> w
->current_matrix
->rows
20682 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
20683 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
20685 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
20686 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
20687 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
20694 Erase the image of a cursor of window W from the screen. */
20697 erase_phys_cursor (w
)
20700 struct frame
*f
= XFRAME (w
->frame
);
20701 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20702 int hpos
= w
->phys_cursor
.hpos
;
20703 int vpos
= w
->phys_cursor
.vpos
;
20704 int mouse_face_here_p
= 0;
20705 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
20706 struct glyph_row
*cursor_row
;
20707 struct glyph
*cursor_glyph
;
20708 enum draw_glyphs_face hl
;
20710 /* No cursor displayed or row invalidated => nothing to do on the
20712 if (w
->phys_cursor_type
== NO_CURSOR
)
20713 goto mark_cursor_off
;
20715 /* VPOS >= active_glyphs->nrows means that window has been resized.
20716 Don't bother to erase the cursor. */
20717 if (vpos
>= active_glyphs
->nrows
)
20718 goto mark_cursor_off
;
20720 /* If row containing cursor is marked invalid, there is nothing we
20722 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
20723 if (!cursor_row
->enabled_p
)
20724 goto mark_cursor_off
;
20726 /* If line spacing is > 0, old cursor may only be partially visible in
20727 window after split-window. So adjust visible height. */
20728 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
20729 window_text_bottom_y (w
) - cursor_row
->y
);
20731 /* If row is completely invisible, don't attempt to delete a cursor which
20732 isn't there. This can happen if cursor is at top of a window, and
20733 we switch to a buffer with a header line in that window. */
20734 if (cursor_row
->visible_height
<= 0)
20735 goto mark_cursor_off
;
20737 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
20738 if (cursor_row
->cursor_in_fringe_p
)
20740 cursor_row
->cursor_in_fringe_p
= 0;
20741 draw_fringe_bitmap (w
, cursor_row
, 0);
20742 goto mark_cursor_off
;
20745 /* This can happen when the new row is shorter than the old one.
20746 In this case, either draw_glyphs or clear_end_of_line
20747 should have cleared the cursor. Note that we wouldn't be
20748 able to erase the cursor in this case because we don't have a
20749 cursor glyph at hand. */
20750 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
20751 goto mark_cursor_off
;
20753 /* If the cursor is in the mouse face area, redisplay that when
20754 we clear the cursor. */
20755 if (! NILP (dpyinfo
->mouse_face_window
)
20756 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
20757 && (vpos
> dpyinfo
->mouse_face_beg_row
20758 || (vpos
== dpyinfo
->mouse_face_beg_row
20759 && hpos
>= dpyinfo
->mouse_face_beg_col
))
20760 && (vpos
< dpyinfo
->mouse_face_end_row
20761 || (vpos
== dpyinfo
->mouse_face_end_row
20762 && hpos
< dpyinfo
->mouse_face_end_col
))
20763 /* Don't redraw the cursor's spot in mouse face if it is at the
20764 end of a line (on a newline). The cursor appears there, but
20765 mouse highlighting does not. */
20766 && cursor_row
->used
[TEXT_AREA
] > hpos
)
20767 mouse_face_here_p
= 1;
20769 /* Maybe clear the display under the cursor. */
20770 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
20773 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
20776 cursor_glyph
= get_phys_cursor_glyph (w
);
20777 if (cursor_glyph
== NULL
)
20778 goto mark_cursor_off
;
20780 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
20781 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
20782 width
= min (cursor_glyph
->pixel_width
,
20783 window_box_width (w
, TEXT_AREA
) - w
->phys_cursor
.x
);
20785 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
20788 /* Erase the cursor by redrawing the character underneath it. */
20789 if (mouse_face_here_p
)
20790 hl
= DRAW_MOUSE_FACE
;
20792 hl
= DRAW_NORMAL_TEXT
;
20793 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
20796 w
->phys_cursor_on_p
= 0;
20797 w
->phys_cursor_type
= NO_CURSOR
;
20802 Display or clear cursor of window W. If ON is zero, clear the
20803 cursor. If it is non-zero, display the cursor. If ON is nonzero,
20804 where to put the cursor is specified by HPOS, VPOS, X and Y. */
20807 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
20809 int on
, hpos
, vpos
, x
, y
;
20811 struct frame
*f
= XFRAME (w
->frame
);
20812 int new_cursor_type
;
20813 int new_cursor_width
;
20815 struct glyph_row
*glyph_row
;
20816 struct glyph
*glyph
;
20818 /* This is pointless on invisible frames, and dangerous on garbaged
20819 windows and frames; in the latter case, the frame or window may
20820 be in the midst of changing its size, and x and y may be off the
20822 if (! FRAME_VISIBLE_P (f
)
20823 || FRAME_GARBAGED_P (f
)
20824 || vpos
>= w
->current_matrix
->nrows
20825 || hpos
>= w
->current_matrix
->matrix_w
)
20828 /* If cursor is off and we want it off, return quickly. */
20829 if (!on
&& !w
->phys_cursor_on_p
)
20832 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
20833 /* If cursor row is not enabled, we don't really know where to
20834 display the cursor. */
20835 if (!glyph_row
->enabled_p
)
20837 w
->phys_cursor_on_p
= 0;
20842 if (!glyph_row
->exact_window_width_line_p
20843 || hpos
< glyph_row
->used
[TEXT_AREA
])
20844 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
20846 xassert (interrupt_input_blocked
);
20848 /* Set new_cursor_type to the cursor we want to be displayed. */
20849 new_cursor_type
= get_window_cursor_type (w
, glyph
,
20850 &new_cursor_width
, &active_cursor
);
20852 /* If cursor is currently being shown and we don't want it to be or
20853 it is in the wrong place, or the cursor type is not what we want,
20855 if (w
->phys_cursor_on_p
20857 || w
->phys_cursor
.x
!= x
20858 || w
->phys_cursor
.y
!= y
20859 || new_cursor_type
!= w
->phys_cursor_type
20860 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
20861 && new_cursor_width
!= w
->phys_cursor_width
)))
20862 erase_phys_cursor (w
);
20864 /* Don't check phys_cursor_on_p here because that flag is only set
20865 to zero in some cases where we know that the cursor has been
20866 completely erased, to avoid the extra work of erasing the cursor
20867 twice. In other words, phys_cursor_on_p can be 1 and the cursor
20868 still not be visible, or it has only been partly erased. */
20871 w
->phys_cursor_ascent
= glyph_row
->ascent
;
20872 w
->phys_cursor_height
= glyph_row
->height
;
20874 /* Set phys_cursor_.* before x_draw_.* is called because some
20875 of them may need the information. */
20876 w
->phys_cursor
.x
= x
;
20877 w
->phys_cursor
.y
= glyph_row
->y
;
20878 w
->phys_cursor
.hpos
= hpos
;
20879 w
->phys_cursor
.vpos
= vpos
;
20882 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
20883 new_cursor_type
, new_cursor_width
,
20884 on
, active_cursor
);
20888 /* Switch the display of W's cursor on or off, according to the value
20892 update_window_cursor (w
, on
)
20896 /* Don't update cursor in windows whose frame is in the process
20897 of being deleted. */
20898 if (w
->current_matrix
)
20901 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20902 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20908 /* Call update_window_cursor with parameter ON_P on all leaf windows
20909 in the window tree rooted at W. */
20912 update_cursor_in_window_tree (w
, on_p
)
20918 if (!NILP (w
->hchild
))
20919 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
20920 else if (!NILP (w
->vchild
))
20921 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
20923 update_window_cursor (w
, on_p
);
20925 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
20931 Display the cursor on window W, or clear it, according to ON_P.
20932 Don't change the cursor's position. */
20935 x_update_cursor (f
, on_p
)
20939 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
20944 Clear the cursor of window W to background color, and mark the
20945 cursor as not shown. This is used when the text where the cursor
20946 is is about to be rewritten. */
20952 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
20953 update_window_cursor (w
, 0);
20958 Display the active region described by mouse_face_* according to DRAW. */
20961 show_mouse_face (dpyinfo
, draw
)
20962 Display_Info
*dpyinfo
;
20963 enum draw_glyphs_face draw
;
20965 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
20966 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20968 if (/* If window is in the process of being destroyed, don't bother
20970 w
->current_matrix
!= NULL
20971 /* Don't update mouse highlight if hidden */
20972 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
20973 /* Recognize when we are called to operate on rows that don't exist
20974 anymore. This can happen when a window is split. */
20975 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
20977 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
20978 struct glyph_row
*row
, *first
, *last
;
20980 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20981 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20983 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
20985 int start_hpos
, end_hpos
, start_x
;
20987 /* For all but the first row, the highlight starts at column 0. */
20990 start_hpos
= dpyinfo
->mouse_face_beg_col
;
20991 start_x
= dpyinfo
->mouse_face_beg_x
;
21000 end_hpos
= dpyinfo
->mouse_face_end_col
;
21002 end_hpos
= row
->used
[TEXT_AREA
];
21004 if (end_hpos
> start_hpos
)
21006 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
21007 start_hpos
, end_hpos
,
21011 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
21015 /* When we've written over the cursor, arrange for it to
21016 be displayed again. */
21017 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
21020 display_and_set_cursor (w
, 1,
21021 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21022 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21027 /* Change the mouse cursor. */
21028 if (draw
== DRAW_NORMAL_TEXT
)
21029 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
21030 else if (draw
== DRAW_MOUSE_FACE
)
21031 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
21033 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
21037 Clear out the mouse-highlighted active region.
21038 Redraw it un-highlighted first. Value is non-zero if mouse
21039 face was actually drawn unhighlighted. */
21042 clear_mouse_face (dpyinfo
)
21043 Display_Info
*dpyinfo
;
21047 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
21049 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
21053 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21054 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21055 dpyinfo
->mouse_face_window
= Qnil
;
21056 dpyinfo
->mouse_face_overlay
= Qnil
;
21062 Non-zero if physical cursor of window W is within mouse face. */
21065 cursor_in_mouse_face_p (w
)
21068 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21069 int in_mouse_face
= 0;
21071 if (WINDOWP (dpyinfo
->mouse_face_window
)
21072 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
21074 int hpos
= w
->phys_cursor
.hpos
;
21075 int vpos
= w
->phys_cursor
.vpos
;
21077 if (vpos
>= dpyinfo
->mouse_face_beg_row
21078 && vpos
<= dpyinfo
->mouse_face_end_row
21079 && (vpos
> dpyinfo
->mouse_face_beg_row
21080 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21081 && (vpos
< dpyinfo
->mouse_face_end_row
21082 || hpos
< dpyinfo
->mouse_face_end_col
21083 || dpyinfo
->mouse_face_past_end
))
21087 return in_mouse_face
;
21093 /* Find the glyph matrix position of buffer position CHARPOS in window
21094 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
21095 current glyphs must be up to date. If CHARPOS is above window
21096 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
21097 of last line in W. In the row containing CHARPOS, stop before glyphs
21098 having STOP as object. */
21100 #if 1 /* This is a version of fast_find_position that's more correct
21101 in the presence of hscrolling, for example. I didn't install
21102 it right away because the problem fixed is minor, it failed
21103 in 20.x as well, and I think it's too risky to install
21104 so near the release of 21.1. 2001-09-25 gerd. */
21107 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
21110 int *hpos
, *vpos
, *x
, *y
;
21113 struct glyph_row
*row
, *first
;
21114 struct glyph
*glyph
, *end
;
21117 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21118 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
21123 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
21127 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
21130 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
21134 /* If whole rows or last part of a row came from a display overlay,
21135 row_containing_pos will skip over such rows because their end pos
21136 equals the start pos of the overlay or interval.
21138 Move back if we have a STOP object and previous row's
21139 end glyph came from STOP. */
21142 struct glyph_row
*prev
;
21143 while ((prev
= row
- 1, prev
>= first
)
21144 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
21145 && prev
->used
[TEXT_AREA
] > 0)
21147 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
21148 glyph
= beg
+ prev
->used
[TEXT_AREA
];
21149 while (--glyph
>= beg
21150 && INTEGERP (glyph
->object
));
21152 || !EQ (stop
, glyph
->object
))
21160 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21162 glyph
= row
->glyphs
[TEXT_AREA
];
21163 end
= glyph
+ row
->used
[TEXT_AREA
];
21165 /* Skip over glyphs not having an object at the start of the row.
21166 These are special glyphs like truncation marks on terminal
21168 if (row
->displays_text_p
)
21170 && INTEGERP (glyph
->object
)
21171 && !EQ (stop
, glyph
->object
)
21172 && glyph
->charpos
< 0)
21174 *x
+= glyph
->pixel_width
;
21179 && !INTEGERP (glyph
->object
)
21180 && !EQ (stop
, glyph
->object
)
21181 && (!BUFFERP (glyph
->object
)
21182 || glyph
->charpos
< charpos
))
21184 *x
+= glyph
->pixel_width
;
21188 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
21195 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
21198 int *hpos
, *vpos
, *x
, *y
;
21203 int maybe_next_line_p
= 0;
21204 int line_start_position
;
21205 int yb
= window_text_bottom_y (w
);
21206 struct glyph_row
*row
, *best_row
;
21207 int row_vpos
, best_row_vpos
;
21210 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21211 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21213 while (row
->y
< yb
)
21215 if (row
->used
[TEXT_AREA
])
21216 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
21218 line_start_position
= 0;
21220 if (line_start_position
> pos
)
21222 /* If the position sought is the end of the buffer,
21223 don't include the blank lines at the bottom of the window. */
21224 else if (line_start_position
== pos
21225 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
21227 maybe_next_line_p
= 1;
21230 else if (line_start_position
> 0)
21233 best_row_vpos
= row_vpos
;
21236 if (row
->y
+ row
->height
>= yb
)
21243 /* Find the right column within BEST_ROW. */
21245 current_x
= best_row
->x
;
21246 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
21248 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
21249 int charpos
= glyph
->charpos
;
21251 if (BUFFERP (glyph
->object
))
21253 if (charpos
== pos
)
21256 *vpos
= best_row_vpos
;
21261 else if (charpos
> pos
)
21264 else if (EQ (glyph
->object
, stop
))
21269 current_x
+= glyph
->pixel_width
;
21272 /* If we're looking for the end of the buffer,
21273 and we didn't find it in the line we scanned,
21274 use the start of the following line. */
21275 if (maybe_next_line_p
)
21280 current_x
= best_row
->x
;
21283 *vpos
= best_row_vpos
;
21284 *hpos
= lastcol
+ 1;
21293 /* Find the position of the glyph for position POS in OBJECT in
21294 window W's current matrix, and return in *X, *Y the pixel
21295 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
21297 RIGHT_P non-zero means return the position of the right edge of the
21298 glyph, RIGHT_P zero means return the left edge position.
21300 If no glyph for POS exists in the matrix, return the position of
21301 the glyph with the next smaller position that is in the matrix, if
21302 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
21303 exists in the matrix, return the position of the glyph with the
21304 next larger position in OBJECT.
21306 Value is non-zero if a glyph was found. */
21309 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
21312 Lisp_Object object
;
21313 int *hpos
, *vpos
, *x
, *y
;
21316 int yb
= window_text_bottom_y (w
);
21317 struct glyph_row
*r
;
21318 struct glyph
*best_glyph
= NULL
;
21319 struct glyph_row
*best_row
= NULL
;
21322 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21323 r
->enabled_p
&& r
->y
< yb
;
21326 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
21327 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
21330 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
21331 if (EQ (g
->object
, object
))
21333 if (g
->charpos
== pos
)
21340 else if (best_glyph
== NULL
21341 || ((abs (g
->charpos
- pos
)
21342 < abs (best_glyph
->charpos
- pos
))
21345 : g
->charpos
> pos
)))
21359 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
21363 *x
+= best_glyph
->pixel_width
;
21368 *vpos
= best_row
- w
->current_matrix
->rows
;
21371 return best_glyph
!= NULL
;
21375 /* See if position X, Y is within a hot-spot of an image. */
21378 on_hot_spot_p (hot_spot
, x
, y
)
21379 Lisp_Object hot_spot
;
21382 if (!CONSP (hot_spot
))
21385 if (EQ (XCAR (hot_spot
), Qrect
))
21387 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
21388 Lisp_Object rect
= XCDR (hot_spot
);
21392 if (!CONSP (XCAR (rect
)))
21394 if (!CONSP (XCDR (rect
)))
21396 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
21398 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
21400 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
21402 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
21406 else if (EQ (XCAR (hot_spot
), Qcircle
))
21408 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
21409 Lisp_Object circ
= XCDR (hot_spot
);
21410 Lisp_Object lr
, lx0
, ly0
;
21412 && CONSP (XCAR (circ
))
21413 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
21414 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
21415 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
21417 double r
= XFLOATINT (lr
);
21418 double dx
= XINT (lx0
) - x
;
21419 double dy
= XINT (ly0
) - y
;
21420 return (dx
* dx
+ dy
* dy
<= r
* r
);
21423 else if (EQ (XCAR (hot_spot
), Qpoly
))
21425 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
21426 if (VECTORP (XCDR (hot_spot
)))
21428 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
21429 Lisp_Object
*poly
= v
->contents
;
21433 Lisp_Object lx
, ly
;
21436 /* Need an even number of coordinates, and at least 3 edges. */
21437 if (n
< 6 || n
& 1)
21440 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
21441 If count is odd, we are inside polygon. Pixels on edges
21442 may or may not be included depending on actual geometry of the
21444 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
21445 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
21447 x0
= XINT (lx
), y0
= XINT (ly
);
21448 for (i
= 0; i
< n
; i
+= 2)
21450 int x1
= x0
, y1
= y0
;
21451 if ((lx
= poly
[i
], !INTEGERP (lx
))
21452 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
21454 x0
= XINT (lx
), y0
= XINT (ly
);
21456 /* Does this segment cross the X line? */
21464 if (y
> y0
&& y
> y1
)
21466 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
21472 /* If we don't understand the format, pretend we're not in the hot-spot. */
21477 find_hot_spot (map
, x
, y
)
21481 while (CONSP (map
))
21483 if (CONSP (XCAR (map
))
21484 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
21492 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
21494 doc
: /* Lookup in image map MAP coordinates X and Y.
21495 An image map is an alist where each element has the format (AREA ID PLIST).
21496 An AREA is specified as either a rectangle, a circle, or a polygon:
21497 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
21498 pixel coordinates of the upper left and bottom right corners.
21499 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
21500 and the radius of the circle; r may be a float or integer.
21501 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
21502 vector describes one corner in the polygon.
21503 Returns the alist element for the first matching AREA in MAP. */)
21514 return find_hot_spot (map
, XINT (x
), XINT (y
));
21518 /* Display frame CURSOR, optionally using shape defined by POINTER. */
21520 define_frame_cursor1 (f
, cursor
, pointer
)
21523 Lisp_Object pointer
;
21525 /* Do not change cursor shape while dragging mouse. */
21526 if (!NILP (do_mouse_tracking
))
21529 if (!NILP (pointer
))
21531 if (EQ (pointer
, Qarrow
))
21532 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21533 else if (EQ (pointer
, Qhand
))
21534 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
21535 else if (EQ (pointer
, Qtext
))
21536 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21537 else if (EQ (pointer
, intern ("hdrag")))
21538 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21539 #ifdef HAVE_X_WINDOWS
21540 else if (EQ (pointer
, intern ("vdrag")))
21541 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
21543 else if (EQ (pointer
, intern ("hourglass")))
21544 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
21545 else if (EQ (pointer
, Qmodeline
))
21546 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
21548 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21551 if (cursor
!= No_Cursor
)
21552 rif
->define_frame_cursor (f
, cursor
);
21555 /* Take proper action when mouse has moved to the mode or header line
21556 or marginal area AREA of window W, x-position X and y-position Y.
21557 X is relative to the start of the text display area of W, so the
21558 width of bitmap areas and scroll bars must be subtracted to get a
21559 position relative to the start of the mode line. */
21562 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
21563 Lisp_Object window
;
21565 enum window_part area
;
21567 struct window
*w
= XWINDOW (window
);
21568 struct frame
*f
= XFRAME (w
->frame
);
21569 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21570 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21571 Lisp_Object pointer
= Qnil
;
21572 int charpos
, dx
, dy
, width
, height
;
21573 Lisp_Object string
, object
= Qnil
;
21574 Lisp_Object pos
, help
;
21576 Lisp_Object mouse_face
;
21577 int original_x_pixel
= x
;
21578 struct glyph
* glyph
= NULL
;
21579 struct glyph_row
*row
;
21581 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
21586 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
21587 &object
, &dx
, &dy
, &width
, &height
);
21589 row
= (area
== ON_MODE_LINE
21590 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
21591 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
21594 if (row
->mode_line_p
&& row
->enabled_p
)
21596 glyph
= row
->glyphs
[TEXT_AREA
];
21597 end
= glyph
+ row
->used
[TEXT_AREA
];
21599 for (x0
= original_x_pixel
;
21600 glyph
< end
&& x0
>= glyph
->pixel_width
;
21602 x0
-= glyph
->pixel_width
;
21610 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
21611 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
21612 &object
, &dx
, &dy
, &width
, &height
);
21617 if (IMAGEP (object
))
21619 Lisp_Object image_map
, hotspot
;
21620 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
21622 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
21624 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21626 Lisp_Object area_id
, plist
;
21628 area_id
= XCAR (hotspot
);
21629 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21630 If so, we could look for mouse-enter, mouse-leave
21631 properties in PLIST (and do something...). */
21632 hotspot
= XCDR (hotspot
);
21633 if (CONSP (hotspot
)
21634 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21636 pointer
= Fplist_get (plist
, Qpointer
);
21637 if (NILP (pointer
))
21639 help
= Fplist_get (plist
, Qhelp_echo
);
21642 help_echo_string
= help
;
21643 /* Is this correct? ++kfs */
21644 XSETWINDOW (help_echo_window
, w
);
21645 help_echo_object
= w
->buffer
;
21646 help_echo_pos
= charpos
;
21650 if (NILP (pointer
))
21651 pointer
= Fplist_get (XCDR (object
), QCpointer
);
21654 if (STRINGP (string
))
21656 pos
= make_number (charpos
);
21657 /* If we're on a string with `help-echo' text property, arrange
21658 for the help to be displayed. This is done by setting the
21659 global variable help_echo_string to the help string. */
21662 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
21665 help_echo_string
= help
;
21666 XSETWINDOW (help_echo_window
, w
);
21667 help_echo_object
= string
;
21668 help_echo_pos
= charpos
;
21672 if (NILP (pointer
))
21673 pointer
= Fget_text_property (pos
, Qpointer
, string
);
21675 /* Change the mouse pointer according to what is under X/Y. */
21676 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
21679 map
= Fget_text_property (pos
, Qlocal_map
, string
);
21680 if (!KEYMAPP (map
))
21681 map
= Fget_text_property (pos
, Qkeymap
, string
);
21682 if (!KEYMAPP (map
))
21683 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
21686 /* Change the mouse face according to what is under X/Y. */
21687 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
21688 if (!NILP (mouse_face
)
21689 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
21694 struct glyph
* tmp_glyph
;
21698 int total_pixel_width
;
21703 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
21704 Qmouse_face
, string
, Qnil
);
21706 b
= make_number (0);
21708 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
21710 e
= make_number (SCHARS (string
));
21712 /* Calculate the position(glyph position: GPOS) of GLYPH in
21713 displayed string. GPOS is different from CHARPOS.
21715 CHARPOS is the position of glyph in internal string
21716 object. A mode line string format has structures which
21717 is converted to a flatten by emacs lisp interpreter.
21718 The internal string is an element of the structures.
21719 The displayed string is the flatten string. */
21720 for (tmp_glyph
= glyph
- 1, gpos
= 0;
21721 tmp_glyph
->charpos
>= XINT (b
);
21722 tmp_glyph
--, gpos
++)
21724 if (!EQ (tmp_glyph
->object
, glyph
->object
))
21728 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
21729 displayed string holding GLYPH.
21731 GSEQ_LENGTH is different from SCHARS (STRING).
21732 SCHARS (STRING) returns the length of the internal string. */
21733 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
21734 tmp_glyph
->charpos
< XINT (e
);
21735 tmp_glyph
++, gseq_length
++)
21737 if (!EQ (tmp_glyph
->object
, glyph
->object
))
21741 total_pixel_width
= 0;
21742 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
21743 total_pixel_width
+= tmp_glyph
->pixel_width
;
21745 /* Pre calculation of re-rendering position */
21747 hpos
= (area
== ON_MODE_LINE
21748 ? (w
->current_matrix
)->nrows
- 1
21751 /* If the re-rendering position is included in the last
21752 re-rendering area, we should do nothing. */
21753 if ( EQ (window
, dpyinfo
->mouse_face_window
)
21754 && dpyinfo
->mouse_face_beg_col
<= vpos
21755 && vpos
< dpyinfo
->mouse_face_end_col
21756 && dpyinfo
->mouse_face_beg_row
== hpos
)
21759 if (clear_mouse_face (dpyinfo
))
21760 cursor
= No_Cursor
;
21762 dpyinfo
->mouse_face_beg_col
= vpos
;
21763 dpyinfo
->mouse_face_beg_row
= hpos
;
21765 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
21766 dpyinfo
->mouse_face_beg_y
= 0;
21768 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
21769 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
21771 dpyinfo
->mouse_face_end_x
= 0;
21772 dpyinfo
->mouse_face_end_y
= 0;
21774 dpyinfo
->mouse_face_past_end
= 0;
21775 dpyinfo
->mouse_face_window
= window
;
21777 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
21780 glyph
->face_id
, 1);
21781 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21783 if (NILP (pointer
))
21786 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
21787 clear_mouse_face (dpyinfo
);
21789 define_frame_cursor1 (f
, cursor
, pointer
);
21794 Take proper action when the mouse has moved to position X, Y on
21795 frame F as regards highlighting characters that have mouse-face
21796 properties. Also de-highlighting chars where the mouse was before.
21797 X and Y can be negative or out of range. */
21800 note_mouse_highlight (f
, x
, y
)
21804 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21805 enum window_part part
;
21806 Lisp_Object window
;
21808 Cursor cursor
= No_Cursor
;
21809 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
21812 /* When a menu is active, don't highlight because this looks odd. */
21813 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
21814 if (popup_activated ())
21818 if (NILP (Vmouse_highlight
)
21819 || !f
->glyphs_initialized_p
)
21822 dpyinfo
->mouse_face_mouse_x
= x
;
21823 dpyinfo
->mouse_face_mouse_y
= y
;
21824 dpyinfo
->mouse_face_mouse_frame
= f
;
21826 if (dpyinfo
->mouse_face_defer
)
21829 if (gc_in_progress
)
21831 dpyinfo
->mouse_face_deferred_gc
= 1;
21835 /* Which window is that in? */
21836 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
21838 /* If we were displaying active text in another window, clear that.
21839 Also clear if we move out of text area in same window. */
21840 if (! EQ (window
, dpyinfo
->mouse_face_window
)
21841 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
21842 && !NILP (dpyinfo
->mouse_face_window
)))
21843 clear_mouse_face (dpyinfo
);
21845 /* Not on a window -> return. */
21846 if (!WINDOWP (window
))
21849 /* Reset help_echo_string. It will get recomputed below. */
21850 help_echo_string
= Qnil
;
21852 /* Convert to window-relative pixel coordinates. */
21853 w
= XWINDOW (window
);
21854 frame_to_window_pixel_xy (w
, &x
, &y
);
21856 /* Handle tool-bar window differently since it doesn't display a
21858 if (EQ (window
, f
->tool_bar_window
))
21860 note_tool_bar_highlight (f
, x
, y
);
21864 /* Mouse is on the mode, header line or margin? */
21865 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
21866 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
21868 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
21872 if (part
== ON_VERTICAL_BORDER
)
21873 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21874 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
21875 || part
== ON_SCROLL_BAR
)
21876 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21878 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21880 /* Are we in a window whose display is up to date?
21881 And verify the buffer's text has not changed. */
21882 b
= XBUFFER (w
->buffer
);
21883 if (part
== ON_TEXT
21884 && EQ (w
->window_end_valid
, w
->buffer
)
21885 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
21886 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
21888 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
21889 struct glyph
*glyph
;
21890 Lisp_Object object
;
21891 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
21892 Lisp_Object
*overlay_vec
= NULL
;
21894 struct buffer
*obuf
;
21895 int obegv
, ozv
, same_region
;
21897 /* Find the glyph under X/Y. */
21898 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
21900 /* Look for :pointer property on image. */
21901 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21903 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21904 if (img
!= NULL
&& IMAGEP (img
->spec
))
21906 Lisp_Object image_map
, hotspot
;
21907 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
21909 && (hotspot
= find_hot_spot (image_map
,
21910 glyph
->slice
.x
+ dx
,
21911 glyph
->slice
.y
+ dy
),
21913 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21915 Lisp_Object area_id
, plist
;
21917 area_id
= XCAR (hotspot
);
21918 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21919 If so, we could look for mouse-enter, mouse-leave
21920 properties in PLIST (and do something...). */
21921 hotspot
= XCDR (hotspot
);
21922 if (CONSP (hotspot
)
21923 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21925 pointer
= Fplist_get (plist
, Qpointer
);
21926 if (NILP (pointer
))
21928 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
21929 if (!NILP (help_echo_string
))
21931 help_echo_window
= window
;
21932 help_echo_object
= glyph
->object
;
21933 help_echo_pos
= glyph
->charpos
;
21937 if (NILP (pointer
))
21938 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
21942 /* Clear mouse face if X/Y not over text. */
21944 || area
!= TEXT_AREA
21945 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
21947 if (clear_mouse_face (dpyinfo
))
21948 cursor
= No_Cursor
;
21949 if (NILP (pointer
))
21951 if (area
!= TEXT_AREA
)
21952 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21954 pointer
= Vvoid_text_area_pointer
;
21959 pos
= glyph
->charpos
;
21960 object
= glyph
->object
;
21961 if (!STRINGP (object
) && !BUFFERP (object
))
21964 /* If we get an out-of-range value, return now; avoid an error. */
21965 if (BUFFERP (object
) && pos
> BUF_Z (b
))
21968 /* Make the window's buffer temporarily current for
21969 overlays_at and compute_char_face. */
21970 obuf
= current_buffer
;
21971 current_buffer
= b
;
21977 /* Is this char mouse-active or does it have help-echo? */
21978 position
= make_number (pos
);
21980 if (BUFFERP (object
))
21982 /* Put all the overlays we want in a vector in overlay_vec. */
21983 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
21984 /* Sort overlays into increasing priority order. */
21985 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
21990 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
21991 && vpos
>= dpyinfo
->mouse_face_beg_row
21992 && vpos
<= dpyinfo
->mouse_face_end_row
21993 && (vpos
> dpyinfo
->mouse_face_beg_row
21994 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21995 && (vpos
< dpyinfo
->mouse_face_end_row
21996 || hpos
< dpyinfo
->mouse_face_end_col
21997 || dpyinfo
->mouse_face_past_end
));
22000 cursor
= No_Cursor
;
22002 /* Check mouse-face highlighting. */
22004 /* If there exists an overlay with mouse-face overlapping
22005 the one we are currently highlighting, we have to
22006 check if we enter the overlapping overlay, and then
22007 highlight only that. */
22008 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
22009 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
22011 /* Find the highest priority overlay that has a mouse-face
22014 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
22016 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
22017 if (!NILP (mouse_face
))
22018 overlay
= overlay_vec
[i
];
22021 /* If we're actually highlighting the same overlay as
22022 before, there's no need to do that again. */
22023 if (!NILP (overlay
)
22024 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
22025 goto check_help_echo
;
22027 dpyinfo
->mouse_face_overlay
= overlay
;
22029 /* Clear the display of the old active region, if any. */
22030 if (clear_mouse_face (dpyinfo
))
22031 cursor
= No_Cursor
;
22033 /* If no overlay applies, get a text property. */
22034 if (NILP (overlay
))
22035 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
22037 /* Handle the overlay case. */
22038 if (!NILP (overlay
))
22040 /* Find the range of text around this char that
22041 should be active. */
22042 Lisp_Object before
, after
;
22045 before
= Foverlay_start (overlay
);
22046 after
= Foverlay_end (overlay
);
22047 /* Record this as the current active region. */
22048 fast_find_position (w
, XFASTINT (before
),
22049 &dpyinfo
->mouse_face_beg_col
,
22050 &dpyinfo
->mouse_face_beg_row
,
22051 &dpyinfo
->mouse_face_beg_x
,
22052 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22054 dpyinfo
->mouse_face_past_end
22055 = !fast_find_position (w
, XFASTINT (after
),
22056 &dpyinfo
->mouse_face_end_col
,
22057 &dpyinfo
->mouse_face_end_row
,
22058 &dpyinfo
->mouse_face_end_x
,
22059 &dpyinfo
->mouse_face_end_y
, Qnil
);
22060 dpyinfo
->mouse_face_window
= window
;
22062 dpyinfo
->mouse_face_face_id
22063 = face_at_buffer_position (w
, pos
, 0, 0,
22065 !dpyinfo
->mouse_face_hidden
);
22067 /* Display it as active. */
22068 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22069 cursor
= No_Cursor
;
22071 /* Handle the text property case. */
22072 else if (!NILP (mouse_face
) && BUFFERP (object
))
22074 /* Find the range of text around this char that
22075 should be active. */
22076 Lisp_Object before
, after
, beginning
, end
;
22079 beginning
= Fmarker_position (w
->start
);
22080 end
= make_number (BUF_Z (XBUFFER (object
))
22081 - XFASTINT (w
->window_end_pos
));
22083 = Fprevious_single_property_change (make_number (pos
+ 1),
22085 object
, beginning
);
22087 = Fnext_single_property_change (position
, Qmouse_face
,
22090 /* Record this as the current active region. */
22091 fast_find_position (w
, XFASTINT (before
),
22092 &dpyinfo
->mouse_face_beg_col
,
22093 &dpyinfo
->mouse_face_beg_row
,
22094 &dpyinfo
->mouse_face_beg_x
,
22095 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22096 dpyinfo
->mouse_face_past_end
22097 = !fast_find_position (w
, XFASTINT (after
),
22098 &dpyinfo
->mouse_face_end_col
,
22099 &dpyinfo
->mouse_face_end_row
,
22100 &dpyinfo
->mouse_face_end_x
,
22101 &dpyinfo
->mouse_face_end_y
, Qnil
);
22102 dpyinfo
->mouse_face_window
= window
;
22104 if (BUFFERP (object
))
22105 dpyinfo
->mouse_face_face_id
22106 = face_at_buffer_position (w
, pos
, 0, 0,
22108 !dpyinfo
->mouse_face_hidden
);
22110 /* Display it as active. */
22111 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22112 cursor
= No_Cursor
;
22114 else if (!NILP (mouse_face
) && STRINGP (object
))
22119 b
= Fprevious_single_property_change (make_number (pos
+ 1),
22122 e
= Fnext_single_property_change (position
, Qmouse_face
,
22125 b
= make_number (0);
22127 e
= make_number (SCHARS (object
) - 1);
22129 fast_find_string_pos (w
, XINT (b
), object
,
22130 &dpyinfo
->mouse_face_beg_col
,
22131 &dpyinfo
->mouse_face_beg_row
,
22132 &dpyinfo
->mouse_face_beg_x
,
22133 &dpyinfo
->mouse_face_beg_y
, 0);
22134 fast_find_string_pos (w
, XINT (e
), object
,
22135 &dpyinfo
->mouse_face_end_col
,
22136 &dpyinfo
->mouse_face_end_row
,
22137 &dpyinfo
->mouse_face_end_x
,
22138 &dpyinfo
->mouse_face_end_y
, 1);
22139 dpyinfo
->mouse_face_past_end
= 0;
22140 dpyinfo
->mouse_face_window
= window
;
22141 dpyinfo
->mouse_face_face_id
22142 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
22143 glyph
->face_id
, 1);
22144 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22145 cursor
= No_Cursor
;
22147 else if (STRINGP (object
) && NILP (mouse_face
))
22149 /* A string which doesn't have mouse-face, but
22150 the text ``under'' it might have. */
22151 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
22152 int start
= MATRIX_ROW_START_CHARPOS (r
);
22154 pos
= string_buffer_position (w
, object
, start
);
22156 mouse_face
= get_char_property_and_overlay (make_number (pos
),
22160 if (!NILP (mouse_face
) && !NILP (overlay
))
22162 Lisp_Object before
= Foverlay_start (overlay
);
22163 Lisp_Object after
= Foverlay_end (overlay
);
22166 /* Note that we might not be able to find position
22167 BEFORE in the glyph matrix if the overlay is
22168 entirely covered by a `display' property. In
22169 this case, we overshoot. So let's stop in
22170 the glyph matrix before glyphs for OBJECT. */
22171 fast_find_position (w
, XFASTINT (before
),
22172 &dpyinfo
->mouse_face_beg_col
,
22173 &dpyinfo
->mouse_face_beg_row
,
22174 &dpyinfo
->mouse_face_beg_x
,
22175 &dpyinfo
->mouse_face_beg_y
,
22178 dpyinfo
->mouse_face_past_end
22179 = !fast_find_position (w
, XFASTINT (after
),
22180 &dpyinfo
->mouse_face_end_col
,
22181 &dpyinfo
->mouse_face_end_row
,
22182 &dpyinfo
->mouse_face_end_x
,
22183 &dpyinfo
->mouse_face_end_y
,
22185 dpyinfo
->mouse_face_window
= window
;
22186 dpyinfo
->mouse_face_face_id
22187 = face_at_buffer_position (w
, pos
, 0, 0,
22189 !dpyinfo
->mouse_face_hidden
);
22191 /* Display it as active. */
22192 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22193 cursor
= No_Cursor
;
22200 /* Look for a `help-echo' property. */
22201 if (NILP (help_echo_string
)) {
22202 Lisp_Object help
, overlay
;
22204 /* Check overlays first. */
22205 help
= overlay
= Qnil
;
22206 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
22208 overlay
= overlay_vec
[i
];
22209 help
= Foverlay_get (overlay
, Qhelp_echo
);
22214 help_echo_string
= help
;
22215 help_echo_window
= window
;
22216 help_echo_object
= overlay
;
22217 help_echo_pos
= pos
;
22221 Lisp_Object object
= glyph
->object
;
22222 int charpos
= glyph
->charpos
;
22224 /* Try text properties. */
22225 if (STRINGP (object
)
22227 && charpos
< SCHARS (object
))
22229 help
= Fget_text_property (make_number (charpos
),
22230 Qhelp_echo
, object
);
22233 /* If the string itself doesn't specify a help-echo,
22234 see if the buffer text ``under'' it does. */
22235 struct glyph_row
*r
22236 = MATRIX_ROW (w
->current_matrix
, vpos
);
22237 int start
= MATRIX_ROW_START_CHARPOS (r
);
22238 int pos
= string_buffer_position (w
, object
, start
);
22241 help
= Fget_char_property (make_number (pos
),
22242 Qhelp_echo
, w
->buffer
);
22246 object
= w
->buffer
;
22251 else if (BUFFERP (object
)
22254 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
22259 help_echo_string
= help
;
22260 help_echo_window
= window
;
22261 help_echo_object
= object
;
22262 help_echo_pos
= charpos
;
22267 /* Look for a `pointer' property. */
22268 if (NILP (pointer
))
22270 /* Check overlays first. */
22271 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
22272 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
22274 if (NILP (pointer
))
22276 Lisp_Object object
= glyph
->object
;
22277 int charpos
= glyph
->charpos
;
22279 /* Try text properties. */
22280 if (STRINGP (object
)
22282 && charpos
< SCHARS (object
))
22284 pointer
= Fget_text_property (make_number (charpos
),
22286 if (NILP (pointer
))
22288 /* If the string itself doesn't specify a pointer,
22289 see if the buffer text ``under'' it does. */
22290 struct glyph_row
*r
22291 = MATRIX_ROW (w
->current_matrix
, vpos
);
22292 int start
= MATRIX_ROW_START_CHARPOS (r
);
22293 int pos
= string_buffer_position (w
, object
, start
);
22295 pointer
= Fget_char_property (make_number (pos
),
22296 Qpointer
, w
->buffer
);
22299 else if (BUFFERP (object
)
22302 pointer
= Fget_text_property (make_number (charpos
),
22309 current_buffer
= obuf
;
22314 define_frame_cursor1 (f
, cursor
, pointer
);
22319 Clear any mouse-face on window W. This function is part of the
22320 redisplay interface, and is called from try_window_id and similar
22321 functions to ensure the mouse-highlight is off. */
22324 x_clear_window_mouse_face (w
)
22327 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22328 Lisp_Object window
;
22331 XSETWINDOW (window
, w
);
22332 if (EQ (window
, dpyinfo
->mouse_face_window
))
22333 clear_mouse_face (dpyinfo
);
22339 Just discard the mouse face information for frame F, if any.
22340 This is used when the size of F is changed. */
22343 cancel_mouse_face (f
)
22346 Lisp_Object window
;
22347 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22349 window
= dpyinfo
->mouse_face_window
;
22350 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
22352 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22353 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22354 dpyinfo
->mouse_face_window
= Qnil
;
22359 #endif /* HAVE_WINDOW_SYSTEM */
22362 /***********************************************************************
22364 ***********************************************************************/
22366 #ifdef HAVE_WINDOW_SYSTEM
22368 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
22369 which intersects rectangle R. R is in window-relative coordinates. */
22372 expose_area (w
, row
, r
, area
)
22374 struct glyph_row
*row
;
22376 enum glyph_row_area area
;
22378 struct glyph
*first
= row
->glyphs
[area
];
22379 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
22380 struct glyph
*last
;
22381 int first_x
, start_x
, x
;
22383 if (area
== TEXT_AREA
&& row
->fill_line_p
)
22384 /* If row extends face to end of line write the whole line. */
22385 draw_glyphs (w
, 0, row
, area
,
22386 0, row
->used
[area
],
22387 DRAW_NORMAL_TEXT
, 0);
22390 /* Set START_X to the window-relative start position for drawing glyphs of
22391 AREA. The first glyph of the text area can be partially visible.
22392 The first glyphs of other areas cannot. */
22393 start_x
= window_box_left_offset (w
, area
);
22395 if (area
== TEXT_AREA
)
22398 /* Find the first glyph that must be redrawn. */
22400 && x
+ first
->pixel_width
< r
->x
)
22402 x
+= first
->pixel_width
;
22406 /* Find the last one. */
22410 && x
< r
->x
+ r
->width
)
22412 x
+= last
->pixel_width
;
22418 draw_glyphs (w
, first_x
- start_x
, row
, area
,
22419 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
22420 DRAW_NORMAL_TEXT
, 0);
22425 /* Redraw the parts of the glyph row ROW on window W intersecting
22426 rectangle R. R is in window-relative coordinates. Value is
22427 non-zero if mouse-face was overwritten. */
22430 expose_line (w
, row
, r
)
22432 struct glyph_row
*row
;
22435 xassert (row
->enabled_p
);
22437 if (row
->mode_line_p
|| w
->pseudo_window_p
)
22438 draw_glyphs (w
, 0, row
, TEXT_AREA
,
22439 0, row
->used
[TEXT_AREA
],
22440 DRAW_NORMAL_TEXT
, 0);
22443 if (row
->used
[LEFT_MARGIN_AREA
])
22444 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
22445 if (row
->used
[TEXT_AREA
])
22446 expose_area (w
, row
, r
, TEXT_AREA
);
22447 if (row
->used
[RIGHT_MARGIN_AREA
])
22448 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
22449 draw_row_fringe_bitmaps (w
, row
);
22452 return row
->mouse_face_p
;
22456 /* Redraw those parts of glyphs rows during expose event handling that
22457 overlap other rows. Redrawing of an exposed line writes over parts
22458 of lines overlapping that exposed line; this function fixes that.
22460 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
22461 row in W's current matrix that is exposed and overlaps other rows.
22462 LAST_OVERLAPPING_ROW is the last such row. */
22465 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
22467 struct glyph_row
*first_overlapping_row
;
22468 struct glyph_row
*last_overlapping_row
;
22470 struct glyph_row
*row
;
22472 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
22473 if (row
->overlapping_p
)
22475 xassert (row
->enabled_p
&& !row
->mode_line_p
);
22477 if (row
->used
[LEFT_MARGIN_AREA
])
22478 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
22480 if (row
->used
[TEXT_AREA
])
22481 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
22483 if (row
->used
[RIGHT_MARGIN_AREA
])
22484 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
22489 /* Return non-zero if W's cursor intersects rectangle R. */
22492 phys_cursor_in_rect_p (w
, r
)
22496 XRectangle cr
, result
;
22497 struct glyph
*cursor_glyph
;
22499 cursor_glyph
= get_phys_cursor_glyph (w
);
22502 /* r is relative to W's box, but w->phys_cursor.x is relative
22503 to left edge of W's TEXT area. Adjust it. */
22504 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
22505 cr
.y
= w
->phys_cursor
.y
;
22506 cr
.width
= cursor_glyph
->pixel_width
;
22507 cr
.height
= w
->phys_cursor_height
;
22508 /* ++KFS: W32 version used W32-specific IntersectRect here, but
22509 I assume the effect is the same -- and this is portable. */
22510 return x_intersect_rectangles (&cr
, r
, &result
);
22518 Draw a vertical window border to the right of window W if W doesn't
22519 have vertical scroll bars. */
22522 x_draw_vertical_border (w
)
22525 /* We could do better, if we knew what type of scroll-bar the adjacent
22526 windows (on either side) have... But we don't :-(
22527 However, I think this works ok. ++KFS 2003-04-25 */
22529 /* Redraw borders between horizontally adjacent windows. Don't
22530 do it for frames with vertical scroll bars because either the
22531 right scroll bar of a window, or the left scroll bar of its
22532 neighbor will suffice as a border. */
22533 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
22536 if (!WINDOW_RIGHTMOST_P (w
)
22537 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
22539 int x0
, x1
, y0
, y1
;
22541 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22544 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22547 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
22549 else if (!WINDOW_LEFTMOST_P (w
)
22550 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
22552 int x0
, x1
, y0
, y1
;
22554 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22557 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22560 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
22565 /* Redraw the part of window W intersection rectangle FR. Pixel
22566 coordinates in FR are frame-relative. Call this function with
22567 input blocked. Value is non-zero if the exposure overwrites
22571 expose_window (w
, fr
)
22575 struct frame
*f
= XFRAME (w
->frame
);
22577 int mouse_face_overwritten_p
= 0;
22579 /* If window is not yet fully initialized, do nothing. This can
22580 happen when toolkit scroll bars are used and a window is split.
22581 Reconfiguring the scroll bar will generate an expose for a newly
22583 if (w
->current_matrix
== NULL
)
22586 /* When we're currently updating the window, display and current
22587 matrix usually don't agree. Arrange for a thorough display
22589 if (w
== updated_window
)
22591 SET_FRAME_GARBAGED (f
);
22595 /* Frame-relative pixel rectangle of W. */
22596 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
22597 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
22598 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
22599 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
22601 if (x_intersect_rectangles (fr
, &wr
, &r
))
22603 int yb
= window_text_bottom_y (w
);
22604 struct glyph_row
*row
;
22605 int cursor_cleared_p
;
22606 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
22608 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
22609 r
.x
, r
.y
, r
.width
, r
.height
));
22611 /* Convert to window coordinates. */
22612 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
22613 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
22615 /* Turn off the cursor. */
22616 if (!w
->pseudo_window_p
22617 && phys_cursor_in_rect_p (w
, &r
))
22619 x_clear_cursor (w
);
22620 cursor_cleared_p
= 1;
22623 cursor_cleared_p
= 0;
22625 /* Update lines intersecting rectangle R. */
22626 first_overlapping_row
= last_overlapping_row
= NULL
;
22627 for (row
= w
->current_matrix
->rows
;
22632 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
22634 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
22635 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
22636 || (r
.y
>= y0
&& r
.y
< y1
)
22637 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
22639 /* A header line may be overlapping, but there is no need
22640 to fix overlapping areas for them. KFS 2005-02-12 */
22641 if (row
->overlapping_p
&& !row
->mode_line_p
)
22643 if (first_overlapping_row
== NULL
)
22644 first_overlapping_row
= row
;
22645 last_overlapping_row
= row
;
22648 if (expose_line (w
, row
, &r
))
22649 mouse_face_overwritten_p
= 1;
22656 /* Display the mode line if there is one. */
22657 if (WINDOW_WANTS_MODELINE_P (w
)
22658 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
22660 && row
->y
< r
.y
+ r
.height
)
22662 if (expose_line (w
, row
, &r
))
22663 mouse_face_overwritten_p
= 1;
22666 if (!w
->pseudo_window_p
)
22668 /* Fix the display of overlapping rows. */
22669 if (first_overlapping_row
)
22670 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
22672 /* Draw border between windows. */
22673 x_draw_vertical_border (w
);
22675 /* Turn the cursor on again. */
22676 if (cursor_cleared_p
)
22677 update_window_cursor (w
, 1);
22681 return mouse_face_overwritten_p
;
22686 /* Redraw (parts) of all windows in the window tree rooted at W that
22687 intersect R. R contains frame pixel coordinates. Value is
22688 non-zero if the exposure overwrites mouse-face. */
22691 expose_window_tree (w
, r
)
22695 struct frame
*f
= XFRAME (w
->frame
);
22696 int mouse_face_overwritten_p
= 0;
22698 while (w
&& !FRAME_GARBAGED_P (f
))
22700 if (!NILP (w
->hchild
))
22701 mouse_face_overwritten_p
22702 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
22703 else if (!NILP (w
->vchild
))
22704 mouse_face_overwritten_p
22705 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
22707 mouse_face_overwritten_p
|= expose_window (w
, r
);
22709 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
22712 return mouse_face_overwritten_p
;
22717 Redisplay an exposed area of frame F. X and Y are the upper-left
22718 corner of the exposed rectangle. W and H are width and height of
22719 the exposed area. All are pixel values. W or H zero means redraw
22720 the entire frame. */
22723 expose_frame (f
, x
, y
, w
, h
)
22728 int mouse_face_overwritten_p
= 0;
22730 TRACE ((stderr
, "expose_frame "));
22732 /* No need to redraw if frame will be redrawn soon. */
22733 if (FRAME_GARBAGED_P (f
))
22735 TRACE ((stderr
, " garbaged\n"));
22739 /* If basic faces haven't been realized yet, there is no point in
22740 trying to redraw anything. This can happen when we get an expose
22741 event while Emacs is starting, e.g. by moving another window. */
22742 if (FRAME_FACE_CACHE (f
) == NULL
22743 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
22745 TRACE ((stderr
, " no faces\n"));
22749 if (w
== 0 || h
== 0)
22752 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
22753 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
22763 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
22764 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
22766 if (WINDOWP (f
->tool_bar_window
))
22767 mouse_face_overwritten_p
22768 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
22770 #ifdef HAVE_X_WINDOWS
22772 #ifndef USE_X_TOOLKIT
22773 if (WINDOWP (f
->menu_bar_window
))
22774 mouse_face_overwritten_p
22775 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
22776 #endif /* not USE_X_TOOLKIT */
22780 /* Some window managers support a focus-follows-mouse style with
22781 delayed raising of frames. Imagine a partially obscured frame,
22782 and moving the mouse into partially obscured mouse-face on that
22783 frame. The visible part of the mouse-face will be highlighted,
22784 then the WM raises the obscured frame. With at least one WM, KDE
22785 2.1, Emacs is not getting any event for the raising of the frame
22786 (even tried with SubstructureRedirectMask), only Expose events.
22787 These expose events will draw text normally, i.e. not
22788 highlighted. Which means we must redo the highlight here.
22789 Subsume it under ``we love X''. --gerd 2001-08-15 */
22790 /* Included in Windows version because Windows most likely does not
22791 do the right thing if any third party tool offers
22792 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
22793 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
22795 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22796 if (f
== dpyinfo
->mouse_face_mouse_frame
)
22798 int x
= dpyinfo
->mouse_face_mouse_x
;
22799 int y
= dpyinfo
->mouse_face_mouse_y
;
22800 clear_mouse_face (dpyinfo
);
22801 note_mouse_highlight (f
, x
, y
);
22808 Determine the intersection of two rectangles R1 and R2. Return
22809 the intersection in *RESULT. Value is non-zero if RESULT is not
22813 x_intersect_rectangles (r1
, r2
, result
)
22814 XRectangle
*r1
, *r2
, *result
;
22816 XRectangle
*left
, *right
;
22817 XRectangle
*upper
, *lower
;
22818 int intersection_p
= 0;
22820 /* Rearrange so that R1 is the left-most rectangle. */
22822 left
= r1
, right
= r2
;
22824 left
= r2
, right
= r1
;
22826 /* X0 of the intersection is right.x0, if this is inside R1,
22827 otherwise there is no intersection. */
22828 if (right
->x
<= left
->x
+ left
->width
)
22830 result
->x
= right
->x
;
22832 /* The right end of the intersection is the minimum of the
22833 the right ends of left and right. */
22834 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
22837 /* Same game for Y. */
22839 upper
= r1
, lower
= r2
;
22841 upper
= r2
, lower
= r1
;
22843 /* The upper end of the intersection is lower.y0, if this is inside
22844 of upper. Otherwise, there is no intersection. */
22845 if (lower
->y
<= upper
->y
+ upper
->height
)
22847 result
->y
= lower
->y
;
22849 /* The lower end of the intersection is the minimum of the lower
22850 ends of upper and lower. */
22851 result
->height
= (min (lower
->y
+ lower
->height
,
22852 upper
->y
+ upper
->height
)
22854 intersection_p
= 1;
22858 return intersection_p
;
22861 #endif /* HAVE_WINDOW_SYSTEM */
22864 /***********************************************************************
22866 ***********************************************************************/
22871 Vwith_echo_area_save_vector
= Qnil
;
22872 staticpro (&Vwith_echo_area_save_vector
);
22874 Vmessage_stack
= Qnil
;
22875 staticpro (&Vmessage_stack
);
22877 Qinhibit_redisplay
= intern ("inhibit-redisplay");
22878 staticpro (&Qinhibit_redisplay
);
22880 message_dolog_marker1
= Fmake_marker ();
22881 staticpro (&message_dolog_marker1
);
22882 message_dolog_marker2
= Fmake_marker ();
22883 staticpro (&message_dolog_marker2
);
22884 message_dolog_marker3
= Fmake_marker ();
22885 staticpro (&message_dolog_marker3
);
22888 defsubr (&Sdump_frame_glyph_matrix
);
22889 defsubr (&Sdump_glyph_matrix
);
22890 defsubr (&Sdump_glyph_row
);
22891 defsubr (&Sdump_tool_bar_row
);
22892 defsubr (&Strace_redisplay
);
22893 defsubr (&Strace_to_stderr
);
22895 #ifdef HAVE_WINDOW_SYSTEM
22896 defsubr (&Stool_bar_lines_needed
);
22897 defsubr (&Slookup_image_map
);
22899 defsubr (&Sformat_mode_line
);
22901 staticpro (&Qmenu_bar_update_hook
);
22902 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
22904 staticpro (&Qoverriding_terminal_local_map
);
22905 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
22907 staticpro (&Qoverriding_local_map
);
22908 Qoverriding_local_map
= intern ("overriding-local-map");
22910 staticpro (&Qwindow_scroll_functions
);
22911 Qwindow_scroll_functions
= intern ("window-scroll-functions");
22913 staticpro (&Qredisplay_end_trigger_functions
);
22914 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
22916 staticpro (&Qinhibit_point_motion_hooks
);
22917 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
22919 QCdata
= intern (":data");
22920 staticpro (&QCdata
);
22921 Qdisplay
= intern ("display");
22922 staticpro (&Qdisplay
);
22923 Qspace_width
= intern ("space-width");
22924 staticpro (&Qspace_width
);
22925 Qraise
= intern ("raise");
22926 staticpro (&Qraise
);
22927 Qslice
= intern ("slice");
22928 staticpro (&Qslice
);
22929 Qspace
= intern ("space");
22930 staticpro (&Qspace
);
22931 Qmargin
= intern ("margin");
22932 staticpro (&Qmargin
);
22933 Qpointer
= intern ("pointer");
22934 staticpro (&Qpointer
);
22935 Qleft_margin
= intern ("left-margin");
22936 staticpro (&Qleft_margin
);
22937 Qright_margin
= intern ("right-margin");
22938 staticpro (&Qright_margin
);
22939 Qcenter
= intern ("center");
22940 staticpro (&Qcenter
);
22941 Qline_height
= intern ("line-height");
22942 staticpro (&Qline_height
);
22943 QCalign_to
= intern (":align-to");
22944 staticpro (&QCalign_to
);
22945 QCrelative_width
= intern (":relative-width");
22946 staticpro (&QCrelative_width
);
22947 QCrelative_height
= intern (":relative-height");
22948 staticpro (&QCrelative_height
);
22949 QCeval
= intern (":eval");
22950 staticpro (&QCeval
);
22951 QCpropertize
= intern (":propertize");
22952 staticpro (&QCpropertize
);
22953 QCfile
= intern (":file");
22954 staticpro (&QCfile
);
22955 Qfontified
= intern ("fontified");
22956 staticpro (&Qfontified
);
22957 Qfontification_functions
= intern ("fontification-functions");
22958 staticpro (&Qfontification_functions
);
22959 Qtrailing_whitespace
= intern ("trailing-whitespace");
22960 staticpro (&Qtrailing_whitespace
);
22961 Qescape_glyph
= intern ("escape-glyph");
22962 staticpro (&Qescape_glyph
);
22963 Qnobreak_space
= intern ("nobreak-space");
22964 staticpro (&Qnobreak_space
);
22965 Qimage
= intern ("image");
22966 staticpro (&Qimage
);
22967 QCmap
= intern (":map");
22968 staticpro (&QCmap
);
22969 QCpointer
= intern (":pointer");
22970 staticpro (&QCpointer
);
22971 Qrect
= intern ("rect");
22972 staticpro (&Qrect
);
22973 Qcircle
= intern ("circle");
22974 staticpro (&Qcircle
);
22975 Qpoly
= intern ("poly");
22976 staticpro (&Qpoly
);
22977 Qmessage_truncate_lines
= intern ("message-truncate-lines");
22978 staticpro (&Qmessage_truncate_lines
);
22979 Qgrow_only
= intern ("grow-only");
22980 staticpro (&Qgrow_only
);
22981 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
22982 staticpro (&Qinhibit_menubar_update
);
22983 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
22984 staticpro (&Qinhibit_eval_during_redisplay
);
22985 Qposition
= intern ("position");
22986 staticpro (&Qposition
);
22987 Qbuffer_position
= intern ("buffer-position");
22988 staticpro (&Qbuffer_position
);
22989 Qobject
= intern ("object");
22990 staticpro (&Qobject
);
22991 Qbar
= intern ("bar");
22993 Qhbar
= intern ("hbar");
22994 staticpro (&Qhbar
);
22995 Qbox
= intern ("box");
22997 Qhollow
= intern ("hollow");
22998 staticpro (&Qhollow
);
22999 Qhand
= intern ("hand");
23000 staticpro (&Qhand
);
23001 Qarrow
= intern ("arrow");
23002 staticpro (&Qarrow
);
23003 Qtext
= intern ("text");
23004 staticpro (&Qtext
);
23005 Qrisky_local_variable
= intern ("risky-local-variable");
23006 staticpro (&Qrisky_local_variable
);
23007 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
23008 staticpro (&Qinhibit_free_realized_faces
);
23010 list_of_error
= Fcons (Fcons (intern ("error"),
23011 Fcons (intern ("void-variable"), Qnil
)),
23013 staticpro (&list_of_error
);
23015 Qlast_arrow_position
= intern ("last-arrow-position");
23016 staticpro (&Qlast_arrow_position
);
23017 Qlast_arrow_string
= intern ("last-arrow-string");
23018 staticpro (&Qlast_arrow_string
);
23020 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
23021 staticpro (&Qoverlay_arrow_string
);
23022 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
23023 staticpro (&Qoverlay_arrow_bitmap
);
23025 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
23026 staticpro (&echo_buffer
[0]);
23027 staticpro (&echo_buffer
[1]);
23029 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
23030 staticpro (&echo_area_buffer
[0]);
23031 staticpro (&echo_area_buffer
[1]);
23033 Vmessages_buffer_name
= build_string ("*Messages*");
23034 staticpro (&Vmessages_buffer_name
);
23036 mode_line_proptrans_alist
= Qnil
;
23037 staticpro (&mode_line_proptrans_alist
);
23038 mode_line_string_list
= Qnil
;
23039 staticpro (&mode_line_string_list
);
23040 mode_line_string_face
= Qnil
;
23041 staticpro (&mode_line_string_face
);
23042 mode_line_string_face_prop
= Qnil
;
23043 staticpro (&mode_line_string_face_prop
);
23044 Vmode_line_unwind_vector
= Qnil
;
23045 staticpro (&Vmode_line_unwind_vector
);
23047 help_echo_string
= Qnil
;
23048 staticpro (&help_echo_string
);
23049 help_echo_object
= Qnil
;
23050 staticpro (&help_echo_object
);
23051 help_echo_window
= Qnil
;
23052 staticpro (&help_echo_window
);
23053 previous_help_echo_string
= Qnil
;
23054 staticpro (&previous_help_echo_string
);
23055 help_echo_pos
= -1;
23057 #ifdef HAVE_WINDOW_SYSTEM
23058 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
23059 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
23060 For example, if a block cursor is over a tab, it will be drawn as
23061 wide as that tab on the display. */);
23062 x_stretch_cursor_p
= 0;
23065 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
23066 doc
: /* *Non-nil means highlight trailing whitespace.
23067 The face used for trailing whitespace is `trailing-whitespace'. */);
23068 Vshow_trailing_whitespace
= Qnil
;
23070 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
23071 doc
: /* *Control highlighting of nobreak space and soft hyphen.
23072 A value of t means highlight the character itself (for nobreak space,
23073 use face `nobreak-space').
23074 A value of nil means no highlighting.
23075 Other values mean display the escape glyph followed by an ordinary
23076 space or ordinary hyphen. */);
23077 Vnobreak_char_display
= Qt
;
23079 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
23080 doc
: /* *The pointer shape to show in void text areas.
23081 A value of nil means to show the text pointer. Other options are `arrow',
23082 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
23083 Vvoid_text_area_pointer
= Qarrow
;
23085 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
23086 doc
: /* Non-nil means don't actually do any redisplay.
23087 This is used for internal purposes. */);
23088 Vinhibit_redisplay
= Qnil
;
23090 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
23091 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
23092 Vglobal_mode_string
= Qnil
;
23094 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
23095 doc
: /* Marker for where to display an arrow on top of the buffer text.
23096 This must be the beginning of a line in order to work.
23097 See also `overlay-arrow-string'. */);
23098 Voverlay_arrow_position
= Qnil
;
23100 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
23101 doc
: /* String to display as an arrow in non-window frames.
23102 See also `overlay-arrow-position'. */);
23103 Voverlay_arrow_string
= build_string ("=>");
23105 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
23106 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
23107 The symbols on this list are examined during redisplay to determine
23108 where to display overlay arrows. */);
23109 Voverlay_arrow_variable_list
23110 = Fcons (intern ("overlay-arrow-position"), Qnil
);
23112 DEFVAR_INT ("scroll-step", &scroll_step
,
23113 doc
: /* *The number of lines to try scrolling a window by when point moves out.
23114 If that fails to bring point back on frame, point is centered instead.
23115 If this is zero, point is always centered after it moves off frame.
23116 If you want scrolling to always be a line at a time, you should set
23117 `scroll-conservatively' to a large value rather than set this to 1. */);
23119 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
23120 doc
: /* *Scroll up to this many lines, to bring point back on screen.
23121 A value of zero means to scroll the text to center point vertically
23122 in the window. */);
23123 scroll_conservatively
= 0;
23125 DEFVAR_INT ("scroll-margin", &scroll_margin
,
23126 doc
: /* *Number of lines of margin at the top and bottom of a window.
23127 Recenter the window whenever point gets within this many lines
23128 of the top or bottom of the window. */);
23131 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
23132 doc
: /* Pixels per inch on current display.
23133 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
23134 Vdisplay_pixels_per_inch
= make_float (72.0);
23137 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
23140 DEFVAR_BOOL ("truncate-partial-width-windows",
23141 &truncate_partial_width_windows
,
23142 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
23143 truncate_partial_width_windows
= 1;
23145 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
23146 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
23147 Any other value means to use the appropriate face, `mode-line',
23148 `header-line', or `menu' respectively. */);
23149 mode_line_inverse_video
= 1;
23151 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
23152 doc
: /* *Maximum buffer size for which line number should be displayed.
23153 If the buffer is bigger than this, the line number does not appear
23154 in the mode line. A value of nil means no limit. */);
23155 Vline_number_display_limit
= Qnil
;
23157 DEFVAR_INT ("line-number-display-limit-width",
23158 &line_number_display_limit_width
,
23159 doc
: /* *Maximum line width (in characters) for line number display.
23160 If the average length of the lines near point is bigger than this, then the
23161 line number may be omitted from the mode line. */);
23162 line_number_display_limit_width
= 200;
23164 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
23165 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
23166 highlight_nonselected_windows
= 0;
23168 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
23169 doc
: /* Non-nil if more than one frame is visible on this display.
23170 Minibuffer-only frames don't count, but iconified frames do.
23171 This variable is not guaranteed to be accurate except while processing
23172 `frame-title-format' and `icon-title-format'. */);
23174 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
23175 doc
: /* Template for displaying the title bar of visible frames.
23176 \(Assuming the window manager supports this feature.)
23177 This variable has the same structure as `mode-line-format' (which see),
23178 and is used only on frames for which no explicit name has been set
23179 \(see `modify-frame-parameters'). */);
23181 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
23182 doc
: /* Template for displaying the title bar of an iconified frame.
23183 \(Assuming the window manager supports this feature.)
23184 This variable has the same structure as `mode-line-format' (which see),
23185 and is used only on frames for which no explicit name has been set
23186 \(see `modify-frame-parameters'). */);
23188 = Vframe_title_format
23189 = Fcons (intern ("multiple-frames"),
23190 Fcons (build_string ("%b"),
23191 Fcons (Fcons (empty_string
,
23192 Fcons (intern ("invocation-name"),
23193 Fcons (build_string ("@"),
23194 Fcons (intern ("system-name"),
23198 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
23199 doc
: /* Maximum number of lines to keep in the message log buffer.
23200 If nil, disable message logging. If t, log messages but don't truncate
23201 the buffer when it becomes large. */);
23202 Vmessage_log_max
= make_number (50);
23204 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
23205 doc
: /* Functions called before redisplay, if window sizes have changed.
23206 The value should be a list of functions that take one argument.
23207 Just before redisplay, for each frame, if any of its windows have changed
23208 size since the last redisplay, or have been split or deleted,
23209 all the functions in the list are called, with the frame as argument. */);
23210 Vwindow_size_change_functions
= Qnil
;
23212 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
23213 doc
: /* List of functions to call before redisplaying a window with scrolling.
23214 Each function is called with two arguments, the window
23215 and its new display-start position. Note that the value of `window-end'
23216 is not valid when these functions are called. */);
23217 Vwindow_scroll_functions
= Qnil
;
23219 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
23220 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
23221 mouse_autoselect_window
= 0;
23223 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
23224 doc
: /* *Non-nil means automatically resize tool-bars.
23225 This increases a tool-bar's height if not all tool-bar items are visible.
23226 It decreases a tool-bar's height when it would display blank lines
23228 auto_resize_tool_bars_p
= 1;
23230 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
23231 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
23232 auto_raise_tool_bar_buttons_p
= 1;
23234 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
23235 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
23236 make_cursor_line_fully_visible_p
= 1;
23238 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
23239 doc
: /* *Margin around tool-bar buttons in pixels.
23240 If an integer, use that for both horizontal and vertical margins.
23241 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
23242 HORZ specifying the horizontal margin, and VERT specifying the
23243 vertical margin. */);
23244 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
23246 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
23247 doc
: /* *Relief thickness of tool-bar buttons. */);
23248 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
23250 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
23251 doc
: /* List of functions to call to fontify regions of text.
23252 Each function is called with one argument POS. Functions must
23253 fontify a region starting at POS in the current buffer, and give
23254 fontified regions the property `fontified'. */);
23255 Vfontification_functions
= Qnil
;
23256 Fmake_variable_buffer_local (Qfontification_functions
);
23258 DEFVAR_BOOL ("unibyte-display-via-language-environment",
23259 &unibyte_display_via_language_environment
,
23260 doc
: /* *Non-nil means display unibyte text according to language environment.
23261 Specifically this means that unibyte non-ASCII characters
23262 are displayed by converting them to the equivalent multibyte characters
23263 according to the current language environment. As a result, they are
23264 displayed according to the current fontset. */);
23265 unibyte_display_via_language_environment
= 0;
23267 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
23268 doc
: /* *Maximum height for resizing mini-windows.
23269 If a float, it specifies a fraction of the mini-window frame's height.
23270 If an integer, it specifies a number of lines. */);
23271 Vmax_mini_window_height
= make_float (0.25);
23273 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
23274 doc
: /* *How to resize mini-windows.
23275 A value of nil means don't automatically resize mini-windows.
23276 A value of t means resize them to fit the text displayed in them.
23277 A value of `grow-only', the default, means let mini-windows grow
23278 only, until their display becomes empty, at which point the windows
23279 go back to their normal size. */);
23280 Vresize_mini_windows
= Qgrow_only
;
23282 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
23283 doc
: /* Alist specifying how to blink the cursor off.
23284 Each element has the form (ON-STATE . OFF-STATE). Whenever the
23285 `cursor-type' frame-parameter or variable equals ON-STATE,
23286 comparing using `equal', Emacs uses OFF-STATE to specify
23287 how to blink it off. */);
23288 Vblink_cursor_alist
= Qnil
;
23290 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
23291 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
23292 automatic_hscrolling_p
= 1;
23294 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
23295 doc
: /* *How many columns away from the window edge point is allowed to get
23296 before automatic hscrolling will horizontally scroll the window. */);
23297 hscroll_margin
= 5;
23299 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
23300 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
23301 When point is less than `automatic-hscroll-margin' columns from the window
23302 edge, automatic hscrolling will scroll the window by the amount of columns
23303 determined by this variable. If its value is a positive integer, scroll that
23304 many columns. If it's a positive floating-point number, it specifies the
23305 fraction of the window's width to scroll. If it's nil or zero, point will be
23306 centered horizontally after the scroll. Any other value, including negative
23307 numbers, are treated as if the value were zero.
23309 Automatic hscrolling always moves point outside the scroll margin, so if
23310 point was more than scroll step columns inside the margin, the window will
23311 scroll more than the value given by the scroll step.
23313 Note that the lower bound for automatic hscrolling specified by `scroll-left'
23314 and `scroll-right' overrides this variable's effect. */);
23315 Vhscroll_step
= make_number (0);
23317 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
23318 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
23319 Bind this around calls to `message' to let it take effect. */);
23320 message_truncate_lines
= 0;
23322 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
23323 doc
: /* Normal hook run to update the menu bar definitions.
23324 Redisplay runs this hook before it redisplays the menu bar.
23325 This is used to update submenus such as Buffers,
23326 whose contents depend on various data. */);
23327 Vmenu_bar_update_hook
= Qnil
;
23329 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
23330 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
23331 inhibit_menubar_update
= 0;
23333 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
23334 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
23335 inhibit_eval_during_redisplay
= 0;
23337 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
23338 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
23339 inhibit_free_realized_faces
= 0;
23342 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
23343 doc
: /* Inhibit try_window_id display optimization. */);
23344 inhibit_try_window_id
= 0;
23346 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
23347 doc
: /* Inhibit try_window_reusing display optimization. */);
23348 inhibit_try_window_reusing
= 0;
23350 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
23351 doc
: /* Inhibit try_cursor_movement display optimization. */);
23352 inhibit_try_cursor_movement
= 0;
23353 #endif /* GLYPH_DEBUG */
23357 /* Initialize this module when Emacs starts. */
23362 Lisp_Object root_window
;
23363 struct window
*mini_w
;
23365 current_header_line_height
= current_mode_line_height
= -1;
23367 CHARPOS (this_line_start_pos
) = 0;
23369 mini_w
= XWINDOW (minibuf_window
);
23370 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
23372 if (!noninteractive
)
23374 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
23377 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
23378 set_window_height (root_window
,
23379 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
23381 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
23382 set_window_height (minibuf_window
, 1, 0);
23384 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
23385 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
23387 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
23388 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
23389 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
23391 /* The default ellipsis glyphs `...'. */
23392 for (i
= 0; i
< 3; ++i
)
23393 default_invis_vector
[i
] = make_number ('.');
23397 /* Allocate the buffer for frame titles.
23398 Also used for `format-mode-line'. */
23400 mode_line_noprop_buf
= (char *) xmalloc (size
);
23401 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
23402 mode_line_noprop_ptr
= mode_line_noprop_buf
;
23403 mode_line_target
= MODE_LINE_DISPLAY
;
23406 help_echo_showing_p
= 0;
23410 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
23411 (do not change this comment) */