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 /* Don't reseat to previous visible line start if current start
2415 position is in a string or image. */
2416 if (it
->method
== GET_FROM_BUFFER
&& !it
->truncate_lines_p
)
2418 int start_at_line_beg_p
;
2419 int first_y
= it
->current_y
;
2421 /* If window start is not at a line start, skip forward to POS to
2422 get the correct continuation lines width. */
2423 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2424 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2425 if (!start_at_line_beg_p
)
2429 reseat_at_previous_visible_line_start (it
);
2430 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2432 new_x
= it
->current_x
+ it
->pixel_width
;
2434 /* If lines are continued, this line may end in the middle
2435 of a multi-glyph character (e.g. a control character
2436 displayed as \003, or in the middle of an overlay
2437 string). In this case move_it_to above will not have
2438 taken us to the start of the continuation line but to the
2439 end of the continued line. */
2440 if (it
->current_x
> 0
2441 && !it
->truncate_lines_p
/* Lines are continued. */
2442 && (/* And glyph doesn't fit on the line. */
2443 new_x
> it
->last_visible_x
2444 /* Or it fits exactly and we're on a window
2446 || (new_x
== it
->last_visible_x
2447 && FRAME_WINDOW_P (it
->f
))))
2449 if (it
->current
.dpvec_index
>= 0
2450 || it
->current
.overlay_string_index
>= 0)
2452 set_iterator_to_next (it
, 1);
2453 move_it_in_display_line_to (it
, -1, -1, 0);
2456 it
->continuation_lines_width
+= it
->current_x
;
2459 /* We're starting a new display line, not affected by the
2460 height of the continued line, so clear the appropriate
2461 fields in the iterator structure. */
2462 it
->max_ascent
= it
->max_descent
= 0;
2463 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2465 it
->current_y
= first_y
;
2467 it
->current_x
= it
->hpos
= 0;
2471 #if 0 /* Don't assert the following because start_display is sometimes
2472 called intentionally with a window start that is not at a
2473 line start. Please leave this code in as a comment. */
2475 /* Window start should be on a line start, now. */
2476 xassert (it
->continuation_lines_width
2477 || IT_CHARPOS (it
) == BEGV
2478 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2483 /* Return 1 if POS is a position in ellipses displayed for invisible
2484 text. W is the window we display, for text property lookup. */
2487 in_ellipses_for_invisible_text_p (pos
, w
)
2488 struct display_pos
*pos
;
2491 Lisp_Object prop
, window
;
2493 int charpos
= CHARPOS (pos
->pos
);
2495 /* If POS specifies a position in a display vector, this might
2496 be for an ellipsis displayed for invisible text. We won't
2497 get the iterator set up for delivering that ellipsis unless
2498 we make sure that it gets aware of the invisible text. */
2499 if (pos
->dpvec_index
>= 0
2500 && pos
->overlay_string_index
< 0
2501 && CHARPOS (pos
->string_pos
) < 0
2503 && (XSETWINDOW (window
, w
),
2504 prop
= Fget_char_property (make_number (charpos
),
2505 Qinvisible
, window
),
2506 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2508 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2510 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2517 /* Initialize IT for stepping through current_buffer in window W,
2518 starting at position POS that includes overlay string and display
2519 vector/ control character translation position information. Value
2520 is zero if there are overlay strings with newlines at POS. */
2523 init_from_display_pos (it
, w
, pos
)
2526 struct display_pos
*pos
;
2528 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2529 int i
, overlay_strings_with_newlines
= 0;
2531 /* If POS specifies a position in a display vector, this might
2532 be for an ellipsis displayed for invisible text. We won't
2533 get the iterator set up for delivering that ellipsis unless
2534 we make sure that it gets aware of the invisible text. */
2535 if (in_ellipses_for_invisible_text_p (pos
, w
))
2541 /* Keep in mind: the call to reseat in init_iterator skips invisible
2542 text, so we might end up at a position different from POS. This
2543 is only a problem when POS is a row start after a newline and an
2544 overlay starts there with an after-string, and the overlay has an
2545 invisible property. Since we don't skip invisible text in
2546 display_line and elsewhere immediately after consuming the
2547 newline before the row start, such a POS will not be in a string,
2548 but the call to init_iterator below will move us to the
2550 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2552 /* This only scans the current chunk -- it should scan all chunks.
2553 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2554 to 16 in 22.1 to make this a lesser problem. */
2555 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2557 const char *s
= SDATA (it
->overlay_strings
[i
]);
2558 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2560 while (s
< e
&& *s
!= '\n')
2565 overlay_strings_with_newlines
= 1;
2570 /* If position is within an overlay string, set up IT to the right
2572 if (pos
->overlay_string_index
>= 0)
2576 /* If the first overlay string happens to have a `display'
2577 property for an image, the iterator will be set up for that
2578 image, and we have to undo that setup first before we can
2579 correct the overlay string index. */
2580 if (it
->method
== GET_FROM_IMAGE
)
2583 /* We already have the first chunk of overlay strings in
2584 IT->overlay_strings. Load more until the one for
2585 pos->overlay_string_index is in IT->overlay_strings. */
2586 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2588 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2589 it
->current
.overlay_string_index
= 0;
2592 load_overlay_strings (it
, 0);
2593 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2597 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2598 relative_index
= (it
->current
.overlay_string_index
2599 % OVERLAY_STRING_CHUNK_SIZE
);
2600 it
->string
= it
->overlay_strings
[relative_index
];
2601 xassert (STRINGP (it
->string
));
2602 it
->current
.string_pos
= pos
->string_pos
;
2603 it
->method
= GET_FROM_STRING
;
2606 #if 0 /* This is bogus because POS not having an overlay string
2607 position does not mean it's after the string. Example: A
2608 line starting with a before-string and initialization of IT
2609 to the previous row's end position. */
2610 else if (it
->current
.overlay_string_index
>= 0)
2612 /* If POS says we're already after an overlay string ending at
2613 POS, make sure to pop the iterator because it will be in
2614 front of that overlay string. When POS is ZV, we've thereby
2615 also ``processed'' overlay strings at ZV. */
2618 it
->current
.overlay_string_index
= -1;
2619 it
->method
= GET_FROM_BUFFER
;
2620 if (CHARPOS (pos
->pos
) == ZV
)
2621 it
->overlay_strings_at_end_processed_p
= 1;
2625 if (CHARPOS (pos
->string_pos
) >= 0)
2627 /* Recorded position is not in an overlay string, but in another
2628 string. This can only be a string from a `display' property.
2629 IT should already be filled with that string. */
2630 it
->current
.string_pos
= pos
->string_pos
;
2631 xassert (STRINGP (it
->string
));
2634 /* Restore position in display vector translations, control
2635 character translations or ellipses. */
2636 if (pos
->dpvec_index
>= 0)
2638 if (it
->dpvec
== NULL
)
2639 get_next_display_element (it
);
2640 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2641 it
->current
.dpvec_index
= pos
->dpvec_index
;
2645 return !overlay_strings_with_newlines
;
2649 /* Initialize IT for stepping through current_buffer in window W
2650 starting at ROW->start. */
2653 init_to_row_start (it
, w
, row
)
2656 struct glyph_row
*row
;
2658 init_from_display_pos (it
, w
, &row
->start
);
2659 it
->start
= row
->start
;
2660 it
->continuation_lines_width
= row
->continuation_lines_width
;
2665 /* Initialize IT for stepping through current_buffer in window W
2666 starting in the line following ROW, i.e. starting at ROW->end.
2667 Value is zero if there are overlay strings with newlines at ROW's
2671 init_to_row_end (it
, w
, row
)
2674 struct glyph_row
*row
;
2678 if (init_from_display_pos (it
, w
, &row
->end
))
2680 if (row
->continued_p
)
2681 it
->continuation_lines_width
2682 = row
->continuation_lines_width
+ row
->pixel_width
;
2693 /***********************************************************************
2695 ***********************************************************************/
2697 /* Called when IT reaches IT->stop_charpos. Handle text property and
2698 overlay changes. Set IT->stop_charpos to the next position where
2705 enum prop_handled handled
;
2706 int handle_overlay_change_p
= 1;
2710 it
->current
.dpvec_index
= -1;
2712 /* Use face of preceding text for ellipsis (if invisible) */
2713 if (it
->selective_display_ellipsis_p
)
2714 it
->saved_face_id
= it
->face_id
;
2718 handled
= HANDLED_NORMALLY
;
2720 /* Call text property handlers. */
2721 for (p
= it_props
; p
->handler
; ++p
)
2723 handled
= p
->handler (it
);
2725 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2727 else if (handled
== HANDLED_RETURN
)
2729 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2730 handle_overlay_change_p
= 0;
2733 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2735 /* Don't check for overlay strings below when set to deliver
2736 characters from a display vector. */
2737 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
2738 handle_overlay_change_p
= 0;
2740 /* Handle overlay changes. */
2741 if (handle_overlay_change_p
)
2742 handled
= handle_overlay_change (it
);
2744 /* Determine where to stop next. */
2745 if (handled
== HANDLED_NORMALLY
)
2746 compute_stop_pos (it
);
2749 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2753 /* Compute IT->stop_charpos from text property and overlay change
2754 information for IT's current position. */
2757 compute_stop_pos (it
)
2760 register INTERVAL iv
, next_iv
;
2761 Lisp_Object object
, limit
, position
;
2763 /* If nowhere else, stop at the end. */
2764 it
->stop_charpos
= it
->end_charpos
;
2766 if (STRINGP (it
->string
))
2768 /* Strings are usually short, so don't limit the search for
2770 object
= it
->string
;
2772 position
= make_number (IT_STRING_CHARPOS (*it
));
2778 /* If next overlay change is in front of the current stop pos
2779 (which is IT->end_charpos), stop there. Note: value of
2780 next_overlay_change is point-max if no overlay change
2782 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2783 if (charpos
< it
->stop_charpos
)
2784 it
->stop_charpos
= charpos
;
2786 /* If showing the region, we have to stop at the region
2787 start or end because the face might change there. */
2788 if (it
->region_beg_charpos
> 0)
2790 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2791 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2792 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2793 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2796 /* Set up variables for computing the stop position from text
2797 property changes. */
2798 XSETBUFFER (object
, current_buffer
);
2799 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2800 position
= make_number (IT_CHARPOS (*it
));
2804 /* Get the interval containing IT's position. Value is a null
2805 interval if there isn't such an interval. */
2806 iv
= validate_interval_range (object
, &position
, &position
, 0);
2807 if (!NULL_INTERVAL_P (iv
))
2809 Lisp_Object values_here
[LAST_PROP_IDX
];
2812 /* Get properties here. */
2813 for (p
= it_props
; p
->handler
; ++p
)
2814 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2816 /* Look for an interval following iv that has different
2818 for (next_iv
= next_interval (iv
);
2819 (!NULL_INTERVAL_P (next_iv
)
2821 || XFASTINT (limit
) > next_iv
->position
));
2822 next_iv
= next_interval (next_iv
))
2824 for (p
= it_props
; p
->handler
; ++p
)
2826 Lisp_Object new_value
;
2828 new_value
= textget (next_iv
->plist
, *p
->name
);
2829 if (!EQ (values_here
[p
->idx
], new_value
))
2837 if (!NULL_INTERVAL_P (next_iv
))
2839 if (INTEGERP (limit
)
2840 && next_iv
->position
>= XFASTINT (limit
))
2841 /* No text property change up to limit. */
2842 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2844 /* Text properties change in next_iv. */
2845 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2849 xassert (STRINGP (it
->string
)
2850 || (it
->stop_charpos
>= BEGV
2851 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2855 /* Return the position of the next overlay change after POS in
2856 current_buffer. Value is point-max if no overlay change
2857 follows. This is like `next-overlay-change' but doesn't use
2861 next_overlay_change (pos
)
2866 Lisp_Object
*overlays
;
2869 /* Get all overlays at the given position. */
2870 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
2872 /* If any of these overlays ends before endpos,
2873 use its ending point instead. */
2874 for (i
= 0; i
< noverlays
; ++i
)
2879 oend
= OVERLAY_END (overlays
[i
]);
2880 oendpos
= OVERLAY_POSITION (oend
);
2881 endpos
= min (endpos
, oendpos
);
2889 /***********************************************************************
2891 ***********************************************************************/
2893 /* Handle changes in the `fontified' property of the current buffer by
2894 calling hook functions from Qfontification_functions to fontify
2897 static enum prop_handled
2898 handle_fontified_prop (it
)
2901 Lisp_Object prop
, pos
;
2902 enum prop_handled handled
= HANDLED_NORMALLY
;
2904 /* Get the value of the `fontified' property at IT's current buffer
2905 position. (The `fontified' property doesn't have a special
2906 meaning in strings.) If the value is nil, call functions from
2907 Qfontification_functions. */
2908 if (!STRINGP (it
->string
)
2910 && !NILP (Vfontification_functions
)
2911 && !NILP (Vrun_hooks
)
2912 && (pos
= make_number (IT_CHARPOS (*it
)),
2913 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2916 int count
= SPECPDL_INDEX ();
2919 val
= Vfontification_functions
;
2920 specbind (Qfontification_functions
, Qnil
);
2922 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2923 safe_call1 (val
, pos
);
2926 Lisp_Object globals
, fn
;
2927 struct gcpro gcpro1
, gcpro2
;
2930 GCPRO2 (val
, globals
);
2932 for (; CONSP (val
); val
= XCDR (val
))
2938 /* A value of t indicates this hook has a local
2939 binding; it means to run the global binding too.
2940 In a global value, t should not occur. If it
2941 does, we must ignore it to avoid an endless
2943 for (globals
= Fdefault_value (Qfontification_functions
);
2945 globals
= XCDR (globals
))
2947 fn
= XCAR (globals
);
2949 safe_call1 (fn
, pos
);
2953 safe_call1 (fn
, pos
);
2959 unbind_to (count
, Qnil
);
2961 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2962 something. This avoids an endless loop if they failed to
2963 fontify the text for which reason ever. */
2964 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2965 handled
= HANDLED_RECOMPUTE_PROPS
;
2973 /***********************************************************************
2975 ***********************************************************************/
2977 /* Set up iterator IT from face properties at its current position.
2978 Called from handle_stop. */
2980 static enum prop_handled
2981 handle_face_prop (it
)
2984 int new_face_id
, next_stop
;
2986 if (!STRINGP (it
->string
))
2989 = face_at_buffer_position (it
->w
,
2991 it
->region_beg_charpos
,
2992 it
->region_end_charpos
,
2995 + TEXT_PROP_DISTANCE_LIMIT
),
2998 /* Is this a start of a run of characters with box face?
2999 Caveat: this can be called for a freshly initialized
3000 iterator; face_id is -1 in this case. We know that the new
3001 face will not change until limit, i.e. if the new face has a
3002 box, all characters up to limit will have one. But, as
3003 usual, we don't know whether limit is really the end. */
3004 if (new_face_id
!= it
->face_id
)
3006 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3008 /* If new face has a box but old face has not, this is
3009 the start of a run of characters with box, i.e. it has
3010 a shadow on the left side. The value of face_id of the
3011 iterator will be -1 if this is the initial call that gets
3012 the face. In this case, we have to look in front of IT's
3013 position and see whether there is a face != new_face_id. */
3014 it
->start_of_box_run_p
3015 = (new_face
->box
!= FACE_NO_BOX
3016 && (it
->face_id
>= 0
3017 || IT_CHARPOS (*it
) == BEG
3018 || new_face_id
!= face_before_it_pos (it
)));
3019 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3024 int base_face_id
, bufpos
;
3026 if (it
->current
.overlay_string_index
>= 0)
3027 bufpos
= IT_CHARPOS (*it
);
3031 /* For strings from a buffer, i.e. overlay strings or strings
3032 from a `display' property, use the face at IT's current
3033 buffer position as the base face to merge with, so that
3034 overlay strings appear in the same face as surrounding
3035 text, unless they specify their own faces. */
3036 base_face_id
= underlying_face_id (it
);
3038 new_face_id
= face_at_string_position (it
->w
,
3040 IT_STRING_CHARPOS (*it
),
3042 it
->region_beg_charpos
,
3043 it
->region_end_charpos
,
3047 #if 0 /* This shouldn't be neccessary. Let's check it. */
3048 /* If IT is used to display a mode line we would really like to
3049 use the mode line face instead of the frame's default face. */
3050 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3051 && new_face_id
== DEFAULT_FACE_ID
)
3052 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3055 /* Is this a start of a run of characters with box? Caveat:
3056 this can be called for a freshly allocated iterator; face_id
3057 is -1 is this case. We know that the new face will not
3058 change until the next check pos, i.e. if the new face has a
3059 box, all characters up to that position will have a
3060 box. But, as usual, we don't know whether that position
3061 is really the end. */
3062 if (new_face_id
!= it
->face_id
)
3064 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3065 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3067 /* If new face has a box but old face hasn't, this is the
3068 start of a run of characters with box, i.e. it has a
3069 shadow on the left side. */
3070 it
->start_of_box_run_p
3071 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3072 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3076 it
->face_id
= new_face_id
;
3077 return HANDLED_NORMALLY
;
3081 /* Return the ID of the face ``underlying'' IT's current position,
3082 which is in a string. If the iterator is associated with a
3083 buffer, return the face at IT's current buffer position.
3084 Otherwise, use the iterator's base_face_id. */
3087 underlying_face_id (it
)
3090 int face_id
= it
->base_face_id
, i
;
3092 xassert (STRINGP (it
->string
));
3094 for (i
= it
->sp
- 1; i
>= 0; --i
)
3095 if (NILP (it
->stack
[i
].string
))
3096 face_id
= it
->stack
[i
].face_id
;
3102 /* Compute the face one character before or after the current position
3103 of IT. BEFORE_P non-zero means get the face in front of IT's
3104 position. Value is the id of the face. */
3107 face_before_or_after_it_pos (it
, before_p
)
3112 int next_check_charpos
;
3113 struct text_pos pos
;
3115 xassert (it
->s
== NULL
);
3117 if (STRINGP (it
->string
))
3119 int bufpos
, base_face_id
;
3121 /* No face change past the end of the string (for the case
3122 we are padding with spaces). No face change before the
3124 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3125 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3128 /* Set pos to the position before or after IT's current position. */
3130 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3132 /* For composition, we must check the character after the
3134 pos
= (it
->what
== IT_COMPOSITION
3135 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3136 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3138 if (it
->current
.overlay_string_index
>= 0)
3139 bufpos
= IT_CHARPOS (*it
);
3143 base_face_id
= underlying_face_id (it
);
3145 /* Get the face for ASCII, or unibyte. */
3146 face_id
= face_at_string_position (it
->w
,
3150 it
->region_beg_charpos
,
3151 it
->region_end_charpos
,
3152 &next_check_charpos
,
3155 /* Correct the face for charsets different from ASCII. Do it
3156 for the multibyte case only. The face returned above is
3157 suitable for unibyte text if IT->string is unibyte. */
3158 if (STRING_MULTIBYTE (it
->string
))
3160 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3161 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3163 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3165 c
= string_char_and_length (p
, rest
, &len
);
3166 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3171 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3172 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3175 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3176 pos
= it
->current
.pos
;
3179 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3182 if (it
->what
== IT_COMPOSITION
)
3183 /* For composition, we must check the position after the
3185 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3187 INC_TEXT_POS (pos
, it
->multibyte_p
);
3190 /* Determine face for CHARSET_ASCII, or unibyte. */
3191 face_id
= face_at_buffer_position (it
->w
,
3193 it
->region_beg_charpos
,
3194 it
->region_end_charpos
,
3195 &next_check_charpos
,
3198 /* Correct the face for charsets different from ASCII. Do it
3199 for the multibyte case only. The face returned above is
3200 suitable for unibyte text if current_buffer is unibyte. */
3201 if (it
->multibyte_p
)
3203 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3204 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3205 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3214 /***********************************************************************
3216 ***********************************************************************/
3218 /* Set up iterator IT from invisible properties at its current
3219 position. Called from handle_stop. */
3221 static enum prop_handled
3222 handle_invisible_prop (it
)
3225 enum prop_handled handled
= HANDLED_NORMALLY
;
3227 if (STRINGP (it
->string
))
3229 extern Lisp_Object Qinvisible
;
3230 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3232 /* Get the value of the invisible text property at the
3233 current position. Value will be nil if there is no such
3235 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3236 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3239 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3241 handled
= HANDLED_RECOMPUTE_PROPS
;
3243 /* Get the position at which the next change of the
3244 invisible text property can be found in IT->string.
3245 Value will be nil if the property value is the same for
3246 all the rest of IT->string. */
3247 XSETINT (limit
, SCHARS (it
->string
));
3248 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3251 /* Text at current position is invisible. The next
3252 change in the property is at position end_charpos.
3253 Move IT's current position to that position. */
3254 if (INTEGERP (end_charpos
)
3255 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3257 struct text_pos old
;
3258 old
= it
->current
.string_pos
;
3259 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3260 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3264 /* The rest of the string is invisible. If this is an
3265 overlay string, proceed with the next overlay string
3266 or whatever comes and return a character from there. */
3267 if (it
->current
.overlay_string_index
>= 0)
3269 next_overlay_string (it
);
3270 /* Don't check for overlay strings when we just
3271 finished processing them. */
3272 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3276 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3277 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3284 int invis_p
, newpos
, next_stop
, start_charpos
;
3285 Lisp_Object pos
, prop
, overlay
;
3287 /* First of all, is there invisible text at this position? */
3288 start_charpos
= IT_CHARPOS (*it
);
3289 pos
= make_number (IT_CHARPOS (*it
));
3290 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3292 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3294 /* If we are on invisible text, skip over it. */
3295 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3297 /* Record whether we have to display an ellipsis for the
3299 int display_ellipsis_p
= invis_p
== 2;
3301 handled
= HANDLED_RECOMPUTE_PROPS
;
3303 /* Loop skipping over invisible text. The loop is left at
3304 ZV or with IT on the first char being visible again. */
3307 /* Try to skip some invisible text. Return value is the
3308 position reached which can be equal to IT's position
3309 if there is nothing invisible here. This skips both
3310 over invisible text properties and overlays with
3311 invisible property. */
3312 newpos
= skip_invisible (IT_CHARPOS (*it
),
3313 &next_stop
, ZV
, it
->window
);
3315 /* If we skipped nothing at all we weren't at invisible
3316 text in the first place. If everything to the end of
3317 the buffer was skipped, end the loop. */
3318 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3322 /* We skipped some characters but not necessarily
3323 all there are. Check if we ended up on visible
3324 text. Fget_char_property returns the property of
3325 the char before the given position, i.e. if we
3326 get invis_p = 0, this means that the char at
3327 newpos is visible. */
3328 pos
= make_number (newpos
);
3329 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3330 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3333 /* If we ended up on invisible text, proceed to
3334 skip starting with next_stop. */
3336 IT_CHARPOS (*it
) = next_stop
;
3340 /* The position newpos is now either ZV or on visible text. */
3341 IT_CHARPOS (*it
) = newpos
;
3342 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3344 /* If there are before-strings at the start of invisible
3345 text, and the text is invisible because of a text
3346 property, arrange to show before-strings because 20.x did
3347 it that way. (If the text is invisible because of an
3348 overlay property instead of a text property, this is
3349 already handled in the overlay code.) */
3351 && get_overlay_strings (it
, start_charpos
))
3353 handled
= HANDLED_RECOMPUTE_PROPS
;
3354 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3356 else if (display_ellipsis_p
)
3357 setup_for_ellipsis (it
, 0);
3365 /* Make iterator IT return `...' next.
3366 Replaces LEN characters from buffer. */
3369 setup_for_ellipsis (it
, len
)
3373 /* Use the display table definition for `...'. Invalid glyphs
3374 will be handled by the method returning elements from dpvec. */
3375 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3377 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3378 it
->dpvec
= v
->contents
;
3379 it
->dpend
= v
->contents
+ v
->size
;
3383 /* Default `...'. */
3384 it
->dpvec
= default_invis_vector
;
3385 it
->dpend
= default_invis_vector
+ 3;
3388 it
->dpvec_char_len
= len
;
3389 it
->current
.dpvec_index
= 0;
3390 it
->dpvec_face_id
= -1;
3392 /* Remember the current face id in case glyphs specify faces.
3393 IT's face is restored in set_iterator_to_next.
3394 saved_face_id was set to preceding char's face in handle_stop. */
3395 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3396 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3398 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3404 /***********************************************************************
3406 ***********************************************************************/
3408 /* Set up iterator IT from `display' property at its current position.
3409 Called from handle_stop.
3410 We return HANDLED_RETURN if some part of the display property
3411 overrides the display of the buffer text itself.
3412 Otherwise we return HANDLED_NORMALLY. */
3414 static enum prop_handled
3415 handle_display_prop (it
)
3418 Lisp_Object prop
, object
;
3419 struct text_pos
*position
;
3420 /* Nonzero if some property replaces the display of the text itself. */
3421 int display_replaced_p
= 0;
3423 if (STRINGP (it
->string
))
3425 object
= it
->string
;
3426 position
= &it
->current
.string_pos
;
3430 object
= it
->w
->buffer
;
3431 position
= &it
->current
.pos
;
3434 /* Reset those iterator values set from display property values. */
3435 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3436 it
->space_width
= Qnil
;
3437 it
->font_height
= Qnil
;
3440 /* We don't support recursive `display' properties, i.e. string
3441 values that have a string `display' property, that have a string
3442 `display' property etc. */
3443 if (!it
->string_from_display_prop_p
)
3444 it
->area
= TEXT_AREA
;
3446 prop
= Fget_char_property (make_number (position
->charpos
),
3449 return HANDLED_NORMALLY
;
3452 /* Simple properties. */
3453 && !EQ (XCAR (prop
), Qimage
)
3454 && !EQ (XCAR (prop
), Qspace
)
3455 && !EQ (XCAR (prop
), Qwhen
)
3456 && !EQ (XCAR (prop
), Qslice
)
3457 && !EQ (XCAR (prop
), Qspace_width
)
3458 && !EQ (XCAR (prop
), Qheight
)
3459 && !EQ (XCAR (prop
), Qraise
)
3460 /* Marginal area specifications. */
3461 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3462 && !EQ (XCAR (prop
), Qleft_fringe
)
3463 && !EQ (XCAR (prop
), Qright_fringe
)
3464 && !NILP (XCAR (prop
)))
3466 for (; CONSP (prop
); prop
= XCDR (prop
))
3468 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3469 position
, display_replaced_p
))
3470 display_replaced_p
= 1;
3473 else if (VECTORP (prop
))
3476 for (i
= 0; i
< ASIZE (prop
); ++i
)
3477 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3478 position
, display_replaced_p
))
3479 display_replaced_p
= 1;
3483 int ret
= handle_single_display_spec (it
, prop
, object
, position
, 0);
3484 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3485 return HANDLED_RECOMPUTE_PROPS
;
3487 display_replaced_p
= 1;
3490 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3494 /* Value is the position of the end of the `display' property starting
3495 at START_POS in OBJECT. */
3497 static struct text_pos
3498 display_prop_end (it
, object
, start_pos
)
3501 struct text_pos start_pos
;
3504 struct text_pos end_pos
;
3506 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3507 Qdisplay
, object
, Qnil
);
3508 CHARPOS (end_pos
) = XFASTINT (end
);
3509 if (STRINGP (object
))
3510 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3512 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3518 /* Set up IT from a single `display' specification PROP. OBJECT
3519 is the object in which the `display' property was found. *POSITION
3520 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3521 means that we previously saw a display specification which already
3522 replaced text display with something else, for example an image;
3523 we ignore such properties after the first one has been processed.
3525 If PROP is a `space' or `image' specification, and in some other
3526 cases too, set *POSITION to the position where the `display'
3529 Value is non-zero if something was found which replaces the display
3530 of buffer or string text. Specifically, the value is -1 if that
3531 "something" is "nothing". */
3534 handle_single_display_spec (it
, spec
, object
, position
,
3535 display_replaced_before_p
)
3539 struct text_pos
*position
;
3540 int display_replaced_before_p
;
3543 Lisp_Object location
, value
;
3544 struct text_pos start_pos
;
3547 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3548 If the result is non-nil, use VALUE instead of SPEC. */
3550 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3559 if (!NILP (form
) && !EQ (form
, Qt
))
3561 int count
= SPECPDL_INDEX ();
3562 struct gcpro gcpro1
;
3564 /* Bind `object' to the object having the `display' property, a
3565 buffer or string. Bind `position' to the position in the
3566 object where the property was found, and `buffer-position'
3567 to the current position in the buffer. */
3568 specbind (Qobject
, object
);
3569 specbind (Qposition
, make_number (CHARPOS (*position
)));
3570 specbind (Qbuffer_position
,
3571 make_number (STRINGP (object
)
3572 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3574 form
= safe_eval (form
);
3576 unbind_to (count
, Qnil
);
3582 /* Handle `(height HEIGHT)' specifications. */
3584 && EQ (XCAR (spec
), Qheight
)
3585 && CONSP (XCDR (spec
)))
3587 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3590 it
->font_height
= XCAR (XCDR (spec
));
3591 if (!NILP (it
->font_height
))
3593 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3594 int new_height
= -1;
3596 if (CONSP (it
->font_height
)
3597 && (EQ (XCAR (it
->font_height
), Qplus
)
3598 || EQ (XCAR (it
->font_height
), Qminus
))
3599 && CONSP (XCDR (it
->font_height
))
3600 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3602 /* `(+ N)' or `(- N)' where N is an integer. */
3603 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3604 if (EQ (XCAR (it
->font_height
), Qplus
))
3606 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3608 else if (FUNCTIONP (it
->font_height
))
3610 /* Call function with current height as argument.
3611 Value is the new height. */
3613 height
= safe_call1 (it
->font_height
,
3614 face
->lface
[LFACE_HEIGHT_INDEX
]);
3615 if (NUMBERP (height
))
3616 new_height
= XFLOATINT (height
);
3618 else if (NUMBERP (it
->font_height
))
3620 /* Value is a multiple of the canonical char height. */
3623 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3624 new_height
= (XFLOATINT (it
->font_height
)
3625 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3629 /* Evaluate IT->font_height with `height' bound to the
3630 current specified height to get the new height. */
3631 int count
= SPECPDL_INDEX ();
3633 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3634 value
= safe_eval (it
->font_height
);
3635 unbind_to (count
, Qnil
);
3637 if (NUMBERP (value
))
3638 new_height
= XFLOATINT (value
);
3642 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3648 /* Handle `(space_width WIDTH)'. */
3650 && EQ (XCAR (spec
), Qspace_width
)
3651 && CONSP (XCDR (spec
)))
3653 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3656 value
= XCAR (XCDR (spec
));
3657 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3658 it
->space_width
= value
;
3663 /* Handle `(slice X Y WIDTH HEIGHT)'. */
3665 && EQ (XCAR (spec
), Qslice
))
3669 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3672 if (tem
= XCDR (spec
), CONSP (tem
))
3674 it
->slice
.x
= XCAR (tem
);
3675 if (tem
= XCDR (tem
), CONSP (tem
))
3677 it
->slice
.y
= XCAR (tem
);
3678 if (tem
= XCDR (tem
), CONSP (tem
))
3680 it
->slice
.width
= XCAR (tem
);
3681 if (tem
= XCDR (tem
), CONSP (tem
))
3682 it
->slice
.height
= XCAR (tem
);
3690 /* Handle `(raise FACTOR)'. */
3692 && EQ (XCAR (spec
), Qraise
)
3693 && CONSP (XCDR (spec
)))
3695 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3698 #ifdef HAVE_WINDOW_SYSTEM
3699 value
= XCAR (XCDR (spec
));
3700 if (NUMBERP (value
))
3702 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3703 it
->voffset
= - (XFLOATINT (value
)
3704 * (FONT_HEIGHT (face
->font
)));
3706 #endif /* HAVE_WINDOW_SYSTEM */
3711 /* Don't handle the other kinds of display specifications
3712 inside a string that we got from a `display' property. */
3713 if (it
->string_from_display_prop_p
)
3716 /* Characters having this form of property are not displayed, so
3717 we have to find the end of the property. */
3718 start_pos
= *position
;
3719 *position
= display_prop_end (it
, object
, start_pos
);
3722 /* Stop the scan at that end position--we assume that all
3723 text properties change there. */
3724 it
->stop_charpos
= position
->charpos
;
3726 /* Handle `(left-fringe BITMAP [FACE])'
3727 and `(right-fringe BITMAP [FACE])'. */
3729 && (EQ (XCAR (spec
), Qleft_fringe
)
3730 || EQ (XCAR (spec
), Qright_fringe
))
3731 && CONSP (XCDR (spec
)))
3733 int face_id
= DEFAULT_FACE_ID
;
3736 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3737 /* If we return here, POSITION has been advanced
3738 across the text with this property. */
3741 #ifdef HAVE_WINDOW_SYSTEM
3742 value
= XCAR (XCDR (spec
));
3743 if (!SYMBOLP (value
)
3744 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
3745 /* If we return here, POSITION has been advanced
3746 across the text with this property. */
3749 if (CONSP (XCDR (XCDR (spec
))))
3751 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
3752 int face_id2
= lookup_derived_face (it
->f
, face_name
,
3758 /* Save current settings of IT so that we can restore them
3759 when we are finished with the glyph property value. */
3763 it
->area
= TEXT_AREA
;
3764 it
->what
= IT_IMAGE
;
3765 it
->image_id
= -1; /* no image */
3766 it
->position
= start_pos
;
3767 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3768 it
->method
= GET_FROM_IMAGE
;
3769 it
->face_id
= face_id
;
3771 /* Say that we haven't consumed the characters with
3772 `display' property yet. The call to pop_it in
3773 set_iterator_to_next will clean this up. */
3774 *position
= start_pos
;
3776 if (EQ (XCAR (spec
), Qleft_fringe
))
3778 it
->left_user_fringe_bitmap
= fringe_bitmap
;
3779 it
->left_user_fringe_face_id
= face_id
;
3783 it
->right_user_fringe_bitmap
= fringe_bitmap
;
3784 it
->right_user_fringe_face_id
= face_id
;
3786 #endif /* HAVE_WINDOW_SYSTEM */
3790 /* Prepare to handle `((margin left-margin) ...)',
3791 `((margin right-margin) ...)' and `((margin nil) ...)'
3792 prefixes for display specifications. */
3793 location
= Qunbound
;
3794 if (CONSP (spec
) && CONSP (XCAR (spec
)))
3798 value
= XCDR (spec
);
3800 value
= XCAR (value
);
3803 if (EQ (XCAR (tem
), Qmargin
)
3804 && (tem
= XCDR (tem
),
3805 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3807 || EQ (tem
, Qleft_margin
)
3808 || EQ (tem
, Qright_margin
))))
3812 if (EQ (location
, Qunbound
))
3818 /* After this point, VALUE is the property after any
3819 margin prefix has been stripped. It must be a string,
3820 an image specification, or `(space ...)'.
3822 LOCATION specifies where to display: `left-margin',
3823 `right-margin' or nil. */
3825 valid_p
= (STRINGP (value
)
3826 #ifdef HAVE_WINDOW_SYSTEM
3827 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
3828 #endif /* not HAVE_WINDOW_SYSTEM */
3829 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
3831 if (valid_p
&& !display_replaced_before_p
)
3833 /* Save current settings of IT so that we can restore them
3834 when we are finished with the glyph property value. */
3837 if (NILP (location
))
3838 it
->area
= TEXT_AREA
;
3839 else if (EQ (location
, Qleft_margin
))
3840 it
->area
= LEFT_MARGIN_AREA
;
3842 it
->area
= RIGHT_MARGIN_AREA
;
3844 if (STRINGP (value
))
3846 if (SCHARS (value
) == 0)
3849 return -1; /* Replaced by "", i.e. nothing. */
3852 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3853 it
->current
.overlay_string_index
= -1;
3854 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3855 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3856 it
->method
= GET_FROM_STRING
;
3857 it
->stop_charpos
= 0;
3858 it
->string_from_display_prop_p
= 1;
3859 /* Say that we haven't consumed the characters with
3860 `display' property yet. The call to pop_it in
3861 set_iterator_to_next will clean this up. */
3862 *position
= start_pos
;
3864 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3866 it
->method
= GET_FROM_STRETCH
;
3868 it
->current
.pos
= it
->position
= start_pos
;
3870 #ifdef HAVE_WINDOW_SYSTEM
3873 it
->what
= IT_IMAGE
;
3874 it
->image_id
= lookup_image (it
->f
, value
);
3875 it
->position
= start_pos
;
3876 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3877 it
->method
= GET_FROM_IMAGE
;
3879 /* Say that we haven't consumed the characters with
3880 `display' property yet. The call to pop_it in
3881 set_iterator_to_next will clean this up. */
3882 *position
= start_pos
;
3884 #endif /* HAVE_WINDOW_SYSTEM */
3889 /* Invalid property or property not supported. Restore
3890 POSITION to what it was before. */
3891 *position
= start_pos
;
3896 /* Check if SPEC is a display specification value whose text should be
3897 treated as intangible. */
3900 single_display_spec_intangible_p (prop
)
3903 /* Skip over `when FORM'. */
3904 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3918 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3919 we don't need to treat text as intangible. */
3920 if (EQ (XCAR (prop
), Qmargin
))
3928 || EQ (XCAR (prop
), Qleft_margin
)
3929 || EQ (XCAR (prop
), Qright_margin
))
3933 return (CONSP (prop
)
3934 && (EQ (XCAR (prop
), Qimage
)
3935 || EQ (XCAR (prop
), Qspace
)));
3939 /* Check if PROP is a display property value whose text should be
3940 treated as intangible. */
3943 display_prop_intangible_p (prop
)
3947 && CONSP (XCAR (prop
))
3948 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3950 /* A list of sub-properties. */
3951 while (CONSP (prop
))
3953 if (single_display_spec_intangible_p (XCAR (prop
)))
3958 else if (VECTORP (prop
))
3960 /* A vector of sub-properties. */
3962 for (i
= 0; i
< ASIZE (prop
); ++i
)
3963 if (single_display_spec_intangible_p (AREF (prop
, i
)))
3967 return single_display_spec_intangible_p (prop
);
3973 /* Return 1 if PROP is a display sub-property value containing STRING. */
3976 single_display_spec_string_p (prop
, string
)
3977 Lisp_Object prop
, string
;
3979 if (EQ (string
, prop
))
3982 /* Skip over `when FORM'. */
3983 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3992 /* Skip over `margin LOCATION'. */
3993 if (EQ (XCAR (prop
), Qmargin
))
4004 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4008 /* Return 1 if STRING appears in the `display' property PROP. */
4011 display_prop_string_p (prop
, string
)
4012 Lisp_Object prop
, string
;
4015 && CONSP (XCAR (prop
))
4016 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4018 /* A list of sub-properties. */
4019 while (CONSP (prop
))
4021 if (single_display_spec_string_p (XCAR (prop
), string
))
4026 else if (VECTORP (prop
))
4028 /* A vector of sub-properties. */
4030 for (i
= 0; i
< ASIZE (prop
); ++i
)
4031 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4035 return single_display_spec_string_p (prop
, string
);
4041 /* Determine from which buffer position in W's buffer STRING comes
4042 from. AROUND_CHARPOS is an approximate position where it could
4043 be from. Value is the buffer position or 0 if it couldn't be
4046 W's buffer must be current.
4048 This function is necessary because we don't record buffer positions
4049 in glyphs generated from strings (to keep struct glyph small).
4050 This function may only use code that doesn't eval because it is
4051 called asynchronously from note_mouse_highlight. */
4054 string_buffer_position (w
, string
, around_charpos
)
4059 Lisp_Object limit
, prop
, pos
;
4060 const int MAX_DISTANCE
= 1000;
4063 pos
= make_number (around_charpos
);
4064 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4065 while (!found
&& !EQ (pos
, limit
))
4067 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4068 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4071 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4076 pos
= make_number (around_charpos
);
4077 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4078 while (!found
&& !EQ (pos
, limit
))
4080 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4081 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4084 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4089 return found
? XINT (pos
) : 0;
4094 /***********************************************************************
4095 `composition' property
4096 ***********************************************************************/
4098 static enum prop_handled
4099 handle_auto_composed_prop (it
)
4102 enum prop_handled handled
= HANDLED_NORMALLY
;
4104 if (FUNCTIONP (Vauto_composition_function
))
4107 EMACS_INT pos
, this_pos
;
4109 if (STRINGP (it
->string
))
4110 pos
= IT_STRING_CHARPOS (*it
);
4112 pos
= IT_CHARPOS (*it
);
4115 val
=Fget_char_property (make_number (pos
), Qauto_composed
, it
->string
);
4118 Lisp_Object limit
= Qnil
, next
;
4120 /* As Fnext_single_char_property_change is very slow, we
4121 limit the search to the current line. */
4122 if (STRINGP (it
->string
))
4123 limit
= make_number (SCHARS (it
->string
));
4125 limit
= make_number (find_next_newline_no_quit (pos
, 1));
4127 next
= (Fnext_single_property_change
4128 (make_number (pos
), Qauto_composed
, it
->string
, limit
));
4129 if (XINT (next
) < XINT (limit
))
4131 /* The current point is auto-composed, but there exist
4132 characters not yet composed beyond the auto-composed
4133 region. There's a possiblity that the last
4134 characters in the region may be newly composed. */
4135 int charpos
= XINT (next
) - 1, bytepos
, c
;
4137 if (STRINGP (it
->string
))
4139 bytepos
= string_char_to_byte (it
->string
, charpos
);
4140 c
= SDATA (it
->string
)[bytepos
];
4144 bytepos
= CHAR_TO_BYTE (charpos
);
4145 c
= FETCH_BYTE (bytepos
);
4148 /* If the last character is not newline, it may be
4149 composed with the following characters. */
4150 val
= Qnil
, pos
= charpos
+ 1;
4155 int count
= SPECPDL_INDEX ();
4156 Lisp_Object args
[3];
4158 args
[0] = Vauto_composition_function
;
4159 specbind (Qauto_composition_function
, Qnil
);
4160 args
[1] = make_number (pos
);
4161 args
[2] = it
->string
;
4162 safe_call (3, args
);
4163 unbind_to (count
, Qnil
);
4165 if (this_pos
== pos
)
4167 val
= Fget_char_property (args
[1], Qauto_composed
, it
->string
);
4168 /* Return HANDLED_RECOMPUTE_PROPS only if function composed
4169 something. This avoids an endless loop if they failed to
4170 fontify the text for which reason ever. */
4172 handled
= HANDLED_RECOMPUTE_PROPS
;
4175 handled
= HANDLED_RECOMPUTE_PROPS
;
4182 /* Set up iterator IT from `composition' property at its current
4183 position. Called from handle_stop. */
4185 static enum prop_handled
4186 handle_composition_prop (it
)
4189 Lisp_Object prop
, string
;
4190 EMACS_INT pos
, pos_byte
, start
, end
;
4191 enum prop_handled handled
= HANDLED_NORMALLY
;
4193 if (STRINGP (it
->string
))
4195 pos
= IT_STRING_CHARPOS (*it
);
4196 pos_byte
= IT_STRING_BYTEPOS (*it
);
4197 string
= it
->string
;
4201 pos
= IT_CHARPOS (*it
);
4202 pos_byte
= IT_BYTEPOS (*it
);
4206 /* If there's a valid composition and point is not inside of the
4207 composition (in the case that the composition is from the current
4208 buffer), draw a glyph composed from the composition components. */
4209 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4210 && COMPOSITION_VALID_P (start
, end
, prop
)
4211 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4217 if (STRINGP (it
->string
))
4218 pos_byte
= string_char_to_byte (it
->string
, start
);
4220 pos_byte
= CHAR_TO_BYTE (start
);
4222 id
= get_composition_id (start
, pos_byte
, end
- start
, prop
, string
);
4226 it
->method
= GET_FROM_COMPOSITION
;
4228 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4229 /* For a terminal, draw only the first character of the
4231 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4232 it
->len
= (STRINGP (it
->string
)
4233 ? string_char_to_byte (it
->string
, end
)
4234 : CHAR_TO_BYTE (end
)) - pos_byte
;
4235 it
->stop_charpos
= end
;
4236 handled
= HANDLED_RETURN
;
4245 /***********************************************************************
4247 ***********************************************************************/
4249 /* The following structure is used to record overlay strings for
4250 later sorting in load_overlay_strings. */
4252 struct overlay_entry
4254 Lisp_Object overlay
;
4261 /* Set up iterator IT from overlay strings at its current position.
4262 Called from handle_stop. */
4264 static enum prop_handled
4265 handle_overlay_change (it
)
4268 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4269 return HANDLED_RECOMPUTE_PROPS
;
4271 return HANDLED_NORMALLY
;
4275 /* Set up the next overlay string for delivery by IT, if there is an
4276 overlay string to deliver. Called by set_iterator_to_next when the
4277 end of the current overlay string is reached. If there are more
4278 overlay strings to display, IT->string and
4279 IT->current.overlay_string_index are set appropriately here.
4280 Otherwise IT->string is set to nil. */
4283 next_overlay_string (it
)
4286 ++it
->current
.overlay_string_index
;
4287 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4289 /* No more overlay strings. Restore IT's settings to what
4290 they were before overlay strings were processed, and
4291 continue to deliver from current_buffer. */
4292 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4295 xassert (it
->stop_charpos
>= BEGV
4296 && it
->stop_charpos
<= it
->end_charpos
);
4298 it
->current
.overlay_string_index
= -1;
4299 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4300 it
->n_overlay_strings
= 0;
4301 it
->method
= GET_FROM_BUFFER
;
4303 /* If we're at the end of the buffer, record that we have
4304 processed the overlay strings there already, so that
4305 next_element_from_buffer doesn't try it again. */
4306 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4307 it
->overlay_strings_at_end_processed_p
= 1;
4309 /* If we have to display `...' for invisible text, set
4310 the iterator up for that. */
4311 if (display_ellipsis_p
)
4312 setup_for_ellipsis (it
, 0);
4316 /* There are more overlay strings to process. If
4317 IT->current.overlay_string_index has advanced to a position
4318 where we must load IT->overlay_strings with more strings, do
4320 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4322 if (it
->current
.overlay_string_index
&& i
== 0)
4323 load_overlay_strings (it
, 0);
4325 /* Initialize IT to deliver display elements from the overlay
4327 it
->string
= it
->overlay_strings
[i
];
4328 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4329 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4330 it
->method
= GET_FROM_STRING
;
4331 it
->stop_charpos
= 0;
4338 /* Compare two overlay_entry structures E1 and E2. Used as a
4339 comparison function for qsort in load_overlay_strings. Overlay
4340 strings for the same position are sorted so that
4342 1. All after-strings come in front of before-strings, except
4343 when they come from the same overlay.
4345 2. Within after-strings, strings are sorted so that overlay strings
4346 from overlays with higher priorities come first.
4348 2. Within before-strings, strings are sorted so that overlay
4349 strings from overlays with higher priorities come last.
4351 Value is analogous to strcmp. */
4355 compare_overlay_entries (e1
, e2
)
4358 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4359 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4362 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4364 /* Let after-strings appear in front of before-strings if
4365 they come from different overlays. */
4366 if (EQ (entry1
->overlay
, entry2
->overlay
))
4367 result
= entry1
->after_string_p
? 1 : -1;
4369 result
= entry1
->after_string_p
? -1 : 1;
4371 else if (entry1
->after_string_p
)
4372 /* After-strings sorted in order of decreasing priority. */
4373 result
= entry2
->priority
- entry1
->priority
;
4375 /* Before-strings sorted in order of increasing priority. */
4376 result
= entry1
->priority
- entry2
->priority
;
4382 /* Load the vector IT->overlay_strings with overlay strings from IT's
4383 current buffer position, or from CHARPOS if that is > 0. Set
4384 IT->n_overlays to the total number of overlay strings found.
4386 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4387 a time. On entry into load_overlay_strings,
4388 IT->current.overlay_string_index gives the number of overlay
4389 strings that have already been loaded by previous calls to this
4392 IT->add_overlay_start contains an additional overlay start
4393 position to consider for taking overlay strings from, if non-zero.
4394 This position comes into play when the overlay has an `invisible'
4395 property, and both before and after-strings. When we've skipped to
4396 the end of the overlay, because of its `invisible' property, we
4397 nevertheless want its before-string to appear.
4398 IT->add_overlay_start will contain the overlay start position
4401 Overlay strings are sorted so that after-string strings come in
4402 front of before-string strings. Within before and after-strings,
4403 strings are sorted by overlay priority. See also function
4404 compare_overlay_entries. */
4407 load_overlay_strings (it
, charpos
)
4411 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4412 Lisp_Object overlay
, window
, str
, invisible
;
4413 struct Lisp_Overlay
*ov
;
4416 int n
= 0, i
, j
, invis_p
;
4417 struct overlay_entry
*entries
4418 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4421 charpos
= IT_CHARPOS (*it
);
4423 /* Append the overlay string STRING of overlay OVERLAY to vector
4424 `entries' which has size `size' and currently contains `n'
4425 elements. AFTER_P non-zero means STRING is an after-string of
4427 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4430 Lisp_Object priority; \
4434 int new_size = 2 * size; \
4435 struct overlay_entry *old = entries; \
4437 (struct overlay_entry *) alloca (new_size \
4438 * sizeof *entries); \
4439 bcopy (old, entries, size * sizeof *entries); \
4443 entries[n].string = (STRING); \
4444 entries[n].overlay = (OVERLAY); \
4445 priority = Foverlay_get ((OVERLAY), Qpriority); \
4446 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4447 entries[n].after_string_p = (AFTER_P); \
4452 /* Process overlay before the overlay center. */
4453 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4455 XSETMISC (overlay
, ov
);
4456 xassert (OVERLAYP (overlay
));
4457 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4458 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4463 /* Skip this overlay if it doesn't start or end at IT's current
4465 if (end
!= charpos
&& start
!= charpos
)
4468 /* Skip this overlay if it doesn't apply to IT->w. */
4469 window
= Foverlay_get (overlay
, Qwindow
);
4470 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4473 /* If the text ``under'' the overlay is invisible, both before-
4474 and after-strings from this overlay are visible; start and
4475 end position are indistinguishable. */
4476 invisible
= Foverlay_get (overlay
, Qinvisible
);
4477 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4479 /* If overlay has a non-empty before-string, record it. */
4480 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4481 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4483 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4485 /* If overlay has a non-empty after-string, record it. */
4486 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4487 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4489 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4492 /* Process overlays after the overlay center. */
4493 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4495 XSETMISC (overlay
, ov
);
4496 xassert (OVERLAYP (overlay
));
4497 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4498 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4500 if (start
> charpos
)
4503 /* Skip this overlay if it doesn't start or end at IT's current
4505 if (end
!= charpos
&& start
!= charpos
)
4508 /* Skip this overlay if it doesn't apply to IT->w. */
4509 window
= Foverlay_get (overlay
, Qwindow
);
4510 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4513 /* If the text ``under'' the overlay is invisible, it has a zero
4514 dimension, and both before- and after-strings apply. */
4515 invisible
= Foverlay_get (overlay
, Qinvisible
);
4516 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4518 /* If overlay has a non-empty before-string, record it. */
4519 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4520 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4522 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4524 /* If overlay has a non-empty after-string, record it. */
4525 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4526 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4528 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4531 #undef RECORD_OVERLAY_STRING
4535 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4537 /* Record the total number of strings to process. */
4538 it
->n_overlay_strings
= n
;
4540 /* IT->current.overlay_string_index is the number of overlay strings
4541 that have already been consumed by IT. Copy some of the
4542 remaining overlay strings to IT->overlay_strings. */
4544 j
= it
->current
.overlay_string_index
;
4545 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4546 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4552 /* Get the first chunk of overlay strings at IT's current buffer
4553 position, or at CHARPOS if that is > 0. Value is non-zero if at
4554 least one overlay string was found. */
4557 get_overlay_strings (it
, charpos
)
4561 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4562 process. This fills IT->overlay_strings with strings, and sets
4563 IT->n_overlay_strings to the total number of strings to process.
4564 IT->pos.overlay_string_index has to be set temporarily to zero
4565 because load_overlay_strings needs this; it must be set to -1
4566 when no overlay strings are found because a zero value would
4567 indicate a position in the first overlay string. */
4568 it
->current
.overlay_string_index
= 0;
4569 load_overlay_strings (it
, charpos
);
4571 /* If we found overlay strings, set up IT to deliver display
4572 elements from the first one. Otherwise set up IT to deliver
4573 from current_buffer. */
4574 if (it
->n_overlay_strings
)
4576 /* Make sure we know settings in current_buffer, so that we can
4577 restore meaningful values when we're done with the overlay
4579 compute_stop_pos (it
);
4580 xassert (it
->face_id
>= 0);
4582 /* Save IT's settings. They are restored after all overlay
4583 strings have been processed. */
4584 xassert (it
->sp
== 0);
4587 /* Set up IT to deliver display elements from the first overlay
4589 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4590 it
->string
= it
->overlay_strings
[0];
4591 it
->stop_charpos
= 0;
4592 xassert (STRINGP (it
->string
));
4593 it
->end_charpos
= SCHARS (it
->string
);
4594 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4595 it
->method
= GET_FROM_STRING
;
4600 it
->current
.overlay_string_index
= -1;
4601 it
->method
= GET_FROM_BUFFER
;
4606 /* Value is non-zero if we found at least one overlay string. */
4607 return STRINGP (it
->string
);
4612 /***********************************************************************
4613 Saving and restoring state
4614 ***********************************************************************/
4616 /* Save current settings of IT on IT->stack. Called, for example,
4617 before setting up IT for an overlay string, to be able to restore
4618 IT's settings to what they were after the overlay string has been
4625 struct iterator_stack_entry
*p
;
4627 xassert (it
->sp
< 2);
4628 p
= it
->stack
+ it
->sp
;
4630 p
->stop_charpos
= it
->stop_charpos
;
4631 xassert (it
->face_id
>= 0);
4632 p
->face_id
= it
->face_id
;
4633 p
->string
= it
->string
;
4634 p
->pos
= it
->current
;
4635 p
->end_charpos
= it
->end_charpos
;
4636 p
->string_nchars
= it
->string_nchars
;
4638 p
->multibyte_p
= it
->multibyte_p
;
4639 p
->slice
= it
->slice
;
4640 p
->space_width
= it
->space_width
;
4641 p
->font_height
= it
->font_height
;
4642 p
->voffset
= it
->voffset
;
4643 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4644 p
->display_ellipsis_p
= 0;
4649 /* Restore IT's settings from IT->stack. Called, for example, when no
4650 more overlay strings must be processed, and we return to delivering
4651 display elements from a buffer, or when the end of a string from a
4652 `display' property is reached and we return to delivering display
4653 elements from an overlay string, or from a buffer. */
4659 struct iterator_stack_entry
*p
;
4661 xassert (it
->sp
> 0);
4663 p
= it
->stack
+ it
->sp
;
4664 it
->stop_charpos
= p
->stop_charpos
;
4665 it
->face_id
= p
->face_id
;
4666 it
->string
= p
->string
;
4667 it
->current
= p
->pos
;
4668 it
->end_charpos
= p
->end_charpos
;
4669 it
->string_nchars
= p
->string_nchars
;
4671 it
->multibyte_p
= p
->multibyte_p
;
4672 it
->slice
= p
->slice
;
4673 it
->space_width
= p
->space_width
;
4674 it
->font_height
= p
->font_height
;
4675 it
->voffset
= p
->voffset
;
4676 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4681 /***********************************************************************
4683 ***********************************************************************/
4685 /* Set IT's current position to the previous line start. */
4688 back_to_previous_line_start (it
)
4691 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4692 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4696 /* Move IT to the next line start.
4698 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4699 we skipped over part of the text (as opposed to moving the iterator
4700 continuously over the text). Otherwise, don't change the value
4703 Newlines may come from buffer text, overlay strings, or strings
4704 displayed via the `display' property. That's the reason we can't
4705 simply use find_next_newline_no_quit.
4707 Note that this function may not skip over invisible text that is so
4708 because of text properties and immediately follows a newline. If
4709 it would, function reseat_at_next_visible_line_start, when called
4710 from set_iterator_to_next, would effectively make invisible
4711 characters following a newline part of the wrong glyph row, which
4712 leads to wrong cursor motion. */
4715 forward_to_next_line_start (it
, skipped_p
)
4719 int old_selective
, newline_found_p
, n
;
4720 const int MAX_NEWLINE_DISTANCE
= 500;
4722 /* If already on a newline, just consume it to avoid unintended
4723 skipping over invisible text below. */
4724 if (it
->what
== IT_CHARACTER
4726 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4728 set_iterator_to_next (it
, 0);
4733 /* Don't handle selective display in the following. It's (a)
4734 unnecessary because it's done by the caller, and (b) leads to an
4735 infinite recursion because next_element_from_ellipsis indirectly
4736 calls this function. */
4737 old_selective
= it
->selective
;
4740 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4741 from buffer text. */
4742 for (n
= newline_found_p
= 0;
4743 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4744 n
+= STRINGP (it
->string
) ? 0 : 1)
4746 if (!get_next_display_element (it
))
4748 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4749 set_iterator_to_next (it
, 0);
4752 /* If we didn't find a newline near enough, see if we can use a
4754 if (!newline_found_p
)
4756 int start
= IT_CHARPOS (*it
);
4757 int limit
= find_next_newline_no_quit (start
, 1);
4760 xassert (!STRINGP (it
->string
));
4762 /* If there isn't any `display' property in sight, and no
4763 overlays, we can just use the position of the newline in
4765 if (it
->stop_charpos
>= limit
4766 || ((pos
= Fnext_single_property_change (make_number (start
),
4768 Qnil
, make_number (limit
)),
4770 && next_overlay_change (start
) == ZV
))
4772 IT_CHARPOS (*it
) = limit
;
4773 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4774 *skipped_p
= newline_found_p
= 1;
4778 while (get_next_display_element (it
)
4779 && !newline_found_p
)
4781 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4782 set_iterator_to_next (it
, 0);
4787 it
->selective
= old_selective
;
4788 return newline_found_p
;
4792 /* Set IT's current position to the previous visible line start. Skip
4793 invisible text that is so either due to text properties or due to
4794 selective display. Caution: this does not change IT->current_x and
4798 back_to_previous_visible_line_start (it
)
4801 while (IT_CHARPOS (*it
) > BEGV
)
4803 back_to_previous_line_start (it
);
4804 if (IT_CHARPOS (*it
) <= BEGV
)
4807 /* If selective > 0, then lines indented more than that values
4809 if (it
->selective
> 0
4810 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4811 (double) it
->selective
)) /* iftc */
4814 /* Check the newline before point for invisibility. */
4817 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
4818 Qinvisible
, it
->window
);
4819 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4823 /* If newline has a display property that replaces the newline with something
4824 else (image or text), find start of overlay or interval and continue search
4826 if (IT_CHARPOS (*it
) > BEGV
)
4828 struct it it2
= *it
;
4831 Lisp_Object val
, overlay
;
4833 pos
= --IT_CHARPOS (it2
);
4836 if (handle_display_prop (&it2
) == HANDLED_RETURN
4837 && !NILP (val
= get_char_property_and_overlay
4838 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
4839 && (OVERLAYP (overlay
)
4840 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
4841 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
4845 IT_CHARPOS (*it
) = beg
;
4846 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
4854 xassert (IT_CHARPOS (*it
) >= BEGV
);
4855 xassert (IT_CHARPOS (*it
) == BEGV
4856 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4861 /* Reseat iterator IT at the previous visible line start. Skip
4862 invisible text that is so either due to text properties or due to
4863 selective display. At the end, update IT's overlay information,
4864 face information etc. */
4867 reseat_at_previous_visible_line_start (it
)
4870 back_to_previous_visible_line_start (it
);
4871 reseat (it
, it
->current
.pos
, 1);
4876 /* Reseat iterator IT on the next visible line start in the current
4877 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4878 preceding the line start. Skip over invisible text that is so
4879 because of selective display. Compute faces, overlays etc at the
4880 new position. Note that this function does not skip over text that
4881 is invisible because of text properties. */
4884 reseat_at_next_visible_line_start (it
, on_newline_p
)
4888 int newline_found_p
, skipped_p
= 0;
4890 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4892 /* Skip over lines that are invisible because they are indented
4893 more than the value of IT->selective. */
4894 if (it
->selective
> 0)
4895 while (IT_CHARPOS (*it
) < ZV
4896 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4897 (double) it
->selective
)) /* iftc */
4899 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4900 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4903 /* Position on the newline if that's what's requested. */
4904 if (on_newline_p
&& newline_found_p
)
4906 if (STRINGP (it
->string
))
4908 if (IT_STRING_CHARPOS (*it
) > 0)
4910 --IT_STRING_CHARPOS (*it
);
4911 --IT_STRING_BYTEPOS (*it
);
4914 else if (IT_CHARPOS (*it
) > BEGV
)
4918 reseat (it
, it
->current
.pos
, 0);
4922 reseat (it
, it
->current
.pos
, 0);
4929 /***********************************************************************
4930 Changing an iterator's position
4931 ***********************************************************************/
4933 /* Change IT's current position to POS in current_buffer. If FORCE_P
4934 is non-zero, always check for text properties at the new position.
4935 Otherwise, text properties are only looked up if POS >=
4936 IT->check_charpos of a property. */
4939 reseat (it
, pos
, force_p
)
4941 struct text_pos pos
;
4944 int original_pos
= IT_CHARPOS (*it
);
4946 reseat_1 (it
, pos
, 0);
4948 /* Determine where to check text properties. Avoid doing it
4949 where possible because text property lookup is very expensive. */
4951 || CHARPOS (pos
) > it
->stop_charpos
4952 || CHARPOS (pos
) < original_pos
)
4959 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4960 IT->stop_pos to POS, also. */
4963 reseat_1 (it
, pos
, set_stop_p
)
4965 struct text_pos pos
;
4968 /* Don't call this function when scanning a C string. */
4969 xassert (it
->s
== NULL
);
4971 /* POS must be a reasonable value. */
4972 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4974 it
->current
.pos
= it
->position
= pos
;
4975 XSETBUFFER (it
->object
, current_buffer
);
4976 it
->end_charpos
= ZV
;
4978 it
->current
.dpvec_index
= -1;
4979 it
->current
.overlay_string_index
= -1;
4980 IT_STRING_CHARPOS (*it
) = -1;
4981 IT_STRING_BYTEPOS (*it
) = -1;
4983 it
->method
= GET_FROM_BUFFER
;
4984 /* RMS: I added this to fix a bug in move_it_vertically_backward
4985 where it->area continued to relate to the starting point
4986 for the backward motion. Bug report from
4987 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
4988 However, I am not sure whether reseat still does the right thing
4989 in general after this change. */
4990 it
->area
= TEXT_AREA
;
4991 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4993 it
->face_before_selective_p
= 0;
4996 it
->stop_charpos
= CHARPOS (pos
);
5000 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5001 If S is non-null, it is a C string to iterate over. Otherwise,
5002 STRING gives a Lisp string to iterate over.
5004 If PRECISION > 0, don't return more then PRECISION number of
5005 characters from the string.
5007 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5008 characters have been returned. FIELD_WIDTH < 0 means an infinite
5011 MULTIBYTE = 0 means disable processing of multibyte characters,
5012 MULTIBYTE > 0 means enable it,
5013 MULTIBYTE < 0 means use IT->multibyte_p.
5015 IT must be initialized via a prior call to init_iterator before
5016 calling this function. */
5019 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5024 int precision
, field_width
, multibyte
;
5026 /* No region in strings. */
5027 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5029 /* No text property checks performed by default, but see below. */
5030 it
->stop_charpos
= -1;
5032 /* Set iterator position and end position. */
5033 bzero (&it
->current
, sizeof it
->current
);
5034 it
->current
.overlay_string_index
= -1;
5035 it
->current
.dpvec_index
= -1;
5036 xassert (charpos
>= 0);
5038 /* If STRING is specified, use its multibyteness, otherwise use the
5039 setting of MULTIBYTE, if specified. */
5041 it
->multibyte_p
= multibyte
> 0;
5045 xassert (STRINGP (string
));
5046 it
->string
= string
;
5048 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5049 it
->method
= GET_FROM_STRING
;
5050 it
->current
.string_pos
= string_pos (charpos
, string
);
5057 /* Note that we use IT->current.pos, not it->current.string_pos,
5058 for displaying C strings. */
5059 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5060 if (it
->multibyte_p
)
5062 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5063 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5067 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5068 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5071 it
->method
= GET_FROM_C_STRING
;
5074 /* PRECISION > 0 means don't return more than PRECISION characters
5076 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5077 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5079 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5080 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5081 FIELD_WIDTH < 0 means infinite field width. This is useful for
5082 padding with `-' at the end of a mode line. */
5083 if (field_width
< 0)
5084 field_width
= INFINITY
;
5085 if (field_width
> it
->end_charpos
- charpos
)
5086 it
->end_charpos
= charpos
+ field_width
;
5088 /* Use the standard display table for displaying strings. */
5089 if (DISP_TABLE_P (Vstandard_display_table
))
5090 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5092 it
->stop_charpos
= charpos
;
5098 /***********************************************************************
5100 ***********************************************************************/
5102 /* Map enum it_method value to corresponding next_element_from_* function. */
5104 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5106 next_element_from_buffer
,
5107 next_element_from_display_vector
,
5108 next_element_from_composition
,
5109 next_element_from_string
,
5110 next_element_from_c_string
,
5111 next_element_from_image
,
5112 next_element_from_stretch
5116 /* Load IT's display element fields with information about the next
5117 display element from the current position of IT. Value is zero if
5118 end of buffer (or C string) is reached. */
5121 get_next_display_element (it
)
5124 /* Non-zero means that we found a display element. Zero means that
5125 we hit the end of what we iterate over. Performance note: the
5126 function pointer `method' used here turns out to be faster than
5127 using a sequence of if-statements. */
5131 success_p
= (*get_next_element
[it
->method
]) (it
);
5133 if (it
->what
== IT_CHARACTER
)
5135 /* Map via display table or translate control characters.
5136 IT->c, IT->len etc. have been set to the next character by
5137 the function call above. If we have a display table, and it
5138 contains an entry for IT->c, translate it. Don't do this if
5139 IT->c itself comes from a display table, otherwise we could
5140 end up in an infinite recursion. (An alternative could be to
5141 count the recursion depth of this function and signal an
5142 error when a certain maximum depth is reached.) Is it worth
5144 if (success_p
&& it
->dpvec
== NULL
)
5149 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5152 struct Lisp_Vector
*v
= XVECTOR (dv
);
5154 /* Return the first character from the display table
5155 entry, if not empty. If empty, don't display the
5156 current character. */
5159 it
->dpvec_char_len
= it
->len
;
5160 it
->dpvec
= v
->contents
;
5161 it
->dpend
= v
->contents
+ v
->size
;
5162 it
->current
.dpvec_index
= 0;
5163 it
->dpvec_face_id
= -1;
5164 it
->saved_face_id
= it
->face_id
;
5165 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5170 set_iterator_to_next (it
, 0);
5175 /* Translate control characters into `\003' or `^C' form.
5176 Control characters coming from a display table entry are
5177 currently not translated because we use IT->dpvec to hold
5178 the translation. This could easily be changed but I
5179 don't believe that it is worth doing.
5181 If it->multibyte_p is nonzero, non-printable non-ASCII
5182 characters are also translated to octal form.
5184 If it->multibyte_p is zero, eight-bit characters that
5185 don't have corresponding multibyte char code are also
5186 translated to octal form. */
5187 else if ((it
->c
< ' '
5188 ? (it
->area
!= TEXT_AREA
5189 /* In mode line, treat \n, \t like other crl chars. */
5191 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5192 || (it
->c
!= '\n' && it
->c
!= '\t'))
5194 ? (!CHAR_PRINTABLE_P (it
->c
)
5195 || (!NILP (Vnobreak_char_display
)
5196 && (it
->c
== 0xA0 /* NO-BREAK SPACE */
5197 || it
->c
== 0xAD /* SOFT HYPHEN */)))
5199 && (! unibyte_display_via_language_environment
5200 || (UNIBYTE_CHAR_HAS_MULTIBYTE_P (it
->c
)))))))
5202 /* IT->c is a control character which must be displayed
5203 either as '\003' or as `^C' where the '\\' and '^'
5204 can be defined in the display table. Fill
5205 IT->ctl_chars with glyphs for what we have to
5206 display. Then, set IT->dpvec to these glyphs. */
5209 int face_id
, lface_id
= 0 ;
5212 /* Handle control characters with ^. */
5214 if (it
->c
< 128 && it
->ctl_arrow_p
)
5216 g
= '^'; /* default glyph for Control */
5217 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5219 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5220 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5222 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5223 lface_id
= FAST_GLYPH_FACE (g
);
5227 g
= FAST_GLYPH_CHAR (g
);
5228 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5233 /* Merge the escape-glyph face into the current face. */
5234 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5238 XSETINT (it
->ctl_chars
[0], g
);
5240 XSETINT (it
->ctl_chars
[1], g
);
5242 goto display_control
;
5245 /* Handle non-break space in the mode where it only gets
5248 if (EQ (Vnobreak_char_display
, Qt
)
5251 /* Merge the no-break-space face into the current face. */
5252 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5256 XSETINT (it
->ctl_chars
[0], g
);
5258 goto display_control
;
5261 /* Handle sequences that start with the "escape glyph". */
5263 /* the default escape glyph is \. */
5264 escape_glyph
= '\\';
5267 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5268 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5270 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5271 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5275 /* The display table specified a face.
5276 Merge it into face_id and also into escape_glyph. */
5277 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5278 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5283 /* Merge the escape-glyph face into the current face. */
5284 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5288 /* Handle soft hyphens in the mode where they only get
5291 if (EQ (Vnobreak_char_display
, Qt
)
5295 XSETINT (it
->ctl_chars
[0], g
);
5297 goto display_control
;
5300 /* Handle non-break space and soft hyphen
5301 with the escape glyph. */
5303 if (it
->c
== 0xA0 || it
->c
== 0xAD)
5305 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5306 g
= it
->c
= (it
->c
== 0xA0 ? ' ' : '-');
5307 XSETINT (it
->ctl_chars
[1], g
);
5309 goto display_control
;
5313 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5317 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5318 if (CHAR_BYTE8_P (it
->c
))
5320 str
[0] = CHAR_TO_BYTE8 (it
->c
);
5323 else if (it
->c
< 256)
5330 /* It's an invalid character, which shouldn't
5331 happen actually, but due to bugs it may
5332 happen. Let's print the char as is, there's
5333 not much meaningful we can do with it. */
5335 str
[1] = it
->c
>> 8;
5336 str
[2] = it
->c
>> 16;
5337 str
[3] = it
->c
>> 24;
5341 for (i
= 0; i
< len
; i
++)
5343 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5344 /* Insert three more glyphs into IT->ctl_chars for
5345 the octal display of the character. */
5346 g
= ((str
[i
] >> 6) & 7) + '0';
5347 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5348 g
= ((str
[i
] >> 3) & 7) + '0';
5349 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5350 g
= (str
[i
] & 7) + '0';
5351 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5357 /* Set up IT->dpvec and return first character from it. */
5358 it
->dpvec_char_len
= it
->len
;
5359 it
->dpvec
= it
->ctl_chars
;
5360 it
->dpend
= it
->dpvec
+ ctl_len
;
5361 it
->current
.dpvec_index
= 0;
5362 it
->dpvec_face_id
= face_id
;
5363 it
->saved_face_id
= it
->face_id
;
5364 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5370 /* Adjust face id for a multibyte character. There are no
5371 multibyte character in unibyte text. */
5374 && FRAME_WINDOW_P (it
->f
))
5376 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5377 int pos
= (it
->s
? -1
5378 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
5379 : IT_CHARPOS (*it
));
5381 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
, pos
, it
->string
);
5385 /* Is this character the last one of a run of characters with
5386 box? If yes, set IT->end_of_box_run_p to 1. */
5393 it
->end_of_box_run_p
5394 = ((face_id
= face_after_it_pos (it
),
5395 face_id
!= it
->face_id
)
5396 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5397 face
->box
== FACE_NO_BOX
));
5400 /* Value is 0 if end of buffer or string reached. */
5405 /* Move IT to the next display element.
5407 RESEAT_P non-zero means if called on a newline in buffer text,
5408 skip to the next visible line start.
5410 Functions get_next_display_element and set_iterator_to_next are
5411 separate because I find this arrangement easier to handle than a
5412 get_next_display_element function that also increments IT's
5413 position. The way it is we can first look at an iterator's current
5414 display element, decide whether it fits on a line, and if it does,
5415 increment the iterator position. The other way around we probably
5416 would either need a flag indicating whether the iterator has to be
5417 incremented the next time, or we would have to implement a
5418 decrement position function which would not be easy to write. */
5421 set_iterator_to_next (it
, reseat_p
)
5425 /* Reset flags indicating start and end of a sequence of characters
5426 with box. Reset them at the start of this function because
5427 moving the iterator to a new position might set them. */
5428 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5432 case GET_FROM_BUFFER
:
5433 /* The current display element of IT is a character from
5434 current_buffer. Advance in the buffer, and maybe skip over
5435 invisible lines that are so because of selective display. */
5436 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5437 reseat_at_next_visible_line_start (it
, 0);
5440 xassert (it
->len
!= 0);
5441 IT_BYTEPOS (*it
) += it
->len
;
5442 IT_CHARPOS (*it
) += 1;
5443 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5447 case GET_FROM_COMPOSITION
:
5448 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5449 if (STRINGP (it
->string
))
5451 IT_STRING_BYTEPOS (*it
) += it
->len
;
5452 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5453 it
->method
= GET_FROM_STRING
;
5454 goto consider_string_end
;
5458 IT_BYTEPOS (*it
) += it
->len
;
5459 IT_CHARPOS (*it
) += it
->cmp_len
;
5460 it
->method
= GET_FROM_BUFFER
;
5464 case GET_FROM_C_STRING
:
5465 /* Current display element of IT is from a C string. */
5466 IT_BYTEPOS (*it
) += it
->len
;
5467 IT_CHARPOS (*it
) += 1;
5470 case GET_FROM_DISPLAY_VECTOR
:
5471 /* Current display element of IT is from a display table entry.
5472 Advance in the display table definition. Reset it to null if
5473 end reached, and continue with characters from buffers/
5475 ++it
->current
.dpvec_index
;
5477 /* Restore face of the iterator to what they were before the
5478 display vector entry (these entries may contain faces). */
5479 it
->face_id
= it
->saved_face_id
;
5481 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5484 it
->method
= GET_FROM_C_STRING
;
5485 else if (STRINGP (it
->string
))
5486 it
->method
= GET_FROM_STRING
;
5488 it
->method
= GET_FROM_BUFFER
;
5491 it
->current
.dpvec_index
= -1;
5493 /* Skip over characters which were displayed via IT->dpvec. */
5494 if (it
->dpvec_char_len
< 0)
5495 reseat_at_next_visible_line_start (it
, 1);
5496 else if (it
->dpvec_char_len
> 0)
5498 it
->len
= it
->dpvec_char_len
;
5499 set_iterator_to_next (it
, reseat_p
);
5502 /* Recheck faces after display vector */
5503 it
->stop_charpos
= IT_CHARPOS (*it
);
5507 case GET_FROM_STRING
:
5508 /* Current display element is a character from a Lisp string. */
5509 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5510 IT_STRING_BYTEPOS (*it
) += it
->len
;
5511 IT_STRING_CHARPOS (*it
) += 1;
5513 consider_string_end
:
5515 if (it
->current
.overlay_string_index
>= 0)
5517 /* IT->string is an overlay string. Advance to the
5518 next, if there is one. */
5519 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5520 next_overlay_string (it
);
5524 /* IT->string is not an overlay string. If we reached
5525 its end, and there is something on IT->stack, proceed
5526 with what is on the stack. This can be either another
5527 string, this time an overlay string, or a buffer. */
5528 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5532 if (STRINGP (it
->string
))
5533 goto consider_string_end
;
5534 it
->method
= GET_FROM_BUFFER
;
5539 case GET_FROM_IMAGE
:
5540 case GET_FROM_STRETCH
:
5541 /* The position etc with which we have to proceed are on
5542 the stack. The position may be at the end of a string,
5543 if the `display' property takes up the whole string. */
5544 xassert (it
->sp
> 0);
5547 if (STRINGP (it
->string
))
5549 it
->method
= GET_FROM_STRING
;
5550 goto consider_string_end
;
5552 it
->method
= GET_FROM_BUFFER
;
5556 /* There are no other methods defined, so this should be a bug. */
5560 xassert (it
->method
!= GET_FROM_STRING
5561 || (STRINGP (it
->string
)
5562 && IT_STRING_CHARPOS (*it
) >= 0));
5565 /* Load IT's display element fields with information about the next
5566 display element which comes from a display table entry or from the
5567 result of translating a control character to one of the forms `^C'
5570 IT->dpvec holds the glyphs to return as characters.
5571 IT->saved_face_id holds the face id before the display vector--
5572 it is restored into IT->face_idin set_iterator_to_next. */
5575 next_element_from_display_vector (it
)
5579 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5581 it
->face_id
= it
->saved_face_id
;
5583 if (INTEGERP (*it
->dpvec
)
5584 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5588 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5589 it
->c
= FAST_GLYPH_CHAR (g
);
5590 it
->len
= CHAR_BYTES (it
->c
);
5592 /* The entry may contain a face id to use. Such a face id is
5593 the id of a Lisp face, not a realized face. A face id of
5594 zero means no face is specified. */
5595 if (it
->dpvec_face_id
>= 0)
5596 it
->face_id
= it
->dpvec_face_id
;
5599 int lface_id
= FAST_GLYPH_FACE (g
);
5601 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5606 /* Display table entry is invalid. Return a space. */
5607 it
->c
= ' ', it
->len
= 1;
5609 /* Don't change position and object of the iterator here. They are
5610 still the values of the character that had this display table
5611 entry or was translated, and that's what we want. */
5612 it
->what
= IT_CHARACTER
;
5617 /* Load IT with the next display element from Lisp string IT->string.
5618 IT->current.string_pos is the current position within the string.
5619 If IT->current.overlay_string_index >= 0, the Lisp string is an
5623 next_element_from_string (it
)
5626 struct text_pos position
;
5628 xassert (STRINGP (it
->string
));
5629 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5630 position
= it
->current
.string_pos
;
5632 /* Time to check for invisible text? */
5633 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5634 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5638 /* Since a handler may have changed IT->method, we must
5640 return get_next_display_element (it
);
5643 if (it
->current
.overlay_string_index
>= 0)
5645 /* Get the next character from an overlay string. In overlay
5646 strings, There is no field width or padding with spaces to
5648 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5653 else if (STRING_MULTIBYTE (it
->string
))
5655 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5656 const unsigned char *s
= (SDATA (it
->string
)
5657 + IT_STRING_BYTEPOS (*it
));
5658 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5662 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5668 /* Get the next character from a Lisp string that is not an
5669 overlay string. Such strings come from the mode line, for
5670 example. We may have to pad with spaces, or truncate the
5671 string. See also next_element_from_c_string. */
5672 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5677 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5679 /* Pad with spaces. */
5680 it
->c
= ' ', it
->len
= 1;
5681 CHARPOS (position
) = BYTEPOS (position
) = -1;
5683 else if (STRING_MULTIBYTE (it
->string
))
5685 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5686 const unsigned char *s
= (SDATA (it
->string
)
5687 + IT_STRING_BYTEPOS (*it
));
5688 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5692 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5697 /* Record what we have and where it came from. Note that we store a
5698 buffer position in IT->position although it could arguably be a
5700 it
->what
= IT_CHARACTER
;
5701 it
->object
= it
->string
;
5702 it
->position
= position
;
5707 /* Load IT with next display element from C string IT->s.
5708 IT->string_nchars is the maximum number of characters to return
5709 from the string. IT->end_charpos may be greater than
5710 IT->string_nchars when this function is called, in which case we
5711 may have to return padding spaces. Value is zero if end of string
5712 reached, including padding spaces. */
5715 next_element_from_c_string (it
)
5721 it
->what
= IT_CHARACTER
;
5722 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5725 /* IT's position can be greater IT->string_nchars in case a field
5726 width or precision has been specified when the iterator was
5728 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5730 /* End of the game. */
5734 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5736 /* Pad with spaces. */
5737 it
->c
= ' ', it
->len
= 1;
5738 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5740 else if (it
->multibyte_p
)
5742 /* Implementation note: The calls to strlen apparently aren't a
5743 performance problem because there is no noticeable performance
5744 difference between Emacs running in unibyte or multibyte mode. */
5745 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5746 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5750 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5756 /* Set up IT to return characters from an ellipsis, if appropriate.
5757 The definition of the ellipsis glyphs may come from a display table
5758 entry. This function Fills IT with the first glyph from the
5759 ellipsis if an ellipsis is to be displayed. */
5762 next_element_from_ellipsis (it
)
5765 if (it
->selective_display_ellipsis_p
)
5766 setup_for_ellipsis (it
, it
->len
);
5769 /* The face at the current position may be different from the
5770 face we find after the invisible text. Remember what it
5771 was in IT->saved_face_id, and signal that it's there by
5772 setting face_before_selective_p. */
5773 it
->saved_face_id
= it
->face_id
;
5774 it
->method
= GET_FROM_BUFFER
;
5775 reseat_at_next_visible_line_start (it
, 1);
5776 it
->face_before_selective_p
= 1;
5779 return get_next_display_element (it
);
5783 /* Deliver an image display element. The iterator IT is already
5784 filled with image information (done in handle_display_prop). Value
5789 next_element_from_image (it
)
5792 it
->what
= IT_IMAGE
;
5797 /* Fill iterator IT with next display element from a stretch glyph
5798 property. IT->object is the value of the text property. Value is
5802 next_element_from_stretch (it
)
5805 it
->what
= IT_STRETCH
;
5810 /* Load IT with the next display element from current_buffer. Value
5811 is zero if end of buffer reached. IT->stop_charpos is the next
5812 position at which to stop and check for text properties or buffer
5816 next_element_from_buffer (it
)
5821 /* Check this assumption, otherwise, we would never enter the
5822 if-statement, below. */
5823 xassert (IT_CHARPOS (*it
) >= BEGV
5824 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
5826 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
5828 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5830 int overlay_strings_follow_p
;
5832 /* End of the game, except when overlay strings follow that
5833 haven't been returned yet. */
5834 if (it
->overlay_strings_at_end_processed_p
)
5835 overlay_strings_follow_p
= 0;
5838 it
->overlay_strings_at_end_processed_p
= 1;
5839 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
5842 if (overlay_strings_follow_p
)
5843 success_p
= get_next_display_element (it
);
5847 it
->position
= it
->current
.pos
;
5854 return get_next_display_element (it
);
5859 /* No face changes, overlays etc. in sight, so just return a
5860 character from current_buffer. */
5863 /* Maybe run the redisplay end trigger hook. Performance note:
5864 This doesn't seem to cost measurable time. */
5865 if (it
->redisplay_end_trigger_charpos
5867 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
5868 run_redisplay_end_trigger_hook (it
);
5870 /* Get the next character, maybe multibyte. */
5871 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
5872 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
5874 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
5875 - IT_BYTEPOS (*it
));
5876 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
5879 it
->c
= *p
, it
->len
= 1;
5881 /* Record what we have and where it came from. */
5882 it
->what
= IT_CHARACTER
;;
5883 it
->object
= it
->w
->buffer
;
5884 it
->position
= it
->current
.pos
;
5886 /* Normally we return the character found above, except when we
5887 really want to return an ellipsis for selective display. */
5892 /* A value of selective > 0 means hide lines indented more
5893 than that number of columns. */
5894 if (it
->selective
> 0
5895 && IT_CHARPOS (*it
) + 1 < ZV
5896 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
5897 IT_BYTEPOS (*it
) + 1,
5898 (double) it
->selective
)) /* iftc */
5900 success_p
= next_element_from_ellipsis (it
);
5901 it
->dpvec_char_len
= -1;
5904 else if (it
->c
== '\r' && it
->selective
== -1)
5906 /* A value of selective == -1 means that everything from the
5907 CR to the end of the line is invisible, with maybe an
5908 ellipsis displayed for it. */
5909 success_p
= next_element_from_ellipsis (it
);
5910 it
->dpvec_char_len
= -1;
5915 /* Value is zero if end of buffer reached. */
5916 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
5921 /* Run the redisplay end trigger hook for IT. */
5924 run_redisplay_end_trigger_hook (it
)
5927 Lisp_Object args
[3];
5929 /* IT->glyph_row should be non-null, i.e. we should be actually
5930 displaying something, or otherwise we should not run the hook. */
5931 xassert (it
->glyph_row
);
5933 /* Set up hook arguments. */
5934 args
[0] = Qredisplay_end_trigger_functions
;
5935 args
[1] = it
->window
;
5936 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
5937 it
->redisplay_end_trigger_charpos
= 0;
5939 /* Since we are *trying* to run these functions, don't try to run
5940 them again, even if they get an error. */
5941 it
->w
->redisplay_end_trigger
= Qnil
;
5942 Frun_hook_with_args (3, args
);
5944 /* Notice if it changed the face of the character we are on. */
5945 handle_face_prop (it
);
5949 /* Deliver a composition display element. The iterator IT is already
5950 filled with composition information (done in
5951 handle_composition_prop). Value is always 1. */
5954 next_element_from_composition (it
)
5957 it
->what
= IT_COMPOSITION
;
5958 it
->position
= (STRINGP (it
->string
)
5959 ? it
->current
.string_pos
5966 /***********************************************************************
5967 Moving an iterator without producing glyphs
5968 ***********************************************************************/
5970 /* Check if iterator is at a position corresponding to a valid buffer
5971 position after some move_it_ call. */
5973 #define IT_POS_VALID_AFTER_MOVE_P(it) \
5974 ((it)->method == GET_FROM_STRING \
5975 ? IT_STRING_CHARPOS (*it) == 0 \
5979 /* Move iterator IT to a specified buffer or X position within one
5980 line on the display without producing glyphs.
5982 OP should be a bit mask including some or all of these bits:
5983 MOVE_TO_X: Stop on reaching x-position TO_X.
5984 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5985 Regardless of OP's value, stop in reaching the end of the display line.
5987 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5988 This means, in particular, that TO_X includes window's horizontal
5991 The return value has several possible values that
5992 say what condition caused the scan to stop:
5994 MOVE_POS_MATCH_OR_ZV
5995 - when TO_POS or ZV was reached.
5998 -when TO_X was reached before TO_POS or ZV were reached.
6001 - when we reached the end of the display area and the line must
6005 - when we reached the end of the display area and the line is
6009 - when we stopped at a line end, i.e. a newline or a CR and selective
6012 static enum move_it_result
6013 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
6015 int to_charpos
, to_x
, op
;
6017 enum move_it_result result
= MOVE_UNDEFINED
;
6018 struct glyph_row
*saved_glyph_row
;
6020 /* Don't produce glyphs in produce_glyphs. */
6021 saved_glyph_row
= it
->glyph_row
;
6022 it
->glyph_row
= NULL
;
6024 #define BUFFER_POS_REACHED_P() \
6025 ((op & MOVE_TO_POS) != 0 \
6026 && BUFFERP (it->object) \
6027 && IT_CHARPOS (*it) >= to_charpos \
6028 && (it->method == GET_FROM_BUFFER \
6029 || (it->method == GET_FROM_DISPLAY_VECTOR \
6030 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6035 int x
, i
, ascent
= 0, descent
= 0;
6037 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
6038 if ((op
& MOVE_TO_POS
) != 0
6039 && BUFFERP (it
->object
)
6040 && it
->method
== GET_FROM_BUFFER
6041 && IT_CHARPOS (*it
) > to_charpos
)
6043 result
= MOVE_POS_MATCH_OR_ZV
;
6047 /* Stop when ZV reached.
6048 We used to stop here when TO_CHARPOS reached as well, but that is
6049 too soon if this glyph does not fit on this line. So we handle it
6050 explicitly below. */
6051 if (!get_next_display_element (it
)
6052 || (it
->truncate_lines_p
6053 && BUFFER_POS_REACHED_P ()))
6055 result
= MOVE_POS_MATCH_OR_ZV
;
6059 /* The call to produce_glyphs will get the metrics of the
6060 display element IT is loaded with. We record in x the
6061 x-position before this display element in case it does not
6065 /* Remember the line height so far in case the next element doesn't
6067 if (!it
->truncate_lines_p
)
6069 ascent
= it
->max_ascent
;
6070 descent
= it
->max_descent
;
6073 PRODUCE_GLYPHS (it
);
6075 if (it
->area
!= TEXT_AREA
)
6077 set_iterator_to_next (it
, 1);
6081 /* The number of glyphs we get back in IT->nglyphs will normally
6082 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6083 character on a terminal frame, or (iii) a line end. For the
6084 second case, IT->nglyphs - 1 padding glyphs will be present
6085 (on X frames, there is only one glyph produced for a
6086 composite character.
6088 The behavior implemented below means, for continuation lines,
6089 that as many spaces of a TAB as fit on the current line are
6090 displayed there. For terminal frames, as many glyphs of a
6091 multi-glyph character are displayed in the current line, too.
6092 This is what the old redisplay code did, and we keep it that
6093 way. Under X, the whole shape of a complex character must
6094 fit on the line or it will be completely displayed in the
6097 Note that both for tabs and padding glyphs, all glyphs have
6101 /* More than one glyph or glyph doesn't fit on line. All
6102 glyphs have the same width. */
6103 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6106 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6108 new_x
= x
+ single_glyph_width
;
6110 /* We want to leave anything reaching TO_X to the caller. */
6111 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6113 if (BUFFER_POS_REACHED_P ())
6114 goto buffer_pos_reached
;
6116 result
= MOVE_X_REACHED
;
6119 else if (/* Lines are continued. */
6120 !it
->truncate_lines_p
6121 && (/* And glyph doesn't fit on the line. */
6122 new_x
> it
->last_visible_x
6123 /* Or it fits exactly and we're on a window
6125 || (new_x
== it
->last_visible_x
6126 && FRAME_WINDOW_P (it
->f
))))
6128 if (/* IT->hpos == 0 means the very first glyph
6129 doesn't fit on the line, e.g. a wide image. */
6131 || (new_x
== it
->last_visible_x
6132 && FRAME_WINDOW_P (it
->f
)))
6135 it
->current_x
= new_x
;
6136 if (i
== it
->nglyphs
- 1)
6138 set_iterator_to_next (it
, 1);
6139 #ifdef HAVE_WINDOW_SYSTEM
6140 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6142 if (!get_next_display_element (it
))
6144 result
= MOVE_POS_MATCH_OR_ZV
;
6147 if (BUFFER_POS_REACHED_P ())
6149 if (ITERATOR_AT_END_OF_LINE_P (it
))
6150 result
= MOVE_POS_MATCH_OR_ZV
;
6152 result
= MOVE_LINE_CONTINUED
;
6155 if (ITERATOR_AT_END_OF_LINE_P (it
))
6157 result
= MOVE_NEWLINE_OR_CR
;
6161 #endif /* HAVE_WINDOW_SYSTEM */
6167 it
->max_ascent
= ascent
;
6168 it
->max_descent
= descent
;
6171 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6173 result
= MOVE_LINE_CONTINUED
;
6176 else if (BUFFER_POS_REACHED_P ())
6177 goto buffer_pos_reached
;
6178 else if (new_x
> it
->first_visible_x
)
6180 /* Glyph is visible. Increment number of glyphs that
6181 would be displayed. */
6186 /* Glyph is completely off the left margin of the display
6187 area. Nothing to do. */
6191 if (result
!= MOVE_UNDEFINED
)
6194 else if (BUFFER_POS_REACHED_P ())
6198 it
->max_ascent
= ascent
;
6199 it
->max_descent
= descent
;
6200 result
= MOVE_POS_MATCH_OR_ZV
;
6203 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6205 /* Stop when TO_X specified and reached. This check is
6206 necessary here because of lines consisting of a line end,
6207 only. The line end will not produce any glyphs and we
6208 would never get MOVE_X_REACHED. */
6209 xassert (it
->nglyphs
== 0);
6210 result
= MOVE_X_REACHED
;
6214 /* Is this a line end? If yes, we're done. */
6215 if (ITERATOR_AT_END_OF_LINE_P (it
))
6217 result
= MOVE_NEWLINE_OR_CR
;
6221 /* The current display element has been consumed. Advance
6223 set_iterator_to_next (it
, 1);
6225 /* Stop if lines are truncated and IT's current x-position is
6226 past the right edge of the window now. */
6227 if (it
->truncate_lines_p
6228 && it
->current_x
>= it
->last_visible_x
)
6230 #ifdef HAVE_WINDOW_SYSTEM
6231 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6233 if (!get_next_display_element (it
)
6234 || BUFFER_POS_REACHED_P ())
6236 result
= MOVE_POS_MATCH_OR_ZV
;
6239 if (ITERATOR_AT_END_OF_LINE_P (it
))
6241 result
= MOVE_NEWLINE_OR_CR
;
6245 #endif /* HAVE_WINDOW_SYSTEM */
6246 result
= MOVE_LINE_TRUNCATED
;
6251 #undef BUFFER_POS_REACHED_P
6253 /* Restore the iterator settings altered at the beginning of this
6255 it
->glyph_row
= saved_glyph_row
;
6260 /* Move IT forward until it satisfies one or more of the criteria in
6261 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6263 OP is a bit-mask that specifies where to stop, and in particular,
6264 which of those four position arguments makes a difference. See the
6265 description of enum move_operation_enum.
6267 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6268 screen line, this function will set IT to the next position >
6272 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6274 int to_charpos
, to_x
, to_y
, to_vpos
;
6277 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6283 if (op
& MOVE_TO_VPOS
)
6285 /* If no TO_CHARPOS and no TO_X specified, stop at the
6286 start of the line TO_VPOS. */
6287 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6289 if (it
->vpos
== to_vpos
)
6295 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6299 /* TO_VPOS >= 0 means stop at TO_X in the line at
6300 TO_VPOS, or at TO_POS, whichever comes first. */
6301 if (it
->vpos
== to_vpos
)
6307 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6309 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6314 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6316 /* We have reached TO_X but not in the line we want. */
6317 skip
= move_it_in_display_line_to (it
, to_charpos
,
6319 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6327 else if (op
& MOVE_TO_Y
)
6329 struct it it_backup
;
6331 /* TO_Y specified means stop at TO_X in the line containing
6332 TO_Y---or at TO_CHARPOS if this is reached first. The
6333 problem is that we can't really tell whether the line
6334 contains TO_Y before we have completely scanned it, and
6335 this may skip past TO_X. What we do is to first scan to
6338 If TO_X is not specified, use a TO_X of zero. The reason
6339 is to make the outcome of this function more predictable.
6340 If we didn't use TO_X == 0, we would stop at the end of
6341 the line which is probably not what a caller would expect
6343 skip
= move_it_in_display_line_to (it
, to_charpos
,
6347 | (op
& MOVE_TO_POS
)));
6349 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6350 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6356 /* If TO_X was reached, we would like to know whether TO_Y
6357 is in the line. This can only be said if we know the
6358 total line height which requires us to scan the rest of
6360 if (skip
== MOVE_X_REACHED
)
6362 /* Wait! We can conclude that TO_Y is in the line if
6363 the already scanned glyphs make the line tall enough
6364 because further scanning doesn't make it shorter. */
6365 line_height
= it
->max_ascent
+ it
->max_descent
;
6366 if (to_y
>= it
->current_y
6367 && to_y
< it
->current_y
+ line_height
)
6373 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6374 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6376 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6379 /* Now, decide whether TO_Y is in this line. */
6380 line_height
= it
->max_ascent
+ it
->max_descent
;
6381 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6383 if (to_y
>= it
->current_y
6384 && to_y
< it
->current_y
+ line_height
)
6386 if (skip
== MOVE_X_REACHED
)
6387 /* If TO_Y is in this line and TO_X was reached above,
6388 we scanned too far. We have to restore IT's settings
6389 to the ones before skipping. */
6393 else if (skip
== MOVE_X_REACHED
)
6396 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6404 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6408 case MOVE_POS_MATCH_OR_ZV
:
6412 case MOVE_NEWLINE_OR_CR
:
6413 set_iterator_to_next (it
, 1);
6414 it
->continuation_lines_width
= 0;
6417 case MOVE_LINE_TRUNCATED
:
6418 it
->continuation_lines_width
= 0;
6419 reseat_at_next_visible_line_start (it
, 0);
6420 if ((op
& MOVE_TO_POS
) != 0
6421 && IT_CHARPOS (*it
) > to_charpos
)
6428 case MOVE_LINE_CONTINUED
:
6429 it
->continuation_lines_width
+= it
->current_x
;
6436 /* Reset/increment for the next run. */
6437 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6438 it
->current_x
= it
->hpos
= 0;
6439 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6441 last_height
= it
->max_ascent
+ it
->max_descent
;
6442 last_max_ascent
= it
->max_ascent
;
6443 it
->max_ascent
= it
->max_descent
= 0;
6448 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6452 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6454 If DY > 0, move IT backward at least that many pixels. DY = 0
6455 means move IT backward to the preceding line start or BEGV. This
6456 function may move over more than DY pixels if IT->current_y - DY
6457 ends up in the middle of a line; in this case IT->current_y will be
6458 set to the top of the line moved to. */
6461 move_it_vertically_backward (it
, dy
)
6472 start_pos
= IT_CHARPOS (*it
);
6474 /* Estimate how many newlines we must move back. */
6475 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6477 /* Set the iterator's position that many lines back. */
6478 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6479 back_to_previous_visible_line_start (it
);
6481 /* Reseat the iterator here. When moving backward, we don't want
6482 reseat to skip forward over invisible text, set up the iterator
6483 to deliver from overlay strings at the new position etc. So,
6484 use reseat_1 here. */
6485 reseat_1 (it
, it
->current
.pos
, 1);
6487 /* We are now surely at a line start. */
6488 it
->current_x
= it
->hpos
= 0;
6489 it
->continuation_lines_width
= 0;
6491 /* Move forward and see what y-distance we moved. First move to the
6492 start of the next line so that we get its height. We need this
6493 height to be able to tell whether we reached the specified
6496 it2
.max_ascent
= it2
.max_descent
= 0;
6499 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6500 MOVE_TO_POS
| MOVE_TO_VPOS
);
6502 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
6503 xassert (IT_CHARPOS (*it
) >= BEGV
);
6506 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6507 xassert (IT_CHARPOS (*it
) >= BEGV
);
6508 /* H is the actual vertical distance from the position in *IT
6509 and the starting position. */
6510 h
= it2
.current_y
- it
->current_y
;
6511 /* NLINES is the distance in number of lines. */
6512 nlines
= it2
.vpos
- it
->vpos
;
6514 /* Correct IT's y and vpos position
6515 so that they are relative to the starting point. */
6521 /* DY == 0 means move to the start of the screen line. The
6522 value of nlines is > 0 if continuation lines were involved. */
6524 move_it_by_lines (it
, nlines
, 1);
6526 /* I think this assert is bogus if buffer contains
6527 invisible text or images. KFS. */
6528 xassert (IT_CHARPOS (*it
) <= start_pos
);
6533 /* The y-position we try to reach, relative to *IT.
6534 Note that H has been subtracted in front of the if-statement. */
6535 int target_y
= it
->current_y
+ h
- dy
;
6536 int y0
= it3
.current_y
;
6537 int y1
= line_bottom_y (&it3
);
6538 int line_height
= y1
- y0
;
6540 /* If we did not reach target_y, try to move further backward if
6541 we can. If we moved too far backward, try to move forward. */
6542 if (target_y
< it
->current_y
6543 /* This is heuristic. In a window that's 3 lines high, with
6544 a line height of 13 pixels each, recentering with point
6545 on the bottom line will try to move -39/2 = 19 pixels
6546 backward. Try to avoid moving into the first line. */
6547 && (it
->current_y
- target_y
6548 > min (window_box_height (it
->w
), line_height
* 2 / 3))
6549 && IT_CHARPOS (*it
) > BEGV
)
6551 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6552 target_y
- it
->current_y
));
6553 dy
= it
->current_y
- target_y
;
6554 goto move_further_back
;
6556 else if (target_y
>= it
->current_y
+ line_height
6557 && IT_CHARPOS (*it
) < ZV
)
6559 /* Should move forward by at least one line, maybe more.
6561 Note: Calling move_it_by_lines can be expensive on
6562 terminal frames, where compute_motion is used (via
6563 vmotion) to do the job, when there are very long lines
6564 and truncate-lines is nil. That's the reason for
6565 treating terminal frames specially here. */
6567 if (!FRAME_WINDOW_P (it
->f
))
6568 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6573 move_it_by_lines (it
, 1, 1);
6575 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6579 /* I think this assert is bogus if buffer contains
6580 invisible text or images. KFS. */
6581 xassert (IT_CHARPOS (*it
) >= BEGV
);
6588 /* Move IT by a specified amount of pixel lines DY. DY negative means
6589 move backwards. DY = 0 means move to start of screen line. At the
6590 end, IT will be on the start of a screen line. */
6593 move_it_vertically (it
, dy
)
6598 move_it_vertically_backward (it
, -dy
);
6601 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6602 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6603 MOVE_TO_POS
| MOVE_TO_Y
);
6604 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6606 /* If buffer ends in ZV without a newline, move to the start of
6607 the line to satisfy the post-condition. */
6608 if (IT_CHARPOS (*it
) == ZV
6609 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6610 move_it_by_lines (it
, 0, 0);
6615 /* Move iterator IT past the end of the text line it is in. */
6618 move_it_past_eol (it
)
6621 enum move_it_result rc
;
6623 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6624 if (rc
== MOVE_NEWLINE_OR_CR
)
6625 set_iterator_to_next (it
, 0);
6629 #if 0 /* Currently not used. */
6631 /* Return non-zero if some text between buffer positions START_CHARPOS
6632 and END_CHARPOS is invisible. IT->window is the window for text
6636 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6638 int start_charpos
, end_charpos
;
6640 Lisp_Object prop
, limit
;
6641 int invisible_found_p
;
6643 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6645 /* Is text at START invisible? */
6646 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6648 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6649 invisible_found_p
= 1;
6652 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6654 make_number (end_charpos
));
6655 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6658 return invisible_found_p
;
6664 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6665 negative means move up. DVPOS == 0 means move to the start of the
6666 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6667 NEED_Y_P is zero, IT->current_y will be left unchanged.
6669 Further optimization ideas: If we would know that IT->f doesn't use
6670 a face with proportional font, we could be faster for
6671 truncate-lines nil. */
6674 move_it_by_lines (it
, dvpos
, need_y_p
)
6676 int dvpos
, need_y_p
;
6678 struct position pos
;
6680 if (!FRAME_WINDOW_P (it
->f
))
6682 struct text_pos textpos
;
6684 /* We can use vmotion on frames without proportional fonts. */
6685 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6686 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6687 reseat (it
, textpos
, 1);
6688 it
->vpos
+= pos
.vpos
;
6689 it
->current_y
+= pos
.vpos
;
6691 else if (dvpos
== 0)
6693 /* DVPOS == 0 means move to the start of the screen line. */
6694 move_it_vertically_backward (it
, 0);
6695 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6696 /* Let next call to line_bottom_y calculate real line height */
6701 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6702 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
6703 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
6708 int start_charpos
, i
;
6710 /* Start at the beginning of the screen line containing IT's
6711 position. This may actually move vertically backwards,
6712 in case of overlays, so adjust dvpos accordingly. */
6714 move_it_vertically_backward (it
, 0);
6717 /* Go back -DVPOS visible lines and reseat the iterator there. */
6718 start_charpos
= IT_CHARPOS (*it
);
6719 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
6720 back_to_previous_visible_line_start (it
);
6721 reseat (it
, it
->current
.pos
, 1);
6723 /* Move further back if we end up in a string or an image. */
6724 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
6726 /* First try to move to start of display line. */
6728 move_it_vertically_backward (it
, 0);
6730 if (IT_POS_VALID_AFTER_MOVE_P (it
))
6732 /* If start of line is still in string or image,
6733 move further back. */
6734 back_to_previous_visible_line_start (it
);
6735 reseat (it
, it
->current
.pos
, 1);
6739 it
->current_x
= it
->hpos
= 0;
6741 /* Above call may have moved too far if continuation lines
6742 are involved. Scan forward and see if it did. */
6744 it2
.vpos
= it2
.current_y
= 0;
6745 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6746 it
->vpos
-= it2
.vpos
;
6747 it
->current_y
-= it2
.current_y
;
6748 it
->current_x
= it
->hpos
= 0;
6750 /* If we moved too far back, move IT some lines forward. */
6751 if (it2
.vpos
> -dvpos
)
6753 int delta
= it2
.vpos
+ dvpos
;
6755 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6756 /* Move back again if we got too far ahead. */
6757 if (IT_CHARPOS (*it
) >= start_charpos
)
6763 /* Return 1 if IT points into the middle of a display vector. */
6766 in_display_vector_p (it
)
6769 return (it
->method
== GET_FROM_DISPLAY_VECTOR
6770 && it
->current
.dpvec_index
> 0
6771 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6775 /***********************************************************************
6777 ***********************************************************************/
6780 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6784 add_to_log (format
, arg1
, arg2
)
6786 Lisp_Object arg1
, arg2
;
6788 Lisp_Object args
[3];
6789 Lisp_Object msg
, fmt
;
6792 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6795 /* Do nothing if called asynchronously. Inserting text into
6796 a buffer may call after-change-functions and alike and
6797 that would means running Lisp asynchronously. */
6798 if (handling_signal
)
6802 GCPRO4 (fmt
, msg
, arg1
, arg2
);
6804 args
[0] = fmt
= build_string (format
);
6807 msg
= Fformat (3, args
);
6809 len
= SBYTES (msg
) + 1;
6810 SAFE_ALLOCA (buffer
, char *, len
);
6811 bcopy (SDATA (msg
), buffer
, len
);
6813 message_dolog (buffer
, len
- 1, 1, 0);
6820 /* Output a newline in the *Messages* buffer if "needs" one. */
6823 message_log_maybe_newline ()
6825 if (message_log_need_newline
)
6826 message_dolog ("", 0, 1, 0);
6830 /* Add a string M of length NBYTES to the message log, optionally
6831 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
6832 nonzero, means interpret the contents of M as multibyte. This
6833 function calls low-level routines in order to bypass text property
6834 hooks, etc. which might not be safe to run. */
6837 message_dolog (m
, nbytes
, nlflag
, multibyte
)
6839 int nbytes
, nlflag
, multibyte
;
6841 if (!NILP (Vmemory_full
))
6844 if (!NILP (Vmessage_log_max
))
6846 struct buffer
*oldbuf
;
6847 Lisp_Object oldpoint
, oldbegv
, oldzv
;
6848 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6849 int point_at_end
= 0;
6851 Lisp_Object old_deactivate_mark
, tem
;
6852 struct gcpro gcpro1
;
6854 old_deactivate_mark
= Vdeactivate_mark
;
6855 oldbuf
= current_buffer
;
6856 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
6857 current_buffer
->undo_list
= Qt
;
6859 oldpoint
= message_dolog_marker1
;
6860 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
6861 oldbegv
= message_dolog_marker2
;
6862 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
6863 oldzv
= message_dolog_marker3
;
6864 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
6865 GCPRO1 (old_deactivate_mark
);
6873 BEGV_BYTE
= BEG_BYTE
;
6876 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6878 /* Insert the string--maybe converting multibyte to single byte
6879 or vice versa, so that all the text fits the buffer. */
6881 && NILP (current_buffer
->enable_multibyte_characters
))
6883 int i
, c
, char_bytes
;
6884 unsigned char work
[1];
6886 /* Convert a multibyte string to single-byte
6887 for the *Message* buffer. */
6888 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
6890 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
6891 work
[0] = (ASCII_CHAR_P (c
)
6893 : multibyte_char_to_unibyte (c
, Qnil
));
6894 insert_1_both (work
, 1, 1, 1, 0, 0);
6897 else if (! multibyte
6898 && ! NILP (current_buffer
->enable_multibyte_characters
))
6900 int i
, c
, char_bytes
;
6901 unsigned char *msg
= (unsigned char *) m
;
6902 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6903 /* Convert a single-byte string to multibyte
6904 for the *Message* buffer. */
6905 for (i
= 0; i
< nbytes
; i
++)
6908 c
= unibyte_char_to_multibyte (c
);
6909 char_bytes
= CHAR_STRING (c
, str
);
6910 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
6914 insert_1 (m
, nbytes
, 1, 0, 0);
6918 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
6919 insert_1 ("\n", 1, 1, 0, 0);
6921 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6923 this_bol_byte
= PT_BYTE
;
6925 /* See if this line duplicates the previous one.
6926 If so, combine duplicates. */
6929 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6931 prev_bol_byte
= PT_BYTE
;
6933 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
6934 this_bol
, this_bol_byte
);
6937 del_range_both (prev_bol
, prev_bol_byte
,
6938 this_bol
, this_bol_byte
, 0);
6944 /* If you change this format, don't forget to also
6945 change message_log_check_duplicate. */
6946 sprintf (dupstr
, " [%d times]", dup
);
6947 duplen
= strlen (dupstr
);
6948 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
6949 insert_1 (dupstr
, duplen
, 1, 0, 1);
6954 /* If we have more than the desired maximum number of lines
6955 in the *Messages* buffer now, delete the oldest ones.
6956 This is safe because we don't have undo in this buffer. */
6958 if (NATNUMP (Vmessage_log_max
))
6960 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
6961 -XFASTINT (Vmessage_log_max
) - 1, 0);
6962 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
6965 BEGV
= XMARKER (oldbegv
)->charpos
;
6966 BEGV_BYTE
= marker_byte_position (oldbegv
);
6975 ZV
= XMARKER (oldzv
)->charpos
;
6976 ZV_BYTE
= marker_byte_position (oldzv
);
6980 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6982 /* We can't do Fgoto_char (oldpoint) because it will run some
6984 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
6985 XMARKER (oldpoint
)->bytepos
);
6988 unchain_marker (XMARKER (oldpoint
));
6989 unchain_marker (XMARKER (oldbegv
));
6990 unchain_marker (XMARKER (oldzv
));
6992 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
6993 set_buffer_internal (oldbuf
);
6995 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6996 message_log_need_newline
= !nlflag
;
6997 Vdeactivate_mark
= old_deactivate_mark
;
7002 /* We are at the end of the buffer after just having inserted a newline.
7003 (Note: We depend on the fact we won't be crossing the gap.)
7004 Check to see if the most recent message looks a lot like the previous one.
7005 Return 0 if different, 1 if the new one should just replace it, or a
7006 value N > 1 if we should also append " [N times]". */
7009 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7010 int prev_bol
, this_bol
;
7011 int prev_bol_byte
, this_bol_byte
;
7014 int len
= Z_BYTE
- 1 - this_bol_byte
;
7016 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7017 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7019 for (i
= 0; i
< len
; i
++)
7021 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7029 if (*p1
++ == ' ' && *p1
++ == '[')
7032 while (*p1
>= '0' && *p1
<= '9')
7033 n
= n
* 10 + *p1
++ - '0';
7034 if (strncmp (p1
, " times]\n", 8) == 0)
7041 /* Display an echo area message M with a specified length of NBYTES
7042 bytes. The string may include null characters. If M is 0, clear
7043 out any existing message, and let the mini-buffer text show
7046 The buffer M must continue to exist until after the echo area gets
7047 cleared or some other message gets displayed there. This means do
7048 not pass text that is stored in a Lisp string; do not pass text in
7049 a buffer that was alloca'd. */
7052 message2 (m
, nbytes
, multibyte
)
7057 /* First flush out any partial line written with print. */
7058 message_log_maybe_newline ();
7060 message_dolog (m
, nbytes
, 1, multibyte
);
7061 message2_nolog (m
, nbytes
, multibyte
);
7065 /* The non-logging counterpart of message2. */
7068 message2_nolog (m
, nbytes
, multibyte
)
7070 int nbytes
, multibyte
;
7072 struct frame
*sf
= SELECTED_FRAME ();
7073 message_enable_multibyte
= multibyte
;
7077 if (noninteractive_need_newline
)
7078 putc ('\n', stderr
);
7079 noninteractive_need_newline
= 0;
7081 fwrite (m
, nbytes
, 1, stderr
);
7082 if (cursor_in_echo_area
== 0)
7083 fprintf (stderr
, "\n");
7086 /* A null message buffer means that the frame hasn't really been
7087 initialized yet. Error messages get reported properly by
7088 cmd_error, so this must be just an informative message; toss it. */
7089 else if (INTERACTIVE
7090 && sf
->glyphs_initialized_p
7091 && FRAME_MESSAGE_BUF (sf
))
7093 Lisp_Object mini_window
;
7096 /* Get the frame containing the mini-buffer
7097 that the selected frame is using. */
7098 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7099 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7101 FRAME_SAMPLE_VISIBILITY (f
);
7102 if (FRAME_VISIBLE_P (sf
)
7103 && ! FRAME_VISIBLE_P (f
))
7104 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7108 set_message (m
, Qnil
, nbytes
, multibyte
);
7109 if (minibuffer_auto_raise
)
7110 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7113 clear_message (1, 1);
7115 do_pending_window_change (0);
7116 echo_area_display (1);
7117 do_pending_window_change (0);
7118 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7119 (*frame_up_to_date_hook
) (f
);
7124 /* Display an echo area message M with a specified length of NBYTES
7125 bytes. The string may include null characters. If M is not a
7126 string, clear out any existing message, and let the mini-buffer
7129 This function cancels echoing. */
7132 message3 (m
, nbytes
, multibyte
)
7137 struct gcpro gcpro1
;
7140 clear_message (1,1);
7143 /* First flush out any partial line written with print. */
7144 message_log_maybe_newline ();
7146 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
7147 message3_nolog (m
, nbytes
, multibyte
);
7153 /* The non-logging version of message3.
7154 This does not cancel echoing, because it is used for echoing.
7155 Perhaps we need to make a separate function for echoing
7156 and make this cancel echoing. */
7159 message3_nolog (m
, nbytes
, multibyte
)
7161 int nbytes
, multibyte
;
7163 struct frame
*sf
= SELECTED_FRAME ();
7164 message_enable_multibyte
= multibyte
;
7168 if (noninteractive_need_newline
)
7169 putc ('\n', stderr
);
7170 noninteractive_need_newline
= 0;
7172 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7173 if (cursor_in_echo_area
== 0)
7174 fprintf (stderr
, "\n");
7177 /* A null message buffer means that the frame hasn't really been
7178 initialized yet. Error messages get reported properly by
7179 cmd_error, so this must be just an informative message; toss it. */
7180 else if (INTERACTIVE
7181 && sf
->glyphs_initialized_p
7182 && FRAME_MESSAGE_BUF (sf
))
7184 Lisp_Object mini_window
;
7188 /* Get the frame containing the mini-buffer
7189 that the selected frame is using. */
7190 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7191 frame
= XWINDOW (mini_window
)->frame
;
7194 FRAME_SAMPLE_VISIBILITY (f
);
7195 if (FRAME_VISIBLE_P (sf
)
7196 && !FRAME_VISIBLE_P (f
))
7197 Fmake_frame_visible (frame
);
7199 if (STRINGP (m
) && SCHARS (m
) > 0)
7201 set_message (NULL
, m
, nbytes
, multibyte
);
7202 if (minibuffer_auto_raise
)
7203 Fraise_frame (frame
);
7206 clear_message (1, 1);
7208 do_pending_window_change (0);
7209 echo_area_display (1);
7210 do_pending_window_change (0);
7211 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7212 (*frame_up_to_date_hook
) (f
);
7217 /* Display a null-terminated echo area message M. If M is 0, clear
7218 out any existing message, and let the mini-buffer text show through.
7220 The buffer M must continue to exist until after the echo area gets
7221 cleared or some other message gets displayed there. Do not pass
7222 text that is stored in a Lisp string. Do not pass text in a buffer
7223 that was alloca'd. */
7229 message2 (m
, (m
? strlen (m
) : 0), 0);
7233 /* The non-logging counterpart of message1. */
7239 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7242 /* Display a message M which contains a single %s
7243 which gets replaced with STRING. */
7246 message_with_string (m
, string
, log
)
7251 CHECK_STRING (string
);
7257 if (noninteractive_need_newline
)
7258 putc ('\n', stderr
);
7259 noninteractive_need_newline
= 0;
7260 fprintf (stderr
, m
, SDATA (string
));
7261 if (cursor_in_echo_area
== 0)
7262 fprintf (stderr
, "\n");
7266 else if (INTERACTIVE
)
7268 /* The frame whose minibuffer we're going to display the message on.
7269 It may be larger than the selected frame, so we need
7270 to use its buffer, not the selected frame's buffer. */
7271 Lisp_Object mini_window
;
7272 struct frame
*f
, *sf
= SELECTED_FRAME ();
7274 /* Get the frame containing the minibuffer
7275 that the selected frame is using. */
7276 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7277 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7279 /* A null message buffer means that the frame hasn't really been
7280 initialized yet. Error messages get reported properly by
7281 cmd_error, so this must be just an informative message; toss it. */
7282 if (FRAME_MESSAGE_BUF (f
))
7284 Lisp_Object args
[2], message
;
7285 struct gcpro gcpro1
, gcpro2
;
7287 args
[0] = build_string (m
);
7288 args
[1] = message
= string
;
7289 GCPRO2 (args
[0], message
);
7292 message
= Fformat (2, args
);
7295 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7297 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7301 /* Print should start at the beginning of the message
7302 buffer next time. */
7303 message_buf_print
= 0;
7309 /* Dump an informative message to the minibuf. If M is 0, clear out
7310 any existing message, and let the mini-buffer text show through. */
7314 message (m
, a1
, a2
, a3
)
7316 EMACS_INT a1
, a2
, a3
;
7322 if (noninteractive_need_newline
)
7323 putc ('\n', stderr
);
7324 noninteractive_need_newline
= 0;
7325 fprintf (stderr
, m
, a1
, a2
, a3
);
7326 if (cursor_in_echo_area
== 0)
7327 fprintf (stderr
, "\n");
7331 else if (INTERACTIVE
)
7333 /* The frame whose mini-buffer we're going to display the message
7334 on. It may be larger than the selected frame, so we need to
7335 use its buffer, not the selected frame's buffer. */
7336 Lisp_Object mini_window
;
7337 struct frame
*f
, *sf
= SELECTED_FRAME ();
7339 /* Get the frame containing the mini-buffer
7340 that the selected frame is using. */
7341 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7342 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7344 /* A null message buffer means that the frame hasn't really been
7345 initialized yet. Error messages get reported properly by
7346 cmd_error, so this must be just an informative message; toss
7348 if (FRAME_MESSAGE_BUF (f
))
7359 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7360 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7362 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7363 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7365 #endif /* NO_ARG_ARRAY */
7367 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7372 /* Print should start at the beginning of the message
7373 buffer next time. */
7374 message_buf_print
= 0;
7380 /* The non-logging version of message. */
7383 message_nolog (m
, a1
, a2
, a3
)
7385 EMACS_INT a1
, a2
, a3
;
7387 Lisp_Object old_log_max
;
7388 old_log_max
= Vmessage_log_max
;
7389 Vmessage_log_max
= Qnil
;
7390 message (m
, a1
, a2
, a3
);
7391 Vmessage_log_max
= old_log_max
;
7395 /* Display the current message in the current mini-buffer. This is
7396 only called from error handlers in process.c, and is not time
7402 if (!NILP (echo_area_buffer
[0]))
7405 string
= Fcurrent_message ();
7406 message3 (string
, SBYTES (string
),
7407 !NILP (current_buffer
->enable_multibyte_characters
));
7412 /* Make sure echo area buffers in `echo_buffers' are live.
7413 If they aren't, make new ones. */
7416 ensure_echo_area_buffers ()
7420 for (i
= 0; i
< 2; ++i
)
7421 if (!BUFFERP (echo_buffer
[i
])
7422 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7425 Lisp_Object old_buffer
;
7428 old_buffer
= echo_buffer
[i
];
7429 sprintf (name
, " *Echo Area %d*", i
);
7430 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7431 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7433 for (j
= 0; j
< 2; ++j
)
7434 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7435 echo_area_buffer
[j
] = echo_buffer
[i
];
7440 /* Call FN with args A1..A4 with either the current or last displayed
7441 echo_area_buffer as current buffer.
7443 WHICH zero means use the current message buffer
7444 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7445 from echo_buffer[] and clear it.
7447 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7448 suitable buffer from echo_buffer[] and clear it.
7450 Value is what FN returns. */
7453 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7456 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7462 int this_one
, the_other
, clear_buffer_p
, rc
;
7463 int count
= SPECPDL_INDEX ();
7465 /* If buffers aren't live, make new ones. */
7466 ensure_echo_area_buffers ();
7471 this_one
= 0, the_other
= 1;
7473 this_one
= 1, the_other
= 0;
7475 /* Choose a suitable buffer from echo_buffer[] is we don't
7477 if (NILP (echo_area_buffer
[this_one
]))
7479 echo_area_buffer
[this_one
]
7480 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7481 ? echo_buffer
[the_other
]
7482 : echo_buffer
[this_one
]);
7486 buffer
= echo_area_buffer
[this_one
];
7488 /* Don't get confused by reusing the buffer used for echoing
7489 for a different purpose. */
7490 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7493 record_unwind_protect (unwind_with_echo_area_buffer
,
7494 with_echo_area_buffer_unwind_data (w
));
7496 /* Make the echo area buffer current. Note that for display
7497 purposes, it is not necessary that the displayed window's buffer
7498 == current_buffer, except for text property lookup. So, let's
7499 only set that buffer temporarily here without doing a full
7500 Fset_window_buffer. We must also change w->pointm, though,
7501 because otherwise an assertions in unshow_buffer fails, and Emacs
7503 set_buffer_internal_1 (XBUFFER (buffer
));
7507 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7510 current_buffer
->undo_list
= Qt
;
7511 current_buffer
->read_only
= Qnil
;
7512 specbind (Qinhibit_read_only
, Qt
);
7513 specbind (Qinhibit_modification_hooks
, Qt
);
7515 if (clear_buffer_p
&& Z
> BEG
)
7518 xassert (BEGV
>= BEG
);
7519 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7521 rc
= fn (a1
, a2
, a3
, a4
);
7523 xassert (BEGV
>= BEG
);
7524 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7526 unbind_to (count
, Qnil
);
7531 /* Save state that should be preserved around the call to the function
7532 FN called in with_echo_area_buffer. */
7535 with_echo_area_buffer_unwind_data (w
)
7541 /* Reduce consing by keeping one vector in
7542 Vwith_echo_area_save_vector. */
7543 vector
= Vwith_echo_area_save_vector
;
7544 Vwith_echo_area_save_vector
= Qnil
;
7547 vector
= Fmake_vector (make_number (7), Qnil
);
7549 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7550 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7551 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7555 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7556 AREF (vector
, i
) = w
->buffer
; ++i
;
7557 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7558 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7563 for (; i
< end
; ++i
)
7564 AREF (vector
, i
) = Qnil
;
7567 xassert (i
== ASIZE (vector
));
7572 /* Restore global state from VECTOR which was created by
7573 with_echo_area_buffer_unwind_data. */
7576 unwind_with_echo_area_buffer (vector
)
7579 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7580 Vdeactivate_mark
= AREF (vector
, 1);
7581 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7583 if (WINDOWP (AREF (vector
, 3)))
7586 Lisp_Object buffer
, charpos
, bytepos
;
7588 w
= XWINDOW (AREF (vector
, 3));
7589 buffer
= AREF (vector
, 4);
7590 charpos
= AREF (vector
, 5);
7591 bytepos
= AREF (vector
, 6);
7594 set_marker_both (w
->pointm
, buffer
,
7595 XFASTINT (charpos
), XFASTINT (bytepos
));
7598 Vwith_echo_area_save_vector
= vector
;
7603 /* Set up the echo area for use by print functions. MULTIBYTE_P
7604 non-zero means we will print multibyte. */
7607 setup_echo_area_for_printing (multibyte_p
)
7610 /* If we can't find an echo area any more, exit. */
7611 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7614 ensure_echo_area_buffers ();
7616 if (!message_buf_print
)
7618 /* A message has been output since the last time we printed.
7619 Choose a fresh echo area buffer. */
7620 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7621 echo_area_buffer
[0] = echo_buffer
[1];
7623 echo_area_buffer
[0] = echo_buffer
[0];
7625 /* Switch to that buffer and clear it. */
7626 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7627 current_buffer
->truncate_lines
= Qnil
;
7631 int count
= SPECPDL_INDEX ();
7632 specbind (Qinhibit_read_only
, Qt
);
7633 /* Note that undo recording is always disabled. */
7635 unbind_to (count
, Qnil
);
7637 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7639 /* Set up the buffer for the multibyteness we need. */
7641 != !NILP (current_buffer
->enable_multibyte_characters
))
7642 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7644 /* Raise the frame containing the echo area. */
7645 if (minibuffer_auto_raise
)
7647 struct frame
*sf
= SELECTED_FRAME ();
7648 Lisp_Object mini_window
;
7649 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7650 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7653 message_log_maybe_newline ();
7654 message_buf_print
= 1;
7658 if (NILP (echo_area_buffer
[0]))
7660 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7661 echo_area_buffer
[0] = echo_buffer
[1];
7663 echo_area_buffer
[0] = echo_buffer
[0];
7666 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7668 /* Someone switched buffers between print requests. */
7669 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7670 current_buffer
->truncate_lines
= Qnil
;
7676 /* Display an echo area message in window W. Value is non-zero if W's
7677 height is changed. If display_last_displayed_message_p is
7678 non-zero, display the message that was last displayed, otherwise
7679 display the current message. */
7682 display_echo_area (w
)
7685 int i
, no_message_p
, window_height_changed_p
, count
;
7687 /* Temporarily disable garbage collections while displaying the echo
7688 area. This is done because a GC can print a message itself.
7689 That message would modify the echo area buffer's contents while a
7690 redisplay of the buffer is going on, and seriously confuse
7692 count
= inhibit_garbage_collection ();
7694 /* If there is no message, we must call display_echo_area_1
7695 nevertheless because it resizes the window. But we will have to
7696 reset the echo_area_buffer in question to nil at the end because
7697 with_echo_area_buffer will sets it to an empty buffer. */
7698 i
= display_last_displayed_message_p
? 1 : 0;
7699 no_message_p
= NILP (echo_area_buffer
[i
]);
7701 window_height_changed_p
7702 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7703 display_echo_area_1
,
7704 (EMACS_INT
) w
, Qnil
, 0, 0);
7707 echo_area_buffer
[i
] = Qnil
;
7709 unbind_to (count
, Qnil
);
7710 return window_height_changed_p
;
7714 /* Helper for display_echo_area. Display the current buffer which
7715 contains the current echo area message in window W, a mini-window,
7716 a pointer to which is passed in A1. A2..A4 are currently not used.
7717 Change the height of W so that all of the message is displayed.
7718 Value is non-zero if height of W was changed. */
7721 display_echo_area_1 (a1
, a2
, a3
, a4
)
7726 struct window
*w
= (struct window
*) a1
;
7728 struct text_pos start
;
7729 int window_height_changed_p
= 0;
7731 /* Do this before displaying, so that we have a large enough glyph
7732 matrix for the display. */
7733 window_height_changed_p
= resize_mini_window (w
, 0);
7736 clear_glyph_matrix (w
->desired_matrix
);
7737 XSETWINDOW (window
, w
);
7738 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
7739 try_window (window
, start
, 0);
7741 return window_height_changed_p
;
7745 /* Resize the echo area window to exactly the size needed for the
7746 currently displayed message, if there is one. If a mini-buffer
7747 is active, don't shrink it. */
7750 resize_echo_area_exactly ()
7752 if (BUFFERP (echo_area_buffer
[0])
7753 && WINDOWP (echo_area_window
))
7755 struct window
*w
= XWINDOW (echo_area_window
);
7757 Lisp_Object resize_exactly
;
7759 if (minibuf_level
== 0)
7760 resize_exactly
= Qt
;
7762 resize_exactly
= Qnil
;
7764 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7765 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7768 ++windows_or_buffers_changed
;
7769 ++update_mode_lines
;
7770 redisplay_internal (0);
7776 /* Callback function for with_echo_area_buffer, when used from
7777 resize_echo_area_exactly. A1 contains a pointer to the window to
7778 resize, EXACTLY non-nil means resize the mini-window exactly to the
7779 size of the text displayed. A3 and A4 are not used. Value is what
7780 resize_mini_window returns. */
7783 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
7785 Lisp_Object exactly
;
7788 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
7792 /* Resize mini-window W to fit the size of its contents. EXACT:P
7793 means size the window exactly to the size needed. Otherwise, it's
7794 only enlarged until W's buffer is empty. Value is non-zero if
7795 the window height has been changed. */
7798 resize_mini_window (w
, exact_p
)
7802 struct frame
*f
= XFRAME (w
->frame
);
7803 int window_height_changed_p
= 0;
7805 xassert (MINI_WINDOW_P (w
));
7807 /* Don't resize windows while redisplaying a window; it would
7808 confuse redisplay functions when the size of the window they are
7809 displaying changes from under them. Such a resizing can happen,
7810 for instance, when which-func prints a long message while
7811 we are running fontification-functions. We're running these
7812 functions with safe_call which binds inhibit-redisplay to t. */
7813 if (!NILP (Vinhibit_redisplay
))
7816 /* Nil means don't try to resize. */
7817 if (NILP (Vresize_mini_windows
)
7818 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
7821 if (!FRAME_MINIBUF_ONLY_P (f
))
7824 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7825 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
7826 int height
, max_height
;
7827 int unit
= FRAME_LINE_HEIGHT (f
);
7828 struct text_pos start
;
7829 struct buffer
*old_current_buffer
= NULL
;
7831 if (current_buffer
!= XBUFFER (w
->buffer
))
7833 old_current_buffer
= current_buffer
;
7834 set_buffer_internal (XBUFFER (w
->buffer
));
7837 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
7839 /* Compute the max. number of lines specified by the user. */
7840 if (FLOATP (Vmax_mini_window_height
))
7841 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
7842 else if (INTEGERP (Vmax_mini_window_height
))
7843 max_height
= XINT (Vmax_mini_window_height
);
7845 max_height
= total_height
/ 4;
7847 /* Correct that max. height if it's bogus. */
7848 max_height
= max (1, max_height
);
7849 max_height
= min (total_height
, max_height
);
7851 /* Find out the height of the text in the window. */
7852 if (it
.truncate_lines_p
)
7857 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
7858 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
7859 height
= it
.current_y
+ last_height
;
7861 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
7862 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
7863 height
= (height
+ unit
- 1) / unit
;
7866 /* Compute a suitable window start. */
7867 if (height
> max_height
)
7869 height
= max_height
;
7870 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
7871 move_it_vertically_backward (&it
, (height
- 1) * unit
);
7872 start
= it
.current
.pos
;
7875 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
7876 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
7878 if (EQ (Vresize_mini_windows
, Qgrow_only
))
7880 /* Let it grow only, until we display an empty message, in which
7881 case the window shrinks again. */
7882 if (height
> WINDOW_TOTAL_LINES (w
))
7884 int old_height
= WINDOW_TOTAL_LINES (w
);
7885 freeze_window_starts (f
, 1);
7886 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7887 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7889 else if (height
< WINDOW_TOTAL_LINES (w
)
7890 && (exact_p
|| BEGV
== ZV
))
7892 int old_height
= WINDOW_TOTAL_LINES (w
);
7893 freeze_window_starts (f
, 0);
7894 shrink_mini_window (w
);
7895 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7900 /* Always resize to exact size needed. */
7901 if (height
> WINDOW_TOTAL_LINES (w
))
7903 int old_height
= WINDOW_TOTAL_LINES (w
);
7904 freeze_window_starts (f
, 1);
7905 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7906 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7908 else if (height
< WINDOW_TOTAL_LINES (w
))
7910 int old_height
= WINDOW_TOTAL_LINES (w
);
7911 freeze_window_starts (f
, 0);
7912 shrink_mini_window (w
);
7916 freeze_window_starts (f
, 1);
7917 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7920 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7924 if (old_current_buffer
)
7925 set_buffer_internal (old_current_buffer
);
7928 return window_height_changed_p
;
7932 /* Value is the current message, a string, or nil if there is no
7940 if (NILP (echo_area_buffer
[0]))
7944 with_echo_area_buffer (0, 0, current_message_1
,
7945 (EMACS_INT
) &msg
, Qnil
, 0, 0);
7947 echo_area_buffer
[0] = Qnil
;
7955 current_message_1 (a1
, a2
, a3
, a4
)
7960 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
7963 *msg
= make_buffer_string (BEG
, Z
, 1);
7970 /* Push the current message on Vmessage_stack for later restauration
7971 by restore_message. Value is non-zero if the current message isn't
7972 empty. This is a relatively infrequent operation, so it's not
7973 worth optimizing. */
7979 msg
= current_message ();
7980 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
7981 return STRINGP (msg
);
7985 /* Restore message display from the top of Vmessage_stack. */
7992 xassert (CONSP (Vmessage_stack
));
7993 msg
= XCAR (Vmessage_stack
);
7995 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
7997 message3_nolog (msg
, 0, 0);
8001 /* Handler for record_unwind_protect calling pop_message. */
8004 pop_message_unwind (dummy
)
8011 /* Pop the top-most entry off Vmessage_stack. */
8016 xassert (CONSP (Vmessage_stack
));
8017 Vmessage_stack
= XCDR (Vmessage_stack
);
8021 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8022 exits. If the stack is not empty, we have a missing pop_message
8026 check_message_stack ()
8028 if (!NILP (Vmessage_stack
))
8033 /* Truncate to NCHARS what will be displayed in the echo area the next
8034 time we display it---but don't redisplay it now. */
8037 truncate_echo_area (nchars
)
8041 echo_area_buffer
[0] = Qnil
;
8042 /* A null message buffer means that the frame hasn't really been
8043 initialized yet. Error messages get reported properly by
8044 cmd_error, so this must be just an informative message; toss it. */
8045 else if (!noninteractive
8047 && !NILP (echo_area_buffer
[0]))
8049 struct frame
*sf
= SELECTED_FRAME ();
8050 if (FRAME_MESSAGE_BUF (sf
))
8051 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8056 /* Helper function for truncate_echo_area. Truncate the current
8057 message to at most NCHARS characters. */
8060 truncate_message_1 (nchars
, a2
, a3
, a4
)
8065 if (BEG
+ nchars
< Z
)
8066 del_range (BEG
+ nchars
, Z
);
8068 echo_area_buffer
[0] = Qnil
;
8073 /* Set the current message to a substring of S or STRING.
8075 If STRING is a Lisp string, set the message to the first NBYTES
8076 bytes from STRING. NBYTES zero means use the whole string. If
8077 STRING is multibyte, the message will be displayed multibyte.
8079 If S is not null, set the message to the first LEN bytes of S. LEN
8080 zero means use the whole string. MULTIBYTE_P non-zero means S is
8081 multibyte. Display the message multibyte in that case. */
8084 set_message (s
, string
, nbytes
, multibyte_p
)
8087 int nbytes
, multibyte_p
;
8089 message_enable_multibyte
8090 = ((s
&& multibyte_p
)
8091 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8093 with_echo_area_buffer (0, 0, set_message_1
,
8094 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8095 message_buf_print
= 0;
8096 help_echo_showing_p
= 0;
8100 /* Helper function for set_message. Arguments have the same meaning
8101 as there, with A1 corresponding to S and A2 corresponding to STRING
8102 This function is called with the echo area buffer being
8106 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8109 EMACS_INT nbytes
, multibyte_p
;
8111 const char *s
= (const char *) a1
;
8112 Lisp_Object string
= a2
;
8114 /* Change multibyteness of the echo buffer appropriately. */
8115 if (message_enable_multibyte
8116 != !NILP (current_buffer
->enable_multibyte_characters
))
8117 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8119 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8121 /* Insert new message at BEG. */
8122 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8125 if (STRINGP (string
))
8130 nbytes
= SBYTES (string
);
8131 nchars
= string_byte_to_char (string
, nbytes
);
8133 /* This function takes care of single/multibyte conversion. We
8134 just have to ensure that the echo area buffer has the right
8135 setting of enable_multibyte_characters. */
8136 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8141 nbytes
= strlen (s
);
8143 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8145 /* Convert from multi-byte to single-byte. */
8147 unsigned char work
[1];
8149 /* Convert a multibyte string to single-byte. */
8150 for (i
= 0; i
< nbytes
; i
+= n
)
8152 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8153 work
[0] = (ASCII_CHAR_P (c
)
8155 : multibyte_char_to_unibyte (c
, Qnil
));
8156 insert_1_both (work
, 1, 1, 1, 0, 0);
8159 else if (!multibyte_p
8160 && !NILP (current_buffer
->enable_multibyte_characters
))
8162 /* Convert from single-byte to multi-byte. */
8164 const unsigned char *msg
= (const unsigned char *) s
;
8165 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8167 /* Convert a single-byte string to multibyte. */
8168 for (i
= 0; i
< nbytes
; i
++)
8171 c
= unibyte_char_to_multibyte (c
);
8172 n
= CHAR_STRING (c
, str
);
8173 insert_1_both (str
, 1, n
, 1, 0, 0);
8177 insert_1 (s
, nbytes
, 1, 0, 0);
8184 /* Clear messages. CURRENT_P non-zero means clear the current
8185 message. LAST_DISPLAYED_P non-zero means clear the message
8189 clear_message (current_p
, last_displayed_p
)
8190 int current_p
, last_displayed_p
;
8194 echo_area_buffer
[0] = Qnil
;
8195 message_cleared_p
= 1;
8198 if (last_displayed_p
)
8199 echo_area_buffer
[1] = Qnil
;
8201 message_buf_print
= 0;
8204 /* Clear garbaged frames.
8206 This function is used where the old redisplay called
8207 redraw_garbaged_frames which in turn called redraw_frame which in
8208 turn called clear_frame. The call to clear_frame was a source of
8209 flickering. I believe a clear_frame is not necessary. It should
8210 suffice in the new redisplay to invalidate all current matrices,
8211 and ensure a complete redisplay of all windows. */
8214 clear_garbaged_frames ()
8218 Lisp_Object tail
, frame
;
8219 int changed_count
= 0;
8221 FOR_EACH_FRAME (tail
, frame
)
8223 struct frame
*f
= XFRAME (frame
);
8225 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8229 Fredraw_frame (frame
);
8230 f
->force_flush_display_p
= 1;
8232 clear_current_matrices (f
);
8241 ++windows_or_buffers_changed
;
8246 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8247 is non-zero update selected_frame. Value is non-zero if the
8248 mini-windows height has been changed. */
8251 echo_area_display (update_frame_p
)
8254 Lisp_Object mini_window
;
8257 int window_height_changed_p
= 0;
8258 struct frame
*sf
= SELECTED_FRAME ();
8260 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8261 w
= XWINDOW (mini_window
);
8262 f
= XFRAME (WINDOW_FRAME (w
));
8264 /* Don't display if frame is invisible or not yet initialized. */
8265 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8268 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8270 #ifdef HAVE_WINDOW_SYSTEM
8271 /* When Emacs starts, selected_frame may be a visible terminal
8272 frame, even if we run under a window system. If we let this
8273 through, a message would be displayed on the terminal. */
8274 if (EQ (selected_frame
, Vterminal_frame
)
8275 && !NILP (Vwindow_system
))
8277 #endif /* HAVE_WINDOW_SYSTEM */
8280 /* Redraw garbaged frames. */
8282 clear_garbaged_frames ();
8284 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8286 echo_area_window
= mini_window
;
8287 window_height_changed_p
= display_echo_area (w
);
8288 w
->must_be_updated_p
= 1;
8290 /* Update the display, unless called from redisplay_internal.
8291 Also don't update the screen during redisplay itself. The
8292 update will happen at the end of redisplay, and an update
8293 here could cause confusion. */
8294 if (update_frame_p
&& !redisplaying_p
)
8298 /* If the display update has been interrupted by pending
8299 input, update mode lines in the frame. Due to the
8300 pending input, it might have been that redisplay hasn't
8301 been called, so that mode lines above the echo area are
8302 garbaged. This looks odd, so we prevent it here. */
8303 if (!display_completed
)
8304 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8306 if (window_height_changed_p
8307 /* Don't do this if Emacs is shutting down. Redisplay
8308 needs to run hooks. */
8309 && !NILP (Vrun_hooks
))
8311 /* Must update other windows. Likewise as in other
8312 cases, don't let this update be interrupted by
8314 int count
= SPECPDL_INDEX ();
8315 specbind (Qredisplay_dont_pause
, Qt
);
8316 windows_or_buffers_changed
= 1;
8317 redisplay_internal (0);
8318 unbind_to (count
, Qnil
);
8320 else if (FRAME_WINDOW_P (f
) && n
== 0)
8322 /* Window configuration is the same as before.
8323 Can do with a display update of the echo area,
8324 unless we displayed some mode lines. */
8325 update_single_window (w
, 1);
8326 rif
->flush_display (f
);
8329 update_frame (f
, 1, 1);
8331 /* If cursor is in the echo area, make sure that the next
8332 redisplay displays the minibuffer, so that the cursor will
8333 be replaced with what the minibuffer wants. */
8334 if (cursor_in_echo_area
)
8335 ++windows_or_buffers_changed
;
8338 else if (!EQ (mini_window
, selected_window
))
8339 windows_or_buffers_changed
++;
8341 /* The current message is now also the last one displayed. */
8342 echo_area_buffer
[1] = echo_area_buffer
[0];
8344 /* Prevent redisplay optimization in redisplay_internal by resetting
8345 this_line_start_pos. This is done because the mini-buffer now
8346 displays the message instead of its buffer text. */
8347 if (EQ (mini_window
, selected_window
))
8348 CHARPOS (this_line_start_pos
) = 0;
8350 return window_height_changed_p
;
8355 /***********************************************************************
8356 Mode Lines and Frame Titles
8357 ***********************************************************************/
8359 /* A buffer for constructing non-propertized mode-line strings and
8360 frame titles in it; allocated from the heap in init_xdisp and
8361 resized as needed in store_mode_line_noprop_char. */
8363 static char *mode_line_noprop_buf
;
8365 /* The buffer's end, and a current output position in it. */
8367 static char *mode_line_noprop_buf_end
;
8368 static char *mode_line_noprop_ptr
;
8370 #define MODE_LINE_NOPROP_LEN(start) \
8371 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8374 MODE_LINE_DISPLAY
= 0,
8380 /* Alist that caches the results of :propertize.
8381 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8382 static Lisp_Object mode_line_proptrans_alist
;
8384 /* List of strings making up the mode-line. */
8385 static Lisp_Object mode_line_string_list
;
8387 /* Base face property when building propertized mode line string. */
8388 static Lisp_Object mode_line_string_face
;
8389 static Lisp_Object mode_line_string_face_prop
;
8392 /* Unwind data for mode line strings */
8394 static Lisp_Object Vmode_line_unwind_vector
;
8397 format_mode_line_unwind_data (obuf
)
8398 struct buffer
*obuf
;
8402 /* Reduce consing by keeping one vector in
8403 Vwith_echo_area_save_vector. */
8404 vector
= Vmode_line_unwind_vector
;
8405 Vmode_line_unwind_vector
= Qnil
;
8408 vector
= Fmake_vector (make_number (7), Qnil
);
8410 AREF (vector
, 0) = make_number (mode_line_target
);
8411 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8412 AREF (vector
, 2) = mode_line_string_list
;
8413 AREF (vector
, 3) = mode_line_proptrans_alist
;
8414 AREF (vector
, 4) = mode_line_string_face
;
8415 AREF (vector
, 5) = mode_line_string_face_prop
;
8418 XSETBUFFER (AREF (vector
, 6), obuf
);
8420 AREF (vector
, 6) = Qnil
;
8426 unwind_format_mode_line (vector
)
8429 mode_line_target
= XINT (AREF (vector
, 0));
8430 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8431 mode_line_string_list
= AREF (vector
, 2);
8432 mode_line_proptrans_alist
= AREF (vector
, 3);
8433 mode_line_string_face
= AREF (vector
, 4);
8434 mode_line_string_face_prop
= AREF (vector
, 5);
8436 if (!NILP (AREF (vector
, 6)))
8438 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8439 AREF (vector
, 6) = Qnil
;
8442 Vmode_line_unwind_vector
= vector
;
8447 /* Store a single character C for the frame title in mode_line_noprop_buf.
8448 Re-allocate mode_line_noprop_buf if necessary. */
8452 store_mode_line_noprop_char (char c
)
8454 store_mode_line_noprop_char (c
)
8458 /* If output position has reached the end of the allocated buffer,
8459 double the buffer's size. */
8460 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8462 int len
= MODE_LINE_NOPROP_LEN (0);
8463 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8464 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8465 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8466 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8469 *mode_line_noprop_ptr
++ = c
;
8473 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8474 mode_line_noprop_ptr. STR is the string to store. Do not copy
8475 characters that yield more columns than PRECISION; PRECISION <= 0
8476 means copy the whole string. Pad with spaces until FIELD_WIDTH
8477 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8478 pad. Called from display_mode_element when it is used to build a
8482 store_mode_line_noprop (str
, field_width
, precision
)
8483 const unsigned char *str
;
8484 int field_width
, precision
;
8489 /* Copy at most PRECISION chars from STR. */
8490 nbytes
= strlen (str
);
8491 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8493 store_mode_line_noprop_char (*str
++);
8495 /* Fill up with spaces until FIELD_WIDTH reached. */
8496 while (field_width
> 0
8499 store_mode_line_noprop_char (' ');
8506 /***********************************************************************
8508 ***********************************************************************/
8510 #ifdef HAVE_WINDOW_SYSTEM
8512 /* Set the title of FRAME, if it has changed. The title format is
8513 Vicon_title_format if FRAME is iconified, otherwise it is
8514 frame_title_format. */
8517 x_consider_frame_title (frame
)
8520 struct frame
*f
= XFRAME (frame
);
8522 if (FRAME_WINDOW_P (f
)
8523 || FRAME_MINIBUF_ONLY_P (f
)
8524 || f
->explicit_name
)
8526 /* Do we have more than one visible frame on this X display? */
8533 int count
= SPECPDL_INDEX ();
8535 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8537 Lisp_Object other_frame
= XCAR (tail
);
8538 struct frame
*tf
= XFRAME (other_frame
);
8541 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8542 && !FRAME_MINIBUF_ONLY_P (tf
)
8543 && !EQ (other_frame
, tip_frame
)
8544 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8548 /* Set global variable indicating that multiple frames exist. */
8549 multiple_frames
= CONSP (tail
);
8551 /* Switch to the buffer of selected window of the frame. Set up
8552 mode_line_target so that display_mode_element will output into
8553 mode_line_noprop_buf; then display the title. */
8554 record_unwind_protect (unwind_format_mode_line
,
8555 format_mode_line_unwind_data (current_buffer
));
8557 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8558 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8560 mode_line_target
= MODE_LINE_TITLE
;
8561 title_start
= MODE_LINE_NOPROP_LEN (0);
8562 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8563 NULL
, DEFAULT_FACE_ID
);
8564 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8565 len
= MODE_LINE_NOPROP_LEN (title_start
);
8566 title
= mode_line_noprop_buf
+ title_start
;
8567 unbind_to (count
, Qnil
);
8569 /* Set the title only if it's changed. This avoids consing in
8570 the common case where it hasn't. (If it turns out that we've
8571 already wasted too much time by walking through the list with
8572 display_mode_element, then we might need to optimize at a
8573 higher level than this.) */
8574 if (! STRINGP (f
->name
)
8575 || SBYTES (f
->name
) != len
8576 || bcmp (title
, SDATA (f
->name
), len
) != 0)
8577 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
8581 #endif /* not HAVE_WINDOW_SYSTEM */
8586 /***********************************************************************
8588 ***********************************************************************/
8591 /* Prepare for redisplay by updating menu-bar item lists when
8592 appropriate. This can call eval. */
8595 prepare_menu_bars ()
8598 struct gcpro gcpro1
, gcpro2
;
8600 Lisp_Object tooltip_frame
;
8602 #ifdef HAVE_WINDOW_SYSTEM
8603 tooltip_frame
= tip_frame
;
8605 tooltip_frame
= Qnil
;
8608 /* Update all frame titles based on their buffer names, etc. We do
8609 this before the menu bars so that the buffer-menu will show the
8610 up-to-date frame titles. */
8611 #ifdef HAVE_WINDOW_SYSTEM
8612 if (windows_or_buffers_changed
|| update_mode_lines
)
8614 Lisp_Object tail
, frame
;
8616 FOR_EACH_FRAME (tail
, frame
)
8619 if (!EQ (frame
, tooltip_frame
)
8620 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8621 x_consider_frame_title (frame
);
8624 #endif /* HAVE_WINDOW_SYSTEM */
8626 /* Update the menu bar item lists, if appropriate. This has to be
8627 done before any actual redisplay or generation of display lines. */
8628 all_windows
= (update_mode_lines
8629 || buffer_shared
> 1
8630 || windows_or_buffers_changed
);
8633 Lisp_Object tail
, frame
;
8634 int count
= SPECPDL_INDEX ();
8636 record_unwind_save_match_data ();
8638 FOR_EACH_FRAME (tail
, frame
)
8642 /* Ignore tooltip frame. */
8643 if (EQ (frame
, tooltip_frame
))
8646 /* If a window on this frame changed size, report that to
8647 the user and clear the size-change flag. */
8648 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8650 Lisp_Object functions
;
8652 /* Clear flag first in case we get an error below. */
8653 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8654 functions
= Vwindow_size_change_functions
;
8655 GCPRO2 (tail
, functions
);
8657 while (CONSP (functions
))
8659 call1 (XCAR (functions
), frame
);
8660 functions
= XCDR (functions
);
8666 update_menu_bar (f
, 0);
8667 #ifdef HAVE_WINDOW_SYSTEM
8668 update_tool_bar (f
, 0);
8673 unbind_to (count
, Qnil
);
8677 struct frame
*sf
= SELECTED_FRAME ();
8678 update_menu_bar (sf
, 1);
8679 #ifdef HAVE_WINDOW_SYSTEM
8680 update_tool_bar (sf
, 1);
8684 /* Motif needs this. See comment in xmenu.c. Turn it off when
8685 pending_menu_activation is not defined. */
8686 #ifdef USE_X_TOOLKIT
8687 pending_menu_activation
= 0;
8692 /* Update the menu bar item list for frame F. This has to be done
8693 before we start to fill in any display lines, because it can call
8696 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8699 update_menu_bar (f
, save_match_data
)
8701 int save_match_data
;
8704 register struct window
*w
;
8706 /* If called recursively during a menu update, do nothing. This can
8707 happen when, for instance, an activate-menubar-hook causes a
8709 if (inhibit_menubar_update
)
8712 window
= FRAME_SELECTED_WINDOW (f
);
8713 w
= XWINDOW (window
);
8715 #if 0 /* The if statement below this if statement used to include the
8716 condition !NILP (w->update_mode_line), rather than using
8717 update_mode_lines directly, and this if statement may have
8718 been added to make that condition work. Now the if
8719 statement below matches its comment, this isn't needed. */
8720 if (update_mode_lines
)
8721 w
->update_mode_line
= Qt
;
8724 if (FRAME_WINDOW_P (f
)
8726 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8727 || defined (USE_GTK)
8728 FRAME_EXTERNAL_MENU_BAR (f
)
8730 FRAME_MENU_BAR_LINES (f
) > 0
8732 : FRAME_MENU_BAR_LINES (f
) > 0)
8734 /* If the user has switched buffers or windows, we need to
8735 recompute to reflect the new bindings. But we'll
8736 recompute when update_mode_lines is set too; that means
8737 that people can use force-mode-line-update to request
8738 that the menu bar be recomputed. The adverse effect on
8739 the rest of the redisplay algorithm is about the same as
8740 windows_or_buffers_changed anyway. */
8741 if (windows_or_buffers_changed
8742 /* This used to test w->update_mode_line, but we believe
8743 there is no need to recompute the menu in that case. */
8744 || update_mode_lines
8745 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8746 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8747 != !NILP (w
->last_had_star
))
8748 || ((!NILP (Vtransient_mark_mode
)
8749 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8750 != !NILP (w
->region_showing
)))
8752 struct buffer
*prev
= current_buffer
;
8753 int count
= SPECPDL_INDEX ();
8755 specbind (Qinhibit_menubar_update
, Qt
);
8757 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8758 if (save_match_data
)
8759 record_unwind_save_match_data ();
8760 if (NILP (Voverriding_local_map_menu_flag
))
8762 specbind (Qoverriding_terminal_local_map
, Qnil
);
8763 specbind (Qoverriding_local_map
, Qnil
);
8766 /* Run the Lucid hook. */
8767 safe_run_hooks (Qactivate_menubar_hook
);
8769 /* If it has changed current-menubar from previous value,
8770 really recompute the menu-bar from the value. */
8771 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8772 call0 (Qrecompute_lucid_menubar
);
8774 safe_run_hooks (Qmenu_bar_update_hook
);
8775 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
8777 /* Redisplay the menu bar in case we changed it. */
8778 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8779 || defined (USE_GTK)
8780 if (FRAME_WINDOW_P (f
)
8781 #if defined (MAC_OS)
8782 /* All frames on Mac OS share the same menubar. So only the
8783 selected frame should be allowed to set it. */
8784 && f
== SELECTED_FRAME ()
8787 set_frame_menubar (f
, 0, 0);
8789 /* On a terminal screen, the menu bar is an ordinary screen
8790 line, and this makes it get updated. */
8791 w
->update_mode_line
= Qt
;
8792 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8793 /* In the non-toolkit version, the menu bar is an ordinary screen
8794 line, and this makes it get updated. */
8795 w
->update_mode_line
= Qt
;
8796 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8798 unbind_to (count
, Qnil
);
8799 set_buffer_internal_1 (prev
);
8806 /***********************************************************************
8808 ***********************************************************************/
8810 #ifdef HAVE_WINDOW_SYSTEM
8813 Nominal cursor position -- where to draw output.
8814 HPOS and VPOS are window relative glyph matrix coordinates.
8815 X and Y are window relative pixel coordinates. */
8817 struct cursor_pos output_cursor
;
8821 Set the global variable output_cursor to CURSOR. All cursor
8822 positions are relative to updated_window. */
8825 set_output_cursor (cursor
)
8826 struct cursor_pos
*cursor
;
8828 output_cursor
.hpos
= cursor
->hpos
;
8829 output_cursor
.vpos
= cursor
->vpos
;
8830 output_cursor
.x
= cursor
->x
;
8831 output_cursor
.y
= cursor
->y
;
8836 Set a nominal cursor position.
8838 HPOS and VPOS are column/row positions in a window glyph matrix. X
8839 and Y are window text area relative pixel positions.
8841 If this is done during an update, updated_window will contain the
8842 window that is being updated and the position is the future output
8843 cursor position for that window. If updated_window is null, use
8844 selected_window and display the cursor at the given position. */
8847 x_cursor_to (vpos
, hpos
, y
, x
)
8848 int vpos
, hpos
, y
, x
;
8852 /* If updated_window is not set, work on selected_window. */
8856 w
= XWINDOW (selected_window
);
8858 /* Set the output cursor. */
8859 output_cursor
.hpos
= hpos
;
8860 output_cursor
.vpos
= vpos
;
8861 output_cursor
.x
= x
;
8862 output_cursor
.y
= y
;
8864 /* If not called as part of an update, really display the cursor.
8865 This will also set the cursor position of W. */
8866 if (updated_window
== NULL
)
8869 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8870 if (rif
->flush_display_optional
)
8871 rif
->flush_display_optional (SELECTED_FRAME ());
8876 #endif /* HAVE_WINDOW_SYSTEM */
8879 /***********************************************************************
8881 ***********************************************************************/
8883 #ifdef HAVE_WINDOW_SYSTEM
8885 /* Where the mouse was last time we reported a mouse event. */
8887 FRAME_PTR last_mouse_frame
;
8889 /* Tool-bar item index of the item on which a mouse button was pressed
8892 int last_tool_bar_item
;
8895 /* Update the tool-bar item list for frame F. This has to be done
8896 before we start to fill in any display lines. Called from
8897 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8898 and restore it here. */
8901 update_tool_bar (f
, save_match_data
)
8903 int save_match_data
;
8906 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
8908 int do_update
= WINDOWP (f
->tool_bar_window
)
8909 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
8917 window
= FRAME_SELECTED_WINDOW (f
);
8918 w
= XWINDOW (window
);
8920 /* If the user has switched buffers or windows, we need to
8921 recompute to reflect the new bindings. But we'll
8922 recompute when update_mode_lines is set too; that means
8923 that people can use force-mode-line-update to request
8924 that the menu bar be recomputed. The adverse effect on
8925 the rest of the redisplay algorithm is about the same as
8926 windows_or_buffers_changed anyway. */
8927 if (windows_or_buffers_changed
8928 || !NILP (w
->update_mode_line
)
8929 || update_mode_lines
8930 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8931 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8932 != !NILP (w
->last_had_star
))
8933 || ((!NILP (Vtransient_mark_mode
)
8934 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8935 != !NILP (w
->region_showing
)))
8937 struct buffer
*prev
= current_buffer
;
8938 int count
= SPECPDL_INDEX ();
8939 Lisp_Object new_tool_bar
;
8941 struct gcpro gcpro1
;
8943 /* Set current_buffer to the buffer of the selected
8944 window of the frame, so that we get the right local
8946 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8948 /* Save match data, if we must. */
8949 if (save_match_data
)
8950 record_unwind_save_match_data ();
8952 /* Make sure that we don't accidentally use bogus keymaps. */
8953 if (NILP (Voverriding_local_map_menu_flag
))
8955 specbind (Qoverriding_terminal_local_map
, Qnil
);
8956 specbind (Qoverriding_local_map
, Qnil
);
8959 GCPRO1 (new_tool_bar
);
8961 /* Build desired tool-bar items from keymaps. */
8962 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
8965 /* Redisplay the tool-bar if we changed it. */
8966 if (NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
8968 /* Redisplay that happens asynchronously due to an expose event
8969 may access f->tool_bar_items. Make sure we update both
8970 variables within BLOCK_INPUT so no such event interrupts. */
8972 f
->tool_bar_items
= new_tool_bar
;
8973 f
->n_tool_bar_items
= new_n_tool_bar
;
8974 w
->update_mode_line
= Qt
;
8980 unbind_to (count
, Qnil
);
8981 set_buffer_internal_1 (prev
);
8987 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8988 F's desired tool-bar contents. F->tool_bar_items must have
8989 been set up previously by calling prepare_menu_bars. */
8992 build_desired_tool_bar_string (f
)
8995 int i
, size
, size_needed
;
8996 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8997 Lisp_Object image
, plist
, props
;
8999 image
= plist
= props
= Qnil
;
9000 GCPRO3 (image
, plist
, props
);
9002 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9003 Otherwise, make a new string. */
9005 /* The size of the string we might be able to reuse. */
9006 size
= (STRINGP (f
->desired_tool_bar_string
)
9007 ? SCHARS (f
->desired_tool_bar_string
)
9010 /* We need one space in the string for each image. */
9011 size_needed
= f
->n_tool_bar_items
;
9013 /* Reuse f->desired_tool_bar_string, if possible. */
9014 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9015 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9019 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9020 Fremove_text_properties (make_number (0), make_number (size
),
9021 props
, f
->desired_tool_bar_string
);
9024 /* Put a `display' property on the string for the images to display,
9025 put a `menu_item' property on tool-bar items with a value that
9026 is the index of the item in F's tool-bar item vector. */
9027 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9029 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9031 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9032 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9033 int hmargin
, vmargin
, relief
, idx
, end
;
9034 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9036 /* If image is a vector, choose the image according to the
9038 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9039 if (VECTORP (image
))
9043 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9044 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9047 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9048 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9050 xassert (ASIZE (image
) >= idx
);
9051 image
= AREF (image
, idx
);
9056 /* Ignore invalid image specifications. */
9057 if (!valid_image_p (image
))
9060 /* Display the tool-bar button pressed, or depressed. */
9061 plist
= Fcopy_sequence (XCDR (image
));
9063 /* Compute margin and relief to draw. */
9064 relief
= (tool_bar_button_relief
>= 0
9065 ? tool_bar_button_relief
9066 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9067 hmargin
= vmargin
= relief
;
9069 if (INTEGERP (Vtool_bar_button_margin
)
9070 && XINT (Vtool_bar_button_margin
) > 0)
9072 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9073 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9075 else if (CONSP (Vtool_bar_button_margin
))
9077 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9078 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9079 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9081 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9082 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9083 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9086 if (auto_raise_tool_bar_buttons_p
)
9088 /* Add a `:relief' property to the image spec if the item is
9092 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9099 /* If image is selected, display it pressed, i.e. with a
9100 negative relief. If it's not selected, display it with a
9102 plist
= Fplist_put (plist
, QCrelief
,
9104 ? make_number (-relief
)
9105 : make_number (relief
)));
9110 /* Put a margin around the image. */
9111 if (hmargin
|| vmargin
)
9113 if (hmargin
== vmargin
)
9114 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9116 plist
= Fplist_put (plist
, QCmargin
,
9117 Fcons (make_number (hmargin
),
9118 make_number (vmargin
)));
9121 /* If button is not enabled, and we don't have special images
9122 for the disabled state, make the image appear disabled by
9123 applying an appropriate algorithm to it. */
9124 if (!enabled_p
&& idx
< 0)
9125 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9127 /* Put a `display' text property on the string for the image to
9128 display. Put a `menu-item' property on the string that gives
9129 the start of this item's properties in the tool-bar items
9131 image
= Fcons (Qimage
, plist
);
9132 props
= list4 (Qdisplay
, image
,
9133 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9135 /* Let the last image hide all remaining spaces in the tool bar
9136 string. The string can be longer than needed when we reuse a
9138 if (i
+ 1 == f
->n_tool_bar_items
)
9139 end
= SCHARS (f
->desired_tool_bar_string
);
9142 Fadd_text_properties (make_number (i
), make_number (end
),
9143 props
, f
->desired_tool_bar_string
);
9151 /* Display one line of the tool-bar of frame IT->f. */
9154 display_tool_bar_line (it
)
9157 struct glyph_row
*row
= it
->glyph_row
;
9158 int max_x
= it
->last_visible_x
;
9161 prepare_desired_row (row
);
9162 row
->y
= it
->current_y
;
9164 /* Note that this isn't made use of if the face hasn't a box,
9165 so there's no need to check the face here. */
9166 it
->start_of_box_run_p
= 1;
9168 while (it
->current_x
< max_x
)
9170 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
9172 /* Get the next display element. */
9173 if (!get_next_display_element (it
))
9176 /* Produce glyphs. */
9177 x_before
= it
->current_x
;
9178 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
9179 PRODUCE_GLYPHS (it
);
9181 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
9186 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9188 if (x
+ glyph
->pixel_width
> max_x
)
9190 /* Glyph doesn't fit on line. */
9191 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
9197 x
+= glyph
->pixel_width
;
9201 /* Stop at line ends. */
9202 if (ITERATOR_AT_END_OF_LINE_P (it
))
9205 set_iterator_to_next (it
, 1);
9210 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9211 extend_face_to_end_of_line (it
);
9212 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9213 last
->right_box_line_p
= 1;
9214 if (last
== row
->glyphs
[TEXT_AREA
])
9215 last
->left_box_line_p
= 1;
9216 compute_line_metrics (it
);
9218 /* If line is empty, make it occupy the rest of the tool-bar. */
9219 if (!row
->displays_text_p
)
9221 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9222 row
->ascent
= row
->phys_ascent
= 0;
9223 row
->extra_line_spacing
= 0;
9226 row
->full_width_p
= 1;
9227 row
->continued_p
= 0;
9228 row
->truncated_on_left_p
= 0;
9229 row
->truncated_on_right_p
= 0;
9231 it
->current_x
= it
->hpos
= 0;
9232 it
->current_y
+= row
->height
;
9238 /* Value is the number of screen lines needed to make all tool-bar
9239 items of frame F visible. */
9242 tool_bar_lines_needed (f
)
9245 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9248 /* Initialize an iterator for iteration over
9249 F->desired_tool_bar_string in the tool-bar window of frame F. */
9250 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9251 it
.first_visible_x
= 0;
9252 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9253 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9255 while (!ITERATOR_AT_END_P (&it
))
9257 it
.glyph_row
= w
->desired_matrix
->rows
;
9258 clear_glyph_row (it
.glyph_row
);
9259 display_tool_bar_line (&it
);
9262 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9266 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9268 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9277 frame
= selected_frame
;
9279 CHECK_FRAME (frame
);
9282 if (WINDOWP (f
->tool_bar_window
)
9283 || (w
= XWINDOW (f
->tool_bar_window
),
9284 WINDOW_TOTAL_LINES (w
) > 0))
9286 update_tool_bar (f
, 1);
9287 if (f
->n_tool_bar_items
)
9289 build_desired_tool_bar_string (f
);
9290 nlines
= tool_bar_lines_needed (f
);
9294 return make_number (nlines
);
9298 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9299 height should be changed. */
9302 redisplay_tool_bar (f
)
9307 struct glyph_row
*row
;
9308 int change_height_p
= 0;
9311 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9312 update_frame_tool_bar (f
);
9316 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9317 do anything. This means you must start with tool-bar-lines
9318 non-zero to get the auto-sizing effect. Or in other words, you
9319 can turn off tool-bars by specifying tool-bar-lines zero. */
9320 if (!WINDOWP (f
->tool_bar_window
)
9321 || (w
= XWINDOW (f
->tool_bar_window
),
9322 WINDOW_TOTAL_LINES (w
) == 0))
9325 /* Set up an iterator for the tool-bar window. */
9326 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9327 it
.first_visible_x
= 0;
9328 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9331 /* Build a string that represents the contents of the tool-bar. */
9332 build_desired_tool_bar_string (f
);
9333 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9335 /* Display as many lines as needed to display all tool-bar items. */
9336 while (it
.current_y
< it
.last_visible_y
)
9337 display_tool_bar_line (&it
);
9339 /* It doesn't make much sense to try scrolling in the tool-bar
9340 window, so don't do it. */
9341 w
->desired_matrix
->no_scrolling_p
= 1;
9342 w
->must_be_updated_p
= 1;
9344 if (auto_resize_tool_bars_p
)
9348 /* If we couldn't display everything, change the tool-bar's
9350 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
9351 change_height_p
= 1;
9353 /* If there are blank lines at the end, except for a partially
9354 visible blank line at the end that is smaller than
9355 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9356 row
= it
.glyph_row
- 1;
9357 if (!row
->displays_text_p
9358 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9359 change_height_p
= 1;
9361 /* If row displays tool-bar items, but is partially visible,
9362 change the tool-bar's height. */
9363 if (row
->displays_text_p
9364 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
9365 change_height_p
= 1;
9367 /* Resize windows as needed by changing the `tool-bar-lines'
9370 && (nlines
= tool_bar_lines_needed (f
),
9371 nlines
!= WINDOW_TOTAL_LINES (w
)))
9373 extern Lisp_Object Qtool_bar_lines
;
9375 int old_height
= WINDOW_TOTAL_LINES (w
);
9377 XSETFRAME (frame
, f
);
9378 clear_glyph_matrix (w
->desired_matrix
);
9379 Fmodify_frame_parameters (frame
,
9380 Fcons (Fcons (Qtool_bar_lines
,
9381 make_number (nlines
)),
9383 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9384 fonts_changed_p
= 1;
9388 return change_height_p
;
9392 /* Get information about the tool-bar item which is displayed in GLYPH
9393 on frame F. Return in *PROP_IDX the index where tool-bar item
9394 properties start in F->tool_bar_items. Value is zero if
9395 GLYPH doesn't display a tool-bar item. */
9398 tool_bar_item_info (f
, glyph
, prop_idx
)
9400 struct glyph
*glyph
;
9407 /* This function can be called asynchronously, which means we must
9408 exclude any possibility that Fget_text_property signals an
9410 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
9411 charpos
= max (0, charpos
);
9413 /* Get the text property `menu-item' at pos. The value of that
9414 property is the start index of this item's properties in
9415 F->tool_bar_items. */
9416 prop
= Fget_text_property (make_number (charpos
),
9417 Qmenu_item
, f
->current_tool_bar_string
);
9418 if (INTEGERP (prop
))
9420 *prop_idx
= XINT (prop
);
9430 /* Get information about the tool-bar item at position X/Y on frame F.
9431 Return in *GLYPH a pointer to the glyph of the tool-bar item in
9432 the current matrix of the tool-bar window of F, or NULL if not
9433 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
9434 item in F->tool_bar_items. Value is
9436 -1 if X/Y is not on a tool-bar item
9437 0 if X/Y is on the same item that was highlighted before.
9441 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
9444 struct glyph
**glyph
;
9445 int *hpos
, *vpos
, *prop_idx
;
9447 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9448 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9451 /* Find the glyph under X/Y. */
9452 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
9456 /* Get the start of this tool-bar item's properties in
9457 f->tool_bar_items. */
9458 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
9461 /* Is mouse on the highlighted item? */
9462 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
9463 && *vpos
>= dpyinfo
->mouse_face_beg_row
9464 && *vpos
<= dpyinfo
->mouse_face_end_row
9465 && (*vpos
> dpyinfo
->mouse_face_beg_row
9466 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
9467 && (*vpos
< dpyinfo
->mouse_face_end_row
9468 || *hpos
< dpyinfo
->mouse_face_end_col
9469 || dpyinfo
->mouse_face_past_end
))
9477 Handle mouse button event on the tool-bar of frame F, at
9478 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
9479 0 for button release. MODIFIERS is event modifiers for button
9483 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
9486 unsigned int modifiers
;
9488 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9489 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9490 int hpos
, vpos
, prop_idx
;
9491 struct glyph
*glyph
;
9492 Lisp_Object enabled_p
;
9494 /* If not on the highlighted tool-bar item, return. */
9495 frame_to_window_pixel_xy (w
, &x
, &y
);
9496 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
9499 /* If item is disabled, do nothing. */
9500 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9501 if (NILP (enabled_p
))
9506 /* Show item in pressed state. */
9507 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
9508 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
9509 last_tool_bar_item
= prop_idx
;
9513 Lisp_Object key
, frame
;
9514 struct input_event event
;
9517 /* Show item in released state. */
9518 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
9519 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
9521 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
9523 XSETFRAME (frame
, f
);
9524 event
.kind
= TOOL_BAR_EVENT
;
9525 event
.frame_or_window
= frame
;
9527 kbd_buffer_store_event (&event
);
9529 event
.kind
= TOOL_BAR_EVENT
;
9530 event
.frame_or_window
= frame
;
9532 event
.modifiers
= modifiers
;
9533 kbd_buffer_store_event (&event
);
9534 last_tool_bar_item
= -1;
9539 /* Possibly highlight a tool-bar item on frame F when mouse moves to
9540 tool-bar window-relative coordinates X/Y. Called from
9541 note_mouse_highlight. */
9544 note_tool_bar_highlight (f
, x
, y
)
9548 Lisp_Object window
= f
->tool_bar_window
;
9549 struct window
*w
= XWINDOW (window
);
9550 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9552 struct glyph
*glyph
;
9553 struct glyph_row
*row
;
9555 Lisp_Object enabled_p
;
9557 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9558 int mouse_down_p
, rc
;
9560 /* Function note_mouse_highlight is called with negative x(y
9561 values when mouse moves outside of the frame. */
9562 if (x
<= 0 || y
<= 0)
9564 clear_mouse_face (dpyinfo
);
9568 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9571 /* Not on tool-bar item. */
9572 clear_mouse_face (dpyinfo
);
9576 /* On same tool-bar item as before. */
9579 clear_mouse_face (dpyinfo
);
9581 /* Mouse is down, but on different tool-bar item? */
9582 mouse_down_p
= (dpyinfo
->grabbed
9583 && f
== last_mouse_frame
9584 && FRAME_LIVE_P (f
));
9586 && last_tool_bar_item
!= prop_idx
)
9589 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9590 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9592 /* If tool-bar item is not enabled, don't highlight it. */
9593 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9594 if (!NILP (enabled_p
))
9596 /* Compute the x-position of the glyph. In front and past the
9597 image is a space. We include this in the highlighted area. */
9598 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9599 for (i
= x
= 0; i
< hpos
; ++i
)
9600 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9602 /* Record this as the current active region. */
9603 dpyinfo
->mouse_face_beg_col
= hpos
;
9604 dpyinfo
->mouse_face_beg_row
= vpos
;
9605 dpyinfo
->mouse_face_beg_x
= x
;
9606 dpyinfo
->mouse_face_beg_y
= row
->y
;
9607 dpyinfo
->mouse_face_past_end
= 0;
9609 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9610 dpyinfo
->mouse_face_end_row
= vpos
;
9611 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9612 dpyinfo
->mouse_face_end_y
= row
->y
;
9613 dpyinfo
->mouse_face_window
= window
;
9614 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9616 /* Display it as active. */
9617 show_mouse_face (dpyinfo
, draw
);
9618 dpyinfo
->mouse_face_image_state
= draw
;
9623 /* Set help_echo_string to a help string to display for this tool-bar item.
9624 XTread_socket does the rest. */
9625 help_echo_object
= help_echo_window
= Qnil
;
9627 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9628 if (NILP (help_echo_string
))
9629 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9632 #endif /* HAVE_WINDOW_SYSTEM */
9636 /************************************************************************
9637 Horizontal scrolling
9638 ************************************************************************/
9640 static int hscroll_window_tree
P_ ((Lisp_Object
));
9641 static int hscroll_windows
P_ ((Lisp_Object
));
9643 /* For all leaf windows in the window tree rooted at WINDOW, set their
9644 hscroll value so that PT is (i) visible in the window, and (ii) so
9645 that it is not within a certain margin at the window's left and
9646 right border. Value is non-zero if any window's hscroll has been
9650 hscroll_window_tree (window
)
9653 int hscrolled_p
= 0;
9654 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9655 int hscroll_step_abs
= 0;
9656 double hscroll_step_rel
= 0;
9658 if (hscroll_relative_p
)
9660 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9661 if (hscroll_step_rel
< 0)
9663 hscroll_relative_p
= 0;
9664 hscroll_step_abs
= 0;
9667 else if (INTEGERP (Vhscroll_step
))
9669 hscroll_step_abs
= XINT (Vhscroll_step
);
9670 if (hscroll_step_abs
< 0)
9671 hscroll_step_abs
= 0;
9674 hscroll_step_abs
= 0;
9676 while (WINDOWP (window
))
9678 struct window
*w
= XWINDOW (window
);
9680 if (WINDOWP (w
->hchild
))
9681 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9682 else if (WINDOWP (w
->vchild
))
9683 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9684 else if (w
->cursor
.vpos
>= 0)
9687 int text_area_width
;
9688 struct glyph_row
*current_cursor_row
9689 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9690 struct glyph_row
*desired_cursor_row
9691 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9692 struct glyph_row
*cursor_row
9693 = (desired_cursor_row
->enabled_p
9694 ? desired_cursor_row
9695 : current_cursor_row
);
9697 text_area_width
= window_box_width (w
, TEXT_AREA
);
9699 /* Scroll when cursor is inside this scroll margin. */
9700 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9702 if ((XFASTINT (w
->hscroll
)
9703 && w
->cursor
.x
<= h_margin
)
9704 || (cursor_row
->enabled_p
9705 && cursor_row
->truncated_on_right_p
9706 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9710 struct buffer
*saved_current_buffer
;
9714 /* Find point in a display of infinite width. */
9715 saved_current_buffer
= current_buffer
;
9716 current_buffer
= XBUFFER (w
->buffer
);
9718 if (w
== XWINDOW (selected_window
))
9719 pt
= BUF_PT (current_buffer
);
9722 pt
= marker_position (w
->pointm
);
9723 pt
= max (BEGV
, pt
);
9727 /* Move iterator to pt starting at cursor_row->start in
9728 a line with infinite width. */
9729 init_to_row_start (&it
, w
, cursor_row
);
9730 it
.last_visible_x
= INFINITY
;
9731 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9732 current_buffer
= saved_current_buffer
;
9734 /* Position cursor in window. */
9735 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9736 hscroll
= max (0, (it
.current_x
9737 - (ITERATOR_AT_END_OF_LINE_P (&it
)
9738 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
9739 : (text_area_width
/ 2))))
9740 / FRAME_COLUMN_WIDTH (it
.f
);
9741 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9743 if (hscroll_relative_p
)
9744 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9747 wanted_x
= text_area_width
9748 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9751 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9755 if (hscroll_relative_p
)
9756 wanted_x
= text_area_width
* hscroll_step_rel
9759 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9762 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9764 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9766 /* Don't call Fset_window_hscroll if value hasn't
9767 changed because it will prevent redisplay
9769 if (XFASTINT (w
->hscroll
) != hscroll
)
9771 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9772 w
->hscroll
= make_number (hscroll
);
9781 /* Value is non-zero if hscroll of any leaf window has been changed. */
9786 /* Set hscroll so that cursor is visible and not inside horizontal
9787 scroll margins for all windows in the tree rooted at WINDOW. See
9788 also hscroll_window_tree above. Value is non-zero if any window's
9789 hscroll has been changed. If it has, desired matrices on the frame
9790 of WINDOW are cleared. */
9793 hscroll_windows (window
)
9798 if (automatic_hscrolling_p
)
9800 hscrolled_p
= hscroll_window_tree (window
);
9802 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9811 /************************************************************************
9813 ************************************************************************/
9815 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9816 to a non-zero value. This is sometimes handy to have in a debugger
9821 /* First and last unchanged row for try_window_id. */
9823 int debug_first_unchanged_at_end_vpos
;
9824 int debug_last_unchanged_at_beg_vpos
;
9826 /* Delta vpos and y. */
9828 int debug_dvpos
, debug_dy
;
9830 /* Delta in characters and bytes for try_window_id. */
9832 int debug_delta
, debug_delta_bytes
;
9834 /* Values of window_end_pos and window_end_vpos at the end of
9837 EMACS_INT debug_end_pos
, debug_end_vpos
;
9839 /* Append a string to W->desired_matrix->method. FMT is a printf
9840 format string. A1...A9 are a supplement for a variable-length
9841 argument list. If trace_redisplay_p is non-zero also printf the
9842 resulting string to stderr. */
9845 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9848 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9851 char *method
= w
->desired_matrix
->method
;
9852 int len
= strlen (method
);
9853 int size
= sizeof w
->desired_matrix
->method
;
9854 int remaining
= size
- len
- 1;
9856 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9857 if (len
&& remaining
)
9863 strncpy (method
+ len
, buffer
, remaining
);
9865 if (trace_redisplay_p
)
9866 fprintf (stderr
, "%p (%s): %s\n",
9868 ((BUFFERP (w
->buffer
)
9869 && STRINGP (XBUFFER (w
->buffer
)->name
))
9870 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9875 #endif /* GLYPH_DEBUG */
9878 /* Value is non-zero if all changes in window W, which displays
9879 current_buffer, are in the text between START and END. START is a
9880 buffer position, END is given as a distance from Z. Used in
9881 redisplay_internal for display optimization. */
9884 text_outside_line_unchanged_p (w
, start
, end
)
9888 int unchanged_p
= 1;
9890 /* If text or overlays have changed, see where. */
9891 if (XFASTINT (w
->last_modified
) < MODIFF
9892 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9894 /* Gap in the line? */
9895 if (GPT
< start
|| Z
- GPT
< end
)
9898 /* Changes start in front of the line, or end after it? */
9900 && (BEG_UNCHANGED
< start
- 1
9901 || END_UNCHANGED
< end
))
9904 /* If selective display, can't optimize if changes start at the
9905 beginning of the line. */
9907 && INTEGERP (current_buffer
->selective_display
)
9908 && XINT (current_buffer
->selective_display
) > 0
9909 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9912 /* If there are overlays at the start or end of the line, these
9913 may have overlay strings with newlines in them. A change at
9914 START, for instance, may actually concern the display of such
9915 overlay strings as well, and they are displayed on different
9916 lines. So, quickly rule out this case. (For the future, it
9917 might be desirable to implement something more telling than
9918 just BEG/END_UNCHANGED.) */
9921 if (BEG
+ BEG_UNCHANGED
== start
9922 && overlay_touches_p (start
))
9924 if (END_UNCHANGED
== end
9925 && overlay_touches_p (Z
- end
))
9934 /* Do a frame update, taking possible shortcuts into account. This is
9935 the main external entry point for redisplay.
9937 If the last redisplay displayed an echo area message and that message
9938 is no longer requested, we clear the echo area or bring back the
9939 mini-buffer if that is in use. */
9944 redisplay_internal (0);
9949 overlay_arrow_string_or_property (var
)
9954 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
9957 return Voverlay_arrow_string
;
9960 /* Return 1 if there are any overlay-arrows in current_buffer. */
9962 overlay_arrow_in_current_buffer_p ()
9966 for (vlist
= Voverlay_arrow_variable_list
;
9968 vlist
= XCDR (vlist
))
9970 Lisp_Object var
= XCAR (vlist
);
9975 val
= find_symbol_value (var
);
9977 && current_buffer
== XMARKER (val
)->buffer
)
9984 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
9988 overlay_arrows_changed_p ()
9992 for (vlist
= Voverlay_arrow_variable_list
;
9994 vlist
= XCDR (vlist
))
9996 Lisp_Object var
= XCAR (vlist
);
9997 Lisp_Object val
, pstr
;
10001 val
= find_symbol_value (var
);
10002 if (!MARKERP (val
))
10004 if (! EQ (COERCE_MARKER (val
),
10005 Fget (var
, Qlast_arrow_position
))
10006 || ! (pstr
= overlay_arrow_string_or_property (var
),
10007 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
10013 /* Mark overlay arrows to be updated on next redisplay. */
10016 update_overlay_arrows (up_to_date
)
10021 for (vlist
= Voverlay_arrow_variable_list
;
10023 vlist
= XCDR (vlist
))
10025 Lisp_Object var
= XCAR (vlist
);
10027 if (!SYMBOLP (var
))
10030 if (up_to_date
> 0)
10032 Lisp_Object val
= find_symbol_value (var
);
10033 Fput (var
, Qlast_arrow_position
,
10034 COERCE_MARKER (val
));
10035 Fput (var
, Qlast_arrow_string
,
10036 overlay_arrow_string_or_property (var
));
10038 else if (up_to_date
< 0
10039 || !NILP (Fget (var
, Qlast_arrow_position
)))
10041 Fput (var
, Qlast_arrow_position
, Qt
);
10042 Fput (var
, Qlast_arrow_string
, Qt
);
10048 /* Return overlay arrow string to display at row.
10049 Return integer (bitmap number) for arrow bitmap in left fringe.
10050 Return nil if no overlay arrow. */
10053 overlay_arrow_at_row (it
, row
)
10055 struct glyph_row
*row
;
10059 for (vlist
= Voverlay_arrow_variable_list
;
10061 vlist
= XCDR (vlist
))
10063 Lisp_Object var
= XCAR (vlist
);
10066 if (!SYMBOLP (var
))
10069 val
= find_symbol_value (var
);
10072 && current_buffer
== XMARKER (val
)->buffer
10073 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10075 if (FRAME_WINDOW_P (it
->f
)
10076 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10078 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10081 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10082 return make_number (fringe_bitmap
);
10084 return make_number (-1); /* Use default arrow bitmap */
10086 return overlay_arrow_string_or_property (var
);
10093 /* Return 1 if point moved out of or into a composition. Otherwise
10094 return 0. PREV_BUF and PREV_PT are the last point buffer and
10095 position. BUF and PT are the current point buffer and position. */
10098 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10099 struct buffer
*prev_buf
, *buf
;
10102 EMACS_INT start
, end
;
10104 Lisp_Object buffer
;
10106 XSETBUFFER (buffer
, buf
);
10107 /* Check a composition at the last point if point moved within the
10109 if (prev_buf
== buf
)
10112 /* Point didn't move. */
10115 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10116 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10117 && COMPOSITION_VALID_P (start
, end
, prop
)
10118 && start
< prev_pt
&& end
> prev_pt
)
10119 /* The last point was within the composition. Return 1 iff
10120 point moved out of the composition. */
10121 return (pt
<= start
|| pt
>= end
);
10124 /* Check a composition at the current point. */
10125 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10126 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10127 && COMPOSITION_VALID_P (start
, end
, prop
)
10128 && start
< pt
&& end
> pt
);
10132 /* Reconsider the setting of B->clip_changed which is displayed
10136 reconsider_clip_changes (w
, b
)
10140 if (b
->clip_changed
10141 && !NILP (w
->window_end_valid
)
10142 && w
->current_matrix
->buffer
== b
10143 && w
->current_matrix
->zv
== BUF_ZV (b
)
10144 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10145 b
->clip_changed
= 0;
10147 /* If display wasn't paused, and W is not a tool bar window, see if
10148 point has been moved into or out of a composition. In that case,
10149 we set b->clip_changed to 1 to force updating the screen. If
10150 b->clip_changed has already been set to 1, we can skip this
10152 if (!b
->clip_changed
10153 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10157 if (w
== XWINDOW (selected_window
))
10158 pt
= BUF_PT (current_buffer
);
10160 pt
= marker_position (w
->pointm
);
10162 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10163 || pt
!= XINT (w
->last_point
))
10164 && check_point_in_composition (w
->current_matrix
->buffer
,
10165 XINT (w
->last_point
),
10166 XBUFFER (w
->buffer
), pt
))
10167 b
->clip_changed
= 1;
10172 /* Select FRAME to forward the values of frame-local variables into C
10173 variables so that the redisplay routines can access those values
10177 select_frame_for_redisplay (frame
)
10180 Lisp_Object tail
, sym
, val
;
10181 Lisp_Object old
= selected_frame
;
10183 selected_frame
= frame
;
10185 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10186 if (CONSP (XCAR (tail
))
10187 && (sym
= XCAR (XCAR (tail
)),
10189 && (sym
= indirect_variable (sym
),
10190 val
= SYMBOL_VALUE (sym
),
10191 (BUFFER_LOCAL_VALUEP (val
)
10192 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10193 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10194 /* Use find_symbol_value rather than Fsymbol_value
10195 to avoid an error if it is void. */
10196 find_symbol_value (sym
);
10198 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10199 if (CONSP (XCAR (tail
))
10200 && (sym
= XCAR (XCAR (tail
)),
10202 && (sym
= indirect_variable (sym
),
10203 val
= SYMBOL_VALUE (sym
),
10204 (BUFFER_LOCAL_VALUEP (val
)
10205 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10206 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10207 find_symbol_value (sym
);
10211 #define STOP_POLLING \
10212 do { if (! polling_stopped_here) stop_polling (); \
10213 polling_stopped_here = 1; } while (0)
10215 #define RESUME_POLLING \
10216 do { if (polling_stopped_here) start_polling (); \
10217 polling_stopped_here = 0; } while (0)
10220 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10221 response to any user action; therefore, we should preserve the echo
10222 area. (Actually, our caller does that job.) Perhaps in the future
10223 avoid recentering windows if it is not necessary; currently that
10224 causes some problems. */
10227 redisplay_internal (preserve_echo_area
)
10228 int preserve_echo_area
;
10230 struct window
*w
= XWINDOW (selected_window
);
10231 struct frame
*f
= XFRAME (w
->frame
);
10233 int must_finish
= 0;
10234 struct text_pos tlbufpos
, tlendpos
;
10235 int number_of_visible_frames
;
10237 struct frame
*sf
= SELECTED_FRAME ();
10238 int polling_stopped_here
= 0;
10240 /* Non-zero means redisplay has to consider all windows on all
10241 frames. Zero means, only selected_window is considered. */
10242 int consider_all_windows_p
;
10244 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10246 /* No redisplay if running in batch mode or frame is not yet fully
10247 initialized, or redisplay is explicitly turned off by setting
10248 Vinhibit_redisplay. */
10250 || !NILP (Vinhibit_redisplay
)
10251 || !f
->glyphs_initialized_p
)
10254 /* The flag redisplay_performed_directly_p is set by
10255 direct_output_for_insert when it already did the whole screen
10256 update necessary. */
10257 if (redisplay_performed_directly_p
)
10259 redisplay_performed_directly_p
= 0;
10260 if (!hscroll_windows (selected_window
))
10264 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
10265 if (popup_activated ())
10269 /* I don't think this happens but let's be paranoid. */
10270 if (redisplaying_p
)
10273 /* Record a function that resets redisplaying_p to its old value
10274 when we leave this function. */
10275 count
= SPECPDL_INDEX ();
10276 record_unwind_protect (unwind_redisplay
,
10277 Fcons (make_number (redisplaying_p
), selected_frame
));
10279 specbind (Qinhibit_free_realized_faces
, Qnil
);
10282 Lisp_Object tail
, frame
;
10284 FOR_EACH_FRAME (tail
, frame
)
10286 struct frame
*f
= XFRAME (frame
);
10287 f
->already_hscrolled_p
= 0;
10293 reconsider_clip_changes (w
, current_buffer
);
10295 /* If new fonts have been loaded that make a glyph matrix adjustment
10296 necessary, do it. */
10297 if (fonts_changed_p
)
10299 adjust_glyphs (NULL
);
10300 ++windows_or_buffers_changed
;
10301 fonts_changed_p
= 0;
10304 /* If face_change_count is non-zero, init_iterator will free all
10305 realized faces, which includes the faces referenced from current
10306 matrices. So, we can't reuse current matrices in this case. */
10307 if (face_change_count
)
10308 ++windows_or_buffers_changed
;
10310 if (! FRAME_WINDOW_P (sf
)
10311 && previous_terminal_frame
!= sf
)
10313 /* Since frames on an ASCII terminal share the same display
10314 area, displaying a different frame means redisplay the whole
10316 windows_or_buffers_changed
++;
10317 SET_FRAME_GARBAGED (sf
);
10318 XSETFRAME (Vterminal_frame
, sf
);
10320 previous_terminal_frame
= sf
;
10322 /* Set the visible flags for all frames. Do this before checking
10323 for resized or garbaged frames; they want to know if their frames
10324 are visible. See the comment in frame.h for
10325 FRAME_SAMPLE_VISIBILITY. */
10327 Lisp_Object tail
, frame
;
10329 number_of_visible_frames
= 0;
10331 FOR_EACH_FRAME (tail
, frame
)
10333 struct frame
*f
= XFRAME (frame
);
10335 FRAME_SAMPLE_VISIBILITY (f
);
10336 if (FRAME_VISIBLE_P (f
))
10337 ++number_of_visible_frames
;
10338 clear_desired_matrices (f
);
10342 /* Notice any pending interrupt request to change frame size. */
10343 do_pending_window_change (1);
10345 /* Clear frames marked as garbaged. */
10346 if (frame_garbaged
)
10347 clear_garbaged_frames ();
10349 /* Build menubar and tool-bar items. */
10350 prepare_menu_bars ();
10352 if (windows_or_buffers_changed
)
10353 update_mode_lines
++;
10355 /* Detect case that we need to write or remove a star in the mode line. */
10356 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10358 w
->update_mode_line
= Qt
;
10359 if (buffer_shared
> 1)
10360 update_mode_lines
++;
10363 /* If %c is in the mode line, update it if needed. */
10364 if (!NILP (w
->column_number_displayed
)
10365 /* This alternative quickly identifies a common case
10366 where no change is needed. */
10367 && !(PT
== XFASTINT (w
->last_point
)
10368 && XFASTINT (w
->last_modified
) >= MODIFF
10369 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10370 && (XFASTINT (w
->column_number_displayed
)
10371 != (int) current_column ())) /* iftc */
10372 w
->update_mode_line
= Qt
;
10374 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10376 /* The variable buffer_shared is set in redisplay_window and
10377 indicates that we redisplay a buffer in different windows. See
10379 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10380 || cursor_type_changed
);
10382 /* If specs for an arrow have changed, do thorough redisplay
10383 to ensure we remove any arrow that should no longer exist. */
10384 if (overlay_arrows_changed_p ())
10385 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10387 /* Normally the message* functions will have already displayed and
10388 updated the echo area, but the frame may have been trashed, or
10389 the update may have been preempted, so display the echo area
10390 again here. Checking message_cleared_p captures the case that
10391 the echo area should be cleared. */
10392 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10393 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10394 || (message_cleared_p
10395 && minibuf_level
== 0
10396 /* If the mini-window is currently selected, this means the
10397 echo-area doesn't show through. */
10398 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10400 int window_height_changed_p
= echo_area_display (0);
10403 /* If we don't display the current message, don't clear the
10404 message_cleared_p flag, because, if we did, we wouldn't clear
10405 the echo area in the next redisplay which doesn't preserve
10407 if (!display_last_displayed_message_p
)
10408 message_cleared_p
= 0;
10410 if (fonts_changed_p
)
10412 else if (window_height_changed_p
)
10414 consider_all_windows_p
= 1;
10415 ++update_mode_lines
;
10416 ++windows_or_buffers_changed
;
10418 /* If window configuration was changed, frames may have been
10419 marked garbaged. Clear them or we will experience
10420 surprises wrt scrolling. */
10421 if (frame_garbaged
)
10422 clear_garbaged_frames ();
10425 else if (EQ (selected_window
, minibuf_window
)
10426 && (current_buffer
->clip_changed
10427 || XFASTINT (w
->last_modified
) < MODIFF
10428 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10429 && resize_mini_window (w
, 0))
10431 /* Resized active mini-window to fit the size of what it is
10432 showing if its contents might have changed. */
10434 consider_all_windows_p
= 1;
10435 ++windows_or_buffers_changed
;
10436 ++update_mode_lines
;
10438 /* If window configuration was changed, frames may have been
10439 marked garbaged. Clear them or we will experience
10440 surprises wrt scrolling. */
10441 if (frame_garbaged
)
10442 clear_garbaged_frames ();
10446 /* If showing the region, and mark has changed, we must redisplay
10447 the whole window. The assignment to this_line_start_pos prevents
10448 the optimization directly below this if-statement. */
10449 if (((!NILP (Vtransient_mark_mode
)
10450 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10451 != !NILP (w
->region_showing
))
10452 || (!NILP (w
->region_showing
)
10453 && !EQ (w
->region_showing
,
10454 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
10455 CHARPOS (this_line_start_pos
) = 0;
10457 /* Optimize the case that only the line containing the cursor in the
10458 selected window has changed. Variables starting with this_ are
10459 set in display_line and record information about the line
10460 containing the cursor. */
10461 tlbufpos
= this_line_start_pos
;
10462 tlendpos
= this_line_end_pos
;
10463 if (!consider_all_windows_p
10464 && CHARPOS (tlbufpos
) > 0
10465 && NILP (w
->update_mode_line
)
10466 && !current_buffer
->clip_changed
10467 && !current_buffer
->prevent_redisplay_optimizations_p
10468 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
10469 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
10470 /* Make sure recorded data applies to current buffer, etc. */
10471 && this_line_buffer
== current_buffer
10472 && current_buffer
== XBUFFER (w
->buffer
)
10473 && NILP (w
->force_start
)
10474 && NILP (w
->optional_new_start
)
10475 /* Point must be on the line that we have info recorded about. */
10476 && PT
>= CHARPOS (tlbufpos
)
10477 && PT
<= Z
- CHARPOS (tlendpos
)
10478 /* All text outside that line, including its final newline,
10479 must be unchanged */
10480 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
10481 CHARPOS (tlendpos
)))
10483 if (CHARPOS (tlbufpos
) > BEGV
10484 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
10485 && (CHARPOS (tlbufpos
) == ZV
10486 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
10487 /* Former continuation line has disappeared by becoming empty */
10489 else if (XFASTINT (w
->last_modified
) < MODIFF
10490 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
10491 || MINI_WINDOW_P (w
))
10493 /* We have to handle the case of continuation around a
10494 wide-column character (See the comment in indent.c around
10497 For instance, in the following case:
10499 -------- Insert --------
10500 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
10501 J_I_ ==> J_I_ `^^' are cursors.
10505 As we have to redraw the line above, we should goto cancel. */
10508 int line_height_before
= this_line_pixel_height
;
10510 /* Note that start_display will handle the case that the
10511 line starting at tlbufpos is a continuation lines. */
10512 start_display (&it
, w
, tlbufpos
);
10514 /* Implementation note: It this still necessary? */
10515 if (it
.current_x
!= this_line_start_x
)
10518 TRACE ((stderr
, "trying display optimization 1\n"));
10519 w
->cursor
.vpos
= -1;
10520 overlay_arrow_seen
= 0;
10521 it
.vpos
= this_line_vpos
;
10522 it
.current_y
= this_line_y
;
10523 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10524 display_line (&it
);
10526 /* If line contains point, is not continued,
10527 and ends at same distance from eob as before, we win */
10528 if (w
->cursor
.vpos
>= 0
10529 /* Line is not continued, otherwise this_line_start_pos
10530 would have been set to 0 in display_line. */
10531 && CHARPOS (this_line_start_pos
)
10532 /* Line ends as before. */
10533 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10534 /* Line has same height as before. Otherwise other lines
10535 would have to be shifted up or down. */
10536 && this_line_pixel_height
== line_height_before
)
10538 /* If this is not the window's last line, we must adjust
10539 the charstarts of the lines below. */
10540 if (it
.current_y
< it
.last_visible_y
)
10542 struct glyph_row
*row
10543 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10544 int delta
, delta_bytes
;
10546 if (Z
- CHARPOS (tlendpos
) == ZV
)
10548 /* This line ends at end of (accessible part of)
10549 buffer. There is no newline to count. */
10551 - CHARPOS (tlendpos
)
10552 - MATRIX_ROW_START_CHARPOS (row
));
10553 delta_bytes
= (Z_BYTE
10554 - BYTEPOS (tlendpos
)
10555 - MATRIX_ROW_START_BYTEPOS (row
));
10559 /* This line ends in a newline. Must take
10560 account of the newline and the rest of the
10561 text that follows. */
10563 - CHARPOS (tlendpos
)
10564 - MATRIX_ROW_START_CHARPOS (row
));
10565 delta_bytes
= (Z_BYTE
10566 - BYTEPOS (tlendpos
)
10567 - MATRIX_ROW_START_BYTEPOS (row
));
10570 increment_matrix_positions (w
->current_matrix
,
10571 this_line_vpos
+ 1,
10572 w
->current_matrix
->nrows
,
10573 delta
, delta_bytes
);
10576 /* If this row displays text now but previously didn't,
10577 or vice versa, w->window_end_vpos may have to be
10579 if ((it
.glyph_row
- 1)->displays_text_p
)
10581 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10582 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10584 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10585 && this_line_vpos
> 0)
10586 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10587 w
->window_end_valid
= Qnil
;
10589 /* Update hint: No need to try to scroll in update_window. */
10590 w
->desired_matrix
->no_scrolling_p
= 1;
10593 *w
->desired_matrix
->method
= 0;
10594 debug_method_add (w
, "optimization 1");
10596 #ifdef HAVE_WINDOW_SYSTEM
10597 update_window_fringes (w
, 0);
10604 else if (/* Cursor position hasn't changed. */
10605 PT
== XFASTINT (w
->last_point
)
10606 /* Make sure the cursor was last displayed
10607 in this window. Otherwise we have to reposition it. */
10608 && 0 <= w
->cursor
.vpos
10609 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10613 do_pending_window_change (1);
10615 /* We used to always goto end_of_redisplay here, but this
10616 isn't enough if we have a blinking cursor. */
10617 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10618 goto end_of_redisplay
;
10622 /* If highlighting the region, or if the cursor is in the echo area,
10623 then we can't just move the cursor. */
10624 else if (! (!NILP (Vtransient_mark_mode
)
10625 && !NILP (current_buffer
->mark_active
))
10626 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10627 || highlight_nonselected_windows
)
10628 && NILP (w
->region_showing
)
10629 && NILP (Vshow_trailing_whitespace
)
10630 && !cursor_in_echo_area
)
10633 struct glyph_row
*row
;
10635 /* Skip from tlbufpos to PT and see where it is. Note that
10636 PT may be in invisible text. If so, we will end at the
10637 next visible position. */
10638 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10639 NULL
, DEFAULT_FACE_ID
);
10640 it
.current_x
= this_line_start_x
;
10641 it
.current_y
= this_line_y
;
10642 it
.vpos
= this_line_vpos
;
10644 /* The call to move_it_to stops in front of PT, but
10645 moves over before-strings. */
10646 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10648 if (it
.vpos
== this_line_vpos
10649 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10652 xassert (this_line_vpos
== it
.vpos
);
10653 xassert (this_line_y
== it
.current_y
);
10654 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10656 *w
->desired_matrix
->method
= 0;
10657 debug_method_add (w
, "optimization 3");
10666 /* Text changed drastically or point moved off of line. */
10667 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10670 CHARPOS (this_line_start_pos
) = 0;
10671 consider_all_windows_p
|= buffer_shared
> 1;
10672 ++clear_face_cache_count
;
10673 #ifdef HAVE_WINDOW_SYSTEM
10674 ++clear_image_cache_count
;
10677 /* Build desired matrices, and update the display. If
10678 consider_all_windows_p is non-zero, do it for all windows on all
10679 frames. Otherwise do it for selected_window, only. */
10681 if (consider_all_windows_p
)
10683 Lisp_Object tail
, frame
;
10684 int i
, n
= 0, size
= 50;
10685 struct frame
**updated
10686 = (struct frame
**) alloca (size
* sizeof *updated
);
10688 /* Recompute # windows showing selected buffer. This will be
10689 incremented each time such a window is displayed. */
10692 FOR_EACH_FRAME (tail
, frame
)
10694 struct frame
*f
= XFRAME (frame
);
10696 if (FRAME_WINDOW_P (f
) || f
== sf
)
10698 if (! EQ (frame
, selected_frame
))
10699 /* Select the frame, for the sake of frame-local
10701 select_frame_for_redisplay (frame
);
10703 /* Mark all the scroll bars to be removed; we'll redeem
10704 the ones we want when we redisplay their windows. */
10705 if (condemn_scroll_bars_hook
)
10706 condemn_scroll_bars_hook (f
);
10708 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10709 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10711 /* Any scroll bars which redisplay_windows should have
10712 nuked should now go away. */
10713 if (judge_scroll_bars_hook
)
10714 judge_scroll_bars_hook (f
);
10716 /* If fonts changed, display again. */
10717 /* ??? rms: I suspect it is a mistake to jump all the way
10718 back to retry here. It should just retry this frame. */
10719 if (fonts_changed_p
)
10722 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10724 /* See if we have to hscroll. */
10725 if (!f
->already_hscrolled_p
)
10727 f
->already_hscrolled_p
= 1;
10728 if (hscroll_windows (f
->root_window
))
10732 /* Prevent various kinds of signals during display
10733 update. stdio is not robust about handling
10734 signals, which can cause an apparent I/O
10736 if (interrupt_input
)
10737 unrequest_sigio ();
10740 /* Update the display. */
10741 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10742 pause
|= update_frame (f
, 0, 0);
10743 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10750 int nbytes
= size
* sizeof *updated
;
10751 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
10752 bcopy (updated
, p
, nbytes
);
10763 /* Do the mark_window_display_accurate after all windows have
10764 been redisplayed because this call resets flags in buffers
10765 which are needed for proper redisplay. */
10766 for (i
= 0; i
< n
; ++i
)
10768 struct frame
*f
= updated
[i
];
10769 mark_window_display_accurate (f
->root_window
, 1);
10770 if (frame_up_to_date_hook
)
10771 frame_up_to_date_hook (f
);
10775 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10777 Lisp_Object mini_window
;
10778 struct frame
*mini_frame
;
10780 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10781 /* Use list_of_error, not Qerror, so that
10782 we catch only errors and don't run the debugger. */
10783 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10785 redisplay_window_error
);
10787 /* Compare desired and current matrices, perform output. */
10790 /* If fonts changed, display again. */
10791 if (fonts_changed_p
)
10794 /* Prevent various kinds of signals during display update.
10795 stdio is not robust about handling signals,
10796 which can cause an apparent I/O error. */
10797 if (interrupt_input
)
10798 unrequest_sigio ();
10801 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10803 if (hscroll_windows (selected_window
))
10806 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10807 pause
= update_frame (sf
, 0, 0);
10810 /* We may have called echo_area_display at the top of this
10811 function. If the echo area is on another frame, that may
10812 have put text on a frame other than the selected one, so the
10813 above call to update_frame would not have caught it. Catch
10815 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10816 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10818 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10820 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10821 pause
|= update_frame (mini_frame
, 0, 0);
10822 if (!pause
&& hscroll_windows (mini_window
))
10827 /* If display was paused because of pending input, make sure we do a
10828 thorough update the next time. */
10831 /* Prevent the optimization at the beginning of
10832 redisplay_internal that tries a single-line update of the
10833 line containing the cursor in the selected window. */
10834 CHARPOS (this_line_start_pos
) = 0;
10836 /* Let the overlay arrow be updated the next time. */
10837 update_overlay_arrows (0);
10839 /* If we pause after scrolling, some rows in the current
10840 matrices of some windows are not valid. */
10841 if (!WINDOW_FULL_WIDTH_P (w
)
10842 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10843 update_mode_lines
= 1;
10847 if (!consider_all_windows_p
)
10849 /* This has already been done above if
10850 consider_all_windows_p is set. */
10851 mark_window_display_accurate_1 (w
, 1);
10853 /* Say overlay arrows are up to date. */
10854 update_overlay_arrows (1);
10856 if (frame_up_to_date_hook
!= 0)
10857 frame_up_to_date_hook (sf
);
10860 update_mode_lines
= 0;
10861 windows_or_buffers_changed
= 0;
10862 cursor_type_changed
= 0;
10865 /* Start SIGIO interrupts coming again. Having them off during the
10866 code above makes it less likely one will discard output, but not
10867 impossible, since there might be stuff in the system buffer here.
10868 But it is much hairier to try to do anything about that. */
10869 if (interrupt_input
)
10873 /* If a frame has become visible which was not before, redisplay
10874 again, so that we display it. Expose events for such a frame
10875 (which it gets when becoming visible) don't call the parts of
10876 redisplay constructing glyphs, so simply exposing a frame won't
10877 display anything in this case. So, we have to display these
10878 frames here explicitly. */
10881 Lisp_Object tail
, frame
;
10884 FOR_EACH_FRAME (tail
, frame
)
10886 int this_is_visible
= 0;
10888 if (XFRAME (frame
)->visible
)
10889 this_is_visible
= 1;
10890 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10891 if (XFRAME (frame
)->visible
)
10892 this_is_visible
= 1;
10894 if (this_is_visible
)
10898 if (new_count
!= number_of_visible_frames
)
10899 windows_or_buffers_changed
++;
10902 /* Change frame size now if a change is pending. */
10903 do_pending_window_change (1);
10905 /* If we just did a pending size change, or have additional
10906 visible frames, redisplay again. */
10907 if (windows_or_buffers_changed
&& !pause
)
10910 /* Clear the face cache eventually. */
10911 if (consider_all_windows_p
)
10913 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
10915 clear_face_cache (0);
10916 clear_face_cache_count
= 0;
10918 #ifdef HAVE_WINDOW_SYSTEM
10919 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
10921 Lisp_Object tail
, frame
;
10922 FOR_EACH_FRAME (tail
, frame
)
10924 struct frame
*f
= XFRAME (frame
);
10925 if (FRAME_WINDOW_P (f
))
10926 clear_image_cache (f
, 0);
10928 clear_image_cache_count
= 0;
10930 #endif /* HAVE_WINDOW_SYSTEM */
10934 unbind_to (count
, Qnil
);
10939 /* Redisplay, but leave alone any recent echo area message unless
10940 another message has been requested in its place.
10942 This is useful in situations where you need to redisplay but no
10943 user action has occurred, making it inappropriate for the message
10944 area to be cleared. See tracking_off and
10945 wait_reading_process_output for examples of these situations.
10947 FROM_WHERE is an integer saying from where this function was
10948 called. This is useful for debugging. */
10951 redisplay_preserve_echo_area (from_where
)
10954 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10956 if (!NILP (echo_area_buffer
[1]))
10958 /* We have a previously displayed message, but no current
10959 message. Redisplay the previous message. */
10960 display_last_displayed_message_p
= 1;
10961 redisplay_internal (1);
10962 display_last_displayed_message_p
= 0;
10965 redisplay_internal (1);
10967 if (rif
!= NULL
&& rif
->flush_display_optional
)
10968 rif
->flush_display_optional (NULL
);
10972 /* Function registered with record_unwind_protect in
10973 redisplay_internal. Reset redisplaying_p to the value it had
10974 before redisplay_internal was called, and clear
10975 prevent_freeing_realized_faces_p. It also selects the previously
10979 unwind_redisplay (val
)
10982 Lisp_Object old_redisplaying_p
, old_frame
;
10984 old_redisplaying_p
= XCAR (val
);
10985 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10986 old_frame
= XCDR (val
);
10987 if (! EQ (old_frame
, selected_frame
))
10988 select_frame_for_redisplay (old_frame
);
10993 /* Mark the display of window W as accurate or inaccurate. If
10994 ACCURATE_P is non-zero mark display of W as accurate. If
10995 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10996 redisplay_internal is called. */
10999 mark_window_display_accurate_1 (w
, accurate_p
)
11003 if (BUFFERP (w
->buffer
))
11005 struct buffer
*b
= XBUFFER (w
->buffer
);
11008 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
11009 w
->last_overlay_modified
11010 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
11012 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
11016 b
->clip_changed
= 0;
11017 b
->prevent_redisplay_optimizations_p
= 0;
11019 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
11020 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
11021 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
11022 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
11024 w
->current_matrix
->buffer
= b
;
11025 w
->current_matrix
->begv
= BUF_BEGV (b
);
11026 w
->current_matrix
->zv
= BUF_ZV (b
);
11028 w
->last_cursor
= w
->cursor
;
11029 w
->last_cursor_off_p
= w
->cursor_off_p
;
11031 if (w
== XWINDOW (selected_window
))
11032 w
->last_point
= make_number (BUF_PT (b
));
11034 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
11040 w
->window_end_valid
= w
->buffer
;
11041 #if 0 /* This is incorrect with variable-height lines. */
11042 xassert (XINT (w
->window_end_vpos
)
11043 < (WINDOW_TOTAL_LINES (w
)
11044 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
11046 w
->update_mode_line
= Qnil
;
11051 /* Mark the display of windows in the window tree rooted at WINDOW as
11052 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
11053 windows as accurate. If ACCURATE_P is zero, arrange for windows to
11054 be redisplayed the next time redisplay_internal is called. */
11057 mark_window_display_accurate (window
, accurate_p
)
11058 Lisp_Object window
;
11063 for (; !NILP (window
); window
= w
->next
)
11065 w
= XWINDOW (window
);
11066 mark_window_display_accurate_1 (w
, accurate_p
);
11068 if (!NILP (w
->vchild
))
11069 mark_window_display_accurate (w
->vchild
, accurate_p
);
11070 if (!NILP (w
->hchild
))
11071 mark_window_display_accurate (w
->hchild
, accurate_p
);
11076 update_overlay_arrows (1);
11080 /* Force a thorough redisplay the next time by setting
11081 last_arrow_position and last_arrow_string to t, which is
11082 unequal to any useful value of Voverlay_arrow_... */
11083 update_overlay_arrows (-1);
11088 /* Return value in display table DP (Lisp_Char_Table *) for character
11089 C. Since a display table doesn't have any parent, we don't have to
11090 follow parent. Do not call this function directly but use the
11091 macro DISP_CHAR_VECTOR. */
11094 disp_char_vector (dp
, c
)
11095 struct Lisp_Char_Table
*dp
;
11100 if (ASCII_CHAR_P (c
))
11103 if (SUB_CHAR_TABLE_P (val
))
11104 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
11110 XSETCHAR_TABLE (table
, dp
);
11111 val
= char_table_ref (table
, c
);
11120 /***********************************************************************
11122 ***********************************************************************/
11124 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11127 redisplay_windows (window
)
11128 Lisp_Object window
;
11130 while (!NILP (window
))
11132 struct window
*w
= XWINDOW (window
);
11134 if (!NILP (w
->hchild
))
11135 redisplay_windows (w
->hchild
);
11136 else if (!NILP (w
->vchild
))
11137 redisplay_windows (w
->vchild
);
11140 displayed_buffer
= XBUFFER (w
->buffer
);
11141 /* Use list_of_error, not Qerror, so that
11142 we catch only errors and don't run the debugger. */
11143 internal_condition_case_1 (redisplay_window_0
, window
,
11145 redisplay_window_error
);
11153 redisplay_window_error ()
11155 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11160 redisplay_window_0 (window
)
11161 Lisp_Object window
;
11163 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11164 redisplay_window (window
, 0);
11169 redisplay_window_1 (window
)
11170 Lisp_Object window
;
11172 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11173 redisplay_window (window
, 1);
11178 /* Increment GLYPH until it reaches END or CONDITION fails while
11179 adding (GLYPH)->pixel_width to X. */
11181 #define SKIP_GLYPHS(glyph, end, x, condition) \
11184 (x) += (glyph)->pixel_width; \
11187 while ((glyph) < (end) && (condition))
11190 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11191 DELTA is the number of bytes by which positions recorded in ROW
11192 differ from current buffer positions. */
11195 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11197 struct glyph_row
*row
;
11198 struct glyph_matrix
*matrix
;
11199 int delta
, delta_bytes
, dy
, dvpos
;
11201 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11202 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11203 struct glyph
*cursor
= NULL
;
11204 /* The first glyph that starts a sequence of glyphs from string. */
11205 struct glyph
*string_start
;
11206 /* The X coordinate of string_start. */
11207 int string_start_x
;
11208 /* The last known character position. */
11209 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11210 /* The last known character position before string_start. */
11211 int string_before_pos
;
11214 int cursor_from_overlay_pos
= 0;
11215 int pt_old
= PT
- delta
;
11217 /* Skip over glyphs not having an object at the start of the row.
11218 These are special glyphs like truncation marks on terminal
11220 if (row
->displays_text_p
)
11222 && INTEGERP (glyph
->object
)
11223 && glyph
->charpos
< 0)
11225 x
+= glyph
->pixel_width
;
11229 string_start
= NULL
;
11231 && !INTEGERP (glyph
->object
)
11232 && (!BUFFERP (glyph
->object
)
11233 || (last_pos
= glyph
->charpos
) < pt_old
))
11235 if (! STRINGP (glyph
->object
))
11237 string_start
= NULL
;
11238 x
+= glyph
->pixel_width
;
11240 if (cursor_from_overlay_pos
11241 && last_pos
> cursor_from_overlay_pos
)
11243 cursor_from_overlay_pos
= 0;
11249 string_before_pos
= last_pos
;
11250 string_start
= glyph
;
11251 string_start_x
= x
;
11252 /* Skip all glyphs from string. */
11256 if ((cursor
== NULL
|| glyph
> cursor
)
11257 && !NILP (Fget_char_property (make_number ((glyph
)->charpos
),
11258 Qcursor
, (glyph
)->object
))
11259 && (pos
= string_buffer_position (w
, glyph
->object
,
11260 string_before_pos
),
11261 (pos
== 0 /* From overlay */
11262 || pos
== pt_old
)))
11264 /* Estimate overlay buffer position from the buffer
11265 positions of the glyphs before and after the overlay.
11266 Add 1 to last_pos so that if point corresponds to the
11267 glyph right after the overlay, we still use a 'cursor'
11268 property found in that overlay. */
11269 cursor_from_overlay_pos
= pos
== 0 ? last_pos
+1 : 0;
11273 x
+= glyph
->pixel_width
;
11276 while (glyph
< end
&& STRINGP (glyph
->object
));
11280 if (cursor
!= NULL
)
11285 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
11287 /* Scan back over the ellipsis glyphs, decrementing positions. */
11288 while (glyph
> row
->glyphs
[TEXT_AREA
]
11289 && (glyph
- 1)->charpos
== last_pos
)
11290 glyph
--, x
-= glyph
->pixel_width
;
11291 /* That loop always goes one position too far,
11292 including the glyph before the ellipsis.
11293 So scan forward over that one. */
11294 x
+= glyph
->pixel_width
;
11297 else if (string_start
11298 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11300 /* We may have skipped over point because the previous glyphs
11301 are from string. As there's no easy way to know the
11302 character position of the current glyph, find the correct
11303 glyph on point by scanning from string_start again. */
11305 Lisp_Object string
;
11308 limit
= make_number (pt_old
+ 1);
11310 glyph
= string_start
;
11311 x
= string_start_x
;
11312 string
= glyph
->object
;
11313 pos
= string_buffer_position (w
, string
, string_before_pos
);
11314 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11315 because we always put cursor after overlay strings. */
11316 while (pos
== 0 && glyph
< end
)
11318 string
= glyph
->object
;
11319 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11321 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11324 while (glyph
< end
)
11326 pos
= XINT (Fnext_single_char_property_change
11327 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11330 /* Skip glyphs from the same string. */
11331 string
= glyph
->object
;
11332 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11333 /* Skip glyphs from an overlay. */
11335 && ! string_buffer_position (w
, glyph
->object
, pos
))
11337 string
= glyph
->object
;
11338 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11343 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11345 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11346 w
->cursor
.y
= row
->y
+ dy
;
11348 if (w
== XWINDOW (selected_window
))
11350 if (!row
->continued_p
11351 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11354 this_line_buffer
= XBUFFER (w
->buffer
);
11356 CHARPOS (this_line_start_pos
)
11357 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11358 BYTEPOS (this_line_start_pos
)
11359 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
11361 CHARPOS (this_line_end_pos
)
11362 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
11363 BYTEPOS (this_line_end_pos
)
11364 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
11366 this_line_y
= w
->cursor
.y
;
11367 this_line_pixel_height
= row
->height
;
11368 this_line_vpos
= w
->cursor
.vpos
;
11369 this_line_start_x
= row
->x
;
11372 CHARPOS (this_line_start_pos
) = 0;
11377 /* Run window scroll functions, if any, for WINDOW with new window
11378 start STARTP. Sets the window start of WINDOW to that position.
11380 We assume that the window's buffer is really current. */
11382 static INLINE
struct text_pos
11383 run_window_scroll_functions (window
, startp
)
11384 Lisp_Object window
;
11385 struct text_pos startp
;
11387 struct window
*w
= XWINDOW (window
);
11388 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
11390 if (current_buffer
!= XBUFFER (w
->buffer
))
11393 if (!NILP (Vwindow_scroll_functions
))
11395 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
11396 make_number (CHARPOS (startp
)));
11397 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11398 /* In case the hook functions switch buffers. */
11399 if (current_buffer
!= XBUFFER (w
->buffer
))
11400 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11407 /* Make sure the line containing the cursor is fully visible.
11408 A value of 1 means there is nothing to be done.
11409 (Either the line is fully visible, or it cannot be made so,
11410 or we cannot tell.)
11412 If FORCE_P is non-zero, return 0 even if partial visible cursor row
11413 is higher than window.
11415 A value of 0 means the caller should do scrolling
11416 as if point had gone off the screen. */
11419 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
11423 struct glyph_matrix
*matrix
;
11424 struct glyph_row
*row
;
11427 if (!make_cursor_line_fully_visible_p
)
11430 /* It's not always possible to find the cursor, e.g, when a window
11431 is full of overlay strings. Don't do anything in that case. */
11432 if (w
->cursor
.vpos
< 0)
11435 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
11436 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
11438 /* If the cursor row is not partially visible, there's nothing to do. */
11439 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
11442 /* If the row the cursor is in is taller than the window's height,
11443 it's not clear what to do, so do nothing. */
11444 window_height
= window_box_height (w
);
11445 if (row
->height
>= window_height
)
11447 if (!force_p
|| MINI_WINDOW_P (w
) || w
->vscroll
)
11453 /* This code used to try to scroll the window just enough to make
11454 the line visible. It returned 0 to say that the caller should
11455 allocate larger glyph matrices. */
11457 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
11459 int dy
= row
->height
- row
->visible_height
;
11462 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11464 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
11466 int dy
= - (row
->height
- row
->visible_height
);
11469 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11472 /* When we change the cursor y-position of the selected window,
11473 change this_line_y as well so that the display optimization for
11474 the cursor line of the selected window in redisplay_internal uses
11475 the correct y-position. */
11476 if (w
== XWINDOW (selected_window
))
11477 this_line_y
= w
->cursor
.y
;
11479 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
11480 redisplay with larger matrices. */
11481 if (matrix
->nrows
< required_matrix_height (w
))
11483 fonts_changed_p
= 1;
11492 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
11493 non-zero means only WINDOW is redisplayed in redisplay_internal.
11494 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
11495 in redisplay_window to bring a partially visible line into view in
11496 the case that only the cursor has moved.
11498 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
11499 last screen line's vertical height extends past the end of the screen.
11503 1 if scrolling succeeded
11505 0 if scrolling didn't find point.
11507 -1 if new fonts have been loaded so that we must interrupt
11508 redisplay, adjust glyph matrices, and try again. */
11514 SCROLLING_NEED_LARGER_MATRICES
11518 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
11519 scroll_step
, temp_scroll_step
, last_line_misfit
)
11520 Lisp_Object window
;
11521 int just_this_one_p
;
11522 EMACS_INT scroll_conservatively
, scroll_step
;
11523 int temp_scroll_step
;
11524 int last_line_misfit
;
11526 struct window
*w
= XWINDOW (window
);
11527 struct frame
*f
= XFRAME (w
->frame
);
11528 struct text_pos scroll_margin_pos
;
11529 struct text_pos pos
;
11530 struct text_pos startp
;
11532 Lisp_Object window_end
;
11533 int this_scroll_margin
;
11537 int amount_to_scroll
= 0;
11538 Lisp_Object aggressive
;
11540 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
11543 debug_method_add (w
, "try_scrolling");
11546 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11548 /* Compute scroll margin height in pixels. We scroll when point is
11549 within this distance from the top or bottom of the window. */
11550 if (scroll_margin
> 0)
11552 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11553 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11556 this_scroll_margin
= 0;
11558 /* Force scroll_conservatively to have a reasonable value so it doesn't
11559 cause an overflow while computing how much to scroll. */
11560 if (scroll_conservatively
)
11561 scroll_conservatively
= min (scroll_conservatively
,
11562 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
11564 /* Compute how much we should try to scroll maximally to bring point
11566 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11567 scroll_max
= max (scroll_step
,
11568 max (scroll_conservatively
, temp_scroll_step
));
11569 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11570 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11571 /* We're trying to scroll because of aggressive scrolling
11572 but no scroll_step is set. Choose an arbitrary one. Maybe
11573 there should be a variable for this. */
11577 scroll_max
*= FRAME_LINE_HEIGHT (f
);
11579 /* Decide whether we have to scroll down. Start at the window end
11580 and move this_scroll_margin up to find the position of the scroll
11582 window_end
= Fwindow_end (window
, Qt
);
11586 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
11587 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
11589 if (this_scroll_margin
|| extra_scroll_margin_lines
)
11591 start_display (&it
, w
, scroll_margin_pos
);
11592 if (this_scroll_margin
)
11593 move_it_vertically_backward (&it
, this_scroll_margin
);
11594 if (extra_scroll_margin_lines
)
11595 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
11596 scroll_margin_pos
= it
.current
.pos
;
11599 if (PT
>= CHARPOS (scroll_margin_pos
))
11603 /* Point is in the scroll margin at the bottom of the window, or
11604 below. Compute a new window start that makes point visible. */
11606 /* Compute the distance from the scroll margin to PT.
11607 Give up if the distance is greater than scroll_max. */
11608 start_display (&it
, w
, scroll_margin_pos
);
11610 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11611 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11613 /* To make point visible, we have to move the window start
11614 down so that the line the cursor is in is visible, which
11615 means we have to add in the height of the cursor line. */
11616 dy
= line_bottom_y (&it
) - y0
;
11618 if (dy
> scroll_max
)
11619 return SCROLLING_FAILED
;
11621 /* Move the window start down. If scrolling conservatively,
11622 move it just enough down to make point visible. If
11623 scroll_step is set, move it down by scroll_step. */
11624 start_display (&it
, w
, startp
);
11626 if (scroll_conservatively
)
11627 /* Set AMOUNT_TO_SCROLL to at least one line,
11628 and at most scroll_conservatively lines. */
11630 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11631 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11632 else if (scroll_step
|| temp_scroll_step
)
11633 amount_to_scroll
= scroll_max
;
11636 aggressive
= current_buffer
->scroll_up_aggressively
;
11637 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11638 if (NUMBERP (aggressive
))
11640 double float_amount
= XFLOATINT (aggressive
) * height
;
11641 amount_to_scroll
= float_amount
;
11642 if (amount_to_scroll
== 0 && float_amount
> 0)
11643 amount_to_scroll
= 1;
11647 if (amount_to_scroll
<= 0)
11648 return SCROLLING_FAILED
;
11650 /* If moving by amount_to_scroll leaves STARTP unchanged,
11651 move it down one screen line. */
11653 move_it_vertically (&it
, amount_to_scroll
);
11654 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
11655 move_it_by_lines (&it
, 1, 1);
11656 startp
= it
.current
.pos
;
11660 /* See if point is inside the scroll margin at the top of the
11662 scroll_margin_pos
= startp
;
11663 if (this_scroll_margin
)
11665 start_display (&it
, w
, startp
);
11666 move_it_vertically (&it
, this_scroll_margin
);
11667 scroll_margin_pos
= it
.current
.pos
;
11670 if (PT
< CHARPOS (scroll_margin_pos
))
11672 /* Point is in the scroll margin at the top of the window or
11673 above what is displayed in the window. */
11676 /* Compute the vertical distance from PT to the scroll
11677 margin position. Give up if distance is greater than
11679 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
11680 start_display (&it
, w
, pos
);
11682 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11683 it
.last_visible_y
, -1,
11684 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11685 dy
= it
.current_y
- y0
;
11686 if (dy
> scroll_max
)
11687 return SCROLLING_FAILED
;
11689 /* Compute new window start. */
11690 start_display (&it
, w
, startp
);
11692 if (scroll_conservatively
)
11694 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11695 else if (scroll_step
|| temp_scroll_step
)
11696 amount_to_scroll
= scroll_max
;
11699 aggressive
= current_buffer
->scroll_down_aggressively
;
11700 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11701 if (NUMBERP (aggressive
))
11703 double float_amount
= XFLOATINT (aggressive
) * height
;
11704 amount_to_scroll
= float_amount
;
11705 if (amount_to_scroll
== 0 && float_amount
> 0)
11706 amount_to_scroll
= 1;
11710 if (amount_to_scroll
<= 0)
11711 return SCROLLING_FAILED
;
11713 move_it_vertically_backward (&it
, amount_to_scroll
);
11714 startp
= it
.current
.pos
;
11718 /* Run window scroll functions. */
11719 startp
= run_window_scroll_functions (window
, startp
);
11721 /* Display the window. Give up if new fonts are loaded, or if point
11723 if (!try_window (window
, startp
, 0))
11724 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11725 else if (w
->cursor
.vpos
< 0)
11727 clear_glyph_matrix (w
->desired_matrix
);
11728 rc
= SCROLLING_FAILED
;
11732 /* Maybe forget recorded base line for line number display. */
11733 if (!just_this_one_p
11734 || current_buffer
->clip_changed
11735 || BEG_UNCHANGED
< CHARPOS (startp
))
11736 w
->base_line_number
= Qnil
;
11738 /* If cursor ends up on a partially visible line,
11739 treat that as being off the bottom of the screen. */
11740 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
11742 clear_glyph_matrix (w
->desired_matrix
);
11743 ++extra_scroll_margin_lines
;
11746 rc
= SCROLLING_SUCCESS
;
11753 /* Compute a suitable window start for window W if display of W starts
11754 on a continuation line. Value is non-zero if a new window start
11757 The new window start will be computed, based on W's width, starting
11758 from the start of the continued line. It is the start of the
11759 screen line with the minimum distance from the old start W->start. */
11762 compute_window_start_on_continuation_line (w
)
11765 struct text_pos pos
, start_pos
;
11766 int window_start_changed_p
= 0;
11768 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
11770 /* If window start is on a continuation line... Window start may be
11771 < BEGV in case there's invisible text at the start of the
11772 buffer (M-x rmail, for example). */
11773 if (CHARPOS (start_pos
) > BEGV
11774 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
11777 struct glyph_row
*row
;
11779 /* Handle the case that the window start is out of range. */
11780 if (CHARPOS (start_pos
) < BEGV
)
11781 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
11782 else if (CHARPOS (start_pos
) > ZV
)
11783 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
11785 /* Find the start of the continued line. This should be fast
11786 because scan_buffer is fast (newline cache). */
11787 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
11788 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
11789 row
, DEFAULT_FACE_ID
);
11790 reseat_at_previous_visible_line_start (&it
);
11792 /* If the line start is "too far" away from the window start,
11793 say it takes too much time to compute a new window start. */
11794 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
11795 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
11797 int min_distance
, distance
;
11799 /* Move forward by display lines to find the new window
11800 start. If window width was enlarged, the new start can
11801 be expected to be > the old start. If window width was
11802 decreased, the new window start will be < the old start.
11803 So, we're looking for the display line start with the
11804 minimum distance from the old window start. */
11805 pos
= it
.current
.pos
;
11806 min_distance
= INFINITY
;
11807 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
11808 distance
< min_distance
)
11810 min_distance
= distance
;
11811 pos
= it
.current
.pos
;
11812 move_it_by_lines (&it
, 1, 0);
11815 /* Set the window start there. */
11816 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
11817 window_start_changed_p
= 1;
11821 return window_start_changed_p
;
11825 /* Try cursor movement in case text has not changed in window WINDOW,
11826 with window start STARTP. Value is
11828 CURSOR_MOVEMENT_SUCCESS if successful
11830 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
11832 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
11833 display. *SCROLL_STEP is set to 1, under certain circumstances, if
11834 we want to scroll as if scroll-step were set to 1. See the code.
11836 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
11837 which case we have to abort this redisplay, and adjust matrices
11842 CURSOR_MOVEMENT_SUCCESS
,
11843 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11844 CURSOR_MOVEMENT_MUST_SCROLL
,
11845 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11849 try_cursor_movement (window
, startp
, scroll_step
)
11850 Lisp_Object window
;
11851 struct text_pos startp
;
11854 struct window
*w
= XWINDOW (window
);
11855 struct frame
*f
= XFRAME (w
->frame
);
11856 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11859 if (inhibit_try_cursor_movement
)
11863 /* Handle case where text has not changed, only point, and it has
11864 not moved off the frame. */
11865 if (/* Point may be in this window. */
11866 PT
>= CHARPOS (startp
)
11867 /* Selective display hasn't changed. */
11868 && !current_buffer
->clip_changed
11869 /* Function force-mode-line-update is used to force a thorough
11870 redisplay. It sets either windows_or_buffers_changed or
11871 update_mode_lines. So don't take a shortcut here for these
11873 && !update_mode_lines
11874 && !windows_or_buffers_changed
11875 && !cursor_type_changed
11876 /* Can't use this case if highlighting a region. When a
11877 region exists, cursor movement has to do more than just
11879 && !(!NILP (Vtransient_mark_mode
)
11880 && !NILP (current_buffer
->mark_active
))
11881 && NILP (w
->region_showing
)
11882 && NILP (Vshow_trailing_whitespace
)
11883 /* Right after splitting windows, last_point may be nil. */
11884 && INTEGERP (w
->last_point
)
11885 /* This code is not used for mini-buffer for the sake of the case
11886 of redisplaying to replace an echo area message; since in
11887 that case the mini-buffer contents per se are usually
11888 unchanged. This code is of no real use in the mini-buffer
11889 since the handling of this_line_start_pos, etc., in redisplay
11890 handles the same cases. */
11891 && !EQ (window
, minibuf_window
)
11892 /* When splitting windows or for new windows, it happens that
11893 redisplay is called with a nil window_end_vpos or one being
11894 larger than the window. This should really be fixed in
11895 window.c. I don't have this on my list, now, so we do
11896 approximately the same as the old redisplay code. --gerd. */
11897 && INTEGERP (w
->window_end_vpos
)
11898 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11899 && (FRAME_WINDOW_P (f
)
11900 || !overlay_arrow_in_current_buffer_p ()))
11902 int this_scroll_margin
, top_scroll_margin
;
11903 struct glyph_row
*row
= NULL
;
11906 debug_method_add (w
, "cursor movement");
11909 /* Scroll if point within this distance from the top or bottom
11910 of the window. This is a pixel value. */
11911 this_scroll_margin
= max (0, scroll_margin
);
11912 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11913 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11915 top_scroll_margin
= this_scroll_margin
;
11916 if (WINDOW_WANTS_HEADER_LINE_P (w
))
11917 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
11919 /* Start with the row the cursor was displayed during the last
11920 not paused redisplay. Give up if that row is not valid. */
11921 if (w
->last_cursor
.vpos
< 0
11922 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11923 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11926 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11927 if (row
->mode_line_p
)
11929 if (!row
->enabled_p
)
11930 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11933 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11936 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11938 if (PT
> XFASTINT (w
->last_point
))
11940 /* Point has moved forward. */
11941 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11942 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11944 xassert (row
->enabled_p
);
11948 /* The end position of a row equals the start position
11949 of the next row. If PT is there, we would rather
11950 display it in the next line. */
11951 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11952 && MATRIX_ROW_END_CHARPOS (row
) == PT
11953 && !cursor_row_p (w
, row
))
11956 /* If within the scroll margin, scroll. Note that
11957 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11958 the next line would be drawn, and that
11959 this_scroll_margin can be zero. */
11960 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11961 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11962 /* Line is completely visible last line in window
11963 and PT is to be set in the next line. */
11964 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11965 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11966 && !row
->ends_at_zv_p
11967 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11970 else if (PT
< XFASTINT (w
->last_point
))
11972 /* Cursor has to be moved backward. Note that PT >=
11973 CHARPOS (startp) because of the outer if-statement. */
11974 while (!row
->mode_line_p
11975 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11976 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11977 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
11978 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
11979 row
> w
->current_matrix
->rows
11980 && (row
-1)->ends_in_newline_from_string_p
))))
11981 && (row
->y
> top_scroll_margin
11982 || CHARPOS (startp
) == BEGV
))
11984 xassert (row
->enabled_p
);
11988 /* Consider the following case: Window starts at BEGV,
11989 there is invisible, intangible text at BEGV, so that
11990 display starts at some point START > BEGV. It can
11991 happen that we are called with PT somewhere between
11992 BEGV and START. Try to handle that case. */
11993 if (row
< w
->current_matrix
->rows
11994 || row
->mode_line_p
)
11996 row
= w
->current_matrix
->rows
;
11997 if (row
->mode_line_p
)
12001 /* Due to newlines in overlay strings, we may have to
12002 skip forward over overlay strings. */
12003 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12004 && MATRIX_ROW_END_CHARPOS (row
) == PT
12005 && !cursor_row_p (w
, row
))
12008 /* If within the scroll margin, scroll. */
12009 if (row
->y
< top_scroll_margin
12010 && CHARPOS (startp
) != BEGV
)
12015 /* Cursor did not move. So don't scroll even if cursor line
12016 is partially visible, as it was so before. */
12017 rc
= CURSOR_MOVEMENT_SUCCESS
;
12020 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
12021 || PT
> MATRIX_ROW_END_CHARPOS (row
))
12023 /* if PT is not in the glyph row, give up. */
12024 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12026 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
12027 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
12028 && make_cursor_line_fully_visible_p
)
12030 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
12031 && !row
->ends_at_zv_p
12032 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12033 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12034 else if (row
->height
> window_box_height (w
))
12036 /* If we end up in a partially visible line, let's
12037 make it fully visible, except when it's taller
12038 than the window, in which case we can't do much
12041 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12045 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12046 if (!cursor_row_fully_visible_p (w
, 0, 1))
12047 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12049 rc
= CURSOR_MOVEMENT_SUCCESS
;
12053 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12056 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12057 rc
= CURSOR_MOVEMENT_SUCCESS
;
12066 set_vertical_scroll_bar (w
)
12069 int start
, end
, whole
;
12071 /* Calculate the start and end positions for the current window.
12072 At some point, it would be nice to choose between scrollbars
12073 which reflect the whole buffer size, with special markers
12074 indicating narrowing, and scrollbars which reflect only the
12077 Note that mini-buffers sometimes aren't displaying any text. */
12078 if (!MINI_WINDOW_P (w
)
12079 || (w
== XWINDOW (minibuf_window
)
12080 && NILP (echo_area_buffer
[0])))
12082 struct buffer
*buf
= XBUFFER (w
->buffer
);
12083 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12084 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12085 /* I don't think this is guaranteed to be right. For the
12086 moment, we'll pretend it is. */
12087 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12091 if (whole
< (end
- start
))
12092 whole
= end
- start
;
12095 start
= end
= whole
= 0;
12097 /* Indicate what this scroll bar ought to be displaying now. */
12098 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
12102 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12103 selected_window is redisplayed.
12105 We can return without actually redisplaying the window if
12106 fonts_changed_p is nonzero. In that case, redisplay_internal will
12110 redisplay_window (window
, just_this_one_p
)
12111 Lisp_Object window
;
12112 int just_this_one_p
;
12114 struct window
*w
= XWINDOW (window
);
12115 struct frame
*f
= XFRAME (w
->frame
);
12116 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12117 struct buffer
*old
= current_buffer
;
12118 struct text_pos lpoint
, opoint
, startp
;
12119 int update_mode_line
;
12122 /* Record it now because it's overwritten. */
12123 int current_matrix_up_to_date_p
= 0;
12124 int used_current_matrix_p
= 0;
12125 /* This is less strict than current_matrix_up_to_date_p.
12126 It indictes that the buffer contents and narrowing are unchanged. */
12127 int buffer_unchanged_p
= 0;
12128 int temp_scroll_step
= 0;
12129 int count
= SPECPDL_INDEX ();
12131 int centering_position
= -1;
12132 int last_line_misfit
= 0;
12134 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12137 /* W must be a leaf window here. */
12138 xassert (!NILP (w
->buffer
));
12140 *w
->desired_matrix
->method
= 0;
12143 specbind (Qinhibit_point_motion_hooks
, Qt
);
12145 reconsider_clip_changes (w
, buffer
);
12147 /* Has the mode line to be updated? */
12148 update_mode_line
= (!NILP (w
->update_mode_line
)
12149 || update_mode_lines
12150 || buffer
->clip_changed
12151 || buffer
->prevent_redisplay_optimizations_p
);
12153 if (MINI_WINDOW_P (w
))
12155 if (w
== XWINDOW (echo_area_window
)
12156 && !NILP (echo_area_buffer
[0]))
12158 if (update_mode_line
)
12159 /* We may have to update a tty frame's menu bar or a
12160 tool-bar. Example `M-x C-h C-h C-g'. */
12161 goto finish_menu_bars
;
12163 /* We've already displayed the echo area glyphs in this window. */
12164 goto finish_scroll_bars
;
12166 else if ((w
!= XWINDOW (minibuf_window
)
12167 || minibuf_level
== 0)
12168 /* When buffer is nonempty, redisplay window normally. */
12169 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12170 /* Quail displays non-mini buffers in minibuffer window.
12171 In that case, redisplay the window normally. */
12172 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12174 /* W is a mini-buffer window, but it's not active, so clear
12176 int yb
= window_text_bottom_y (w
);
12177 struct glyph_row
*row
;
12180 for (y
= 0, row
= w
->desired_matrix
->rows
;
12182 y
+= row
->height
, ++row
)
12183 blank_row (w
, row
, y
);
12184 goto finish_scroll_bars
;
12187 clear_glyph_matrix (w
->desired_matrix
);
12190 /* Otherwise set up data on this window; select its buffer and point
12192 /* Really select the buffer, for the sake of buffer-local
12194 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12195 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12197 current_matrix_up_to_date_p
12198 = (!NILP (w
->window_end_valid
)
12199 && !current_buffer
->clip_changed
12200 && !current_buffer
->prevent_redisplay_optimizations_p
12201 && XFASTINT (w
->last_modified
) >= MODIFF
12202 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12205 = (!NILP (w
->window_end_valid
)
12206 && !current_buffer
->clip_changed
12207 && XFASTINT (w
->last_modified
) >= MODIFF
12208 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12210 /* When windows_or_buffers_changed is non-zero, we can't rely on
12211 the window end being valid, so set it to nil there. */
12212 if (windows_or_buffers_changed
)
12214 /* If window starts on a continuation line, maybe adjust the
12215 window start in case the window's width changed. */
12216 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12217 compute_window_start_on_continuation_line (w
);
12219 w
->window_end_valid
= Qnil
;
12222 /* Some sanity checks. */
12223 CHECK_WINDOW_END (w
);
12224 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12226 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12229 /* If %c is in mode line, update it if needed. */
12230 if (!NILP (w
->column_number_displayed
)
12231 /* This alternative quickly identifies a common case
12232 where no change is needed. */
12233 && !(PT
== XFASTINT (w
->last_point
)
12234 && XFASTINT (w
->last_modified
) >= MODIFF
12235 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12236 && (XFASTINT (w
->column_number_displayed
)
12237 != (int) current_column ())) /* iftc */
12238 update_mode_line
= 1;
12240 /* Count number of windows showing the selected buffer. An indirect
12241 buffer counts as its base buffer. */
12242 if (!just_this_one_p
)
12244 struct buffer
*current_base
, *window_base
;
12245 current_base
= current_buffer
;
12246 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12247 if (current_base
->base_buffer
)
12248 current_base
= current_base
->base_buffer
;
12249 if (window_base
->base_buffer
)
12250 window_base
= window_base
->base_buffer
;
12251 if (current_base
== window_base
)
12255 /* Point refers normally to the selected window. For any other
12256 window, set up appropriate value. */
12257 if (!EQ (window
, selected_window
))
12259 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12260 int new_pt_byte
= marker_byte_position (w
->pointm
);
12264 new_pt_byte
= BEGV_BYTE
;
12265 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
12267 else if (new_pt
> (ZV
- 1))
12270 new_pt_byte
= ZV_BYTE
;
12271 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
12274 /* We don't use SET_PT so that the point-motion hooks don't run. */
12275 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
12278 /* If any of the character widths specified in the display table
12279 have changed, invalidate the width run cache. It's true that
12280 this may be a bit late to catch such changes, but the rest of
12281 redisplay goes (non-fatally) haywire when the display table is
12282 changed, so why should we worry about doing any better? */
12283 if (current_buffer
->width_run_cache
)
12285 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
12287 if (! disptab_matches_widthtab (disptab
,
12288 XVECTOR (current_buffer
->width_table
)))
12290 invalidate_region_cache (current_buffer
,
12291 current_buffer
->width_run_cache
,
12293 recompute_width_table (current_buffer
, disptab
);
12297 /* If window-start is screwed up, choose a new one. */
12298 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12301 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12303 /* If someone specified a new starting point but did not insist,
12304 check whether it can be used. */
12305 if (!NILP (w
->optional_new_start
)
12306 && CHARPOS (startp
) >= BEGV
12307 && CHARPOS (startp
) <= ZV
)
12309 w
->optional_new_start
= Qnil
;
12310 start_display (&it
, w
, startp
);
12311 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12312 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12313 if (IT_CHARPOS (it
) == PT
)
12314 w
->force_start
= Qt
;
12315 /* IT may overshoot PT if text at PT is invisible. */
12316 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12317 w
->force_start
= Qt
;
12322 /* Handle case where place to start displaying has been specified,
12323 unless the specified location is outside the accessible range. */
12324 if (!NILP (w
->force_start
)
12325 || w
->frozen_window_start_p
)
12327 /* We set this later on if we have to adjust point. */
12331 w
->force_start
= Qnil
;
12333 w
->window_end_valid
= Qnil
;
12335 /* Forget any recorded base line for line number display. */
12336 if (!buffer_unchanged_p
)
12337 w
->base_line_number
= Qnil
;
12339 /* Redisplay the mode line. Select the buffer properly for that.
12340 Also, run the hook window-scroll-functions
12341 because we have scrolled. */
12342 /* Note, we do this after clearing force_start because
12343 if there's an error, it is better to forget about force_start
12344 than to get into an infinite loop calling the hook functions
12345 and having them get more errors. */
12346 if (!update_mode_line
12347 || ! NILP (Vwindow_scroll_functions
))
12349 update_mode_line
= 1;
12350 w
->update_mode_line
= Qt
;
12351 startp
= run_window_scroll_functions (window
, startp
);
12354 w
->last_modified
= make_number (0);
12355 w
->last_overlay_modified
= make_number (0);
12356 if (CHARPOS (startp
) < BEGV
)
12357 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
12358 else if (CHARPOS (startp
) > ZV
)
12359 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12361 /* Redisplay, then check if cursor has been set during the
12362 redisplay. Give up if new fonts were loaded. */
12363 val
= try_window (window
, startp
, 1);
12366 w
->force_start
= Qt
;
12367 clear_glyph_matrix (w
->desired_matrix
);
12368 goto need_larger_matrices
;
12370 /* Point was outside the scroll margins. */
12372 new_vpos
= window_box_height (w
) / 2;
12374 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12376 /* If point does not appear, try to move point so it does
12377 appear. The desired matrix has been built above, so we
12378 can use it here. */
12379 new_vpos
= window_box_height (w
) / 2;
12382 if (!cursor_row_fully_visible_p (w
, 0, 0))
12384 /* Point does appear, but on a line partly visible at end of window.
12385 Move it back to a fully-visible line. */
12386 new_vpos
= window_box_height (w
);
12389 /* If we need to move point for either of the above reasons,
12390 now actually do it. */
12393 struct glyph_row
*row
;
12395 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
12396 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
12399 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
12400 MATRIX_ROW_START_BYTEPOS (row
));
12402 if (w
!= XWINDOW (selected_window
))
12403 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
12404 else if (current_buffer
== old
)
12405 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12407 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
12409 /* If we are highlighting the region, then we just changed
12410 the region, so redisplay to show it. */
12411 if (!NILP (Vtransient_mark_mode
)
12412 && !NILP (current_buffer
->mark_active
))
12414 clear_glyph_matrix (w
->desired_matrix
);
12415 if (!try_window (window
, startp
, 0))
12416 goto need_larger_matrices
;
12421 debug_method_add (w
, "forced window start");
12426 /* Handle case where text has not changed, only point, and it has
12427 not moved off the frame, and we are not retrying after hscroll.
12428 (current_matrix_up_to_date_p is nonzero when retrying.) */
12429 if (current_matrix_up_to_date_p
12430 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
12431 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
12435 case CURSOR_MOVEMENT_SUCCESS
:
12436 used_current_matrix_p
= 1;
12439 #if 0 /* try_cursor_movement never returns this value. */
12440 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
12441 goto need_larger_matrices
;
12444 case CURSOR_MOVEMENT_MUST_SCROLL
:
12445 goto try_to_scroll
;
12451 /* If current starting point was originally the beginning of a line
12452 but no longer is, find a new starting point. */
12453 else if (!NILP (w
->start_at_line_beg
)
12454 && !(CHARPOS (startp
) <= BEGV
12455 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
12458 debug_method_add (w
, "recenter 1");
12463 /* Try scrolling with try_window_id. Value is > 0 if update has
12464 been done, it is -1 if we know that the same window start will
12465 not work. It is 0 if unsuccessful for some other reason. */
12466 else if ((tem
= try_window_id (w
)) != 0)
12469 debug_method_add (w
, "try_window_id %d", tem
);
12472 if (fonts_changed_p
)
12473 goto need_larger_matrices
;
12477 /* Otherwise try_window_id has returned -1 which means that we
12478 don't want the alternative below this comment to execute. */
12480 else if (CHARPOS (startp
) >= BEGV
12481 && CHARPOS (startp
) <= ZV
12482 && PT
>= CHARPOS (startp
)
12483 && (CHARPOS (startp
) < ZV
12484 /* Avoid starting at end of buffer. */
12485 || CHARPOS (startp
) == BEGV
12486 || (XFASTINT (w
->last_modified
) >= MODIFF
12487 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
12490 debug_method_add (w
, "same window start");
12493 /* Try to redisplay starting at same place as before.
12494 If point has not moved off frame, accept the results. */
12495 if (!current_matrix_up_to_date_p
12496 /* Don't use try_window_reusing_current_matrix in this case
12497 because a window scroll function can have changed the
12499 || !NILP (Vwindow_scroll_functions
)
12500 || MINI_WINDOW_P (w
)
12501 || !(used_current_matrix_p
12502 = try_window_reusing_current_matrix (w
)))
12504 IF_DEBUG (debug_method_add (w
, "1"));
12505 if (try_window (window
, startp
, 1) < 0)
12506 /* -1 means we need to scroll.
12507 0 means we need new matrices, but fonts_changed_p
12508 is set in that case, so we will detect it below. */
12509 goto try_to_scroll
;
12512 if (fonts_changed_p
)
12513 goto need_larger_matrices
;
12515 if (w
->cursor
.vpos
>= 0)
12517 if (!just_this_one_p
12518 || current_buffer
->clip_changed
12519 || BEG_UNCHANGED
< CHARPOS (startp
))
12520 /* Forget any recorded base line for line number display. */
12521 w
->base_line_number
= Qnil
;
12523 if (!cursor_row_fully_visible_p (w
, 1, 0))
12525 clear_glyph_matrix (w
->desired_matrix
);
12526 last_line_misfit
= 1;
12528 /* Drop through and scroll. */
12533 clear_glyph_matrix (w
->desired_matrix
);
12538 w
->last_modified
= make_number (0);
12539 w
->last_overlay_modified
= make_number (0);
12541 /* Redisplay the mode line. Select the buffer properly for that. */
12542 if (!update_mode_line
)
12544 update_mode_line
= 1;
12545 w
->update_mode_line
= Qt
;
12548 /* Try to scroll by specified few lines. */
12549 if ((scroll_conservatively
12551 || temp_scroll_step
12552 || NUMBERP (current_buffer
->scroll_up_aggressively
)
12553 || NUMBERP (current_buffer
->scroll_down_aggressively
))
12554 && !current_buffer
->clip_changed
12555 && CHARPOS (startp
) >= BEGV
12556 && CHARPOS (startp
) <= ZV
)
12558 /* The function returns -1 if new fonts were loaded, 1 if
12559 successful, 0 if not successful. */
12560 int rc
= try_scrolling (window
, just_this_one_p
,
12561 scroll_conservatively
,
12563 temp_scroll_step
, last_line_misfit
);
12566 case SCROLLING_SUCCESS
:
12569 case SCROLLING_NEED_LARGER_MATRICES
:
12570 goto need_larger_matrices
;
12572 case SCROLLING_FAILED
:
12580 /* Finally, just choose place to start which centers point */
12583 if (centering_position
< 0)
12584 centering_position
= window_box_height (w
) / 2;
12587 debug_method_add (w
, "recenter");
12590 /* w->vscroll = 0; */
12592 /* Forget any previously recorded base line for line number display. */
12593 if (!buffer_unchanged_p
)
12594 w
->base_line_number
= Qnil
;
12596 /* Move backward half the height of the window. */
12597 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12598 it
.current_y
= it
.last_visible_y
;
12599 move_it_vertically_backward (&it
, centering_position
);
12600 xassert (IT_CHARPOS (it
) >= BEGV
);
12602 /* The function move_it_vertically_backward may move over more
12603 than the specified y-distance. If it->w is small, e.g. a
12604 mini-buffer window, we may end up in front of the window's
12605 display area. Start displaying at the start of the line
12606 containing PT in this case. */
12607 if (it
.current_y
<= 0)
12609 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12610 move_it_vertically_backward (&it
, 0);
12612 /* I think this assert is bogus if buffer contains
12613 invisible text or images. KFS. */
12614 xassert (IT_CHARPOS (it
) <= PT
);
12619 it
.current_x
= it
.hpos
= 0;
12621 /* Set startp here explicitly in case that helps avoid an infinite loop
12622 in case the window-scroll-functions functions get errors. */
12623 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
12625 /* Run scroll hooks. */
12626 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
12628 /* Redisplay the window. */
12629 if (!current_matrix_up_to_date_p
12630 || windows_or_buffers_changed
12631 || cursor_type_changed
12632 /* Don't use try_window_reusing_current_matrix in this case
12633 because it can have changed the buffer. */
12634 || !NILP (Vwindow_scroll_functions
)
12635 || !just_this_one_p
12636 || MINI_WINDOW_P (w
)
12637 || !(used_current_matrix_p
12638 = try_window_reusing_current_matrix (w
)))
12639 try_window (window
, startp
, 0);
12641 /* If new fonts have been loaded (due to fontsets), give up. We
12642 have to start a new redisplay since we need to re-adjust glyph
12644 if (fonts_changed_p
)
12645 goto need_larger_matrices
;
12647 /* If cursor did not appear assume that the middle of the window is
12648 in the first line of the window. Do it again with the next line.
12649 (Imagine a window of height 100, displaying two lines of height
12650 60. Moving back 50 from it->last_visible_y will end in the first
12652 if (w
->cursor
.vpos
< 0)
12654 if (!NILP (w
->window_end_valid
)
12655 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
12657 clear_glyph_matrix (w
->desired_matrix
);
12658 move_it_by_lines (&it
, 1, 0);
12659 try_window (window
, it
.current
.pos
, 0);
12661 else if (PT
< IT_CHARPOS (it
))
12663 clear_glyph_matrix (w
->desired_matrix
);
12664 move_it_by_lines (&it
, -1, 0);
12665 try_window (window
, it
.current
.pos
, 0);
12669 /* Not much we can do about it. */
12673 /* Consider the following case: Window starts at BEGV, there is
12674 invisible, intangible text at BEGV, so that display starts at
12675 some point START > BEGV. It can happen that we are called with
12676 PT somewhere between BEGV and START. Try to handle that case. */
12677 if (w
->cursor
.vpos
< 0)
12679 struct glyph_row
*row
= w
->current_matrix
->rows
;
12680 if (row
->mode_line_p
)
12682 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12685 if (!cursor_row_fully_visible_p (w
, 0, 0))
12687 /* If vscroll is enabled, disable it and try again. */
12691 clear_glyph_matrix (w
->desired_matrix
);
12695 /* If centering point failed to make the whole line visible,
12696 put point at the top instead. That has to make the whole line
12697 visible, if it can be done. */
12698 if (centering_position
== 0)
12701 clear_glyph_matrix (w
->desired_matrix
);
12702 centering_position
= 0;
12708 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12709 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
12710 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
12713 /* Display the mode line, if we must. */
12714 if ((update_mode_line
12715 /* If window not full width, must redo its mode line
12716 if (a) the window to its side is being redone and
12717 (b) we do a frame-based redisplay. This is a consequence
12718 of how inverted lines are drawn in frame-based redisplay. */
12719 || (!just_this_one_p
12720 && !FRAME_WINDOW_P (f
)
12721 && !WINDOW_FULL_WIDTH_P (w
))
12722 /* Line number to display. */
12723 || INTEGERP (w
->base_line_pos
)
12724 /* Column number is displayed and different from the one displayed. */
12725 || (!NILP (w
->column_number_displayed
)
12726 && (XFASTINT (w
->column_number_displayed
)
12727 != (int) current_column ()))) /* iftc */
12728 /* This means that the window has a mode line. */
12729 && (WINDOW_WANTS_MODELINE_P (w
)
12730 || WINDOW_WANTS_HEADER_LINE_P (w
)))
12732 display_mode_lines (w
);
12734 /* If mode line height has changed, arrange for a thorough
12735 immediate redisplay using the correct mode line height. */
12736 if (WINDOW_WANTS_MODELINE_P (w
)
12737 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12739 fonts_changed_p
= 1;
12740 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12741 = DESIRED_MODE_LINE_HEIGHT (w
);
12744 /* If top line height has changed, arrange for a thorough
12745 immediate redisplay using the correct mode line height. */
12746 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12747 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
12749 fonts_changed_p
= 1;
12750 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
12751 = DESIRED_HEADER_LINE_HEIGHT (w
);
12754 if (fonts_changed_p
)
12755 goto need_larger_matrices
;
12758 if (!line_number_displayed
12759 && !BUFFERP (w
->base_line_pos
))
12761 w
->base_line_pos
= Qnil
;
12762 w
->base_line_number
= Qnil
;
12767 /* When we reach a frame's selected window, redo the frame's menu bar. */
12768 if (update_mode_line
12769 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
12771 int redisplay_menu_p
= 0;
12772 int redisplay_tool_bar_p
= 0;
12774 if (FRAME_WINDOW_P (f
))
12776 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
12777 || defined (USE_GTK)
12778 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
12780 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12784 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12786 if (redisplay_menu_p
)
12787 display_menu_bar (w
);
12789 #ifdef HAVE_WINDOW_SYSTEM
12791 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
12793 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
12794 && (FRAME_TOOL_BAR_LINES (f
) > 0
12795 || auto_resize_tool_bars_p
);
12799 if (redisplay_tool_bar_p
)
12800 redisplay_tool_bar (f
);
12804 #ifdef HAVE_WINDOW_SYSTEM
12805 if (FRAME_WINDOW_P (f
)
12806 && update_window_fringes (w
, 0)
12807 && !just_this_one_p
12808 && (used_current_matrix_p
|| overlay_arrow_seen
)
12809 && !w
->pseudo_window_p
)
12813 if (draw_window_fringes (w
, 1))
12814 x_draw_vertical_border (w
);
12818 #endif /* HAVE_WINDOW_SYSTEM */
12820 /* We go to this label, with fonts_changed_p nonzero,
12821 if it is necessary to try again using larger glyph matrices.
12822 We have to redeem the scroll bar even in this case,
12823 because the loop in redisplay_internal expects that. */
12824 need_larger_matrices
:
12826 finish_scroll_bars
:
12828 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
12830 /* Set the thumb's position and size. */
12831 set_vertical_scroll_bar (w
);
12833 /* Note that we actually used the scroll bar attached to this
12834 window, so it shouldn't be deleted at the end of redisplay. */
12835 redeem_scroll_bar_hook (w
);
12838 /* Restore current_buffer and value of point in it. */
12839 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
12840 set_buffer_internal_1 (old
);
12841 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12843 unbind_to (count
, Qnil
);
12847 /* Build the complete desired matrix of WINDOW with a window start
12848 buffer position POS.
12850 Value is 1 if successful. It is zero if fonts were loaded during
12851 redisplay which makes re-adjusting glyph matrices necessary, and -1
12852 if point would appear in the scroll margins.
12853 (We check that only if CHECK_MARGINS is nonzero. */
12856 try_window (window
, pos
, check_margins
)
12857 Lisp_Object window
;
12858 struct text_pos pos
;
12861 struct window
*w
= XWINDOW (window
);
12863 struct glyph_row
*last_text_row
= NULL
;
12865 /* Make POS the new window start. */
12866 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
12868 /* Mark cursor position as unknown. No overlay arrow seen. */
12869 w
->cursor
.vpos
= -1;
12870 overlay_arrow_seen
= 0;
12872 /* Initialize iterator and info to start at POS. */
12873 start_display (&it
, w
, pos
);
12875 /* Display all lines of W. */
12876 while (it
.current_y
< it
.last_visible_y
)
12878 if (display_line (&it
))
12879 last_text_row
= it
.glyph_row
- 1;
12880 if (fonts_changed_p
)
12884 /* Don't let the cursor end in the scroll margins. */
12886 && !MINI_WINDOW_P (w
))
12888 int this_scroll_margin
, cursor_height
;
12890 this_scroll_margin
= max (0, scroll_margin
);
12891 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12892 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
12893 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
12895 if ((w
->cursor
.y
< this_scroll_margin
12896 && CHARPOS (pos
) > BEGV
)
12897 /* rms: considering make_cursor_line_fully_visible_p here
12898 seems to give wrong results. We don't want to recenter
12899 when the last line is partly visible, we want to allow
12900 that case to be handled in the usual way. */
12901 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
12903 w
->cursor
.vpos
= -1;
12904 clear_glyph_matrix (w
->desired_matrix
);
12909 /* If bottom moved off end of frame, change mode line percentage. */
12910 if (XFASTINT (w
->window_end_pos
) <= 0
12911 && Z
!= IT_CHARPOS (it
))
12912 w
->update_mode_line
= Qt
;
12914 /* Set window_end_pos to the offset of the last character displayed
12915 on the window from the end of current_buffer. Set
12916 window_end_vpos to its row number. */
12919 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
12920 w
->window_end_bytepos
12921 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12923 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12925 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12926 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12927 ->displays_text_p
);
12931 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12932 w
->window_end_pos
= make_number (Z
- ZV
);
12933 w
->window_end_vpos
= make_number (0);
12936 /* But that is not valid info until redisplay finishes. */
12937 w
->window_end_valid
= Qnil
;
12943 /************************************************************************
12944 Window redisplay reusing current matrix when buffer has not changed
12945 ************************************************************************/
12947 /* Try redisplay of window W showing an unchanged buffer with a
12948 different window start than the last time it was displayed by
12949 reusing its current matrix. Value is non-zero if successful.
12950 W->start is the new window start. */
12953 try_window_reusing_current_matrix (w
)
12956 struct frame
*f
= XFRAME (w
->frame
);
12957 struct glyph_row
*row
, *bottom_row
;
12960 struct text_pos start
, new_start
;
12961 int nrows_scrolled
, i
;
12962 struct glyph_row
*last_text_row
;
12963 struct glyph_row
*last_reused_text_row
;
12964 struct glyph_row
*start_row
;
12965 int start_vpos
, min_y
, max_y
;
12968 if (inhibit_try_window_reusing
)
12972 if (/* This function doesn't handle terminal frames. */
12973 !FRAME_WINDOW_P (f
)
12974 /* Don't try to reuse the display if windows have been split
12976 || windows_or_buffers_changed
12977 || cursor_type_changed
)
12980 /* Can't do this if region may have changed. */
12981 if ((!NILP (Vtransient_mark_mode
)
12982 && !NILP (current_buffer
->mark_active
))
12983 || !NILP (w
->region_showing
)
12984 || !NILP (Vshow_trailing_whitespace
))
12987 /* If top-line visibility has changed, give up. */
12988 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12989 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12992 /* Give up if old or new display is scrolled vertically. We could
12993 make this function handle this, but right now it doesn't. */
12994 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12995 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
12998 /* The variable new_start now holds the new window start. The old
12999 start `start' can be determined from the current matrix. */
13000 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
13001 start
= start_row
->start
.pos
;
13002 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13004 /* Clear the desired matrix for the display below. */
13005 clear_glyph_matrix (w
->desired_matrix
);
13007 if (CHARPOS (new_start
) <= CHARPOS (start
))
13011 /* Don't use this method if the display starts with an ellipsis
13012 displayed for invisible text. It's not easy to handle that case
13013 below, and it's certainly not worth the effort since this is
13014 not a frequent case. */
13015 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
13018 IF_DEBUG (debug_method_add (w
, "twu1"));
13020 /* Display up to a row that can be reused. The variable
13021 last_text_row is set to the last row displayed that displays
13022 text. Note that it.vpos == 0 if or if not there is a
13023 header-line; it's not the same as the MATRIX_ROW_VPOS! */
13024 start_display (&it
, w
, new_start
);
13025 first_row_y
= it
.current_y
;
13026 w
->cursor
.vpos
= -1;
13027 last_text_row
= last_reused_text_row
= NULL
;
13029 while (it
.current_y
< it
.last_visible_y
13030 && !fonts_changed_p
)
13032 /* If we have reached into the characters in the START row,
13033 that means the line boundaries have changed. So we
13034 can't start copying with the row START. Maybe it will
13035 work to start copying with the following row. */
13036 while (IT_CHARPOS (it
) > CHARPOS (start
))
13038 /* Advance to the next row as the "start". */
13040 start
= start_row
->start
.pos
;
13041 /* If there are no more rows to try, or just one, give up. */
13042 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
13043 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
13044 || CHARPOS (start
) == ZV
)
13046 clear_glyph_matrix (w
->desired_matrix
);
13050 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13052 /* If we have reached alignment,
13053 we can copy the rest of the rows. */
13054 if (IT_CHARPOS (it
) == CHARPOS (start
))
13057 if (display_line (&it
))
13058 last_text_row
= it
.glyph_row
- 1;
13061 /* A value of current_y < last_visible_y means that we stopped
13062 at the previous window start, which in turn means that we
13063 have at least one reusable row. */
13064 if (it
.current_y
< it
.last_visible_y
)
13066 /* IT.vpos always starts from 0; it counts text lines. */
13067 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13069 /* Find PT if not already found in the lines displayed. */
13070 if (w
->cursor
.vpos
< 0)
13072 int dy
= it
.current_y
- start_row
->y
;
13074 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13075 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13077 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13078 dy
, nrows_scrolled
);
13081 clear_glyph_matrix (w
->desired_matrix
);
13086 /* Scroll the display. Do it before the current matrix is
13087 changed. The problem here is that update has not yet
13088 run, i.e. part of the current matrix is not up to date.
13089 scroll_run_hook will clear the cursor, and use the
13090 current matrix to get the height of the row the cursor is
13092 run
.current_y
= start_row
->y
;
13093 run
.desired_y
= it
.current_y
;
13094 run
.height
= it
.last_visible_y
- it
.current_y
;
13096 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13099 rif
->update_window_begin_hook (w
);
13100 rif
->clear_window_mouse_face (w
);
13101 rif
->scroll_run_hook (w
, &run
);
13102 rif
->update_window_end_hook (w
, 0, 0);
13106 /* Shift current matrix down by nrows_scrolled lines. */
13107 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13108 rotate_matrix (w
->current_matrix
,
13110 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13113 /* Disable lines that must be updated. */
13114 for (i
= 0; i
< it
.vpos
; ++i
)
13115 (start_row
+ i
)->enabled_p
= 0;
13117 /* Re-compute Y positions. */
13118 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13119 max_y
= it
.last_visible_y
;
13120 for (row
= start_row
+ nrows_scrolled
;
13124 row
->y
= it
.current_y
;
13125 row
->visible_height
= row
->height
;
13127 if (row
->y
< min_y
)
13128 row
->visible_height
-= min_y
- row
->y
;
13129 if (row
->y
+ row
->height
> max_y
)
13130 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13131 row
->redraw_fringe_bitmaps_p
= 1;
13133 it
.current_y
+= row
->height
;
13135 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13136 last_reused_text_row
= row
;
13137 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13141 /* Disable lines in the current matrix which are now
13142 below the window. */
13143 for (++row
; row
< bottom_row
; ++row
)
13144 row
->enabled_p
= 0;
13147 /* Update window_end_pos etc.; last_reused_text_row is the last
13148 reused row from the current matrix containing text, if any.
13149 The value of last_text_row is the last displayed line
13150 containing text. */
13151 if (last_reused_text_row
)
13153 w
->window_end_bytepos
13154 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13156 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13158 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13159 w
->current_matrix
));
13161 else if (last_text_row
)
13163 w
->window_end_bytepos
13164 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13166 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13168 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13172 /* This window must be completely empty. */
13173 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13174 w
->window_end_pos
= make_number (Z
- ZV
);
13175 w
->window_end_vpos
= make_number (0);
13177 w
->window_end_valid
= Qnil
;
13179 /* Update hint: don't try scrolling again in update_window. */
13180 w
->desired_matrix
->no_scrolling_p
= 1;
13183 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13187 else if (CHARPOS (new_start
) > CHARPOS (start
))
13189 struct glyph_row
*pt_row
, *row
;
13190 struct glyph_row
*first_reusable_row
;
13191 struct glyph_row
*first_row_to_display
;
13193 int yb
= window_text_bottom_y (w
);
13195 /* Find the row starting at new_start, if there is one. Don't
13196 reuse a partially visible line at the end. */
13197 first_reusable_row
= start_row
;
13198 while (first_reusable_row
->enabled_p
13199 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13200 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13201 < CHARPOS (new_start
)))
13202 ++first_reusable_row
;
13204 /* Give up if there is no row to reuse. */
13205 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13206 || !first_reusable_row
->enabled_p
13207 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13208 != CHARPOS (new_start
)))
13211 /* We can reuse fully visible rows beginning with
13212 first_reusable_row to the end of the window. Set
13213 first_row_to_display to the first row that cannot be reused.
13214 Set pt_row to the row containing point, if there is any. */
13216 for (first_row_to_display
= first_reusable_row
;
13217 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13218 ++first_row_to_display
)
13220 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13221 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13222 pt_row
= first_row_to_display
;
13225 /* Start displaying at the start of first_row_to_display. */
13226 xassert (first_row_to_display
->y
< yb
);
13227 init_to_row_start (&it
, w
, first_row_to_display
);
13229 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
13231 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
13233 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
13234 + WINDOW_HEADER_LINE_HEIGHT (w
));
13236 /* Display lines beginning with first_row_to_display in the
13237 desired matrix. Set last_text_row to the last row displayed
13238 that displays text. */
13239 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
13240 if (pt_row
== NULL
)
13241 w
->cursor
.vpos
= -1;
13242 last_text_row
= NULL
;
13243 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
13244 if (display_line (&it
))
13245 last_text_row
= it
.glyph_row
- 1;
13247 /* Give up If point isn't in a row displayed or reused. */
13248 if (w
->cursor
.vpos
< 0)
13250 clear_glyph_matrix (w
->desired_matrix
);
13254 /* If point is in a reused row, adjust y and vpos of the cursor
13258 w
->cursor
.vpos
-= nrows_scrolled
;
13259 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
13262 /* Scroll the display. */
13263 run
.current_y
= first_reusable_row
->y
;
13264 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13265 run
.height
= it
.last_visible_y
- run
.current_y
;
13266 dy
= run
.current_y
- run
.desired_y
;
13271 rif
->update_window_begin_hook (w
);
13272 rif
->clear_window_mouse_face (w
);
13273 rif
->scroll_run_hook (w
, &run
);
13274 rif
->update_window_end_hook (w
, 0, 0);
13278 /* Adjust Y positions of reused rows. */
13279 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13280 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13281 max_y
= it
.last_visible_y
;
13282 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
13285 row
->visible_height
= row
->height
;
13286 if (row
->y
< min_y
)
13287 row
->visible_height
-= min_y
- row
->y
;
13288 if (row
->y
+ row
->height
> max_y
)
13289 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13290 row
->redraw_fringe_bitmaps_p
= 1;
13293 /* Scroll the current matrix. */
13294 xassert (nrows_scrolled
> 0);
13295 rotate_matrix (w
->current_matrix
,
13297 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13300 /* Disable rows not reused. */
13301 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
13302 row
->enabled_p
= 0;
13304 /* Point may have moved to a different line, so we cannot assume that
13305 the previous cursor position is valid; locate the correct row. */
13308 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
13309 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
13313 w
->cursor
.y
= row
->y
;
13315 if (row
< bottom_row
)
13317 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
13318 while (glyph
->charpos
< PT
)
13321 w
->cursor
.x
+= glyph
->pixel_width
;
13327 /* Adjust window end. A null value of last_text_row means that
13328 the window end is in reused rows which in turn means that
13329 only its vpos can have changed. */
13332 w
->window_end_bytepos
13333 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13335 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13337 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13342 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
13345 w
->window_end_valid
= Qnil
;
13346 w
->desired_matrix
->no_scrolling_p
= 1;
13349 debug_method_add (w
, "try_window_reusing_current_matrix 2");
13359 /************************************************************************
13360 Window redisplay reusing current matrix when buffer has changed
13361 ************************************************************************/
13363 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
13364 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
13366 static struct glyph_row
*
13367 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
13368 struct glyph_row
*));
13371 /* Return the last row in MATRIX displaying text. If row START is
13372 non-null, start searching with that row. IT gives the dimensions
13373 of the display. Value is null if matrix is empty; otherwise it is
13374 a pointer to the row found. */
13376 static struct glyph_row
*
13377 find_last_row_displaying_text (matrix
, it
, start
)
13378 struct glyph_matrix
*matrix
;
13380 struct glyph_row
*start
;
13382 struct glyph_row
*row
, *row_found
;
13384 /* Set row_found to the last row in IT->w's current matrix
13385 displaying text. The loop looks funny but think of partially
13388 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
13389 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13391 xassert (row
->enabled_p
);
13393 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
13402 /* Return the last row in the current matrix of W that is not affected
13403 by changes at the start of current_buffer that occurred since W's
13404 current matrix was built. Value is null if no such row exists.
13406 BEG_UNCHANGED us the number of characters unchanged at the start of
13407 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
13408 first changed character in current_buffer. Characters at positions <
13409 BEG + BEG_UNCHANGED are at the same buffer positions as they were
13410 when the current matrix was built. */
13412 static struct glyph_row
*
13413 find_last_unchanged_at_beg_row (w
)
13416 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
13417 struct glyph_row
*row
;
13418 struct glyph_row
*row_found
= NULL
;
13419 int yb
= window_text_bottom_y (w
);
13421 /* Find the last row displaying unchanged text. */
13422 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13423 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13424 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
13426 if (/* If row ends before first_changed_pos, it is unchanged,
13427 except in some case. */
13428 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
13429 /* When row ends in ZV and we write at ZV it is not
13431 && !row
->ends_at_zv_p
13432 /* When first_changed_pos is the end of a continued line,
13433 row is not unchanged because it may be no longer
13435 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
13436 && (row
->continued_p
13437 || row
->exact_window_width_line_p
)))
13440 /* Stop if last visible row. */
13441 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
13451 /* Find the first glyph row in the current matrix of W that is not
13452 affected by changes at the end of current_buffer since the
13453 time W's current matrix was built.
13455 Return in *DELTA the number of chars by which buffer positions in
13456 unchanged text at the end of current_buffer must be adjusted.
13458 Return in *DELTA_BYTES the corresponding number of bytes.
13460 Value is null if no such row exists, i.e. all rows are affected by
13463 static struct glyph_row
*
13464 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
13466 int *delta
, *delta_bytes
;
13468 struct glyph_row
*row
;
13469 struct glyph_row
*row_found
= NULL
;
13471 *delta
= *delta_bytes
= 0;
13473 /* Display must not have been paused, otherwise the current matrix
13474 is not up to date. */
13475 if (NILP (w
->window_end_valid
))
13478 /* A value of window_end_pos >= END_UNCHANGED means that the window
13479 end is in the range of changed text. If so, there is no
13480 unchanged row at the end of W's current matrix. */
13481 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
13484 /* Set row to the last row in W's current matrix displaying text. */
13485 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13487 /* If matrix is entirely empty, no unchanged row exists. */
13488 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13490 /* The value of row is the last glyph row in the matrix having a
13491 meaningful buffer position in it. The end position of row
13492 corresponds to window_end_pos. This allows us to translate
13493 buffer positions in the current matrix to current buffer
13494 positions for characters not in changed text. */
13495 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13496 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13497 int last_unchanged_pos
, last_unchanged_pos_old
;
13498 struct glyph_row
*first_text_row
13499 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13501 *delta
= Z
- Z_old
;
13502 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13504 /* Set last_unchanged_pos to the buffer position of the last
13505 character in the buffer that has not been changed. Z is the
13506 index + 1 of the last character in current_buffer, i.e. by
13507 subtracting END_UNCHANGED we get the index of the last
13508 unchanged character, and we have to add BEG to get its buffer
13510 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
13511 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
13513 /* Search backward from ROW for a row displaying a line that
13514 starts at a minimum position >= last_unchanged_pos_old. */
13515 for (; row
> first_text_row
; --row
)
13517 /* This used to abort, but it can happen.
13518 It is ok to just stop the search instead here. KFS. */
13519 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13522 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
13527 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
13534 /* Make sure that glyph rows in the current matrix of window W
13535 reference the same glyph memory as corresponding rows in the
13536 frame's frame matrix. This function is called after scrolling W's
13537 current matrix on a terminal frame in try_window_id and
13538 try_window_reusing_current_matrix. */
13541 sync_frame_with_window_matrix_rows (w
)
13544 struct frame
*f
= XFRAME (w
->frame
);
13545 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
13547 /* Preconditions: W must be a leaf window and full-width. Its frame
13548 must have a frame matrix. */
13549 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
13550 xassert (WINDOW_FULL_WIDTH_P (w
));
13551 xassert (!FRAME_WINDOW_P (f
));
13553 /* If W is a full-width window, glyph pointers in W's current matrix
13554 have, by definition, to be the same as glyph pointers in the
13555 corresponding frame matrix. Note that frame matrices have no
13556 marginal areas (see build_frame_matrix). */
13557 window_row
= w
->current_matrix
->rows
;
13558 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
13559 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
13560 while (window_row
< window_row_end
)
13562 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
13563 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
13565 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
13566 frame_row
->glyphs
[TEXT_AREA
] = start
;
13567 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
13568 frame_row
->glyphs
[LAST_AREA
] = end
;
13570 /* Disable frame rows whose corresponding window rows have
13571 been disabled in try_window_id. */
13572 if (!window_row
->enabled_p
)
13573 frame_row
->enabled_p
= 0;
13575 ++window_row
, ++frame_row
;
13580 /* Find the glyph row in window W containing CHARPOS. Consider all
13581 rows between START and END (not inclusive). END null means search
13582 all rows to the end of the display area of W. Value is the row
13583 containing CHARPOS or null. */
13586 row_containing_pos (w
, charpos
, start
, end
, dy
)
13589 struct glyph_row
*start
, *end
;
13592 struct glyph_row
*row
= start
;
13595 /* If we happen to start on a header-line, skip that. */
13596 if (row
->mode_line_p
)
13599 if ((end
&& row
>= end
) || !row
->enabled_p
)
13602 last_y
= window_text_bottom_y (w
) - dy
;
13606 /* Give up if we have gone too far. */
13607 if (end
&& row
>= end
)
13609 /* This formerly returned if they were equal.
13610 I think that both quantities are of a "last plus one" type;
13611 if so, when they are equal, the row is within the screen. -- rms. */
13612 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
13615 /* If it is in this row, return this row. */
13616 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
13617 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
13618 /* The end position of a row equals the start
13619 position of the next row. If CHARPOS is there, we
13620 would rather display it in the next line, except
13621 when this line ends in ZV. */
13622 && !row
->ends_at_zv_p
13623 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13624 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
13631 /* Try to redisplay window W by reusing its existing display. W's
13632 current matrix must be up to date when this function is called,
13633 i.e. window_end_valid must not be nil.
13637 1 if display has been updated
13638 0 if otherwise unsuccessful
13639 -1 if redisplay with same window start is known not to succeed
13641 The following steps are performed:
13643 1. Find the last row in the current matrix of W that is not
13644 affected by changes at the start of current_buffer. If no such row
13647 2. Find the first row in W's current matrix that is not affected by
13648 changes at the end of current_buffer. Maybe there is no such row.
13650 3. Display lines beginning with the row + 1 found in step 1 to the
13651 row found in step 2 or, if step 2 didn't find a row, to the end of
13654 4. If cursor is not known to appear on the window, give up.
13656 5. If display stopped at the row found in step 2, scroll the
13657 display and current matrix as needed.
13659 6. Maybe display some lines at the end of W, if we must. This can
13660 happen under various circumstances, like a partially visible line
13661 becoming fully visible, or because newly displayed lines are displayed
13662 in smaller font sizes.
13664 7. Update W's window end information. */
13670 struct frame
*f
= XFRAME (w
->frame
);
13671 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
13672 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
13673 struct glyph_row
*last_unchanged_at_beg_row
;
13674 struct glyph_row
*first_unchanged_at_end_row
;
13675 struct glyph_row
*row
;
13676 struct glyph_row
*bottom_row
;
13679 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
13680 struct text_pos start_pos
;
13682 int first_unchanged_at_end_vpos
= 0;
13683 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
13684 struct text_pos start
;
13685 int first_changed_charpos
, last_changed_charpos
;
13688 if (inhibit_try_window_id
)
13692 /* This is handy for debugging. */
13694 #define GIVE_UP(X) \
13696 fprintf (stderr, "try_window_id give up %d\n", (X)); \
13700 #define GIVE_UP(X) return 0
13703 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
13705 /* Don't use this for mini-windows because these can show
13706 messages and mini-buffers, and we don't handle that here. */
13707 if (MINI_WINDOW_P (w
))
13710 /* This flag is used to prevent redisplay optimizations. */
13711 if (windows_or_buffers_changed
|| cursor_type_changed
)
13714 /* Verify that narrowing has not changed.
13715 Also verify that we were not told to prevent redisplay optimizations.
13716 It would be nice to further
13717 reduce the number of cases where this prevents try_window_id. */
13718 if (current_buffer
->clip_changed
13719 || current_buffer
->prevent_redisplay_optimizations_p
)
13722 /* Window must either use window-based redisplay or be full width. */
13723 if (!FRAME_WINDOW_P (f
)
13724 && (!line_ins_del_ok
13725 || !WINDOW_FULL_WIDTH_P (w
)))
13728 /* Give up if point is not known NOT to appear in W. */
13729 if (PT
< CHARPOS (start
))
13732 /* Another way to prevent redisplay optimizations. */
13733 if (XFASTINT (w
->last_modified
) == 0)
13736 /* Verify that window is not hscrolled. */
13737 if (XFASTINT (w
->hscroll
) != 0)
13740 /* Verify that display wasn't paused. */
13741 if (NILP (w
->window_end_valid
))
13744 /* Can't use this if highlighting a region because a cursor movement
13745 will do more than just set the cursor. */
13746 if (!NILP (Vtransient_mark_mode
)
13747 && !NILP (current_buffer
->mark_active
))
13750 /* Likewise if highlighting trailing whitespace. */
13751 if (!NILP (Vshow_trailing_whitespace
))
13754 /* Likewise if showing a region. */
13755 if (!NILP (w
->region_showing
))
13758 /* Can use this if overlay arrow position and or string have changed. */
13759 if (overlay_arrows_changed_p ())
13763 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
13764 only if buffer has really changed. The reason is that the gap is
13765 initially at Z for freshly visited files. The code below would
13766 set end_unchanged to 0 in that case. */
13767 if (MODIFF
> SAVE_MODIFF
13768 /* This seems to happen sometimes after saving a buffer. */
13769 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
13771 if (GPT
- BEG
< BEG_UNCHANGED
)
13772 BEG_UNCHANGED
= GPT
- BEG
;
13773 if (Z
- GPT
< END_UNCHANGED
)
13774 END_UNCHANGED
= Z
- GPT
;
13777 /* The position of the first and last character that has been changed. */
13778 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
13779 last_changed_charpos
= Z
- END_UNCHANGED
;
13781 /* If window starts after a line end, and the last change is in
13782 front of that newline, then changes don't affect the display.
13783 This case happens with stealth-fontification. Note that although
13784 the display is unchanged, glyph positions in the matrix have to
13785 be adjusted, of course. */
13786 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13787 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13788 && ((last_changed_charpos
< CHARPOS (start
)
13789 && CHARPOS (start
) == BEGV
)
13790 || (last_changed_charpos
< CHARPOS (start
) - 1
13791 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
13793 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
13794 struct glyph_row
*r0
;
13796 /* Compute how many chars/bytes have been added to or removed
13797 from the buffer. */
13798 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13799 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13801 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13803 /* Give up if PT is not in the window. Note that it already has
13804 been checked at the start of try_window_id that PT is not in
13805 front of the window start. */
13806 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
13809 /* If window start is unchanged, we can reuse the whole matrix
13810 as is, after adjusting glyph positions. No need to compute
13811 the window end again, since its offset from Z hasn't changed. */
13812 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13813 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
13814 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
13815 /* PT must not be in a partially visible line. */
13816 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
13817 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13819 /* Adjust positions in the glyph matrix. */
13820 if (delta
|| delta_bytes
)
13822 struct glyph_row
*r1
13823 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13824 increment_matrix_positions (w
->current_matrix
,
13825 MATRIX_ROW_VPOS (r0
, current_matrix
),
13826 MATRIX_ROW_VPOS (r1
, current_matrix
),
13827 delta
, delta_bytes
);
13830 /* Set the cursor. */
13831 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13833 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13840 /* Handle the case that changes are all below what is displayed in
13841 the window, and that PT is in the window. This shortcut cannot
13842 be taken if ZV is visible in the window, and text has been added
13843 there that is visible in the window. */
13844 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
13845 /* ZV is not visible in the window, or there are no
13846 changes at ZV, actually. */
13847 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
13848 || first_changed_charpos
== last_changed_charpos
))
13850 struct glyph_row
*r0
;
13852 /* Give up if PT is not in the window. Note that it already has
13853 been checked at the start of try_window_id that PT is not in
13854 front of the window start. */
13855 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
13858 /* If window start is unchanged, we can reuse the whole matrix
13859 as is, without changing glyph positions since no text has
13860 been added/removed in front of the window end. */
13861 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13862 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
13863 /* PT must not be in a partially visible line. */
13864 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
13865 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13867 /* We have to compute the window end anew since text
13868 can have been added/removed after it. */
13870 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13871 w
->window_end_bytepos
13872 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13874 /* Set the cursor. */
13875 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13877 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13884 /* Give up if window start is in the changed area.
13886 The condition used to read
13888 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
13890 but why that was tested escapes me at the moment. */
13891 if (CHARPOS (start
) >= first_changed_charpos
13892 && CHARPOS (start
) <= last_changed_charpos
)
13895 /* Check that window start agrees with the start of the first glyph
13896 row in its current matrix. Check this after we know the window
13897 start is not in changed text, otherwise positions would not be
13899 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13900 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
13903 /* Give up if the window ends in strings. Overlay strings
13904 at the end are difficult to handle, so don't try. */
13905 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
13906 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
13909 /* Compute the position at which we have to start displaying new
13910 lines. Some of the lines at the top of the window might be
13911 reusable because they are not displaying changed text. Find the
13912 last row in W's current matrix not affected by changes at the
13913 start of current_buffer. Value is null if changes start in the
13914 first line of window. */
13915 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
13916 if (last_unchanged_at_beg_row
)
13918 /* Avoid starting to display in the moddle of a character, a TAB
13919 for instance. This is easier than to set up the iterator
13920 exactly, and it's not a frequent case, so the additional
13921 effort wouldn't really pay off. */
13922 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
13923 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
13924 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
13925 --last_unchanged_at_beg_row
;
13927 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
13930 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
13932 start_pos
= it
.current
.pos
;
13934 /* Start displaying new lines in the desired matrix at the same
13935 vpos we would use in the current matrix, i.e. below
13936 last_unchanged_at_beg_row. */
13937 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
13939 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13940 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
13942 xassert (it
.hpos
== 0 && it
.current_x
== 0);
13946 /* There are no reusable lines at the start of the window.
13947 Start displaying in the first text line. */
13948 start_display (&it
, w
, start
);
13949 it
.vpos
= it
.first_vpos
;
13950 start_pos
= it
.current
.pos
;
13953 /* Find the first row that is not affected by changes at the end of
13954 the buffer. Value will be null if there is no unchanged row, in
13955 which case we must redisplay to the end of the window. delta
13956 will be set to the value by which buffer positions beginning with
13957 first_unchanged_at_end_row have to be adjusted due to text
13959 first_unchanged_at_end_row
13960 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
13961 IF_DEBUG (debug_delta
= delta
);
13962 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
13964 /* Set stop_pos to the buffer position up to which we will have to
13965 display new lines. If first_unchanged_at_end_row != NULL, this
13966 is the buffer position of the start of the line displayed in that
13967 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
13968 that we don't stop at a buffer position. */
13970 if (first_unchanged_at_end_row
)
13972 xassert (last_unchanged_at_beg_row
== NULL
13973 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
13975 /* If this is a continuation line, move forward to the next one
13976 that isn't. Changes in lines above affect this line.
13977 Caution: this may move first_unchanged_at_end_row to a row
13978 not displaying text. */
13979 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
13980 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13981 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13982 < it
.last_visible_y
))
13983 ++first_unchanged_at_end_row
;
13985 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13986 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13987 >= it
.last_visible_y
))
13988 first_unchanged_at_end_row
= NULL
;
13991 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13993 first_unchanged_at_end_vpos
13994 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13995 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13998 else if (last_unchanged_at_beg_row
== NULL
)
14004 /* Either there is no unchanged row at the end, or the one we have
14005 now displays text. This is a necessary condition for the window
14006 end pos calculation at the end of this function. */
14007 xassert (first_unchanged_at_end_row
== NULL
14008 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
14010 debug_last_unchanged_at_beg_vpos
14011 = (last_unchanged_at_beg_row
14012 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
14014 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
14016 #endif /* GLYPH_DEBUG != 0 */
14019 /* Display new lines. Set last_text_row to the last new line
14020 displayed which has text on it, i.e. might end up as being the
14021 line where the window_end_vpos is. */
14022 w
->cursor
.vpos
= -1;
14023 last_text_row
= NULL
;
14024 overlay_arrow_seen
= 0;
14025 while (it
.current_y
< it
.last_visible_y
14026 && !fonts_changed_p
14027 && (first_unchanged_at_end_row
== NULL
14028 || IT_CHARPOS (it
) < stop_pos
))
14030 if (display_line (&it
))
14031 last_text_row
= it
.glyph_row
- 1;
14034 if (fonts_changed_p
)
14038 /* Compute differences in buffer positions, y-positions etc. for
14039 lines reused at the bottom of the window. Compute what we can
14041 if (first_unchanged_at_end_row
14042 /* No lines reused because we displayed everything up to the
14043 bottom of the window. */
14044 && it
.current_y
< it
.last_visible_y
)
14047 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
14049 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
14050 run
.current_y
= first_unchanged_at_end_row
->y
;
14051 run
.desired_y
= run
.current_y
+ dy
;
14052 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
14056 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
14057 first_unchanged_at_end_row
= NULL
;
14059 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14062 /* Find the cursor if not already found. We have to decide whether
14063 PT will appear on this window (it sometimes doesn't, but this is
14064 not a very frequent case.) This decision has to be made before
14065 the current matrix is altered. A value of cursor.vpos < 0 means
14066 that PT is either in one of the lines beginning at
14067 first_unchanged_at_end_row or below the window. Don't care for
14068 lines that might be displayed later at the window end; as
14069 mentioned, this is not a frequent case. */
14070 if (w
->cursor
.vpos
< 0)
14072 /* Cursor in unchanged rows at the top? */
14073 if (PT
< CHARPOS (start_pos
)
14074 && last_unchanged_at_beg_row
)
14076 row
= row_containing_pos (w
, PT
,
14077 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14078 last_unchanged_at_beg_row
+ 1, 0);
14080 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14083 /* Start from first_unchanged_at_end_row looking for PT. */
14084 else if (first_unchanged_at_end_row
)
14086 row
= row_containing_pos (w
, PT
- delta
,
14087 first_unchanged_at_end_row
, NULL
, 0);
14089 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14090 delta_bytes
, dy
, dvpos
);
14093 /* Give up if cursor was not found. */
14094 if (w
->cursor
.vpos
< 0)
14096 clear_glyph_matrix (w
->desired_matrix
);
14101 /* Don't let the cursor end in the scroll margins. */
14103 int this_scroll_margin
, cursor_height
;
14105 this_scroll_margin
= max (0, scroll_margin
);
14106 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14107 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14108 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14110 if ((w
->cursor
.y
< this_scroll_margin
14111 && CHARPOS (start
) > BEGV
)
14112 /* Old redisplay didn't take scroll margin into account at the bottom,
14113 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14114 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14115 ? cursor_height
+ this_scroll_margin
14116 : 1)) > it
.last_visible_y
)
14118 w
->cursor
.vpos
= -1;
14119 clear_glyph_matrix (w
->desired_matrix
);
14124 /* Scroll the display. Do it before changing the current matrix so
14125 that xterm.c doesn't get confused about where the cursor glyph is
14127 if (dy
&& run
.height
)
14131 if (FRAME_WINDOW_P (f
))
14133 rif
->update_window_begin_hook (w
);
14134 rif
->clear_window_mouse_face (w
);
14135 rif
->scroll_run_hook (w
, &run
);
14136 rif
->update_window_end_hook (w
, 0, 0);
14140 /* Terminal frame. In this case, dvpos gives the number of
14141 lines to scroll by; dvpos < 0 means scroll up. */
14142 int first_unchanged_at_end_vpos
14143 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14144 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14145 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14146 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14147 + window_internal_height (w
));
14149 /* Perform the operation on the screen. */
14152 /* Scroll last_unchanged_at_beg_row to the end of the
14153 window down dvpos lines. */
14154 set_terminal_window (end
);
14156 /* On dumb terminals delete dvpos lines at the end
14157 before inserting dvpos empty lines. */
14158 if (!scroll_region_ok
)
14159 ins_del_lines (end
- dvpos
, -dvpos
);
14161 /* Insert dvpos empty lines in front of
14162 last_unchanged_at_beg_row. */
14163 ins_del_lines (from
, dvpos
);
14165 else if (dvpos
< 0)
14167 /* Scroll up last_unchanged_at_beg_vpos to the end of
14168 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14169 set_terminal_window (end
);
14171 /* Delete dvpos lines in front of
14172 last_unchanged_at_beg_vpos. ins_del_lines will set
14173 the cursor to the given vpos and emit |dvpos| delete
14175 ins_del_lines (from
+ dvpos
, dvpos
);
14177 /* On a dumb terminal insert dvpos empty lines at the
14179 if (!scroll_region_ok
)
14180 ins_del_lines (end
+ dvpos
, -dvpos
);
14183 set_terminal_window (0);
14189 /* Shift reused rows of the current matrix to the right position.
14190 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14192 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14193 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14196 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14197 bottom_vpos
, dvpos
);
14198 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14201 else if (dvpos
> 0)
14203 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14204 bottom_vpos
, dvpos
);
14205 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14206 first_unchanged_at_end_vpos
+ dvpos
, 0);
14209 /* For frame-based redisplay, make sure that current frame and window
14210 matrix are in sync with respect to glyph memory. */
14211 if (!FRAME_WINDOW_P (f
))
14212 sync_frame_with_window_matrix_rows (w
);
14214 /* Adjust buffer positions in reused rows. */
14216 increment_matrix_positions (current_matrix
,
14217 first_unchanged_at_end_vpos
+ dvpos
,
14218 bottom_vpos
, delta
, delta_bytes
);
14220 /* Adjust Y positions. */
14222 shift_glyph_matrix (w
, current_matrix
,
14223 first_unchanged_at_end_vpos
+ dvpos
,
14226 if (first_unchanged_at_end_row
)
14228 first_unchanged_at_end_row
+= dvpos
;
14229 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14230 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
14231 first_unchanged_at_end_row
= NULL
;
14234 /* If scrolling up, there may be some lines to display at the end of
14236 last_text_row_at_end
= NULL
;
14239 /* Scrolling up can leave for example a partially visible line
14240 at the end of the window to be redisplayed. */
14241 /* Set last_row to the glyph row in the current matrix where the
14242 window end line is found. It has been moved up or down in
14243 the matrix by dvpos. */
14244 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
14245 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
14247 /* If last_row is the window end line, it should display text. */
14248 xassert (last_row
->displays_text_p
);
14250 /* If window end line was partially visible before, begin
14251 displaying at that line. Otherwise begin displaying with the
14252 line following it. */
14253 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
14255 init_to_row_start (&it
, w
, last_row
);
14256 it
.vpos
= last_vpos
;
14257 it
.current_y
= last_row
->y
;
14261 init_to_row_end (&it
, w
, last_row
);
14262 it
.vpos
= 1 + last_vpos
;
14263 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
14267 /* We may start in a continuation line. If so, we have to
14268 get the right continuation_lines_width and current_x. */
14269 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
14270 it
.hpos
= it
.current_x
= 0;
14272 /* Display the rest of the lines at the window end. */
14273 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14274 while (it
.current_y
< it
.last_visible_y
14275 && !fonts_changed_p
)
14277 /* Is it always sure that the display agrees with lines in
14278 the current matrix? I don't think so, so we mark rows
14279 displayed invalid in the current matrix by setting their
14280 enabled_p flag to zero. */
14281 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
14282 if (display_line (&it
))
14283 last_text_row_at_end
= it
.glyph_row
- 1;
14287 /* Update window_end_pos and window_end_vpos. */
14288 if (first_unchanged_at_end_row
14289 && !last_text_row_at_end
)
14291 /* Window end line if one of the preserved rows from the current
14292 matrix. Set row to the last row displaying text in current
14293 matrix starting at first_unchanged_at_end_row, after
14295 xassert (first_unchanged_at_end_row
->displays_text_p
);
14296 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
14297 first_unchanged_at_end_row
);
14298 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
14300 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14301 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14303 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
14304 xassert (w
->window_end_bytepos
>= 0);
14305 IF_DEBUG (debug_method_add (w
, "A"));
14307 else if (last_text_row_at_end
)
14310 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
14311 w
->window_end_bytepos
14312 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
14314 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
14315 xassert (w
->window_end_bytepos
>= 0);
14316 IF_DEBUG (debug_method_add (w
, "B"));
14318 else if (last_text_row
)
14320 /* We have displayed either to the end of the window or at the
14321 end of the window, i.e. the last row with text is to be found
14322 in the desired matrix. */
14324 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14325 w
->window_end_bytepos
14326 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14328 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
14329 xassert (w
->window_end_bytepos
>= 0);
14331 else if (first_unchanged_at_end_row
== NULL
14332 && last_text_row
== NULL
14333 && last_text_row_at_end
== NULL
)
14335 /* Displayed to end of window, but no line containing text was
14336 displayed. Lines were deleted at the end of the window. */
14337 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
14338 int vpos
= XFASTINT (w
->window_end_vpos
);
14339 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
14340 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
14343 row
== NULL
&& vpos
>= first_vpos
;
14344 --vpos
, --current_row
, --desired_row
)
14346 if (desired_row
->enabled_p
)
14348 if (desired_row
->displays_text_p
)
14351 else if (current_row
->displays_text_p
)
14355 xassert (row
!= NULL
);
14356 w
->window_end_vpos
= make_number (vpos
+ 1);
14357 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14358 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14359 xassert (w
->window_end_bytepos
>= 0);
14360 IF_DEBUG (debug_method_add (w
, "C"));
14365 #if 0 /* This leads to problems, for instance when the cursor is
14366 at ZV, and the cursor line displays no text. */
14367 /* Disable rows below what's displayed in the window. This makes
14368 debugging easier. */
14369 enable_glyph_matrix_rows (current_matrix
,
14370 XFASTINT (w
->window_end_vpos
) + 1,
14374 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
14375 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
14377 /* Record that display has not been completed. */
14378 w
->window_end_valid
= Qnil
;
14379 w
->desired_matrix
->no_scrolling_p
= 1;
14387 /***********************************************************************
14388 More debugging support
14389 ***********************************************************************/
14393 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
14394 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
14395 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
14398 /* Dump the contents of glyph matrix MATRIX on stderr.
14400 GLYPHS 0 means don't show glyph contents.
14401 GLYPHS 1 means show glyphs in short form
14402 GLYPHS > 1 means show glyphs in long form. */
14405 dump_glyph_matrix (matrix
, glyphs
)
14406 struct glyph_matrix
*matrix
;
14410 for (i
= 0; i
< matrix
->nrows
; ++i
)
14411 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
14415 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
14416 the glyph row and area where the glyph comes from. */
14419 dump_glyph (row
, glyph
, area
)
14420 struct glyph_row
*row
;
14421 struct glyph
*glyph
;
14424 if (glyph
->type
== CHAR_GLYPH
)
14427 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14428 glyph
- row
->glyphs
[TEXT_AREA
],
14431 (BUFFERP (glyph
->object
)
14433 : (STRINGP (glyph
->object
)
14436 glyph
->pixel_width
,
14438 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
14442 glyph
->left_box_line_p
,
14443 glyph
->right_box_line_p
);
14445 else if (glyph
->type
== STRETCH_GLYPH
)
14448 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14449 glyph
- row
->glyphs
[TEXT_AREA
],
14452 (BUFFERP (glyph
->object
)
14454 : (STRINGP (glyph
->object
)
14457 glyph
->pixel_width
,
14461 glyph
->left_box_line_p
,
14462 glyph
->right_box_line_p
);
14464 else if (glyph
->type
== IMAGE_GLYPH
)
14467 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14468 glyph
- row
->glyphs
[TEXT_AREA
],
14471 (BUFFERP (glyph
->object
)
14473 : (STRINGP (glyph
->object
)
14476 glyph
->pixel_width
,
14480 glyph
->left_box_line_p
,
14481 glyph
->right_box_line_p
);
14486 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
14487 GLYPHS 0 means don't show glyph contents.
14488 GLYPHS 1 means show glyphs in short form
14489 GLYPHS > 1 means show glyphs in long form. */
14492 dump_glyph_row (row
, vpos
, glyphs
)
14493 struct glyph_row
*row
;
14498 fprintf (stderr
, "Row Start End Used oEI><\\CTZFesm X Y W H V A P\n");
14499 fprintf (stderr
, "======================================================================\n");
14501 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
14502 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
14504 MATRIX_ROW_START_CHARPOS (row
),
14505 MATRIX_ROW_END_CHARPOS (row
),
14506 row
->used
[TEXT_AREA
],
14507 row
->contains_overlapping_glyphs_p
,
14509 row
->truncated_on_left_p
,
14510 row
->truncated_on_right_p
,
14512 MATRIX_ROW_CONTINUATION_LINE_P (row
),
14513 row
->displays_text_p
,
14516 row
->ends_in_middle_of_char_p
,
14517 row
->starts_in_middle_of_char_p
,
14523 row
->visible_height
,
14526 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
14527 row
->end
.overlay_string_index
,
14528 row
->continuation_lines_width
);
14529 fprintf (stderr
, "%9d %5d\n",
14530 CHARPOS (row
->start
.string_pos
),
14531 CHARPOS (row
->end
.string_pos
));
14532 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
14533 row
->end
.dpvec_index
);
14540 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14542 struct glyph
*glyph
= row
->glyphs
[area
];
14543 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
14545 /* Glyph for a line end in text. */
14546 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
14549 if (glyph
< glyph_end
)
14550 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
14552 for (; glyph
< glyph_end
; ++glyph
)
14553 dump_glyph (row
, glyph
, area
);
14556 else if (glyphs
== 1)
14560 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14562 char *s
= (char *) alloca (row
->used
[area
] + 1);
14565 for (i
= 0; i
< row
->used
[area
]; ++i
)
14567 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
14568 if (glyph
->type
== CHAR_GLYPH
14569 && glyph
->u
.ch
< 0x80
14570 && glyph
->u
.ch
>= ' ')
14571 s
[i
] = glyph
->u
.ch
;
14577 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
14583 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
14584 Sdump_glyph_matrix
, 0, 1, "p",
14585 doc
: /* Dump the current matrix of the selected window to stderr.
14586 Shows contents of glyph row structures. With non-nil
14587 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
14588 glyphs in short form, otherwise show glyphs in long form. */)
14590 Lisp_Object glyphs
;
14592 struct window
*w
= XWINDOW (selected_window
);
14593 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14595 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
14596 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
14597 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
14598 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
14599 fprintf (stderr
, "=============================================\n");
14600 dump_glyph_matrix (w
->current_matrix
,
14601 NILP (glyphs
) ? 0 : XINT (glyphs
));
14606 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
14607 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
14610 struct frame
*f
= XFRAME (selected_frame
);
14611 dump_glyph_matrix (f
->current_matrix
, 1);
14616 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
14617 doc
: /* Dump glyph row ROW to stderr.
14618 GLYPH 0 means don't dump glyphs.
14619 GLYPH 1 means dump glyphs in short form.
14620 GLYPH > 1 or omitted means dump glyphs in long form. */)
14622 Lisp_Object row
, glyphs
;
14624 struct glyph_matrix
*matrix
;
14627 CHECK_NUMBER (row
);
14628 matrix
= XWINDOW (selected_window
)->current_matrix
;
14630 if (vpos
>= 0 && vpos
< matrix
->nrows
)
14631 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
14633 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14638 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
14639 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
14640 GLYPH 0 means don't dump glyphs.
14641 GLYPH 1 means dump glyphs in short form.
14642 GLYPH > 1 or omitted means dump glyphs in long form. */)
14644 Lisp_Object row
, glyphs
;
14646 struct frame
*sf
= SELECTED_FRAME ();
14647 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
14650 CHECK_NUMBER (row
);
14652 if (vpos
>= 0 && vpos
< m
->nrows
)
14653 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
14654 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14659 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
14660 doc
: /* Toggle tracing of redisplay.
14661 With ARG, turn tracing on if and only if ARG is positive. */)
14666 trace_redisplay_p
= !trace_redisplay_p
;
14669 arg
= Fprefix_numeric_value (arg
);
14670 trace_redisplay_p
= XINT (arg
) > 0;
14677 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
14678 doc
: /* Like `format', but print result to stderr.
14679 usage: (trace-to-stderr STRING &rest OBJECTS) */)
14684 Lisp_Object s
= Fformat (nargs
, args
);
14685 fprintf (stderr
, "%s", SDATA (s
));
14689 #endif /* GLYPH_DEBUG */
14693 /***********************************************************************
14694 Building Desired Matrix Rows
14695 ***********************************************************************/
14697 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
14698 Used for non-window-redisplay windows, and for windows w/o left fringe. */
14700 static struct glyph_row
*
14701 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
14703 Lisp_Object overlay_arrow_string
;
14705 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14706 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14707 struct buffer
*old
= current_buffer
;
14708 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
14709 int arrow_len
= SCHARS (overlay_arrow_string
);
14710 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
14711 const unsigned char *p
;
14714 int n_glyphs_before
;
14716 set_buffer_temp (buffer
);
14717 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
14718 it
.glyph_row
->used
[TEXT_AREA
] = 0;
14719 SET_TEXT_POS (it
.position
, 0, 0);
14721 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
14723 while (p
< arrow_end
)
14725 Lisp_Object face
, ilisp
;
14727 /* Get the next character. */
14729 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
14731 it
.c
= *p
, it
.len
= 1;
14734 /* Get its face. */
14735 ilisp
= make_number (p
- arrow_string
);
14736 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
14737 it
.face_id
= compute_char_face (f
, it
.c
, face
);
14739 /* Compute its width, get its glyphs. */
14740 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
14741 SET_TEXT_POS (it
.position
, -1, -1);
14742 PRODUCE_GLYPHS (&it
);
14744 /* If this character doesn't fit any more in the line, we have
14745 to remove some glyphs. */
14746 if (it
.current_x
> it
.last_visible_x
)
14748 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14753 set_buffer_temp (old
);
14754 return it
.glyph_row
;
14758 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
14759 glyphs are only inserted for terminal frames since we can't really
14760 win with truncation glyphs when partially visible glyphs are
14761 involved. Which glyphs to insert is determined by
14762 produce_special_glyphs. */
14765 insert_left_trunc_glyphs (it
)
14768 struct it truncate_it
;
14769 struct glyph
*from
, *end
, *to
, *toend
;
14771 xassert (!FRAME_WINDOW_P (it
->f
));
14773 /* Get the truncation glyphs. */
14775 truncate_it
.current_x
= 0;
14776 truncate_it
.face_id
= DEFAULT_FACE_ID
;
14777 truncate_it
.glyph_row
= &scratch_glyph_row
;
14778 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
14779 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
14780 truncate_it
.object
= make_number (0);
14781 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
14783 /* Overwrite glyphs from IT with truncation glyphs. */
14784 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14785 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
14786 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
14787 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
14792 /* There may be padding glyphs left over. Overwrite them too. */
14793 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
14795 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14801 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
14805 /* Compute the pixel height and width of IT->glyph_row.
14807 Most of the time, ascent and height of a display line will be equal
14808 to the max_ascent and max_height values of the display iterator
14809 structure. This is not the case if
14811 1. We hit ZV without displaying anything. In this case, max_ascent
14812 and max_height will be zero.
14814 2. We have some glyphs that don't contribute to the line height.
14815 (The glyph row flag contributes_to_line_height_p is for future
14816 pixmap extensions).
14818 The first case is easily covered by using default values because in
14819 these cases, the line height does not really matter, except that it
14820 must not be zero. */
14823 compute_line_metrics (it
)
14826 struct glyph_row
*row
= it
->glyph_row
;
14829 if (FRAME_WINDOW_P (it
->f
))
14831 int i
, min_y
, max_y
;
14833 /* The line may consist of one space only, that was added to
14834 place the cursor on it. If so, the row's height hasn't been
14836 if (row
->height
== 0)
14838 if (it
->max_ascent
+ it
->max_descent
== 0)
14839 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
14840 row
->ascent
= it
->max_ascent
;
14841 row
->height
= it
->max_ascent
+ it
->max_descent
;
14842 row
->phys_ascent
= it
->max_phys_ascent
;
14843 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14844 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
14847 /* Compute the width of this line. */
14848 row
->pixel_width
= row
->x
;
14849 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
14850 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
14852 xassert (row
->pixel_width
>= 0);
14853 xassert (row
->ascent
>= 0 && row
->height
> 0);
14855 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
14856 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
14858 /* If first line's physical ascent is larger than its logical
14859 ascent, use the physical ascent, and make the row taller.
14860 This makes accented characters fully visible. */
14861 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
14862 && row
->phys_ascent
> row
->ascent
)
14864 row
->height
+= row
->phys_ascent
- row
->ascent
;
14865 row
->ascent
= row
->phys_ascent
;
14868 /* Compute how much of the line is visible. */
14869 row
->visible_height
= row
->height
;
14871 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
14872 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
14874 if (row
->y
< min_y
)
14875 row
->visible_height
-= min_y
- row
->y
;
14876 if (row
->y
+ row
->height
> max_y
)
14877 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14881 row
->pixel_width
= row
->used
[TEXT_AREA
];
14882 if (row
->continued_p
)
14883 row
->pixel_width
-= it
->continuation_pixel_width
;
14884 else if (row
->truncated_on_right_p
)
14885 row
->pixel_width
-= it
->truncation_pixel_width
;
14886 row
->ascent
= row
->phys_ascent
= 0;
14887 row
->height
= row
->phys_height
= row
->visible_height
= 1;
14888 row
->extra_line_spacing
= 0;
14891 /* Compute a hash code for this row. */
14893 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14894 for (i
= 0; i
< row
->used
[area
]; ++i
)
14895 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
14896 + row
->glyphs
[area
][i
].u
.val
14897 + row
->glyphs
[area
][i
].face_id
14898 + row
->glyphs
[area
][i
].padding_p
14899 + (row
->glyphs
[area
][i
].type
<< 2));
14901 it
->max_ascent
= it
->max_descent
= 0;
14902 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
14906 /* Append one space to the glyph row of iterator IT if doing a
14907 window-based redisplay. The space has the same face as
14908 IT->face_id. Value is non-zero if a space was added.
14910 This function is called to make sure that there is always one glyph
14911 at the end of a glyph row that the cursor can be set on under
14912 window-systems. (If there weren't such a glyph we would not know
14913 how wide and tall a box cursor should be displayed).
14915 At the same time this space let's a nicely handle clearing to the
14916 end of the line if the row ends in italic text. */
14919 append_space_for_newline (it
, default_face_p
)
14921 int default_face_p
;
14923 if (FRAME_WINDOW_P (it
->f
))
14925 int n
= it
->glyph_row
->used
[TEXT_AREA
];
14927 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
14928 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
14930 /* Save some values that must not be changed.
14931 Must save IT->c and IT->len because otherwise
14932 ITERATOR_AT_END_P wouldn't work anymore after
14933 append_space_for_newline has been called. */
14934 enum display_element_type saved_what
= it
->what
;
14935 int saved_c
= it
->c
, saved_len
= it
->len
;
14936 int saved_x
= it
->current_x
;
14937 int saved_face_id
= it
->face_id
;
14938 struct text_pos saved_pos
;
14939 Lisp_Object saved_object
;
14942 saved_object
= it
->object
;
14943 saved_pos
= it
->position
;
14945 it
->what
= IT_CHARACTER
;
14946 bzero (&it
->position
, sizeof it
->position
);
14947 it
->object
= make_number (0);
14951 if (default_face_p
)
14952 it
->face_id
= DEFAULT_FACE_ID
;
14953 else if (it
->face_before_selective_p
)
14954 it
->face_id
= it
->saved_face_id
;
14955 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14956 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
14958 PRODUCE_GLYPHS (it
);
14960 it
->override_ascent
= -1;
14961 it
->constrain_row_ascent_descent_p
= 0;
14962 it
->current_x
= saved_x
;
14963 it
->object
= saved_object
;
14964 it
->position
= saved_pos
;
14965 it
->what
= saved_what
;
14966 it
->face_id
= saved_face_id
;
14967 it
->len
= saved_len
;
14977 /* Extend the face of the last glyph in the text area of IT->glyph_row
14978 to the end of the display line. Called from display_line.
14979 If the glyph row is empty, add a space glyph to it so that we
14980 know the face to draw. Set the glyph row flag fill_line_p. */
14983 extend_face_to_end_of_line (it
)
14987 struct frame
*f
= it
->f
;
14989 /* If line is already filled, do nothing. */
14990 if (it
->current_x
>= it
->last_visible_x
)
14993 /* Face extension extends the background and box of IT->face_id
14994 to the end of the line. If the background equals the background
14995 of the frame, we don't have to do anything. */
14996 if (it
->face_before_selective_p
)
14997 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14999 face
= FACE_FROM_ID (f
, it
->face_id
);
15001 if (FRAME_WINDOW_P (f
)
15002 && face
->box
== FACE_NO_BOX
15003 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
15007 /* Set the glyph row flag indicating that the face of the last glyph
15008 in the text area has to be drawn to the end of the text area. */
15009 it
->glyph_row
->fill_line_p
= 1;
15011 /* If current character of IT is not ASCII, make sure we have the
15012 ASCII face. This will be automatically undone the next time
15013 get_next_display_element returns a multibyte character. Note
15014 that the character will always be single byte in unibyte text. */
15015 if (!ASCII_CHAR_P (it
->c
))
15017 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
15020 if (FRAME_WINDOW_P (f
))
15022 /* If the row is empty, add a space with the current face of IT,
15023 so that we know which face to draw. */
15024 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
15026 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
15027 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
15028 it
->glyph_row
->used
[TEXT_AREA
] = 1;
15033 /* Save some values that must not be changed. */
15034 int saved_x
= it
->current_x
;
15035 struct text_pos saved_pos
;
15036 Lisp_Object saved_object
;
15037 enum display_element_type saved_what
= it
->what
;
15038 int saved_face_id
= it
->face_id
;
15040 saved_object
= it
->object
;
15041 saved_pos
= it
->position
;
15043 it
->what
= IT_CHARACTER
;
15044 bzero (&it
->position
, sizeof it
->position
);
15045 it
->object
= make_number (0);
15048 it
->face_id
= face
->id
;
15050 PRODUCE_GLYPHS (it
);
15052 while (it
->current_x
<= it
->last_visible_x
)
15053 PRODUCE_GLYPHS (it
);
15055 /* Don't count these blanks really. It would let us insert a left
15056 truncation glyph below and make us set the cursor on them, maybe. */
15057 it
->current_x
= saved_x
;
15058 it
->object
= saved_object
;
15059 it
->position
= saved_pos
;
15060 it
->what
= saved_what
;
15061 it
->face_id
= saved_face_id
;
15066 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15067 trailing whitespace. */
15070 trailing_whitespace_p (charpos
)
15073 int bytepos
= CHAR_TO_BYTE (charpos
);
15076 while (bytepos
< ZV_BYTE
15077 && (c
= FETCH_CHAR (bytepos
),
15078 c
== ' ' || c
== '\t'))
15081 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15083 if (bytepos
!= PT_BYTE
)
15090 /* Highlight trailing whitespace, if any, in ROW. */
15093 highlight_trailing_whitespace (f
, row
)
15095 struct glyph_row
*row
;
15097 int used
= row
->used
[TEXT_AREA
];
15101 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15102 struct glyph
*glyph
= start
+ used
- 1;
15104 /* Skip over glyphs inserted to display the cursor at the
15105 end of a line, for extending the face of the last glyph
15106 to the end of the line on terminals, and for truncation
15107 and continuation glyphs. */
15108 while (glyph
>= start
15109 && glyph
->type
== CHAR_GLYPH
15110 && INTEGERP (glyph
->object
))
15113 /* If last glyph is a space or stretch, and it's trailing
15114 whitespace, set the face of all trailing whitespace glyphs in
15115 IT->glyph_row to `trailing-whitespace'. */
15117 && BUFFERP (glyph
->object
)
15118 && (glyph
->type
== STRETCH_GLYPH
15119 || (glyph
->type
== CHAR_GLYPH
15120 && glyph
->u
.ch
== ' '))
15121 && trailing_whitespace_p (glyph
->charpos
))
15123 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
15127 while (glyph
>= start
15128 && BUFFERP (glyph
->object
)
15129 && (glyph
->type
== STRETCH_GLYPH
15130 || (glyph
->type
== CHAR_GLYPH
15131 && glyph
->u
.ch
== ' ')))
15132 (glyph
--)->face_id
= face_id
;
15138 /* Value is non-zero if glyph row ROW in window W should be
15139 used to hold the cursor. */
15142 cursor_row_p (w
, row
)
15144 struct glyph_row
*row
;
15146 int cursor_row_p
= 1;
15148 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15150 /* If the row ends with a newline from a string, we don't want
15151 the cursor there, but we still want it at the start of the
15152 string if the string starts in this row.
15153 If the row is continued it doesn't end in a newline. */
15154 if (CHARPOS (row
->end
.string_pos
) >= 0)
15155 cursor_row_p
= (row
->continued_p
15156 || PT
>= MATRIX_ROW_START_CHARPOS (row
));
15157 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15159 /* If the row ends in middle of a real character,
15160 and the line is continued, we want the cursor here.
15161 That's because MATRIX_ROW_END_CHARPOS would equal
15162 PT if PT is before the character. */
15163 if (!row
->ends_in_ellipsis_p
)
15164 cursor_row_p
= row
->continued_p
;
15166 /* If the row ends in an ellipsis, then
15167 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15168 We want that position to be displayed after the ellipsis. */
15171 /* If the row ends at ZV, display the cursor at the end of that
15172 row instead of at the start of the row below. */
15173 else if (row
->ends_at_zv_p
)
15179 return cursor_row_p
;
15183 /* Construct the glyph row IT->glyph_row in the desired matrix of
15184 IT->w from text at the current position of IT. See dispextern.h
15185 for an overview of struct it. Value is non-zero if
15186 IT->glyph_row displays text, as opposed to a line displaying ZV
15193 struct glyph_row
*row
= it
->glyph_row
;
15194 Lisp_Object overlay_arrow_string
;
15196 /* We always start displaying at hpos zero even if hscrolled. */
15197 xassert (it
->hpos
== 0 && it
->current_x
== 0);
15199 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
15200 >= it
->w
->desired_matrix
->nrows
)
15202 it
->w
->nrows_scale_factor
++;
15203 fonts_changed_p
= 1;
15207 /* Is IT->w showing the region? */
15208 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
15210 /* Clear the result glyph row and enable it. */
15211 prepare_desired_row (row
);
15213 row
->y
= it
->current_y
;
15214 row
->start
= it
->start
;
15215 row
->continuation_lines_width
= it
->continuation_lines_width
;
15216 row
->displays_text_p
= 1;
15217 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
15218 it
->starts_in_middle_of_char_p
= 0;
15220 /* Arrange the overlays nicely for our purposes. Usually, we call
15221 display_line on only one line at a time, in which case this
15222 can't really hurt too much, or we call it on lines which appear
15223 one after another in the buffer, in which case all calls to
15224 recenter_overlay_lists but the first will be pretty cheap. */
15225 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
15227 /* Move over display elements that are not visible because we are
15228 hscrolled. This may stop at an x-position < IT->first_visible_x
15229 if the first glyph is partially visible or if we hit a line end. */
15230 if (it
->current_x
< it
->first_visible_x
)
15232 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
15233 MOVE_TO_POS
| MOVE_TO_X
);
15236 /* Get the initial row height. This is either the height of the
15237 text hscrolled, if there is any, or zero. */
15238 row
->ascent
= it
->max_ascent
;
15239 row
->height
= it
->max_ascent
+ it
->max_descent
;
15240 row
->phys_ascent
= it
->max_phys_ascent
;
15241 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15242 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15244 /* Loop generating characters. The loop is left with IT on the next
15245 character to display. */
15248 int n_glyphs_before
, hpos_before
, x_before
;
15250 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
15252 /* Retrieve the next thing to display. Value is zero if end of
15254 if (!get_next_display_element (it
))
15256 /* Maybe add a space at the end of this line that is used to
15257 display the cursor there under X. Set the charpos of the
15258 first glyph of blank lines not corresponding to any text
15260 #ifdef HAVE_WINDOW_SYSTEM
15261 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15262 row
->exact_window_width_line_p
= 1;
15264 #endif /* HAVE_WINDOW_SYSTEM */
15265 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
15266 || row
->used
[TEXT_AREA
] == 0)
15268 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
15269 row
->displays_text_p
= 0;
15271 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
15272 && (!MINI_WINDOW_P (it
->w
)
15273 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
15274 row
->indicate_empty_line_p
= 1;
15277 it
->continuation_lines_width
= 0;
15278 row
->ends_at_zv_p
= 1;
15282 /* Now, get the metrics of what we want to display. This also
15283 generates glyphs in `row' (which is IT->glyph_row). */
15284 n_glyphs_before
= row
->used
[TEXT_AREA
];
15287 /* Remember the line height so far in case the next element doesn't
15288 fit on the line. */
15289 if (!it
->truncate_lines_p
)
15291 ascent
= it
->max_ascent
;
15292 descent
= it
->max_descent
;
15293 phys_ascent
= it
->max_phys_ascent
;
15294 phys_descent
= it
->max_phys_descent
;
15297 PRODUCE_GLYPHS (it
);
15299 /* If this display element was in marginal areas, continue with
15301 if (it
->area
!= TEXT_AREA
)
15303 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15304 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15305 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15306 row
->phys_height
= max (row
->phys_height
,
15307 it
->max_phys_ascent
+ it
->max_phys_descent
);
15308 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15309 it
->max_extra_line_spacing
);
15310 set_iterator_to_next (it
, 1);
15314 /* Does the display element fit on the line? If we truncate
15315 lines, we should draw past the right edge of the window. If
15316 we don't truncate, we want to stop so that we can display the
15317 continuation glyph before the right margin. If lines are
15318 continued, there are two possible strategies for characters
15319 resulting in more than 1 glyph (e.g. tabs): Display as many
15320 glyphs as possible in this line and leave the rest for the
15321 continuation line, or display the whole element in the next
15322 line. Original redisplay did the former, so we do it also. */
15323 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
15324 hpos_before
= it
->hpos
;
15327 if (/* Not a newline. */
15329 /* Glyphs produced fit entirely in the line. */
15330 && it
->current_x
< it
->last_visible_x
)
15332 it
->hpos
+= nglyphs
;
15333 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15334 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15335 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15336 row
->phys_height
= max (row
->phys_height
,
15337 it
->max_phys_ascent
+ it
->max_phys_descent
);
15338 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15339 it
->max_extra_line_spacing
);
15340 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
15341 row
->x
= x
- it
->first_visible_x
;
15346 struct glyph
*glyph
;
15348 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
15350 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15351 new_x
= x
+ glyph
->pixel_width
;
15353 if (/* Lines are continued. */
15354 !it
->truncate_lines_p
15355 && (/* Glyph doesn't fit on the line. */
15356 new_x
> it
->last_visible_x
15357 /* Or it fits exactly on a window system frame. */
15358 || (new_x
== it
->last_visible_x
15359 && FRAME_WINDOW_P (it
->f
))))
15361 /* End of a continued line. */
15364 || (new_x
== it
->last_visible_x
15365 && FRAME_WINDOW_P (it
->f
)))
15367 /* Current glyph is the only one on the line or
15368 fits exactly on the line. We must continue
15369 the line because we can't draw the cursor
15370 after the glyph. */
15371 row
->continued_p
= 1;
15372 it
->current_x
= new_x
;
15373 it
->continuation_lines_width
+= new_x
;
15375 if (i
== nglyphs
- 1)
15377 set_iterator_to_next (it
, 1);
15378 #ifdef HAVE_WINDOW_SYSTEM
15379 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15381 if (!get_next_display_element (it
))
15383 row
->exact_window_width_line_p
= 1;
15384 it
->continuation_lines_width
= 0;
15385 row
->continued_p
= 0;
15386 row
->ends_at_zv_p
= 1;
15388 else if (ITERATOR_AT_END_OF_LINE_P (it
))
15390 row
->continued_p
= 0;
15391 row
->exact_window_width_line_p
= 1;
15394 #endif /* HAVE_WINDOW_SYSTEM */
15397 else if (CHAR_GLYPH_PADDING_P (*glyph
)
15398 && !FRAME_WINDOW_P (it
->f
))
15400 /* A padding glyph that doesn't fit on this line.
15401 This means the whole character doesn't fit
15403 row
->used
[TEXT_AREA
] = n_glyphs_before
;
15405 /* Fill the rest of the row with continuation
15406 glyphs like in 20.x. */
15407 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
15408 < row
->glyphs
[1 + TEXT_AREA
])
15409 produce_special_glyphs (it
, IT_CONTINUATION
);
15411 row
->continued_p
= 1;
15412 it
->current_x
= x_before
;
15413 it
->continuation_lines_width
+= x_before
;
15415 /* Restore the height to what it was before the
15416 element not fitting on the line. */
15417 it
->max_ascent
= ascent
;
15418 it
->max_descent
= descent
;
15419 it
->max_phys_ascent
= phys_ascent
;
15420 it
->max_phys_descent
= phys_descent
;
15422 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
15424 /* A TAB that extends past the right edge of the
15425 window. This produces a single glyph on
15426 window system frames. We leave the glyph in
15427 this row and let it fill the row, but don't
15428 consume the TAB. */
15429 it
->continuation_lines_width
+= it
->last_visible_x
;
15430 row
->ends_in_middle_of_char_p
= 1;
15431 row
->continued_p
= 1;
15432 glyph
->pixel_width
= it
->last_visible_x
- x
;
15433 it
->starts_in_middle_of_char_p
= 1;
15437 /* Something other than a TAB that draws past
15438 the right edge of the window. Restore
15439 positions to values before the element. */
15440 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15442 /* Display continuation glyphs. */
15443 if (!FRAME_WINDOW_P (it
->f
))
15444 produce_special_glyphs (it
, IT_CONTINUATION
);
15445 row
->continued_p
= 1;
15447 it
->continuation_lines_width
+= x
;
15449 if (nglyphs
> 1 && i
> 0)
15451 row
->ends_in_middle_of_char_p
= 1;
15452 it
->starts_in_middle_of_char_p
= 1;
15455 /* Restore the height to what it was before the
15456 element not fitting on the line. */
15457 it
->max_ascent
= ascent
;
15458 it
->max_descent
= descent
;
15459 it
->max_phys_ascent
= phys_ascent
;
15460 it
->max_phys_descent
= phys_descent
;
15465 else if (new_x
> it
->first_visible_x
)
15467 /* Increment number of glyphs actually displayed. */
15470 if (x
< it
->first_visible_x
)
15471 /* Glyph is partially visible, i.e. row starts at
15472 negative X position. */
15473 row
->x
= x
- it
->first_visible_x
;
15477 /* Glyph is completely off the left margin of the
15478 window. This should not happen because of the
15479 move_it_in_display_line at the start of this
15480 function, unless the text display area of the
15481 window is empty. */
15482 xassert (it
->first_visible_x
<= it
->last_visible_x
);
15486 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15487 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15488 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15489 row
->phys_height
= max (row
->phys_height
,
15490 it
->max_phys_ascent
+ it
->max_phys_descent
);
15491 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15492 it
->max_extra_line_spacing
);
15494 /* End of this display line if row is continued. */
15495 if (row
->continued_p
|| row
->ends_at_zv_p
)
15500 /* Is this a line end? If yes, we're also done, after making
15501 sure that a non-default face is extended up to the right
15502 margin of the window. */
15503 if (ITERATOR_AT_END_OF_LINE_P (it
))
15505 int used_before
= row
->used
[TEXT_AREA
];
15507 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
15509 #ifdef HAVE_WINDOW_SYSTEM
15510 /* Add a space at the end of the line that is used to
15511 display the cursor there. */
15512 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15513 append_space_for_newline (it
, 0);
15514 #endif /* HAVE_WINDOW_SYSTEM */
15516 /* Extend the face to the end of the line. */
15517 extend_face_to_end_of_line (it
);
15519 /* Make sure we have the position. */
15520 if (used_before
== 0)
15521 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
15523 /* Consume the line end. This skips over invisible lines. */
15524 set_iterator_to_next (it
, 1);
15525 it
->continuation_lines_width
= 0;
15529 /* Proceed with next display element. Note that this skips
15530 over lines invisible because of selective display. */
15531 set_iterator_to_next (it
, 1);
15533 /* If we truncate lines, we are done when the last displayed
15534 glyphs reach past the right margin of the window. */
15535 if (it
->truncate_lines_p
15536 && (FRAME_WINDOW_P (it
->f
)
15537 ? (it
->current_x
>= it
->last_visible_x
)
15538 : (it
->current_x
> it
->last_visible_x
)))
15540 /* Maybe add truncation glyphs. */
15541 if (!FRAME_WINDOW_P (it
->f
))
15545 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15546 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15549 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15551 row
->used
[TEXT_AREA
] = i
;
15552 produce_special_glyphs (it
, IT_TRUNCATION
);
15555 #ifdef HAVE_WINDOW_SYSTEM
15558 /* Don't truncate if we can overflow newline into fringe. */
15559 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15561 if (!get_next_display_element (it
))
15563 it
->continuation_lines_width
= 0;
15564 row
->ends_at_zv_p
= 1;
15565 row
->exact_window_width_line_p
= 1;
15568 if (ITERATOR_AT_END_OF_LINE_P (it
))
15570 row
->exact_window_width_line_p
= 1;
15571 goto at_end_of_line
;
15575 #endif /* HAVE_WINDOW_SYSTEM */
15577 row
->truncated_on_right_p
= 1;
15578 it
->continuation_lines_width
= 0;
15579 reseat_at_next_visible_line_start (it
, 0);
15580 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
15581 it
->hpos
= hpos_before
;
15582 it
->current_x
= x_before
;
15587 /* If line is not empty and hscrolled, maybe insert truncation glyphs
15588 at the left window margin. */
15589 if (it
->first_visible_x
15590 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
15592 if (!FRAME_WINDOW_P (it
->f
))
15593 insert_left_trunc_glyphs (it
);
15594 row
->truncated_on_left_p
= 1;
15597 /* If the start of this line is the overlay arrow-position, then
15598 mark this glyph row as the one containing the overlay arrow.
15599 This is clearly a mess with variable size fonts. It would be
15600 better to let it be displayed like cursors under X. */
15601 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
15602 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
15603 !NILP (overlay_arrow_string
)))
15605 /* Overlay arrow in window redisplay is a fringe bitmap. */
15606 if (STRINGP (overlay_arrow_string
))
15608 struct glyph_row
*arrow_row
15609 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
15610 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
15611 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
15612 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
15613 struct glyph
*p2
, *end
;
15615 /* Copy the arrow glyphs. */
15616 while (glyph
< arrow_end
)
15619 /* Throw away padding glyphs. */
15621 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15622 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
15628 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
15633 xassert (INTEGERP (overlay_arrow_string
));
15634 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
15636 overlay_arrow_seen
= 1;
15639 /* Compute pixel dimensions of this line. */
15640 compute_line_metrics (it
);
15642 /* Remember the position at which this line ends. */
15643 row
->end
= it
->current
;
15645 /* Record whether this row ends inside an ellipsis. */
15646 row
->ends_in_ellipsis_p
15647 = (it
->method
== GET_FROM_DISPLAY_VECTOR
15648 && it
->ellipsis_p
);
15650 /* Save fringe bitmaps in this row. */
15651 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
15652 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
15653 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
15654 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
15656 it
->left_user_fringe_bitmap
= 0;
15657 it
->left_user_fringe_face_id
= 0;
15658 it
->right_user_fringe_bitmap
= 0;
15659 it
->right_user_fringe_face_id
= 0;
15661 /* Maybe set the cursor. */
15662 if (it
->w
->cursor
.vpos
< 0
15663 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
15664 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15665 && cursor_row_p (it
->w
, row
))
15666 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
15668 /* Highlight trailing whitespace. */
15669 if (!NILP (Vshow_trailing_whitespace
))
15670 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
15672 /* Prepare for the next line. This line starts horizontally at (X
15673 HPOS) = (0 0). Vertical positions are incremented. As a
15674 convenience for the caller, IT->glyph_row is set to the next
15676 it
->current_x
= it
->hpos
= 0;
15677 it
->current_y
+= row
->height
;
15680 it
->start
= it
->current
;
15681 return row
->displays_text_p
;
15686 /***********************************************************************
15688 ***********************************************************************/
15690 /* Redisplay the menu bar in the frame for window W.
15692 The menu bar of X frames that don't have X toolkit support is
15693 displayed in a special window W->frame->menu_bar_window.
15695 The menu bar of terminal frames is treated specially as far as
15696 glyph matrices are concerned. Menu bar lines are not part of
15697 windows, so the update is done directly on the frame matrix rows
15698 for the menu bar. */
15701 display_menu_bar (w
)
15704 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15709 /* Don't do all this for graphical frames. */
15711 if (!NILP (Vwindow_system
))
15714 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
15719 if (FRAME_MAC_P (f
))
15723 #ifdef USE_X_TOOLKIT
15724 xassert (!FRAME_WINDOW_P (f
));
15725 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
15726 it
.first_visible_x
= 0;
15727 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15728 #else /* not USE_X_TOOLKIT */
15729 if (FRAME_WINDOW_P (f
))
15731 /* Menu bar lines are displayed in the desired matrix of the
15732 dummy window menu_bar_window. */
15733 struct window
*menu_w
;
15734 xassert (WINDOWP (f
->menu_bar_window
));
15735 menu_w
= XWINDOW (f
->menu_bar_window
);
15736 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
15738 it
.first_visible_x
= 0;
15739 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15743 /* This is a TTY frame, i.e. character hpos/vpos are used as
15745 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
15747 it
.first_visible_x
= 0;
15748 it
.last_visible_x
= FRAME_COLS (f
);
15750 #endif /* not USE_X_TOOLKIT */
15752 if (! mode_line_inverse_video
)
15753 /* Force the menu-bar to be displayed in the default face. */
15754 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15756 /* Clear all rows of the menu bar. */
15757 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
15759 struct glyph_row
*row
= it
.glyph_row
+ i
;
15760 clear_glyph_row (row
);
15761 row
->enabled_p
= 1;
15762 row
->full_width_p
= 1;
15765 /* Display all items of the menu bar. */
15766 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
15767 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
15769 Lisp_Object string
;
15771 /* Stop at nil string. */
15772 string
= AREF (items
, i
+ 1);
15776 /* Remember where item was displayed. */
15777 AREF (items
, i
+ 3) = make_number (it
.hpos
);
15779 /* Display the item, pad with one space. */
15780 if (it
.current_x
< it
.last_visible_x
)
15781 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
15782 SCHARS (string
) + 1, 0, 0, -1);
15785 /* Fill out the line with spaces. */
15786 if (it
.current_x
< it
.last_visible_x
)
15787 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
15789 /* Compute the total height of the lines. */
15790 compute_line_metrics (&it
);
15795 /***********************************************************************
15797 ***********************************************************************/
15799 /* Redisplay mode lines in the window tree whose root is WINDOW. If
15800 FORCE is non-zero, redisplay mode lines unconditionally.
15801 Otherwise, redisplay only mode lines that are garbaged. Value is
15802 the number of windows whose mode lines were redisplayed. */
15805 redisplay_mode_lines (window
, force
)
15806 Lisp_Object window
;
15811 while (!NILP (window
))
15813 struct window
*w
= XWINDOW (window
);
15815 if (WINDOWP (w
->hchild
))
15816 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
15817 else if (WINDOWP (w
->vchild
))
15818 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
15820 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
15821 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
15823 struct text_pos lpoint
;
15824 struct buffer
*old
= current_buffer
;
15826 /* Set the window's buffer for the mode line display. */
15827 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15828 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15830 /* Point refers normally to the selected window. For any
15831 other window, set up appropriate value. */
15832 if (!EQ (window
, selected_window
))
15834 struct text_pos pt
;
15836 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
15837 if (CHARPOS (pt
) < BEGV
)
15838 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15839 else if (CHARPOS (pt
) > (ZV
- 1))
15840 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
15842 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
15845 /* Display mode lines. */
15846 clear_glyph_matrix (w
->desired_matrix
);
15847 if (display_mode_lines (w
))
15850 w
->must_be_updated_p
= 1;
15853 /* Restore old settings. */
15854 set_buffer_internal_1 (old
);
15855 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15865 /* Display the mode and/or top line of window W. Value is the number
15866 of mode lines displayed. */
15869 display_mode_lines (w
)
15872 Lisp_Object old_selected_window
, old_selected_frame
;
15875 old_selected_frame
= selected_frame
;
15876 selected_frame
= w
->frame
;
15877 old_selected_window
= selected_window
;
15878 XSETWINDOW (selected_window
, w
);
15880 /* These will be set while the mode line specs are processed. */
15881 line_number_displayed
= 0;
15882 w
->column_number_displayed
= Qnil
;
15884 if (WINDOW_WANTS_MODELINE_P (w
))
15886 struct window
*sel_w
= XWINDOW (old_selected_window
);
15888 /* Select mode line face based on the real selected window. */
15889 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
15890 current_buffer
->mode_line_format
);
15894 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15896 display_mode_line (w
, HEADER_LINE_FACE_ID
,
15897 current_buffer
->header_line_format
);
15901 selected_frame
= old_selected_frame
;
15902 selected_window
= old_selected_window
;
15907 /* Display mode or top line of window W. FACE_ID specifies which line
15908 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
15909 FORMAT is the mode line format to display. Value is the pixel
15910 height of the mode line displayed. */
15913 display_mode_line (w
, face_id
, format
)
15915 enum face_id face_id
;
15916 Lisp_Object format
;
15920 int count
= SPECPDL_INDEX ();
15922 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15923 prepare_desired_row (it
.glyph_row
);
15925 it
.glyph_row
->mode_line_p
= 1;
15927 if (! mode_line_inverse_video
)
15928 /* Force the mode-line to be displayed in the default face. */
15929 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15931 record_unwind_protect (unwind_format_mode_line
,
15932 format_mode_line_unwind_data (NULL
));
15934 mode_line_target
= MODE_LINE_DISPLAY
;
15936 /* Temporarily make frame's keyboard the current kboard so that
15937 kboard-local variables in the mode_line_format will get the right
15939 push_frame_kboard (it
.f
);
15940 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15941 pop_frame_kboard ();
15943 unbind_to (count
, Qnil
);
15945 /* Fill up with spaces. */
15946 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
15948 compute_line_metrics (&it
);
15949 it
.glyph_row
->full_width_p
= 1;
15950 it
.glyph_row
->continued_p
= 0;
15951 it
.glyph_row
->truncated_on_left_p
= 0;
15952 it
.glyph_row
->truncated_on_right_p
= 0;
15954 /* Make a 3D mode-line have a shadow at its right end. */
15955 face
= FACE_FROM_ID (it
.f
, face_id
);
15956 extend_face_to_end_of_line (&it
);
15957 if (face
->box
!= FACE_NO_BOX
)
15959 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
15960 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
15961 last
->right_box_line_p
= 1;
15964 return it
.glyph_row
->height
;
15967 /* Contribute ELT to the mode line for window IT->w. How it
15968 translates into text depends on its data type.
15970 IT describes the display environment in which we display, as usual.
15972 DEPTH is the depth in recursion. It is used to prevent
15973 infinite recursion here.
15975 FIELD_WIDTH is the number of characters the display of ELT should
15976 occupy in the mode line, and PRECISION is the maximum number of
15977 characters to display from ELT's representation. See
15978 display_string for details.
15980 Returns the hpos of the end of the text generated by ELT.
15982 PROPS is a property list to add to any string we encounter.
15984 If RISKY is nonzero, remove (disregard) any properties in any string
15985 we encounter, and ignore :eval and :propertize.
15987 The global variable `mode_line_target' determines whether the
15988 output is passed to `store_mode_line_noprop',
15989 `store_mode_line_string', or `display_string'. */
15992 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
15995 int field_width
, precision
;
15996 Lisp_Object elt
, props
;
15999 int n
= 0, field
, prec
;
16004 elt
= build_string ("*too-deep*");
16008 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
16012 /* A string: output it and check for %-constructs within it. */
16014 const unsigned char *this, *lisp_string
;
16016 if (!NILP (props
) || risky
)
16018 Lisp_Object oprops
, aelt
;
16019 oprops
= Ftext_properties_at (make_number (0), elt
);
16021 /* If the starting string's properties are not what
16022 we want, translate the string. Also, if the string
16023 is risky, do that anyway. */
16025 if (NILP (Fequal (props
, oprops
)) || risky
)
16027 /* If the starting string has properties,
16028 merge the specified ones onto the existing ones. */
16029 if (! NILP (oprops
) && !risky
)
16033 oprops
= Fcopy_sequence (oprops
);
16035 while (CONSP (tem
))
16037 oprops
= Fplist_put (oprops
, XCAR (tem
),
16038 XCAR (XCDR (tem
)));
16039 tem
= XCDR (XCDR (tem
));
16044 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
16045 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
16047 mode_line_proptrans_alist
16048 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
16055 elt
= Fcopy_sequence (elt
);
16056 Fset_text_properties (make_number (0), Flength (elt
),
16058 /* Add this item to mode_line_proptrans_alist. */
16059 mode_line_proptrans_alist
16060 = Fcons (Fcons (elt
, props
),
16061 mode_line_proptrans_alist
);
16062 /* Truncate mode_line_proptrans_alist
16063 to at most 50 elements. */
16064 tem
= Fnthcdr (make_number (50),
16065 mode_line_proptrans_alist
);
16067 XSETCDR (tem
, Qnil
);
16072 this = SDATA (elt
);
16073 lisp_string
= this;
16077 prec
= precision
- n
;
16078 switch (mode_line_target
)
16080 case MODE_LINE_NOPROP
:
16081 case MODE_LINE_TITLE
:
16082 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
16084 case MODE_LINE_STRING
:
16085 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
16087 case MODE_LINE_DISPLAY
:
16088 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
16089 0, prec
, 0, STRING_MULTIBYTE (elt
));
16096 while ((precision
<= 0 || n
< precision
)
16098 && (mode_line_target
!= MODE_LINE_DISPLAY
16099 || it
->current_x
< it
->last_visible_x
))
16101 const unsigned char *last
= this;
16103 /* Advance to end of string or next format specifier. */
16104 while ((c
= *this++) != '\0' && c
!= '%')
16107 if (this - 1 != last
)
16109 int nchars
, nbytes
;
16111 /* Output to end of string or up to '%'. Field width
16112 is length of string. Don't output more than
16113 PRECISION allows us. */
16116 prec
= c_string_width (last
, this - last
, precision
- n
,
16119 switch (mode_line_target
)
16121 case MODE_LINE_NOPROP
:
16122 case MODE_LINE_TITLE
:
16123 n
+= store_mode_line_noprop (last
, 0, prec
);
16125 case MODE_LINE_STRING
:
16127 int bytepos
= last
- lisp_string
;
16128 int charpos
= string_byte_to_char (elt
, bytepos
);
16129 int endpos
= (precision
<= 0
16130 ? string_byte_to_char (elt
,
16131 this - lisp_string
)
16132 : charpos
+ nchars
);
16134 n
+= store_mode_line_string (NULL
,
16135 Fsubstring (elt
, make_number (charpos
),
16136 make_number (endpos
)),
16140 case MODE_LINE_DISPLAY
:
16142 int bytepos
= last
- lisp_string
;
16143 int charpos
= string_byte_to_char (elt
, bytepos
);
16144 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
16146 STRING_MULTIBYTE (elt
));
16151 else /* c == '%' */
16153 const unsigned char *percent_position
= this;
16155 /* Get the specified minimum width. Zero means
16158 while ((c
= *this++) >= '0' && c
<= '9')
16159 field
= field
* 10 + c
- '0';
16161 /* Don't pad beyond the total padding allowed. */
16162 if (field_width
- n
> 0 && field
> field_width
- n
)
16163 field
= field_width
- n
;
16165 /* Note that either PRECISION <= 0 or N < PRECISION. */
16166 prec
= precision
- n
;
16169 n
+= display_mode_element (it
, depth
, field
, prec
,
16170 Vglobal_mode_string
, props
,
16175 int bytepos
, charpos
;
16176 unsigned char *spec
;
16178 bytepos
= percent_position
- lisp_string
;
16179 charpos
= (STRING_MULTIBYTE (elt
)
16180 ? string_byte_to_char (elt
, bytepos
)
16184 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
16186 switch (mode_line_target
)
16188 case MODE_LINE_NOPROP
:
16189 case MODE_LINE_TITLE
:
16190 n
+= store_mode_line_noprop (spec
, field
, prec
);
16192 case MODE_LINE_STRING
:
16194 int len
= strlen (spec
);
16195 Lisp_Object tem
= make_string (spec
, len
);
16196 props
= Ftext_properties_at (make_number (charpos
), elt
);
16197 /* Should only keep face property in props */
16198 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
16201 case MODE_LINE_DISPLAY
:
16203 int nglyphs_before
, nwritten
;
16205 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16206 nwritten
= display_string (spec
, Qnil
, elt
,
16211 /* Assign to the glyphs written above the
16212 string where the `%x' came from, position
16216 struct glyph
*glyph
16217 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
16221 for (i
= 0; i
< nwritten
; ++i
)
16223 glyph
[i
].object
= elt
;
16224 glyph
[i
].charpos
= charpos
;
16241 /* A symbol: process the value of the symbol recursively
16242 as if it appeared here directly. Avoid error if symbol void.
16243 Special case: if value of symbol is a string, output the string
16246 register Lisp_Object tem
;
16248 /* If the variable is not marked as risky to set
16249 then its contents are risky to use. */
16250 if (NILP (Fget (elt
, Qrisky_local_variable
)))
16253 tem
= Fboundp (elt
);
16256 tem
= Fsymbol_value (elt
);
16257 /* If value is a string, output that string literally:
16258 don't check for % within it. */
16262 if (!EQ (tem
, elt
))
16264 /* Give up right away for nil or t. */
16274 register Lisp_Object car
, tem
;
16276 /* A cons cell: five distinct cases.
16277 If first element is :eval or :propertize, do something special.
16278 If first element is a string or a cons, process all the elements
16279 and effectively concatenate them.
16280 If first element is a negative number, truncate displaying cdr to
16281 at most that many characters. If positive, pad (with spaces)
16282 to at least that many characters.
16283 If first element is a symbol, process the cadr or caddr recursively
16284 according to whether the symbol's value is non-nil or nil. */
16286 if (EQ (car
, QCeval
))
16288 /* An element of the form (:eval FORM) means evaluate FORM
16289 and use the result as mode line elements. */
16294 if (CONSP (XCDR (elt
)))
16297 spec
= safe_eval (XCAR (XCDR (elt
)));
16298 n
+= display_mode_element (it
, depth
, field_width
- n
,
16299 precision
- n
, spec
, props
,
16303 else if (EQ (car
, QCpropertize
))
16305 /* An element of the form (:propertize ELT PROPS...)
16306 means display ELT but applying properties PROPS. */
16311 if (CONSP (XCDR (elt
)))
16312 n
+= display_mode_element (it
, depth
, field_width
- n
,
16313 precision
- n
, XCAR (XCDR (elt
)),
16314 XCDR (XCDR (elt
)), risky
);
16316 else if (SYMBOLP (car
))
16318 tem
= Fboundp (car
);
16322 /* elt is now the cdr, and we know it is a cons cell.
16323 Use its car if CAR has a non-nil value. */
16326 tem
= Fsymbol_value (car
);
16333 /* Symbol's value is nil (or symbol is unbound)
16334 Get the cddr of the original list
16335 and if possible find the caddr and use that. */
16339 else if (!CONSP (elt
))
16344 else if (INTEGERP (car
))
16346 register int lim
= XINT (car
);
16350 /* Negative int means reduce maximum width. */
16351 if (precision
<= 0)
16354 precision
= min (precision
, -lim
);
16358 /* Padding specified. Don't let it be more than
16359 current maximum. */
16361 lim
= min (precision
, lim
);
16363 /* If that's more padding than already wanted, queue it.
16364 But don't reduce padding already specified even if
16365 that is beyond the current truncation point. */
16366 field_width
= max (lim
, field_width
);
16370 else if (STRINGP (car
) || CONSP (car
))
16372 register int limit
= 50;
16373 /* Limit is to protect against circular lists. */
16376 && (precision
<= 0 || n
< precision
))
16378 n
+= display_mode_element (it
, depth
,
16379 /* Do padding only after the last
16380 element in the list. */
16381 (! CONSP (XCDR (elt
))
16384 precision
- n
, XCAR (elt
),
16394 elt
= build_string ("*invalid*");
16398 /* Pad to FIELD_WIDTH. */
16399 if (field_width
> 0 && n
< field_width
)
16401 switch (mode_line_target
)
16403 case MODE_LINE_NOPROP
:
16404 case MODE_LINE_TITLE
:
16405 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
16407 case MODE_LINE_STRING
:
16408 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
16410 case MODE_LINE_DISPLAY
:
16411 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
16420 /* Store a mode-line string element in mode_line_string_list.
16422 If STRING is non-null, display that C string. Otherwise, the Lisp
16423 string LISP_STRING is displayed.
16425 FIELD_WIDTH is the minimum number of output glyphs to produce.
16426 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16427 with spaces. FIELD_WIDTH <= 0 means don't pad.
16429 PRECISION is the maximum number of characters to output from
16430 STRING. PRECISION <= 0 means don't truncate the string.
16432 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
16433 properties to the string.
16435 PROPS are the properties to add to the string.
16436 The mode_line_string_face face property is always added to the string.
16440 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
16442 Lisp_Object lisp_string
;
16451 if (string
!= NULL
)
16453 len
= strlen (string
);
16454 if (precision
> 0 && len
> precision
)
16456 lisp_string
= make_string (string
, len
);
16458 props
= mode_line_string_face_prop
;
16459 else if (!NILP (mode_line_string_face
))
16461 Lisp_Object face
= Fplist_get (props
, Qface
);
16462 props
= Fcopy_sequence (props
);
16464 face
= mode_line_string_face
;
16466 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16467 props
= Fplist_put (props
, Qface
, face
);
16469 Fadd_text_properties (make_number (0), make_number (len
),
16470 props
, lisp_string
);
16474 len
= XFASTINT (Flength (lisp_string
));
16475 if (precision
> 0 && len
> precision
)
16478 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
16481 if (!NILP (mode_line_string_face
))
16485 props
= Ftext_properties_at (make_number (0), lisp_string
);
16486 face
= Fplist_get (props
, Qface
);
16488 face
= mode_line_string_face
;
16490 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16491 props
= Fcons (Qface
, Fcons (face
, Qnil
));
16493 lisp_string
= Fcopy_sequence (lisp_string
);
16496 Fadd_text_properties (make_number (0), make_number (len
),
16497 props
, lisp_string
);
16502 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16506 if (field_width
> len
)
16508 field_width
-= len
;
16509 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
16511 Fadd_text_properties (make_number (0), make_number (field_width
),
16512 props
, lisp_string
);
16513 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16521 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
16523 doc
: /* Format a string out of a mode line format specification.
16524 First arg FORMAT specifies the mode line format (see `mode-line-format'
16525 for details) to use.
16527 Optional second arg FACE specifies the face property to put
16528 on all characters for which no face is specified.
16529 t means whatever face the window's mode line currently uses
16530 \(either `mode-line' or `mode-line-inactive', depending).
16531 nil means the default is no face property.
16532 If FACE is an integer, the value string has no text properties.
16534 Optional third and fourth args WINDOW and BUFFER specify the window
16535 and buffer to use as the context for the formatting (defaults
16536 are the selected window and the window's buffer). */)
16537 (format
, face
, window
, buffer
)
16538 Lisp_Object format
, face
, window
, buffer
;
16543 struct buffer
*old_buffer
= NULL
;
16545 int no_props
= INTEGERP (face
);
16546 int count
= SPECPDL_INDEX ();
16548 int string_start
= 0;
16551 window
= selected_window
;
16552 CHECK_WINDOW (window
);
16553 w
= XWINDOW (window
);
16556 buffer
= w
->buffer
;
16557 CHECK_BUFFER (buffer
);
16560 return build_string ("");
16568 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
16569 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
16573 face_id
= DEFAULT_FACE_ID
;
16575 if (XBUFFER (buffer
) != current_buffer
)
16576 old_buffer
= current_buffer
;
16578 record_unwind_protect (unwind_format_mode_line
,
16579 format_mode_line_unwind_data (old_buffer
));
16582 set_buffer_internal_1 (XBUFFER (buffer
));
16584 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16588 mode_line_target
= MODE_LINE_NOPROP
;
16589 mode_line_string_face_prop
= Qnil
;
16590 mode_line_string_list
= Qnil
;
16591 string_start
= MODE_LINE_NOPROP_LEN (0);
16595 mode_line_target
= MODE_LINE_STRING
;
16596 mode_line_string_list
= Qnil
;
16597 mode_line_string_face
= face
;
16598 mode_line_string_face_prop
16599 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
16602 push_frame_kboard (it
.f
);
16603 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16604 pop_frame_kboard ();
16608 len
= MODE_LINE_NOPROP_LEN (string_start
);
16609 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
16613 mode_line_string_list
= Fnreverse (mode_line_string_list
);
16614 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
16615 make_string ("", 0));
16618 unbind_to (count
, Qnil
);
16622 /* Write a null-terminated, right justified decimal representation of
16623 the positive integer D to BUF using a minimal field width WIDTH. */
16626 pint2str (buf
, width
, d
)
16627 register char *buf
;
16628 register int width
;
16631 register char *p
= buf
;
16639 *p
++ = d
% 10 + '0';
16644 for (width
-= (int) (p
- buf
); width
> 0; --width
)
16655 /* Write a null-terminated, right justified decimal and "human
16656 readable" representation of the nonnegative integer D to BUF using
16657 a minimal field width WIDTH. D should be smaller than 999.5e24. */
16659 static const char power_letter
[] =
16673 pint2hrstr (buf
, width
, d
)
16678 /* We aim to represent the nonnegative integer D as
16679 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
16682 /* -1 means: do not use TENTHS. */
16686 /* Length of QUOTIENT.TENTHS as a string. */
16692 if (1000 <= quotient
)
16694 /* Scale to the appropriate EXPONENT. */
16697 remainder
= quotient
% 1000;
16701 while (1000 <= quotient
);
16703 /* Round to nearest and decide whether to use TENTHS or not. */
16706 tenths
= remainder
/ 100;
16707 if (50 <= remainder
% 100)
16714 if (quotient
== 10)
16722 if (500 <= remainder
)
16724 if (quotient
< 999)
16735 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
16736 if (tenths
== -1 && quotient
<= 99)
16743 p
= psuffix
= buf
+ max (width
, length
);
16745 /* Print EXPONENT. */
16747 *psuffix
++ = power_letter
[exponent
];
16750 /* Print TENTHS. */
16753 *--p
= '0' + tenths
;
16757 /* Print QUOTIENT. */
16760 int digit
= quotient
% 10;
16761 *--p
= '0' + digit
;
16763 while ((quotient
/= 10) != 0);
16765 /* Print leading spaces. */
16770 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
16771 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
16772 type of CODING_SYSTEM. Return updated pointer into BUF. */
16774 static unsigned char invalid_eol_type
[] = "(*invalid*)";
16777 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
16778 Lisp_Object coding_system
;
16779 register char *buf
;
16783 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
16784 const unsigned char *eol_str
;
16786 /* The EOL conversion we are using. */
16787 Lisp_Object eoltype
;
16789 val
= CODING_SYSTEM_SPEC (coding_system
);
16792 if (!VECTORP (val
)) /* Not yet decided. */
16797 eoltype
= eol_mnemonic_undecided
;
16798 /* Don't mention EOL conversion if it isn't decided. */
16803 Lisp_Object eolvalue
;
16805 attrs
= AREF (val
, 0);
16806 eolvalue
= AREF (val
, 2);
16809 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
16813 /* The EOL conversion that is normal on this system. */
16815 if (NILP (eolvalue
)) /* Not yet decided. */
16816 eoltype
= eol_mnemonic_undecided
;
16817 else if (VECTORP (eolvalue
)) /* Not yet decided. */
16818 eoltype
= eol_mnemonic_undecided
;
16819 else /* eolvalue is Qunix, Qdos, or Qmac. */
16820 eoltype
= (EQ (eolvalue
, Qunix
)
16821 ? eol_mnemonic_unix
16822 : (EQ (eolvalue
, Qdos
) == 1
16823 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
16829 /* Mention the EOL conversion if it is not the usual one. */
16830 if (STRINGP (eoltype
))
16832 eol_str
= SDATA (eoltype
);
16833 eol_str_len
= SBYTES (eoltype
);
16835 else if (CHARACTERP (eoltype
))
16837 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
16838 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
16843 eol_str
= invalid_eol_type
;
16844 eol_str_len
= sizeof (invalid_eol_type
) - 1;
16846 bcopy (eol_str
, buf
, eol_str_len
);
16847 buf
+= eol_str_len
;
16853 /* Return a string for the output of a mode line %-spec for window W,
16854 generated by character C. PRECISION >= 0 means don't return a
16855 string longer than that value. FIELD_WIDTH > 0 means pad the
16856 string returned with spaces to that value. Return 1 in *MULTIBYTE
16857 if the result is multibyte text.
16859 Note we operate on the current buffer for most purposes,
16860 the exception being w->base_line_pos. */
16862 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
16865 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
16868 int field_width
, precision
;
16872 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16873 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
16874 struct buffer
*b
= current_buffer
;
16882 if (!NILP (b
->read_only
))
16884 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16889 /* This differs from %* only for a modified read-only buffer. */
16890 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16892 if (!NILP (b
->read_only
))
16897 /* This differs from %* in ignoring read-only-ness. */
16898 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16910 if (command_loop_level
> 5)
16912 p
= decode_mode_spec_buf
;
16913 for (i
= 0; i
< command_loop_level
; i
++)
16916 return decode_mode_spec_buf
;
16924 if (command_loop_level
> 5)
16926 p
= decode_mode_spec_buf
;
16927 for (i
= 0; i
< command_loop_level
; i
++)
16930 return decode_mode_spec_buf
;
16937 /* Let lots_of_dashes be a string of infinite length. */
16938 if (mode_line_target
== MODE_LINE_NOPROP
||
16939 mode_line_target
== MODE_LINE_STRING
)
16941 if (field_width
<= 0
16942 || field_width
> sizeof (lots_of_dashes
))
16944 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
16945 decode_mode_spec_buf
[i
] = '-';
16946 decode_mode_spec_buf
[i
] = '\0';
16947 return decode_mode_spec_buf
;
16950 return lots_of_dashes
;
16959 int col
= (int) current_column (); /* iftc */
16960 w
->column_number_displayed
= make_number (col
);
16961 pint2str (decode_mode_spec_buf
, field_width
, col
);
16962 return decode_mode_spec_buf
;
16966 /* %F displays the frame name. */
16967 if (!NILP (f
->title
))
16968 return (char *) SDATA (f
->title
);
16969 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
16970 return (char *) SDATA (f
->name
);
16979 int size
= ZV
- BEGV
;
16980 pint2str (decode_mode_spec_buf
, field_width
, size
);
16981 return decode_mode_spec_buf
;
16986 int size
= ZV
- BEGV
;
16987 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
16988 return decode_mode_spec_buf
;
16993 int startpos
= XMARKER (w
->start
)->charpos
;
16994 int startpos_byte
= marker_byte_position (w
->start
);
16995 int line
, linepos
, linepos_byte
, topline
;
16997 int height
= WINDOW_TOTAL_LINES (w
);
16999 /* If we decided that this buffer isn't suitable for line numbers,
17000 don't forget that too fast. */
17001 if (EQ (w
->base_line_pos
, w
->buffer
))
17003 /* But do forget it, if the window shows a different buffer now. */
17004 else if (BUFFERP (w
->base_line_pos
))
17005 w
->base_line_pos
= Qnil
;
17007 /* If the buffer is very big, don't waste time. */
17008 if (INTEGERP (Vline_number_display_limit
)
17009 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
17011 w
->base_line_pos
= Qnil
;
17012 w
->base_line_number
= Qnil
;
17016 if (!NILP (w
->base_line_number
)
17017 && !NILP (w
->base_line_pos
)
17018 && XFASTINT (w
->base_line_pos
) <= startpos
)
17020 line
= XFASTINT (w
->base_line_number
);
17021 linepos
= XFASTINT (w
->base_line_pos
);
17022 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
17027 linepos
= BUF_BEGV (b
);
17028 linepos_byte
= BUF_BEGV_BYTE (b
);
17031 /* Count lines from base line to window start position. */
17032 nlines
= display_count_lines (linepos
, linepos_byte
,
17036 topline
= nlines
+ line
;
17038 /* Determine a new base line, if the old one is too close
17039 or too far away, or if we did not have one.
17040 "Too close" means it's plausible a scroll-down would
17041 go back past it. */
17042 if (startpos
== BUF_BEGV (b
))
17044 w
->base_line_number
= make_number (topline
);
17045 w
->base_line_pos
= make_number (BUF_BEGV (b
));
17047 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
17048 || linepos
== BUF_BEGV (b
))
17050 int limit
= BUF_BEGV (b
);
17051 int limit_byte
= BUF_BEGV_BYTE (b
);
17053 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
17055 if (startpos
- distance
> limit
)
17057 limit
= startpos
- distance
;
17058 limit_byte
= CHAR_TO_BYTE (limit
);
17061 nlines
= display_count_lines (startpos
, startpos_byte
,
17063 - (height
* 2 + 30),
17065 /* If we couldn't find the lines we wanted within
17066 line_number_display_limit_width chars per line,
17067 give up on line numbers for this window. */
17068 if (position
== limit_byte
&& limit
== startpos
- distance
)
17070 w
->base_line_pos
= w
->buffer
;
17071 w
->base_line_number
= Qnil
;
17075 w
->base_line_number
= make_number (topline
- nlines
);
17076 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
17079 /* Now count lines from the start pos to point. */
17080 nlines
= display_count_lines (startpos
, startpos_byte
,
17081 PT_BYTE
, PT
, &junk
);
17083 /* Record that we did display the line number. */
17084 line_number_displayed
= 1;
17086 /* Make the string to show. */
17087 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
17088 return decode_mode_spec_buf
;
17091 char* p
= decode_mode_spec_buf
;
17092 int pad
= field_width
- 2;
17098 return decode_mode_spec_buf
;
17104 obj
= b
->mode_name
;
17108 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
17114 int pos
= marker_position (w
->start
);
17115 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17117 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
17119 if (pos
<= BUF_BEGV (b
))
17124 else if (pos
<= BUF_BEGV (b
))
17128 if (total
> 1000000)
17129 /* Do it differently for a large value, to avoid overflow. */
17130 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17132 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17133 /* We can't normally display a 3-digit number,
17134 so get us a 2-digit number that is close. */
17137 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17138 return decode_mode_spec_buf
;
17142 /* Display percentage of size above the bottom of the screen. */
17145 int toppos
= marker_position (w
->start
);
17146 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
17147 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17149 if (botpos
>= BUF_ZV (b
))
17151 if (toppos
<= BUF_BEGV (b
))
17158 if (total
> 1000000)
17159 /* Do it differently for a large value, to avoid overflow. */
17160 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17162 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17163 /* We can't normally display a 3-digit number,
17164 so get us a 2-digit number that is close. */
17167 if (toppos
<= BUF_BEGV (b
))
17168 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
17170 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17171 return decode_mode_spec_buf
;
17176 /* status of process */
17177 obj
= Fget_buffer_process (Fcurrent_buffer ());
17179 return "no process";
17180 #ifdef subprocesses
17181 obj
= Fsymbol_name (Fprocess_status (obj
));
17185 case 't': /* indicate TEXT or BINARY */
17186 #ifdef MODE_LINE_BINARY_TEXT
17187 return MODE_LINE_BINARY_TEXT (b
);
17193 /* coding-system (not including end-of-line format) */
17195 /* coding-system (including end-of-line type) */
17197 int eol_flag
= (c
== 'Z');
17198 char *p
= decode_mode_spec_buf
;
17200 if (! FRAME_WINDOW_P (f
))
17202 /* No need to mention EOL here--the terminal never needs
17203 to do EOL conversion. */
17204 p
= decode_mode_spec_coding (CODING_ID_NAME (keyboard_coding
.id
),
17206 p
= decode_mode_spec_coding (CODING_ID_NAME (terminal_coding
.id
),
17209 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
17212 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
17213 #ifdef subprocesses
17214 obj
= Fget_buffer_process (Fcurrent_buffer ());
17215 if (PROCESSP (obj
))
17217 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
17219 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
17222 #endif /* subprocesses */
17225 return decode_mode_spec_buf
;
17231 *multibyte
= STRING_MULTIBYTE (obj
);
17232 return (char *) SDATA (obj
);
17239 /* Count up to COUNT lines starting from START / START_BYTE.
17240 But don't go beyond LIMIT_BYTE.
17241 Return the number of lines thus found (always nonnegative).
17243 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
17246 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
17247 int start
, start_byte
, limit_byte
, count
;
17250 register unsigned char *cursor
;
17251 unsigned char *base
;
17253 register int ceiling
;
17254 register unsigned char *ceiling_addr
;
17255 int orig_count
= count
;
17257 /* If we are not in selective display mode,
17258 check only for newlines. */
17259 int selective_display
= (!NILP (current_buffer
->selective_display
)
17260 && !INTEGERP (current_buffer
->selective_display
));
17264 while (start_byte
< limit_byte
)
17266 ceiling
= BUFFER_CEILING_OF (start_byte
);
17267 ceiling
= min (limit_byte
- 1, ceiling
);
17268 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
17269 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
17272 if (selective_display
)
17273 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
17276 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
17279 if (cursor
!= ceiling_addr
)
17283 start_byte
+= cursor
- base
+ 1;
17284 *byte_pos_ptr
= start_byte
;
17288 if (++cursor
== ceiling_addr
)
17294 start_byte
+= cursor
- base
;
17299 while (start_byte
> limit_byte
)
17301 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
17302 ceiling
= max (limit_byte
, ceiling
);
17303 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
17304 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
17307 if (selective_display
)
17308 while (--cursor
!= ceiling_addr
17309 && *cursor
!= '\n' && *cursor
!= 015)
17312 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
17315 if (cursor
!= ceiling_addr
)
17319 start_byte
+= cursor
- base
+ 1;
17320 *byte_pos_ptr
= start_byte
;
17321 /* When scanning backwards, we should
17322 not count the newline posterior to which we stop. */
17323 return - orig_count
- 1;
17329 /* Here we add 1 to compensate for the last decrement
17330 of CURSOR, which took it past the valid range. */
17331 start_byte
+= cursor
- base
+ 1;
17335 *byte_pos_ptr
= limit_byte
;
17338 return - orig_count
+ count
;
17339 return orig_count
- count
;
17345 /***********************************************************************
17347 ***********************************************************************/
17349 /* Display a NUL-terminated string, starting with index START.
17351 If STRING is non-null, display that C string. Otherwise, the Lisp
17352 string LISP_STRING is displayed.
17354 If FACE_STRING is not nil, FACE_STRING_POS is a position in
17355 FACE_STRING. Display STRING or LISP_STRING with the face at
17356 FACE_STRING_POS in FACE_STRING:
17358 Display the string in the environment given by IT, but use the
17359 standard display table, temporarily.
17361 FIELD_WIDTH is the minimum number of output glyphs to produce.
17362 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17363 with spaces. If STRING has more characters, more than FIELD_WIDTH
17364 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
17366 PRECISION is the maximum number of characters to output from
17367 STRING. PRECISION < 0 means don't truncate the string.
17369 This is roughly equivalent to printf format specifiers:
17371 FIELD_WIDTH PRECISION PRINTF
17372 ----------------------------------------
17378 MULTIBYTE zero means do not display multibyte chars, > 0 means do
17379 display them, and < 0 means obey the current buffer's value of
17380 enable_multibyte_characters.
17382 Value is the number of glyphs produced. */
17385 display_string (string
, lisp_string
, face_string
, face_string_pos
,
17386 start
, it
, field_width
, precision
, max_x
, multibyte
)
17387 unsigned char *string
;
17388 Lisp_Object lisp_string
;
17389 Lisp_Object face_string
;
17390 int face_string_pos
;
17393 int field_width
, precision
, max_x
;
17396 int hpos_at_start
= it
->hpos
;
17397 int saved_face_id
= it
->face_id
;
17398 struct glyph_row
*row
= it
->glyph_row
;
17400 /* Initialize the iterator IT for iteration over STRING beginning
17401 with index START. */
17402 reseat_to_string (it
, string
, lisp_string
, start
,
17403 precision
, field_width
, multibyte
);
17405 /* If displaying STRING, set up the face of the iterator
17406 from LISP_STRING, if that's given. */
17407 if (STRINGP (face_string
))
17413 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
17414 0, it
->region_beg_charpos
,
17415 it
->region_end_charpos
,
17416 &endptr
, it
->base_face_id
, 0);
17417 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17418 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
17421 /* Set max_x to the maximum allowed X position. Don't let it go
17422 beyond the right edge of the window. */
17424 max_x
= it
->last_visible_x
;
17426 max_x
= min (max_x
, it
->last_visible_x
);
17428 /* Skip over display elements that are not visible. because IT->w is
17430 if (it
->current_x
< it
->first_visible_x
)
17431 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
17432 MOVE_TO_POS
| MOVE_TO_X
);
17434 row
->ascent
= it
->max_ascent
;
17435 row
->height
= it
->max_ascent
+ it
->max_descent
;
17436 row
->phys_ascent
= it
->max_phys_ascent
;
17437 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17438 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17440 /* This condition is for the case that we are called with current_x
17441 past last_visible_x. */
17442 while (it
->current_x
< max_x
)
17444 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
17446 /* Get the next display element. */
17447 if (!get_next_display_element (it
))
17450 /* Produce glyphs. */
17451 x_before
= it
->current_x
;
17452 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17453 PRODUCE_GLYPHS (it
);
17455 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
17458 while (i
< nglyphs
)
17460 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17462 if (!it
->truncate_lines_p
17463 && x
+ glyph
->pixel_width
> max_x
)
17465 /* End of continued line or max_x reached. */
17466 if (CHAR_GLYPH_PADDING_P (*glyph
))
17468 /* A wide character is unbreakable. */
17469 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17470 it
->current_x
= x_before
;
17474 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17479 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
17481 /* Glyph is at least partially visible. */
17483 if (x
< it
->first_visible_x
)
17484 it
->glyph_row
->x
= x
- it
->first_visible_x
;
17488 /* Glyph is off the left margin of the display area.
17489 Should not happen. */
17493 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17494 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17495 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17496 row
->phys_height
= max (row
->phys_height
,
17497 it
->max_phys_ascent
+ it
->max_phys_descent
);
17498 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17499 it
->max_extra_line_spacing
);
17500 x
+= glyph
->pixel_width
;
17504 /* Stop if max_x reached. */
17508 /* Stop at line ends. */
17509 if (ITERATOR_AT_END_OF_LINE_P (it
))
17511 it
->continuation_lines_width
= 0;
17515 set_iterator_to_next (it
, 1);
17517 /* Stop if truncating at the right edge. */
17518 if (it
->truncate_lines_p
17519 && it
->current_x
>= it
->last_visible_x
)
17521 /* Add truncation mark, but don't do it if the line is
17522 truncated at a padding space. */
17523 if (IT_CHARPOS (*it
) < it
->string_nchars
)
17525 if (!FRAME_WINDOW_P (it
->f
))
17529 if (it
->current_x
> it
->last_visible_x
)
17531 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17532 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17534 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17536 row
->used
[TEXT_AREA
] = i
;
17537 produce_special_glyphs (it
, IT_TRUNCATION
);
17540 produce_special_glyphs (it
, IT_TRUNCATION
);
17542 it
->glyph_row
->truncated_on_right_p
= 1;
17548 /* Maybe insert a truncation at the left. */
17549 if (it
->first_visible_x
17550 && IT_CHARPOS (*it
) > 0)
17552 if (!FRAME_WINDOW_P (it
->f
))
17553 insert_left_trunc_glyphs (it
);
17554 it
->glyph_row
->truncated_on_left_p
= 1;
17557 it
->face_id
= saved_face_id
;
17559 /* Value is number of columns displayed. */
17560 return it
->hpos
- hpos_at_start
;
17565 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
17566 appears as an element of LIST or as the car of an element of LIST.
17567 If PROPVAL is a list, compare each element against LIST in that
17568 way, and return 1/2 if any element of PROPVAL is found in LIST.
17569 Otherwise return 0. This function cannot quit.
17570 The return value is 2 if the text is invisible but with an ellipsis
17571 and 1 if it's invisible and without an ellipsis. */
17574 invisible_p (propval
, list
)
17575 register Lisp_Object propval
;
17578 register Lisp_Object tail
, proptail
;
17580 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17582 register Lisp_Object tem
;
17584 if (EQ (propval
, tem
))
17586 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
17587 return NILP (XCDR (tem
)) ? 1 : 2;
17590 if (CONSP (propval
))
17592 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
17594 Lisp_Object propelt
;
17595 propelt
= XCAR (proptail
);
17596 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17598 register Lisp_Object tem
;
17600 if (EQ (propelt
, tem
))
17602 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
17603 return NILP (XCDR (tem
)) ? 1 : 2;
17611 /* Calculate a width or height in pixels from a specification using
17612 the following elements:
17615 NUM - a (fractional) multiple of the default font width/height
17616 (NUM) - specifies exactly NUM pixels
17617 UNIT - a fixed number of pixels, see below.
17618 ELEMENT - size of a display element in pixels, see below.
17619 (NUM . SPEC) - equals NUM * SPEC
17620 (+ SPEC SPEC ...) - add pixel values
17621 (- SPEC SPEC ...) - subtract pixel values
17622 (- SPEC) - negate pixel value
17625 INT or FLOAT - a number constant
17626 SYMBOL - use symbol's (buffer local) variable binding.
17629 in - pixels per inch *)
17630 mm - pixels per 1/1000 meter *)
17631 cm - pixels per 1/100 meter *)
17632 width - width of current font in pixels.
17633 height - height of current font in pixels.
17635 *) using the ratio(s) defined in display-pixels-per-inch.
17639 left-fringe - left fringe width in pixels
17640 right-fringe - right fringe width in pixels
17642 left-margin - left margin width in pixels
17643 right-margin - right margin width in pixels
17645 scroll-bar - scroll-bar area width in pixels
17649 Pixels corresponding to 5 inches:
17652 Total width of non-text areas on left side of window (if scroll-bar is on left):
17653 '(space :width (+ left-fringe left-margin scroll-bar))
17655 Align to first text column (in header line):
17656 '(space :align-to 0)
17658 Align to middle of text area minus half the width of variable `my-image'
17659 containing a loaded image:
17660 '(space :align-to (0.5 . (- text my-image)))
17662 Width of left margin minus width of 1 character in the default font:
17663 '(space :width (- left-margin 1))
17665 Width of left margin minus width of 2 characters in the current font:
17666 '(space :width (- left-margin (2 . width)))
17668 Center 1 character over left-margin (in header line):
17669 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
17671 Different ways to express width of left fringe plus left margin minus one pixel:
17672 '(space :width (- (+ left-fringe left-margin) (1)))
17673 '(space :width (+ left-fringe left-margin (- (1))))
17674 '(space :width (+ left-fringe left-margin (-1)))
17678 #define NUMVAL(X) \
17679 ((INTEGERP (X) || FLOATP (X)) \
17684 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
17689 int width_p
, *align_to
;
17693 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
17694 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
17697 return OK_PIXELS (0);
17699 if (SYMBOLP (prop
))
17701 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
17703 char *unit
= SDATA (SYMBOL_NAME (prop
));
17705 if (unit
[0] == 'i' && unit
[1] == 'n')
17707 else if (unit
[0] == 'm' && unit
[1] == 'm')
17709 else if (unit
[0] == 'c' && unit
[1] == 'm')
17716 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
17717 || (CONSP (Vdisplay_pixels_per_inch
)
17719 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
17720 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
17722 return OK_PIXELS (ppi
/ pixels
);
17728 #ifdef HAVE_WINDOW_SYSTEM
17729 if (EQ (prop
, Qheight
))
17730 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
17731 if (EQ (prop
, Qwidth
))
17732 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
17734 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
17735 return OK_PIXELS (1);
17738 if (EQ (prop
, Qtext
))
17739 return OK_PIXELS (width_p
17740 ? window_box_width (it
->w
, TEXT_AREA
)
17741 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
17743 if (align_to
&& *align_to
< 0)
17746 if (EQ (prop
, Qleft
))
17747 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
17748 if (EQ (prop
, Qright
))
17749 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
17750 if (EQ (prop
, Qcenter
))
17751 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
17752 + window_box_width (it
->w
, TEXT_AREA
) / 2);
17753 if (EQ (prop
, Qleft_fringe
))
17754 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17755 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
17756 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
17757 if (EQ (prop
, Qright_fringe
))
17758 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17759 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17760 : window_box_right_offset (it
->w
, TEXT_AREA
));
17761 if (EQ (prop
, Qleft_margin
))
17762 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
17763 if (EQ (prop
, Qright_margin
))
17764 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
17765 if (EQ (prop
, Qscroll_bar
))
17766 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
17768 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17769 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17770 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
17775 if (EQ (prop
, Qleft_fringe
))
17776 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
17777 if (EQ (prop
, Qright_fringe
))
17778 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
17779 if (EQ (prop
, Qleft_margin
))
17780 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
17781 if (EQ (prop
, Qright_margin
))
17782 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
17783 if (EQ (prop
, Qscroll_bar
))
17784 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
17787 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
17790 if (INTEGERP (prop
) || FLOATP (prop
))
17792 int base_unit
= (width_p
17793 ? FRAME_COLUMN_WIDTH (it
->f
)
17794 : FRAME_LINE_HEIGHT (it
->f
));
17795 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
17800 Lisp_Object car
= XCAR (prop
);
17801 Lisp_Object cdr
= XCDR (prop
);
17805 #ifdef HAVE_WINDOW_SYSTEM
17806 if (valid_image_p (prop
))
17808 int id
= lookup_image (it
->f
, prop
);
17809 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
17811 return OK_PIXELS (width_p
? img
->width
: img
->height
);
17814 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
17820 while (CONSP (cdr
))
17822 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
17823 font
, width_p
, align_to
))
17826 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
17831 if (EQ (car
, Qminus
))
17833 return OK_PIXELS (pixels
);
17836 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
17839 if (INTEGERP (car
) || FLOATP (car
))
17842 pixels
= XFLOATINT (car
);
17844 return OK_PIXELS (pixels
);
17845 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
17846 font
, width_p
, align_to
))
17847 return OK_PIXELS (pixels
* fact
);
17858 /***********************************************************************
17860 ***********************************************************************/
17862 #ifdef HAVE_WINDOW_SYSTEM
17867 dump_glyph_string (s
)
17868 struct glyph_string
*s
;
17870 fprintf (stderr
, "glyph string\n");
17871 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
17872 s
->x
, s
->y
, s
->width
, s
->height
);
17873 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
17874 fprintf (stderr
, " hl = %d\n", s
->hl
);
17875 fprintf (stderr
, " left overhang = %d, right = %d\n",
17876 s
->left_overhang
, s
->right_overhang
);
17877 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
17878 fprintf (stderr
, " extends to end of line = %d\n",
17879 s
->extends_to_end_of_line_p
);
17880 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
17881 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
17884 #endif /* GLYPH_DEBUG */
17886 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
17887 of XChar2b structures for S; it can't be allocated in
17888 init_glyph_string because it must be allocated via `alloca'. W
17889 is the window on which S is drawn. ROW and AREA are the glyph row
17890 and area within the row from which S is constructed. START is the
17891 index of the first glyph structure covered by S. HL is a
17892 face-override for drawing S. */
17895 #define OPTIONAL_HDC(hdc) hdc,
17896 #define DECLARE_HDC(hdc) HDC hdc;
17897 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
17898 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
17901 #ifndef OPTIONAL_HDC
17902 #define OPTIONAL_HDC(hdc)
17903 #define DECLARE_HDC(hdc)
17904 #define ALLOCATE_HDC(hdc, f)
17905 #define RELEASE_HDC(hdc, f)
17909 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
17910 struct glyph_string
*s
;
17914 struct glyph_row
*row
;
17915 enum glyph_row_area area
;
17917 enum draw_glyphs_face hl
;
17919 bzero (s
, sizeof *s
);
17921 s
->f
= XFRAME (w
->frame
);
17925 s
->display
= FRAME_X_DISPLAY (s
->f
);
17926 s
->window
= FRAME_X_WINDOW (s
->f
);
17927 s
->char2b
= char2b
;
17931 s
->first_glyph
= row
->glyphs
[area
] + start
;
17932 s
->height
= row
->height
;
17933 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
17935 /* Display the internal border below the tool-bar window. */
17936 if (WINDOWP (s
->f
->tool_bar_window
)
17937 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
17938 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
17940 s
->ybase
= s
->y
+ row
->ascent
;
17944 /* Append the list of glyph strings with head H and tail T to the list
17945 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
17948 append_glyph_string_lists (head
, tail
, h
, t
)
17949 struct glyph_string
**head
, **tail
;
17950 struct glyph_string
*h
, *t
;
17964 /* Prepend the list of glyph strings with head H and tail T to the
17965 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
17969 prepend_glyph_string_lists (head
, tail
, h
, t
)
17970 struct glyph_string
**head
, **tail
;
17971 struct glyph_string
*h
, *t
;
17985 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
17986 Set *HEAD and *TAIL to the resulting list. */
17989 append_glyph_string (head
, tail
, s
)
17990 struct glyph_string
**head
, **tail
;
17991 struct glyph_string
*s
;
17993 s
->next
= s
->prev
= NULL
;
17994 append_glyph_string_lists (head
, tail
, s
, s
);
17998 /* Get face and two-byte form of character glyph GLYPH on frame F.
17999 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
18000 a pointer to a realized face that is ready for display. */
18002 static INLINE
struct face
*
18003 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
18005 struct glyph
*glyph
;
18011 xassert (glyph
->type
== CHAR_GLYPH
);
18012 face
= FACE_FROM_ID (f
, glyph
->face_id
);
18017 if (!glyph
->multibyte_p
)
18019 /* Unibyte case. We don't have to encode, but we have to make
18020 sure to use a face suitable for unibyte. */
18021 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18023 else if (glyph
->u
.ch
< 128
18024 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
18026 /* Case of ASCII in a face known to fit ASCII. */
18027 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18031 struct font_info
*font_info
18032 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18035 struct charset
*charset
= CHARSET_FROM_ID (font_info
->charset
);
18036 unsigned code
= ENCODE_CHAR (charset
, glyph
->u
.ch
);
18038 if (CHARSET_DIMENSION (charset
) == 1)
18039 STORE_XCHAR2B (char2b
, 0, code
);
18041 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
18043 /* Maybe encode the character in *CHAR2B. */
18044 if (CHARSET_ID (charset
) != charset_ascii
)
18047 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, charset
,
18053 /* Make sure X resources of the face are allocated. */
18054 xassert (face
!= NULL
);
18055 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18060 /* Fill glyph string S with composition components specified by S->cmp.
18062 FACES is an array of faces for all components of this composition.
18063 S->gidx is the index of the first component for S.
18064 OVERLAPS_P non-zero means S should draw the foreground only, and
18065 use its physical height for clipping.
18067 Value is the index of a component not in S. */
18070 fill_composite_glyph_string (s
, faces
, overlaps_p
)
18071 struct glyph_string
*s
;
18072 struct face
**faces
;
18079 s
->for_overlaps_p
= overlaps_p
;
18081 s
->face
= faces
[s
->gidx
];
18082 s
->font
= s
->face
->font
;
18083 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18085 /* For all glyphs of this composition, starting at the offset
18086 S->gidx, until we reach the end of the definition or encounter a
18087 glyph that requires the different face, add it to S. */
18089 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
18092 /* All glyph strings for the same composition has the same width,
18093 i.e. the width set for the first component of the composition. */
18095 s
->width
= s
->first_glyph
->pixel_width
;
18097 /* If the specified font could not be loaded, use the frame's
18098 default font, but record the fact that we couldn't load it in
18099 the glyph string so that we can draw rectangles for the
18100 characters of the glyph string. */
18101 if (s
->font
== NULL
)
18103 s
->font_not_found_p
= 1;
18104 s
->font
= FRAME_FONT (s
->f
);
18107 /* Adjust base line for subscript/superscript text. */
18108 s
->ybase
+= s
->first_glyph
->voffset
;
18110 xassert (s
->face
&& s
->face
->gc
);
18112 /* This glyph string must always be drawn with 16-bit functions. */
18115 return s
->gidx
+ s
->nchars
;
18119 /* Fill glyph string S from a sequence of character glyphs.
18121 FACE_ID is the face id of the string. START is the index of the
18122 first glyph to consider, END is the index of the last + 1.
18123 OVERLAPS_P non-zero means S should draw the foreground only, and
18124 use its physical height for clipping.
18126 Value is the index of the first glyph not in S. */
18129 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
18130 struct glyph_string
*s
;
18132 int start
, end
, overlaps_p
;
18134 struct glyph
*glyph
, *last
;
18136 int glyph_not_available_p
;
18138 xassert (s
->f
== XFRAME (s
->w
->frame
));
18139 xassert (s
->nchars
== 0);
18140 xassert (start
>= 0 && end
> start
);
18142 s
->for_overlaps_p
= overlaps_p
,
18143 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18144 last
= s
->row
->glyphs
[s
->area
] + end
;
18145 voffset
= glyph
->voffset
;
18147 glyph_not_available_p
= glyph
->glyph_not_available_p
;
18149 while (glyph
< last
18150 && glyph
->type
== CHAR_GLYPH
18151 && glyph
->voffset
== voffset
18152 /* Same face id implies same font, nowadays. */
18153 && glyph
->face_id
== face_id
18154 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
18158 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
18159 s
->char2b
+ s
->nchars
,
18161 s
->two_byte_p
= two_byte_p
;
18163 xassert (s
->nchars
<= end
- start
);
18164 s
->width
+= glyph
->pixel_width
;
18168 s
->font
= s
->face
->font
;
18169 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18171 /* If the specified font could not be loaded, use the frame's font,
18172 but record the fact that we couldn't load it in
18173 S->font_not_found_p so that we can draw rectangles for the
18174 characters of the glyph string. */
18175 if (s
->font
== NULL
|| glyph_not_available_p
)
18177 s
->font_not_found_p
= 1;
18178 s
->font
= FRAME_FONT (s
->f
);
18181 /* Adjust base line for subscript/superscript text. */
18182 s
->ybase
+= voffset
;
18184 xassert (s
->face
&& s
->face
->gc
);
18185 return glyph
- s
->row
->glyphs
[s
->area
];
18189 /* Fill glyph string S from image glyph S->first_glyph. */
18192 fill_image_glyph_string (s
)
18193 struct glyph_string
*s
;
18195 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
18196 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
18198 s
->slice
= s
->first_glyph
->slice
;
18199 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
18200 s
->font
= s
->face
->font
;
18201 s
->width
= s
->first_glyph
->pixel_width
;
18203 /* Adjust base line for subscript/superscript text. */
18204 s
->ybase
+= s
->first_glyph
->voffset
;
18208 /* Fill glyph string S from a sequence of stretch glyphs.
18210 ROW is the glyph row in which the glyphs are found, AREA is the
18211 area within the row. START is the index of the first glyph to
18212 consider, END is the index of the last + 1.
18214 Value is the index of the first glyph not in S. */
18217 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
18218 struct glyph_string
*s
;
18219 struct glyph_row
*row
;
18220 enum glyph_row_area area
;
18223 struct glyph
*glyph
, *last
;
18224 int voffset
, face_id
;
18226 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
18228 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18229 last
= s
->row
->glyphs
[s
->area
] + end
;
18230 face_id
= glyph
->face_id
;
18231 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
18232 s
->font
= s
->face
->font
;
18233 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18234 s
->width
= glyph
->pixel_width
;
18235 voffset
= glyph
->voffset
;
18239 && glyph
->type
== STRETCH_GLYPH
18240 && glyph
->voffset
== voffset
18241 && glyph
->face_id
== face_id
);
18243 s
->width
+= glyph
->pixel_width
;
18245 /* Adjust base line for subscript/superscript text. */
18246 s
->ybase
+= voffset
;
18248 /* The case that face->gc == 0 is handled when drawing the glyph
18249 string by calling PREPARE_FACE_FOR_DISPLAY. */
18251 return glyph
- s
->row
->glyphs
[s
->area
];
18256 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
18257 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
18258 assumed to be zero. */
18261 x_get_glyph_overhangs (glyph
, f
, left
, right
)
18262 struct glyph
*glyph
;
18266 *left
= *right
= 0;
18268 if (glyph
->type
== CHAR_GLYPH
)
18272 struct font_info
*font_info
;
18276 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
18278 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18279 if (font
/* ++KFS: Should this be font_info ? */
18280 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
18282 if (pcm
->rbearing
> pcm
->width
)
18283 *right
= pcm
->rbearing
- pcm
->width
;
18284 if (pcm
->lbearing
< 0)
18285 *left
= -pcm
->lbearing
;
18288 else if (glyph
->type
== COMPOSITE_GLYPH
)
18290 struct composition
*cmp
= composition_table
[glyph
->u
.cmp_id
];
18292 *right
= cmp
->rbearing
- cmp
->pixel_width
;
18293 *left
= - cmp
->lbearing
;
18298 /* Return the index of the first glyph preceding glyph string S that
18299 is overwritten by S because of S's left overhang. Value is -1
18300 if no glyphs are overwritten. */
18303 left_overwritten (s
)
18304 struct glyph_string
*s
;
18308 if (s
->left_overhang
)
18311 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18312 int first
= s
->first_glyph
- glyphs
;
18314 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
18315 x
-= glyphs
[i
].pixel_width
;
18326 /* Return the index of the first glyph preceding glyph string S that
18327 is overwriting S because of its right overhang. Value is -1 if no
18328 glyph in front of S overwrites S. */
18331 left_overwriting (s
)
18332 struct glyph_string
*s
;
18335 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18336 int first
= s
->first_glyph
- glyphs
;
18340 for (i
= first
- 1; i
>= 0; --i
)
18343 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18346 x
-= glyphs
[i
].pixel_width
;
18353 /* Return the index of the last glyph following glyph string S that is
18354 not overwritten by S because of S's right overhang. Value is -1 if
18355 no such glyph is found. */
18358 right_overwritten (s
)
18359 struct glyph_string
*s
;
18363 if (s
->right_overhang
)
18366 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18367 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18368 int end
= s
->row
->used
[s
->area
];
18370 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
18371 x
+= glyphs
[i
].pixel_width
;
18380 /* Return the index of the last glyph following glyph string S that
18381 overwrites S because of its left overhang. Value is negative
18382 if no such glyph is found. */
18385 right_overwriting (s
)
18386 struct glyph_string
*s
;
18389 int end
= s
->row
->used
[s
->area
];
18390 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18391 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18395 for (i
= first
; i
< end
; ++i
)
18398 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18401 x
+= glyphs
[i
].pixel_width
;
18408 /* Get face and two-byte form of character C in face FACE_ID on frame
18409 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
18410 means we want to display multibyte text. DISPLAY_P non-zero means
18411 make sure that X resources for the face returned are allocated.
18412 Value is a pointer to a realized face that is ready for display if
18413 DISPLAY_P is non-zero. */
18415 static INLINE
struct face
*
18416 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
18420 int multibyte_p
, display_p
;
18422 struct face
*face
= FACE_FROM_ID (f
, face_id
);
18426 /* Unibyte case. We don't have to encode, but we have to make
18427 sure to use a face suitable for unibyte. */
18428 STORE_XCHAR2B (char2b
, 0, c
);
18429 face_id
= FACE_FOR_CHAR (f
, face
, c
, -1, Qnil
);
18430 face
= FACE_FROM_ID (f
, face_id
);
18432 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
18434 /* Case of ASCII in a face known to fit ASCII. */
18435 STORE_XCHAR2B (char2b
, 0, c
);
18437 else if (face
->font
!= NULL
)
18439 struct font_info
*font_info
18440 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18441 struct charset
*charset
= CHARSET_FROM_ID (font_info
->charset
);
18442 unsigned code
= ENCODE_CHAR (charset
, c
);
18444 if (CHARSET_DIMENSION (charset
) == 1)
18445 STORE_XCHAR2B (char2b
, 0, code
);
18447 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
18448 /* Maybe encode the character in *CHAR2B. */
18449 rif
->encode_char (c
, char2b
, font_info
, charset
, NULL
);
18452 /* Make sure X resources of the face are allocated. */
18453 #ifdef HAVE_X_WINDOWS
18457 xassert (face
!= NULL
);
18458 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18465 /* Set background width of glyph string S. START is the index of the
18466 first glyph following S. LAST_X is the right-most x-position + 1
18467 in the drawing area. */
18470 set_glyph_string_background_width (s
, start
, last_x
)
18471 struct glyph_string
*s
;
18475 /* If the face of this glyph string has to be drawn to the end of
18476 the drawing area, set S->extends_to_end_of_line_p. */
18477 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
18479 if (start
== s
->row
->used
[s
->area
]
18480 && s
->area
== TEXT_AREA
18481 && ((s
->hl
== DRAW_NORMAL_TEXT
18482 && (s
->row
->fill_line_p
18483 || s
->face
->background
!= default_face
->background
18484 || s
->face
->stipple
!= default_face
->stipple
18485 || s
->row
->mouse_face_p
))
18486 || s
->hl
== DRAW_MOUSE_FACE
18487 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
18488 && s
->row
->fill_line_p
)))
18489 s
->extends_to_end_of_line_p
= 1;
18491 /* If S extends its face to the end of the line, set its
18492 background_width to the distance to the right edge of the drawing
18494 if (s
->extends_to_end_of_line_p
)
18495 s
->background_width
= last_x
- s
->x
+ 1;
18497 s
->background_width
= s
->width
;
18501 /* Compute overhangs and x-positions for glyph string S and its
18502 predecessors, or successors. X is the starting x-position for S.
18503 BACKWARD_P non-zero means process predecessors. */
18506 compute_overhangs_and_x (s
, x
, backward_p
)
18507 struct glyph_string
*s
;
18515 if (rif
->compute_glyph_string_overhangs
)
18516 rif
->compute_glyph_string_overhangs (s
);
18526 if (rif
->compute_glyph_string_overhangs
)
18527 rif
->compute_glyph_string_overhangs (s
);
18537 /* The following macros are only called from draw_glyphs below.
18538 They reference the following parameters of that function directly:
18539 `w', `row', `area', and `overlap_p'
18540 as well as the following local variables:
18541 `s', `f', and `hdc' (in W32) */
18544 /* On W32, silently add local `hdc' variable to argument list of
18545 init_glyph_string. */
18546 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18547 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
18549 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18550 init_glyph_string (s, char2b, w, row, area, start, hl)
18553 /* Add a glyph string for a stretch glyph to the list of strings
18554 between HEAD and TAIL. START is the index of the stretch glyph in
18555 row area AREA of glyph row ROW. END is the index of the last glyph
18556 in that glyph row area. X is the current output position assigned
18557 to the new glyph string constructed. HL overrides that face of the
18558 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18559 is the right-most x-position of the drawing area. */
18561 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
18562 and below -- keep them on one line. */
18563 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18566 s = (struct glyph_string *) alloca (sizeof *s); \
18567 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18568 START = fill_stretch_glyph_string (s, row, area, START, END); \
18569 append_glyph_string (&HEAD, &TAIL, s); \
18575 /* Add a glyph string for an image glyph to the list of strings
18576 between HEAD and TAIL. START is the index of the image glyph in
18577 row area AREA of glyph row ROW. END is the index of the last glyph
18578 in that glyph row area. X is the current output position assigned
18579 to the new glyph string constructed. HL overrides that face of the
18580 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18581 is the right-most x-position of the drawing area. */
18583 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18586 s = (struct glyph_string *) alloca (sizeof *s); \
18587 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18588 fill_image_glyph_string (s); \
18589 append_glyph_string (&HEAD, &TAIL, s); \
18596 /* Add a glyph string for a sequence of character glyphs to the list
18597 of strings between HEAD and TAIL. START is the index of the first
18598 glyph in row area AREA of glyph row ROW that is part of the new
18599 glyph string. END is the index of the last glyph in that glyph row
18600 area. X is the current output position assigned to the new glyph
18601 string constructed. HL overrides that face of the glyph; e.g. it
18602 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
18603 right-most x-position of the drawing area. */
18605 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18611 face_id = (row)->glyphs[area][START].face_id; \
18613 s = (struct glyph_string *) alloca (sizeof *s); \
18614 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
18615 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
18616 append_glyph_string (&HEAD, &TAIL, s); \
18618 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
18623 /* Add a glyph string for a composite sequence to the list of strings
18624 between HEAD and TAIL. START is the index of the first glyph in
18625 row area AREA of glyph row ROW that is part of the new glyph
18626 string. END is the index of the last glyph in that glyph row area.
18627 X is the current output position assigned to the new glyph string
18628 constructed. HL overrides that face of the glyph; e.g. it is
18629 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
18630 x-position of the drawing area. */
18632 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18634 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
18635 int face_id = (row)->glyphs[area][START].face_id; \
18636 struct face *base_face = FACE_FROM_ID (f, face_id); \
18637 struct composition *cmp = composition_table[cmp_id]; \
18638 int glyph_len = cmp->glyph_len; \
18640 struct face **faces; \
18641 struct glyph_string *first_s = NULL; \
18644 base_face = base_face->ascii_face; \
18645 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
18646 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
18647 /* At first, fill in `char2b' and `faces'. */ \
18648 for (n = 0; n < glyph_len; n++) \
18650 int c = COMPOSITION_GLYPH (cmp, n); \
18651 int this_face_id = FACE_FOR_CHAR (f, base_face, c, -1, Qnil); \
18652 faces[n] = FACE_FROM_ID (f, this_face_id); \
18653 get_char_face_and_encoding (f, c, this_face_id, \
18654 char2b + n, 1, 1); \
18657 /* Make glyph_strings for each glyph sequence that is drawable by \
18658 the same face, and append them to HEAD/TAIL. */ \
18659 for (n = 0; n < cmp->glyph_len;) \
18661 s = (struct glyph_string *) alloca (sizeof *s); \
18662 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
18663 append_glyph_string (&(HEAD), &(TAIL), s); \
18671 n = fill_composite_glyph_string (s, faces, overlaps_p); \
18679 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
18680 of AREA of glyph row ROW on window W between indices START and END.
18681 HL overrides the face for drawing glyph strings, e.g. it is
18682 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
18683 x-positions of the drawing area.
18685 This is an ugly monster macro construct because we must use alloca
18686 to allocate glyph strings (because draw_glyphs can be called
18687 asynchronously). */
18689 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18692 HEAD = TAIL = NULL; \
18693 while (START < END) \
18695 struct glyph *first_glyph = (row)->glyphs[area] + START; \
18696 switch (first_glyph->type) \
18699 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
18703 case COMPOSITE_GLYPH: \
18704 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
18708 case STRETCH_GLYPH: \
18709 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
18713 case IMAGE_GLYPH: \
18714 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
18724 set_glyph_string_background_width (s, START, LAST_X); \
18732 /* Draw glyphs between START and END in AREA of ROW on window W,
18733 starting at x-position X. X is relative to AREA in W. HL is a
18734 face-override with the following meaning:
18736 DRAW_NORMAL_TEXT draw normally
18737 DRAW_CURSOR draw in cursor face
18738 DRAW_MOUSE_FACE draw in mouse face.
18739 DRAW_INVERSE_VIDEO draw in mode line face
18740 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
18741 DRAW_IMAGE_RAISED draw an image with a raised relief around it
18743 If OVERLAPS_P is non-zero, draw only the foreground of characters
18744 and clip to the physical height of ROW.
18746 Value is the x-position reached, relative to AREA of W. */
18749 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
18752 struct glyph_row
*row
;
18753 enum glyph_row_area area
;
18754 EMACS_INT start
, end
;
18755 enum draw_glyphs_face hl
;
18758 struct glyph_string
*head
, *tail
;
18759 struct glyph_string
*s
;
18760 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
18761 int last_x
, area_width
;
18764 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18767 ALLOCATE_HDC (hdc
, f
);
18769 /* Let's rather be paranoid than getting a SEGV. */
18770 end
= min (end
, row
->used
[area
]);
18771 start
= max (0, start
);
18772 start
= min (end
, start
);
18774 /* Translate X to frame coordinates. Set last_x to the right
18775 end of the drawing area. */
18776 if (row
->full_width_p
)
18778 /* X is relative to the left edge of W, without scroll bars
18780 x
+= WINDOW_LEFT_EDGE_X (w
);
18781 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
18785 int area_left
= window_box_left (w
, area
);
18787 area_width
= window_box_width (w
, area
);
18788 last_x
= area_left
+ area_width
;
18791 /* Build a doubly-linked list of glyph_string structures between
18792 head and tail from what we have to draw. Note that the macro
18793 BUILD_GLYPH_STRINGS will modify its start parameter. That's
18794 the reason we use a separate variable `i'. */
18796 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
18798 x_reached
= tail
->x
+ tail
->background_width
;
18802 /* If there are any glyphs with lbearing < 0 or rbearing > width in
18803 the row, redraw some glyphs in front or following the glyph
18804 strings built above. */
18805 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
18808 struct glyph_string
*h
, *t
;
18810 /* Compute overhangs for all glyph strings. */
18811 if (rif
->compute_glyph_string_overhangs
)
18812 for (s
= head
; s
; s
= s
->next
)
18813 rif
->compute_glyph_string_overhangs (s
);
18815 /* Prepend glyph strings for glyphs in front of the first glyph
18816 string that are overwritten because of the first glyph
18817 string's left overhang. The background of all strings
18818 prepended must be drawn because the first glyph string
18820 i
= left_overwritten (head
);
18824 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
18825 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18827 compute_overhangs_and_x (t
, head
->x
, 1);
18828 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18832 /* Prepend glyph strings for glyphs in front of the first glyph
18833 string that overwrite that glyph string because of their
18834 right overhang. For these strings, only the foreground must
18835 be drawn, because it draws over the glyph string at `head'.
18836 The background must not be drawn because this would overwrite
18837 right overhangs of preceding glyphs for which no glyph
18839 i
= left_overwriting (head
);
18843 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
18844 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18845 for (s
= h
; s
; s
= s
->next
)
18846 s
->background_filled_p
= 1;
18847 compute_overhangs_and_x (t
, head
->x
, 1);
18848 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18851 /* Append glyphs strings for glyphs following the last glyph
18852 string tail that are overwritten by tail. The background of
18853 these strings has to be drawn because tail's foreground draws
18855 i
= right_overwritten (tail
);
18858 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18859 DRAW_NORMAL_TEXT
, x
, last_x
);
18860 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18861 append_glyph_string_lists (&head
, &tail
, h
, t
);
18865 /* Append glyph strings for glyphs following the last glyph
18866 string tail that overwrite tail. The foreground of such
18867 glyphs has to be drawn because it writes into the background
18868 of tail. The background must not be drawn because it could
18869 paint over the foreground of following glyphs. */
18870 i
= right_overwriting (tail
);
18874 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18875 DRAW_NORMAL_TEXT
, x
, last_x
);
18876 for (s
= h
; s
; s
= s
->next
)
18877 s
->background_filled_p
= 1;
18878 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18879 append_glyph_string_lists (&head
, &tail
, h
, t
);
18881 if (clip_head
|| clip_tail
)
18882 for (s
= head
; s
; s
= s
->next
)
18884 s
->clip_head
= clip_head
;
18885 s
->clip_tail
= clip_tail
;
18889 /* Draw all strings. */
18890 for (s
= head
; s
; s
= s
->next
)
18891 rif
->draw_glyph_string (s
);
18893 if (area
== TEXT_AREA
18894 && !row
->full_width_p
18895 /* When drawing overlapping rows, only the glyph strings'
18896 foreground is drawn, which doesn't erase a cursor
18900 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
18901 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
18902 : (tail
? tail
->x
+ tail
->background_width
: x
));
18904 int text_left
= window_box_left (w
, TEXT_AREA
);
18908 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
18909 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
18912 /* Value is the x-position up to which drawn, relative to AREA of W.
18913 This doesn't include parts drawn because of overhangs. */
18914 if (row
->full_width_p
)
18915 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
18917 x_reached
-= window_box_left (w
, area
);
18919 RELEASE_HDC (hdc
, f
);
18924 /* Expand row matrix if too narrow. Don't expand if area
18927 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
18929 if (!fonts_changed_p \
18930 && (it->glyph_row->glyphs[area] \
18931 < it->glyph_row->glyphs[area + 1])) \
18933 it->w->ncols_scale_factor++; \
18934 fonts_changed_p = 1; \
18938 /* Store one glyph for IT->char_to_display in IT->glyph_row.
18939 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18945 struct glyph
*glyph
;
18946 enum glyph_row_area area
= it
->area
;
18948 xassert (it
->glyph_row
);
18949 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
18951 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18952 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18954 glyph
->charpos
= CHARPOS (it
->position
);
18955 glyph
->object
= it
->object
;
18956 glyph
->pixel_width
= it
->pixel_width
;
18957 glyph
->ascent
= it
->ascent
;
18958 glyph
->descent
= it
->descent
;
18959 glyph
->voffset
= it
->voffset
;
18960 glyph
->type
= CHAR_GLYPH
;
18961 glyph
->multibyte_p
= it
->multibyte_p
;
18962 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18963 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18964 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18965 || it
->phys_descent
> it
->descent
);
18966 glyph
->padding_p
= 0;
18967 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
18968 glyph
->face_id
= it
->face_id
;
18969 glyph
->u
.ch
= it
->char_to_display
;
18970 glyph
->slice
= null_glyph_slice
;
18971 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18972 ++it
->glyph_row
->used
[area
];
18975 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18978 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
18979 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18982 append_composite_glyph (it
)
18985 struct glyph
*glyph
;
18986 enum glyph_row_area area
= it
->area
;
18988 xassert (it
->glyph_row
);
18990 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18991 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18993 glyph
->charpos
= CHARPOS (it
->position
);
18994 glyph
->object
= it
->object
;
18995 glyph
->pixel_width
= it
->pixel_width
;
18996 glyph
->ascent
= it
->ascent
;
18997 glyph
->descent
= it
->descent
;
18998 glyph
->voffset
= it
->voffset
;
18999 glyph
->type
= COMPOSITE_GLYPH
;
19000 glyph
->multibyte_p
= it
->multibyte_p
;
19001 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19002 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19003 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19004 || it
->phys_descent
> it
->descent
);
19005 glyph
->padding_p
= 0;
19006 glyph
->glyph_not_available_p
= 0;
19007 glyph
->face_id
= it
->face_id
;
19008 glyph
->u
.cmp_id
= it
->cmp_id
;
19009 glyph
->slice
= null_glyph_slice
;
19010 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19011 ++it
->glyph_row
->used
[area
];
19014 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19018 /* Change IT->ascent and IT->height according to the setting of
19022 take_vertical_position_into_account (it
)
19027 if (it
->voffset
< 0)
19028 /* Increase the ascent so that we can display the text higher
19030 it
->ascent
-= it
->voffset
;
19032 /* Increase the descent so that we can display the text lower
19034 it
->descent
+= it
->voffset
;
19039 /* Produce glyphs/get display metrics for the image IT is loaded with.
19040 See the description of struct display_iterator in dispextern.h for
19041 an overview of struct display_iterator. */
19044 produce_image_glyph (it
)
19050 struct glyph_slice slice
;
19052 xassert (it
->what
== IT_IMAGE
);
19054 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19056 /* Make sure X resources of the face is loaded. */
19057 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19059 if (it
->image_id
< 0)
19061 /* Fringe bitmap. */
19062 it
->ascent
= it
->phys_ascent
= 0;
19063 it
->descent
= it
->phys_descent
= 0;
19064 it
->pixel_width
= 0;
19069 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
19071 /* Make sure X resources of the image is loaded. */
19072 prepare_image_for_display (it
->f
, img
);
19074 slice
.x
= slice
.y
= 0;
19075 slice
.width
= img
->width
;
19076 slice
.height
= img
->height
;
19078 if (INTEGERP (it
->slice
.x
))
19079 slice
.x
= XINT (it
->slice
.x
);
19080 else if (FLOATP (it
->slice
.x
))
19081 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
19083 if (INTEGERP (it
->slice
.y
))
19084 slice
.y
= XINT (it
->slice
.y
);
19085 else if (FLOATP (it
->slice
.y
))
19086 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
19088 if (INTEGERP (it
->slice
.width
))
19089 slice
.width
= XINT (it
->slice
.width
);
19090 else if (FLOATP (it
->slice
.width
))
19091 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
19093 if (INTEGERP (it
->slice
.height
))
19094 slice
.height
= XINT (it
->slice
.height
);
19095 else if (FLOATP (it
->slice
.height
))
19096 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
19098 if (slice
.x
>= img
->width
)
19099 slice
.x
= img
->width
;
19100 if (slice
.y
>= img
->height
)
19101 slice
.y
= img
->height
;
19102 if (slice
.x
+ slice
.width
>= img
->width
)
19103 slice
.width
= img
->width
- slice
.x
;
19104 if (slice
.y
+ slice
.height
> img
->height
)
19105 slice
.height
= img
->height
- slice
.y
;
19107 if (slice
.width
== 0 || slice
.height
== 0)
19110 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
19112 it
->descent
= slice
.height
- glyph_ascent
;
19114 it
->descent
+= img
->vmargin
;
19115 if (slice
.y
+ slice
.height
== img
->height
)
19116 it
->descent
+= img
->vmargin
;
19117 it
->phys_descent
= it
->descent
;
19119 it
->pixel_width
= slice
.width
;
19121 it
->pixel_width
+= img
->hmargin
;
19122 if (slice
.x
+ slice
.width
== img
->width
)
19123 it
->pixel_width
+= img
->hmargin
;
19125 /* It's quite possible for images to have an ascent greater than
19126 their height, so don't get confused in that case. */
19127 if (it
->descent
< 0)
19130 #if 0 /* this breaks image tiling */
19131 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
19132 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
19133 if (face_ascent
> it
->ascent
)
19134 it
->ascent
= it
->phys_ascent
= face_ascent
;
19139 if (face
->box
!= FACE_NO_BOX
)
19141 if (face
->box_line_width
> 0)
19144 it
->ascent
+= face
->box_line_width
;
19145 if (slice
.y
+ slice
.height
== img
->height
)
19146 it
->descent
+= face
->box_line_width
;
19149 if (it
->start_of_box_run_p
&& slice
.x
== 0)
19150 it
->pixel_width
+= abs (face
->box_line_width
);
19151 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
19152 it
->pixel_width
+= abs (face
->box_line_width
);
19155 take_vertical_position_into_account (it
);
19159 struct glyph
*glyph
;
19160 enum glyph_row_area area
= it
->area
;
19162 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19163 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19165 glyph
->charpos
= CHARPOS (it
->position
);
19166 glyph
->object
= it
->object
;
19167 glyph
->pixel_width
= it
->pixel_width
;
19168 glyph
->ascent
= glyph_ascent
;
19169 glyph
->descent
= it
->descent
;
19170 glyph
->voffset
= it
->voffset
;
19171 glyph
->type
= IMAGE_GLYPH
;
19172 glyph
->multibyte_p
= it
->multibyte_p
;
19173 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19174 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19175 glyph
->overlaps_vertically_p
= 0;
19176 glyph
->padding_p
= 0;
19177 glyph
->glyph_not_available_p
= 0;
19178 glyph
->face_id
= it
->face_id
;
19179 glyph
->u
.img_id
= img
->id
;
19180 glyph
->slice
= slice
;
19181 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19182 ++it
->glyph_row
->used
[area
];
19185 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19190 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
19191 of the glyph, WIDTH and HEIGHT are the width and height of the
19192 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
19195 append_stretch_glyph (it
, object
, width
, height
, ascent
)
19197 Lisp_Object object
;
19201 struct glyph
*glyph
;
19202 enum glyph_row_area area
= it
->area
;
19204 xassert (ascent
>= 0 && ascent
<= height
);
19206 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19207 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19209 glyph
->charpos
= CHARPOS (it
->position
);
19210 glyph
->object
= object
;
19211 glyph
->pixel_width
= width
;
19212 glyph
->ascent
= ascent
;
19213 glyph
->descent
= height
- ascent
;
19214 glyph
->voffset
= it
->voffset
;
19215 glyph
->type
= STRETCH_GLYPH
;
19216 glyph
->multibyte_p
= it
->multibyte_p
;
19217 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19218 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19219 glyph
->overlaps_vertically_p
= 0;
19220 glyph
->padding_p
= 0;
19221 glyph
->glyph_not_available_p
= 0;
19222 glyph
->face_id
= it
->face_id
;
19223 glyph
->u
.stretch
.ascent
= ascent
;
19224 glyph
->u
.stretch
.height
= height
;
19225 glyph
->slice
= null_glyph_slice
;
19226 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19227 ++it
->glyph_row
->used
[area
];
19230 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19234 /* Produce a stretch glyph for iterator IT. IT->object is the value
19235 of the glyph property displayed. The value must be a list
19236 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
19239 1. `:width WIDTH' specifies that the space should be WIDTH *
19240 canonical char width wide. WIDTH may be an integer or floating
19243 2. `:relative-width FACTOR' specifies that the width of the stretch
19244 should be computed from the width of the first character having the
19245 `glyph' property, and should be FACTOR times that width.
19247 3. `:align-to HPOS' specifies that the space should be wide enough
19248 to reach HPOS, a value in canonical character units.
19250 Exactly one of the above pairs must be present.
19252 4. `:height HEIGHT' specifies that the height of the stretch produced
19253 should be HEIGHT, measured in canonical character units.
19255 5. `:relative-height FACTOR' specifies that the height of the
19256 stretch should be FACTOR times the height of the characters having
19257 the glyph property.
19259 Either none or exactly one of 4 or 5 must be present.
19261 6. `:ascent ASCENT' specifies that ASCENT percent of the height
19262 of the stretch should be used for the ascent of the stretch.
19263 ASCENT must be in the range 0 <= ASCENT <= 100. */
19266 produce_stretch_glyph (it
)
19269 /* (space :width WIDTH :height HEIGHT ...) */
19270 Lisp_Object prop
, plist
;
19271 int width
= 0, height
= 0, align_to
= -1;
19272 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
19275 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19276 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
19278 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19280 /* List should start with `space'. */
19281 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
19282 plist
= XCDR (it
->object
);
19284 /* Compute the width of the stretch. */
19285 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
19286 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
19288 /* Absolute width `:width WIDTH' specified and valid. */
19289 zero_width_ok_p
= 1;
19292 else if (prop
= Fplist_get (plist
, QCrelative_width
),
19295 /* Relative width `:relative-width FACTOR' specified and valid.
19296 Compute the width of the characters having the `glyph'
19299 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
19302 if (it
->multibyte_p
)
19304 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
19305 - IT_BYTEPOS (*it
));
19306 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
19309 it2
.c
= *p
, it2
.len
= 1;
19311 it2
.glyph_row
= NULL
;
19312 it2
.what
= IT_CHARACTER
;
19313 x_produce_glyphs (&it2
);
19314 width
= NUMVAL (prop
) * it2
.pixel_width
;
19316 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
19317 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
19319 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
19320 align_to
= (align_to
< 0
19322 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
19323 else if (align_to
< 0)
19324 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
19325 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
19326 zero_width_ok_p
= 1;
19329 /* Nothing specified -> width defaults to canonical char width. */
19330 width
= FRAME_COLUMN_WIDTH (it
->f
);
19332 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
19335 /* Compute height. */
19336 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
19337 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19340 zero_height_ok_p
= 1;
19342 else if (prop
= Fplist_get (plist
, QCrelative_height
),
19344 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
19346 height
= FONT_HEIGHT (font
);
19348 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
19351 /* Compute percentage of height used for ascent. If
19352 `:ascent ASCENT' is present and valid, use that. Otherwise,
19353 derive the ascent from the font in use. */
19354 if (prop
= Fplist_get (plist
, QCascent
),
19355 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
19356 ascent
= height
* NUMVAL (prop
) / 100.0;
19357 else if (!NILP (prop
)
19358 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19359 ascent
= min (max (0, (int)tem
), height
);
19361 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
19363 if (width
> 0 && height
> 0 && it
->glyph_row
)
19365 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
19366 if (!STRINGP (object
))
19367 object
= it
->w
->buffer
;
19368 append_stretch_glyph (it
, object
, width
, height
, ascent
);
19371 it
->pixel_width
= width
;
19372 it
->ascent
= it
->phys_ascent
= ascent
;
19373 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
19374 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
19376 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
19378 if (face
->box_line_width
> 0)
19380 it
->ascent
+= face
->box_line_width
;
19381 it
->descent
+= face
->box_line_width
;
19384 if (it
->start_of_box_run_p
)
19385 it
->pixel_width
+= abs (face
->box_line_width
);
19386 if (it
->end_of_box_run_p
)
19387 it
->pixel_width
+= abs (face
->box_line_width
);
19390 take_vertical_position_into_account (it
);
19393 /* Get line-height and line-spacing property at point.
19394 If line-height has format (HEIGHT TOTAL), return TOTAL
19395 in TOTAL_HEIGHT. */
19398 get_line_height_property (it
, prop
)
19402 Lisp_Object position
;
19404 if (STRINGP (it
->object
))
19405 position
= make_number (IT_STRING_CHARPOS (*it
));
19406 else if (BUFFERP (it
->object
))
19407 position
= make_number (IT_CHARPOS (*it
));
19411 return Fget_char_property (position
, prop
, it
->object
);
19414 /* Calculate line-height and line-spacing properties.
19415 An integer value specifies explicit pixel value.
19416 A float value specifies relative value to current face height.
19417 A cons (float . face-name) specifies relative value to
19418 height of specified face font.
19420 Returns height in pixels, or nil. */
19424 calc_line_height_property (it
, val
, font
, boff
, override
)
19428 int boff
, override
;
19430 Lisp_Object face_name
= Qnil
;
19431 int ascent
, descent
, height
;
19433 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
19438 face_name
= XCAR (val
);
19440 if (!NUMBERP (val
))
19441 val
= make_number (1);
19442 if (NILP (face_name
))
19444 height
= it
->ascent
+ it
->descent
;
19449 if (NILP (face_name
))
19451 font
= FRAME_FONT (it
->f
);
19452 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19454 else if (EQ (face_name
, Qt
))
19462 struct font_info
*font_info
;
19464 face_id
= lookup_named_face (it
->f
, face_name
, 0);
19466 return make_number (-1);
19468 face
= FACE_FROM_ID (it
->f
, face_id
);
19471 return make_number (-1);
19473 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19474 boff
= font_info
->baseline_offset
;
19475 if (font_info
->vertical_centering
)
19476 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19479 ascent
= FONT_BASE (font
) + boff
;
19480 descent
= FONT_DESCENT (font
) - boff
;
19484 it
->override_ascent
= ascent
;
19485 it
->override_descent
= descent
;
19486 it
->override_boff
= boff
;
19489 height
= ascent
+ descent
;
19493 height
= (int)(XFLOAT_DATA (val
) * height
);
19494 else if (INTEGERP (val
))
19495 height
*= XINT (val
);
19497 return make_number (height
);
19502 Produce glyphs/get display metrics for the display element IT is
19503 loaded with. See the description of struct display_iterator in
19504 dispextern.h for an overview of struct display_iterator. */
19507 x_produce_glyphs (it
)
19510 int extra_line_spacing
= it
->extra_line_spacing
;
19512 it
->glyph_not_available_p
= 0;
19514 if (it
->what
== IT_CHARACTER
)
19518 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19520 int font_not_found_p
;
19521 struct font_info
*font_info
;
19522 int boff
; /* baseline offset */
19523 /* We may change it->multibyte_p upon unibyte<->multibyte
19524 conversion. So, save the current value now and restore it
19527 Note: It seems that we don't have to record multibyte_p in
19528 struct glyph because the character code itself tells if or
19529 not the character is multibyte. Thus, in the future, we must
19530 consider eliminating the field `multibyte_p' in the struct
19532 int saved_multibyte_p
= it
->multibyte_p
;
19534 /* Maybe translate single-byte characters to multibyte, or the
19536 it
->char_to_display
= it
->c
;
19537 if (!ASCII_BYTE_P (it
->c
)
19538 && ! it
->multibyte_p
)
19540 if (SINGLE_BYTE_CHAR_P (it
->c
)
19541 && unibyte_display_via_language_environment
)
19542 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19543 if (! SINGLE_BYTE_CHAR_P (it
->c
))
19545 it
->multibyte_p
= 1;
19546 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
,
19548 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19552 /* Get font to use. Encode IT->char_to_display. */
19553 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19554 &char2b
, it
->multibyte_p
, 0);
19557 /* When no suitable font found, use the default font. */
19558 font_not_found_p
= font
== NULL
;
19559 if (font_not_found_p
)
19561 font
= FRAME_FONT (it
->f
);
19562 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19567 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19568 boff
= font_info
->baseline_offset
;
19569 if (font_info
->vertical_centering
)
19570 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19573 if (it
->char_to_display
>= ' '
19574 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
19576 /* Either unibyte or ASCII. */
19581 pcm
= rif
->per_char_metric (font
, &char2b
,
19582 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
19584 if (it
->override_ascent
>= 0)
19586 it
->ascent
= it
->override_ascent
;
19587 it
->descent
= it
->override_descent
;
19588 boff
= it
->override_boff
;
19592 it
->ascent
= FONT_BASE (font
) + boff
;
19593 it
->descent
= FONT_DESCENT (font
) - boff
;
19598 it
->phys_ascent
= pcm
->ascent
+ boff
;
19599 it
->phys_descent
= pcm
->descent
- boff
;
19600 it
->pixel_width
= pcm
->width
;
19604 it
->glyph_not_available_p
= 1;
19605 it
->phys_ascent
= it
->ascent
;
19606 it
->phys_descent
= it
->descent
;
19607 it
->pixel_width
= FONT_WIDTH (font
);
19610 if (it
->constrain_row_ascent_descent_p
)
19612 if (it
->descent
> it
->max_descent
)
19614 it
->ascent
+= it
->descent
- it
->max_descent
;
19615 it
->descent
= it
->max_descent
;
19617 if (it
->ascent
> it
->max_ascent
)
19619 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19620 it
->ascent
= it
->max_ascent
;
19622 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19623 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19624 extra_line_spacing
= 0;
19627 /* If this is a space inside a region of text with
19628 `space-width' property, change its width. */
19629 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
19631 it
->pixel_width
*= XFLOATINT (it
->space_width
);
19633 /* If face has a box, add the box thickness to the character
19634 height. If character has a box line to the left and/or
19635 right, add the box line width to the character's width. */
19636 if (face
->box
!= FACE_NO_BOX
)
19638 int thick
= face
->box_line_width
;
19642 it
->ascent
+= thick
;
19643 it
->descent
+= thick
;
19648 if (it
->start_of_box_run_p
)
19649 it
->pixel_width
+= thick
;
19650 if (it
->end_of_box_run_p
)
19651 it
->pixel_width
+= thick
;
19654 /* If face has an overline, add the height of the overline
19655 (1 pixel) and a 1 pixel margin to the character height. */
19656 if (face
->overline_p
)
19659 if (it
->constrain_row_ascent_descent_p
)
19661 if (it
->ascent
> it
->max_ascent
)
19662 it
->ascent
= it
->max_ascent
;
19663 if (it
->descent
> it
->max_descent
)
19664 it
->descent
= it
->max_descent
;
19667 take_vertical_position_into_account (it
);
19669 /* If we have to actually produce glyphs, do it. */
19674 /* Translate a space with a `space-width' property
19675 into a stretch glyph. */
19676 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
19677 / FONT_HEIGHT (font
));
19678 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19679 it
->ascent
+ it
->descent
, ascent
);
19684 /* If characters with lbearing or rbearing are displayed
19685 in this line, record that fact in a flag of the
19686 glyph row. This is used to optimize X output code. */
19687 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
19688 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19691 else if (it
->char_to_display
== '\n')
19693 /* A newline has no width but we need the height of the line.
19694 But if previous part of the line set a height, don't
19695 increase that height */
19697 Lisp_Object height
;
19698 Lisp_Object total_height
= Qnil
;
19700 it
->override_ascent
= -1;
19701 it
->pixel_width
= 0;
19704 height
= get_line_height_property(it
, Qline_height
);
19705 /* Split (line-height total-height) list */
19707 && CONSP (XCDR (height
))
19708 && NILP (XCDR (XCDR (height
))))
19710 total_height
= XCAR (XCDR (height
));
19711 height
= XCAR (height
);
19713 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
19715 if (it
->override_ascent
>= 0)
19717 it
->ascent
= it
->override_ascent
;
19718 it
->descent
= it
->override_descent
;
19719 boff
= it
->override_boff
;
19723 it
->ascent
= FONT_BASE (font
) + boff
;
19724 it
->descent
= FONT_DESCENT (font
) - boff
;
19727 if (EQ (height
, Qt
))
19729 if (it
->descent
> it
->max_descent
)
19731 it
->ascent
+= it
->descent
- it
->max_descent
;
19732 it
->descent
= it
->max_descent
;
19734 if (it
->ascent
> it
->max_ascent
)
19736 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19737 it
->ascent
= it
->max_ascent
;
19739 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19740 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19741 it
->constrain_row_ascent_descent_p
= 1;
19742 extra_line_spacing
= 0;
19746 Lisp_Object spacing
;
19748 it
->phys_ascent
= it
->ascent
;
19749 it
->phys_descent
= it
->descent
;
19751 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
19752 && face
->box
!= FACE_NO_BOX
19753 && face
->box_line_width
> 0)
19755 it
->ascent
+= face
->box_line_width
;
19756 it
->descent
+= face
->box_line_width
;
19759 && XINT (height
) > it
->ascent
+ it
->descent
)
19760 it
->ascent
= XINT (height
) - it
->descent
;
19762 if (!NILP (total_height
))
19763 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
19766 spacing
= get_line_height_property(it
, Qline_spacing
);
19767 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
19769 if (INTEGERP (spacing
))
19771 extra_line_spacing
= XINT (spacing
);
19772 if (!NILP (total_height
))
19773 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
19777 else if (it
->char_to_display
== '\t')
19779 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
19780 int x
= it
->current_x
+ it
->continuation_lines_width
;
19781 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
19783 /* If the distance from the current position to the next tab
19784 stop is less than a space character width, use the
19785 tab stop after that. */
19786 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
19787 next_tab_x
+= tab_width
;
19789 it
->pixel_width
= next_tab_x
- x
;
19791 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
19792 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19796 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19797 it
->ascent
+ it
->descent
, it
->ascent
);
19802 /* A multi-byte character. Assume that the display width of the
19803 character is the width of the character multiplied by the
19804 width of the font. */
19806 /* If we found a font, this font should give us the right
19807 metrics. If we didn't find a font, use the frame's
19808 default font and calculate the width of the character by
19809 multiplying the width of font by the width of the
19812 pcm
= rif
->per_char_metric (font
, &char2b
,
19813 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
19815 if (font_not_found_p
|| !pcm
)
19817 it
->glyph_not_available_p
= 1;
19818 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
19819 * CHAR_WIDTH (it
->char_to_display
));
19820 it
->phys_ascent
= FONT_BASE (font
) + boff
;
19821 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19825 it
->pixel_width
= pcm
->width
;
19826 it
->phys_ascent
= pcm
->ascent
+ boff
;
19827 it
->phys_descent
= pcm
->descent
- boff
;
19829 && (pcm
->lbearing
< 0
19830 || pcm
->rbearing
> pcm
->width
))
19831 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19834 it
->ascent
= FONT_BASE (font
) + boff
;
19835 it
->descent
= FONT_DESCENT (font
) - boff
;
19836 if (face
->box
!= FACE_NO_BOX
)
19838 int thick
= face
->box_line_width
;
19842 it
->ascent
+= thick
;
19843 it
->descent
+= thick
;
19848 if (it
->start_of_box_run_p
)
19849 it
->pixel_width
+= thick
;
19850 if (it
->end_of_box_run_p
)
19851 it
->pixel_width
+= thick
;
19854 /* If face has an overline, add the height of the overline
19855 (1 pixel) and a 1 pixel margin to the character height. */
19856 if (face
->overline_p
)
19859 take_vertical_position_into_account (it
);
19864 it
->multibyte_p
= saved_multibyte_p
;
19866 else if (it
->what
== IT_COMPOSITION
)
19868 /* Note: A composition is represented as one glyph in the
19869 glyph matrix. There are no padding glyphs. */
19872 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19874 int font_not_found_p
;
19875 struct font_info
*font_info
;
19876 int boff
; /* baseline offset */
19877 struct composition
*cmp
= composition_table
[it
->cmp_id
];
19880 /* Maybe translate single-byte characters to multibyte. */
19881 it
->char_to_display
= it
->c
;
19882 if (unibyte_display_via_language_environment
19885 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19888 /* Get face and font to use. Encode IT->char_to_display. */
19889 pos
= STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
) : IT_CHARPOS (*it
);
19890 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
,
19892 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19893 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19894 &char2b
, it
->multibyte_p
, 0);
19897 /* When no suitable font found, use the default font. */
19898 font_not_found_p
= font
== NULL
;
19899 if (font_not_found_p
)
19901 font
= FRAME_FONT (it
->f
);
19902 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19907 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19908 boff
= font_info
->baseline_offset
;
19909 if (font_info
->vertical_centering
)
19910 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19913 /* There are no padding glyphs, so there is only one glyph to
19914 produce for the composition. Important is that pixel_width,
19915 ascent and descent are the values of what is drawn by
19916 draw_glyphs (i.e. the values of the overall glyphs composed). */
19919 /* If we have not yet calculated pixel size data of glyphs of
19920 the composition for the current face font, calculate them
19921 now. Theoretically, we have to check all fonts for the
19922 glyphs, but that requires much time and memory space. So,
19923 here we check only the font of the first glyph. This leads
19924 to incorrect display, but it's very rare, and C-l (recenter)
19925 can correct the display anyway. */
19926 if (cmp
->glyph_len
== 0)
19928 cmp
->lbearing
= cmp
->rbearing
= 0;
19929 cmp
->pixel_width
= cmp
->ascent
= cmp
->descent
= 0;
19931 else if (cmp
->font
!= (void *) font
)
19933 /* Ascent and descent of the font of the first character of
19934 this composition (adjusted by baseline offset). Ascent
19935 and descent of overall glyphs should not be less than
19936 them respectively. */
19937 int font_ascent
= FONT_BASE (font
) + boff
;
19938 int font_descent
= FONT_DESCENT (font
) - boff
;
19939 int font_height
= FONT_HEIGHT (font
);
19940 /* Bounding box of the overall glyphs. */
19941 int leftmost
, rightmost
, lowest
, highest
;
19942 int lbearing
, rbearing
;
19943 int i
, width
, ascent
, descent
;
19945 cmp
->font
= (void *) font
;
19947 /* Initialize the bounding box. */
19949 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19950 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
19952 width
= pcm
->width
;
19953 ascent
= pcm
->ascent
;
19954 descent
= pcm
->descent
;
19955 lbearing
= pcm
->lbearing
;
19958 rbearing
= pcm
->rbearing
;
19959 if (rbearing
< width
)
19964 width
= FONT_WIDTH (font
);
19965 ascent
= FONT_BASE (font
);
19966 descent
= FONT_DESCENT (font
);
19972 lowest
= - descent
+ boff
;
19973 highest
= ascent
+ boff
;
19977 && font_info
->default_ascent
19978 && CHAR_TABLE_P (Vuse_default_ascent
)
19979 && !NILP (Faref (Vuse_default_ascent
,
19980 make_number (it
->char_to_display
))))
19981 highest
= font_info
->default_ascent
+ boff
;
19983 /* Draw the first glyph at the normal position. It may be
19984 shifted to right later if some other glyphs are drawn at
19986 cmp
->offsets
[0] = 0;
19987 cmp
->offsets
[1] = boff
;
19988 cmp
->lbearing
= lbearing
;
19989 cmp
->rbearing
= rbearing
;
19991 /* Set cmp->offsets for the remaining glyphs. */
19992 for (i
= 1; i
< cmp
->glyph_len
; i
++)
19994 int left
, right
, btm
, top
;
19995 int ch
= COMPOSITION_GLYPH (cmp
, i
);
19996 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
19998 face
= FACE_FROM_ID (it
->f
, face_id
);
19999 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
20000 &char2b
, it
->multibyte_p
, 0);
20004 font
= FRAME_FONT (it
->f
);
20005 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20011 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20012 boff
= font_info
->baseline_offset
;
20013 if (font_info
->vertical_centering
)
20014 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20018 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20019 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
20021 width
= pcm
->width
;
20022 ascent
= pcm
->ascent
;
20023 descent
= pcm
->descent
;
20024 lbearing
= pcm
->lbearing
;
20027 rbearing
= pcm
->rbearing
;
20028 if (rbearing
< width
)
20033 width
= FONT_WIDTH (font
);
20040 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
20042 /* Relative composition with or without
20043 alternate chars. */
20044 left
= (leftmost
+ rightmost
- width
) / 2;
20045 btm
= - descent
+ boff
;
20046 if (font_info
&& font_info
->relative_compose
20047 && (! CHAR_TABLE_P (Vignore_relative_composition
)
20048 || NILP (Faref (Vignore_relative_composition
,
20049 make_number (ch
)))))
20052 if (- descent
>= font_info
->relative_compose
)
20053 /* One extra pixel between two glyphs. */
20055 else if (ascent
<= 0)
20056 /* One extra pixel between two glyphs. */
20057 btm
= lowest
- 1 - ascent
- descent
;
20062 /* A composition rule is specified by an integer
20063 value that encodes global and new reference
20064 points (GREF and NREF). GREF and NREF are
20065 specified by numbers as below:
20067 0---1---2 -- ascent
20071 9--10--11 -- center
20073 ---3---4---5--- baseline
20075 6---7---8 -- descent
20077 int rule
= COMPOSITION_RULE (cmp
, i
);
20078 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
20080 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
20081 grefx
= gref
% 3, nrefx
= nref
% 3;
20082 grefy
= gref
/ 3, nrefy
= nref
/ 3;
20084 xoff
= font_height
* (xoff
- 128) / 256;
20086 yoff
= font_height
* (yoff
- 128) / 256;
20089 + grefx
* (rightmost
- leftmost
) / 2
20090 - nrefx
* width
/ 2
20093 btm
= ((grefy
== 0 ? highest
20095 : grefy
== 2 ? lowest
20096 : (highest
+ lowest
) / 2)
20097 - (nrefy
== 0 ? ascent
+ descent
20098 : nrefy
== 1 ? descent
- boff
20100 : (ascent
+ descent
) / 2)
20104 cmp
->offsets
[i
* 2] = left
;
20105 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
20107 /* Update the bounding box of the overall glyphs. */
20110 right
= left
+ width
;
20111 if (left
< leftmost
)
20113 if (right
> rightmost
)
20116 top
= btm
+ descent
+ ascent
;
20122 if (cmp
->lbearing
> left
+ lbearing
)
20123 cmp
->lbearing
= left
+ lbearing
;
20124 if (cmp
->rbearing
< left
+ rbearing
)
20125 cmp
->rbearing
= left
+ rbearing
;
20128 /* If there are glyphs whose x-offsets are negative,
20129 shift all glyphs to the right and make all x-offsets
20133 for (i
= 0; i
< cmp
->glyph_len
; i
++)
20134 cmp
->offsets
[i
* 2] -= leftmost
;
20135 rightmost
-= leftmost
;
20136 cmp
->lbearing
-= leftmost
;
20137 cmp
->rbearing
-= leftmost
;
20140 cmp
->pixel_width
= rightmost
;
20141 cmp
->ascent
= highest
;
20142 cmp
->descent
= - lowest
;
20143 if (cmp
->ascent
< font_ascent
)
20144 cmp
->ascent
= font_ascent
;
20145 if (cmp
->descent
< font_descent
)
20146 cmp
->descent
= font_descent
;
20150 && (cmp
->lbearing
< 0
20151 || cmp
->rbearing
> cmp
->pixel_width
))
20152 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20154 it
->pixel_width
= cmp
->pixel_width
;
20155 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
20156 it
->descent
= it
->phys_descent
= cmp
->descent
;
20158 if (face
->box
!= FACE_NO_BOX
)
20160 int thick
= face
->box_line_width
;
20164 it
->ascent
+= thick
;
20165 it
->descent
+= thick
;
20170 if (it
->start_of_box_run_p
)
20171 it
->pixel_width
+= thick
;
20172 if (it
->end_of_box_run_p
)
20173 it
->pixel_width
+= thick
;
20176 /* If face has an overline, add the height of the overline
20177 (1 pixel) and a 1 pixel margin to the character height. */
20178 if (face
->overline_p
)
20181 take_vertical_position_into_account (it
);
20184 append_composite_glyph (it
);
20186 else if (it
->what
== IT_IMAGE
)
20187 produce_image_glyph (it
);
20188 else if (it
->what
== IT_STRETCH
)
20189 produce_stretch_glyph (it
);
20191 /* Accumulate dimensions. Note: can't assume that it->descent > 0
20192 because this isn't true for images with `:ascent 100'. */
20193 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
20194 if (it
->area
== TEXT_AREA
)
20195 it
->current_x
+= it
->pixel_width
;
20197 if (extra_line_spacing
> 0)
20199 it
->descent
+= extra_line_spacing
;
20200 if (extra_line_spacing
> it
->max_extra_line_spacing
)
20201 it
->max_extra_line_spacing
= extra_line_spacing
;
20204 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
20205 it
->max_descent
= max (it
->max_descent
, it
->descent
);
20206 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
20207 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
20211 Output LEN glyphs starting at START at the nominal cursor position.
20212 Advance the nominal cursor over the text. The global variable
20213 updated_window contains the window being updated, updated_row is
20214 the glyph row being updated, and updated_area is the area of that
20215 row being updated. */
20218 x_write_glyphs (start
, len
)
20219 struct glyph
*start
;
20224 xassert (updated_window
&& updated_row
);
20227 /* Write glyphs. */
20229 hpos
= start
- updated_row
->glyphs
[updated_area
];
20230 x
= draw_glyphs (updated_window
, output_cursor
.x
,
20231 updated_row
, updated_area
,
20233 DRAW_NORMAL_TEXT
, 0);
20235 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
20236 if (updated_area
== TEXT_AREA
20237 && updated_window
->phys_cursor_on_p
20238 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
20239 && updated_window
->phys_cursor
.hpos
>= hpos
20240 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
20241 updated_window
->phys_cursor_on_p
= 0;
20245 /* Advance the output cursor. */
20246 output_cursor
.hpos
+= len
;
20247 output_cursor
.x
= x
;
20252 Insert LEN glyphs from START at the nominal cursor position. */
20255 x_insert_glyphs (start
, len
)
20256 struct glyph
*start
;
20261 int line_height
, shift_by_width
, shifted_region_width
;
20262 struct glyph_row
*row
;
20263 struct glyph
*glyph
;
20264 int frame_x
, frame_y
;
20267 xassert (updated_window
&& updated_row
);
20269 w
= updated_window
;
20270 f
= XFRAME (WINDOW_FRAME (w
));
20272 /* Get the height of the line we are in. */
20274 line_height
= row
->height
;
20276 /* Get the width of the glyphs to insert. */
20277 shift_by_width
= 0;
20278 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
20279 shift_by_width
+= glyph
->pixel_width
;
20281 /* Get the width of the region to shift right. */
20282 shifted_region_width
= (window_box_width (w
, updated_area
)
20287 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
20288 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
20290 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
20291 line_height
, shift_by_width
);
20293 /* Write the glyphs. */
20294 hpos
= start
- row
->glyphs
[updated_area
];
20295 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
20297 DRAW_NORMAL_TEXT
, 0);
20299 /* Advance the output cursor. */
20300 output_cursor
.hpos
+= len
;
20301 output_cursor
.x
+= shift_by_width
;
20307 Erase the current text line from the nominal cursor position
20308 (inclusive) to pixel column TO_X (exclusive). The idea is that
20309 everything from TO_X onward is already erased.
20311 TO_X is a pixel position relative to updated_area of
20312 updated_window. TO_X == -1 means clear to the end of this area. */
20315 x_clear_end_of_line (to_x
)
20319 struct window
*w
= updated_window
;
20320 int max_x
, min_y
, max_y
;
20321 int from_x
, from_y
, to_y
;
20323 xassert (updated_window
&& updated_row
);
20324 f
= XFRAME (w
->frame
);
20326 if (updated_row
->full_width_p
)
20327 max_x
= WINDOW_TOTAL_WIDTH (w
);
20329 max_x
= window_box_width (w
, updated_area
);
20330 max_y
= window_text_bottom_y (w
);
20332 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
20333 of window. For TO_X > 0, truncate to end of drawing area. */
20339 to_x
= min (to_x
, max_x
);
20341 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
20343 /* Notice if the cursor will be cleared by this operation. */
20344 if (!updated_row
->full_width_p
)
20345 notice_overwritten_cursor (w
, updated_area
,
20346 output_cursor
.x
, -1,
20348 MATRIX_ROW_BOTTOM_Y (updated_row
));
20350 from_x
= output_cursor
.x
;
20352 /* Translate to frame coordinates. */
20353 if (updated_row
->full_width_p
)
20355 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
20356 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
20360 int area_left
= window_box_left (w
, updated_area
);
20361 from_x
+= area_left
;
20365 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
20366 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
20367 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
20369 /* Prevent inadvertently clearing to end of the X window. */
20370 if (to_x
> from_x
&& to_y
> from_y
)
20373 rif
->clear_frame_area (f
, from_x
, from_y
,
20374 to_x
- from_x
, to_y
- from_y
);
20379 #endif /* HAVE_WINDOW_SYSTEM */
20383 /***********************************************************************
20385 ***********************************************************************/
20387 /* Value is the internal representation of the specified cursor type
20388 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
20389 of the bar cursor. */
20391 static enum text_cursor_kinds
20392 get_specified_cursor_type (arg
, width
)
20396 enum text_cursor_kinds type
;
20401 if (EQ (arg
, Qbox
))
20402 return FILLED_BOX_CURSOR
;
20404 if (EQ (arg
, Qhollow
))
20405 return HOLLOW_BOX_CURSOR
;
20407 if (EQ (arg
, Qbar
))
20414 && EQ (XCAR (arg
), Qbar
)
20415 && INTEGERP (XCDR (arg
))
20416 && XINT (XCDR (arg
)) >= 0)
20418 *width
= XINT (XCDR (arg
));
20422 if (EQ (arg
, Qhbar
))
20425 return HBAR_CURSOR
;
20429 && EQ (XCAR (arg
), Qhbar
)
20430 && INTEGERP (XCDR (arg
))
20431 && XINT (XCDR (arg
)) >= 0)
20433 *width
= XINT (XCDR (arg
));
20434 return HBAR_CURSOR
;
20437 /* Treat anything unknown as "hollow box cursor".
20438 It was bad to signal an error; people have trouble fixing
20439 .Xdefaults with Emacs, when it has something bad in it. */
20440 type
= HOLLOW_BOX_CURSOR
;
20445 /* Set the default cursor types for specified frame. */
20447 set_frame_cursor_types (f
, arg
)
20454 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
20455 FRAME_CURSOR_WIDTH (f
) = width
;
20457 /* By default, set up the blink-off state depending on the on-state. */
20459 tem
= Fassoc (arg
, Vblink_cursor_alist
);
20462 FRAME_BLINK_OFF_CURSOR (f
)
20463 = get_specified_cursor_type (XCDR (tem
), &width
);
20464 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
20467 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
20471 /* Return the cursor we want to be displayed in window W. Return
20472 width of bar/hbar cursor through WIDTH arg. Return with
20473 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
20474 (i.e. if the `system caret' should track this cursor).
20476 In a mini-buffer window, we want the cursor only to appear if we
20477 are reading input from this window. For the selected window, we
20478 want the cursor type given by the frame parameter or buffer local
20479 setting of cursor-type. If explicitly marked off, draw no cursor.
20480 In all other cases, we want a hollow box cursor. */
20482 static enum text_cursor_kinds
20483 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
20485 struct glyph
*glyph
;
20487 int *active_cursor
;
20489 struct frame
*f
= XFRAME (w
->frame
);
20490 struct buffer
*b
= XBUFFER (w
->buffer
);
20491 int cursor_type
= DEFAULT_CURSOR
;
20492 Lisp_Object alt_cursor
;
20493 int non_selected
= 0;
20495 *active_cursor
= 1;
20498 if (cursor_in_echo_area
20499 && FRAME_HAS_MINIBUF_P (f
)
20500 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
20502 if (w
== XWINDOW (echo_area_window
))
20504 *width
= FRAME_CURSOR_WIDTH (f
);
20505 return FRAME_DESIRED_CURSOR (f
);
20508 *active_cursor
= 0;
20512 /* Nonselected window or nonselected frame. */
20513 else if (w
!= XWINDOW (f
->selected_window
)
20514 #ifdef HAVE_WINDOW_SYSTEM
20515 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
20519 *active_cursor
= 0;
20521 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
20527 /* Never display a cursor in a window in which cursor-type is nil. */
20528 if (NILP (b
->cursor_type
))
20531 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
20534 alt_cursor
= XBUFFER (w
->buffer
)->cursor_in_non_selected_windows
;
20535 return get_specified_cursor_type (alt_cursor
, width
);
20538 /* Get the normal cursor type for this window. */
20539 if (EQ (b
->cursor_type
, Qt
))
20541 cursor_type
= FRAME_DESIRED_CURSOR (f
);
20542 *width
= FRAME_CURSOR_WIDTH (f
);
20545 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
20547 /* Use normal cursor if not blinked off. */
20548 if (!w
->cursor_off_p
)
20550 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
20551 if (cursor_type
== FILLED_BOX_CURSOR
)
20552 cursor_type
= HOLLOW_BOX_CURSOR
;
20554 return cursor_type
;
20557 /* Cursor is blinked off, so determine how to "toggle" it. */
20559 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
20560 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
20561 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
20563 /* Then see if frame has specified a specific blink off cursor type. */
20564 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
20566 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
20567 return FRAME_BLINK_OFF_CURSOR (f
);
20571 /* Some people liked having a permanently visible blinking cursor,
20572 while others had very strong opinions against it. So it was
20573 decided to remove it. KFS 2003-09-03 */
20575 /* Finally perform built-in cursor blinking:
20576 filled box <-> hollow box
20577 wide [h]bar <-> narrow [h]bar
20578 narrow [h]bar <-> no cursor
20579 other type <-> no cursor */
20581 if (cursor_type
== FILLED_BOX_CURSOR
)
20582 return HOLLOW_BOX_CURSOR
;
20584 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
20587 return cursor_type
;
20595 #ifdef HAVE_WINDOW_SYSTEM
20597 /* Notice when the text cursor of window W has been completely
20598 overwritten by a drawing operation that outputs glyphs in AREA
20599 starting at X0 and ending at X1 in the line starting at Y0 and
20600 ending at Y1. X coordinates are area-relative. X1 < 0 means all
20601 the rest of the line after X0 has been written. Y coordinates
20602 are window-relative. */
20605 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
20607 enum glyph_row_area area
;
20608 int x0
, y0
, x1
, y1
;
20610 int cx0
, cx1
, cy0
, cy1
;
20611 struct glyph_row
*row
;
20613 if (!w
->phys_cursor_on_p
)
20615 if (area
!= TEXT_AREA
)
20618 if (w
->phys_cursor
.vpos
< 0
20619 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
20620 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
20621 !(row
->enabled_p
&& row
->displays_text_p
)))
20624 if (row
->cursor_in_fringe_p
)
20626 row
->cursor_in_fringe_p
= 0;
20627 draw_fringe_bitmap (w
, row
, 0);
20628 w
->phys_cursor_on_p
= 0;
20632 cx0
= w
->phys_cursor
.x
;
20633 cx1
= cx0
+ w
->phys_cursor_width
;
20634 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
20637 /* The cursor image will be completely removed from the
20638 screen if the output area intersects the cursor area in
20639 y-direction. When we draw in [y0 y1[, and some part of
20640 the cursor is at y < y0, that part must have been drawn
20641 before. When scrolling, the cursor is erased before
20642 actually scrolling, so we don't come here. When not
20643 scrolling, the rows above the old cursor row must have
20644 changed, and in this case these rows must have written
20645 over the cursor image.
20647 Likewise if part of the cursor is below y1, with the
20648 exception of the cursor being in the first blank row at
20649 the buffer and window end because update_text_area
20650 doesn't draw that row. (Except when it does, but
20651 that's handled in update_text_area.) */
20653 cy0
= w
->phys_cursor
.y
;
20654 cy1
= cy0
+ w
->phys_cursor_height
;
20655 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
20658 w
->phys_cursor_on_p
= 0;
20661 #endif /* HAVE_WINDOW_SYSTEM */
20664 /************************************************************************
20666 ************************************************************************/
20668 #ifdef HAVE_WINDOW_SYSTEM
20671 Fix the display of area AREA of overlapping row ROW in window W. */
20674 x_fix_overlapping_area (w
, row
, area
)
20676 struct glyph_row
*row
;
20677 enum glyph_row_area area
;
20684 for (i
= 0; i
< row
->used
[area
];)
20686 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
20688 int start
= i
, start_x
= x
;
20692 x
+= row
->glyphs
[area
][i
].pixel_width
;
20695 while (i
< row
->used
[area
]
20696 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
20698 draw_glyphs (w
, start_x
, row
, area
,
20700 DRAW_NORMAL_TEXT
, 1);
20704 x
+= row
->glyphs
[area
][i
].pixel_width
;
20714 Draw the cursor glyph of window W in glyph row ROW. See the
20715 comment of draw_glyphs for the meaning of HL. */
20718 draw_phys_cursor_glyph (w
, row
, hl
)
20720 struct glyph_row
*row
;
20721 enum draw_glyphs_face hl
;
20723 /* If cursor hpos is out of bounds, don't draw garbage. This can
20724 happen in mini-buffer windows when switching between echo area
20725 glyphs and mini-buffer. */
20726 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
20728 int on_p
= w
->phys_cursor_on_p
;
20730 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
20731 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
20733 w
->phys_cursor_on_p
= on_p
;
20735 if (hl
== DRAW_CURSOR
)
20736 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
20737 /* When we erase the cursor, and ROW is overlapped by other
20738 rows, make sure that these overlapping parts of other rows
20740 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
20742 if (row
> w
->current_matrix
->rows
20743 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
20744 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
20746 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
20747 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
20748 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
20755 Erase the image of a cursor of window W from the screen. */
20758 erase_phys_cursor (w
)
20761 struct frame
*f
= XFRAME (w
->frame
);
20762 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20763 int hpos
= w
->phys_cursor
.hpos
;
20764 int vpos
= w
->phys_cursor
.vpos
;
20765 int mouse_face_here_p
= 0;
20766 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
20767 struct glyph_row
*cursor_row
;
20768 struct glyph
*cursor_glyph
;
20769 enum draw_glyphs_face hl
;
20771 /* No cursor displayed or row invalidated => nothing to do on the
20773 if (w
->phys_cursor_type
== NO_CURSOR
)
20774 goto mark_cursor_off
;
20776 /* VPOS >= active_glyphs->nrows means that window has been resized.
20777 Don't bother to erase the cursor. */
20778 if (vpos
>= active_glyphs
->nrows
)
20779 goto mark_cursor_off
;
20781 /* If row containing cursor is marked invalid, there is nothing we
20783 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
20784 if (!cursor_row
->enabled_p
)
20785 goto mark_cursor_off
;
20787 /* If line spacing is > 0, old cursor may only be partially visible in
20788 window after split-window. So adjust visible height. */
20789 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
20790 window_text_bottom_y (w
) - cursor_row
->y
);
20792 /* If row is completely invisible, don't attempt to delete a cursor which
20793 isn't there. This can happen if cursor is at top of a window, and
20794 we switch to a buffer with a header line in that window. */
20795 if (cursor_row
->visible_height
<= 0)
20796 goto mark_cursor_off
;
20798 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
20799 if (cursor_row
->cursor_in_fringe_p
)
20801 cursor_row
->cursor_in_fringe_p
= 0;
20802 draw_fringe_bitmap (w
, cursor_row
, 0);
20803 goto mark_cursor_off
;
20806 /* This can happen when the new row is shorter than the old one.
20807 In this case, either draw_glyphs or clear_end_of_line
20808 should have cleared the cursor. Note that we wouldn't be
20809 able to erase the cursor in this case because we don't have a
20810 cursor glyph at hand. */
20811 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
20812 goto mark_cursor_off
;
20814 /* If the cursor is in the mouse face area, redisplay that when
20815 we clear the cursor. */
20816 if (! NILP (dpyinfo
->mouse_face_window
)
20817 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
20818 && (vpos
> dpyinfo
->mouse_face_beg_row
20819 || (vpos
== dpyinfo
->mouse_face_beg_row
20820 && hpos
>= dpyinfo
->mouse_face_beg_col
))
20821 && (vpos
< dpyinfo
->mouse_face_end_row
20822 || (vpos
== dpyinfo
->mouse_face_end_row
20823 && hpos
< dpyinfo
->mouse_face_end_col
))
20824 /* Don't redraw the cursor's spot in mouse face if it is at the
20825 end of a line (on a newline). The cursor appears there, but
20826 mouse highlighting does not. */
20827 && cursor_row
->used
[TEXT_AREA
] > hpos
)
20828 mouse_face_here_p
= 1;
20830 /* Maybe clear the display under the cursor. */
20831 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
20834 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
20837 cursor_glyph
= get_phys_cursor_glyph (w
);
20838 if (cursor_glyph
== NULL
)
20839 goto mark_cursor_off
;
20841 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
20842 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
20843 width
= min (cursor_glyph
->pixel_width
,
20844 window_box_width (w
, TEXT_AREA
) - w
->phys_cursor
.x
);
20846 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
20849 /* Erase the cursor by redrawing the character underneath it. */
20850 if (mouse_face_here_p
)
20851 hl
= DRAW_MOUSE_FACE
;
20853 hl
= DRAW_NORMAL_TEXT
;
20854 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
20857 w
->phys_cursor_on_p
= 0;
20858 w
->phys_cursor_type
= NO_CURSOR
;
20863 Display or clear cursor of window W. If ON is zero, clear the
20864 cursor. If it is non-zero, display the cursor. If ON is nonzero,
20865 where to put the cursor is specified by HPOS, VPOS, X and Y. */
20868 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
20870 int on
, hpos
, vpos
, x
, y
;
20872 struct frame
*f
= XFRAME (w
->frame
);
20873 int new_cursor_type
;
20874 int new_cursor_width
;
20876 struct glyph_row
*glyph_row
;
20877 struct glyph
*glyph
;
20879 /* This is pointless on invisible frames, and dangerous on garbaged
20880 windows and frames; in the latter case, the frame or window may
20881 be in the midst of changing its size, and x and y may be off the
20883 if (! FRAME_VISIBLE_P (f
)
20884 || FRAME_GARBAGED_P (f
)
20885 || vpos
>= w
->current_matrix
->nrows
20886 || hpos
>= w
->current_matrix
->matrix_w
)
20889 /* If cursor is off and we want it off, return quickly. */
20890 if (!on
&& !w
->phys_cursor_on_p
)
20893 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
20894 /* If cursor row is not enabled, we don't really know where to
20895 display the cursor. */
20896 if (!glyph_row
->enabled_p
)
20898 w
->phys_cursor_on_p
= 0;
20903 if (!glyph_row
->exact_window_width_line_p
20904 || hpos
< glyph_row
->used
[TEXT_AREA
])
20905 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
20907 xassert (interrupt_input_blocked
);
20909 /* Set new_cursor_type to the cursor we want to be displayed. */
20910 new_cursor_type
= get_window_cursor_type (w
, glyph
,
20911 &new_cursor_width
, &active_cursor
);
20913 /* If cursor is currently being shown and we don't want it to be or
20914 it is in the wrong place, or the cursor type is not what we want,
20916 if (w
->phys_cursor_on_p
20918 || w
->phys_cursor
.x
!= x
20919 || w
->phys_cursor
.y
!= y
20920 || new_cursor_type
!= w
->phys_cursor_type
20921 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
20922 && new_cursor_width
!= w
->phys_cursor_width
)))
20923 erase_phys_cursor (w
);
20925 /* Don't check phys_cursor_on_p here because that flag is only set
20926 to zero in some cases where we know that the cursor has been
20927 completely erased, to avoid the extra work of erasing the cursor
20928 twice. In other words, phys_cursor_on_p can be 1 and the cursor
20929 still not be visible, or it has only been partly erased. */
20932 w
->phys_cursor_ascent
= glyph_row
->ascent
;
20933 w
->phys_cursor_height
= glyph_row
->height
;
20935 /* Set phys_cursor_.* before x_draw_.* is called because some
20936 of them may need the information. */
20937 w
->phys_cursor
.x
= x
;
20938 w
->phys_cursor
.y
= glyph_row
->y
;
20939 w
->phys_cursor
.hpos
= hpos
;
20940 w
->phys_cursor
.vpos
= vpos
;
20943 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
20944 new_cursor_type
, new_cursor_width
,
20945 on
, active_cursor
);
20949 /* Switch the display of W's cursor on or off, according to the value
20953 update_window_cursor (w
, on
)
20957 /* Don't update cursor in windows whose frame is in the process
20958 of being deleted. */
20959 if (w
->current_matrix
)
20962 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20963 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20969 /* Call update_window_cursor with parameter ON_P on all leaf windows
20970 in the window tree rooted at W. */
20973 update_cursor_in_window_tree (w
, on_p
)
20979 if (!NILP (w
->hchild
))
20980 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
20981 else if (!NILP (w
->vchild
))
20982 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
20984 update_window_cursor (w
, on_p
);
20986 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
20992 Display the cursor on window W, or clear it, according to ON_P.
20993 Don't change the cursor's position. */
20996 x_update_cursor (f
, on_p
)
21000 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
21005 Clear the cursor of window W to background color, and mark the
21006 cursor as not shown. This is used when the text where the cursor
21007 is is about to be rewritten. */
21013 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
21014 update_window_cursor (w
, 0);
21019 Display the active region described by mouse_face_* according to DRAW. */
21022 show_mouse_face (dpyinfo
, draw
)
21023 Display_Info
*dpyinfo
;
21024 enum draw_glyphs_face draw
;
21026 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
21027 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21029 if (/* If window is in the process of being destroyed, don't bother
21031 w
->current_matrix
!= NULL
21032 /* Don't update mouse highlight if hidden */
21033 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
21034 /* Recognize when we are called to operate on rows that don't exist
21035 anymore. This can happen when a window is split. */
21036 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
21038 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
21039 struct glyph_row
*row
, *first
, *last
;
21041 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
21042 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
21044 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
21046 int start_hpos
, end_hpos
, start_x
;
21048 /* For all but the first row, the highlight starts at column 0. */
21051 start_hpos
= dpyinfo
->mouse_face_beg_col
;
21052 start_x
= dpyinfo
->mouse_face_beg_x
;
21061 end_hpos
= dpyinfo
->mouse_face_end_col
;
21063 end_hpos
= row
->used
[TEXT_AREA
];
21065 if (end_hpos
> start_hpos
)
21067 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
21068 start_hpos
, end_hpos
,
21072 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
21076 /* When we've written over the cursor, arrange for it to
21077 be displayed again. */
21078 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
21081 display_and_set_cursor (w
, 1,
21082 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21083 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21088 /* Change the mouse cursor. */
21089 if (draw
== DRAW_NORMAL_TEXT
)
21090 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
21091 else if (draw
== DRAW_MOUSE_FACE
)
21092 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
21094 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
21098 Clear out the mouse-highlighted active region.
21099 Redraw it un-highlighted first. Value is non-zero if mouse
21100 face was actually drawn unhighlighted. */
21103 clear_mouse_face (dpyinfo
)
21104 Display_Info
*dpyinfo
;
21108 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
21110 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
21114 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21115 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21116 dpyinfo
->mouse_face_window
= Qnil
;
21117 dpyinfo
->mouse_face_overlay
= Qnil
;
21123 Non-zero if physical cursor of window W is within mouse face. */
21126 cursor_in_mouse_face_p (w
)
21129 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21130 int in_mouse_face
= 0;
21132 if (WINDOWP (dpyinfo
->mouse_face_window
)
21133 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
21135 int hpos
= w
->phys_cursor
.hpos
;
21136 int vpos
= w
->phys_cursor
.vpos
;
21138 if (vpos
>= dpyinfo
->mouse_face_beg_row
21139 && vpos
<= dpyinfo
->mouse_face_end_row
21140 && (vpos
> dpyinfo
->mouse_face_beg_row
21141 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21142 && (vpos
< dpyinfo
->mouse_face_end_row
21143 || hpos
< dpyinfo
->mouse_face_end_col
21144 || dpyinfo
->mouse_face_past_end
))
21148 return in_mouse_face
;
21154 /* Find the glyph matrix position of buffer position CHARPOS in window
21155 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
21156 current glyphs must be up to date. If CHARPOS is above window
21157 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
21158 of last line in W. In the row containing CHARPOS, stop before glyphs
21159 having STOP as object. */
21161 #if 1 /* This is a version of fast_find_position that's more correct
21162 in the presence of hscrolling, for example. I didn't install
21163 it right away because the problem fixed is minor, it failed
21164 in 20.x as well, and I think it's too risky to install
21165 so near the release of 21.1. 2001-09-25 gerd. */
21168 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
21171 int *hpos
, *vpos
, *x
, *y
;
21174 struct glyph_row
*row
, *first
;
21175 struct glyph
*glyph
, *end
;
21178 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21179 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
21184 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
21188 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
21191 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
21195 /* If whole rows or last part of a row came from a display overlay,
21196 row_containing_pos will skip over such rows because their end pos
21197 equals the start pos of the overlay or interval.
21199 Move back if we have a STOP object and previous row's
21200 end glyph came from STOP. */
21203 struct glyph_row
*prev
;
21204 while ((prev
= row
- 1, prev
>= first
)
21205 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
21206 && prev
->used
[TEXT_AREA
] > 0)
21208 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
21209 glyph
= beg
+ prev
->used
[TEXT_AREA
];
21210 while (--glyph
>= beg
21211 && INTEGERP (glyph
->object
));
21213 || !EQ (stop
, glyph
->object
))
21221 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21223 glyph
= row
->glyphs
[TEXT_AREA
];
21224 end
= glyph
+ row
->used
[TEXT_AREA
];
21226 /* Skip over glyphs not having an object at the start of the row.
21227 These are special glyphs like truncation marks on terminal
21229 if (row
->displays_text_p
)
21231 && INTEGERP (glyph
->object
)
21232 && !EQ (stop
, glyph
->object
)
21233 && glyph
->charpos
< 0)
21235 *x
+= glyph
->pixel_width
;
21240 && !INTEGERP (glyph
->object
)
21241 && !EQ (stop
, glyph
->object
)
21242 && (!BUFFERP (glyph
->object
)
21243 || glyph
->charpos
< charpos
))
21245 *x
+= glyph
->pixel_width
;
21249 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
21256 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
21259 int *hpos
, *vpos
, *x
, *y
;
21264 int maybe_next_line_p
= 0;
21265 int line_start_position
;
21266 int yb
= window_text_bottom_y (w
);
21267 struct glyph_row
*row
, *best_row
;
21268 int row_vpos
, best_row_vpos
;
21271 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21272 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21274 while (row
->y
< yb
)
21276 if (row
->used
[TEXT_AREA
])
21277 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
21279 line_start_position
= 0;
21281 if (line_start_position
> pos
)
21283 /* If the position sought is the end of the buffer,
21284 don't include the blank lines at the bottom of the window. */
21285 else if (line_start_position
== pos
21286 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
21288 maybe_next_line_p
= 1;
21291 else if (line_start_position
> 0)
21294 best_row_vpos
= row_vpos
;
21297 if (row
->y
+ row
->height
>= yb
)
21304 /* Find the right column within BEST_ROW. */
21306 current_x
= best_row
->x
;
21307 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
21309 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
21310 int charpos
= glyph
->charpos
;
21312 if (BUFFERP (glyph
->object
))
21314 if (charpos
== pos
)
21317 *vpos
= best_row_vpos
;
21322 else if (charpos
> pos
)
21325 else if (EQ (glyph
->object
, stop
))
21330 current_x
+= glyph
->pixel_width
;
21333 /* If we're looking for the end of the buffer,
21334 and we didn't find it in the line we scanned,
21335 use the start of the following line. */
21336 if (maybe_next_line_p
)
21341 current_x
= best_row
->x
;
21344 *vpos
= best_row_vpos
;
21345 *hpos
= lastcol
+ 1;
21354 /* Find the position of the glyph for position POS in OBJECT in
21355 window W's current matrix, and return in *X, *Y the pixel
21356 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
21358 RIGHT_P non-zero means return the position of the right edge of the
21359 glyph, RIGHT_P zero means return the left edge position.
21361 If no glyph for POS exists in the matrix, return the position of
21362 the glyph with the next smaller position that is in the matrix, if
21363 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
21364 exists in the matrix, return the position of the glyph with the
21365 next larger position in OBJECT.
21367 Value is non-zero if a glyph was found. */
21370 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
21373 Lisp_Object object
;
21374 int *hpos
, *vpos
, *x
, *y
;
21377 int yb
= window_text_bottom_y (w
);
21378 struct glyph_row
*r
;
21379 struct glyph
*best_glyph
= NULL
;
21380 struct glyph_row
*best_row
= NULL
;
21383 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21384 r
->enabled_p
&& r
->y
< yb
;
21387 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
21388 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
21391 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
21392 if (EQ (g
->object
, object
))
21394 if (g
->charpos
== pos
)
21401 else if (best_glyph
== NULL
21402 || ((abs (g
->charpos
- pos
)
21403 < abs (best_glyph
->charpos
- pos
))
21406 : g
->charpos
> pos
)))
21420 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
21424 *x
+= best_glyph
->pixel_width
;
21429 *vpos
= best_row
- w
->current_matrix
->rows
;
21432 return best_glyph
!= NULL
;
21436 /* See if position X, Y is within a hot-spot of an image. */
21439 on_hot_spot_p (hot_spot
, x
, y
)
21440 Lisp_Object hot_spot
;
21443 if (!CONSP (hot_spot
))
21446 if (EQ (XCAR (hot_spot
), Qrect
))
21448 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
21449 Lisp_Object rect
= XCDR (hot_spot
);
21453 if (!CONSP (XCAR (rect
)))
21455 if (!CONSP (XCDR (rect
)))
21457 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
21459 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
21461 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
21463 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
21467 else if (EQ (XCAR (hot_spot
), Qcircle
))
21469 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
21470 Lisp_Object circ
= XCDR (hot_spot
);
21471 Lisp_Object lr
, lx0
, ly0
;
21473 && CONSP (XCAR (circ
))
21474 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
21475 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
21476 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
21478 double r
= XFLOATINT (lr
);
21479 double dx
= XINT (lx0
) - x
;
21480 double dy
= XINT (ly0
) - y
;
21481 return (dx
* dx
+ dy
* dy
<= r
* r
);
21484 else if (EQ (XCAR (hot_spot
), Qpoly
))
21486 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
21487 if (VECTORP (XCDR (hot_spot
)))
21489 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
21490 Lisp_Object
*poly
= v
->contents
;
21494 Lisp_Object lx
, ly
;
21497 /* Need an even number of coordinates, and at least 3 edges. */
21498 if (n
< 6 || n
& 1)
21501 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
21502 If count is odd, we are inside polygon. Pixels on edges
21503 may or may not be included depending on actual geometry of the
21505 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
21506 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
21508 x0
= XINT (lx
), y0
= XINT (ly
);
21509 for (i
= 0; i
< n
; i
+= 2)
21511 int x1
= x0
, y1
= y0
;
21512 if ((lx
= poly
[i
], !INTEGERP (lx
))
21513 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
21515 x0
= XINT (lx
), y0
= XINT (ly
);
21517 /* Does this segment cross the X line? */
21525 if (y
> y0
&& y
> y1
)
21527 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
21533 /* If we don't understand the format, pretend we're not in the hot-spot. */
21538 find_hot_spot (map
, x
, y
)
21542 while (CONSP (map
))
21544 if (CONSP (XCAR (map
))
21545 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
21553 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
21555 doc
: /* Lookup in image map MAP coordinates X and Y.
21556 An image map is an alist where each element has the format (AREA ID PLIST).
21557 An AREA is specified as either a rectangle, a circle, or a polygon:
21558 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
21559 pixel coordinates of the upper left and bottom right corners.
21560 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
21561 and the radius of the circle; r may be a float or integer.
21562 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
21563 vector describes one corner in the polygon.
21564 Returns the alist element for the first matching AREA in MAP. */)
21575 return find_hot_spot (map
, XINT (x
), XINT (y
));
21579 /* Display frame CURSOR, optionally using shape defined by POINTER. */
21581 define_frame_cursor1 (f
, cursor
, pointer
)
21584 Lisp_Object pointer
;
21586 /* Do not change cursor shape while dragging mouse. */
21587 if (!NILP (do_mouse_tracking
))
21590 if (!NILP (pointer
))
21592 if (EQ (pointer
, Qarrow
))
21593 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21594 else if (EQ (pointer
, Qhand
))
21595 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
21596 else if (EQ (pointer
, Qtext
))
21597 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21598 else if (EQ (pointer
, intern ("hdrag")))
21599 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21600 #ifdef HAVE_X_WINDOWS
21601 else if (EQ (pointer
, intern ("vdrag")))
21602 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
21604 else if (EQ (pointer
, intern ("hourglass")))
21605 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
21606 else if (EQ (pointer
, Qmodeline
))
21607 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
21609 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21612 if (cursor
!= No_Cursor
)
21613 rif
->define_frame_cursor (f
, cursor
);
21616 /* Take proper action when mouse has moved to the mode or header line
21617 or marginal area AREA of window W, x-position X and y-position Y.
21618 X is relative to the start of the text display area of W, so the
21619 width of bitmap areas and scroll bars must be subtracted to get a
21620 position relative to the start of the mode line. */
21623 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
21624 Lisp_Object window
;
21626 enum window_part area
;
21628 struct window
*w
= XWINDOW (window
);
21629 struct frame
*f
= XFRAME (w
->frame
);
21630 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21631 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21632 Lisp_Object pointer
= Qnil
;
21633 int charpos
, dx
, dy
, width
, height
;
21634 Lisp_Object string
, object
= Qnil
;
21635 Lisp_Object pos
, help
;
21637 Lisp_Object mouse_face
;
21638 int original_x_pixel
= x
;
21639 struct glyph
* glyph
= NULL
;
21640 struct glyph_row
*row
;
21642 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
21647 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
21648 &object
, &dx
, &dy
, &width
, &height
);
21650 row
= (area
== ON_MODE_LINE
21651 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
21652 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
21655 if (row
->mode_line_p
&& row
->enabled_p
)
21657 glyph
= row
->glyphs
[TEXT_AREA
];
21658 end
= glyph
+ row
->used
[TEXT_AREA
];
21660 for (x0
= original_x_pixel
;
21661 glyph
< end
&& x0
>= glyph
->pixel_width
;
21663 x0
-= glyph
->pixel_width
;
21671 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
21672 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
21673 &object
, &dx
, &dy
, &width
, &height
);
21678 if (IMAGEP (object
))
21680 Lisp_Object image_map
, hotspot
;
21681 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
21683 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
21685 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21687 Lisp_Object area_id
, plist
;
21689 area_id
= XCAR (hotspot
);
21690 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21691 If so, we could look for mouse-enter, mouse-leave
21692 properties in PLIST (and do something...). */
21693 hotspot
= XCDR (hotspot
);
21694 if (CONSP (hotspot
)
21695 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21697 pointer
= Fplist_get (plist
, Qpointer
);
21698 if (NILP (pointer
))
21700 help
= Fplist_get (plist
, Qhelp_echo
);
21703 help_echo_string
= help
;
21704 /* Is this correct? ++kfs */
21705 XSETWINDOW (help_echo_window
, w
);
21706 help_echo_object
= w
->buffer
;
21707 help_echo_pos
= charpos
;
21711 if (NILP (pointer
))
21712 pointer
= Fplist_get (XCDR (object
), QCpointer
);
21715 if (STRINGP (string
))
21717 pos
= make_number (charpos
);
21718 /* If we're on a string with `help-echo' text property, arrange
21719 for the help to be displayed. This is done by setting the
21720 global variable help_echo_string to the help string. */
21723 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
21726 help_echo_string
= help
;
21727 XSETWINDOW (help_echo_window
, w
);
21728 help_echo_object
= string
;
21729 help_echo_pos
= charpos
;
21733 if (NILP (pointer
))
21734 pointer
= Fget_text_property (pos
, Qpointer
, string
);
21736 /* Change the mouse pointer according to what is under X/Y. */
21737 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
21740 map
= Fget_text_property (pos
, Qlocal_map
, string
);
21741 if (!KEYMAPP (map
))
21742 map
= Fget_text_property (pos
, Qkeymap
, string
);
21743 if (!KEYMAPP (map
))
21744 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
21747 /* Change the mouse face according to what is under X/Y. */
21748 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
21749 if (!NILP (mouse_face
)
21750 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
21755 struct glyph
* tmp_glyph
;
21759 int total_pixel_width
;
21764 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
21765 Qmouse_face
, string
, Qnil
);
21767 b
= make_number (0);
21769 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
21771 e
= make_number (SCHARS (string
));
21773 /* Calculate the position(glyph position: GPOS) of GLYPH in
21774 displayed string. GPOS is different from CHARPOS.
21776 CHARPOS is the position of glyph in internal string
21777 object. A mode line string format has structures which
21778 is converted to a flatten by emacs lisp interpreter.
21779 The internal string is an element of the structures.
21780 The displayed string is the flatten string. */
21781 for (tmp_glyph
= glyph
- 1, gpos
= 0;
21782 tmp_glyph
->charpos
>= XINT (b
);
21783 tmp_glyph
--, gpos
++)
21785 if (!EQ (tmp_glyph
->object
, glyph
->object
))
21789 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
21790 displayed string holding GLYPH.
21792 GSEQ_LENGTH is different from SCHARS (STRING).
21793 SCHARS (STRING) returns the length of the internal string. */
21794 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
21795 tmp_glyph
->charpos
< XINT (e
);
21796 tmp_glyph
++, gseq_length
++)
21798 if (!EQ (tmp_glyph
->object
, glyph
->object
))
21802 total_pixel_width
= 0;
21803 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
21804 total_pixel_width
+= tmp_glyph
->pixel_width
;
21806 /* Pre calculation of re-rendering position */
21808 hpos
= (area
== ON_MODE_LINE
21809 ? (w
->current_matrix
)->nrows
- 1
21812 /* If the re-rendering position is included in the last
21813 re-rendering area, we should do nothing. */
21814 if ( EQ (window
, dpyinfo
->mouse_face_window
)
21815 && dpyinfo
->mouse_face_beg_col
<= vpos
21816 && vpos
< dpyinfo
->mouse_face_end_col
21817 && dpyinfo
->mouse_face_beg_row
== hpos
)
21820 if (clear_mouse_face (dpyinfo
))
21821 cursor
= No_Cursor
;
21823 dpyinfo
->mouse_face_beg_col
= vpos
;
21824 dpyinfo
->mouse_face_beg_row
= hpos
;
21826 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
21827 dpyinfo
->mouse_face_beg_y
= 0;
21829 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
21830 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
21832 dpyinfo
->mouse_face_end_x
= 0;
21833 dpyinfo
->mouse_face_end_y
= 0;
21835 dpyinfo
->mouse_face_past_end
= 0;
21836 dpyinfo
->mouse_face_window
= window
;
21838 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
21841 glyph
->face_id
, 1);
21842 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21844 if (NILP (pointer
))
21847 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
21848 clear_mouse_face (dpyinfo
);
21850 define_frame_cursor1 (f
, cursor
, pointer
);
21855 Take proper action when the mouse has moved to position X, Y on
21856 frame F as regards highlighting characters that have mouse-face
21857 properties. Also de-highlighting chars where the mouse was before.
21858 X and Y can be negative or out of range. */
21861 note_mouse_highlight (f
, x
, y
)
21865 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21866 enum window_part part
;
21867 Lisp_Object window
;
21869 Cursor cursor
= No_Cursor
;
21870 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
21873 /* When a menu is active, don't highlight because this looks odd. */
21874 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
21875 if (popup_activated ())
21879 if (NILP (Vmouse_highlight
)
21880 || !f
->glyphs_initialized_p
)
21883 dpyinfo
->mouse_face_mouse_x
= x
;
21884 dpyinfo
->mouse_face_mouse_y
= y
;
21885 dpyinfo
->mouse_face_mouse_frame
= f
;
21887 if (dpyinfo
->mouse_face_defer
)
21890 if (gc_in_progress
)
21892 dpyinfo
->mouse_face_deferred_gc
= 1;
21896 /* Which window is that in? */
21897 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
21899 /* If we were displaying active text in another window, clear that.
21900 Also clear if we move out of text area in same window. */
21901 if (! EQ (window
, dpyinfo
->mouse_face_window
)
21902 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
21903 && !NILP (dpyinfo
->mouse_face_window
)))
21904 clear_mouse_face (dpyinfo
);
21906 /* Not on a window -> return. */
21907 if (!WINDOWP (window
))
21910 /* Reset help_echo_string. It will get recomputed below. */
21911 help_echo_string
= Qnil
;
21913 /* Convert to window-relative pixel coordinates. */
21914 w
= XWINDOW (window
);
21915 frame_to_window_pixel_xy (w
, &x
, &y
);
21917 /* Handle tool-bar window differently since it doesn't display a
21919 if (EQ (window
, f
->tool_bar_window
))
21921 note_tool_bar_highlight (f
, x
, y
);
21925 /* Mouse is on the mode, header line or margin? */
21926 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
21927 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
21929 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
21933 if (part
== ON_VERTICAL_BORDER
)
21934 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21935 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
21936 || part
== ON_SCROLL_BAR
)
21937 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21939 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21941 /* Are we in a window whose display is up to date?
21942 And verify the buffer's text has not changed. */
21943 b
= XBUFFER (w
->buffer
);
21944 if (part
== ON_TEXT
21945 && EQ (w
->window_end_valid
, w
->buffer
)
21946 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
21947 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
21949 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
21950 struct glyph
*glyph
;
21951 Lisp_Object object
;
21952 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
21953 Lisp_Object
*overlay_vec
= NULL
;
21955 struct buffer
*obuf
;
21956 int obegv
, ozv
, same_region
;
21958 /* Find the glyph under X/Y. */
21959 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
21961 /* Look for :pointer property on image. */
21962 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21964 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21965 if (img
!= NULL
&& IMAGEP (img
->spec
))
21967 Lisp_Object image_map
, hotspot
;
21968 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
21970 && (hotspot
= find_hot_spot (image_map
,
21971 glyph
->slice
.x
+ dx
,
21972 glyph
->slice
.y
+ dy
),
21974 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21976 Lisp_Object area_id
, plist
;
21978 area_id
= XCAR (hotspot
);
21979 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21980 If so, we could look for mouse-enter, mouse-leave
21981 properties in PLIST (and do something...). */
21982 hotspot
= XCDR (hotspot
);
21983 if (CONSP (hotspot
)
21984 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21986 pointer
= Fplist_get (plist
, Qpointer
);
21987 if (NILP (pointer
))
21989 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
21990 if (!NILP (help_echo_string
))
21992 help_echo_window
= window
;
21993 help_echo_object
= glyph
->object
;
21994 help_echo_pos
= glyph
->charpos
;
21998 if (NILP (pointer
))
21999 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
22003 /* Clear mouse face if X/Y not over text. */
22005 || area
!= TEXT_AREA
22006 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
22008 if (clear_mouse_face (dpyinfo
))
22009 cursor
= No_Cursor
;
22010 if (NILP (pointer
))
22012 if (area
!= TEXT_AREA
)
22013 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22015 pointer
= Vvoid_text_area_pointer
;
22020 pos
= glyph
->charpos
;
22021 object
= glyph
->object
;
22022 if (!STRINGP (object
) && !BUFFERP (object
))
22025 /* If we get an out-of-range value, return now; avoid an error. */
22026 if (BUFFERP (object
) && pos
> BUF_Z (b
))
22029 /* Make the window's buffer temporarily current for
22030 overlays_at and compute_char_face. */
22031 obuf
= current_buffer
;
22032 current_buffer
= b
;
22038 /* Is this char mouse-active or does it have help-echo? */
22039 position
= make_number (pos
);
22041 if (BUFFERP (object
))
22043 /* Put all the overlays we want in a vector in overlay_vec. */
22044 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
22045 /* Sort overlays into increasing priority order. */
22046 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
22051 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
22052 && vpos
>= dpyinfo
->mouse_face_beg_row
22053 && vpos
<= dpyinfo
->mouse_face_end_row
22054 && (vpos
> dpyinfo
->mouse_face_beg_row
22055 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22056 && (vpos
< dpyinfo
->mouse_face_end_row
22057 || hpos
< dpyinfo
->mouse_face_end_col
22058 || dpyinfo
->mouse_face_past_end
));
22061 cursor
= No_Cursor
;
22063 /* Check mouse-face highlighting. */
22065 /* If there exists an overlay with mouse-face overlapping
22066 the one we are currently highlighting, we have to
22067 check if we enter the overlapping overlay, and then
22068 highlight only that. */
22069 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
22070 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
22072 /* Find the highest priority overlay that has a mouse-face
22075 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
22077 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
22078 if (!NILP (mouse_face
))
22079 overlay
= overlay_vec
[i
];
22082 /* If we're actually highlighting the same overlay as
22083 before, there's no need to do that again. */
22084 if (!NILP (overlay
)
22085 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
22086 goto check_help_echo
;
22088 dpyinfo
->mouse_face_overlay
= overlay
;
22090 /* Clear the display of the old active region, if any. */
22091 if (clear_mouse_face (dpyinfo
))
22092 cursor
= No_Cursor
;
22094 /* If no overlay applies, get a text property. */
22095 if (NILP (overlay
))
22096 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
22098 /* Handle the overlay case. */
22099 if (!NILP (overlay
))
22101 /* Find the range of text around this char that
22102 should be active. */
22103 Lisp_Object before
, after
;
22106 before
= Foverlay_start (overlay
);
22107 after
= Foverlay_end (overlay
);
22108 /* Record this as the current active region. */
22109 fast_find_position (w
, XFASTINT (before
),
22110 &dpyinfo
->mouse_face_beg_col
,
22111 &dpyinfo
->mouse_face_beg_row
,
22112 &dpyinfo
->mouse_face_beg_x
,
22113 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22115 dpyinfo
->mouse_face_past_end
22116 = !fast_find_position (w
, XFASTINT (after
),
22117 &dpyinfo
->mouse_face_end_col
,
22118 &dpyinfo
->mouse_face_end_row
,
22119 &dpyinfo
->mouse_face_end_x
,
22120 &dpyinfo
->mouse_face_end_y
, Qnil
);
22121 dpyinfo
->mouse_face_window
= window
;
22123 dpyinfo
->mouse_face_face_id
22124 = face_at_buffer_position (w
, pos
, 0, 0,
22126 !dpyinfo
->mouse_face_hidden
);
22128 /* Display it as active. */
22129 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22130 cursor
= No_Cursor
;
22132 /* Handle the text property case. */
22133 else if (!NILP (mouse_face
) && BUFFERP (object
))
22135 /* Find the range of text around this char that
22136 should be active. */
22137 Lisp_Object before
, after
, beginning
, end
;
22140 beginning
= Fmarker_position (w
->start
);
22141 end
= make_number (BUF_Z (XBUFFER (object
))
22142 - XFASTINT (w
->window_end_pos
));
22144 = Fprevious_single_property_change (make_number (pos
+ 1),
22146 object
, beginning
);
22148 = Fnext_single_property_change (position
, Qmouse_face
,
22151 /* Record this as the current active region. */
22152 fast_find_position (w
, XFASTINT (before
),
22153 &dpyinfo
->mouse_face_beg_col
,
22154 &dpyinfo
->mouse_face_beg_row
,
22155 &dpyinfo
->mouse_face_beg_x
,
22156 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22157 dpyinfo
->mouse_face_past_end
22158 = !fast_find_position (w
, XFASTINT (after
),
22159 &dpyinfo
->mouse_face_end_col
,
22160 &dpyinfo
->mouse_face_end_row
,
22161 &dpyinfo
->mouse_face_end_x
,
22162 &dpyinfo
->mouse_face_end_y
, Qnil
);
22163 dpyinfo
->mouse_face_window
= window
;
22165 if (BUFFERP (object
))
22166 dpyinfo
->mouse_face_face_id
22167 = face_at_buffer_position (w
, pos
, 0, 0,
22169 !dpyinfo
->mouse_face_hidden
);
22171 /* Display it as active. */
22172 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22173 cursor
= No_Cursor
;
22175 else if (!NILP (mouse_face
) && STRINGP (object
))
22180 b
= Fprevious_single_property_change (make_number (pos
+ 1),
22183 e
= Fnext_single_property_change (position
, Qmouse_face
,
22186 b
= make_number (0);
22188 e
= make_number (SCHARS (object
) - 1);
22190 fast_find_string_pos (w
, XINT (b
), object
,
22191 &dpyinfo
->mouse_face_beg_col
,
22192 &dpyinfo
->mouse_face_beg_row
,
22193 &dpyinfo
->mouse_face_beg_x
,
22194 &dpyinfo
->mouse_face_beg_y
, 0);
22195 fast_find_string_pos (w
, XINT (e
), object
,
22196 &dpyinfo
->mouse_face_end_col
,
22197 &dpyinfo
->mouse_face_end_row
,
22198 &dpyinfo
->mouse_face_end_x
,
22199 &dpyinfo
->mouse_face_end_y
, 1);
22200 dpyinfo
->mouse_face_past_end
= 0;
22201 dpyinfo
->mouse_face_window
= window
;
22202 dpyinfo
->mouse_face_face_id
22203 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
22204 glyph
->face_id
, 1);
22205 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22206 cursor
= No_Cursor
;
22208 else if (STRINGP (object
) && NILP (mouse_face
))
22210 /* A string which doesn't have mouse-face, but
22211 the text ``under'' it might have. */
22212 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
22213 int start
= MATRIX_ROW_START_CHARPOS (r
);
22215 pos
= string_buffer_position (w
, object
, start
);
22217 mouse_face
= get_char_property_and_overlay (make_number (pos
),
22221 if (!NILP (mouse_face
) && !NILP (overlay
))
22223 Lisp_Object before
= Foverlay_start (overlay
);
22224 Lisp_Object after
= Foverlay_end (overlay
);
22227 /* Note that we might not be able to find position
22228 BEFORE in the glyph matrix if the overlay is
22229 entirely covered by a `display' property. In
22230 this case, we overshoot. So let's stop in
22231 the glyph matrix before glyphs for OBJECT. */
22232 fast_find_position (w
, XFASTINT (before
),
22233 &dpyinfo
->mouse_face_beg_col
,
22234 &dpyinfo
->mouse_face_beg_row
,
22235 &dpyinfo
->mouse_face_beg_x
,
22236 &dpyinfo
->mouse_face_beg_y
,
22239 dpyinfo
->mouse_face_past_end
22240 = !fast_find_position (w
, XFASTINT (after
),
22241 &dpyinfo
->mouse_face_end_col
,
22242 &dpyinfo
->mouse_face_end_row
,
22243 &dpyinfo
->mouse_face_end_x
,
22244 &dpyinfo
->mouse_face_end_y
,
22246 dpyinfo
->mouse_face_window
= window
;
22247 dpyinfo
->mouse_face_face_id
22248 = face_at_buffer_position (w
, pos
, 0, 0,
22250 !dpyinfo
->mouse_face_hidden
);
22252 /* Display it as active. */
22253 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22254 cursor
= No_Cursor
;
22261 /* Look for a `help-echo' property. */
22262 if (NILP (help_echo_string
)) {
22263 Lisp_Object help
, overlay
;
22265 /* Check overlays first. */
22266 help
= overlay
= Qnil
;
22267 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
22269 overlay
= overlay_vec
[i
];
22270 help
= Foverlay_get (overlay
, Qhelp_echo
);
22275 help_echo_string
= help
;
22276 help_echo_window
= window
;
22277 help_echo_object
= overlay
;
22278 help_echo_pos
= pos
;
22282 Lisp_Object object
= glyph
->object
;
22283 int charpos
= glyph
->charpos
;
22285 /* Try text properties. */
22286 if (STRINGP (object
)
22288 && charpos
< SCHARS (object
))
22290 help
= Fget_text_property (make_number (charpos
),
22291 Qhelp_echo
, object
);
22294 /* If the string itself doesn't specify a help-echo,
22295 see if the buffer text ``under'' it does. */
22296 struct glyph_row
*r
22297 = MATRIX_ROW (w
->current_matrix
, vpos
);
22298 int start
= MATRIX_ROW_START_CHARPOS (r
);
22299 int pos
= string_buffer_position (w
, object
, start
);
22302 help
= Fget_char_property (make_number (pos
),
22303 Qhelp_echo
, w
->buffer
);
22307 object
= w
->buffer
;
22312 else if (BUFFERP (object
)
22315 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
22320 help_echo_string
= help
;
22321 help_echo_window
= window
;
22322 help_echo_object
= object
;
22323 help_echo_pos
= charpos
;
22328 /* Look for a `pointer' property. */
22329 if (NILP (pointer
))
22331 /* Check overlays first. */
22332 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
22333 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
22335 if (NILP (pointer
))
22337 Lisp_Object object
= glyph
->object
;
22338 int charpos
= glyph
->charpos
;
22340 /* Try text properties. */
22341 if (STRINGP (object
)
22343 && charpos
< SCHARS (object
))
22345 pointer
= Fget_text_property (make_number (charpos
),
22347 if (NILP (pointer
))
22349 /* If the string itself doesn't specify a pointer,
22350 see if the buffer text ``under'' it does. */
22351 struct glyph_row
*r
22352 = MATRIX_ROW (w
->current_matrix
, vpos
);
22353 int start
= MATRIX_ROW_START_CHARPOS (r
);
22354 int pos
= string_buffer_position (w
, object
, start
);
22356 pointer
= Fget_char_property (make_number (pos
),
22357 Qpointer
, w
->buffer
);
22360 else if (BUFFERP (object
)
22363 pointer
= Fget_text_property (make_number (charpos
),
22370 current_buffer
= obuf
;
22375 define_frame_cursor1 (f
, cursor
, pointer
);
22380 Clear any mouse-face on window W. This function is part of the
22381 redisplay interface, and is called from try_window_id and similar
22382 functions to ensure the mouse-highlight is off. */
22385 x_clear_window_mouse_face (w
)
22388 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22389 Lisp_Object window
;
22392 XSETWINDOW (window
, w
);
22393 if (EQ (window
, dpyinfo
->mouse_face_window
))
22394 clear_mouse_face (dpyinfo
);
22400 Just discard the mouse face information for frame F, if any.
22401 This is used when the size of F is changed. */
22404 cancel_mouse_face (f
)
22407 Lisp_Object window
;
22408 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22410 window
= dpyinfo
->mouse_face_window
;
22411 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
22413 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22414 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22415 dpyinfo
->mouse_face_window
= Qnil
;
22420 #endif /* HAVE_WINDOW_SYSTEM */
22423 /***********************************************************************
22425 ***********************************************************************/
22427 #ifdef HAVE_WINDOW_SYSTEM
22429 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
22430 which intersects rectangle R. R is in window-relative coordinates. */
22433 expose_area (w
, row
, r
, area
)
22435 struct glyph_row
*row
;
22437 enum glyph_row_area area
;
22439 struct glyph
*first
= row
->glyphs
[area
];
22440 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
22441 struct glyph
*last
;
22442 int first_x
, start_x
, x
;
22444 if (area
== TEXT_AREA
&& row
->fill_line_p
)
22445 /* If row extends face to end of line write the whole line. */
22446 draw_glyphs (w
, 0, row
, area
,
22447 0, row
->used
[area
],
22448 DRAW_NORMAL_TEXT
, 0);
22451 /* Set START_X to the window-relative start position for drawing glyphs of
22452 AREA. The first glyph of the text area can be partially visible.
22453 The first glyphs of other areas cannot. */
22454 start_x
= window_box_left_offset (w
, area
);
22456 if (area
== TEXT_AREA
)
22459 /* Find the first glyph that must be redrawn. */
22461 && x
+ first
->pixel_width
< r
->x
)
22463 x
+= first
->pixel_width
;
22467 /* Find the last one. */
22471 && x
< r
->x
+ r
->width
)
22473 x
+= last
->pixel_width
;
22479 draw_glyphs (w
, first_x
- start_x
, row
, area
,
22480 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
22481 DRAW_NORMAL_TEXT
, 0);
22486 /* Redraw the parts of the glyph row ROW on window W intersecting
22487 rectangle R. R is in window-relative coordinates. Value is
22488 non-zero if mouse-face was overwritten. */
22491 expose_line (w
, row
, r
)
22493 struct glyph_row
*row
;
22496 xassert (row
->enabled_p
);
22498 if (row
->mode_line_p
|| w
->pseudo_window_p
)
22499 draw_glyphs (w
, 0, row
, TEXT_AREA
,
22500 0, row
->used
[TEXT_AREA
],
22501 DRAW_NORMAL_TEXT
, 0);
22504 if (row
->used
[LEFT_MARGIN_AREA
])
22505 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
22506 if (row
->used
[TEXT_AREA
])
22507 expose_area (w
, row
, r
, TEXT_AREA
);
22508 if (row
->used
[RIGHT_MARGIN_AREA
])
22509 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
22510 draw_row_fringe_bitmaps (w
, row
);
22513 return row
->mouse_face_p
;
22517 /* Redraw those parts of glyphs rows during expose event handling that
22518 overlap other rows. Redrawing of an exposed line writes over parts
22519 of lines overlapping that exposed line; this function fixes that.
22521 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
22522 row in W's current matrix that is exposed and overlaps other rows.
22523 LAST_OVERLAPPING_ROW is the last such row. */
22526 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
22528 struct glyph_row
*first_overlapping_row
;
22529 struct glyph_row
*last_overlapping_row
;
22531 struct glyph_row
*row
;
22533 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
22534 if (row
->overlapping_p
)
22536 xassert (row
->enabled_p
&& !row
->mode_line_p
);
22538 if (row
->used
[LEFT_MARGIN_AREA
])
22539 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
22541 if (row
->used
[TEXT_AREA
])
22542 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
22544 if (row
->used
[RIGHT_MARGIN_AREA
])
22545 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
22550 /* Return non-zero if W's cursor intersects rectangle R. */
22553 phys_cursor_in_rect_p (w
, r
)
22557 XRectangle cr
, result
;
22558 struct glyph
*cursor_glyph
;
22560 cursor_glyph
= get_phys_cursor_glyph (w
);
22563 /* r is relative to W's box, but w->phys_cursor.x is relative
22564 to left edge of W's TEXT area. Adjust it. */
22565 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
22566 cr
.y
= w
->phys_cursor
.y
;
22567 cr
.width
= cursor_glyph
->pixel_width
;
22568 cr
.height
= w
->phys_cursor_height
;
22569 /* ++KFS: W32 version used W32-specific IntersectRect here, but
22570 I assume the effect is the same -- and this is portable. */
22571 return x_intersect_rectangles (&cr
, r
, &result
);
22579 Draw a vertical window border to the right of window W if W doesn't
22580 have vertical scroll bars. */
22583 x_draw_vertical_border (w
)
22586 /* We could do better, if we knew what type of scroll-bar the adjacent
22587 windows (on either side) have... But we don't :-(
22588 However, I think this works ok. ++KFS 2003-04-25 */
22590 /* Redraw borders between horizontally adjacent windows. Don't
22591 do it for frames with vertical scroll bars because either the
22592 right scroll bar of a window, or the left scroll bar of its
22593 neighbor will suffice as a border. */
22594 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
22597 if (!WINDOW_RIGHTMOST_P (w
)
22598 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
22600 int x0
, x1
, y0
, y1
;
22602 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22605 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22608 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
22610 else if (!WINDOW_LEFTMOST_P (w
)
22611 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
22613 int x0
, x1
, y0
, y1
;
22615 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22618 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22621 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
22626 /* Redraw the part of window W intersection rectangle FR. Pixel
22627 coordinates in FR are frame-relative. Call this function with
22628 input blocked. Value is non-zero if the exposure overwrites
22632 expose_window (w
, fr
)
22636 struct frame
*f
= XFRAME (w
->frame
);
22638 int mouse_face_overwritten_p
= 0;
22640 /* If window is not yet fully initialized, do nothing. This can
22641 happen when toolkit scroll bars are used and a window is split.
22642 Reconfiguring the scroll bar will generate an expose for a newly
22644 if (w
->current_matrix
== NULL
)
22647 /* When we're currently updating the window, display and current
22648 matrix usually don't agree. Arrange for a thorough display
22650 if (w
== updated_window
)
22652 SET_FRAME_GARBAGED (f
);
22656 /* Frame-relative pixel rectangle of W. */
22657 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
22658 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
22659 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
22660 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
22662 if (x_intersect_rectangles (fr
, &wr
, &r
))
22664 int yb
= window_text_bottom_y (w
);
22665 struct glyph_row
*row
;
22666 int cursor_cleared_p
;
22667 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
22669 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
22670 r
.x
, r
.y
, r
.width
, r
.height
));
22672 /* Convert to window coordinates. */
22673 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
22674 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
22676 /* Turn off the cursor. */
22677 if (!w
->pseudo_window_p
22678 && phys_cursor_in_rect_p (w
, &r
))
22680 x_clear_cursor (w
);
22681 cursor_cleared_p
= 1;
22684 cursor_cleared_p
= 0;
22686 /* Update lines intersecting rectangle R. */
22687 first_overlapping_row
= last_overlapping_row
= NULL
;
22688 for (row
= w
->current_matrix
->rows
;
22693 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
22695 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
22696 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
22697 || (r
.y
>= y0
&& r
.y
< y1
)
22698 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
22700 /* A header line may be overlapping, but there is no need
22701 to fix overlapping areas for them. KFS 2005-02-12 */
22702 if (row
->overlapping_p
&& !row
->mode_line_p
)
22704 if (first_overlapping_row
== NULL
)
22705 first_overlapping_row
= row
;
22706 last_overlapping_row
= row
;
22709 if (expose_line (w
, row
, &r
))
22710 mouse_face_overwritten_p
= 1;
22717 /* Display the mode line if there is one. */
22718 if (WINDOW_WANTS_MODELINE_P (w
)
22719 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
22721 && row
->y
< r
.y
+ r
.height
)
22723 if (expose_line (w
, row
, &r
))
22724 mouse_face_overwritten_p
= 1;
22727 if (!w
->pseudo_window_p
)
22729 /* Fix the display of overlapping rows. */
22730 if (first_overlapping_row
)
22731 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
22733 /* Draw border between windows. */
22734 x_draw_vertical_border (w
);
22736 /* Turn the cursor on again. */
22737 if (cursor_cleared_p
)
22738 update_window_cursor (w
, 1);
22742 return mouse_face_overwritten_p
;
22747 /* Redraw (parts) of all windows in the window tree rooted at W that
22748 intersect R. R contains frame pixel coordinates. Value is
22749 non-zero if the exposure overwrites mouse-face. */
22752 expose_window_tree (w
, r
)
22756 struct frame
*f
= XFRAME (w
->frame
);
22757 int mouse_face_overwritten_p
= 0;
22759 while (w
&& !FRAME_GARBAGED_P (f
))
22761 if (!NILP (w
->hchild
))
22762 mouse_face_overwritten_p
22763 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
22764 else if (!NILP (w
->vchild
))
22765 mouse_face_overwritten_p
22766 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
22768 mouse_face_overwritten_p
|= expose_window (w
, r
);
22770 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
22773 return mouse_face_overwritten_p
;
22778 Redisplay an exposed area of frame F. X and Y are the upper-left
22779 corner of the exposed rectangle. W and H are width and height of
22780 the exposed area. All are pixel values. W or H zero means redraw
22781 the entire frame. */
22784 expose_frame (f
, x
, y
, w
, h
)
22789 int mouse_face_overwritten_p
= 0;
22791 TRACE ((stderr
, "expose_frame "));
22793 /* No need to redraw if frame will be redrawn soon. */
22794 if (FRAME_GARBAGED_P (f
))
22796 TRACE ((stderr
, " garbaged\n"));
22800 /* If basic faces haven't been realized yet, there is no point in
22801 trying to redraw anything. This can happen when we get an expose
22802 event while Emacs is starting, e.g. by moving another window. */
22803 if (FRAME_FACE_CACHE (f
) == NULL
22804 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
22806 TRACE ((stderr
, " no faces\n"));
22810 if (w
== 0 || h
== 0)
22813 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
22814 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
22824 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
22825 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
22827 if (WINDOWP (f
->tool_bar_window
))
22828 mouse_face_overwritten_p
22829 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
22831 #ifdef HAVE_X_WINDOWS
22833 #ifndef USE_X_TOOLKIT
22834 if (WINDOWP (f
->menu_bar_window
))
22835 mouse_face_overwritten_p
22836 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
22837 #endif /* not USE_X_TOOLKIT */
22841 /* Some window managers support a focus-follows-mouse style with
22842 delayed raising of frames. Imagine a partially obscured frame,
22843 and moving the mouse into partially obscured mouse-face on that
22844 frame. The visible part of the mouse-face will be highlighted,
22845 then the WM raises the obscured frame. With at least one WM, KDE
22846 2.1, Emacs is not getting any event for the raising of the frame
22847 (even tried with SubstructureRedirectMask), only Expose events.
22848 These expose events will draw text normally, i.e. not
22849 highlighted. Which means we must redo the highlight here.
22850 Subsume it under ``we love X''. --gerd 2001-08-15 */
22851 /* Included in Windows version because Windows most likely does not
22852 do the right thing if any third party tool offers
22853 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
22854 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
22856 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22857 if (f
== dpyinfo
->mouse_face_mouse_frame
)
22859 int x
= dpyinfo
->mouse_face_mouse_x
;
22860 int y
= dpyinfo
->mouse_face_mouse_y
;
22861 clear_mouse_face (dpyinfo
);
22862 note_mouse_highlight (f
, x
, y
);
22869 Determine the intersection of two rectangles R1 and R2. Return
22870 the intersection in *RESULT. Value is non-zero if RESULT is not
22874 x_intersect_rectangles (r1
, r2
, result
)
22875 XRectangle
*r1
, *r2
, *result
;
22877 XRectangle
*left
, *right
;
22878 XRectangle
*upper
, *lower
;
22879 int intersection_p
= 0;
22881 /* Rearrange so that R1 is the left-most rectangle. */
22883 left
= r1
, right
= r2
;
22885 left
= r2
, right
= r1
;
22887 /* X0 of the intersection is right.x0, if this is inside R1,
22888 otherwise there is no intersection. */
22889 if (right
->x
<= left
->x
+ left
->width
)
22891 result
->x
= right
->x
;
22893 /* The right end of the intersection is the minimum of the
22894 the right ends of left and right. */
22895 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
22898 /* Same game for Y. */
22900 upper
= r1
, lower
= r2
;
22902 upper
= r2
, lower
= r1
;
22904 /* The upper end of the intersection is lower.y0, if this is inside
22905 of upper. Otherwise, there is no intersection. */
22906 if (lower
->y
<= upper
->y
+ upper
->height
)
22908 result
->y
= lower
->y
;
22910 /* The lower end of the intersection is the minimum of the lower
22911 ends of upper and lower. */
22912 result
->height
= (min (lower
->y
+ lower
->height
,
22913 upper
->y
+ upper
->height
)
22915 intersection_p
= 1;
22919 return intersection_p
;
22922 #endif /* HAVE_WINDOW_SYSTEM */
22925 /***********************************************************************
22927 ***********************************************************************/
22932 Vwith_echo_area_save_vector
= Qnil
;
22933 staticpro (&Vwith_echo_area_save_vector
);
22935 Vmessage_stack
= Qnil
;
22936 staticpro (&Vmessage_stack
);
22938 Qinhibit_redisplay
= intern ("inhibit-redisplay");
22939 staticpro (&Qinhibit_redisplay
);
22941 message_dolog_marker1
= Fmake_marker ();
22942 staticpro (&message_dolog_marker1
);
22943 message_dolog_marker2
= Fmake_marker ();
22944 staticpro (&message_dolog_marker2
);
22945 message_dolog_marker3
= Fmake_marker ();
22946 staticpro (&message_dolog_marker3
);
22949 defsubr (&Sdump_frame_glyph_matrix
);
22950 defsubr (&Sdump_glyph_matrix
);
22951 defsubr (&Sdump_glyph_row
);
22952 defsubr (&Sdump_tool_bar_row
);
22953 defsubr (&Strace_redisplay
);
22954 defsubr (&Strace_to_stderr
);
22956 #ifdef HAVE_WINDOW_SYSTEM
22957 defsubr (&Stool_bar_lines_needed
);
22958 defsubr (&Slookup_image_map
);
22960 defsubr (&Sformat_mode_line
);
22962 staticpro (&Qmenu_bar_update_hook
);
22963 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
22965 staticpro (&Qoverriding_terminal_local_map
);
22966 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
22968 staticpro (&Qoverriding_local_map
);
22969 Qoverriding_local_map
= intern ("overriding-local-map");
22971 staticpro (&Qwindow_scroll_functions
);
22972 Qwindow_scroll_functions
= intern ("window-scroll-functions");
22974 staticpro (&Qredisplay_end_trigger_functions
);
22975 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
22977 staticpro (&Qinhibit_point_motion_hooks
);
22978 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
22980 QCdata
= intern (":data");
22981 staticpro (&QCdata
);
22982 Qdisplay
= intern ("display");
22983 staticpro (&Qdisplay
);
22984 Qspace_width
= intern ("space-width");
22985 staticpro (&Qspace_width
);
22986 Qraise
= intern ("raise");
22987 staticpro (&Qraise
);
22988 Qslice
= intern ("slice");
22989 staticpro (&Qslice
);
22990 Qspace
= intern ("space");
22991 staticpro (&Qspace
);
22992 Qmargin
= intern ("margin");
22993 staticpro (&Qmargin
);
22994 Qpointer
= intern ("pointer");
22995 staticpro (&Qpointer
);
22996 Qleft_margin
= intern ("left-margin");
22997 staticpro (&Qleft_margin
);
22998 Qright_margin
= intern ("right-margin");
22999 staticpro (&Qright_margin
);
23000 Qcenter
= intern ("center");
23001 staticpro (&Qcenter
);
23002 Qline_height
= intern ("line-height");
23003 staticpro (&Qline_height
);
23004 QCalign_to
= intern (":align-to");
23005 staticpro (&QCalign_to
);
23006 QCrelative_width
= intern (":relative-width");
23007 staticpro (&QCrelative_width
);
23008 QCrelative_height
= intern (":relative-height");
23009 staticpro (&QCrelative_height
);
23010 QCeval
= intern (":eval");
23011 staticpro (&QCeval
);
23012 QCpropertize
= intern (":propertize");
23013 staticpro (&QCpropertize
);
23014 QCfile
= intern (":file");
23015 staticpro (&QCfile
);
23016 Qfontified
= intern ("fontified");
23017 staticpro (&Qfontified
);
23018 Qfontification_functions
= intern ("fontification-functions");
23019 staticpro (&Qfontification_functions
);
23020 Qtrailing_whitespace
= intern ("trailing-whitespace");
23021 staticpro (&Qtrailing_whitespace
);
23022 Qescape_glyph
= intern ("escape-glyph");
23023 staticpro (&Qescape_glyph
);
23024 Qnobreak_space
= intern ("nobreak-space");
23025 staticpro (&Qnobreak_space
);
23026 Qimage
= intern ("image");
23027 staticpro (&Qimage
);
23028 QCmap
= intern (":map");
23029 staticpro (&QCmap
);
23030 QCpointer
= intern (":pointer");
23031 staticpro (&QCpointer
);
23032 Qrect
= intern ("rect");
23033 staticpro (&Qrect
);
23034 Qcircle
= intern ("circle");
23035 staticpro (&Qcircle
);
23036 Qpoly
= intern ("poly");
23037 staticpro (&Qpoly
);
23038 Qmessage_truncate_lines
= intern ("message-truncate-lines");
23039 staticpro (&Qmessage_truncate_lines
);
23040 Qgrow_only
= intern ("grow-only");
23041 staticpro (&Qgrow_only
);
23042 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
23043 staticpro (&Qinhibit_menubar_update
);
23044 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
23045 staticpro (&Qinhibit_eval_during_redisplay
);
23046 Qposition
= intern ("position");
23047 staticpro (&Qposition
);
23048 Qbuffer_position
= intern ("buffer-position");
23049 staticpro (&Qbuffer_position
);
23050 Qobject
= intern ("object");
23051 staticpro (&Qobject
);
23052 Qbar
= intern ("bar");
23054 Qhbar
= intern ("hbar");
23055 staticpro (&Qhbar
);
23056 Qbox
= intern ("box");
23058 Qhollow
= intern ("hollow");
23059 staticpro (&Qhollow
);
23060 Qhand
= intern ("hand");
23061 staticpro (&Qhand
);
23062 Qarrow
= intern ("arrow");
23063 staticpro (&Qarrow
);
23064 Qtext
= intern ("text");
23065 staticpro (&Qtext
);
23066 Qrisky_local_variable
= intern ("risky-local-variable");
23067 staticpro (&Qrisky_local_variable
);
23068 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
23069 staticpro (&Qinhibit_free_realized_faces
);
23071 list_of_error
= Fcons (Fcons (intern ("error"),
23072 Fcons (intern ("void-variable"), Qnil
)),
23074 staticpro (&list_of_error
);
23076 Qlast_arrow_position
= intern ("last-arrow-position");
23077 staticpro (&Qlast_arrow_position
);
23078 Qlast_arrow_string
= intern ("last-arrow-string");
23079 staticpro (&Qlast_arrow_string
);
23081 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
23082 staticpro (&Qoverlay_arrow_string
);
23083 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
23084 staticpro (&Qoverlay_arrow_bitmap
);
23086 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
23087 staticpro (&echo_buffer
[0]);
23088 staticpro (&echo_buffer
[1]);
23090 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
23091 staticpro (&echo_area_buffer
[0]);
23092 staticpro (&echo_area_buffer
[1]);
23094 Vmessages_buffer_name
= build_string ("*Messages*");
23095 staticpro (&Vmessages_buffer_name
);
23097 mode_line_proptrans_alist
= Qnil
;
23098 staticpro (&mode_line_proptrans_alist
);
23099 mode_line_string_list
= Qnil
;
23100 staticpro (&mode_line_string_list
);
23101 mode_line_string_face
= Qnil
;
23102 staticpro (&mode_line_string_face
);
23103 mode_line_string_face_prop
= Qnil
;
23104 staticpro (&mode_line_string_face_prop
);
23105 Vmode_line_unwind_vector
= Qnil
;
23106 staticpro (&Vmode_line_unwind_vector
);
23108 help_echo_string
= Qnil
;
23109 staticpro (&help_echo_string
);
23110 help_echo_object
= Qnil
;
23111 staticpro (&help_echo_object
);
23112 help_echo_window
= Qnil
;
23113 staticpro (&help_echo_window
);
23114 previous_help_echo_string
= Qnil
;
23115 staticpro (&previous_help_echo_string
);
23116 help_echo_pos
= -1;
23118 #ifdef HAVE_WINDOW_SYSTEM
23119 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
23120 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
23121 For example, if a block cursor is over a tab, it will be drawn as
23122 wide as that tab on the display. */);
23123 x_stretch_cursor_p
= 0;
23126 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
23127 doc
: /* *Non-nil means highlight trailing whitespace.
23128 The face used for trailing whitespace is `trailing-whitespace'. */);
23129 Vshow_trailing_whitespace
= Qnil
;
23131 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
23132 doc
: /* *Control highlighting of nobreak space and soft hyphen.
23133 A value of t means highlight the character itself (for nobreak space,
23134 use face `nobreak-space').
23135 A value of nil means no highlighting.
23136 Other values mean display the escape glyph followed by an ordinary
23137 space or ordinary hyphen. */);
23138 Vnobreak_char_display
= Qt
;
23140 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
23141 doc
: /* *The pointer shape to show in void text areas.
23142 A value of nil means to show the text pointer. Other options are `arrow',
23143 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
23144 Vvoid_text_area_pointer
= Qarrow
;
23146 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
23147 doc
: /* Non-nil means don't actually do any redisplay.
23148 This is used for internal purposes. */);
23149 Vinhibit_redisplay
= Qnil
;
23151 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
23152 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
23153 Vglobal_mode_string
= Qnil
;
23155 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
23156 doc
: /* Marker for where to display an arrow on top of the buffer text.
23157 This must be the beginning of a line in order to work.
23158 See also `overlay-arrow-string'. */);
23159 Voverlay_arrow_position
= Qnil
;
23161 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
23162 doc
: /* String to display as an arrow in non-window frames.
23163 See also `overlay-arrow-position'. */);
23164 Voverlay_arrow_string
= build_string ("=>");
23166 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
23167 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
23168 The symbols on this list are examined during redisplay to determine
23169 where to display overlay arrows. */);
23170 Voverlay_arrow_variable_list
23171 = Fcons (intern ("overlay-arrow-position"), Qnil
);
23173 DEFVAR_INT ("scroll-step", &scroll_step
,
23174 doc
: /* *The number of lines to try scrolling a window by when point moves out.
23175 If that fails to bring point back on frame, point is centered instead.
23176 If this is zero, point is always centered after it moves off frame.
23177 If you want scrolling to always be a line at a time, you should set
23178 `scroll-conservatively' to a large value rather than set this to 1. */);
23180 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
23181 doc
: /* *Scroll up to this many lines, to bring point back on screen.
23182 A value of zero means to scroll the text to center point vertically
23183 in the window. */);
23184 scroll_conservatively
= 0;
23186 DEFVAR_INT ("scroll-margin", &scroll_margin
,
23187 doc
: /* *Number of lines of margin at the top and bottom of a window.
23188 Recenter the window whenever point gets within this many lines
23189 of the top or bottom of the window. */);
23192 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
23193 doc
: /* Pixels per inch on current display.
23194 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
23195 Vdisplay_pixels_per_inch
= make_float (72.0);
23198 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
23201 DEFVAR_BOOL ("truncate-partial-width-windows",
23202 &truncate_partial_width_windows
,
23203 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
23204 truncate_partial_width_windows
= 1;
23206 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
23207 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
23208 Any other value means to use the appropriate face, `mode-line',
23209 `header-line', or `menu' respectively. */);
23210 mode_line_inverse_video
= 1;
23212 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
23213 doc
: /* *Maximum buffer size for which line number should be displayed.
23214 If the buffer is bigger than this, the line number does not appear
23215 in the mode line. A value of nil means no limit. */);
23216 Vline_number_display_limit
= Qnil
;
23218 DEFVAR_INT ("line-number-display-limit-width",
23219 &line_number_display_limit_width
,
23220 doc
: /* *Maximum line width (in characters) for line number display.
23221 If the average length of the lines near point is bigger than this, then the
23222 line number may be omitted from the mode line. */);
23223 line_number_display_limit_width
= 200;
23225 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
23226 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
23227 highlight_nonselected_windows
= 0;
23229 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
23230 doc
: /* Non-nil if more than one frame is visible on this display.
23231 Minibuffer-only frames don't count, but iconified frames do.
23232 This variable is not guaranteed to be accurate except while processing
23233 `frame-title-format' and `icon-title-format'. */);
23235 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
23236 doc
: /* Template for displaying the title bar of visible frames.
23237 \(Assuming the window manager supports this feature.)
23238 This variable has the same structure as `mode-line-format' (which see),
23239 and is used only on frames for which no explicit name has been set
23240 \(see `modify-frame-parameters'). */);
23242 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
23243 doc
: /* Template for displaying the title bar of an iconified frame.
23244 \(Assuming the window manager supports this feature.)
23245 This variable has the same structure as `mode-line-format' (which see),
23246 and is used only on frames for which no explicit name has been set
23247 \(see `modify-frame-parameters'). */);
23249 = Vframe_title_format
23250 = Fcons (intern ("multiple-frames"),
23251 Fcons (build_string ("%b"),
23252 Fcons (Fcons (empty_string
,
23253 Fcons (intern ("invocation-name"),
23254 Fcons (build_string ("@"),
23255 Fcons (intern ("system-name"),
23259 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
23260 doc
: /* Maximum number of lines to keep in the message log buffer.
23261 If nil, disable message logging. If t, log messages but don't truncate
23262 the buffer when it becomes large. */);
23263 Vmessage_log_max
= make_number (50);
23265 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
23266 doc
: /* Functions called before redisplay, if window sizes have changed.
23267 The value should be a list of functions that take one argument.
23268 Just before redisplay, for each frame, if any of its windows have changed
23269 size since the last redisplay, or have been split or deleted,
23270 all the functions in the list are called, with the frame as argument. */);
23271 Vwindow_size_change_functions
= Qnil
;
23273 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
23274 doc
: /* List of functions to call before redisplaying a window with scrolling.
23275 Each function is called with two arguments, the window
23276 and its new display-start position. Note that the value of `window-end'
23277 is not valid when these functions are called. */);
23278 Vwindow_scroll_functions
= Qnil
;
23280 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
23281 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
23282 mouse_autoselect_window
= 0;
23284 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
23285 doc
: /* *Non-nil means automatically resize tool-bars.
23286 This increases a tool-bar's height if not all tool-bar items are visible.
23287 It decreases a tool-bar's height when it would display blank lines
23289 auto_resize_tool_bars_p
= 1;
23291 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
23292 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
23293 auto_raise_tool_bar_buttons_p
= 1;
23295 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
23296 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
23297 make_cursor_line_fully_visible_p
= 1;
23299 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
23300 doc
: /* *Margin around tool-bar buttons in pixels.
23301 If an integer, use that for both horizontal and vertical margins.
23302 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
23303 HORZ specifying the horizontal margin, and VERT specifying the
23304 vertical margin. */);
23305 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
23307 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
23308 doc
: /* *Relief thickness of tool-bar buttons. */);
23309 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
23311 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
23312 doc
: /* List of functions to call to fontify regions of text.
23313 Each function is called with one argument POS. Functions must
23314 fontify a region starting at POS in the current buffer, and give
23315 fontified regions the property `fontified'. */);
23316 Vfontification_functions
= Qnil
;
23317 Fmake_variable_buffer_local (Qfontification_functions
);
23319 DEFVAR_BOOL ("unibyte-display-via-language-environment",
23320 &unibyte_display_via_language_environment
,
23321 doc
: /* *Non-nil means display unibyte text according to language environment.
23322 Specifically this means that unibyte non-ASCII characters
23323 are displayed by converting them to the equivalent multibyte characters
23324 according to the current language environment. As a result, they are
23325 displayed according to the current fontset. */);
23326 unibyte_display_via_language_environment
= 0;
23328 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
23329 doc
: /* *Maximum height for resizing mini-windows.
23330 If a float, it specifies a fraction of the mini-window frame's height.
23331 If an integer, it specifies a number of lines. */);
23332 Vmax_mini_window_height
= make_float (0.25);
23334 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
23335 doc
: /* *How to resize mini-windows.
23336 A value of nil means don't automatically resize mini-windows.
23337 A value of t means resize them to fit the text displayed in them.
23338 A value of `grow-only', the default, means let mini-windows grow
23339 only, until their display becomes empty, at which point the windows
23340 go back to their normal size. */);
23341 Vresize_mini_windows
= Qgrow_only
;
23343 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
23344 doc
: /* Alist specifying how to blink the cursor off.
23345 Each element has the form (ON-STATE . OFF-STATE). Whenever the
23346 `cursor-type' frame-parameter or variable equals ON-STATE,
23347 comparing using `equal', Emacs uses OFF-STATE to specify
23348 how to blink it off. */);
23349 Vblink_cursor_alist
= Qnil
;
23351 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
23352 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
23353 automatic_hscrolling_p
= 1;
23355 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
23356 doc
: /* *How many columns away from the window edge point is allowed to get
23357 before automatic hscrolling will horizontally scroll the window. */);
23358 hscroll_margin
= 5;
23360 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
23361 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
23362 When point is less than `automatic-hscroll-margin' columns from the window
23363 edge, automatic hscrolling will scroll the window by the amount of columns
23364 determined by this variable. If its value is a positive integer, scroll that
23365 many columns. If it's a positive floating-point number, it specifies the
23366 fraction of the window's width to scroll. If it's nil or zero, point will be
23367 centered horizontally after the scroll. Any other value, including negative
23368 numbers, are treated as if the value were zero.
23370 Automatic hscrolling always moves point outside the scroll margin, so if
23371 point was more than scroll step columns inside the margin, the window will
23372 scroll more than the value given by the scroll step.
23374 Note that the lower bound for automatic hscrolling specified by `scroll-left'
23375 and `scroll-right' overrides this variable's effect. */);
23376 Vhscroll_step
= make_number (0);
23378 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
23379 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
23380 Bind this around calls to `message' to let it take effect. */);
23381 message_truncate_lines
= 0;
23383 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
23384 doc
: /* Normal hook run to update the menu bar definitions.
23385 Redisplay runs this hook before it redisplays the menu bar.
23386 This is used to update submenus such as Buffers,
23387 whose contents depend on various data. */);
23388 Vmenu_bar_update_hook
= Qnil
;
23390 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
23391 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
23392 inhibit_menubar_update
= 0;
23394 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
23395 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
23396 inhibit_eval_during_redisplay
= 0;
23398 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
23399 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
23400 inhibit_free_realized_faces
= 0;
23403 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
23404 doc
: /* Inhibit try_window_id display optimization. */);
23405 inhibit_try_window_id
= 0;
23407 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
23408 doc
: /* Inhibit try_window_reusing display optimization. */);
23409 inhibit_try_window_reusing
= 0;
23411 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
23412 doc
: /* Inhibit try_cursor_movement display optimization. */);
23413 inhibit_try_cursor_movement
= 0;
23414 #endif /* GLYPH_DEBUG */
23418 /* Initialize this module when Emacs starts. */
23423 Lisp_Object root_window
;
23424 struct window
*mini_w
;
23426 current_header_line_height
= current_mode_line_height
= -1;
23428 CHARPOS (this_line_start_pos
) = 0;
23430 mini_w
= XWINDOW (minibuf_window
);
23431 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
23433 if (!noninteractive
)
23435 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
23438 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
23439 set_window_height (root_window
,
23440 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
23442 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
23443 set_window_height (minibuf_window
, 1, 0);
23445 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
23446 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
23448 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
23449 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
23450 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
23452 /* The default ellipsis glyphs `...'. */
23453 for (i
= 0; i
< 3; ++i
)
23454 default_invis_vector
[i
] = make_number ('.');
23458 /* Allocate the buffer for frame titles.
23459 Also used for `format-mode-line'. */
23461 mode_line_noprop_buf
= (char *) xmalloc (size
);
23462 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
23463 mode_line_noprop_ptr
= mode_line_noprop_buf
;
23464 mode_line_target
= MODE_LINE_DISPLAY
;
23467 help_echo_showing_p
= 0;
23471 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
23472 (do not change this comment) */