1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
3 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
27 Emacs separates the task of updating the display from code
28 modifying global state, e.g. buffer text. This way functions
29 operating on buffers don't also have to be concerned with updating
32 Updating the display is triggered by the Lisp interpreter when it
33 decides it's time to do it. This is done either automatically for
34 you as part of the interpreter's command loop or as the result of
35 calling Lisp functions like `sit-for'. The C function `redisplay'
36 in xdisp.c is the only entry into the inner redisplay code. (Or,
37 let's say almost---see the description of direct update
40 The following diagram shows how redisplay code is invoked. As you
41 can see, Lisp calls redisplay and vice versa. Under window systems
42 like X, some portions of the redisplay code are also called
43 asynchronously during mouse movement or expose events. It is very
44 important that these code parts do NOT use the C library (malloc,
45 free) because many C libraries under Unix are not reentrant. They
46 may also NOT call functions of the Lisp interpreter which could
47 change the interpreter's state. If you don't follow these rules,
48 you will encounter bugs which are very hard to explain.
50 (Direct functions, see below)
51 direct_output_for_insert,
52 direct_forward_char (dispnew.c)
53 +---------------------------------+
56 +--------------+ redisplay +----------------+
57 | Lisp machine |---------------->| Redisplay code |<--+
58 +--------------+ (xdisp.c) +----------------+ |
60 +----------------------------------+ |
61 Don't use this path when called |
64 expose_window (asynchronous) |
66 X expose events -----+
68 What does redisplay do? Obviously, it has to figure out somehow what
69 has been changed since the last time the display has been updated,
70 and to make these changes visible. Preferably it would do that in
71 a moderately intelligent way, i.e. fast.
73 Changes in buffer text can be deduced from window and buffer
74 structures, and from some global variables like `beg_unchanged' and
75 `end_unchanged'. The contents of the display are additionally
76 recorded in a `glyph matrix', a two-dimensional matrix of glyph
77 structures. Each row in such a matrix corresponds to a line on the
78 display, and each glyph in a row corresponds to a column displaying
79 a character, an image, or what else. This matrix is called the
80 `current glyph matrix' or `current matrix' in redisplay
83 For buffer parts that have been changed since the last update, a
84 second glyph matrix is constructed, the so called `desired glyph
85 matrix' or short `desired matrix'. Current and desired matrix are
86 then compared to find a cheap way to update the display, e.g. by
87 reusing part of the display by scrolling lines.
92 You will find a lot of redisplay optimizations when you start
93 looking at the innards of redisplay. The overall goal of all these
94 optimizations is to make redisplay fast because it is done
97 Two optimizations are not found in xdisp.c. These are the direct
98 operations mentioned above. As the name suggests they follow a
99 different principle than the rest of redisplay. Instead of
100 building a desired matrix and then comparing it with the current
101 display, they perform their actions directly on the display and on
104 One direct operation updates the display after one character has
105 been entered. The other one moves the cursor by one position
106 forward or backward. You find these functions under the names
107 `direct_output_for_insert' and `direct_output_forward_char' in
113 Desired matrices are always built per Emacs window. The function
114 `display_line' is the central function to look at if you are
115 interested. It constructs one row in a desired matrix given an
116 iterator structure containing both a buffer position and a
117 description of the environment in which the text is to be
118 displayed. But this is too early, read on.
120 Characters and pixmaps displayed for a range of buffer text depend
121 on various settings of buffers and windows, on overlays and text
122 properties, on display tables, on selective display. The good news
123 is that all this hairy stuff is hidden behind a small set of
124 interface functions taking an iterator structure (struct it)
127 Iteration over things to be displayed is then simple. It is
128 started by initializing an iterator with a call to init_iterator.
129 Calls to get_next_display_element fill the iterator structure with
130 relevant information about the next thing to display. Calls to
131 set_iterator_to_next move the iterator to the next thing.
133 Besides this, an iterator also contains information about the
134 display environment in which glyphs for display elements are to be
135 produced. It has fields for the width and height of the display,
136 the information whether long lines are truncated or continued, a
137 current X and Y position, and lots of other stuff you can better
140 Glyphs in a desired matrix are normally constructed in a loop
141 calling get_next_display_element and then produce_glyphs. The call
142 to produce_glyphs will fill the iterator structure with pixel
143 information about the element being displayed and at the same time
144 produce glyphs for it. If the display element fits on the line
145 being displayed, set_iterator_to_next is called next, otherwise the
146 glyphs produced are discarded.
151 That just couldn't be all, could it? What about terminal types not
152 supporting operations on sub-windows of the screen? To update the
153 display on such a terminal, window-based glyph matrices are not
154 well suited. To be able to reuse part of the display (scrolling
155 lines up and down), we must instead have a view of the whole
156 screen. This is what `frame matrices' are for. They are a trick.
158 Frames on terminals like above have a glyph pool. Windows on such
159 a frame sub-allocate their glyph memory from their frame's glyph
160 pool. The frame itself is given its own glyph matrices. By
161 coincidence---or maybe something else---rows in window glyph
162 matrices are slices of corresponding rows in frame matrices. Thus
163 writing to window matrices implicitly updates a frame matrix which
164 provides us with the view of the whole screen that we originally
165 wanted to have without having to move many bytes around. To be
166 honest, there is a little bit more done, but not much more. If you
167 plan to extend that code, take a look at dispnew.c. The function
168 build_frame_matrix is a good starting point. */
174 #include "keyboard.h"
177 #include "termchar.h"
178 #include "dispextern.h"
182 #include "commands.h"
186 #include "termhooks.h"
187 #include "intervals.h"
190 #include "region-cache.h"
192 #include "blockinput.h"
194 #ifdef HAVE_X_WINDOWS
204 #ifndef FRAME_X_OUTPUT
205 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
208 #define INFINITY 10000000
210 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
212 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
213 extern int pending_menu_activation
;
216 extern int interrupt_input
;
217 extern int command_loop_level
;
219 extern Lisp_Object do_mouse_tracking
;
221 extern int minibuffer_auto_raise
;
222 extern Lisp_Object Vminibuffer_list
;
224 extern Lisp_Object Qface
;
225 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
227 extern Lisp_Object Voverriding_local_map
;
228 extern Lisp_Object Voverriding_local_map_menu_flag
;
229 extern Lisp_Object Qmenu_item
;
230 extern Lisp_Object Qwhen
;
231 extern Lisp_Object Qhelp_echo
;
233 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
234 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
235 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
236 Lisp_Object Qinhibit_point_motion_hooks
;
237 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
238 Lisp_Object Qfontified
;
239 Lisp_Object Qgrow_only
;
240 Lisp_Object Qinhibit_eval_during_redisplay
;
241 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
244 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
247 Lisp_Object Qarrow
, Qhand
, Qtext
;
249 Lisp_Object Qrisky_local_variable
;
251 /* Holds the list (error). */
252 Lisp_Object list_of_error
;
254 /* Functions called to fontify regions of text. */
256 Lisp_Object Vfontification_functions
;
257 Lisp_Object Qfontification_functions
;
259 /* Non-nil means automatically select any window when the mouse
260 cursor moves into it. */
261 Lisp_Object Vmouse_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 below tool bar in pixels. 0 or nil means no margin.
273 If value is `internal-border-width' or `border-width',
274 the corresponding frame parameter is used. */
276 Lisp_Object Vtool_bar_border
;
278 /* Margin around tool bar buttons in pixels. */
280 Lisp_Object Vtool_bar_button_margin
;
282 /* Thickness of shadow to draw around tool bar buttons. */
284 EMACS_INT tool_bar_button_relief
;
286 /* Non-nil means automatically resize tool-bars so that all tool-bar
287 items are visible, and no blank lines remain.
289 If value is `grow-only', only make tool-bar bigger. */
291 Lisp_Object Vauto_resize_tool_bars
;
293 /* Non-zero means draw block and hollow cursor as wide as the glyph
294 under it. For example, if a block cursor is over a tab, it will be
295 drawn as wide as that tab on the display. */
297 int x_stretch_cursor_p
;
299 /* Non-nil means don't actually do any redisplay. */
301 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
303 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
305 int inhibit_eval_during_redisplay
;
307 /* Names of text properties relevant for redisplay. */
309 Lisp_Object Qdisplay
;
310 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
312 /* Symbols used in text property values. */
314 Lisp_Object Vdisplay_pixels_per_inch
;
315 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
316 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
319 Lisp_Object Qmargin
, Qpointer
;
320 Lisp_Object Qline_height
;
321 extern Lisp_Object Qheight
;
322 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
323 extern Lisp_Object Qscroll_bar
;
324 extern Lisp_Object Qcursor
;
326 /* Non-nil means highlight trailing whitespace. */
328 Lisp_Object Vshow_trailing_whitespace
;
330 /* Non-nil means escape non-break space and hyphens. */
332 Lisp_Object Vnobreak_char_display
;
334 #ifdef HAVE_WINDOW_SYSTEM
335 extern Lisp_Object Voverflow_newline_into_fringe
;
337 /* Test if overflow newline into fringe. Called with iterator IT
338 at or past right window margin, and with IT->current_x set. */
340 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
341 (!NILP (Voverflow_newline_into_fringe) \
342 && FRAME_WINDOW_P (it->f) \
343 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
344 && it->current_x == it->last_visible_x)
346 #endif /* HAVE_WINDOW_SYSTEM */
348 /* Non-nil means show the text cursor in void text areas
349 i.e. in blank areas after eol and eob. This used to be
350 the default in 21.3. */
352 Lisp_Object Vvoid_text_area_pointer
;
354 /* Name of the face used to highlight trailing whitespace. */
356 Lisp_Object Qtrailing_whitespace
;
358 /* Name and number of the face used to highlight escape glyphs. */
360 Lisp_Object Qescape_glyph
;
362 /* Name and number of the face used to highlight non-breaking spaces. */
364 Lisp_Object Qnobreak_space
;
366 /* The symbol `image' which is the car of the lists used to represent
371 /* The image map types. */
372 Lisp_Object QCmap
, QCpointer
;
373 Lisp_Object Qrect
, Qcircle
, Qpoly
;
375 /* Non-zero means print newline to stdout before next mini-buffer
378 int noninteractive_need_newline
;
380 /* Non-zero means print newline to message log before next message. */
382 static int message_log_need_newline
;
384 /* Three markers that message_dolog uses.
385 It could allocate them itself, but that causes trouble
386 in handling memory-full errors. */
387 static Lisp_Object message_dolog_marker1
;
388 static Lisp_Object message_dolog_marker2
;
389 static Lisp_Object message_dolog_marker3
;
391 /* The buffer position of the first character appearing entirely or
392 partially on the line of the selected window which contains the
393 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
394 redisplay optimization in redisplay_internal. */
396 static struct text_pos this_line_start_pos
;
398 /* Number of characters past the end of the line above, including the
399 terminating newline. */
401 static struct text_pos this_line_end_pos
;
403 /* The vertical positions and the height of this line. */
405 static int this_line_vpos
;
406 static int this_line_y
;
407 static int this_line_pixel_height
;
409 /* X position at which this display line starts. Usually zero;
410 negative if first character is partially visible. */
412 static int this_line_start_x
;
414 /* Buffer that this_line_.* variables are referring to. */
416 static struct buffer
*this_line_buffer
;
418 /* Nonzero means truncate lines in all windows less wide than the
421 int truncate_partial_width_windows
;
423 /* A flag to control how to display unibyte 8-bit character. */
425 int unibyte_display_via_language_environment
;
427 /* Nonzero means we have more than one non-mini-buffer-only frame.
428 Not guaranteed to be accurate except while parsing
429 frame-title-format. */
433 Lisp_Object Vglobal_mode_string
;
436 /* List of variables (symbols) which hold markers for overlay arrows.
437 The symbols on this list are examined during redisplay to determine
438 where to display overlay arrows. */
440 Lisp_Object Voverlay_arrow_variable_list
;
442 /* Marker for where to display an arrow on top of the buffer text. */
444 Lisp_Object Voverlay_arrow_position
;
446 /* String to display for the arrow. Only used on terminal frames. */
448 Lisp_Object Voverlay_arrow_string
;
450 /* Values of those variables at last redisplay are stored as
451 properties on `overlay-arrow-position' symbol. However, if
452 Voverlay_arrow_position is a marker, last-arrow-position is its
453 numerical position. */
455 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
457 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
458 properties on a symbol in overlay-arrow-variable-list. */
460 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
462 /* Like mode-line-format, but for the title bar on a visible frame. */
464 Lisp_Object Vframe_title_format
;
466 /* Like mode-line-format, but for the title bar on an iconified frame. */
468 Lisp_Object Vicon_title_format
;
470 /* List of functions to call when a window's size changes. These
471 functions get one arg, a frame on which one or more windows' sizes
474 static Lisp_Object Vwindow_size_change_functions
;
476 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
478 /* Nonzero if an overlay arrow has been displayed in this window. */
480 static int overlay_arrow_seen
;
482 /* Nonzero means highlight the region even in nonselected windows. */
484 int highlight_nonselected_windows
;
486 /* If cursor motion alone moves point off frame, try scrolling this
487 many lines up or down if that will bring it back. */
489 static EMACS_INT scroll_step
;
491 /* Nonzero means scroll just far enough to bring point back on the
492 screen, when appropriate. */
494 static EMACS_INT scroll_conservatively
;
496 /* Recenter the window whenever point gets within this many lines of
497 the top or bottom of the window. This value is translated into a
498 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
499 that there is really a fixed pixel height scroll margin. */
501 EMACS_INT scroll_margin
;
503 /* Number of windows showing the buffer of the selected window (or
504 another buffer with the same base buffer). keyboard.c refers to
509 /* Vector containing glyphs for an ellipsis `...'. */
511 static Lisp_Object default_invis_vector
[3];
513 /* Zero means display the mode-line/header-line/menu-bar in the default face
514 (this slightly odd definition is for compatibility with previous versions
515 of emacs), non-zero means display them using their respective faces.
517 This variable is deprecated. */
519 int mode_line_inverse_video
;
521 /* Prompt to display in front of the mini-buffer contents. */
523 Lisp_Object minibuf_prompt
;
525 /* Width of current mini-buffer prompt. Only set after display_line
526 of the line that contains the prompt. */
528 int minibuf_prompt_width
;
530 /* This is the window where the echo area message was displayed. It
531 is always a mini-buffer window, but it may not be the same window
532 currently active as a mini-buffer. */
534 Lisp_Object echo_area_window
;
536 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
537 pushes the current message and the value of
538 message_enable_multibyte on the stack, the function restore_message
539 pops the stack and displays MESSAGE again. */
541 Lisp_Object Vmessage_stack
;
543 /* Nonzero means multibyte characters were enabled when the echo area
544 message was specified. */
546 int message_enable_multibyte
;
548 /* Nonzero if we should redraw the mode lines on the next redisplay. */
550 int update_mode_lines
;
552 /* Nonzero if window sizes or contents have changed since last
553 redisplay that finished. */
555 int windows_or_buffers_changed
;
557 /* Nonzero means a frame's cursor type has been changed. */
559 int cursor_type_changed
;
561 /* Nonzero after display_mode_line if %l was used and it displayed a
564 int line_number_displayed
;
566 /* Maximum buffer size for which to display line numbers. */
568 Lisp_Object Vline_number_display_limit
;
570 /* Line width to consider when repositioning for line number display. */
572 static EMACS_INT line_number_display_limit_width
;
574 /* Number of lines to keep in the message log buffer. t means
575 infinite. nil means don't log at all. */
577 Lisp_Object Vmessage_log_max
;
579 /* The name of the *Messages* buffer, a string. */
581 static Lisp_Object Vmessages_buffer_name
;
583 /* Index 0 is the buffer that holds the current (desired) echo area message,
584 or nil if none is desired right now.
586 Index 1 is the buffer that holds the previously displayed echo area message,
587 or nil to indicate no message. This is normally what's on the screen now.
589 These two can point to the same buffer. That happens when the last
590 message output by the user (or made by echoing) has been displayed. */
592 Lisp_Object echo_area_buffer
[2];
594 /* Permanent pointers to the two buffers that are used for echo area
595 purposes. Once the two buffers are made, and their pointers are
596 placed here, these two slots remain unchanged unless those buffers
597 need to be created afresh. */
599 static Lisp_Object echo_buffer
[2];
601 /* A vector saved used in with_area_buffer to reduce consing. */
603 static Lisp_Object Vwith_echo_area_save_vector
;
605 /* Non-zero means display_echo_area should display the last echo area
606 message again. Set by redisplay_preserve_echo_area. */
608 static int display_last_displayed_message_p
;
610 /* Nonzero if echo area is being used by print; zero if being used by
613 int message_buf_print
;
615 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
617 Lisp_Object Qinhibit_menubar_update
;
618 int inhibit_menubar_update
;
620 /* When evaluating expressions from menu bar items (enable conditions,
621 for instance), this is the frame they are being processed for. */
623 Lisp_Object Vmenu_updating_frame
;
625 /* Maximum height for resizing mini-windows. Either a float
626 specifying a fraction of the available height, or an integer
627 specifying a number of lines. */
629 Lisp_Object Vmax_mini_window_height
;
631 /* Non-zero means messages should be displayed with truncated
632 lines instead of being continued. */
634 int message_truncate_lines
;
635 Lisp_Object Qmessage_truncate_lines
;
637 /* Set to 1 in clear_message to make redisplay_internal aware
638 of an emptied echo area. */
640 static int message_cleared_p
;
642 /* How to blink the default frame cursor off. */
643 Lisp_Object Vblink_cursor_alist
;
645 /* A scratch glyph row with contents used for generating truncation
646 glyphs. Also used in direct_output_for_insert. */
648 #define MAX_SCRATCH_GLYPHS 100
649 struct glyph_row scratch_glyph_row
;
650 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
652 /* Ascent and height of the last line processed by move_it_to. */
654 static int last_max_ascent
, last_height
;
656 /* Non-zero if there's a help-echo in the echo area. */
658 int help_echo_showing_p
;
660 /* If >= 0, computed, exact values of mode-line and header-line height
661 to use in the macros CURRENT_MODE_LINE_HEIGHT and
662 CURRENT_HEADER_LINE_HEIGHT. */
664 int current_mode_line_height
, current_header_line_height
;
666 /* The maximum distance to look ahead for text properties. Values
667 that are too small let us call compute_char_face and similar
668 functions too often which is expensive. Values that are too large
669 let us call compute_char_face and alike too often because we
670 might not be interested in text properties that far away. */
672 #define TEXT_PROP_DISTANCE_LIMIT 100
676 /* Variables to turn off display optimizations from Lisp. */
678 int inhibit_try_window_id
, inhibit_try_window_reusing
;
679 int inhibit_try_cursor_movement
;
681 /* Non-zero means print traces of redisplay if compiled with
684 int trace_redisplay_p
;
686 #endif /* GLYPH_DEBUG */
688 #ifdef DEBUG_TRACE_MOVE
689 /* Non-zero means trace with TRACE_MOVE to stderr. */
692 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
694 #define TRACE_MOVE(x) (void) 0
697 /* Non-zero means automatically scroll windows horizontally to make
700 int automatic_hscrolling_p
;
702 /* How close to the margin can point get before the window is scrolled
704 EMACS_INT hscroll_margin
;
706 /* How much to scroll horizontally when point is inside the above margin. */
707 Lisp_Object Vhscroll_step
;
709 /* The variable `resize-mini-windows'. If nil, don't resize
710 mini-windows. If t, always resize them to fit the text they
711 display. If `grow-only', let mini-windows grow only until they
714 Lisp_Object Vresize_mini_windows
;
716 /* Buffer being redisplayed -- for redisplay_window_error. */
718 struct buffer
*displayed_buffer
;
720 /* Space between overline and text. */
722 EMACS_INT overline_margin
;
724 /* Value returned from text property handlers (see below). */
729 HANDLED_RECOMPUTE_PROPS
,
730 HANDLED_OVERLAY_STRING_CONSUMED
,
734 /* A description of text properties that redisplay is interested
739 /* The name of the property. */
742 /* A unique index for the property. */
745 /* A handler function called to set up iterator IT from the property
746 at IT's current position. Value is used to steer handle_stop. */
747 enum prop_handled (*handler
) P_ ((struct it
*it
));
750 static enum prop_handled handle_face_prop
P_ ((struct it
*));
751 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
752 static enum prop_handled handle_display_prop
P_ ((struct it
*));
753 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
754 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
755 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
757 /* Properties handled by iterators. */
759 static struct props it_props
[] =
761 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
762 /* Handle `face' before `display' because some sub-properties of
763 `display' need to know the face. */
764 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
765 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
766 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
767 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
771 /* Value is the position described by X. If X is a marker, value is
772 the marker_position of X. Otherwise, value is X. */
774 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
776 /* Enumeration returned by some move_it_.* functions internally. */
780 /* Not used. Undefined value. */
783 /* Move ended at the requested buffer position or ZV. */
784 MOVE_POS_MATCH_OR_ZV
,
786 /* Move ended at the requested X pixel position. */
789 /* Move within a line ended at the end of a line that must be
793 /* Move within a line ended at the end of a line that would
794 be displayed truncated. */
797 /* Move within a line ended at a line end. */
801 /* This counter is used to clear the face cache every once in a while
802 in redisplay_internal. It is incremented for each redisplay.
803 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
806 #define CLEAR_FACE_CACHE_COUNT 500
807 static int clear_face_cache_count
;
809 /* Similarly for the image cache. */
811 #ifdef HAVE_WINDOW_SYSTEM
812 #define CLEAR_IMAGE_CACHE_COUNT 101
813 static int clear_image_cache_count
;
816 /* Record the previous terminal frame we displayed. */
818 static struct frame
*previous_terminal_frame
;
820 /* Non-zero while redisplay_internal is in progress. */
824 /* Non-zero means don't free realized faces. Bound while freeing
825 realized faces is dangerous because glyph matrices might still
828 int inhibit_free_realized_faces
;
829 Lisp_Object Qinhibit_free_realized_faces
;
831 /* If a string, XTread_socket generates an event to display that string.
832 (The display is done in read_char.) */
834 Lisp_Object help_echo_string
;
835 Lisp_Object help_echo_window
;
836 Lisp_Object help_echo_object
;
839 /* Temporary variable for XTread_socket. */
841 Lisp_Object previous_help_echo_string
;
843 /* Null glyph slice */
845 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
848 /* Function prototypes. */
850 static void setup_for_ellipsis
P_ ((struct it
*, int));
851 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
852 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
853 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
854 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
855 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
856 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
859 static int invisible_text_between_p
P_ ((struct it
*, int, int));
862 static void pint2str
P_ ((char *, int, int));
863 static void pint2hrstr
P_ ((char *, int, int));
864 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
866 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
867 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
868 static void store_mode_line_noprop_char
P_ ((char));
869 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
870 static void x_consider_frame_title
P_ ((Lisp_Object
));
871 static void handle_stop
P_ ((struct it
*));
872 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
873 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
874 static void ensure_echo_area_buffers
P_ ((void));
875 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
876 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
877 static int with_echo_area_buffer
P_ ((struct window
*, int,
878 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
879 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
880 static void clear_garbaged_frames
P_ ((void));
881 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
882 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
883 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
884 static int display_echo_area
P_ ((struct window
*));
885 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
886 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
887 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
888 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
889 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
891 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
892 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
893 static void insert_left_trunc_glyphs
P_ ((struct it
*));
894 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
896 static void extend_face_to_end_of_line
P_ ((struct it
*));
897 static int append_space_for_newline
P_ ((struct it
*, int));
898 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
899 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
900 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
901 static int trailing_whitespace_p
P_ ((int));
902 static int message_log_check_duplicate
P_ ((int, int, int, int));
903 static void push_it
P_ ((struct it
*));
904 static void pop_it
P_ ((struct it
*));
905 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
906 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
907 static void redisplay_internal
P_ ((int));
908 static int echo_area_display
P_ ((int));
909 static void redisplay_windows
P_ ((Lisp_Object
));
910 static void redisplay_window
P_ ((Lisp_Object
, int));
911 static Lisp_Object
redisplay_window_error ();
912 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
913 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
914 static int update_menu_bar
P_ ((struct frame
*, int, int));
915 static int try_window_reusing_current_matrix
P_ ((struct window
*));
916 static int try_window_id
P_ ((struct window
*));
917 static int display_line
P_ ((struct it
*));
918 static int display_mode_lines
P_ ((struct window
*));
919 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
920 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
921 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
922 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
923 static void display_menu_bar
P_ ((struct window
*));
924 static int display_count_lines
P_ ((int, int, int, int, int *));
925 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
926 int, int, struct it
*, int, int, int, int));
927 static void compute_line_metrics
P_ ((struct it
*));
928 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
929 static int get_overlay_strings
P_ ((struct it
*, int));
930 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
931 static void next_overlay_string
P_ ((struct it
*));
932 static void reseat
P_ ((struct it
*, struct text_pos
, int));
933 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
934 static void back_to_previous_visible_line_start
P_ ((struct it
*));
935 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
936 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
937 static int next_element_from_ellipsis
P_ ((struct it
*));
938 static int next_element_from_display_vector
P_ ((struct it
*));
939 static int next_element_from_string
P_ ((struct it
*));
940 static int next_element_from_c_string
P_ ((struct it
*));
941 static int next_element_from_buffer
P_ ((struct it
*));
942 static int next_element_from_composition
P_ ((struct it
*));
943 static int next_element_from_image
P_ ((struct it
*));
944 static int next_element_from_stretch
P_ ((struct it
*));
945 static void load_overlay_strings
P_ ((struct it
*, int));
946 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
947 struct display_pos
*));
948 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
949 Lisp_Object
, int, int, int, int));
950 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
952 void move_it_vertically_backward
P_ ((struct it
*, int));
953 static void init_to_row_start
P_ ((struct it
*, struct window
*,
954 struct glyph_row
*));
955 static int init_to_row_end
P_ ((struct it
*, struct window
*,
956 struct glyph_row
*));
957 static void back_to_previous_line_start
P_ ((struct it
*));
958 static int forward_to_next_line_start
P_ ((struct it
*, int *));
959 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
961 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
962 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
963 static int number_of_chars
P_ ((unsigned char *, int));
964 static void compute_stop_pos
P_ ((struct it
*));
965 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
967 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
968 static int next_overlay_change
P_ ((int));
969 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
970 Lisp_Object
, struct text_pos
*,
972 static int underlying_face_id
P_ ((struct it
*));
973 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
976 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
977 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
979 #ifdef HAVE_WINDOW_SYSTEM
981 static void update_tool_bar
P_ ((struct frame
*, int));
982 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
983 static int redisplay_tool_bar
P_ ((struct frame
*));
984 static void display_tool_bar_line
P_ ((struct it
*, int));
985 static void notice_overwritten_cursor
P_ ((struct window
*,
987 int, int, int, int));
991 #endif /* HAVE_WINDOW_SYSTEM */
994 /***********************************************************************
995 Window display dimensions
996 ***********************************************************************/
998 /* Return the bottom boundary y-position for text lines in window W.
999 This is the first y position at which a line cannot start.
1000 It is relative to the top of the window.
1002 This is the height of W minus the height of a mode line, if any. */
1005 window_text_bottom_y (w
)
1008 int height
= WINDOW_TOTAL_HEIGHT (w
);
1010 if (WINDOW_WANTS_MODELINE_P (w
))
1011 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1015 /* Return the pixel width of display area AREA of window W. AREA < 0
1016 means return the total width of W, not including fringes to
1017 the left and right of the window. */
1020 window_box_width (w
, area
)
1024 int cols
= XFASTINT (w
->total_cols
);
1027 if (!w
->pseudo_window_p
)
1029 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1031 if (area
== TEXT_AREA
)
1033 if (INTEGERP (w
->left_margin_cols
))
1034 cols
-= XFASTINT (w
->left_margin_cols
);
1035 if (INTEGERP (w
->right_margin_cols
))
1036 cols
-= XFASTINT (w
->right_margin_cols
);
1037 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1039 else if (area
== LEFT_MARGIN_AREA
)
1041 cols
= (INTEGERP (w
->left_margin_cols
)
1042 ? XFASTINT (w
->left_margin_cols
) : 0);
1045 else if (area
== RIGHT_MARGIN_AREA
)
1047 cols
= (INTEGERP (w
->right_margin_cols
)
1048 ? XFASTINT (w
->right_margin_cols
) : 0);
1053 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1057 /* Return the pixel height of the display area of window W, not
1058 including mode lines of W, if any. */
1061 window_box_height (w
)
1064 struct frame
*f
= XFRAME (w
->frame
);
1065 int height
= WINDOW_TOTAL_HEIGHT (w
);
1067 xassert (height
>= 0);
1069 /* Note: the code below that determines the mode-line/header-line
1070 height is essentially the same as that contained in the macro
1071 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1072 the appropriate glyph row has its `mode_line_p' flag set,
1073 and if it doesn't, uses estimate_mode_line_height instead. */
1075 if (WINDOW_WANTS_MODELINE_P (w
))
1077 struct glyph_row
*ml_row
1078 = (w
->current_matrix
&& w
->current_matrix
->rows
1079 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1081 if (ml_row
&& ml_row
->mode_line_p
)
1082 height
-= ml_row
->height
;
1084 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1087 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1089 struct glyph_row
*hl_row
1090 = (w
->current_matrix
&& w
->current_matrix
->rows
1091 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1093 if (hl_row
&& hl_row
->mode_line_p
)
1094 height
-= hl_row
->height
;
1096 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1099 /* With a very small font and a mode-line that's taller than
1100 default, we might end up with a negative height. */
1101 return max (0, height
);
1104 /* Return the window-relative coordinate of the left edge of display
1105 area AREA of window W. AREA < 0 means return the left edge of the
1106 whole window, to the right of the left fringe of W. */
1109 window_box_left_offset (w
, area
)
1115 if (w
->pseudo_window_p
)
1118 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1120 if (area
== TEXT_AREA
)
1121 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1122 + window_box_width (w
, LEFT_MARGIN_AREA
));
1123 else if (area
== RIGHT_MARGIN_AREA
)
1124 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1125 + window_box_width (w
, LEFT_MARGIN_AREA
)
1126 + window_box_width (w
, TEXT_AREA
)
1127 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1129 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1130 else if (area
== LEFT_MARGIN_AREA
1131 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1132 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1138 /* Return the window-relative coordinate of the right edge of display
1139 area AREA of window W. AREA < 0 means return the left edge of the
1140 whole window, to the left of the right fringe of W. */
1143 window_box_right_offset (w
, area
)
1147 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1150 /* Return the frame-relative coordinate of the left edge of display
1151 area AREA of window W. AREA < 0 means return the left edge of the
1152 whole window, to the right of the left fringe of W. */
1155 window_box_left (w
, area
)
1159 struct frame
*f
= XFRAME (w
->frame
);
1162 if (w
->pseudo_window_p
)
1163 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1165 x
= (WINDOW_LEFT_EDGE_X (w
)
1166 + window_box_left_offset (w
, area
));
1172 /* Return the frame-relative coordinate of the right edge of display
1173 area AREA of window W. AREA < 0 means return the left edge of the
1174 whole window, to the left of the right fringe of W. */
1177 window_box_right (w
, area
)
1181 return window_box_left (w
, area
) + window_box_width (w
, area
);
1184 /* Get the bounding box of the display area AREA of window W, without
1185 mode lines, in frame-relative coordinates. AREA < 0 means the
1186 whole window, not including the left and right fringes of
1187 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1188 coordinates of the upper-left corner of the box. Return in
1189 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1192 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1195 int *box_x
, *box_y
, *box_width
, *box_height
;
1198 *box_width
= window_box_width (w
, area
);
1200 *box_height
= window_box_height (w
);
1202 *box_x
= window_box_left (w
, area
);
1205 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1206 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1207 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1212 /* Get the bounding box of the display area AREA of window W, without
1213 mode lines. AREA < 0 means the whole window, not including the
1214 left and right fringe of the window. Return in *TOP_LEFT_X
1215 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1216 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1217 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1221 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1222 bottom_right_x
, bottom_right_y
)
1225 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1227 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1229 *bottom_right_x
+= *top_left_x
;
1230 *bottom_right_y
+= *top_left_y
;
1235 /***********************************************************************
1237 ***********************************************************************/
1239 /* Return the bottom y-position of the line the iterator IT is in.
1240 This can modify IT's settings. */
1246 int line_height
= it
->max_ascent
+ it
->max_descent
;
1247 int line_top_y
= it
->current_y
;
1249 if (line_height
== 0)
1252 line_height
= last_height
;
1253 else if (IT_CHARPOS (*it
) < ZV
)
1255 move_it_by_lines (it
, 1, 1);
1256 line_height
= (it
->max_ascent
|| it
->max_descent
1257 ? it
->max_ascent
+ it
->max_descent
1262 struct glyph_row
*row
= it
->glyph_row
;
1264 /* Use the default character height. */
1265 it
->glyph_row
= NULL
;
1266 it
->what
= IT_CHARACTER
;
1269 PRODUCE_GLYPHS (it
);
1270 line_height
= it
->ascent
+ it
->descent
;
1271 it
->glyph_row
= row
;
1275 return line_top_y
+ line_height
;
1279 /* Return 1 if position CHARPOS is visible in window W.
1280 CHARPOS < 0 means return info about WINDOW_END position.
1281 If visible, set *X and *Y to pixel coordinates of top left corner.
1282 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1283 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1286 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1288 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1291 struct text_pos top
;
1293 struct buffer
*old_buffer
= NULL
;
1298 if (XBUFFER (w
->buffer
) != current_buffer
)
1300 old_buffer
= current_buffer
;
1301 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1304 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1306 /* Compute exact mode line heights. */
1307 if (WINDOW_WANTS_MODELINE_P (w
))
1308 current_mode_line_height
1309 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1310 current_buffer
->mode_line_format
);
1312 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1313 current_header_line_height
1314 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1315 current_buffer
->header_line_format
);
1317 start_display (&it
, w
, top
);
1318 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1319 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1321 /* Note that we may overshoot because of invisible text. */
1322 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1324 int top_x
= it
.current_x
;
1325 int top_y
= it
.current_y
;
1326 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1327 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1329 if (top_y
< window_top_y
)
1330 visible_p
= bottom_y
> window_top_y
;
1331 else if (top_y
< it
.last_visible_y
)
1336 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1337 *rtop
= max (0, window_top_y
- top_y
);
1338 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1339 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1340 - max (top_y
, window_top_y
)));
1349 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1350 move_it_by_lines (&it
, 1, 0);
1351 if (charpos
< IT_CHARPOS (it
)
1352 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1355 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1357 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1358 *rtop
= max (0, -it2
.current_y
);
1359 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1360 - it
.last_visible_y
));
1361 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1363 - max (it2
.current_y
,
1364 WINDOW_HEADER_LINE_HEIGHT (w
))));
1370 set_buffer_internal_1 (old_buffer
);
1372 current_header_line_height
= current_mode_line_height
= -1;
1374 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1375 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1378 /* Debugging code. */
1380 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1381 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1383 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1390 /* Return the next character from STR which is MAXLEN bytes long.
1391 Return in *LEN the length of the character. This is like
1392 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1393 we find one, we return a `?', but with the length of the invalid
1397 string_char_and_length (str
, maxlen
, len
)
1398 const unsigned char *str
;
1403 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1404 if (!CHAR_VALID_P (c
, 1))
1405 /* We may not change the length here because other places in Emacs
1406 don't use this function, i.e. they silently accept invalid
1415 /* Given a position POS containing a valid character and byte position
1416 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1418 static struct text_pos
1419 string_pos_nchars_ahead (pos
, string
, nchars
)
1420 struct text_pos pos
;
1424 xassert (STRINGP (string
) && nchars
>= 0);
1426 if (STRING_MULTIBYTE (string
))
1428 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1429 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1434 string_char_and_length (p
, rest
, &len
);
1435 p
+= len
, rest
-= len
;
1436 xassert (rest
>= 0);
1438 BYTEPOS (pos
) += len
;
1442 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1448 /* Value is the text position, i.e. character and byte position,
1449 for character position CHARPOS in STRING. */
1451 static INLINE
struct text_pos
1452 string_pos (charpos
, string
)
1456 struct text_pos pos
;
1457 xassert (STRINGP (string
));
1458 xassert (charpos
>= 0);
1459 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1464 /* Value is a text position, i.e. character and byte position, for
1465 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1466 means recognize multibyte characters. */
1468 static struct text_pos
1469 c_string_pos (charpos
, s
, multibyte_p
)
1474 struct text_pos pos
;
1476 xassert (s
!= NULL
);
1477 xassert (charpos
>= 0);
1481 int rest
= strlen (s
), len
;
1483 SET_TEXT_POS (pos
, 0, 0);
1486 string_char_and_length (s
, rest
, &len
);
1487 s
+= len
, rest
-= len
;
1488 xassert (rest
>= 0);
1490 BYTEPOS (pos
) += len
;
1494 SET_TEXT_POS (pos
, charpos
, charpos
);
1500 /* Value is the number of characters in C string S. MULTIBYTE_P
1501 non-zero means recognize multibyte characters. */
1504 number_of_chars (s
, multibyte_p
)
1512 int rest
= strlen (s
), len
;
1513 unsigned char *p
= (unsigned char *) s
;
1515 for (nchars
= 0; rest
> 0; ++nchars
)
1517 string_char_and_length (p
, rest
, &len
);
1518 rest
-= len
, p
+= len
;
1522 nchars
= strlen (s
);
1528 /* Compute byte position NEWPOS->bytepos corresponding to
1529 NEWPOS->charpos. POS is a known position in string STRING.
1530 NEWPOS->charpos must be >= POS.charpos. */
1533 compute_string_pos (newpos
, pos
, string
)
1534 struct text_pos
*newpos
, pos
;
1537 xassert (STRINGP (string
));
1538 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1540 if (STRING_MULTIBYTE (string
))
1541 *newpos
= string_pos_nchars_ahead (pos
, string
,
1542 CHARPOS (*newpos
) - CHARPOS (pos
));
1544 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1548 Return an estimation of the pixel height of mode or top lines on
1549 frame F. FACE_ID specifies what line's height to estimate. */
1552 estimate_mode_line_height (f
, face_id
)
1554 enum face_id face_id
;
1556 #ifdef HAVE_WINDOW_SYSTEM
1557 if (FRAME_WINDOW_P (f
))
1559 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1561 /* This function is called so early when Emacs starts that the face
1562 cache and mode line face are not yet initialized. */
1563 if (FRAME_FACE_CACHE (f
))
1565 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1569 height
= FONT_HEIGHT (face
->font
);
1570 if (face
->box_line_width
> 0)
1571 height
+= 2 * face
->box_line_width
;
1582 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1583 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1584 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1585 not force the value into range. */
1588 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1590 register int pix_x
, pix_y
;
1592 NativeRectangle
*bounds
;
1596 #ifdef HAVE_WINDOW_SYSTEM
1597 if (FRAME_WINDOW_P (f
))
1599 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1600 even for negative values. */
1602 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1604 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1606 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1607 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1610 STORE_NATIVE_RECT (*bounds
,
1611 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1612 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1613 FRAME_COLUMN_WIDTH (f
) - 1,
1614 FRAME_LINE_HEIGHT (f
) - 1);
1620 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1621 pix_x
= FRAME_TOTAL_COLS (f
);
1625 else if (pix_y
> FRAME_LINES (f
))
1626 pix_y
= FRAME_LINES (f
);
1636 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1637 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1638 can't tell the positions because W's display is not up to date,
1642 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1645 int *frame_x
, *frame_y
;
1647 #ifdef HAVE_WINDOW_SYSTEM
1648 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1652 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1653 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1655 if (display_completed
)
1657 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1658 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1659 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1665 hpos
+= glyph
->pixel_width
;
1669 /* If first glyph is partially visible, its first visible position is still 0. */
1681 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1682 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1693 #ifdef HAVE_WINDOW_SYSTEM
1695 /* Find the glyph under window-relative coordinates X/Y in window W.
1696 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1697 strings. Return in *HPOS and *VPOS the row and column number of
1698 the glyph found. Return in *AREA the glyph area containing X.
1699 Value is a pointer to the glyph found or null if X/Y is not on
1700 text, or we can't tell because W's current matrix is not up to
1703 static struct glyph
*
1704 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1707 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1709 struct glyph
*glyph
, *end
;
1710 struct glyph_row
*row
= NULL
;
1713 /* Find row containing Y. Give up if some row is not enabled. */
1714 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1716 row
= MATRIX_ROW (w
->current_matrix
, i
);
1717 if (!row
->enabled_p
)
1719 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1726 /* Give up if Y is not in the window. */
1727 if (i
== w
->current_matrix
->nrows
)
1730 /* Get the glyph area containing X. */
1731 if (w
->pseudo_window_p
)
1738 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1740 *area
= LEFT_MARGIN_AREA
;
1741 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1743 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1746 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1750 *area
= RIGHT_MARGIN_AREA
;
1751 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1755 /* Find glyph containing X. */
1756 glyph
= row
->glyphs
[*area
];
1757 end
= glyph
+ row
->used
[*area
];
1759 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1761 x
-= glyph
->pixel_width
;
1771 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1774 *hpos
= glyph
- row
->glyphs
[*area
];
1780 Convert frame-relative x/y to coordinates relative to window W.
1781 Takes pseudo-windows into account. */
1784 frame_to_window_pixel_xy (w
, x
, y
)
1788 if (w
->pseudo_window_p
)
1790 /* A pseudo-window is always full-width, and starts at the
1791 left edge of the frame, plus a frame border. */
1792 struct frame
*f
= XFRAME (w
->frame
);
1793 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1794 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1798 *x
-= WINDOW_LEFT_EDGE_X (w
);
1799 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1804 Return in RECTS[] at most N clipping rectangles for glyph string S.
1805 Return the number of stored rectangles. */
1808 get_glyph_string_clip_rects (s
, rects
, n
)
1809 struct glyph_string
*s
;
1810 NativeRectangle
*rects
;
1818 if (s
->row
->full_width_p
)
1820 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1821 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1822 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1824 /* Unless displaying a mode or menu bar line, which are always
1825 fully visible, clip to the visible part of the row. */
1826 if (s
->w
->pseudo_window_p
)
1827 r
.height
= s
->row
->visible_height
;
1829 r
.height
= s
->height
;
1833 /* This is a text line that may be partially visible. */
1834 r
.x
= window_box_left (s
->w
, s
->area
);
1835 r
.width
= window_box_width (s
->w
, s
->area
);
1836 r
.height
= s
->row
->visible_height
;
1840 if (r
.x
< s
->clip_head
->x
)
1842 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1843 r
.width
-= s
->clip_head
->x
- r
.x
;
1846 r
.x
= s
->clip_head
->x
;
1849 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1851 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1852 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1857 /* If S draws overlapping rows, it's sufficient to use the top and
1858 bottom of the window for clipping because this glyph string
1859 intentionally draws over other lines. */
1860 if (s
->for_overlaps
)
1862 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1863 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1865 /* Alas, the above simple strategy does not work for the
1866 environments with anti-aliased text: if the same text is
1867 drawn onto the same place multiple times, it gets thicker.
1868 If the overlap we are processing is for the erased cursor, we
1869 take the intersection with the rectagle of the cursor. */
1870 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1872 XRectangle rc
, r_save
= r
;
1874 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1875 rc
.y
= s
->w
->phys_cursor
.y
;
1876 rc
.width
= s
->w
->phys_cursor_width
;
1877 rc
.height
= s
->w
->phys_cursor_height
;
1879 x_intersect_rectangles (&r_save
, &rc
, &r
);
1884 /* Don't use S->y for clipping because it doesn't take partially
1885 visible lines into account. For example, it can be negative for
1886 partially visible lines at the top of a window. */
1887 if (!s
->row
->full_width_p
1888 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1889 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1891 r
.y
= max (0, s
->row
->y
);
1893 /* If drawing a tool-bar window, draw it over the internal border
1894 at the top of the window. */
1895 if (WINDOWP (s
->f
->tool_bar_window
)
1896 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1897 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1900 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1902 /* If drawing the cursor, don't let glyph draw outside its
1903 advertised boundaries. Cleartype does this under some circumstances. */
1904 if (s
->hl
== DRAW_CURSOR
)
1906 struct glyph
*glyph
= s
->first_glyph
;
1911 r
.width
-= s
->x
- r
.x
;
1914 r
.width
= min (r
.width
, glyph
->pixel_width
);
1916 /* If r.y is below window bottom, ensure that we still see a cursor. */
1917 height
= min (glyph
->ascent
+ glyph
->descent
,
1918 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1919 max_y
= window_text_bottom_y (s
->w
) - height
;
1920 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1921 if (s
->ybase
- glyph
->ascent
> max_y
)
1928 /* Don't draw cursor glyph taller than our actual glyph. */
1929 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1930 if (height
< r
.height
)
1932 max_y
= r
.y
+ r
.height
;
1933 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1934 r
.height
= min (max_y
- r
.y
, height
);
1939 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1940 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1942 #ifdef CONVERT_FROM_XRECT
1943 CONVERT_FROM_XRECT (r
, *rects
);
1951 /* If we are processing overlapping and allowed to return
1952 multiple clipping rectangles, we exclude the row of the glyph
1953 string from the clipping rectangle. This is to avoid drawing
1954 the same text on the environment with anti-aliasing. */
1955 #ifdef CONVERT_FROM_XRECT
1958 XRectangle
*rs
= rects
;
1960 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1962 if (s
->for_overlaps
& OVERLAPS_PRED
)
1965 if (r
.y
+ r
.height
> row_y
)
1968 rs
[i
].height
= row_y
- r
.y
;
1974 if (s
->for_overlaps
& OVERLAPS_SUCC
)
1977 if (r
.y
< row_y
+ s
->row
->visible_height
)
1979 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
1981 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
1982 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
1991 #ifdef CONVERT_FROM_XRECT
1992 for (i
= 0; i
< n
; i
++)
1993 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2000 Return in *NR the clipping rectangle for glyph string S. */
2003 get_glyph_string_clip_rect (s
, nr
)
2004 struct glyph_string
*s
;
2005 NativeRectangle
*nr
;
2007 get_glyph_string_clip_rects (s
, nr
, 1);
2012 Return the position and height of the phys cursor in window W.
2013 Set w->phys_cursor_width to width of phys cursor.
2017 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2019 struct glyph_row
*row
;
2020 struct glyph
*glyph
;
2021 int *xp
, *yp
, *heightp
;
2023 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2024 int x
, y
, wd
, h
, h0
, y0
;
2026 /* Compute the width of the rectangle to draw. If on a stretch
2027 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2028 rectangle as wide as the glyph, but use a canonical character
2030 wd
= glyph
->pixel_width
- 1;
2035 x
= w
->phys_cursor
.x
;
2042 if (glyph
->type
== STRETCH_GLYPH
2043 && !x_stretch_cursor_p
)
2044 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2045 w
->phys_cursor_width
= wd
;
2047 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2049 /* If y is below window bottom, ensure that we still see a cursor. */
2050 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2052 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2053 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2055 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2058 h
= max (h
- (y0
- y
) + 1, h0
);
2063 y0
= window_text_bottom_y (w
) - h0
;
2071 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2072 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2077 * Remember which glyph the mouse is over.
2081 remember_mouse_glyph (f
, gx
, gy
, rect
)
2084 NativeRectangle
*rect
;
2088 struct glyph_row
*r
, *gr
, *end_row
;
2089 enum window_part part
;
2090 enum glyph_row_area area
;
2091 int x
, y
, width
, height
;
2093 /* Try to determine frame pixel position and size of the glyph under
2094 frame pixel coordinates X/Y on frame F. */
2096 if (!f
->glyphs_initialized_p
2097 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2100 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2101 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2105 w
= XWINDOW (window
);
2106 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2107 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2109 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2110 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2112 if (w
->pseudo_window_p
)
2115 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2121 case ON_LEFT_MARGIN
:
2122 area
= LEFT_MARGIN_AREA
;
2125 case ON_RIGHT_MARGIN
:
2126 area
= RIGHT_MARGIN_AREA
;
2129 case ON_HEADER_LINE
:
2131 gr
= (part
== ON_HEADER_LINE
2132 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2133 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2136 goto text_glyph_row_found
;
2143 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2144 if (r
->y
+ r
->height
> y
)
2150 text_glyph_row_found
:
2153 struct glyph
*g
= gr
->glyphs
[area
];
2154 struct glyph
*end
= g
+ gr
->used
[area
];
2156 height
= gr
->height
;
2157 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2158 if (gx
+ g
->pixel_width
> x
)
2163 if (g
->type
== IMAGE_GLYPH
)
2165 /* Don't remember when mouse is over image, as
2166 image may have hot-spots. */
2167 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2170 width
= g
->pixel_width
;
2174 /* Use nominal char spacing at end of line. */
2176 gx
+= (x
/ width
) * width
;
2179 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2180 gx
+= window_box_left_offset (w
, area
);
2184 /* Use nominal line height at end of window. */
2185 gx
= (x
/ width
) * width
;
2187 gy
+= (y
/ height
) * height
;
2191 case ON_LEFT_FRINGE
:
2192 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2193 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2194 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2195 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2198 case ON_RIGHT_FRINGE
:
2199 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2200 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2201 : window_box_right_offset (w
, TEXT_AREA
));
2202 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2206 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2208 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2209 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2210 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2212 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2216 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2217 if (r
->y
+ r
->height
> y
)
2224 height
= gr
->height
;
2227 /* Use nominal line height at end of window. */
2229 gy
+= (y
/ height
) * height
;
2236 /* If there is no glyph under the mouse, then we divide the screen
2237 into a grid of the smallest glyph in the frame, and use that
2240 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2241 round down even for negative values. */
2247 gx
= (gx
/ width
) * width
;
2248 gy
= (gy
/ height
) * height
;
2253 gx
+= WINDOW_LEFT_EDGE_X (w
);
2254 gy
+= WINDOW_TOP_EDGE_Y (w
);
2257 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2259 /* Visible feedback for debugging. */
2262 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2263 f
->output_data
.x
->normal_gc
,
2264 gx
, gy
, width
, height
);
2270 #endif /* HAVE_WINDOW_SYSTEM */
2273 /***********************************************************************
2274 Lisp form evaluation
2275 ***********************************************************************/
2277 /* Error handler for safe_eval and safe_call. */
2280 safe_eval_handler (arg
)
2283 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2288 /* Evaluate SEXPR and return the result, or nil if something went
2289 wrong. Prevent redisplay during the evaluation. */
2297 if (inhibit_eval_during_redisplay
)
2301 int count
= SPECPDL_INDEX ();
2302 struct gcpro gcpro1
;
2305 specbind (Qinhibit_redisplay
, Qt
);
2306 /* Use Qt to ensure debugger does not run,
2307 so there is no possibility of wanting to redisplay. */
2308 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
2311 val
= unbind_to (count
, val
);
2318 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2319 Return the result, or nil if something went wrong. Prevent
2320 redisplay during the evaluation. */
2323 safe_call (nargs
, args
)
2329 if (inhibit_eval_during_redisplay
)
2333 int count
= SPECPDL_INDEX ();
2334 struct gcpro gcpro1
;
2337 gcpro1
.nvars
= nargs
;
2338 specbind (Qinhibit_redisplay
, Qt
);
2339 /* Use Qt to ensure debugger does not run,
2340 so there is no possibility of wanting to redisplay. */
2341 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2344 val
= unbind_to (count
, val
);
2351 /* Call function FN with one argument ARG.
2352 Return the result, or nil if something went wrong. */
2355 safe_call1 (fn
, arg
)
2356 Lisp_Object fn
, arg
;
2358 Lisp_Object args
[2];
2361 return safe_call (2, args
);
2366 /***********************************************************************
2368 ***********************************************************************/
2372 /* Define CHECK_IT to perform sanity checks on iterators.
2373 This is for debugging. It is too slow to do unconditionally. */
2379 if (it
->method
== GET_FROM_STRING
)
2381 xassert (STRINGP (it
->string
));
2382 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2386 xassert (IT_STRING_CHARPOS (*it
) < 0);
2387 if (it
->method
== GET_FROM_BUFFER
)
2389 /* Check that character and byte positions agree. */
2390 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2395 xassert (it
->current
.dpvec_index
>= 0);
2397 xassert (it
->current
.dpvec_index
< 0);
2400 #define CHECK_IT(IT) check_it ((IT))
2404 #define CHECK_IT(IT) (void) 0
2411 /* Check that the window end of window W is what we expect it
2412 to be---the last row in the current matrix displaying text. */
2415 check_window_end (w
)
2418 if (!MINI_WINDOW_P (w
)
2419 && !NILP (w
->window_end_valid
))
2421 struct glyph_row
*row
;
2422 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2423 XFASTINT (w
->window_end_vpos
)),
2425 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2426 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2430 #define CHECK_WINDOW_END(W) check_window_end ((W))
2432 #else /* not GLYPH_DEBUG */
2434 #define CHECK_WINDOW_END(W) (void) 0
2436 #endif /* not GLYPH_DEBUG */
2440 /***********************************************************************
2441 Iterator initialization
2442 ***********************************************************************/
2444 /* Initialize IT for displaying current_buffer in window W, starting
2445 at character position CHARPOS. CHARPOS < 0 means that no buffer
2446 position is specified which is useful when the iterator is assigned
2447 a position later. BYTEPOS is the byte position corresponding to
2448 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2450 If ROW is not null, calls to produce_glyphs with IT as parameter
2451 will produce glyphs in that row.
2453 BASE_FACE_ID is the id of a base face to use. It must be one of
2454 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2455 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2456 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2458 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2459 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2460 will be initialized to use the corresponding mode line glyph row of
2461 the desired matrix of W. */
2464 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2467 int charpos
, bytepos
;
2468 struct glyph_row
*row
;
2469 enum face_id base_face_id
;
2471 int highlight_region_p
;
2473 /* Some precondition checks. */
2474 xassert (w
!= NULL
&& it
!= NULL
);
2475 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2478 /* If face attributes have been changed since the last redisplay,
2479 free realized faces now because they depend on face definitions
2480 that might have changed. Don't free faces while there might be
2481 desired matrices pending which reference these faces. */
2482 if (face_change_count
&& !inhibit_free_realized_faces
)
2484 face_change_count
= 0;
2485 free_all_realized_faces (Qnil
);
2488 /* Use one of the mode line rows of W's desired matrix if
2492 if (base_face_id
== MODE_LINE_FACE_ID
2493 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2494 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2495 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2496 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2500 bzero (it
, sizeof *it
);
2501 it
->current
.overlay_string_index
= -1;
2502 it
->current
.dpvec_index
= -1;
2503 it
->base_face_id
= base_face_id
;
2505 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2507 /* The window in which we iterate over current_buffer: */
2508 XSETWINDOW (it
->window
, w
);
2510 it
->f
= XFRAME (w
->frame
);
2512 /* Extra space between lines (on window systems only). */
2513 if (base_face_id
== DEFAULT_FACE_ID
2514 && FRAME_WINDOW_P (it
->f
))
2516 if (NATNUMP (current_buffer
->extra_line_spacing
))
2517 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2518 else if (FLOATP (current_buffer
->extra_line_spacing
))
2519 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2520 * FRAME_LINE_HEIGHT (it
->f
));
2521 else if (it
->f
->extra_line_spacing
> 0)
2522 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2523 it
->max_extra_line_spacing
= 0;
2526 /* If realized faces have been removed, e.g. because of face
2527 attribute changes of named faces, recompute them. When running
2528 in batch mode, the face cache of Vterminal_frame is null. If
2529 we happen to get called, make a dummy face cache. */
2530 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2531 init_frame_faces (it
->f
);
2532 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2533 recompute_basic_faces (it
->f
);
2535 /* Current value of the `slice', `space-width', and 'height' properties. */
2536 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2537 it
->space_width
= Qnil
;
2538 it
->font_height
= Qnil
;
2539 it
->override_ascent
= -1;
2541 /* Are control characters displayed as `^C'? */
2542 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2544 /* -1 means everything between a CR and the following line end
2545 is invisible. >0 means lines indented more than this value are
2547 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2548 ? XFASTINT (current_buffer
->selective_display
)
2549 : (!NILP (current_buffer
->selective_display
)
2551 it
->selective_display_ellipsis_p
2552 = !NILP (current_buffer
->selective_display_ellipses
);
2554 /* Display table to use. */
2555 it
->dp
= window_display_table (w
);
2557 /* Are multibyte characters enabled in current_buffer? */
2558 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2560 /* Non-zero if we should highlight the region. */
2562 = (!NILP (Vtransient_mark_mode
)
2563 && !NILP (current_buffer
->mark_active
)
2564 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2566 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2567 start and end of a visible region in window IT->w. Set both to
2568 -1 to indicate no region. */
2569 if (highlight_region_p
2570 /* Maybe highlight only in selected window. */
2571 && (/* Either show region everywhere. */
2572 highlight_nonselected_windows
2573 /* Or show region in the selected window. */
2574 || w
== XWINDOW (selected_window
)
2575 /* Or show the region if we are in the mini-buffer and W is
2576 the window the mini-buffer refers to. */
2577 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2578 && WINDOWP (minibuf_selected_window
)
2579 && w
== XWINDOW (minibuf_selected_window
))))
2581 int charpos
= marker_position (current_buffer
->mark
);
2582 it
->region_beg_charpos
= min (PT
, charpos
);
2583 it
->region_end_charpos
= max (PT
, charpos
);
2586 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2588 /* Get the position at which the redisplay_end_trigger hook should
2589 be run, if it is to be run at all. */
2590 if (MARKERP (w
->redisplay_end_trigger
)
2591 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2592 it
->redisplay_end_trigger_charpos
2593 = marker_position (w
->redisplay_end_trigger
);
2594 else if (INTEGERP (w
->redisplay_end_trigger
))
2595 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2597 /* Correct bogus values of tab_width. */
2598 it
->tab_width
= XINT (current_buffer
->tab_width
);
2599 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2602 /* Are lines in the display truncated? */
2603 it
->truncate_lines_p
2604 = (base_face_id
!= DEFAULT_FACE_ID
2605 || XINT (it
->w
->hscroll
)
2606 || (truncate_partial_width_windows
2607 && !WINDOW_FULL_WIDTH_P (it
->w
))
2608 || !NILP (current_buffer
->truncate_lines
));
2610 /* Get dimensions of truncation and continuation glyphs. These are
2611 displayed as fringe bitmaps under X, so we don't need them for such
2613 if (!FRAME_WINDOW_P (it
->f
))
2615 if (it
->truncate_lines_p
)
2617 /* We will need the truncation glyph. */
2618 xassert (it
->glyph_row
== NULL
);
2619 produce_special_glyphs (it
, IT_TRUNCATION
);
2620 it
->truncation_pixel_width
= it
->pixel_width
;
2624 /* We will need the continuation glyph. */
2625 xassert (it
->glyph_row
== NULL
);
2626 produce_special_glyphs (it
, IT_CONTINUATION
);
2627 it
->continuation_pixel_width
= it
->pixel_width
;
2630 /* Reset these values to zero because the produce_special_glyphs
2631 above has changed them. */
2632 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2633 it
->phys_ascent
= it
->phys_descent
= 0;
2636 /* Set this after getting the dimensions of truncation and
2637 continuation glyphs, so that we don't produce glyphs when calling
2638 produce_special_glyphs, above. */
2639 it
->glyph_row
= row
;
2640 it
->area
= TEXT_AREA
;
2642 /* Get the dimensions of the display area. The display area
2643 consists of the visible window area plus a horizontally scrolled
2644 part to the left of the window. All x-values are relative to the
2645 start of this total display area. */
2646 if (base_face_id
!= DEFAULT_FACE_ID
)
2648 /* Mode lines, menu bar in terminal frames. */
2649 it
->first_visible_x
= 0;
2650 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2655 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2656 it
->last_visible_x
= (it
->first_visible_x
2657 + window_box_width (w
, TEXT_AREA
));
2659 /* If we truncate lines, leave room for the truncator glyph(s) at
2660 the right margin. Otherwise, leave room for the continuation
2661 glyph(s). Truncation and continuation glyphs are not inserted
2662 for window-based redisplay. */
2663 if (!FRAME_WINDOW_P (it
->f
))
2665 if (it
->truncate_lines_p
)
2666 it
->last_visible_x
-= it
->truncation_pixel_width
;
2668 it
->last_visible_x
-= it
->continuation_pixel_width
;
2671 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2672 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2675 /* Leave room for a border glyph. */
2676 if (!FRAME_WINDOW_P (it
->f
)
2677 && !WINDOW_RIGHTMOST_P (it
->w
))
2678 it
->last_visible_x
-= 1;
2680 it
->last_visible_y
= window_text_bottom_y (w
);
2682 /* For mode lines and alike, arrange for the first glyph having a
2683 left box line if the face specifies a box. */
2684 if (base_face_id
!= DEFAULT_FACE_ID
)
2688 it
->face_id
= base_face_id
;
2690 /* If we have a boxed mode line, make the first character appear
2691 with a left box line. */
2692 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2693 if (face
->box
!= FACE_NO_BOX
)
2694 it
->start_of_box_run_p
= 1;
2697 /* If a buffer position was specified, set the iterator there,
2698 getting overlays and face properties from that position. */
2699 if (charpos
>= BUF_BEG (current_buffer
))
2701 it
->end_charpos
= ZV
;
2703 IT_CHARPOS (*it
) = charpos
;
2705 /* Compute byte position if not specified. */
2706 if (bytepos
< charpos
)
2707 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2709 IT_BYTEPOS (*it
) = bytepos
;
2711 it
->start
= it
->current
;
2713 /* Compute faces etc. */
2714 reseat (it
, it
->current
.pos
, 1);
2721 /* Initialize IT for the display of window W with window start POS. */
2724 start_display (it
, w
, pos
)
2727 struct text_pos pos
;
2729 struct glyph_row
*row
;
2730 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2732 row
= w
->desired_matrix
->rows
+ first_vpos
;
2733 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2734 it
->first_vpos
= first_vpos
;
2736 /* Don't reseat to previous visible line start if current start
2737 position is in a string or image. */
2738 if (it
->method
== GET_FROM_BUFFER
&& !it
->truncate_lines_p
)
2740 int start_at_line_beg_p
;
2741 int first_y
= it
->current_y
;
2743 /* If window start is not at a line start, skip forward to POS to
2744 get the correct continuation lines width. */
2745 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2746 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2747 if (!start_at_line_beg_p
)
2751 reseat_at_previous_visible_line_start (it
);
2752 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2754 new_x
= it
->current_x
+ it
->pixel_width
;
2756 /* If lines are continued, this line may end in the middle
2757 of a multi-glyph character (e.g. a control character
2758 displayed as \003, or in the middle of an overlay
2759 string). In this case move_it_to above will not have
2760 taken us to the start of the continuation line but to the
2761 end of the continued line. */
2762 if (it
->current_x
> 0
2763 && !it
->truncate_lines_p
/* Lines are continued. */
2764 && (/* And glyph doesn't fit on the line. */
2765 new_x
> it
->last_visible_x
2766 /* Or it fits exactly and we're on a window
2768 || (new_x
== it
->last_visible_x
2769 && FRAME_WINDOW_P (it
->f
))))
2771 if (it
->current
.dpvec_index
>= 0
2772 || it
->current
.overlay_string_index
>= 0)
2774 set_iterator_to_next (it
, 1);
2775 move_it_in_display_line_to (it
, -1, -1, 0);
2778 it
->continuation_lines_width
+= it
->current_x
;
2781 /* We're starting a new display line, not affected by the
2782 height of the continued line, so clear the appropriate
2783 fields in the iterator structure. */
2784 it
->max_ascent
= it
->max_descent
= 0;
2785 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2787 it
->current_y
= first_y
;
2789 it
->current_x
= it
->hpos
= 0;
2793 #if 0 /* Don't assert the following because start_display is sometimes
2794 called intentionally with a window start that is not at a
2795 line start. Please leave this code in as a comment. */
2797 /* Window start should be on a line start, now. */
2798 xassert (it
->continuation_lines_width
2799 || IT_CHARPOS (it
) == BEGV
2800 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2805 /* Return 1 if POS is a position in ellipses displayed for invisible
2806 text. W is the window we display, for text property lookup. */
2809 in_ellipses_for_invisible_text_p (pos
, w
)
2810 struct display_pos
*pos
;
2813 Lisp_Object prop
, window
;
2815 int charpos
= CHARPOS (pos
->pos
);
2817 /* If POS specifies a position in a display vector, this might
2818 be for an ellipsis displayed for invisible text. We won't
2819 get the iterator set up for delivering that ellipsis unless
2820 we make sure that it gets aware of the invisible text. */
2821 if (pos
->dpvec_index
>= 0
2822 && pos
->overlay_string_index
< 0
2823 && CHARPOS (pos
->string_pos
) < 0
2825 && (XSETWINDOW (window
, w
),
2826 prop
= Fget_char_property (make_number (charpos
),
2827 Qinvisible
, window
),
2828 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2830 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2832 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2839 /* Initialize IT for stepping through current_buffer in window W,
2840 starting at position POS that includes overlay string and display
2841 vector/ control character translation position information. Value
2842 is zero if there are overlay strings with newlines at POS. */
2845 init_from_display_pos (it
, w
, pos
)
2848 struct display_pos
*pos
;
2850 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2851 int i
, overlay_strings_with_newlines
= 0;
2853 /* If POS specifies a position in a display vector, this might
2854 be for an ellipsis displayed for invisible text. We won't
2855 get the iterator set up for delivering that ellipsis unless
2856 we make sure that it gets aware of the invisible text. */
2857 if (in_ellipses_for_invisible_text_p (pos
, w
))
2863 /* Keep in mind: the call to reseat in init_iterator skips invisible
2864 text, so we might end up at a position different from POS. This
2865 is only a problem when POS is a row start after a newline and an
2866 overlay starts there with an after-string, and the overlay has an
2867 invisible property. Since we don't skip invisible text in
2868 display_line and elsewhere immediately after consuming the
2869 newline before the row start, such a POS will not be in a string,
2870 but the call to init_iterator below will move us to the
2872 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2874 /* This only scans the current chunk -- it should scan all chunks.
2875 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2876 to 16 in 22.1 to make this a lesser problem. */
2877 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2879 const char *s
= SDATA (it
->overlay_strings
[i
]);
2880 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2882 while (s
< e
&& *s
!= '\n')
2887 overlay_strings_with_newlines
= 1;
2892 /* If position is within an overlay string, set up IT to the right
2894 if (pos
->overlay_string_index
>= 0)
2898 /* If the first overlay string happens to have a `display'
2899 property for an image, the iterator will be set up for that
2900 image, and we have to undo that setup first before we can
2901 correct the overlay string index. */
2902 if (it
->method
== GET_FROM_IMAGE
)
2905 /* We already have the first chunk of overlay strings in
2906 IT->overlay_strings. Load more until the one for
2907 pos->overlay_string_index is in IT->overlay_strings. */
2908 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2910 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2911 it
->current
.overlay_string_index
= 0;
2914 load_overlay_strings (it
, 0);
2915 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2919 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2920 relative_index
= (it
->current
.overlay_string_index
2921 % OVERLAY_STRING_CHUNK_SIZE
);
2922 it
->string
= it
->overlay_strings
[relative_index
];
2923 xassert (STRINGP (it
->string
));
2924 it
->current
.string_pos
= pos
->string_pos
;
2925 it
->method
= GET_FROM_STRING
;
2928 #if 0 /* This is bogus because POS not having an overlay string
2929 position does not mean it's after the string. Example: A
2930 line starting with a before-string and initialization of IT
2931 to the previous row's end position. */
2932 else if (it
->current
.overlay_string_index
>= 0)
2934 /* If POS says we're already after an overlay string ending at
2935 POS, make sure to pop the iterator because it will be in
2936 front of that overlay string. When POS is ZV, we've thereby
2937 also ``processed'' overlay strings at ZV. */
2940 xassert (it
->current
.overlay_string_index
== -1);
2941 xassert (it
->method
== GET_FROM_BUFFER
);
2942 if (CHARPOS (pos
->pos
) == ZV
)
2943 it
->overlay_strings_at_end_processed_p
= 1;
2947 if (CHARPOS (pos
->string_pos
) >= 0)
2949 /* Recorded position is not in an overlay string, but in another
2950 string. This can only be a string from a `display' property.
2951 IT should already be filled with that string. */
2952 it
->current
.string_pos
= pos
->string_pos
;
2953 xassert (STRINGP (it
->string
));
2956 /* Restore position in display vector translations, control
2957 character translations or ellipses. */
2958 if (pos
->dpvec_index
>= 0)
2960 if (it
->dpvec
== NULL
)
2961 get_next_display_element (it
);
2962 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2963 it
->current
.dpvec_index
= pos
->dpvec_index
;
2967 return !overlay_strings_with_newlines
;
2971 /* Initialize IT for stepping through current_buffer in window W
2972 starting at ROW->start. */
2975 init_to_row_start (it
, w
, row
)
2978 struct glyph_row
*row
;
2980 init_from_display_pos (it
, w
, &row
->start
);
2981 it
->start
= row
->start
;
2982 it
->continuation_lines_width
= row
->continuation_lines_width
;
2987 /* Initialize IT for stepping through current_buffer in window W
2988 starting in the line following ROW, i.e. starting at ROW->end.
2989 Value is zero if there are overlay strings with newlines at ROW's
2993 init_to_row_end (it
, w
, row
)
2996 struct glyph_row
*row
;
3000 if (init_from_display_pos (it
, w
, &row
->end
))
3002 if (row
->continued_p
)
3003 it
->continuation_lines_width
3004 = row
->continuation_lines_width
+ row
->pixel_width
;
3015 /***********************************************************************
3017 ***********************************************************************/
3019 /* Called when IT reaches IT->stop_charpos. Handle text property and
3020 overlay changes. Set IT->stop_charpos to the next position where
3027 enum prop_handled handled
;
3028 int handle_overlay_change_p
;
3032 it
->current
.dpvec_index
= -1;
3033 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3034 it
->ignore_overlay_strings_at_pos_p
= 0;
3036 /* Use face of preceding text for ellipsis (if invisible) */
3037 if (it
->selective_display_ellipsis_p
)
3038 it
->saved_face_id
= it
->face_id
;
3042 handled
= HANDLED_NORMALLY
;
3044 /* Call text property handlers. */
3045 for (p
= it_props
; p
->handler
; ++p
)
3047 handled
= p
->handler (it
);
3049 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3051 else if (handled
== HANDLED_RETURN
)
3053 /* We still want to show before and after strings from
3054 overlays even if the actual buffer text is replaced. */
3055 if (!handle_overlay_change_p
|| it
->sp
> 1)
3057 if (!get_overlay_strings_1 (it
, 0, 0))
3059 it
->ignore_overlay_strings_at_pos_p
= 1;
3060 it
->string_from_display_prop_p
= 0;
3061 handle_overlay_change_p
= 0;
3062 handled
= HANDLED_RECOMPUTE_PROPS
;
3065 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3066 handle_overlay_change_p
= 0;
3069 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3071 /* Don't check for overlay strings below when set to deliver
3072 characters from a display vector. */
3073 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3074 handle_overlay_change_p
= 0;
3076 /* Handle overlay changes. */
3077 if (handle_overlay_change_p
)
3078 handled
= handle_overlay_change (it
);
3080 /* Determine where to stop next. */
3081 if (handled
== HANDLED_NORMALLY
)
3082 compute_stop_pos (it
);
3085 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3089 /* Compute IT->stop_charpos from text property and overlay change
3090 information for IT's current position. */
3093 compute_stop_pos (it
)
3096 register INTERVAL iv
, next_iv
;
3097 Lisp_Object object
, limit
, position
;
3099 /* If nowhere else, stop at the end. */
3100 it
->stop_charpos
= it
->end_charpos
;
3102 if (STRINGP (it
->string
))
3104 /* Strings are usually short, so don't limit the search for
3106 object
= it
->string
;
3108 position
= make_number (IT_STRING_CHARPOS (*it
));
3114 /* If next overlay change is in front of the current stop pos
3115 (which is IT->end_charpos), stop there. Note: value of
3116 next_overlay_change is point-max if no overlay change
3118 charpos
= next_overlay_change (IT_CHARPOS (*it
));
3119 if (charpos
< it
->stop_charpos
)
3120 it
->stop_charpos
= charpos
;
3122 /* If showing the region, we have to stop at the region
3123 start or end because the face might change there. */
3124 if (it
->region_beg_charpos
> 0)
3126 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3127 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3128 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3129 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3132 /* Set up variables for computing the stop position from text
3133 property changes. */
3134 XSETBUFFER (object
, current_buffer
);
3135 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3136 position
= make_number (IT_CHARPOS (*it
));
3140 /* Get the interval containing IT's position. Value is a null
3141 interval if there isn't such an interval. */
3142 iv
= validate_interval_range (object
, &position
, &position
, 0);
3143 if (!NULL_INTERVAL_P (iv
))
3145 Lisp_Object values_here
[LAST_PROP_IDX
];
3148 /* Get properties here. */
3149 for (p
= it_props
; p
->handler
; ++p
)
3150 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3152 /* Look for an interval following iv that has different
3154 for (next_iv
= next_interval (iv
);
3155 (!NULL_INTERVAL_P (next_iv
)
3157 || XFASTINT (limit
) > next_iv
->position
));
3158 next_iv
= next_interval (next_iv
))
3160 for (p
= it_props
; p
->handler
; ++p
)
3162 Lisp_Object new_value
;
3164 new_value
= textget (next_iv
->plist
, *p
->name
);
3165 if (!EQ (values_here
[p
->idx
], new_value
))
3173 if (!NULL_INTERVAL_P (next_iv
))
3175 if (INTEGERP (limit
)
3176 && next_iv
->position
>= XFASTINT (limit
))
3177 /* No text property change up to limit. */
3178 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3180 /* Text properties change in next_iv. */
3181 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3185 xassert (STRINGP (it
->string
)
3186 || (it
->stop_charpos
>= BEGV
3187 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3191 /* Return the position of the next overlay change after POS in
3192 current_buffer. Value is point-max if no overlay change
3193 follows. This is like `next-overlay-change' but doesn't use
3197 next_overlay_change (pos
)
3202 Lisp_Object
*overlays
;
3205 /* Get all overlays at the given position. */
3206 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3208 /* If any of these overlays ends before endpos,
3209 use its ending point instead. */
3210 for (i
= 0; i
< noverlays
; ++i
)
3215 oend
= OVERLAY_END (overlays
[i
]);
3216 oendpos
= OVERLAY_POSITION (oend
);
3217 endpos
= min (endpos
, oendpos
);
3225 /***********************************************************************
3227 ***********************************************************************/
3229 /* Handle changes in the `fontified' property of the current buffer by
3230 calling hook functions from Qfontification_functions to fontify
3233 static enum prop_handled
3234 handle_fontified_prop (it
)
3237 Lisp_Object prop
, pos
;
3238 enum prop_handled handled
= HANDLED_NORMALLY
;
3240 if (!NILP (Vmemory_full
))
3243 /* Get the value of the `fontified' property at IT's current buffer
3244 position. (The `fontified' property doesn't have a special
3245 meaning in strings.) If the value is nil, call functions from
3246 Qfontification_functions. */
3247 if (!STRINGP (it
->string
)
3249 && !NILP (Vfontification_functions
)
3250 && !NILP (Vrun_hooks
)
3251 && (pos
= make_number (IT_CHARPOS (*it
)),
3252 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3253 /* Ignore the special cased nil value always present at EOB since
3254 no amount of fontifying will be able to change it. */
3255 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3257 int count
= SPECPDL_INDEX ();
3260 val
= Vfontification_functions
;
3261 specbind (Qfontification_functions
, Qnil
);
3263 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3264 safe_call1 (val
, pos
);
3267 Lisp_Object globals
, fn
;
3268 struct gcpro gcpro1
, gcpro2
;
3271 GCPRO2 (val
, globals
);
3273 for (; CONSP (val
); val
= XCDR (val
))
3279 /* A value of t indicates this hook has a local
3280 binding; it means to run the global binding too.
3281 In a global value, t should not occur. If it
3282 does, we must ignore it to avoid an endless
3284 for (globals
= Fdefault_value (Qfontification_functions
);
3286 globals
= XCDR (globals
))
3288 fn
= XCAR (globals
);
3290 safe_call1 (fn
, pos
);
3294 safe_call1 (fn
, pos
);
3300 unbind_to (count
, Qnil
);
3302 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3303 something. This avoids an endless loop if they failed to
3304 fontify the text for which reason ever. */
3305 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3306 handled
= HANDLED_RECOMPUTE_PROPS
;
3314 /***********************************************************************
3316 ***********************************************************************/
3318 /* Set up iterator IT from face properties at its current position.
3319 Called from handle_stop. */
3321 static enum prop_handled
3322 handle_face_prop (it
)
3325 int new_face_id
, next_stop
;
3327 if (!STRINGP (it
->string
))
3330 = face_at_buffer_position (it
->w
,
3332 it
->region_beg_charpos
,
3333 it
->region_end_charpos
,
3336 + TEXT_PROP_DISTANCE_LIMIT
),
3339 /* Is this a start of a run of characters with box face?
3340 Caveat: this can be called for a freshly initialized
3341 iterator; face_id is -1 in this case. We know that the new
3342 face will not change until limit, i.e. if the new face has a
3343 box, all characters up to limit will have one. But, as
3344 usual, we don't know whether limit is really the end. */
3345 if (new_face_id
!= it
->face_id
)
3347 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3349 /* If new face has a box but old face has not, this is
3350 the start of a run of characters with box, i.e. it has
3351 a shadow on the left side. The value of face_id of the
3352 iterator will be -1 if this is the initial call that gets
3353 the face. In this case, we have to look in front of IT's
3354 position and see whether there is a face != new_face_id. */
3355 it
->start_of_box_run_p
3356 = (new_face
->box
!= FACE_NO_BOX
3357 && (it
->face_id
>= 0
3358 || IT_CHARPOS (*it
) == BEG
3359 || new_face_id
!= face_before_it_pos (it
)));
3360 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3365 int base_face_id
, bufpos
;
3367 if (it
->current
.overlay_string_index
>= 0)
3368 bufpos
= IT_CHARPOS (*it
);
3372 /* For strings from a buffer, i.e. overlay strings or strings
3373 from a `display' property, use the face at IT's current
3374 buffer position as the base face to merge with, so that
3375 overlay strings appear in the same face as surrounding
3376 text, unless they specify their own faces. */
3377 base_face_id
= underlying_face_id (it
);
3379 new_face_id
= face_at_string_position (it
->w
,
3381 IT_STRING_CHARPOS (*it
),
3383 it
->region_beg_charpos
,
3384 it
->region_end_charpos
,
3388 #if 0 /* This shouldn't be neccessary. Let's check it. */
3389 /* If IT is used to display a mode line we would really like to
3390 use the mode line face instead of the frame's default face. */
3391 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3392 && new_face_id
== DEFAULT_FACE_ID
)
3393 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3396 /* Is this a start of a run of characters with box? Caveat:
3397 this can be called for a freshly allocated iterator; face_id
3398 is -1 is this case. We know that the new face will not
3399 change until the next check pos, i.e. if the new face has a
3400 box, all characters up to that position will have a
3401 box. But, as usual, we don't know whether that position
3402 is really the end. */
3403 if (new_face_id
!= it
->face_id
)
3405 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3406 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3408 /* If new face has a box but old face hasn't, this is the
3409 start of a run of characters with box, i.e. it has a
3410 shadow on the left side. */
3411 it
->start_of_box_run_p
3412 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3413 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3417 it
->face_id
= new_face_id
;
3418 return HANDLED_NORMALLY
;
3422 /* Return the ID of the face ``underlying'' IT's current position,
3423 which is in a string. If the iterator is associated with a
3424 buffer, return the face at IT's current buffer position.
3425 Otherwise, use the iterator's base_face_id. */
3428 underlying_face_id (it
)
3431 int face_id
= it
->base_face_id
, i
;
3433 xassert (STRINGP (it
->string
));
3435 for (i
= it
->sp
- 1; i
>= 0; --i
)
3436 if (NILP (it
->stack
[i
].string
))
3437 face_id
= it
->stack
[i
].face_id
;
3443 /* Compute the face one character before or after the current position
3444 of IT. BEFORE_P non-zero means get the face in front of IT's
3445 position. Value is the id of the face. */
3448 face_before_or_after_it_pos (it
, before_p
)
3453 int next_check_charpos
;
3454 struct text_pos pos
;
3456 xassert (it
->s
== NULL
);
3458 if (STRINGP (it
->string
))
3460 int bufpos
, base_face_id
;
3462 /* No face change past the end of the string (for the case
3463 we are padding with spaces). No face change before the
3465 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3466 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3469 /* Set pos to the position before or after IT's current position. */
3471 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3473 /* For composition, we must check the character after the
3475 pos
= (it
->what
== IT_COMPOSITION
3476 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3477 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3479 if (it
->current
.overlay_string_index
>= 0)
3480 bufpos
= IT_CHARPOS (*it
);
3484 base_face_id
= underlying_face_id (it
);
3486 /* Get the face for ASCII, or unibyte. */
3487 face_id
= face_at_string_position (it
->w
,
3491 it
->region_beg_charpos
,
3492 it
->region_end_charpos
,
3493 &next_check_charpos
,
3496 /* Correct the face for charsets different from ASCII. Do it
3497 for the multibyte case only. The face returned above is
3498 suitable for unibyte text if IT->string is unibyte. */
3499 if (STRING_MULTIBYTE (it
->string
))
3501 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3502 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3504 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3506 c
= string_char_and_length (p
, rest
, &len
);
3507 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3512 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3513 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3516 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3517 pos
= it
->current
.pos
;
3520 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3523 if (it
->what
== IT_COMPOSITION
)
3524 /* For composition, we must check the position after the
3526 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3528 INC_TEXT_POS (pos
, it
->multibyte_p
);
3531 /* Determine face for CHARSET_ASCII, or unibyte. */
3532 face_id
= face_at_buffer_position (it
->w
,
3534 it
->region_beg_charpos
,
3535 it
->region_end_charpos
,
3536 &next_check_charpos
,
3539 /* Correct the face for charsets different from ASCII. Do it
3540 for the multibyte case only. The face returned above is
3541 suitable for unibyte text if current_buffer is unibyte. */
3542 if (it
->multibyte_p
)
3544 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3545 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3546 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3555 /***********************************************************************
3557 ***********************************************************************/
3559 /* Set up iterator IT from invisible properties at its current
3560 position. Called from handle_stop. */
3562 static enum prop_handled
3563 handle_invisible_prop (it
)
3566 enum prop_handled handled
= HANDLED_NORMALLY
;
3568 if (STRINGP (it
->string
))
3570 extern Lisp_Object Qinvisible
;
3571 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3573 /* Get the value of the invisible text property at the
3574 current position. Value will be nil if there is no such
3576 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3577 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3580 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3582 handled
= HANDLED_RECOMPUTE_PROPS
;
3584 /* Get the position at which the next change of the
3585 invisible text property can be found in IT->string.
3586 Value will be nil if the property value is the same for
3587 all the rest of IT->string. */
3588 XSETINT (limit
, SCHARS (it
->string
));
3589 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3592 /* Text at current position is invisible. The next
3593 change in the property is at position end_charpos.
3594 Move IT's current position to that position. */
3595 if (INTEGERP (end_charpos
)
3596 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3598 struct text_pos old
;
3599 old
= it
->current
.string_pos
;
3600 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3601 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3605 /* The rest of the string is invisible. If this is an
3606 overlay string, proceed with the next overlay string
3607 or whatever comes and return a character from there. */
3608 if (it
->current
.overlay_string_index
>= 0)
3610 next_overlay_string (it
);
3611 /* Don't check for overlay strings when we just
3612 finished processing them. */
3613 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3617 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3618 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3625 int invis_p
, newpos
, next_stop
, start_charpos
;
3626 Lisp_Object pos
, prop
, overlay
;
3628 /* First of all, is there invisible text at this position? */
3629 start_charpos
= IT_CHARPOS (*it
);
3630 pos
= make_number (IT_CHARPOS (*it
));
3631 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3633 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3635 /* If we are on invisible text, skip over it. */
3636 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3638 /* Record whether we have to display an ellipsis for the
3640 int display_ellipsis_p
= invis_p
== 2;
3642 handled
= HANDLED_RECOMPUTE_PROPS
;
3644 /* Loop skipping over invisible text. The loop is left at
3645 ZV or with IT on the first char being visible again. */
3648 /* Try to skip some invisible text. Return value is the
3649 position reached which can be equal to IT's position
3650 if there is nothing invisible here. This skips both
3651 over invisible text properties and overlays with
3652 invisible property. */
3653 newpos
= skip_invisible (IT_CHARPOS (*it
),
3654 &next_stop
, ZV
, it
->window
);
3656 /* If we skipped nothing at all we weren't at invisible
3657 text in the first place. If everything to the end of
3658 the buffer was skipped, end the loop. */
3659 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3663 /* We skipped some characters but not necessarily
3664 all there are. Check if we ended up on visible
3665 text. Fget_char_property returns the property of
3666 the char before the given position, i.e. if we
3667 get invis_p = 0, this means that the char at
3668 newpos is visible. */
3669 pos
= make_number (newpos
);
3670 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3671 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3674 /* If we ended up on invisible text, proceed to
3675 skip starting with next_stop. */
3677 IT_CHARPOS (*it
) = next_stop
;
3679 /* If there are adjacent invisible texts, don't lose the
3680 second one's ellipsis. */
3682 display_ellipsis_p
= 1;
3686 /* The position newpos is now either ZV or on visible text. */
3687 IT_CHARPOS (*it
) = newpos
;
3688 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3690 /* If there are before-strings at the start of invisible
3691 text, and the text is invisible because of a text
3692 property, arrange to show before-strings because 20.x did
3693 it that way. (If the text is invisible because of an
3694 overlay property instead of a text property, this is
3695 already handled in the overlay code.) */
3697 && get_overlay_strings (it
, start_charpos
))
3699 handled
= HANDLED_RECOMPUTE_PROPS
;
3700 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3702 else if (display_ellipsis_p
)
3704 /* Make sure that the glyphs of the ellipsis will get
3705 correct `charpos' values. If we would not update
3706 it->position here, the glyphs would belong to the
3707 last visible character _before_ the invisible
3708 text, which confuses `set_cursor_from_row'.
3710 We use the last invisible position instead of the
3711 first because this way the cursor is always drawn on
3712 the first "." of the ellipsis, whenever PT is inside
3713 the invisible text. Otherwise the cursor would be
3714 placed _after_ the ellipsis when the point is after the
3715 first invisible character. */
3716 if (!STRINGP (it
->object
))
3718 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3719 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3721 setup_for_ellipsis (it
, 0);
3722 /* Let the ellipsis display before
3723 considering any properties of the following char.
3724 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3725 handled
= HANDLED_RETURN
;
3734 /* Make iterator IT return `...' next.
3735 Replaces LEN characters from buffer. */
3738 setup_for_ellipsis (it
, len
)
3742 /* Use the display table definition for `...'. Invalid glyphs
3743 will be handled by the method returning elements from dpvec. */
3744 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3746 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3747 it
->dpvec
= v
->contents
;
3748 it
->dpend
= v
->contents
+ v
->size
;
3752 /* Default `...'. */
3753 it
->dpvec
= default_invis_vector
;
3754 it
->dpend
= default_invis_vector
+ 3;
3757 it
->dpvec_char_len
= len
;
3758 it
->current
.dpvec_index
= 0;
3759 it
->dpvec_face_id
= -1;
3761 /* Remember the current face id in case glyphs specify faces.
3762 IT's face is restored in set_iterator_to_next.
3763 saved_face_id was set to preceding char's face in handle_stop. */
3764 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3765 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3767 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3773 /***********************************************************************
3775 ***********************************************************************/
3777 /* Set up iterator IT from `display' property at its current position.
3778 Called from handle_stop.
3779 We return HANDLED_RETURN if some part of the display property
3780 overrides the display of the buffer text itself.
3781 Otherwise we return HANDLED_NORMALLY. */
3783 static enum prop_handled
3784 handle_display_prop (it
)
3787 Lisp_Object prop
, object
;
3788 struct text_pos
*position
;
3789 /* Nonzero if some property replaces the display of the text itself. */
3790 int display_replaced_p
= 0;
3792 if (STRINGP (it
->string
))
3794 object
= it
->string
;
3795 position
= &it
->current
.string_pos
;
3799 XSETWINDOW (object
, it
->w
);
3800 position
= &it
->current
.pos
;
3803 /* Reset those iterator values set from display property values. */
3804 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3805 it
->space_width
= Qnil
;
3806 it
->font_height
= Qnil
;
3809 /* We don't support recursive `display' properties, i.e. string
3810 values that have a string `display' property, that have a string
3811 `display' property etc. */
3812 if (!it
->string_from_display_prop_p
)
3813 it
->area
= TEXT_AREA
;
3815 prop
= Fget_char_property (make_number (position
->charpos
),
3818 return HANDLED_NORMALLY
;
3820 if (!STRINGP (it
->string
))
3821 object
= it
->w
->buffer
;
3824 /* Simple properties. */
3825 && !EQ (XCAR (prop
), Qimage
)
3826 && !EQ (XCAR (prop
), Qspace
)
3827 && !EQ (XCAR (prop
), Qwhen
)
3828 && !EQ (XCAR (prop
), Qslice
)
3829 && !EQ (XCAR (prop
), Qspace_width
)
3830 && !EQ (XCAR (prop
), Qheight
)
3831 && !EQ (XCAR (prop
), Qraise
)
3832 /* Marginal area specifications. */
3833 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3834 && !EQ (XCAR (prop
), Qleft_fringe
)
3835 && !EQ (XCAR (prop
), Qright_fringe
)
3836 && !NILP (XCAR (prop
)))
3838 for (; CONSP (prop
); prop
= XCDR (prop
))
3840 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3841 position
, display_replaced_p
))
3842 display_replaced_p
= 1;
3845 else if (VECTORP (prop
))
3848 for (i
= 0; i
< ASIZE (prop
); ++i
)
3849 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3850 position
, display_replaced_p
))
3851 display_replaced_p
= 1;
3855 int ret
= handle_single_display_spec (it
, prop
, object
, position
, 0);
3856 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3857 return HANDLED_RECOMPUTE_PROPS
;
3859 display_replaced_p
= 1;
3862 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3866 /* Value is the position of the end of the `display' property starting
3867 at START_POS in OBJECT. */
3869 static struct text_pos
3870 display_prop_end (it
, object
, start_pos
)
3873 struct text_pos start_pos
;
3876 struct text_pos end_pos
;
3878 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3879 Qdisplay
, object
, Qnil
);
3880 CHARPOS (end_pos
) = XFASTINT (end
);
3881 if (STRINGP (object
))
3882 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3884 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3890 /* Set up IT from a single `display' specification PROP. OBJECT
3891 is the object in which the `display' property was found. *POSITION
3892 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3893 means that we previously saw a display specification which already
3894 replaced text display with something else, for example an image;
3895 we ignore such properties after the first one has been processed.
3897 If PROP is a `space' or `image' specification, and in some other
3898 cases too, set *POSITION to the position where the `display'
3901 Value is non-zero if something was found which replaces the display
3902 of buffer or string text. Specifically, the value is -1 if that
3903 "something" is "nothing". */
3906 handle_single_display_spec (it
, spec
, object
, position
,
3907 display_replaced_before_p
)
3911 struct text_pos
*position
;
3912 int display_replaced_before_p
;
3915 Lisp_Object location
, value
;
3916 struct text_pos start_pos
, save_pos
;
3919 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3920 If the result is non-nil, use VALUE instead of SPEC. */
3922 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3931 if (!NILP (form
) && !EQ (form
, Qt
))
3933 int count
= SPECPDL_INDEX ();
3934 struct gcpro gcpro1
;
3936 /* Bind `object' to the object having the `display' property, a
3937 buffer or string. Bind `position' to the position in the
3938 object where the property was found, and `buffer-position'
3939 to the current position in the buffer. */
3940 specbind (Qobject
, object
);
3941 specbind (Qposition
, make_number (CHARPOS (*position
)));
3942 specbind (Qbuffer_position
,
3943 make_number (STRINGP (object
)
3944 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3946 form
= safe_eval (form
);
3948 unbind_to (count
, Qnil
);
3954 /* Handle `(height HEIGHT)' specifications. */
3956 && EQ (XCAR (spec
), Qheight
)
3957 && CONSP (XCDR (spec
)))
3959 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3962 it
->font_height
= XCAR (XCDR (spec
));
3963 if (!NILP (it
->font_height
))
3965 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3966 int new_height
= -1;
3968 if (CONSP (it
->font_height
)
3969 && (EQ (XCAR (it
->font_height
), Qplus
)
3970 || EQ (XCAR (it
->font_height
), Qminus
))
3971 && CONSP (XCDR (it
->font_height
))
3972 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3974 /* `(+ N)' or `(- N)' where N is an integer. */
3975 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3976 if (EQ (XCAR (it
->font_height
), Qplus
))
3978 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3980 else if (FUNCTIONP (it
->font_height
))
3982 /* Call function with current height as argument.
3983 Value is the new height. */
3985 height
= safe_call1 (it
->font_height
,
3986 face
->lface
[LFACE_HEIGHT_INDEX
]);
3987 if (NUMBERP (height
))
3988 new_height
= XFLOATINT (height
);
3990 else if (NUMBERP (it
->font_height
))
3992 /* Value is a multiple of the canonical char height. */
3995 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3996 new_height
= (XFLOATINT (it
->font_height
)
3997 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4001 /* Evaluate IT->font_height with `height' bound to the
4002 current specified height to get the new height. */
4003 int count
= SPECPDL_INDEX ();
4005 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4006 value
= safe_eval (it
->font_height
);
4007 unbind_to (count
, Qnil
);
4009 if (NUMBERP (value
))
4010 new_height
= XFLOATINT (value
);
4014 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4020 /* Handle `(space_width WIDTH)'. */
4022 && EQ (XCAR (spec
), Qspace_width
)
4023 && CONSP (XCDR (spec
)))
4025 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4028 value
= XCAR (XCDR (spec
));
4029 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4030 it
->space_width
= value
;
4035 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4037 && EQ (XCAR (spec
), Qslice
))
4041 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4044 if (tem
= XCDR (spec
), CONSP (tem
))
4046 it
->slice
.x
= XCAR (tem
);
4047 if (tem
= XCDR (tem
), CONSP (tem
))
4049 it
->slice
.y
= XCAR (tem
);
4050 if (tem
= XCDR (tem
), CONSP (tem
))
4052 it
->slice
.width
= XCAR (tem
);
4053 if (tem
= XCDR (tem
), CONSP (tem
))
4054 it
->slice
.height
= XCAR (tem
);
4062 /* Handle `(raise FACTOR)'. */
4064 && EQ (XCAR (spec
), Qraise
)
4065 && CONSP (XCDR (spec
)))
4067 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4070 #ifdef HAVE_WINDOW_SYSTEM
4071 value
= XCAR (XCDR (spec
));
4072 if (NUMBERP (value
))
4074 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4075 it
->voffset
= - (XFLOATINT (value
)
4076 * (FONT_HEIGHT (face
->font
)));
4078 #endif /* HAVE_WINDOW_SYSTEM */
4083 /* Don't handle the other kinds of display specifications
4084 inside a string that we got from a `display' property. */
4085 if (it
->string_from_display_prop_p
)
4088 /* Characters having this form of property are not displayed, so
4089 we have to find the end of the property. */
4090 start_pos
= *position
;
4091 *position
= display_prop_end (it
, object
, start_pos
);
4094 /* Stop the scan at that end position--we assume that all
4095 text properties change there. */
4096 it
->stop_charpos
= position
->charpos
;
4098 /* Handle `(left-fringe BITMAP [FACE])'
4099 and `(right-fringe BITMAP [FACE])'. */
4101 && (EQ (XCAR (spec
), Qleft_fringe
)
4102 || EQ (XCAR (spec
), Qright_fringe
))
4103 && CONSP (XCDR (spec
)))
4105 int face_id
= DEFAULT_FACE_ID
;
4108 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4109 /* If we return here, POSITION has been advanced
4110 across the text with this property. */
4113 #ifdef HAVE_WINDOW_SYSTEM
4114 value
= XCAR (XCDR (spec
));
4115 if (!SYMBOLP (value
)
4116 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4117 /* If we return here, POSITION has been advanced
4118 across the text with this property. */
4121 if (CONSP (XCDR (XCDR (spec
))))
4123 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4124 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4125 'A', FRINGE_FACE_ID
, 0);
4130 /* Save current settings of IT so that we can restore them
4131 when we are finished with the glyph property value. */
4133 save_pos
= it
->position
;
4134 it
->position
= *position
;
4136 it
->position
= save_pos
;
4138 it
->area
= TEXT_AREA
;
4139 it
->what
= IT_IMAGE
;
4140 it
->image_id
= -1; /* no image */
4141 it
->position
= start_pos
;
4142 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4143 it
->method
= GET_FROM_IMAGE
;
4144 it
->face_id
= face_id
;
4146 /* Say that we haven't consumed the characters with
4147 `display' property yet. The call to pop_it in
4148 set_iterator_to_next will clean this up. */
4149 *position
= start_pos
;
4151 if (EQ (XCAR (spec
), Qleft_fringe
))
4153 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4154 it
->left_user_fringe_face_id
= face_id
;
4158 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4159 it
->right_user_fringe_face_id
= face_id
;
4161 #endif /* HAVE_WINDOW_SYSTEM */
4165 /* Prepare to handle `((margin left-margin) ...)',
4166 `((margin right-margin) ...)' and `((margin nil) ...)'
4167 prefixes for display specifications. */
4168 location
= Qunbound
;
4169 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4173 value
= XCDR (spec
);
4175 value
= XCAR (value
);
4178 if (EQ (XCAR (tem
), Qmargin
)
4179 && (tem
= XCDR (tem
),
4180 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4182 || EQ (tem
, Qleft_margin
)
4183 || EQ (tem
, Qright_margin
))))
4187 if (EQ (location
, Qunbound
))
4193 /* After this point, VALUE is the property after any
4194 margin prefix has been stripped. It must be a string,
4195 an image specification, or `(space ...)'.
4197 LOCATION specifies where to display: `left-margin',
4198 `right-margin' or nil. */
4200 valid_p
= (STRINGP (value
)
4201 #ifdef HAVE_WINDOW_SYSTEM
4202 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
4203 #endif /* not HAVE_WINDOW_SYSTEM */
4204 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4206 if (valid_p
&& !display_replaced_before_p
)
4208 /* Save current settings of IT so that we can restore them
4209 when we are finished with the glyph property value. */
4210 save_pos
= it
->position
;
4211 it
->position
= *position
;
4213 it
->position
= save_pos
;
4215 if (NILP (location
))
4216 it
->area
= TEXT_AREA
;
4217 else if (EQ (location
, Qleft_margin
))
4218 it
->area
= LEFT_MARGIN_AREA
;
4220 it
->area
= RIGHT_MARGIN_AREA
;
4222 if (STRINGP (value
))
4224 if (SCHARS (value
) == 0)
4227 return -1; /* Replaced by "", i.e. nothing. */
4230 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4231 it
->current
.overlay_string_index
= -1;
4232 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4233 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4234 it
->method
= GET_FROM_STRING
;
4235 it
->stop_charpos
= 0;
4236 it
->string_from_display_prop_p
= 1;
4237 /* Say that we haven't consumed the characters with
4238 `display' property yet. The call to pop_it in
4239 set_iterator_to_next will clean this up. */
4240 *position
= start_pos
;
4242 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4244 it
->method
= GET_FROM_STRETCH
;
4246 *position
= it
->position
= start_pos
;
4248 #ifdef HAVE_WINDOW_SYSTEM
4251 it
->what
= IT_IMAGE
;
4252 it
->image_id
= lookup_image (it
->f
, value
);
4253 it
->position
= start_pos
;
4254 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4255 it
->method
= GET_FROM_IMAGE
;
4257 /* Say that we haven't consumed the characters with
4258 `display' property yet. The call to pop_it in
4259 set_iterator_to_next will clean this up. */
4260 *position
= start_pos
;
4262 #endif /* HAVE_WINDOW_SYSTEM */
4267 /* Invalid property or property not supported. Restore
4268 POSITION to what it was before. */
4269 *position
= start_pos
;
4274 /* Check if SPEC is a display specification value whose text should be
4275 treated as intangible. */
4278 single_display_spec_intangible_p (prop
)
4281 /* Skip over `when FORM'. */
4282 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4296 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4297 we don't need to treat text as intangible. */
4298 if (EQ (XCAR (prop
), Qmargin
))
4306 || EQ (XCAR (prop
), Qleft_margin
)
4307 || EQ (XCAR (prop
), Qright_margin
))
4311 return (CONSP (prop
)
4312 && (EQ (XCAR (prop
), Qimage
)
4313 || EQ (XCAR (prop
), Qspace
)));
4317 /* Check if PROP is a display property value whose text should be
4318 treated as intangible. */
4321 display_prop_intangible_p (prop
)
4325 && CONSP (XCAR (prop
))
4326 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4328 /* A list of sub-properties. */
4329 while (CONSP (prop
))
4331 if (single_display_spec_intangible_p (XCAR (prop
)))
4336 else if (VECTORP (prop
))
4338 /* A vector of sub-properties. */
4340 for (i
= 0; i
< ASIZE (prop
); ++i
)
4341 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4345 return single_display_spec_intangible_p (prop
);
4351 /* Return 1 if PROP is a display sub-property value containing STRING. */
4354 single_display_spec_string_p (prop
, string
)
4355 Lisp_Object prop
, string
;
4357 if (EQ (string
, prop
))
4360 /* Skip over `when FORM'. */
4361 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4370 /* Skip over `margin LOCATION'. */
4371 if (EQ (XCAR (prop
), Qmargin
))
4382 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4386 /* Return 1 if STRING appears in the `display' property PROP. */
4389 display_prop_string_p (prop
, string
)
4390 Lisp_Object prop
, string
;
4393 && CONSP (XCAR (prop
))
4394 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4396 /* A list of sub-properties. */
4397 while (CONSP (prop
))
4399 if (single_display_spec_string_p (XCAR (prop
), string
))
4404 else if (VECTORP (prop
))
4406 /* A vector of sub-properties. */
4408 for (i
= 0; i
< ASIZE (prop
); ++i
)
4409 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4413 return single_display_spec_string_p (prop
, string
);
4419 /* Determine from which buffer position in W's buffer STRING comes
4420 from. AROUND_CHARPOS is an approximate position where it could
4421 be from. Value is the buffer position or 0 if it couldn't be
4424 W's buffer must be current.
4426 This function is necessary because we don't record buffer positions
4427 in glyphs generated from strings (to keep struct glyph small).
4428 This function may only use code that doesn't eval because it is
4429 called asynchronously from note_mouse_highlight. */
4432 string_buffer_position (w
, string
, around_charpos
)
4437 Lisp_Object limit
, prop
, pos
;
4438 const int MAX_DISTANCE
= 1000;
4441 pos
= make_number (around_charpos
);
4442 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4443 while (!found
&& !EQ (pos
, limit
))
4445 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4446 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4449 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4454 pos
= make_number (around_charpos
);
4455 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4456 while (!found
&& !EQ (pos
, limit
))
4458 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4459 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4462 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4467 return found
? XINT (pos
) : 0;
4472 /***********************************************************************
4473 `composition' property
4474 ***********************************************************************/
4476 /* Set up iterator IT from `composition' property at its current
4477 position. Called from handle_stop. */
4479 static enum prop_handled
4480 handle_composition_prop (it
)
4483 Lisp_Object prop
, string
;
4484 int pos
, pos_byte
, end
;
4485 enum prop_handled handled
= HANDLED_NORMALLY
;
4487 if (STRINGP (it
->string
))
4489 pos
= IT_STRING_CHARPOS (*it
);
4490 pos_byte
= IT_STRING_BYTEPOS (*it
);
4491 string
= it
->string
;
4495 pos
= IT_CHARPOS (*it
);
4496 pos_byte
= IT_BYTEPOS (*it
);
4500 /* If there's a valid composition and point is not inside of the
4501 composition (in the case that the composition is from the current
4502 buffer), draw a glyph composed from the composition components. */
4503 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
4504 && COMPOSITION_VALID_P (pos
, end
, prop
)
4505 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
4507 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4511 struct composition
*cmp
= composition_table
[id
];
4513 if (cmp
->glyph_len
== 0)
4516 if (STRINGP (it
->string
))
4518 IT_STRING_CHARPOS (*it
) = end
;
4519 IT_STRING_BYTEPOS (*it
) = string_char_to_byte (it
->string
,
4524 IT_CHARPOS (*it
) = end
;
4525 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (end
);
4527 return HANDLED_RECOMPUTE_PROPS
;
4530 it
->stop_charpos
= end
;
4533 it
->method
= GET_FROM_COMPOSITION
;
4535 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4536 /* For a terminal, draw only the first character of the
4538 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4539 it
->len
= (STRINGP (it
->string
)
4540 ? string_char_to_byte (it
->string
, end
)
4541 : CHAR_TO_BYTE (end
)) - pos_byte
;
4542 handled
= HANDLED_RETURN
;
4551 /***********************************************************************
4553 ***********************************************************************/
4555 /* The following structure is used to record overlay strings for
4556 later sorting in load_overlay_strings. */
4558 struct overlay_entry
4560 Lisp_Object overlay
;
4567 /* Set up iterator IT from overlay strings at its current position.
4568 Called from handle_stop. */
4570 static enum prop_handled
4571 handle_overlay_change (it
)
4574 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4575 return HANDLED_RECOMPUTE_PROPS
;
4577 return HANDLED_NORMALLY
;
4581 /* Set up the next overlay string for delivery by IT, if there is an
4582 overlay string to deliver. Called by set_iterator_to_next when the
4583 end of the current overlay string is reached. If there are more
4584 overlay strings to display, IT->string and
4585 IT->current.overlay_string_index are set appropriately here.
4586 Otherwise IT->string is set to nil. */
4589 next_overlay_string (it
)
4592 ++it
->current
.overlay_string_index
;
4593 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4595 /* No more overlay strings. Restore IT's settings to what
4596 they were before overlay strings were processed, and
4597 continue to deliver from current_buffer. */
4598 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4602 || it
->method
== GET_FROM_COMPOSITION
4603 || (NILP (it
->string
)
4604 && it
->method
== GET_FROM_BUFFER
4605 && it
->stop_charpos
>= BEGV
4606 && it
->stop_charpos
<= it
->end_charpos
));
4607 it
->current
.overlay_string_index
= -1;
4608 it
->n_overlay_strings
= 0;
4610 /* If we're at the end of the buffer, record that we have
4611 processed the overlay strings there already, so that
4612 next_element_from_buffer doesn't try it again. */
4613 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4614 it
->overlay_strings_at_end_processed_p
= 1;
4616 /* If we have to display `...' for invisible text, set
4617 the iterator up for that. */
4618 if (display_ellipsis_p
)
4619 setup_for_ellipsis (it
, 0);
4623 /* There are more overlay strings to process. If
4624 IT->current.overlay_string_index has advanced to a position
4625 where we must load IT->overlay_strings with more strings, do
4627 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4629 if (it
->current
.overlay_string_index
&& i
== 0)
4630 load_overlay_strings (it
, 0);
4632 /* Initialize IT to deliver display elements from the overlay
4634 it
->string
= it
->overlay_strings
[i
];
4635 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4636 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4637 it
->method
= GET_FROM_STRING
;
4638 it
->stop_charpos
= 0;
4645 /* Compare two overlay_entry structures E1 and E2. Used as a
4646 comparison function for qsort in load_overlay_strings. Overlay
4647 strings for the same position are sorted so that
4649 1. All after-strings come in front of before-strings, except
4650 when they come from the same overlay.
4652 2. Within after-strings, strings are sorted so that overlay strings
4653 from overlays with higher priorities come first.
4655 2. Within before-strings, strings are sorted so that overlay
4656 strings from overlays with higher priorities come last.
4658 Value is analogous to strcmp. */
4662 compare_overlay_entries (e1
, e2
)
4665 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4666 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4669 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4671 /* Let after-strings appear in front of before-strings if
4672 they come from different overlays. */
4673 if (EQ (entry1
->overlay
, entry2
->overlay
))
4674 result
= entry1
->after_string_p
? 1 : -1;
4676 result
= entry1
->after_string_p
? -1 : 1;
4678 else if (entry1
->after_string_p
)
4679 /* After-strings sorted in order of decreasing priority. */
4680 result
= entry2
->priority
- entry1
->priority
;
4682 /* Before-strings sorted in order of increasing priority. */
4683 result
= entry1
->priority
- entry2
->priority
;
4689 /* Load the vector IT->overlay_strings with overlay strings from IT's
4690 current buffer position, or from CHARPOS if that is > 0. Set
4691 IT->n_overlays to the total number of overlay strings found.
4693 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4694 a time. On entry into load_overlay_strings,
4695 IT->current.overlay_string_index gives the number of overlay
4696 strings that have already been loaded by previous calls to this
4699 IT->add_overlay_start contains an additional overlay start
4700 position to consider for taking overlay strings from, if non-zero.
4701 This position comes into play when the overlay has an `invisible'
4702 property, and both before and after-strings. When we've skipped to
4703 the end of the overlay, because of its `invisible' property, we
4704 nevertheless want its before-string to appear.
4705 IT->add_overlay_start will contain the overlay start position
4708 Overlay strings are sorted so that after-string strings come in
4709 front of before-string strings. Within before and after-strings,
4710 strings are sorted by overlay priority. See also function
4711 compare_overlay_entries. */
4714 load_overlay_strings (it
, charpos
)
4718 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4719 Lisp_Object overlay
, window
, str
, invisible
;
4720 struct Lisp_Overlay
*ov
;
4723 int n
= 0, i
, j
, invis_p
;
4724 struct overlay_entry
*entries
4725 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4728 charpos
= IT_CHARPOS (*it
);
4730 /* Append the overlay string STRING of overlay OVERLAY to vector
4731 `entries' which has size `size' and currently contains `n'
4732 elements. AFTER_P non-zero means STRING is an after-string of
4734 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4737 Lisp_Object priority; \
4741 int new_size = 2 * size; \
4742 struct overlay_entry *old = entries; \
4744 (struct overlay_entry *) alloca (new_size \
4745 * sizeof *entries); \
4746 bcopy (old, entries, size * sizeof *entries); \
4750 entries[n].string = (STRING); \
4751 entries[n].overlay = (OVERLAY); \
4752 priority = Foverlay_get ((OVERLAY), Qpriority); \
4753 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4754 entries[n].after_string_p = (AFTER_P); \
4759 /* Process overlay before the overlay center. */
4760 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4762 XSETMISC (overlay
, ov
);
4763 xassert (OVERLAYP (overlay
));
4764 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4765 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4770 /* Skip this overlay if it doesn't start or end at IT's current
4772 if (end
!= charpos
&& start
!= charpos
)
4775 /* Skip this overlay if it doesn't apply to IT->w. */
4776 window
= Foverlay_get (overlay
, Qwindow
);
4777 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4780 /* If the text ``under'' the overlay is invisible, both before-
4781 and after-strings from this overlay are visible; start and
4782 end position are indistinguishable. */
4783 invisible
= Foverlay_get (overlay
, Qinvisible
);
4784 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4786 /* If overlay has a non-empty before-string, record it. */
4787 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4788 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4790 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4792 /* If overlay has a non-empty after-string, record it. */
4793 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4794 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4796 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4799 /* Process overlays after the overlay center. */
4800 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4802 XSETMISC (overlay
, ov
);
4803 xassert (OVERLAYP (overlay
));
4804 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4805 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4807 if (start
> charpos
)
4810 /* Skip this overlay if it doesn't start or end at IT's current
4812 if (end
!= charpos
&& start
!= charpos
)
4815 /* Skip this overlay if it doesn't apply to IT->w. */
4816 window
= Foverlay_get (overlay
, Qwindow
);
4817 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4820 /* If the text ``under'' the overlay is invisible, it has a zero
4821 dimension, and both before- and after-strings apply. */
4822 invisible
= Foverlay_get (overlay
, Qinvisible
);
4823 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4825 /* If overlay has a non-empty before-string, record it. */
4826 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4827 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4829 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4831 /* If overlay has a non-empty after-string, record it. */
4832 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4833 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4835 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4838 #undef RECORD_OVERLAY_STRING
4842 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4844 /* Record the total number of strings to process. */
4845 it
->n_overlay_strings
= n
;
4847 /* IT->current.overlay_string_index is the number of overlay strings
4848 that have already been consumed by IT. Copy some of the
4849 remaining overlay strings to IT->overlay_strings. */
4851 j
= it
->current
.overlay_string_index
;
4852 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4853 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4859 /* Get the first chunk of overlay strings at IT's current buffer
4860 position, or at CHARPOS if that is > 0. Value is non-zero if at
4861 least one overlay string was found. */
4864 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
4868 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4869 process. This fills IT->overlay_strings with strings, and sets
4870 IT->n_overlay_strings to the total number of strings to process.
4871 IT->pos.overlay_string_index has to be set temporarily to zero
4872 because load_overlay_strings needs this; it must be set to -1
4873 when no overlay strings are found because a zero value would
4874 indicate a position in the first overlay string. */
4875 it
->current
.overlay_string_index
= 0;
4876 load_overlay_strings (it
, charpos
);
4878 /* If we found overlay strings, set up IT to deliver display
4879 elements from the first one. Otherwise set up IT to deliver
4880 from current_buffer. */
4881 if (it
->n_overlay_strings
)
4883 /* Make sure we know settings in current_buffer, so that we can
4884 restore meaningful values when we're done with the overlay
4887 compute_stop_pos (it
);
4888 xassert (it
->face_id
>= 0);
4890 /* Save IT's settings. They are restored after all overlay
4891 strings have been processed. */
4892 xassert (!compute_stop_p
|| it
->sp
== 0);
4895 /* Set up IT to deliver display elements from the first overlay
4897 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4898 it
->string
= it
->overlay_strings
[0];
4899 it
->stop_charpos
= 0;
4900 xassert (STRINGP (it
->string
));
4901 it
->end_charpos
= SCHARS (it
->string
);
4902 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4903 it
->method
= GET_FROM_STRING
;
4907 it
->current
.overlay_string_index
= -1;
4912 get_overlay_strings (it
, charpos
)
4917 it
->method
= GET_FROM_BUFFER
;
4919 (void) get_overlay_strings_1 (it
, charpos
, 1);
4923 /* Value is non-zero if we found at least one overlay string. */
4924 return STRINGP (it
->string
);
4929 /***********************************************************************
4930 Saving and restoring state
4931 ***********************************************************************/
4933 /* Save current settings of IT on IT->stack. Called, for example,
4934 before setting up IT for an overlay string, to be able to restore
4935 IT's settings to what they were after the overlay string has been
4942 struct iterator_stack_entry
*p
;
4944 xassert (it
->sp
< IT_STACK_SIZE
);
4945 p
= it
->stack
+ it
->sp
;
4947 p
->stop_charpos
= it
->stop_charpos
;
4948 xassert (it
->face_id
>= 0);
4949 p
->face_id
= it
->face_id
;
4950 p
->string
= it
->string
;
4951 p
->method
= it
->method
;
4954 case GET_FROM_IMAGE
:
4955 p
->u
.image
.object
= it
->object
;
4956 p
->u
.image
.image_id
= it
->image_id
;
4957 p
->u
.image
.slice
= it
->slice
;
4959 case GET_FROM_COMPOSITION
:
4960 p
->u
.comp
.object
= it
->object
;
4961 p
->u
.comp
.c
= it
->c
;
4962 p
->u
.comp
.len
= it
->len
;
4963 p
->u
.comp
.cmp_id
= it
->cmp_id
;
4964 p
->u
.comp
.cmp_len
= it
->cmp_len
;
4966 case GET_FROM_STRETCH
:
4967 p
->u
.stretch
.object
= it
->object
;
4970 p
->position
= it
->position
;
4971 p
->current
= it
->current
;
4972 p
->end_charpos
= it
->end_charpos
;
4973 p
->string_nchars
= it
->string_nchars
;
4975 p
->multibyte_p
= it
->multibyte_p
;
4976 p
->space_width
= it
->space_width
;
4977 p
->font_height
= it
->font_height
;
4978 p
->voffset
= it
->voffset
;
4979 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4980 p
->display_ellipsis_p
= 0;
4985 /* Restore IT's settings from IT->stack. Called, for example, when no
4986 more overlay strings must be processed, and we return to delivering
4987 display elements from a buffer, or when the end of a string from a
4988 `display' property is reached and we return to delivering display
4989 elements from an overlay string, or from a buffer. */
4995 struct iterator_stack_entry
*p
;
4997 xassert (it
->sp
> 0);
4999 p
= it
->stack
+ it
->sp
;
5000 it
->stop_charpos
= p
->stop_charpos
;
5001 it
->face_id
= p
->face_id
;
5002 it
->current
= p
->current
;
5003 it
->position
= p
->position
;
5004 it
->string
= p
->string
;
5005 if (NILP (it
->string
))
5006 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5007 it
->method
= p
->method
;
5010 case GET_FROM_IMAGE
:
5011 it
->image_id
= p
->u
.image
.image_id
;
5012 it
->object
= p
->u
.image
.object
;
5013 it
->slice
= p
->u
.image
.slice
;
5015 case GET_FROM_COMPOSITION
:
5016 it
->object
= p
->u
.comp
.object
;
5017 it
->c
= p
->u
.comp
.c
;
5018 it
->len
= p
->u
.comp
.len
;
5019 it
->cmp_id
= p
->u
.comp
.cmp_id
;
5020 it
->cmp_len
= p
->u
.comp
.cmp_len
;
5022 case GET_FROM_STRETCH
:
5023 it
->object
= p
->u
.comp
.object
;
5025 case GET_FROM_BUFFER
:
5026 it
->object
= it
->w
->buffer
;
5028 case GET_FROM_STRING
:
5029 it
->object
= it
->string
;
5032 it
->end_charpos
= p
->end_charpos
;
5033 it
->string_nchars
= p
->string_nchars
;
5035 it
->multibyte_p
= p
->multibyte_p
;
5036 it
->space_width
= p
->space_width
;
5037 it
->font_height
= p
->font_height
;
5038 it
->voffset
= p
->voffset
;
5039 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5044 /***********************************************************************
5046 ***********************************************************************/
5048 /* Set IT's current position to the previous line start. */
5051 back_to_previous_line_start (it
)
5054 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5055 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5059 /* Move IT to the next line start.
5061 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5062 we skipped over part of the text (as opposed to moving the iterator
5063 continuously over the text). Otherwise, don't change the value
5066 Newlines may come from buffer text, overlay strings, or strings
5067 displayed via the `display' property. That's the reason we can't
5068 simply use find_next_newline_no_quit.
5070 Note that this function may not skip over invisible text that is so
5071 because of text properties and immediately follows a newline. If
5072 it would, function reseat_at_next_visible_line_start, when called
5073 from set_iterator_to_next, would effectively make invisible
5074 characters following a newline part of the wrong glyph row, which
5075 leads to wrong cursor motion. */
5078 forward_to_next_line_start (it
, skipped_p
)
5082 int old_selective
, newline_found_p
, n
;
5083 const int MAX_NEWLINE_DISTANCE
= 500;
5085 /* If already on a newline, just consume it to avoid unintended
5086 skipping over invisible text below. */
5087 if (it
->what
== IT_CHARACTER
5089 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5091 set_iterator_to_next (it
, 0);
5096 /* Don't handle selective display in the following. It's (a)
5097 unnecessary because it's done by the caller, and (b) leads to an
5098 infinite recursion because next_element_from_ellipsis indirectly
5099 calls this function. */
5100 old_selective
= it
->selective
;
5103 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5104 from buffer text. */
5105 for (n
= newline_found_p
= 0;
5106 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5107 n
+= STRINGP (it
->string
) ? 0 : 1)
5109 if (!get_next_display_element (it
))
5111 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5112 set_iterator_to_next (it
, 0);
5115 /* If we didn't find a newline near enough, see if we can use a
5117 if (!newline_found_p
)
5119 int start
= IT_CHARPOS (*it
);
5120 int limit
= find_next_newline_no_quit (start
, 1);
5123 xassert (!STRINGP (it
->string
));
5125 /* If there isn't any `display' property in sight, and no
5126 overlays, we can just use the position of the newline in
5128 if (it
->stop_charpos
>= limit
5129 || ((pos
= Fnext_single_property_change (make_number (start
),
5131 Qnil
, make_number (limit
)),
5133 && next_overlay_change (start
) == ZV
))
5135 IT_CHARPOS (*it
) = limit
;
5136 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5137 *skipped_p
= newline_found_p
= 1;
5141 while (get_next_display_element (it
)
5142 && !newline_found_p
)
5144 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5145 set_iterator_to_next (it
, 0);
5150 it
->selective
= old_selective
;
5151 return newline_found_p
;
5155 /* Set IT's current position to the previous visible line start. Skip
5156 invisible text that is so either due to text properties or due to
5157 selective display. Caution: this does not change IT->current_x and
5161 back_to_previous_visible_line_start (it
)
5164 while (IT_CHARPOS (*it
) > BEGV
)
5166 back_to_previous_line_start (it
);
5168 if (IT_CHARPOS (*it
) <= BEGV
)
5171 /* If selective > 0, then lines indented more than that values
5173 if (it
->selective
> 0
5174 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5175 (double) it
->selective
)) /* iftc */
5178 /* Check the newline before point for invisibility. */
5181 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5182 Qinvisible
, it
->window
);
5183 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5187 if (IT_CHARPOS (*it
) <= BEGV
)
5194 Lisp_Object val
, overlay
;
5196 /* If newline is part of a composition, continue from start of composition */
5197 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5198 && beg
< IT_CHARPOS (*it
))
5201 /* If newline is replaced by a display property, find start of overlay
5202 or interval and continue search from that point. */
5204 pos
= --IT_CHARPOS (it2
);
5207 if (handle_display_prop (&it2
) == HANDLED_RETURN
5208 && !NILP (val
= get_char_property_and_overlay
5209 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5210 && (OVERLAYP (overlay
)
5211 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5212 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5215 /* Newline is not replaced by anything -- so we are done. */
5221 IT_CHARPOS (*it
) = beg
;
5222 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5226 it
->continuation_lines_width
= 0;
5228 xassert (IT_CHARPOS (*it
) >= BEGV
);
5229 xassert (IT_CHARPOS (*it
) == BEGV
5230 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5235 /* Reseat iterator IT at the previous visible line start. Skip
5236 invisible text that is so either due to text properties or due to
5237 selective display. At the end, update IT's overlay information,
5238 face information etc. */
5241 reseat_at_previous_visible_line_start (it
)
5244 back_to_previous_visible_line_start (it
);
5245 reseat (it
, it
->current
.pos
, 1);
5250 /* Reseat iterator IT on the next visible line start in the current
5251 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5252 preceding the line start. Skip over invisible text that is so
5253 because of selective display. Compute faces, overlays etc at the
5254 new position. Note that this function does not skip over text that
5255 is invisible because of text properties. */
5258 reseat_at_next_visible_line_start (it
, on_newline_p
)
5262 int newline_found_p
, skipped_p
= 0;
5264 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5266 /* Skip over lines that are invisible because they are indented
5267 more than the value of IT->selective. */
5268 if (it
->selective
> 0)
5269 while (IT_CHARPOS (*it
) < ZV
5270 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5271 (double) it
->selective
)) /* iftc */
5273 xassert (IT_BYTEPOS (*it
) == BEGV
5274 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5275 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5278 /* Position on the newline if that's what's requested. */
5279 if (on_newline_p
&& newline_found_p
)
5281 if (STRINGP (it
->string
))
5283 if (IT_STRING_CHARPOS (*it
) > 0)
5285 --IT_STRING_CHARPOS (*it
);
5286 --IT_STRING_BYTEPOS (*it
);
5289 else if (IT_CHARPOS (*it
) > BEGV
)
5293 reseat (it
, it
->current
.pos
, 0);
5297 reseat (it
, it
->current
.pos
, 0);
5304 /***********************************************************************
5305 Changing an iterator's position
5306 ***********************************************************************/
5308 /* Change IT's current position to POS in current_buffer. If FORCE_P
5309 is non-zero, always check for text properties at the new position.
5310 Otherwise, text properties are only looked up if POS >=
5311 IT->check_charpos of a property. */
5314 reseat (it
, pos
, force_p
)
5316 struct text_pos pos
;
5319 int original_pos
= IT_CHARPOS (*it
);
5321 reseat_1 (it
, pos
, 0);
5323 /* Determine where to check text properties. Avoid doing it
5324 where possible because text property lookup is very expensive. */
5326 || CHARPOS (pos
) > it
->stop_charpos
5327 || CHARPOS (pos
) < original_pos
)
5334 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5335 IT->stop_pos to POS, also. */
5338 reseat_1 (it
, pos
, set_stop_p
)
5340 struct text_pos pos
;
5343 /* Don't call this function when scanning a C string. */
5344 xassert (it
->s
== NULL
);
5346 /* POS must be a reasonable value. */
5347 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5349 it
->current
.pos
= it
->position
= pos
;
5350 it
->end_charpos
= ZV
;
5352 it
->current
.dpvec_index
= -1;
5353 it
->current
.overlay_string_index
= -1;
5354 IT_STRING_CHARPOS (*it
) = -1;
5355 IT_STRING_BYTEPOS (*it
) = -1;
5357 it
->method
= GET_FROM_BUFFER
;
5358 it
->object
= it
->w
->buffer
;
5359 it
->area
= TEXT_AREA
;
5360 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5362 it
->string_from_display_prop_p
= 0;
5363 it
->face_before_selective_p
= 0;
5366 it
->stop_charpos
= CHARPOS (pos
);
5370 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5371 If S is non-null, it is a C string to iterate over. Otherwise,
5372 STRING gives a Lisp string to iterate over.
5374 If PRECISION > 0, don't return more then PRECISION number of
5375 characters from the string.
5377 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5378 characters have been returned. FIELD_WIDTH < 0 means an infinite
5381 MULTIBYTE = 0 means disable processing of multibyte characters,
5382 MULTIBYTE > 0 means enable it,
5383 MULTIBYTE < 0 means use IT->multibyte_p.
5385 IT must be initialized via a prior call to init_iterator before
5386 calling this function. */
5389 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5394 int precision
, field_width
, multibyte
;
5396 /* No region in strings. */
5397 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5399 /* No text property checks performed by default, but see below. */
5400 it
->stop_charpos
= -1;
5402 /* Set iterator position and end position. */
5403 bzero (&it
->current
, sizeof it
->current
);
5404 it
->current
.overlay_string_index
= -1;
5405 it
->current
.dpvec_index
= -1;
5406 xassert (charpos
>= 0);
5408 /* If STRING is specified, use its multibyteness, otherwise use the
5409 setting of MULTIBYTE, if specified. */
5411 it
->multibyte_p
= multibyte
> 0;
5415 xassert (STRINGP (string
));
5416 it
->string
= string
;
5418 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5419 it
->method
= GET_FROM_STRING
;
5420 it
->current
.string_pos
= string_pos (charpos
, string
);
5427 /* Note that we use IT->current.pos, not it->current.string_pos,
5428 for displaying C strings. */
5429 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5430 if (it
->multibyte_p
)
5432 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5433 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5437 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5438 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5441 it
->method
= GET_FROM_C_STRING
;
5444 /* PRECISION > 0 means don't return more than PRECISION characters
5446 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5447 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5449 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5450 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5451 FIELD_WIDTH < 0 means infinite field width. This is useful for
5452 padding with `-' at the end of a mode line. */
5453 if (field_width
< 0)
5454 field_width
= INFINITY
;
5455 if (field_width
> it
->end_charpos
- charpos
)
5456 it
->end_charpos
= charpos
+ field_width
;
5458 /* Use the standard display table for displaying strings. */
5459 if (DISP_TABLE_P (Vstandard_display_table
))
5460 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5462 it
->stop_charpos
= charpos
;
5468 /***********************************************************************
5470 ***********************************************************************/
5472 /* Map enum it_method value to corresponding next_element_from_* function. */
5474 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5476 next_element_from_buffer
,
5477 next_element_from_display_vector
,
5478 next_element_from_composition
,
5479 next_element_from_string
,
5480 next_element_from_c_string
,
5481 next_element_from_image
,
5482 next_element_from_stretch
5486 /* Load IT's display element fields with information about the next
5487 display element from the current position of IT. Value is zero if
5488 end of buffer (or C string) is reached. */
5490 static struct frame
*last_escape_glyph_frame
= NULL
;
5491 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5492 static int last_escape_glyph_merged_face_id
= 0;
5495 get_next_display_element (it
)
5498 /* Non-zero means that we found a display element. Zero means that
5499 we hit the end of what we iterate over. Performance note: the
5500 function pointer `method' used here turns out to be faster than
5501 using a sequence of if-statements. */
5505 success_p
= (*get_next_element
[it
->method
]) (it
);
5507 if (it
->what
== IT_CHARACTER
)
5509 /* Map via display table or translate control characters.
5510 IT->c, IT->len etc. have been set to the next character by
5511 the function call above. If we have a display table, and it
5512 contains an entry for IT->c, translate it. Don't do this if
5513 IT->c itself comes from a display table, otherwise we could
5514 end up in an infinite recursion. (An alternative could be to
5515 count the recursion depth of this function and signal an
5516 error when a certain maximum depth is reached.) Is it worth
5518 if (success_p
&& it
->dpvec
== NULL
)
5523 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5526 struct Lisp_Vector
*v
= XVECTOR (dv
);
5528 /* Return the first character from the display table
5529 entry, if not empty. If empty, don't display the
5530 current character. */
5533 it
->dpvec_char_len
= it
->len
;
5534 it
->dpvec
= v
->contents
;
5535 it
->dpend
= v
->contents
+ v
->size
;
5536 it
->current
.dpvec_index
= 0;
5537 it
->dpvec_face_id
= -1;
5538 it
->saved_face_id
= it
->face_id
;
5539 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5544 set_iterator_to_next (it
, 0);
5549 /* Translate control characters into `\003' or `^C' form.
5550 Control characters coming from a display table entry are
5551 currently not translated because we use IT->dpvec to hold
5552 the translation. This could easily be changed but I
5553 don't believe that it is worth doing.
5555 If it->multibyte_p is nonzero, eight-bit characters and
5556 non-printable multibyte characters are also translated to
5559 If it->multibyte_p is zero, eight-bit characters that
5560 don't have corresponding multibyte char code are also
5561 translated to octal form. */
5562 else if ((it
->c
< ' '
5563 && (it
->area
!= TEXT_AREA
5564 /* In mode line, treat \n like other crl chars. */
5566 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5567 || (it
->c
!= '\n' && it
->c
!= '\t')))
5571 || !CHAR_PRINTABLE_P (it
->c
)
5572 || (!NILP (Vnobreak_char_display
)
5573 && (it
->c
== 0x8a0 || it
->c
== 0x8ad
5574 || it
->c
== 0x920 || it
->c
== 0x92d
5575 || it
->c
== 0xe20 || it
->c
== 0xe2d
5576 || it
->c
== 0xf20 || it
->c
== 0xf2d)))
5578 && (!unibyte_display_via_language_environment
5579 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5581 /* IT->c is a control character which must be displayed
5582 either as '\003' or as `^C' where the '\\' and '^'
5583 can be defined in the display table. Fill
5584 IT->ctl_chars with glyphs for what we have to
5585 display. Then, set IT->dpvec to these glyphs. */
5588 int face_id
, lface_id
= 0 ;
5591 /* Handle control characters with ^. */
5593 if (it
->c
< 128 && it
->ctl_arrow_p
)
5595 g
= '^'; /* default glyph for Control */
5596 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5598 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5599 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5601 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5602 lface_id
= FAST_GLYPH_FACE (g
);
5606 g
= FAST_GLYPH_CHAR (g
);
5607 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5610 else if (it
->f
== last_escape_glyph_frame
5611 && it
->face_id
== last_escape_glyph_face_id
)
5613 face_id
= last_escape_glyph_merged_face_id
;
5617 /* Merge the escape-glyph face into the current face. */
5618 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5620 last_escape_glyph_frame
= it
->f
;
5621 last_escape_glyph_face_id
= it
->face_id
;
5622 last_escape_glyph_merged_face_id
= face_id
;
5625 XSETINT (it
->ctl_chars
[0], g
);
5627 XSETINT (it
->ctl_chars
[1], g
);
5629 goto display_control
;
5632 /* Handle non-break space in the mode where it only gets
5635 if (EQ (Vnobreak_char_display
, Qt
)
5636 && (it
->c
== 0x8a0 || it
->c
== 0x920
5637 || it
->c
== 0xe20 || it
->c
== 0xf20))
5639 /* Merge the no-break-space face into the current face. */
5640 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5644 XSETINT (it
->ctl_chars
[0], g
);
5646 goto display_control
;
5649 /* Handle sequences that start with the "escape glyph". */
5651 /* the default escape glyph is \. */
5652 escape_glyph
= '\\';
5655 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5656 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5658 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5659 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5663 /* The display table specified a face.
5664 Merge it into face_id and also into escape_glyph. */
5665 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5666 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5669 else if (it
->f
== last_escape_glyph_frame
5670 && it
->face_id
== last_escape_glyph_face_id
)
5672 face_id
= last_escape_glyph_merged_face_id
;
5676 /* Merge the escape-glyph face into the current face. */
5677 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5679 last_escape_glyph_frame
= it
->f
;
5680 last_escape_glyph_face_id
= it
->face_id
;
5681 last_escape_glyph_merged_face_id
= face_id
;
5684 /* Handle soft hyphens in the mode where they only get
5687 if (EQ (Vnobreak_char_display
, Qt
)
5688 && (it
->c
== 0x8ad || it
->c
== 0x92d
5689 || it
->c
== 0xe2d || it
->c
== 0xf2d))
5692 XSETINT (it
->ctl_chars
[0], g
);
5694 goto display_control
;
5697 /* Handle non-break space and soft hyphen
5698 with the escape glyph. */
5700 if (it
->c
== 0x8a0 || it
->c
== 0x8ad
5701 || it
->c
== 0x920 || it
->c
== 0x92d
5702 || it
->c
== 0xe20 || it
->c
== 0xe2d
5703 || it
->c
== 0xf20 || it
->c
== 0xf2d)
5705 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5706 g
= it
->c
= ((it
->c
& 0xf) == 0 ? ' ' : '-');
5707 XSETINT (it
->ctl_chars
[1], g
);
5709 goto display_control
;
5713 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5717 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5718 if (SINGLE_BYTE_CHAR_P (it
->c
))
5719 str
[0] = it
->c
, len
= 1;
5722 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5725 /* It's an invalid character, which shouldn't
5726 happen actually, but due to bugs it may
5727 happen. Let's print the char as is, there's
5728 not much meaningful we can do with it. */
5730 str
[1] = it
->c
>> 8;
5731 str
[2] = it
->c
>> 16;
5732 str
[3] = it
->c
>> 24;
5737 for (i
= 0; i
< len
; i
++)
5739 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5740 /* Insert three more glyphs into IT->ctl_chars for
5741 the octal display of the character. */
5742 g
= ((str
[i
] >> 6) & 7) + '0';
5743 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5744 g
= ((str
[i
] >> 3) & 7) + '0';
5745 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5746 g
= (str
[i
] & 7) + '0';
5747 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5753 /* Set up IT->dpvec and return first character from it. */
5754 it
->dpvec_char_len
= it
->len
;
5755 it
->dpvec
= it
->ctl_chars
;
5756 it
->dpend
= it
->dpvec
+ ctl_len
;
5757 it
->current
.dpvec_index
= 0;
5758 it
->dpvec_face_id
= face_id
;
5759 it
->saved_face_id
= it
->face_id
;
5760 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5766 /* Adjust face id for a multibyte character. There are no
5767 multibyte character in unibyte text. */
5770 && FRAME_WINDOW_P (it
->f
))
5772 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5773 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5777 /* Is this character the last one of a run of characters with
5778 box? If yes, set IT->end_of_box_run_p to 1. */
5785 it
->end_of_box_run_p
5786 = ((face_id
= face_after_it_pos (it
),
5787 face_id
!= it
->face_id
)
5788 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5789 face
->box
== FACE_NO_BOX
));
5792 /* Value is 0 if end of buffer or string reached. */
5797 /* Move IT to the next display element.
5799 RESEAT_P non-zero means if called on a newline in buffer text,
5800 skip to the next visible line start.
5802 Functions get_next_display_element and set_iterator_to_next are
5803 separate because I find this arrangement easier to handle than a
5804 get_next_display_element function that also increments IT's
5805 position. The way it is we can first look at an iterator's current
5806 display element, decide whether it fits on a line, and if it does,
5807 increment the iterator position. The other way around we probably
5808 would either need a flag indicating whether the iterator has to be
5809 incremented the next time, or we would have to implement a
5810 decrement position function which would not be easy to write. */
5813 set_iterator_to_next (it
, reseat_p
)
5817 /* Reset flags indicating start and end of a sequence of characters
5818 with box. Reset them at the start of this function because
5819 moving the iterator to a new position might set them. */
5820 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5824 case GET_FROM_BUFFER
:
5825 /* The current display element of IT is a character from
5826 current_buffer. Advance in the buffer, and maybe skip over
5827 invisible lines that are so because of selective display. */
5828 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5829 reseat_at_next_visible_line_start (it
, 0);
5832 xassert (it
->len
!= 0);
5833 IT_BYTEPOS (*it
) += it
->len
;
5834 IT_CHARPOS (*it
) += 1;
5835 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5839 case GET_FROM_COMPOSITION
:
5840 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5841 xassert (it
->sp
> 0);
5843 if (it
->method
== GET_FROM_STRING
)
5845 IT_STRING_BYTEPOS (*it
) += it
->len
;
5846 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5847 goto consider_string_end
;
5849 else if (it
->method
== GET_FROM_BUFFER
)
5851 IT_BYTEPOS (*it
) += it
->len
;
5852 IT_CHARPOS (*it
) += it
->cmp_len
;
5856 case GET_FROM_C_STRING
:
5857 /* Current display element of IT is from a C string. */
5858 IT_BYTEPOS (*it
) += it
->len
;
5859 IT_CHARPOS (*it
) += 1;
5862 case GET_FROM_DISPLAY_VECTOR
:
5863 /* Current display element of IT is from a display table entry.
5864 Advance in the display table definition. Reset it to null if
5865 end reached, and continue with characters from buffers/
5867 ++it
->current
.dpvec_index
;
5869 /* Restore face of the iterator to what they were before the
5870 display vector entry (these entries may contain faces). */
5871 it
->face_id
= it
->saved_face_id
;
5873 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5875 int recheck_faces
= it
->ellipsis_p
;
5878 it
->method
= GET_FROM_C_STRING
;
5879 else if (STRINGP (it
->string
))
5880 it
->method
= GET_FROM_STRING
;
5883 it
->method
= GET_FROM_BUFFER
;
5884 it
->object
= it
->w
->buffer
;
5888 it
->current
.dpvec_index
= -1;
5890 /* Skip over characters which were displayed via IT->dpvec. */
5891 if (it
->dpvec_char_len
< 0)
5892 reseat_at_next_visible_line_start (it
, 1);
5893 else if (it
->dpvec_char_len
> 0)
5895 if (it
->method
== GET_FROM_STRING
5896 && it
->n_overlay_strings
> 0)
5897 it
->ignore_overlay_strings_at_pos_p
= 1;
5898 it
->len
= it
->dpvec_char_len
;
5899 set_iterator_to_next (it
, reseat_p
);
5902 /* Maybe recheck faces after display vector */
5904 it
->stop_charpos
= IT_CHARPOS (*it
);
5908 case GET_FROM_STRING
:
5909 /* Current display element is a character from a Lisp string. */
5910 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5911 IT_STRING_BYTEPOS (*it
) += it
->len
;
5912 IT_STRING_CHARPOS (*it
) += 1;
5914 consider_string_end
:
5916 if (it
->current
.overlay_string_index
>= 0)
5918 /* IT->string is an overlay string. Advance to the
5919 next, if there is one. */
5920 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5921 next_overlay_string (it
);
5925 /* IT->string is not an overlay string. If we reached
5926 its end, and there is something on IT->stack, proceed
5927 with what is on the stack. This can be either another
5928 string, this time an overlay string, or a buffer. */
5929 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5933 if (it
->method
== GET_FROM_STRING
)
5934 goto consider_string_end
;
5939 case GET_FROM_IMAGE
:
5940 case GET_FROM_STRETCH
:
5941 /* The position etc with which we have to proceed are on
5942 the stack. The position may be at the end of a string,
5943 if the `display' property takes up the whole string. */
5944 xassert (it
->sp
> 0);
5946 if (it
->method
== GET_FROM_STRING
)
5947 goto consider_string_end
;
5951 /* There are no other methods defined, so this should be a bug. */
5955 xassert (it
->method
!= GET_FROM_STRING
5956 || (STRINGP (it
->string
)
5957 && IT_STRING_CHARPOS (*it
) >= 0));
5960 /* Load IT's display element fields with information about the next
5961 display element which comes from a display table entry or from the
5962 result of translating a control character to one of the forms `^C'
5965 IT->dpvec holds the glyphs to return as characters.
5966 IT->saved_face_id holds the face id before the display vector--
5967 it is restored into IT->face_idin set_iterator_to_next. */
5970 next_element_from_display_vector (it
)
5974 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5976 it
->face_id
= it
->saved_face_id
;
5978 if (INTEGERP (*it
->dpvec
)
5979 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5983 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5984 it
->c
= FAST_GLYPH_CHAR (g
);
5985 it
->len
= CHAR_BYTES (it
->c
);
5987 /* The entry may contain a face id to use. Such a face id is
5988 the id of a Lisp face, not a realized face. A face id of
5989 zero means no face is specified. */
5990 if (it
->dpvec_face_id
>= 0)
5991 it
->face_id
= it
->dpvec_face_id
;
5994 int lface_id
= FAST_GLYPH_FACE (g
);
5996 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6001 /* Display table entry is invalid. Return a space. */
6002 it
->c
= ' ', it
->len
= 1;
6004 /* Don't change position and object of the iterator here. They are
6005 still the values of the character that had this display table
6006 entry or was translated, and that's what we want. */
6007 it
->what
= IT_CHARACTER
;
6012 /* Load IT with the next display element from Lisp string IT->string.
6013 IT->current.string_pos is the current position within the string.
6014 If IT->current.overlay_string_index >= 0, the Lisp string is an
6018 next_element_from_string (it
)
6021 struct text_pos position
;
6023 xassert (STRINGP (it
->string
));
6024 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6025 position
= it
->current
.string_pos
;
6027 /* Time to check for invisible text? */
6028 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6029 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6033 /* Since a handler may have changed IT->method, we must
6035 return get_next_display_element (it
);
6038 if (it
->current
.overlay_string_index
>= 0)
6040 /* Get the next character from an overlay string. In overlay
6041 strings, There is no field width or padding with spaces to
6043 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6048 else if (STRING_MULTIBYTE (it
->string
))
6050 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6051 const unsigned char *s
= (SDATA (it
->string
)
6052 + IT_STRING_BYTEPOS (*it
));
6053 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
6057 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6063 /* Get the next character from a Lisp string that is not an
6064 overlay string. Such strings come from the mode line, for
6065 example. We may have to pad with spaces, or truncate the
6066 string. See also next_element_from_c_string. */
6067 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6072 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6074 /* Pad with spaces. */
6075 it
->c
= ' ', it
->len
= 1;
6076 CHARPOS (position
) = BYTEPOS (position
) = -1;
6078 else if (STRING_MULTIBYTE (it
->string
))
6080 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6081 const unsigned char *s
= (SDATA (it
->string
)
6082 + IT_STRING_BYTEPOS (*it
));
6083 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
6087 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6092 /* Record what we have and where it came from. */
6093 it
->what
= IT_CHARACTER
;
6094 it
->object
= it
->string
;
6095 it
->position
= position
;
6100 /* Load IT with next display element from C string IT->s.
6101 IT->string_nchars is the maximum number of characters to return
6102 from the string. IT->end_charpos may be greater than
6103 IT->string_nchars when this function is called, in which case we
6104 may have to return padding spaces. Value is zero if end of string
6105 reached, including padding spaces. */
6108 next_element_from_c_string (it
)
6114 it
->what
= IT_CHARACTER
;
6115 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6118 /* IT's position can be greater IT->string_nchars in case a field
6119 width or precision has been specified when the iterator was
6121 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6123 /* End of the game. */
6127 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6129 /* Pad with spaces. */
6130 it
->c
= ' ', it
->len
= 1;
6131 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6133 else if (it
->multibyte_p
)
6135 /* Implementation note: The calls to strlen apparently aren't a
6136 performance problem because there is no noticeable performance
6137 difference between Emacs running in unibyte or multibyte mode. */
6138 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6139 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
6143 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6149 /* Set up IT to return characters from an ellipsis, if appropriate.
6150 The definition of the ellipsis glyphs may come from a display table
6151 entry. This function Fills IT with the first glyph from the
6152 ellipsis if an ellipsis is to be displayed. */
6155 next_element_from_ellipsis (it
)
6158 if (it
->selective_display_ellipsis_p
)
6159 setup_for_ellipsis (it
, it
->len
);
6162 /* The face at the current position may be different from the
6163 face we find after the invisible text. Remember what it
6164 was in IT->saved_face_id, and signal that it's there by
6165 setting face_before_selective_p. */
6166 it
->saved_face_id
= it
->face_id
;
6167 it
->method
= GET_FROM_BUFFER
;
6168 it
->object
= it
->w
->buffer
;
6169 reseat_at_next_visible_line_start (it
, 1);
6170 it
->face_before_selective_p
= 1;
6173 return get_next_display_element (it
);
6177 /* Deliver an image display element. The iterator IT is already
6178 filled with image information (done in handle_display_prop). Value
6183 next_element_from_image (it
)
6186 it
->what
= IT_IMAGE
;
6191 /* Fill iterator IT with next display element from a stretch glyph
6192 property. IT->object is the value of the text property. Value is
6196 next_element_from_stretch (it
)
6199 it
->what
= IT_STRETCH
;
6204 /* Load IT with the next display element from current_buffer. Value
6205 is zero if end of buffer reached. IT->stop_charpos is the next
6206 position at which to stop and check for text properties or buffer
6210 next_element_from_buffer (it
)
6215 /* Check this assumption, otherwise, we would never enter the
6216 if-statement, below. */
6217 xassert (IT_CHARPOS (*it
) >= BEGV
6218 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6220 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6222 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6224 int overlay_strings_follow_p
;
6226 /* End of the game, except when overlay strings follow that
6227 haven't been returned yet. */
6228 if (it
->overlay_strings_at_end_processed_p
)
6229 overlay_strings_follow_p
= 0;
6232 it
->overlay_strings_at_end_processed_p
= 1;
6233 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6236 if (overlay_strings_follow_p
)
6237 success_p
= get_next_display_element (it
);
6241 it
->position
= it
->current
.pos
;
6248 return get_next_display_element (it
);
6253 /* No face changes, overlays etc. in sight, so just return a
6254 character from current_buffer. */
6257 /* Maybe run the redisplay end trigger hook. Performance note:
6258 This doesn't seem to cost measurable time. */
6259 if (it
->redisplay_end_trigger_charpos
6261 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6262 run_redisplay_end_trigger_hook (it
);
6264 /* Get the next character, maybe multibyte. */
6265 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6266 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6268 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6269 - IT_BYTEPOS (*it
));
6270 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6273 it
->c
= *p
, it
->len
= 1;
6275 /* Record what we have and where it came from. */
6276 it
->what
= IT_CHARACTER
;
6277 it
->object
= it
->w
->buffer
;
6278 it
->position
= it
->current
.pos
;
6280 /* Normally we return the character found above, except when we
6281 really want to return an ellipsis for selective display. */
6286 /* A value of selective > 0 means hide lines indented more
6287 than that number of columns. */
6288 if (it
->selective
> 0
6289 && IT_CHARPOS (*it
) + 1 < ZV
6290 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6291 IT_BYTEPOS (*it
) + 1,
6292 (double) it
->selective
)) /* iftc */
6294 success_p
= next_element_from_ellipsis (it
);
6295 it
->dpvec_char_len
= -1;
6298 else if (it
->c
== '\r' && it
->selective
== -1)
6300 /* A value of selective == -1 means that everything from the
6301 CR to the end of the line is invisible, with maybe an
6302 ellipsis displayed for it. */
6303 success_p
= next_element_from_ellipsis (it
);
6304 it
->dpvec_char_len
= -1;
6309 /* Value is zero if end of buffer reached. */
6310 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6315 /* Run the redisplay end trigger hook for IT. */
6318 run_redisplay_end_trigger_hook (it
)
6321 Lisp_Object args
[3];
6323 /* IT->glyph_row should be non-null, i.e. we should be actually
6324 displaying something, or otherwise we should not run the hook. */
6325 xassert (it
->glyph_row
);
6327 /* Set up hook arguments. */
6328 args
[0] = Qredisplay_end_trigger_functions
;
6329 args
[1] = it
->window
;
6330 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6331 it
->redisplay_end_trigger_charpos
= 0;
6333 /* Since we are *trying* to run these functions, don't try to run
6334 them again, even if they get an error. */
6335 it
->w
->redisplay_end_trigger
= Qnil
;
6336 Frun_hook_with_args (3, args
);
6338 /* Notice if it changed the face of the character we are on. */
6339 handle_face_prop (it
);
6343 /* Deliver a composition display element. The iterator IT is already
6344 filled with composition information (done in
6345 handle_composition_prop). Value is always 1. */
6348 next_element_from_composition (it
)
6351 it
->what
= IT_COMPOSITION
;
6352 it
->position
= (STRINGP (it
->string
)
6353 ? it
->current
.string_pos
6355 if (STRINGP (it
->string
))
6356 it
->object
= it
->string
;
6358 it
->object
= it
->w
->buffer
;
6364 /***********************************************************************
6365 Moving an iterator without producing glyphs
6366 ***********************************************************************/
6368 /* Check if iterator is at a position corresponding to a valid buffer
6369 position after some move_it_ call. */
6371 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6372 ((it)->method == GET_FROM_STRING \
6373 ? IT_STRING_CHARPOS (*it) == 0 \
6377 /* Move iterator IT to a specified buffer or X position within one
6378 line on the display without producing glyphs.
6380 OP should be a bit mask including some or all of these bits:
6381 MOVE_TO_X: Stop on reaching x-position TO_X.
6382 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6383 Regardless of OP's value, stop in reaching the end of the display line.
6385 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6386 This means, in particular, that TO_X includes window's horizontal
6389 The return value has several possible values that
6390 say what condition caused the scan to stop:
6392 MOVE_POS_MATCH_OR_ZV
6393 - when TO_POS or ZV was reached.
6396 -when TO_X was reached before TO_POS or ZV were reached.
6399 - when we reached the end of the display area and the line must
6403 - when we reached the end of the display area and the line is
6407 - when we stopped at a line end, i.e. a newline or a CR and selective
6410 static enum move_it_result
6411 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
6413 int to_charpos
, to_x
, op
;
6415 enum move_it_result result
= MOVE_UNDEFINED
;
6416 struct glyph_row
*saved_glyph_row
;
6418 /* Don't produce glyphs in produce_glyphs. */
6419 saved_glyph_row
= it
->glyph_row
;
6420 it
->glyph_row
= NULL
;
6422 #define BUFFER_POS_REACHED_P() \
6423 ((op & MOVE_TO_POS) != 0 \
6424 && BUFFERP (it->object) \
6425 && IT_CHARPOS (*it) >= to_charpos \
6426 && (it->method == GET_FROM_BUFFER \
6427 || (it->method == GET_FROM_DISPLAY_VECTOR \
6428 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6433 int x
, i
, ascent
= 0, descent
= 0;
6435 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
6436 if ((op
& MOVE_TO_POS
) != 0
6437 && BUFFERP (it
->object
)
6438 && it
->method
== GET_FROM_BUFFER
6439 && IT_CHARPOS (*it
) > to_charpos
)
6441 result
= MOVE_POS_MATCH_OR_ZV
;
6445 /* Stop when ZV reached.
6446 We used to stop here when TO_CHARPOS reached as well, but that is
6447 too soon if this glyph does not fit on this line. So we handle it
6448 explicitly below. */
6449 if (!get_next_display_element (it
)
6450 || (it
->truncate_lines_p
6451 && BUFFER_POS_REACHED_P ()))
6453 result
= MOVE_POS_MATCH_OR_ZV
;
6457 /* The call to produce_glyphs will get the metrics of the
6458 display element IT is loaded with. We record in x the
6459 x-position before this display element in case it does not
6463 /* Remember the line height so far in case the next element doesn't
6465 if (!it
->truncate_lines_p
)
6467 ascent
= it
->max_ascent
;
6468 descent
= it
->max_descent
;
6471 PRODUCE_GLYPHS (it
);
6473 if (it
->area
!= TEXT_AREA
)
6475 set_iterator_to_next (it
, 1);
6479 /* The number of glyphs we get back in IT->nglyphs will normally
6480 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6481 character on a terminal frame, or (iii) a line end. For the
6482 second case, IT->nglyphs - 1 padding glyphs will be present
6483 (on X frames, there is only one glyph produced for a
6484 composite character.
6486 The behavior implemented below means, for continuation lines,
6487 that as many spaces of a TAB as fit on the current line are
6488 displayed there. For terminal frames, as many glyphs of a
6489 multi-glyph character are displayed in the current line, too.
6490 This is what the old redisplay code did, and we keep it that
6491 way. Under X, the whole shape of a complex character must
6492 fit on the line or it will be completely displayed in the
6495 Note that both for tabs and padding glyphs, all glyphs have
6499 /* More than one glyph or glyph doesn't fit on line. All
6500 glyphs have the same width. */
6501 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6503 int x_before_this_char
= x
;
6504 int hpos_before_this_char
= it
->hpos
;
6506 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6508 new_x
= x
+ single_glyph_width
;
6510 /* We want to leave anything reaching TO_X to the caller. */
6511 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6513 if (BUFFER_POS_REACHED_P ())
6514 goto buffer_pos_reached
;
6516 result
= MOVE_X_REACHED
;
6519 else if (/* Lines are continued. */
6520 !it
->truncate_lines_p
6521 && (/* And glyph doesn't fit on the line. */
6522 new_x
> it
->last_visible_x
6523 /* Or it fits exactly and we're on a window
6525 || (new_x
== it
->last_visible_x
6526 && FRAME_WINDOW_P (it
->f
))))
6528 if (/* IT->hpos == 0 means the very first glyph
6529 doesn't fit on the line, e.g. a wide image. */
6531 || (new_x
== it
->last_visible_x
6532 && FRAME_WINDOW_P (it
->f
)))
6535 it
->current_x
= new_x
;
6537 /* The character's last glyph just barely fits
6539 if (i
== it
->nglyphs
- 1)
6541 /* If this is the destination position,
6542 return a position *before* it in this row,
6543 now that we know it fits in this row. */
6544 if (BUFFER_POS_REACHED_P ())
6546 it
->hpos
= hpos_before_this_char
;
6547 it
->current_x
= x_before_this_char
;
6548 result
= MOVE_POS_MATCH_OR_ZV
;
6552 set_iterator_to_next (it
, 1);
6553 #ifdef HAVE_WINDOW_SYSTEM
6554 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6556 if (!get_next_display_element (it
))
6558 result
= MOVE_POS_MATCH_OR_ZV
;
6561 if (BUFFER_POS_REACHED_P ())
6563 if (ITERATOR_AT_END_OF_LINE_P (it
))
6564 result
= MOVE_POS_MATCH_OR_ZV
;
6566 result
= MOVE_LINE_CONTINUED
;
6569 if (ITERATOR_AT_END_OF_LINE_P (it
))
6571 result
= MOVE_NEWLINE_OR_CR
;
6575 #endif /* HAVE_WINDOW_SYSTEM */
6581 it
->max_ascent
= ascent
;
6582 it
->max_descent
= descent
;
6585 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6587 result
= MOVE_LINE_CONTINUED
;
6590 else if (BUFFER_POS_REACHED_P ())
6591 goto buffer_pos_reached
;
6592 else if (new_x
> it
->first_visible_x
)
6594 /* Glyph is visible. Increment number of glyphs that
6595 would be displayed. */
6600 /* Glyph is completely off the left margin of the display
6601 area. Nothing to do. */
6605 if (result
!= MOVE_UNDEFINED
)
6608 else if (BUFFER_POS_REACHED_P ())
6612 it
->max_ascent
= ascent
;
6613 it
->max_descent
= descent
;
6614 result
= MOVE_POS_MATCH_OR_ZV
;
6617 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6619 /* Stop when TO_X specified and reached. This check is
6620 necessary here because of lines consisting of a line end,
6621 only. The line end will not produce any glyphs and we
6622 would never get MOVE_X_REACHED. */
6623 xassert (it
->nglyphs
== 0);
6624 result
= MOVE_X_REACHED
;
6628 /* Is this a line end? If yes, we're done. */
6629 if (ITERATOR_AT_END_OF_LINE_P (it
))
6631 result
= MOVE_NEWLINE_OR_CR
;
6635 /* The current display element has been consumed. Advance
6637 set_iterator_to_next (it
, 1);
6639 /* Stop if lines are truncated and IT's current x-position is
6640 past the right edge of the window now. */
6641 if (it
->truncate_lines_p
6642 && it
->current_x
>= it
->last_visible_x
)
6644 #ifdef HAVE_WINDOW_SYSTEM
6645 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6647 if (!get_next_display_element (it
)
6648 || BUFFER_POS_REACHED_P ())
6650 result
= MOVE_POS_MATCH_OR_ZV
;
6653 if (ITERATOR_AT_END_OF_LINE_P (it
))
6655 result
= MOVE_NEWLINE_OR_CR
;
6659 #endif /* HAVE_WINDOW_SYSTEM */
6660 result
= MOVE_LINE_TRUNCATED
;
6665 #undef BUFFER_POS_REACHED_P
6667 /* Restore the iterator settings altered at the beginning of this
6669 it
->glyph_row
= saved_glyph_row
;
6674 /* Move IT forward until it satisfies one or more of the criteria in
6675 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6677 OP is a bit-mask that specifies where to stop, and in particular,
6678 which of those four position arguments makes a difference. See the
6679 description of enum move_operation_enum.
6681 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6682 screen line, this function will set IT to the next position >
6686 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6688 int to_charpos
, to_x
, to_y
, to_vpos
;
6691 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6697 if (op
& MOVE_TO_VPOS
)
6699 /* If no TO_CHARPOS and no TO_X specified, stop at the
6700 start of the line TO_VPOS. */
6701 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6703 if (it
->vpos
== to_vpos
)
6709 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6713 /* TO_VPOS >= 0 means stop at TO_X in the line at
6714 TO_VPOS, or at TO_POS, whichever comes first. */
6715 if (it
->vpos
== to_vpos
)
6721 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6723 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6728 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6730 /* We have reached TO_X but not in the line we want. */
6731 skip
= move_it_in_display_line_to (it
, to_charpos
,
6733 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6741 else if (op
& MOVE_TO_Y
)
6743 struct it it_backup
;
6745 /* TO_Y specified means stop at TO_X in the line containing
6746 TO_Y---or at TO_CHARPOS if this is reached first. The
6747 problem is that we can't really tell whether the line
6748 contains TO_Y before we have completely scanned it, and
6749 this may skip past TO_X. What we do is to first scan to
6752 If TO_X is not specified, use a TO_X of zero. The reason
6753 is to make the outcome of this function more predictable.
6754 If we didn't use TO_X == 0, we would stop at the end of
6755 the line which is probably not what a caller would expect
6757 skip
= move_it_in_display_line_to (it
, to_charpos
,
6761 | (op
& MOVE_TO_POS
)));
6763 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6764 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6770 /* If TO_X was reached, we would like to know whether TO_Y
6771 is in the line. This can only be said if we know the
6772 total line height which requires us to scan the rest of
6774 if (skip
== MOVE_X_REACHED
)
6777 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6778 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6780 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6783 /* Now, decide whether TO_Y is in this line. */
6784 line_height
= it
->max_ascent
+ it
->max_descent
;
6785 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6787 if (to_y
>= it
->current_y
6788 && to_y
< it
->current_y
+ line_height
)
6790 if (skip
== MOVE_X_REACHED
)
6791 /* If TO_Y is in this line and TO_X was reached above,
6792 we scanned too far. We have to restore IT's settings
6793 to the ones before skipping. */
6797 else if (skip
== MOVE_X_REACHED
)
6800 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6807 else if (BUFFERP (it
->object
)
6808 && it
->method
== GET_FROM_BUFFER
6809 && IT_CHARPOS (*it
) >= to_charpos
)
6810 skip
= MOVE_POS_MATCH_OR_ZV
;
6812 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6816 case MOVE_POS_MATCH_OR_ZV
:
6820 case MOVE_NEWLINE_OR_CR
:
6821 set_iterator_to_next (it
, 1);
6822 it
->continuation_lines_width
= 0;
6825 case MOVE_LINE_TRUNCATED
:
6826 it
->continuation_lines_width
= 0;
6827 reseat_at_next_visible_line_start (it
, 0);
6828 if ((op
& MOVE_TO_POS
) != 0
6829 && IT_CHARPOS (*it
) > to_charpos
)
6836 case MOVE_LINE_CONTINUED
:
6837 /* For continued lines ending in a tab, some of the glyphs
6838 associated with the tab are displayed on the current
6839 line. Since it->current_x does not include these glyphs,
6840 we use it->last_visible_x instead. */
6841 it
->continuation_lines_width
+=
6842 (it
->c
== '\t') ? it
->last_visible_x
: it
->current_x
;
6849 /* Reset/increment for the next run. */
6850 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6851 it
->current_x
= it
->hpos
= 0;
6852 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6854 last_height
= it
->max_ascent
+ it
->max_descent
;
6855 last_max_ascent
= it
->max_ascent
;
6856 it
->max_ascent
= it
->max_descent
= 0;
6861 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6865 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6867 If DY > 0, move IT backward at least that many pixels. DY = 0
6868 means move IT backward to the preceding line start or BEGV. This
6869 function may move over more than DY pixels if IT->current_y - DY
6870 ends up in the middle of a line; in this case IT->current_y will be
6871 set to the top of the line moved to. */
6874 move_it_vertically_backward (it
, dy
)
6885 start_pos
= IT_CHARPOS (*it
);
6887 /* Estimate how many newlines we must move back. */
6888 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6890 /* Set the iterator's position that many lines back. */
6891 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6892 back_to_previous_visible_line_start (it
);
6894 /* Reseat the iterator here. When moving backward, we don't want
6895 reseat to skip forward over invisible text, set up the iterator
6896 to deliver from overlay strings at the new position etc. So,
6897 use reseat_1 here. */
6898 reseat_1 (it
, it
->current
.pos
, 1);
6900 /* We are now surely at a line start. */
6901 it
->current_x
= it
->hpos
= 0;
6902 it
->continuation_lines_width
= 0;
6904 /* Move forward and see what y-distance we moved. First move to the
6905 start of the next line so that we get its height. We need this
6906 height to be able to tell whether we reached the specified
6909 it2
.max_ascent
= it2
.max_descent
= 0;
6912 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6913 MOVE_TO_POS
| MOVE_TO_VPOS
);
6915 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
6916 xassert (IT_CHARPOS (*it
) >= BEGV
);
6919 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6920 xassert (IT_CHARPOS (*it
) >= BEGV
);
6921 /* H is the actual vertical distance from the position in *IT
6922 and the starting position. */
6923 h
= it2
.current_y
- it
->current_y
;
6924 /* NLINES is the distance in number of lines. */
6925 nlines
= it2
.vpos
- it
->vpos
;
6927 /* Correct IT's y and vpos position
6928 so that they are relative to the starting point. */
6934 /* DY == 0 means move to the start of the screen line. The
6935 value of nlines is > 0 if continuation lines were involved. */
6937 move_it_by_lines (it
, nlines
, 1);
6939 /* I think this assert is bogus if buffer contains
6940 invisible text or images. KFS. */
6941 xassert (IT_CHARPOS (*it
) <= start_pos
);
6946 /* The y-position we try to reach, relative to *IT.
6947 Note that H has been subtracted in front of the if-statement. */
6948 int target_y
= it
->current_y
+ h
- dy
;
6949 int y0
= it3
.current_y
;
6950 int y1
= line_bottom_y (&it3
);
6951 int line_height
= y1
- y0
;
6953 /* If we did not reach target_y, try to move further backward if
6954 we can. If we moved too far backward, try to move forward. */
6955 if (target_y
< it
->current_y
6956 /* This is heuristic. In a window that's 3 lines high, with
6957 a line height of 13 pixels each, recentering with point
6958 on the bottom line will try to move -39/2 = 19 pixels
6959 backward. Try to avoid moving into the first line. */
6960 && (it
->current_y
- target_y
6961 > min (window_box_height (it
->w
), line_height
* 2 / 3))
6962 && IT_CHARPOS (*it
) > BEGV
)
6964 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6965 target_y
- it
->current_y
));
6966 dy
= it
->current_y
- target_y
;
6967 goto move_further_back
;
6969 else if (target_y
>= it
->current_y
+ line_height
6970 && IT_CHARPOS (*it
) < ZV
)
6972 /* Should move forward by at least one line, maybe more.
6974 Note: Calling move_it_by_lines can be expensive on
6975 terminal frames, where compute_motion is used (via
6976 vmotion) to do the job, when there are very long lines
6977 and truncate-lines is nil. That's the reason for
6978 treating terminal frames specially here. */
6980 if (!FRAME_WINDOW_P (it
->f
))
6981 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6986 move_it_by_lines (it
, 1, 1);
6988 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6992 /* I think this assert is bogus if buffer contains
6993 invisible text or images. KFS. */
6994 xassert (IT_CHARPOS (*it
) >= BEGV
);
7001 /* Move IT by a specified amount of pixel lines DY. DY negative means
7002 move backwards. DY = 0 means move to start of screen line. At the
7003 end, IT will be on the start of a screen line. */
7006 move_it_vertically (it
, dy
)
7011 move_it_vertically_backward (it
, -dy
);
7014 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7015 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7016 MOVE_TO_POS
| MOVE_TO_Y
);
7017 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7019 /* If buffer ends in ZV without a newline, move to the start of
7020 the line to satisfy the post-condition. */
7021 if (IT_CHARPOS (*it
) == ZV
7023 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7024 move_it_by_lines (it
, 0, 0);
7029 /* Move iterator IT past the end of the text line it is in. */
7032 move_it_past_eol (it
)
7035 enum move_it_result rc
;
7037 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7038 if (rc
== MOVE_NEWLINE_OR_CR
)
7039 set_iterator_to_next (it
, 0);
7043 #if 0 /* Currently not used. */
7045 /* Return non-zero if some text between buffer positions START_CHARPOS
7046 and END_CHARPOS is invisible. IT->window is the window for text
7050 invisible_text_between_p (it
, start_charpos
, end_charpos
)
7052 int start_charpos
, end_charpos
;
7054 Lisp_Object prop
, limit
;
7055 int invisible_found_p
;
7057 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
7059 /* Is text at START invisible? */
7060 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
7062 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
7063 invisible_found_p
= 1;
7066 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
7068 make_number (end_charpos
));
7069 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
7072 return invisible_found_p
;
7078 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7079 negative means move up. DVPOS == 0 means move to the start of the
7080 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7081 NEED_Y_P is zero, IT->current_y will be left unchanged.
7083 Further optimization ideas: If we would know that IT->f doesn't use
7084 a face with proportional font, we could be faster for
7085 truncate-lines nil. */
7088 move_it_by_lines (it
, dvpos
, need_y_p
)
7090 int dvpos
, need_y_p
;
7092 struct position pos
;
7094 /* The commented-out optimization uses vmotion on terminals. This
7095 gives bad results, because elements like it->what, on which
7096 callers such as pos_visible_p rely, aren't updated. */
7097 /* if (!FRAME_WINDOW_P (it->f))
7099 struct text_pos textpos;
7101 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7102 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7103 reseat (it, textpos, 1);
7104 it->vpos += pos.vpos;
7105 it->current_y += pos.vpos;
7111 /* DVPOS == 0 means move to the start of the screen line. */
7112 move_it_vertically_backward (it
, 0);
7113 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7114 /* Let next call to line_bottom_y calculate real line height */
7119 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7120 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7121 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7126 int start_charpos
, i
;
7128 /* Start at the beginning of the screen line containing IT's
7129 position. This may actually move vertically backwards,
7130 in case of overlays, so adjust dvpos accordingly. */
7132 move_it_vertically_backward (it
, 0);
7135 /* Go back -DVPOS visible lines and reseat the iterator there. */
7136 start_charpos
= IT_CHARPOS (*it
);
7137 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7138 back_to_previous_visible_line_start (it
);
7139 reseat (it
, it
->current
.pos
, 1);
7141 /* Move further back if we end up in a string or an image. */
7142 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7144 /* First try to move to start of display line. */
7146 move_it_vertically_backward (it
, 0);
7148 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7150 /* If start of line is still in string or image,
7151 move further back. */
7152 back_to_previous_visible_line_start (it
);
7153 reseat (it
, it
->current
.pos
, 1);
7157 it
->current_x
= it
->hpos
= 0;
7159 /* Above call may have moved too far if continuation lines
7160 are involved. Scan forward and see if it did. */
7162 it2
.vpos
= it2
.current_y
= 0;
7163 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7164 it
->vpos
-= it2
.vpos
;
7165 it
->current_y
-= it2
.current_y
;
7166 it
->current_x
= it
->hpos
= 0;
7168 /* If we moved too far back, move IT some lines forward. */
7169 if (it2
.vpos
> -dvpos
)
7171 int delta
= it2
.vpos
+ dvpos
;
7173 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7174 /* Move back again if we got too far ahead. */
7175 if (IT_CHARPOS (*it
) >= start_charpos
)
7181 /* Return 1 if IT points into the middle of a display vector. */
7184 in_display_vector_p (it
)
7187 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7188 && it
->current
.dpvec_index
> 0
7189 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7193 /***********************************************************************
7195 ***********************************************************************/
7198 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7202 add_to_log (format
, arg1
, arg2
)
7204 Lisp_Object arg1
, arg2
;
7206 Lisp_Object args
[3];
7207 Lisp_Object msg
, fmt
;
7210 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7213 /* Do nothing if called asynchronously. Inserting text into
7214 a buffer may call after-change-functions and alike and
7215 that would means running Lisp asynchronously. */
7216 if (handling_signal
)
7220 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7222 args
[0] = fmt
= build_string (format
);
7225 msg
= Fformat (3, args
);
7227 len
= SBYTES (msg
) + 1;
7228 SAFE_ALLOCA (buffer
, char *, len
);
7229 bcopy (SDATA (msg
), buffer
, len
);
7231 message_dolog (buffer
, len
- 1, 1, 0);
7238 /* Output a newline in the *Messages* buffer if "needs" one. */
7241 message_log_maybe_newline ()
7243 if (message_log_need_newline
)
7244 message_dolog ("", 0, 1, 0);
7248 /* Add a string M of length NBYTES to the message log, optionally
7249 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7250 nonzero, means interpret the contents of M as multibyte. This
7251 function calls low-level routines in order to bypass text property
7252 hooks, etc. which might not be safe to run.
7254 This may GC (insert may run before/after change hooks),
7255 so the buffer M must NOT point to a Lisp string. */
7258 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7260 int nbytes
, nlflag
, multibyte
;
7262 if (!NILP (Vmemory_full
))
7265 if (!NILP (Vmessage_log_max
))
7267 struct buffer
*oldbuf
;
7268 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7269 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7270 int point_at_end
= 0;
7272 Lisp_Object old_deactivate_mark
, tem
;
7273 struct gcpro gcpro1
;
7275 old_deactivate_mark
= Vdeactivate_mark
;
7276 oldbuf
= current_buffer
;
7277 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7278 current_buffer
->undo_list
= Qt
;
7280 oldpoint
= message_dolog_marker1
;
7281 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7282 oldbegv
= message_dolog_marker2
;
7283 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7284 oldzv
= message_dolog_marker3
;
7285 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7286 GCPRO1 (old_deactivate_mark
);
7294 BEGV_BYTE
= BEG_BYTE
;
7297 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7299 /* Insert the string--maybe converting multibyte to single byte
7300 or vice versa, so that all the text fits the buffer. */
7302 && NILP (current_buffer
->enable_multibyte_characters
))
7304 int i
, c
, char_bytes
;
7305 unsigned char work
[1];
7307 /* Convert a multibyte string to single-byte
7308 for the *Message* buffer. */
7309 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7311 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7312 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7314 : multibyte_char_to_unibyte (c
, Qnil
));
7315 insert_1_both (work
, 1, 1, 1, 0, 0);
7318 else if (! multibyte
7319 && ! NILP (current_buffer
->enable_multibyte_characters
))
7321 int i
, c
, char_bytes
;
7322 unsigned char *msg
= (unsigned char *) m
;
7323 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7324 /* Convert a single-byte string to multibyte
7325 for the *Message* buffer. */
7326 for (i
= 0; i
< nbytes
; i
++)
7328 c
= unibyte_char_to_multibyte (msg
[i
]);
7329 char_bytes
= CHAR_STRING (c
, str
);
7330 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7334 insert_1 (m
, nbytes
, 1, 0, 0);
7338 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7339 insert_1 ("\n", 1, 1, 0, 0);
7341 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7343 this_bol_byte
= PT_BYTE
;
7345 /* See if this line duplicates the previous one.
7346 If so, combine duplicates. */
7349 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7351 prev_bol_byte
= PT_BYTE
;
7353 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7354 this_bol
, this_bol_byte
);
7357 del_range_both (prev_bol
, prev_bol_byte
,
7358 this_bol
, this_bol_byte
, 0);
7364 /* If you change this format, don't forget to also
7365 change message_log_check_duplicate. */
7366 sprintf (dupstr
, " [%d times]", dup
);
7367 duplen
= strlen (dupstr
);
7368 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7369 insert_1 (dupstr
, duplen
, 1, 0, 1);
7374 /* If we have more than the desired maximum number of lines
7375 in the *Messages* buffer now, delete the oldest ones.
7376 This is safe because we don't have undo in this buffer. */
7378 if (NATNUMP (Vmessage_log_max
))
7380 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7381 -XFASTINT (Vmessage_log_max
) - 1, 0);
7382 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7385 BEGV
= XMARKER (oldbegv
)->charpos
;
7386 BEGV_BYTE
= marker_byte_position (oldbegv
);
7395 ZV
= XMARKER (oldzv
)->charpos
;
7396 ZV_BYTE
= marker_byte_position (oldzv
);
7400 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7402 /* We can't do Fgoto_char (oldpoint) because it will run some
7404 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7405 XMARKER (oldpoint
)->bytepos
);
7408 unchain_marker (XMARKER (oldpoint
));
7409 unchain_marker (XMARKER (oldbegv
));
7410 unchain_marker (XMARKER (oldzv
));
7412 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7413 set_buffer_internal (oldbuf
);
7415 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7416 message_log_need_newline
= !nlflag
;
7417 Vdeactivate_mark
= old_deactivate_mark
;
7422 /* We are at the end of the buffer after just having inserted a newline.
7423 (Note: We depend on the fact we won't be crossing the gap.)
7424 Check to see if the most recent message looks a lot like the previous one.
7425 Return 0 if different, 1 if the new one should just replace it, or a
7426 value N > 1 if we should also append " [N times]". */
7429 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7430 int prev_bol
, this_bol
;
7431 int prev_bol_byte
, this_bol_byte
;
7434 int len
= Z_BYTE
- 1 - this_bol_byte
;
7436 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7437 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7439 for (i
= 0; i
< len
; i
++)
7441 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7449 if (*p1
++ == ' ' && *p1
++ == '[')
7452 while (*p1
>= '0' && *p1
<= '9')
7453 n
= n
* 10 + *p1
++ - '0';
7454 if (strncmp (p1
, " times]\n", 8) == 0)
7461 /* Display an echo area message M with a specified length of NBYTES
7462 bytes. The string may include null characters. If M is 0, clear
7463 out any existing message, and let the mini-buffer text show
7466 This may GC, so the buffer M must NOT point to a Lisp string. */
7469 message2 (m
, nbytes
, multibyte
)
7474 /* First flush out any partial line written with print. */
7475 message_log_maybe_newline ();
7477 message_dolog (m
, nbytes
, 1, multibyte
);
7478 message2_nolog (m
, nbytes
, multibyte
);
7482 /* The non-logging counterpart of message2. */
7485 message2_nolog (m
, nbytes
, multibyte
)
7487 int nbytes
, multibyte
;
7489 struct frame
*sf
= SELECTED_FRAME ();
7490 message_enable_multibyte
= multibyte
;
7494 if (noninteractive_need_newline
)
7495 putc ('\n', stderr
);
7496 noninteractive_need_newline
= 0;
7498 fwrite (m
, nbytes
, 1, stderr
);
7499 if (cursor_in_echo_area
== 0)
7500 fprintf (stderr
, "\n");
7503 /* A null message buffer means that the frame hasn't really been
7504 initialized yet. Error messages get reported properly by
7505 cmd_error, so this must be just an informative message; toss it. */
7506 else if (INTERACTIVE
7507 && sf
->glyphs_initialized_p
7508 && FRAME_MESSAGE_BUF (sf
))
7510 Lisp_Object mini_window
;
7513 /* Get the frame containing the mini-buffer
7514 that the selected frame is using. */
7515 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7516 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7518 FRAME_SAMPLE_VISIBILITY (f
);
7519 if (FRAME_VISIBLE_P (sf
)
7520 && ! FRAME_VISIBLE_P (f
))
7521 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7525 set_message (m
, Qnil
, nbytes
, multibyte
);
7526 if (minibuffer_auto_raise
)
7527 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7530 clear_message (1, 1);
7532 do_pending_window_change (0);
7533 echo_area_display (1);
7534 do_pending_window_change (0);
7535 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7536 (*frame_up_to_date_hook
) (f
);
7541 /* Display an echo area message M with a specified length of NBYTES
7542 bytes. The string may include null characters. If M is not a
7543 string, clear out any existing message, and let the mini-buffer
7546 This function cancels echoing. */
7549 message3 (m
, nbytes
, multibyte
)
7554 struct gcpro gcpro1
;
7557 clear_message (1,1);
7560 /* First flush out any partial line written with print. */
7561 message_log_maybe_newline ();
7567 SAFE_ALLOCA (buffer
, char *, nbytes
);
7568 bcopy (SDATA (m
), buffer
, nbytes
);
7569 message_dolog (buffer
, nbytes
, 1, multibyte
);
7572 message3_nolog (m
, nbytes
, multibyte
);
7578 /* The non-logging version of message3.
7579 This does not cancel echoing, because it is used for echoing.
7580 Perhaps we need to make a separate function for echoing
7581 and make this cancel echoing. */
7584 message3_nolog (m
, nbytes
, multibyte
)
7586 int nbytes
, multibyte
;
7588 struct frame
*sf
= SELECTED_FRAME ();
7589 message_enable_multibyte
= multibyte
;
7593 if (noninteractive_need_newline
)
7594 putc ('\n', stderr
);
7595 noninteractive_need_newline
= 0;
7597 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7598 if (cursor_in_echo_area
== 0)
7599 fprintf (stderr
, "\n");
7602 /* A null message buffer means that the frame hasn't really been
7603 initialized yet. Error messages get reported properly by
7604 cmd_error, so this must be just an informative message; toss it. */
7605 else if (INTERACTIVE
7606 && sf
->glyphs_initialized_p
7607 && FRAME_MESSAGE_BUF (sf
))
7609 Lisp_Object mini_window
;
7613 /* Get the frame containing the mini-buffer
7614 that the selected frame is using. */
7615 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7616 frame
= XWINDOW (mini_window
)->frame
;
7619 FRAME_SAMPLE_VISIBILITY (f
);
7620 if (FRAME_VISIBLE_P (sf
)
7621 && !FRAME_VISIBLE_P (f
))
7622 Fmake_frame_visible (frame
);
7624 if (STRINGP (m
) && SCHARS (m
) > 0)
7626 set_message (NULL
, m
, nbytes
, multibyte
);
7627 if (minibuffer_auto_raise
)
7628 Fraise_frame (frame
);
7629 /* Assume we are not echoing.
7630 (If we are, echo_now will override this.) */
7631 echo_message_buffer
= Qnil
;
7634 clear_message (1, 1);
7636 do_pending_window_change (0);
7637 echo_area_display (1);
7638 do_pending_window_change (0);
7639 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7640 (*frame_up_to_date_hook
) (f
);
7645 /* Display a null-terminated echo area message M. If M is 0, clear
7646 out any existing message, and let the mini-buffer text show through.
7648 The buffer M must continue to exist until after the echo area gets
7649 cleared or some other message gets displayed there. Do not pass
7650 text that is stored in a Lisp string. Do not pass text in a buffer
7651 that was alloca'd. */
7657 message2 (m
, (m
? strlen (m
) : 0), 0);
7661 /* The non-logging counterpart of message1. */
7667 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7670 /* Display a message M which contains a single %s
7671 which gets replaced with STRING. */
7674 message_with_string (m
, string
, log
)
7679 CHECK_STRING (string
);
7685 if (noninteractive_need_newline
)
7686 putc ('\n', stderr
);
7687 noninteractive_need_newline
= 0;
7688 fprintf (stderr
, m
, SDATA (string
));
7689 if (cursor_in_echo_area
== 0)
7690 fprintf (stderr
, "\n");
7694 else if (INTERACTIVE
)
7696 /* The frame whose minibuffer we're going to display the message on.
7697 It may be larger than the selected frame, so we need
7698 to use its buffer, not the selected frame's buffer. */
7699 Lisp_Object mini_window
;
7700 struct frame
*f
, *sf
= SELECTED_FRAME ();
7702 /* Get the frame containing the minibuffer
7703 that the selected frame is using. */
7704 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7705 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7707 /* A null message buffer means that the frame hasn't really been
7708 initialized yet. Error messages get reported properly by
7709 cmd_error, so this must be just an informative message; toss it. */
7710 if (FRAME_MESSAGE_BUF (f
))
7712 Lisp_Object args
[2], message
;
7713 struct gcpro gcpro1
, gcpro2
;
7715 args
[0] = build_string (m
);
7716 args
[1] = message
= string
;
7717 GCPRO2 (args
[0], message
);
7720 message
= Fformat (2, args
);
7723 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7725 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7729 /* Print should start at the beginning of the message
7730 buffer next time. */
7731 message_buf_print
= 0;
7737 /* Dump an informative message to the minibuf. If M is 0, clear out
7738 any existing message, and let the mini-buffer text show through. */
7742 message (m
, a1
, a2
, a3
)
7744 EMACS_INT a1
, a2
, a3
;
7750 if (noninteractive_need_newline
)
7751 putc ('\n', stderr
);
7752 noninteractive_need_newline
= 0;
7753 fprintf (stderr
, m
, a1
, a2
, a3
);
7754 if (cursor_in_echo_area
== 0)
7755 fprintf (stderr
, "\n");
7759 else if (INTERACTIVE
)
7761 /* The frame whose mini-buffer we're going to display the message
7762 on. It may be larger than the selected frame, so we need to
7763 use its buffer, not the selected frame's buffer. */
7764 Lisp_Object mini_window
;
7765 struct frame
*f
, *sf
= SELECTED_FRAME ();
7767 /* Get the frame containing the mini-buffer
7768 that the selected frame is using. */
7769 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7770 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7772 /* A null message buffer means that the frame hasn't really been
7773 initialized yet. Error messages get reported properly by
7774 cmd_error, so this must be just an informative message; toss
7776 if (FRAME_MESSAGE_BUF (f
))
7787 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7788 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7790 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7791 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7793 #endif /* NO_ARG_ARRAY */
7795 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7800 /* Print should start at the beginning of the message
7801 buffer next time. */
7802 message_buf_print
= 0;
7808 /* The non-logging version of message. */
7811 message_nolog (m
, a1
, a2
, a3
)
7813 EMACS_INT a1
, a2
, a3
;
7815 Lisp_Object old_log_max
;
7816 old_log_max
= Vmessage_log_max
;
7817 Vmessage_log_max
= Qnil
;
7818 message (m
, a1
, a2
, a3
);
7819 Vmessage_log_max
= old_log_max
;
7823 /* Display the current message in the current mini-buffer. This is
7824 only called from error handlers in process.c, and is not time
7830 if (!NILP (echo_area_buffer
[0]))
7833 string
= Fcurrent_message ();
7834 message3 (string
, SBYTES (string
),
7835 !NILP (current_buffer
->enable_multibyte_characters
));
7840 /* Make sure echo area buffers in `echo_buffers' are live.
7841 If they aren't, make new ones. */
7844 ensure_echo_area_buffers ()
7848 for (i
= 0; i
< 2; ++i
)
7849 if (!BUFFERP (echo_buffer
[i
])
7850 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7853 Lisp_Object old_buffer
;
7856 old_buffer
= echo_buffer
[i
];
7857 sprintf (name
, " *Echo Area %d*", i
);
7858 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7859 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7861 for (j
= 0; j
< 2; ++j
)
7862 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7863 echo_area_buffer
[j
] = echo_buffer
[i
];
7868 /* Call FN with args A1..A4 with either the current or last displayed
7869 echo_area_buffer as current buffer.
7871 WHICH zero means use the current message buffer
7872 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7873 from echo_buffer[] and clear it.
7875 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7876 suitable buffer from echo_buffer[] and clear it.
7878 Value is what FN returns. */
7881 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7884 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7890 int this_one
, the_other
, clear_buffer_p
, rc
;
7891 int count
= SPECPDL_INDEX ();
7893 /* If buffers aren't live, make new ones. */
7894 ensure_echo_area_buffers ();
7899 this_one
= 0, the_other
= 1;
7901 this_one
= 1, the_other
= 0;
7903 /* Choose a suitable buffer from echo_buffer[] is we don't
7905 if (NILP (echo_area_buffer
[this_one
]))
7907 echo_area_buffer
[this_one
]
7908 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7909 ? echo_buffer
[the_other
]
7910 : echo_buffer
[this_one
]);
7914 buffer
= echo_area_buffer
[this_one
];
7916 /* Don't get confused by reusing the buffer used for echoing
7917 for a different purpose. */
7918 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7921 record_unwind_protect (unwind_with_echo_area_buffer
,
7922 with_echo_area_buffer_unwind_data (w
));
7924 /* Make the echo area buffer current. Note that for display
7925 purposes, it is not necessary that the displayed window's buffer
7926 == current_buffer, except for text property lookup. So, let's
7927 only set that buffer temporarily here without doing a full
7928 Fset_window_buffer. We must also change w->pointm, though,
7929 because otherwise an assertions in unshow_buffer fails, and Emacs
7931 set_buffer_internal_1 (XBUFFER (buffer
));
7935 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7938 current_buffer
->undo_list
= Qt
;
7939 current_buffer
->read_only
= Qnil
;
7940 specbind (Qinhibit_read_only
, Qt
);
7941 specbind (Qinhibit_modification_hooks
, Qt
);
7943 if (clear_buffer_p
&& Z
> BEG
)
7946 xassert (BEGV
>= BEG
);
7947 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7949 rc
= fn (a1
, a2
, a3
, a4
);
7951 xassert (BEGV
>= BEG
);
7952 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7954 unbind_to (count
, Qnil
);
7959 /* Save state that should be preserved around the call to the function
7960 FN called in with_echo_area_buffer. */
7963 with_echo_area_buffer_unwind_data (w
)
7969 /* Reduce consing by keeping one vector in
7970 Vwith_echo_area_save_vector. */
7971 vector
= Vwith_echo_area_save_vector
;
7972 Vwith_echo_area_save_vector
= Qnil
;
7975 vector
= Fmake_vector (make_number (7), Qnil
);
7977 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7978 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7979 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7983 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7984 AREF (vector
, i
) = w
->buffer
; ++i
;
7985 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7986 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7991 for (; i
< end
; ++i
)
7992 AREF (vector
, i
) = Qnil
;
7995 xassert (i
== ASIZE (vector
));
8000 /* Restore global state from VECTOR which was created by
8001 with_echo_area_buffer_unwind_data. */
8004 unwind_with_echo_area_buffer (vector
)
8007 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8008 Vdeactivate_mark
= AREF (vector
, 1);
8009 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8011 if (WINDOWP (AREF (vector
, 3)))
8014 Lisp_Object buffer
, charpos
, bytepos
;
8016 w
= XWINDOW (AREF (vector
, 3));
8017 buffer
= AREF (vector
, 4);
8018 charpos
= AREF (vector
, 5);
8019 bytepos
= AREF (vector
, 6);
8022 set_marker_both (w
->pointm
, buffer
,
8023 XFASTINT (charpos
), XFASTINT (bytepos
));
8026 Vwith_echo_area_save_vector
= vector
;
8031 /* Set up the echo area for use by print functions. MULTIBYTE_P
8032 non-zero means we will print multibyte. */
8035 setup_echo_area_for_printing (multibyte_p
)
8038 /* If we can't find an echo area any more, exit. */
8039 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8042 ensure_echo_area_buffers ();
8044 if (!message_buf_print
)
8046 /* A message has been output since the last time we printed.
8047 Choose a fresh echo area buffer. */
8048 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8049 echo_area_buffer
[0] = echo_buffer
[1];
8051 echo_area_buffer
[0] = echo_buffer
[0];
8053 /* Switch to that buffer and clear it. */
8054 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8055 current_buffer
->truncate_lines
= Qnil
;
8059 int count
= SPECPDL_INDEX ();
8060 specbind (Qinhibit_read_only
, Qt
);
8061 /* Note that undo recording is always disabled. */
8063 unbind_to (count
, Qnil
);
8065 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8067 /* Set up the buffer for the multibyteness we need. */
8069 != !NILP (current_buffer
->enable_multibyte_characters
))
8070 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8072 /* Raise the frame containing the echo area. */
8073 if (minibuffer_auto_raise
)
8075 struct frame
*sf
= SELECTED_FRAME ();
8076 Lisp_Object mini_window
;
8077 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8078 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8081 message_log_maybe_newline ();
8082 message_buf_print
= 1;
8086 if (NILP (echo_area_buffer
[0]))
8088 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8089 echo_area_buffer
[0] = echo_buffer
[1];
8091 echo_area_buffer
[0] = echo_buffer
[0];
8094 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8096 /* Someone switched buffers between print requests. */
8097 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8098 current_buffer
->truncate_lines
= Qnil
;
8104 /* Display an echo area message in window W. Value is non-zero if W's
8105 height is changed. If display_last_displayed_message_p is
8106 non-zero, display the message that was last displayed, otherwise
8107 display the current message. */
8110 display_echo_area (w
)
8113 int i
, no_message_p
, window_height_changed_p
, count
;
8115 /* Temporarily disable garbage collections while displaying the echo
8116 area. This is done because a GC can print a message itself.
8117 That message would modify the echo area buffer's contents while a
8118 redisplay of the buffer is going on, and seriously confuse
8120 count
= inhibit_garbage_collection ();
8122 /* If there is no message, we must call display_echo_area_1
8123 nevertheless because it resizes the window. But we will have to
8124 reset the echo_area_buffer in question to nil at the end because
8125 with_echo_area_buffer will sets it to an empty buffer. */
8126 i
= display_last_displayed_message_p
? 1 : 0;
8127 no_message_p
= NILP (echo_area_buffer
[i
]);
8129 window_height_changed_p
8130 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8131 display_echo_area_1
,
8132 (EMACS_INT
) w
, Qnil
, 0, 0);
8135 echo_area_buffer
[i
] = Qnil
;
8137 unbind_to (count
, Qnil
);
8138 return window_height_changed_p
;
8142 /* Helper for display_echo_area. Display the current buffer which
8143 contains the current echo area message in window W, a mini-window,
8144 a pointer to which is passed in A1. A2..A4 are currently not used.
8145 Change the height of W so that all of the message is displayed.
8146 Value is non-zero if height of W was changed. */
8149 display_echo_area_1 (a1
, a2
, a3
, a4
)
8154 struct window
*w
= (struct window
*) a1
;
8156 struct text_pos start
;
8157 int window_height_changed_p
= 0;
8159 /* Do this before displaying, so that we have a large enough glyph
8160 matrix for the display. If we can't get enough space for the
8161 whole text, display the last N lines. That works by setting w->start. */
8162 window_height_changed_p
= resize_mini_window (w
, 0);
8164 /* Use the starting position chosen by resize_mini_window. */
8165 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8168 clear_glyph_matrix (w
->desired_matrix
);
8169 XSETWINDOW (window
, w
);
8170 try_window (window
, start
, 0);
8172 return window_height_changed_p
;
8176 /* Resize the echo area window to exactly the size needed for the
8177 currently displayed message, if there is one. If a mini-buffer
8178 is active, don't shrink it. */
8181 resize_echo_area_exactly ()
8183 if (BUFFERP (echo_area_buffer
[0])
8184 && WINDOWP (echo_area_window
))
8186 struct window
*w
= XWINDOW (echo_area_window
);
8188 Lisp_Object resize_exactly
;
8190 if (minibuf_level
== 0)
8191 resize_exactly
= Qt
;
8193 resize_exactly
= Qnil
;
8195 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8196 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8199 ++windows_or_buffers_changed
;
8200 ++update_mode_lines
;
8201 redisplay_internal (0);
8207 /* Callback function for with_echo_area_buffer, when used from
8208 resize_echo_area_exactly. A1 contains a pointer to the window to
8209 resize, EXACTLY non-nil means resize the mini-window exactly to the
8210 size of the text displayed. A3 and A4 are not used. Value is what
8211 resize_mini_window returns. */
8214 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8216 Lisp_Object exactly
;
8219 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8223 /* Resize mini-window W to fit the size of its contents. EXACT:P
8224 means size the window exactly to the size needed. Otherwise, it's
8225 only enlarged until W's buffer is empty.
8227 Set W->start to the right place to begin display. If the whole
8228 contents fit, start at the beginning. Otherwise, start so as
8229 to make the end of the contents appear. This is particularly
8230 important for y-or-n-p, but seems desirable generally.
8232 Value is non-zero if the window height has been changed. */
8235 resize_mini_window (w
, exact_p
)
8239 struct frame
*f
= XFRAME (w
->frame
);
8240 int window_height_changed_p
= 0;
8242 xassert (MINI_WINDOW_P (w
));
8244 /* By default, start display at the beginning. */
8245 set_marker_both (w
->start
, w
->buffer
,
8246 BUF_BEGV (XBUFFER (w
->buffer
)),
8247 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8249 /* Don't resize windows while redisplaying a window; it would
8250 confuse redisplay functions when the size of the window they are
8251 displaying changes from under them. Such a resizing can happen,
8252 for instance, when which-func prints a long message while
8253 we are running fontification-functions. We're running these
8254 functions with safe_call which binds inhibit-redisplay to t. */
8255 if (!NILP (Vinhibit_redisplay
))
8258 /* Nil means don't try to resize. */
8259 if (NILP (Vresize_mini_windows
)
8260 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8263 if (!FRAME_MINIBUF_ONLY_P (f
))
8266 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8267 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8268 int height
, max_height
;
8269 int unit
= FRAME_LINE_HEIGHT (f
);
8270 struct text_pos start
;
8271 struct buffer
*old_current_buffer
= NULL
;
8273 if (current_buffer
!= XBUFFER (w
->buffer
))
8275 old_current_buffer
= current_buffer
;
8276 set_buffer_internal (XBUFFER (w
->buffer
));
8279 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8281 /* Compute the max. number of lines specified by the user. */
8282 if (FLOATP (Vmax_mini_window_height
))
8283 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8284 else if (INTEGERP (Vmax_mini_window_height
))
8285 max_height
= XINT (Vmax_mini_window_height
);
8287 max_height
= total_height
/ 4;
8289 /* Correct that max. height if it's bogus. */
8290 max_height
= max (1, max_height
);
8291 max_height
= min (total_height
, max_height
);
8293 /* Find out the height of the text in the window. */
8294 if (it
.truncate_lines_p
)
8299 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8300 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8301 height
= it
.current_y
+ last_height
;
8303 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8304 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8305 height
= (height
+ unit
- 1) / unit
;
8308 /* Compute a suitable window start. */
8309 if (height
> max_height
)
8311 height
= max_height
;
8312 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8313 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8314 start
= it
.current
.pos
;
8317 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8318 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8320 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8322 /* Let it grow only, until we display an empty message, in which
8323 case the window shrinks again. */
8324 if (height
> WINDOW_TOTAL_LINES (w
))
8326 int old_height
= WINDOW_TOTAL_LINES (w
);
8327 freeze_window_starts (f
, 1);
8328 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8329 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8331 else if (height
< WINDOW_TOTAL_LINES (w
)
8332 && (exact_p
|| BEGV
== ZV
))
8334 int old_height
= WINDOW_TOTAL_LINES (w
);
8335 freeze_window_starts (f
, 0);
8336 shrink_mini_window (w
);
8337 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8342 /* Always resize to exact size needed. */
8343 if (height
> WINDOW_TOTAL_LINES (w
))
8345 int old_height
= WINDOW_TOTAL_LINES (w
);
8346 freeze_window_starts (f
, 1);
8347 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8348 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8350 else if (height
< WINDOW_TOTAL_LINES (w
))
8352 int old_height
= WINDOW_TOTAL_LINES (w
);
8353 freeze_window_starts (f
, 0);
8354 shrink_mini_window (w
);
8358 freeze_window_starts (f
, 1);
8359 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8362 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8366 if (old_current_buffer
)
8367 set_buffer_internal (old_current_buffer
);
8370 return window_height_changed_p
;
8374 /* Value is the current message, a string, or nil if there is no
8382 if (NILP (echo_area_buffer
[0]))
8386 with_echo_area_buffer (0, 0, current_message_1
,
8387 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8389 echo_area_buffer
[0] = Qnil
;
8397 current_message_1 (a1
, a2
, a3
, a4
)
8402 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8405 *msg
= make_buffer_string (BEG
, Z
, 1);
8412 /* Push the current message on Vmessage_stack for later restauration
8413 by restore_message. Value is non-zero if the current message isn't
8414 empty. This is a relatively infrequent operation, so it's not
8415 worth optimizing. */
8421 msg
= current_message ();
8422 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8423 return STRINGP (msg
);
8427 /* Restore message display from the top of Vmessage_stack. */
8434 xassert (CONSP (Vmessage_stack
));
8435 msg
= XCAR (Vmessage_stack
);
8437 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8439 message3_nolog (msg
, 0, 0);
8443 /* Handler for record_unwind_protect calling pop_message. */
8446 pop_message_unwind (dummy
)
8453 /* Pop the top-most entry off Vmessage_stack. */
8458 xassert (CONSP (Vmessage_stack
));
8459 Vmessage_stack
= XCDR (Vmessage_stack
);
8463 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8464 exits. If the stack is not empty, we have a missing pop_message
8468 check_message_stack ()
8470 if (!NILP (Vmessage_stack
))
8475 /* Truncate to NCHARS what will be displayed in the echo area the next
8476 time we display it---but don't redisplay it now. */
8479 truncate_echo_area (nchars
)
8483 echo_area_buffer
[0] = Qnil
;
8484 /* A null message buffer means that the frame hasn't really been
8485 initialized yet. Error messages get reported properly by
8486 cmd_error, so this must be just an informative message; toss it. */
8487 else if (!noninteractive
8489 && !NILP (echo_area_buffer
[0]))
8491 struct frame
*sf
= SELECTED_FRAME ();
8492 if (FRAME_MESSAGE_BUF (sf
))
8493 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8498 /* Helper function for truncate_echo_area. Truncate the current
8499 message to at most NCHARS characters. */
8502 truncate_message_1 (nchars
, a2
, a3
, a4
)
8507 if (BEG
+ nchars
< Z
)
8508 del_range (BEG
+ nchars
, Z
);
8510 echo_area_buffer
[0] = Qnil
;
8515 /* Set the current message to a substring of S or STRING.
8517 If STRING is a Lisp string, set the message to the first NBYTES
8518 bytes from STRING. NBYTES zero means use the whole string. If
8519 STRING is multibyte, the message will be displayed multibyte.
8521 If S is not null, set the message to the first LEN bytes of S. LEN
8522 zero means use the whole string. MULTIBYTE_P non-zero means S is
8523 multibyte. Display the message multibyte in that case.
8525 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8526 to t before calling set_message_1 (which calls insert).
8530 set_message (s
, string
, nbytes
, multibyte_p
)
8533 int nbytes
, multibyte_p
;
8535 message_enable_multibyte
8536 = ((s
&& multibyte_p
)
8537 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8539 with_echo_area_buffer (0, 0, set_message_1
,
8540 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8541 message_buf_print
= 0;
8542 help_echo_showing_p
= 0;
8546 /* Helper function for set_message. Arguments have the same meaning
8547 as there, with A1 corresponding to S and A2 corresponding to STRING
8548 This function is called with the echo area buffer being
8552 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8555 EMACS_INT nbytes
, multibyte_p
;
8557 const char *s
= (const char *) a1
;
8558 Lisp_Object string
= a2
;
8560 /* Change multibyteness of the echo buffer appropriately. */
8561 if (message_enable_multibyte
8562 != !NILP (current_buffer
->enable_multibyte_characters
))
8563 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8565 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8567 /* Insert new message at BEG. */
8568 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8571 if (STRINGP (string
))
8576 nbytes
= SBYTES (string
);
8577 nchars
= string_byte_to_char (string
, nbytes
);
8579 /* This function takes care of single/multibyte conversion. We
8580 just have to ensure that the echo area buffer has the right
8581 setting of enable_multibyte_characters. */
8582 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8587 nbytes
= strlen (s
);
8589 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8591 /* Convert from multi-byte to single-byte. */
8593 unsigned char work
[1];
8595 /* Convert a multibyte string to single-byte. */
8596 for (i
= 0; i
< nbytes
; i
+= n
)
8598 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8599 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
8601 : multibyte_char_to_unibyte (c
, Qnil
));
8602 insert_1_both (work
, 1, 1, 1, 0, 0);
8605 else if (!multibyte_p
8606 && !NILP (current_buffer
->enable_multibyte_characters
))
8608 /* Convert from single-byte to multi-byte. */
8610 const unsigned char *msg
= (const unsigned char *) s
;
8611 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8613 /* Convert a single-byte string to multibyte. */
8614 for (i
= 0; i
< nbytes
; i
++)
8616 c
= unibyte_char_to_multibyte (msg
[i
]);
8617 n
= CHAR_STRING (c
, str
);
8618 insert_1_both (str
, 1, n
, 1, 0, 0);
8622 insert_1 (s
, nbytes
, 1, 0, 0);
8629 /* Clear messages. CURRENT_P non-zero means clear the current
8630 message. LAST_DISPLAYED_P non-zero means clear the message
8634 clear_message (current_p
, last_displayed_p
)
8635 int current_p
, last_displayed_p
;
8639 echo_area_buffer
[0] = Qnil
;
8640 message_cleared_p
= 1;
8643 if (last_displayed_p
)
8644 echo_area_buffer
[1] = Qnil
;
8646 message_buf_print
= 0;
8649 /* Clear garbaged frames.
8651 This function is used where the old redisplay called
8652 redraw_garbaged_frames which in turn called redraw_frame which in
8653 turn called clear_frame. The call to clear_frame was a source of
8654 flickering. I believe a clear_frame is not necessary. It should
8655 suffice in the new redisplay to invalidate all current matrices,
8656 and ensure a complete redisplay of all windows. */
8659 clear_garbaged_frames ()
8663 Lisp_Object tail
, frame
;
8664 int changed_count
= 0;
8666 FOR_EACH_FRAME (tail
, frame
)
8668 struct frame
*f
= XFRAME (frame
);
8670 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8674 Fredraw_frame (frame
);
8675 f
->force_flush_display_p
= 1;
8677 clear_current_matrices (f
);
8686 ++windows_or_buffers_changed
;
8691 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8692 is non-zero update selected_frame. Value is non-zero if the
8693 mini-windows height has been changed. */
8696 echo_area_display (update_frame_p
)
8699 Lisp_Object mini_window
;
8702 int window_height_changed_p
= 0;
8703 struct frame
*sf
= SELECTED_FRAME ();
8705 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8706 w
= XWINDOW (mini_window
);
8707 f
= XFRAME (WINDOW_FRAME (w
));
8709 /* Don't display if frame is invisible or not yet initialized. */
8710 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8713 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8715 #ifdef HAVE_WINDOW_SYSTEM
8716 /* When Emacs starts, selected_frame may be a visible terminal
8717 frame, even if we run under a window system. If we let this
8718 through, a message would be displayed on the terminal. */
8719 if (EQ (selected_frame
, Vterminal_frame
)
8720 && !NILP (Vwindow_system
))
8722 #endif /* HAVE_WINDOW_SYSTEM */
8725 /* Redraw garbaged frames. */
8727 clear_garbaged_frames ();
8729 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8731 echo_area_window
= mini_window
;
8732 window_height_changed_p
= display_echo_area (w
);
8733 w
->must_be_updated_p
= 1;
8735 /* Update the display, unless called from redisplay_internal.
8736 Also don't update the screen during redisplay itself. The
8737 update will happen at the end of redisplay, and an update
8738 here could cause confusion. */
8739 if (update_frame_p
&& !redisplaying_p
)
8743 /* If the display update has been interrupted by pending
8744 input, update mode lines in the frame. Due to the
8745 pending input, it might have been that redisplay hasn't
8746 been called, so that mode lines above the echo area are
8747 garbaged. This looks odd, so we prevent it here. */
8748 if (!display_completed
)
8749 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8751 if (window_height_changed_p
8752 /* Don't do this if Emacs is shutting down. Redisplay
8753 needs to run hooks. */
8754 && !NILP (Vrun_hooks
))
8756 /* Must update other windows. Likewise as in other
8757 cases, don't let this update be interrupted by
8759 int count
= SPECPDL_INDEX ();
8760 specbind (Qredisplay_dont_pause
, Qt
);
8761 windows_or_buffers_changed
= 1;
8762 redisplay_internal (0);
8763 unbind_to (count
, Qnil
);
8765 else if (FRAME_WINDOW_P (f
) && n
== 0)
8767 /* Window configuration is the same as before.
8768 Can do with a display update of the echo area,
8769 unless we displayed some mode lines. */
8770 update_single_window (w
, 1);
8771 rif
->flush_display (f
);
8774 update_frame (f
, 1, 1);
8776 /* If cursor is in the echo area, make sure that the next
8777 redisplay displays the minibuffer, so that the cursor will
8778 be replaced with what the minibuffer wants. */
8779 if (cursor_in_echo_area
)
8780 ++windows_or_buffers_changed
;
8783 else if (!EQ (mini_window
, selected_window
))
8784 windows_or_buffers_changed
++;
8786 /* The current message is now also the last one displayed. */
8787 echo_area_buffer
[1] = echo_area_buffer
[0];
8789 /* Prevent redisplay optimization in redisplay_internal by resetting
8790 this_line_start_pos. This is done because the mini-buffer now
8791 displays the message instead of its buffer text. */
8792 if (EQ (mini_window
, selected_window
))
8793 CHARPOS (this_line_start_pos
) = 0;
8795 return window_height_changed_p
;
8800 /***********************************************************************
8801 Mode Lines and Frame Titles
8802 ***********************************************************************/
8804 /* A buffer for constructing non-propertized mode-line strings and
8805 frame titles in it; allocated from the heap in init_xdisp and
8806 resized as needed in store_mode_line_noprop_char. */
8808 static char *mode_line_noprop_buf
;
8810 /* The buffer's end, and a current output position in it. */
8812 static char *mode_line_noprop_buf_end
;
8813 static char *mode_line_noprop_ptr
;
8815 #define MODE_LINE_NOPROP_LEN(start) \
8816 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8819 MODE_LINE_DISPLAY
= 0,
8825 /* Alist that caches the results of :propertize.
8826 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8827 static Lisp_Object mode_line_proptrans_alist
;
8829 /* List of strings making up the mode-line. */
8830 static Lisp_Object mode_line_string_list
;
8832 /* Base face property when building propertized mode line string. */
8833 static Lisp_Object mode_line_string_face
;
8834 static Lisp_Object mode_line_string_face_prop
;
8837 /* Unwind data for mode line strings */
8839 static Lisp_Object Vmode_line_unwind_vector
;
8842 format_mode_line_unwind_data (obuf
, save_proptrans
)
8843 struct buffer
*obuf
;
8847 /* Reduce consing by keeping one vector in
8848 Vwith_echo_area_save_vector. */
8849 vector
= Vmode_line_unwind_vector
;
8850 Vmode_line_unwind_vector
= Qnil
;
8853 vector
= Fmake_vector (make_number (7), Qnil
);
8855 AREF (vector
, 0) = make_number (mode_line_target
);
8856 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8857 AREF (vector
, 2) = mode_line_string_list
;
8858 AREF (vector
, 3) = (save_proptrans
? mode_line_proptrans_alist
: Qt
);
8859 AREF (vector
, 4) = mode_line_string_face
;
8860 AREF (vector
, 5) = mode_line_string_face_prop
;
8863 XSETBUFFER (AREF (vector
, 6), obuf
);
8865 AREF (vector
, 6) = Qnil
;
8871 unwind_format_mode_line (vector
)
8874 mode_line_target
= XINT (AREF (vector
, 0));
8875 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8876 mode_line_string_list
= AREF (vector
, 2);
8877 if (! EQ (AREF (vector
, 3), Qt
))
8878 mode_line_proptrans_alist
= AREF (vector
, 3);
8879 mode_line_string_face
= AREF (vector
, 4);
8880 mode_line_string_face_prop
= AREF (vector
, 5);
8882 if (!NILP (AREF (vector
, 6)))
8884 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8885 AREF (vector
, 6) = Qnil
;
8888 Vmode_line_unwind_vector
= vector
;
8893 /* Store a single character C for the frame title in mode_line_noprop_buf.
8894 Re-allocate mode_line_noprop_buf if necessary. */
8898 store_mode_line_noprop_char (char c
)
8900 store_mode_line_noprop_char (c
)
8904 /* If output position has reached the end of the allocated buffer,
8905 double the buffer's size. */
8906 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8908 int len
= MODE_LINE_NOPROP_LEN (0);
8909 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8910 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8911 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8912 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8915 *mode_line_noprop_ptr
++ = c
;
8919 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8920 mode_line_noprop_ptr. STR is the string to store. Do not copy
8921 characters that yield more columns than PRECISION; PRECISION <= 0
8922 means copy the whole string. Pad with spaces until FIELD_WIDTH
8923 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8924 pad. Called from display_mode_element when it is used to build a
8928 store_mode_line_noprop (str
, field_width
, precision
)
8929 const unsigned char *str
;
8930 int field_width
, precision
;
8935 /* Copy at most PRECISION chars from STR. */
8936 nbytes
= strlen (str
);
8937 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8939 store_mode_line_noprop_char (*str
++);
8941 /* Fill up with spaces until FIELD_WIDTH reached. */
8942 while (field_width
> 0
8945 store_mode_line_noprop_char (' ');
8952 /***********************************************************************
8954 ***********************************************************************/
8956 #ifdef HAVE_WINDOW_SYSTEM
8958 /* Set the title of FRAME, if it has changed. The title format is
8959 Vicon_title_format if FRAME is iconified, otherwise it is
8960 frame_title_format. */
8963 x_consider_frame_title (frame
)
8966 struct frame
*f
= XFRAME (frame
);
8968 if (FRAME_WINDOW_P (f
)
8969 || FRAME_MINIBUF_ONLY_P (f
)
8970 || f
->explicit_name
)
8972 /* Do we have more than one visible frame on this X display? */
8979 int count
= SPECPDL_INDEX ();
8981 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8983 Lisp_Object other_frame
= XCAR (tail
);
8984 struct frame
*tf
= XFRAME (other_frame
);
8987 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8988 && !FRAME_MINIBUF_ONLY_P (tf
)
8989 && !EQ (other_frame
, tip_frame
)
8990 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8994 /* Set global variable indicating that multiple frames exist. */
8995 multiple_frames
= CONSP (tail
);
8997 /* Switch to the buffer of selected window of the frame. Set up
8998 mode_line_target so that display_mode_element will output into
8999 mode_line_noprop_buf; then display the title. */
9000 record_unwind_protect (unwind_format_mode_line
,
9001 format_mode_line_unwind_data (current_buffer
, 0));
9003 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9004 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9006 mode_line_target
= MODE_LINE_TITLE
;
9007 title_start
= MODE_LINE_NOPROP_LEN (0);
9008 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9009 NULL
, DEFAULT_FACE_ID
);
9010 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9011 len
= MODE_LINE_NOPROP_LEN (title_start
);
9012 title
= mode_line_noprop_buf
+ title_start
;
9013 unbind_to (count
, Qnil
);
9015 /* Set the title only if it's changed. This avoids consing in
9016 the common case where it hasn't. (If it turns out that we've
9017 already wasted too much time by walking through the list with
9018 display_mode_element, then we might need to optimize at a
9019 higher level than this.) */
9020 if (! STRINGP (f
->name
)
9021 || SBYTES (f
->name
) != len
9022 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9023 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9027 #endif /* not HAVE_WINDOW_SYSTEM */
9032 /***********************************************************************
9034 ***********************************************************************/
9037 /* Prepare for redisplay by updating menu-bar item lists when
9038 appropriate. This can call eval. */
9041 prepare_menu_bars ()
9044 struct gcpro gcpro1
, gcpro2
;
9046 Lisp_Object tooltip_frame
;
9048 #ifdef HAVE_WINDOW_SYSTEM
9049 tooltip_frame
= tip_frame
;
9051 tooltip_frame
= Qnil
;
9054 /* Update all frame titles based on their buffer names, etc. We do
9055 this before the menu bars so that the buffer-menu will show the
9056 up-to-date frame titles. */
9057 #ifdef HAVE_WINDOW_SYSTEM
9058 if (windows_or_buffers_changed
|| update_mode_lines
)
9060 Lisp_Object tail
, frame
;
9062 FOR_EACH_FRAME (tail
, frame
)
9065 if (!EQ (frame
, tooltip_frame
)
9066 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9067 x_consider_frame_title (frame
);
9070 #endif /* HAVE_WINDOW_SYSTEM */
9072 /* Update the menu bar item lists, if appropriate. This has to be
9073 done before any actual redisplay or generation of display lines. */
9074 all_windows
= (update_mode_lines
9075 || buffer_shared
> 1
9076 || windows_or_buffers_changed
);
9079 Lisp_Object tail
, frame
;
9080 int count
= SPECPDL_INDEX ();
9081 /* 1 means that update_menu_bar has run its hooks
9082 so any further calls to update_menu_bar shouldn't do so again. */
9083 int menu_bar_hooks_run
= 0;
9085 record_unwind_save_match_data ();
9087 FOR_EACH_FRAME (tail
, frame
)
9091 /* Ignore tooltip frame. */
9092 if (EQ (frame
, tooltip_frame
))
9095 /* If a window on this frame changed size, report that to
9096 the user and clear the size-change flag. */
9097 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9099 Lisp_Object functions
;
9101 /* Clear flag first in case we get an error below. */
9102 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9103 functions
= Vwindow_size_change_functions
;
9104 GCPRO2 (tail
, functions
);
9106 while (CONSP (functions
))
9108 call1 (XCAR (functions
), frame
);
9109 functions
= XCDR (functions
);
9115 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9116 #ifdef HAVE_WINDOW_SYSTEM
9117 update_tool_bar (f
, 0);
9119 mac_update_title_bar (f
, 0);
9125 unbind_to (count
, Qnil
);
9129 struct frame
*sf
= SELECTED_FRAME ();
9130 update_menu_bar (sf
, 1, 0);
9131 #ifdef HAVE_WINDOW_SYSTEM
9132 update_tool_bar (sf
, 1);
9134 mac_update_title_bar (sf
, 1);
9139 /* Motif needs this. See comment in xmenu.c. Turn it off when
9140 pending_menu_activation is not defined. */
9141 #ifdef USE_X_TOOLKIT
9142 pending_menu_activation
= 0;
9147 /* Update the menu bar item list for frame F. This has to be done
9148 before we start to fill in any display lines, because it can call
9151 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9153 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9154 already ran the menu bar hooks for this redisplay, so there
9155 is no need to run them again. The return value is the
9156 updated value of this flag, to pass to the next call. */
9159 update_menu_bar (f
, save_match_data
, hooks_run
)
9161 int save_match_data
;
9165 register struct window
*w
;
9167 /* If called recursively during a menu update, do nothing. This can
9168 happen when, for instance, an activate-menubar-hook causes a
9170 if (inhibit_menubar_update
)
9173 window
= FRAME_SELECTED_WINDOW (f
);
9174 w
= XWINDOW (window
);
9176 #if 0 /* The if statement below this if statement used to include the
9177 condition !NILP (w->update_mode_line), rather than using
9178 update_mode_lines directly, and this if statement may have
9179 been added to make that condition work. Now the if
9180 statement below matches its comment, this isn't needed. */
9181 if (update_mode_lines
)
9182 w
->update_mode_line
= Qt
;
9185 if (FRAME_WINDOW_P (f
)
9187 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9188 || defined (USE_GTK)
9189 FRAME_EXTERNAL_MENU_BAR (f
)
9191 FRAME_MENU_BAR_LINES (f
) > 0
9193 : FRAME_MENU_BAR_LINES (f
) > 0)
9195 /* If the user has switched buffers or windows, we need to
9196 recompute to reflect the new bindings. But we'll
9197 recompute when update_mode_lines is set too; that means
9198 that people can use force-mode-line-update to request
9199 that the menu bar be recomputed. The adverse effect on
9200 the rest of the redisplay algorithm is about the same as
9201 windows_or_buffers_changed anyway. */
9202 if (windows_or_buffers_changed
9203 /* This used to test w->update_mode_line, but we believe
9204 there is no need to recompute the menu in that case. */
9205 || update_mode_lines
9206 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9207 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9208 != !NILP (w
->last_had_star
))
9209 || ((!NILP (Vtransient_mark_mode
)
9210 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9211 != !NILP (w
->region_showing
)))
9213 struct buffer
*prev
= current_buffer
;
9214 int count
= SPECPDL_INDEX ();
9216 specbind (Qinhibit_menubar_update
, Qt
);
9218 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9219 if (save_match_data
)
9220 record_unwind_save_match_data ();
9221 if (NILP (Voverriding_local_map_menu_flag
))
9223 specbind (Qoverriding_terminal_local_map
, Qnil
);
9224 specbind (Qoverriding_local_map
, Qnil
);
9229 /* Run the Lucid hook. */
9230 safe_run_hooks (Qactivate_menubar_hook
);
9232 /* If it has changed current-menubar from previous value,
9233 really recompute the menu-bar from the value. */
9234 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9235 call0 (Qrecompute_lucid_menubar
);
9237 safe_run_hooks (Qmenu_bar_update_hook
);
9242 XSETFRAME (Vmenu_updating_frame
, f
);
9243 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9245 /* Redisplay the menu bar in case we changed it. */
9246 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9247 || defined (USE_GTK)
9248 if (FRAME_WINDOW_P (f
))
9251 /* All frames on Mac OS share the same menubar. So only
9252 the selected frame should be allowed to set it. */
9253 if (f
== SELECTED_FRAME ())
9255 set_frame_menubar (f
, 0, 0);
9258 /* On a terminal screen, the menu bar is an ordinary screen
9259 line, and this makes it get updated. */
9260 w
->update_mode_line
= Qt
;
9261 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9262 /* In the non-toolkit version, the menu bar is an ordinary screen
9263 line, and this makes it get updated. */
9264 w
->update_mode_line
= Qt
;
9265 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9267 unbind_to (count
, Qnil
);
9268 set_buffer_internal_1 (prev
);
9277 /***********************************************************************
9279 ***********************************************************************/
9281 #ifdef HAVE_WINDOW_SYSTEM
9284 Nominal cursor position -- where to draw output.
9285 HPOS and VPOS are window relative glyph matrix coordinates.
9286 X and Y are window relative pixel coordinates. */
9288 struct cursor_pos output_cursor
;
9292 Set the global variable output_cursor to CURSOR. All cursor
9293 positions are relative to updated_window. */
9296 set_output_cursor (cursor
)
9297 struct cursor_pos
*cursor
;
9299 output_cursor
.hpos
= cursor
->hpos
;
9300 output_cursor
.vpos
= cursor
->vpos
;
9301 output_cursor
.x
= cursor
->x
;
9302 output_cursor
.y
= cursor
->y
;
9307 Set a nominal cursor position.
9309 HPOS and VPOS are column/row positions in a window glyph matrix. X
9310 and Y are window text area relative pixel positions.
9312 If this is done during an update, updated_window will contain the
9313 window that is being updated and the position is the future output
9314 cursor position for that window. If updated_window is null, use
9315 selected_window and display the cursor at the given position. */
9318 x_cursor_to (vpos
, hpos
, y
, x
)
9319 int vpos
, hpos
, y
, x
;
9323 /* If updated_window is not set, work on selected_window. */
9327 w
= XWINDOW (selected_window
);
9329 /* Set the output cursor. */
9330 output_cursor
.hpos
= hpos
;
9331 output_cursor
.vpos
= vpos
;
9332 output_cursor
.x
= x
;
9333 output_cursor
.y
= y
;
9335 /* If not called as part of an update, really display the cursor.
9336 This will also set the cursor position of W. */
9337 if (updated_window
== NULL
)
9340 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9341 if (rif
->flush_display_optional
)
9342 rif
->flush_display_optional (SELECTED_FRAME ());
9347 #endif /* HAVE_WINDOW_SYSTEM */
9350 /***********************************************************************
9352 ***********************************************************************/
9354 #ifdef HAVE_WINDOW_SYSTEM
9356 /* Where the mouse was last time we reported a mouse event. */
9358 FRAME_PTR last_mouse_frame
;
9360 /* Tool-bar item index of the item on which a mouse button was pressed
9363 int last_tool_bar_item
;
9366 /* Update the tool-bar item list for frame F. This has to be done
9367 before we start to fill in any display lines. Called from
9368 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9369 and restore it here. */
9372 update_tool_bar (f
, save_match_data
)
9374 int save_match_data
;
9377 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9379 int do_update
= WINDOWP (f
->tool_bar_window
)
9380 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9388 window
= FRAME_SELECTED_WINDOW (f
);
9389 w
= XWINDOW (window
);
9391 /* If the user has switched buffers or windows, we need to
9392 recompute to reflect the new bindings. But we'll
9393 recompute when update_mode_lines is set too; that means
9394 that people can use force-mode-line-update to request
9395 that the menu bar be recomputed. The adverse effect on
9396 the rest of the redisplay algorithm is about the same as
9397 windows_or_buffers_changed anyway. */
9398 if (windows_or_buffers_changed
9399 || !NILP (w
->update_mode_line
)
9400 || update_mode_lines
9401 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9402 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9403 != !NILP (w
->last_had_star
))
9404 || ((!NILP (Vtransient_mark_mode
)
9405 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9406 != !NILP (w
->region_showing
)))
9408 struct buffer
*prev
= current_buffer
;
9409 int count
= SPECPDL_INDEX ();
9410 Lisp_Object new_tool_bar
;
9412 struct gcpro gcpro1
;
9414 /* Set current_buffer to the buffer of the selected
9415 window of the frame, so that we get the right local
9417 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9419 /* Save match data, if we must. */
9420 if (save_match_data
)
9421 record_unwind_save_match_data ();
9423 /* Make sure that we don't accidentally use bogus keymaps. */
9424 if (NILP (Voverriding_local_map_menu_flag
))
9426 specbind (Qoverriding_terminal_local_map
, Qnil
);
9427 specbind (Qoverriding_local_map
, Qnil
);
9430 GCPRO1 (new_tool_bar
);
9432 /* Build desired tool-bar items from keymaps. */
9433 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9436 /* Redisplay the tool-bar if we changed it. */
9437 if (new_n_tool_bar
!= f
->n_tool_bar_items
9438 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9440 /* Redisplay that happens asynchronously due to an expose event
9441 may access f->tool_bar_items. Make sure we update both
9442 variables within BLOCK_INPUT so no such event interrupts. */
9444 f
->tool_bar_items
= new_tool_bar
;
9445 f
->n_tool_bar_items
= new_n_tool_bar
;
9446 w
->update_mode_line
= Qt
;
9452 unbind_to (count
, Qnil
);
9453 set_buffer_internal_1 (prev
);
9459 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9460 F's desired tool-bar contents. F->tool_bar_items must have
9461 been set up previously by calling prepare_menu_bars. */
9464 build_desired_tool_bar_string (f
)
9467 int i
, size
, size_needed
;
9468 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9469 Lisp_Object image
, plist
, props
;
9471 image
= plist
= props
= Qnil
;
9472 GCPRO3 (image
, plist
, props
);
9474 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9475 Otherwise, make a new string. */
9477 /* The size of the string we might be able to reuse. */
9478 size
= (STRINGP (f
->desired_tool_bar_string
)
9479 ? SCHARS (f
->desired_tool_bar_string
)
9482 /* We need one space in the string for each image. */
9483 size_needed
= f
->n_tool_bar_items
;
9485 /* Reuse f->desired_tool_bar_string, if possible. */
9486 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9487 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9491 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9492 Fremove_text_properties (make_number (0), make_number (size
),
9493 props
, f
->desired_tool_bar_string
);
9496 /* Put a `display' property on the string for the images to display,
9497 put a `menu_item' property on tool-bar items with a value that
9498 is the index of the item in F's tool-bar item vector. */
9499 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9501 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9503 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9504 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9505 int hmargin
, vmargin
, relief
, idx
, end
;
9506 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9508 /* If image is a vector, choose the image according to the
9510 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9511 if (VECTORP (image
))
9515 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9516 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9519 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9520 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9522 xassert (ASIZE (image
) >= idx
);
9523 image
= AREF (image
, idx
);
9528 /* Ignore invalid image specifications. */
9529 if (!valid_image_p (image
))
9532 /* Display the tool-bar button pressed, or depressed. */
9533 plist
= Fcopy_sequence (XCDR (image
));
9535 /* Compute margin and relief to draw. */
9536 relief
= (tool_bar_button_relief
>= 0
9537 ? tool_bar_button_relief
9538 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9539 hmargin
= vmargin
= relief
;
9541 if (INTEGERP (Vtool_bar_button_margin
)
9542 && XINT (Vtool_bar_button_margin
) > 0)
9544 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9545 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9547 else if (CONSP (Vtool_bar_button_margin
))
9549 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9550 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9551 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9553 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9554 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9555 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9558 if (auto_raise_tool_bar_buttons_p
)
9560 /* Add a `:relief' property to the image spec if the item is
9564 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9571 /* If image is selected, display it pressed, i.e. with a
9572 negative relief. If it's not selected, display it with a
9574 plist
= Fplist_put (plist
, QCrelief
,
9576 ? make_number (-relief
)
9577 : make_number (relief
)));
9582 /* Put a margin around the image. */
9583 if (hmargin
|| vmargin
)
9585 if (hmargin
== vmargin
)
9586 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9588 plist
= Fplist_put (plist
, QCmargin
,
9589 Fcons (make_number (hmargin
),
9590 make_number (vmargin
)));
9593 /* If button is not enabled, and we don't have special images
9594 for the disabled state, make the image appear disabled by
9595 applying an appropriate algorithm to it. */
9596 if (!enabled_p
&& idx
< 0)
9597 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9599 /* Put a `display' text property on the string for the image to
9600 display. Put a `menu-item' property on the string that gives
9601 the start of this item's properties in the tool-bar items
9603 image
= Fcons (Qimage
, plist
);
9604 props
= list4 (Qdisplay
, image
,
9605 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9607 /* Let the last image hide all remaining spaces in the tool bar
9608 string. The string can be longer than needed when we reuse a
9610 if (i
+ 1 == f
->n_tool_bar_items
)
9611 end
= SCHARS (f
->desired_tool_bar_string
);
9614 Fadd_text_properties (make_number (i
), make_number (end
),
9615 props
, f
->desired_tool_bar_string
);
9623 /* Display one line of the tool-bar of frame IT->f.
9625 HEIGHT specifies the desired height of the tool-bar line.
9626 If the actual height of the glyph row is less than HEIGHT, the
9627 row's height is increased to HEIGHT, and the icons are centered
9628 vertically in the new height.
9630 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
9631 count a final empty row in case the tool-bar width exactly matches
9636 display_tool_bar_line (it
, height
)
9640 struct glyph_row
*row
= it
->glyph_row
;
9641 int max_x
= it
->last_visible_x
;
9644 prepare_desired_row (row
);
9645 row
->y
= it
->current_y
;
9647 /* Note that this isn't made use of if the face hasn't a box,
9648 so there's no need to check the face here. */
9649 it
->start_of_box_run_p
= 1;
9651 while (it
->current_x
< max_x
)
9653 int x
, n_glyphs_before
, i
, nglyphs
;
9654 struct it it_before
;
9656 /* Get the next display element. */
9657 if (!get_next_display_element (it
))
9659 /* Don't count empty row if we are counting needed tool-bar lines. */
9660 if (height
< 0 && !it
->hpos
)
9665 /* Produce glyphs. */
9666 n_glyphs_before
= row
->used
[TEXT_AREA
];
9669 PRODUCE_GLYPHS (it
);
9671 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
9673 x
= it_before
.current_x
;
9676 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9678 if (x
+ glyph
->pixel_width
> max_x
)
9680 /* Glyph doesn't fit on line. Backtrack. */
9681 row
->used
[TEXT_AREA
] = n_glyphs_before
;
9683 /* If this is the only glyph on this line, it will never fit on the
9684 toolbar, so skip it. But ensure there is at least one glyph,
9685 so we don't accidentally disable the tool-bar. */
9686 if (n_glyphs_before
== 0
9687 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
9693 x
+= glyph
->pixel_width
;
9697 /* Stop at line ends. */
9698 if (ITERATOR_AT_END_OF_LINE_P (it
))
9701 set_iterator_to_next (it
, 1);
9706 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9708 /* Use default face for the border below the tool bar.
9710 FIXME: When auto-resize-tool-bars is grow-only, there is
9711 no additional border below the possibly empty tool-bar lines.
9712 So to make the extra empty lines look "normal", we have to
9713 use the tool-bar face for the border too. */
9714 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
9715 it
->face_id
= DEFAULT_FACE_ID
;
9717 extend_face_to_end_of_line (it
);
9718 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9719 last
->right_box_line_p
= 1;
9720 if (last
== row
->glyphs
[TEXT_AREA
])
9721 last
->left_box_line_p
= 1;
9723 /* Make line the desired height and center it vertically. */
9724 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
9726 /* Don't add more than one line height. */
9727 height
%= FRAME_LINE_HEIGHT (it
->f
);
9728 it
->max_ascent
+= height
/ 2;
9729 it
->max_descent
+= (height
+ 1) / 2;
9732 compute_line_metrics (it
);
9734 /* If line is empty, make it occupy the rest of the tool-bar. */
9735 if (!row
->displays_text_p
)
9737 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9738 row
->visible_height
= row
->height
;
9739 row
->ascent
= row
->phys_ascent
= 0;
9740 row
->extra_line_spacing
= 0;
9743 row
->full_width_p
= 1;
9744 row
->continued_p
= 0;
9745 row
->truncated_on_left_p
= 0;
9746 row
->truncated_on_right_p
= 0;
9748 it
->current_x
= it
->hpos
= 0;
9749 it
->current_y
+= row
->height
;
9755 /* Max tool-bar height. */
9757 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
9758 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
9760 /* Value is the number of screen lines needed to make all tool-bar
9761 items of frame F visible. The number of actual rows needed is
9762 returned in *N_ROWS if non-NULL. */
9765 tool_bar_lines_needed (f
, n_rows
)
9769 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9771 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
9772 the desired matrix, so use (unused) mode-line row as temporary row to
9773 avoid destroying the first tool-bar row. */
9774 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
9776 /* Initialize an iterator for iteration over
9777 F->desired_tool_bar_string in the tool-bar window of frame F. */
9778 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
9779 it
.first_visible_x
= 0;
9780 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9781 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9783 while (!ITERATOR_AT_END_P (&it
))
9785 clear_glyph_row (temp_row
);
9786 it
.glyph_row
= temp_row
;
9787 display_tool_bar_line (&it
, -1);
9789 clear_glyph_row (temp_row
);
9791 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
9793 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
9795 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9799 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9801 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9810 frame
= selected_frame
;
9812 CHECK_FRAME (frame
);
9815 if (WINDOWP (f
->tool_bar_window
)
9816 || (w
= XWINDOW (f
->tool_bar_window
),
9817 WINDOW_TOTAL_LINES (w
) > 0))
9819 update_tool_bar (f
, 1);
9820 if (f
->n_tool_bar_items
)
9822 build_desired_tool_bar_string (f
);
9823 nlines
= tool_bar_lines_needed (f
, NULL
);
9827 return make_number (nlines
);
9831 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9832 height should be changed. */
9835 redisplay_tool_bar (f
)
9840 struct glyph_row
*row
;
9843 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9844 update_frame_tool_bar (f
);
9848 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9849 do anything. This means you must start with tool-bar-lines
9850 non-zero to get the auto-sizing effect. Or in other words, you
9851 can turn off tool-bars by specifying tool-bar-lines zero. */
9852 if (!WINDOWP (f
->tool_bar_window
)
9853 || (w
= XWINDOW (f
->tool_bar_window
),
9854 WINDOW_TOTAL_LINES (w
) == 0))
9857 /* Set up an iterator for the tool-bar window. */
9858 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9859 it
.first_visible_x
= 0;
9860 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9863 /* Build a string that represents the contents of the tool-bar. */
9864 build_desired_tool_bar_string (f
);
9865 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9867 if (f
->n_tool_bar_rows
== 0)
9871 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
9872 nlines
!= WINDOW_TOTAL_LINES (w
)))
9874 extern Lisp_Object Qtool_bar_lines
;
9876 int old_height
= WINDOW_TOTAL_LINES (w
);
9878 XSETFRAME (frame
, f
);
9879 Fmodify_frame_parameters (frame
,
9880 Fcons (Fcons (Qtool_bar_lines
,
9881 make_number (nlines
)),
9883 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9885 clear_glyph_matrix (w
->desired_matrix
);
9886 fonts_changed_p
= 1;
9892 /* Display as many lines as needed to display all tool-bar items. */
9894 if (f
->n_tool_bar_rows
> 0)
9896 int border
, rows
, height
, extra
;
9898 if (INTEGERP (Vtool_bar_border
))
9899 border
= XINT (Vtool_bar_border
);
9900 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
9901 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
9902 else if (EQ (Vtool_bar_border
, Qborder_width
))
9903 border
= f
->border_width
;
9909 rows
= f
->n_tool_bar_rows
;
9910 height
= max (1, (it
.last_visible_y
- border
) / rows
);
9911 extra
= it
.last_visible_y
- border
- height
* rows
;
9913 while (it
.current_y
< it
.last_visible_y
)
9916 if (extra
> 0 && rows
-- > 0)
9918 h
= (extra
+ rows
- 1) / rows
;
9921 display_tool_bar_line (&it
, height
+ h
);
9926 while (it
.current_y
< it
.last_visible_y
)
9927 display_tool_bar_line (&it
, 0);
9930 /* It doesn't make much sense to try scrolling in the tool-bar
9931 window, so don't do it. */
9932 w
->desired_matrix
->no_scrolling_p
= 1;
9933 w
->must_be_updated_p
= 1;
9935 if (!NILP (Vauto_resize_tool_bars
))
9937 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
9938 int change_height_p
= 0;
9940 /* If we couldn't display everything, change the tool-bar's
9941 height if there is room for more. */
9942 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
9943 && it
.current_y
< max_tool_bar_height
)
9944 change_height_p
= 1;
9946 row
= it
.glyph_row
- 1;
9948 /* If there are blank lines at the end, except for a partially
9949 visible blank line at the end that is smaller than
9950 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9951 if (!row
->displays_text_p
9952 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9953 change_height_p
= 1;
9955 /* If row displays tool-bar items, but is partially visible,
9956 change the tool-bar's height. */
9957 if (row
->displays_text_p
9958 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
9959 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
9960 change_height_p
= 1;
9962 /* Resize windows as needed by changing the `tool-bar-lines'
9964 if (change_height_p
)
9966 extern Lisp_Object Qtool_bar_lines
;
9968 int old_height
= WINDOW_TOTAL_LINES (w
);
9970 int nlines
= tool_bar_lines_needed (f
, &nrows
);
9972 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
9973 && !f
->minimize_tool_bar_window_p
)
9974 ? (nlines
> old_height
)
9975 : (nlines
!= old_height
));
9976 f
->minimize_tool_bar_window_p
= 0;
9978 if (change_height_p
)
9980 XSETFRAME (frame
, f
);
9981 Fmodify_frame_parameters (frame
,
9982 Fcons (Fcons (Qtool_bar_lines
,
9983 make_number (nlines
)),
9985 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9987 clear_glyph_matrix (w
->desired_matrix
);
9988 f
->n_tool_bar_rows
= nrows
;
9989 fonts_changed_p
= 1;
9996 f
->minimize_tool_bar_window_p
= 0;
10001 /* Get information about the tool-bar item which is displayed in GLYPH
10002 on frame F. Return in *PROP_IDX the index where tool-bar item
10003 properties start in F->tool_bar_items. Value is zero if
10004 GLYPH doesn't display a tool-bar item. */
10007 tool_bar_item_info (f
, glyph
, prop_idx
)
10009 struct glyph
*glyph
;
10016 /* This function can be called asynchronously, which means we must
10017 exclude any possibility that Fget_text_property signals an
10019 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10020 charpos
= max (0, charpos
);
10022 /* Get the text property `menu-item' at pos. The value of that
10023 property is the start index of this item's properties in
10024 F->tool_bar_items. */
10025 prop
= Fget_text_property (make_number (charpos
),
10026 Qmenu_item
, f
->current_tool_bar_string
);
10027 if (INTEGERP (prop
))
10029 *prop_idx
= XINT (prop
);
10039 /* Get information about the tool-bar item at position X/Y on frame F.
10040 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10041 the current matrix of the tool-bar window of F, or NULL if not
10042 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10043 item in F->tool_bar_items. Value is
10045 -1 if X/Y is not on a tool-bar item
10046 0 if X/Y is on the same item that was highlighted before.
10050 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10053 struct glyph
**glyph
;
10054 int *hpos
, *vpos
, *prop_idx
;
10056 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10057 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10060 /* Find the glyph under X/Y. */
10061 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10062 if (*glyph
== NULL
)
10065 /* Get the start of this tool-bar item's properties in
10066 f->tool_bar_items. */
10067 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10070 /* Is mouse on the highlighted item? */
10071 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10072 && *vpos
>= dpyinfo
->mouse_face_beg_row
10073 && *vpos
<= dpyinfo
->mouse_face_end_row
10074 && (*vpos
> dpyinfo
->mouse_face_beg_row
10075 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10076 && (*vpos
< dpyinfo
->mouse_face_end_row
10077 || *hpos
< dpyinfo
->mouse_face_end_col
10078 || dpyinfo
->mouse_face_past_end
))
10086 Handle mouse button event on the tool-bar of frame F, at
10087 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10088 0 for button release. MODIFIERS is event modifiers for button
10092 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10095 unsigned int modifiers
;
10097 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10098 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10099 int hpos
, vpos
, prop_idx
;
10100 struct glyph
*glyph
;
10101 Lisp_Object enabled_p
;
10103 /* If not on the highlighted tool-bar item, return. */
10104 frame_to_window_pixel_xy (w
, &x
, &y
);
10105 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10108 /* If item is disabled, do nothing. */
10109 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10110 if (NILP (enabled_p
))
10115 /* Show item in pressed state. */
10116 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10117 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10118 last_tool_bar_item
= prop_idx
;
10122 Lisp_Object key
, frame
;
10123 struct input_event event
;
10124 EVENT_INIT (event
);
10126 /* Show item in released state. */
10127 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10128 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10130 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10132 XSETFRAME (frame
, f
);
10133 event
.kind
= TOOL_BAR_EVENT
;
10134 event
.frame_or_window
= frame
;
10136 kbd_buffer_store_event (&event
);
10138 event
.kind
= TOOL_BAR_EVENT
;
10139 event
.frame_or_window
= frame
;
10141 event
.modifiers
= modifiers
;
10142 kbd_buffer_store_event (&event
);
10143 last_tool_bar_item
= -1;
10148 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10149 tool-bar window-relative coordinates X/Y. Called from
10150 note_mouse_highlight. */
10153 note_tool_bar_highlight (f
, x
, y
)
10157 Lisp_Object window
= f
->tool_bar_window
;
10158 struct window
*w
= XWINDOW (window
);
10159 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10161 struct glyph
*glyph
;
10162 struct glyph_row
*row
;
10164 Lisp_Object enabled_p
;
10166 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10167 int mouse_down_p
, rc
;
10169 /* Function note_mouse_highlight is called with negative x(y
10170 values when mouse moves outside of the frame. */
10171 if (x
<= 0 || y
<= 0)
10173 clear_mouse_face (dpyinfo
);
10177 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10180 /* Not on tool-bar item. */
10181 clear_mouse_face (dpyinfo
);
10185 /* On same tool-bar item as before. */
10186 goto set_help_echo
;
10188 clear_mouse_face (dpyinfo
);
10190 /* Mouse is down, but on different tool-bar item? */
10191 mouse_down_p
= (dpyinfo
->grabbed
10192 && f
== last_mouse_frame
10193 && FRAME_LIVE_P (f
));
10195 && last_tool_bar_item
!= prop_idx
)
10198 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10199 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10201 /* If tool-bar item is not enabled, don't highlight it. */
10202 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10203 if (!NILP (enabled_p
))
10205 /* Compute the x-position of the glyph. In front and past the
10206 image is a space. We include this in the highlighted area. */
10207 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10208 for (i
= x
= 0; i
< hpos
; ++i
)
10209 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10211 /* Record this as the current active region. */
10212 dpyinfo
->mouse_face_beg_col
= hpos
;
10213 dpyinfo
->mouse_face_beg_row
= vpos
;
10214 dpyinfo
->mouse_face_beg_x
= x
;
10215 dpyinfo
->mouse_face_beg_y
= row
->y
;
10216 dpyinfo
->mouse_face_past_end
= 0;
10218 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10219 dpyinfo
->mouse_face_end_row
= vpos
;
10220 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10221 dpyinfo
->mouse_face_end_y
= row
->y
;
10222 dpyinfo
->mouse_face_window
= window
;
10223 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10225 /* Display it as active. */
10226 show_mouse_face (dpyinfo
, draw
);
10227 dpyinfo
->mouse_face_image_state
= draw
;
10232 /* Set help_echo_string to a help string to display for this tool-bar item.
10233 XTread_socket does the rest. */
10234 help_echo_object
= help_echo_window
= Qnil
;
10235 help_echo_pos
= -1;
10236 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10237 if (NILP (help_echo_string
))
10238 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10241 #endif /* HAVE_WINDOW_SYSTEM */
10245 /************************************************************************
10246 Horizontal scrolling
10247 ************************************************************************/
10249 static int hscroll_window_tree
P_ ((Lisp_Object
));
10250 static int hscroll_windows
P_ ((Lisp_Object
));
10252 /* For all leaf windows in the window tree rooted at WINDOW, set their
10253 hscroll value so that PT is (i) visible in the window, and (ii) so
10254 that it is not within a certain margin at the window's left and
10255 right border. Value is non-zero if any window's hscroll has been
10259 hscroll_window_tree (window
)
10260 Lisp_Object window
;
10262 int hscrolled_p
= 0;
10263 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10264 int hscroll_step_abs
= 0;
10265 double hscroll_step_rel
= 0;
10267 if (hscroll_relative_p
)
10269 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10270 if (hscroll_step_rel
< 0)
10272 hscroll_relative_p
= 0;
10273 hscroll_step_abs
= 0;
10276 else if (INTEGERP (Vhscroll_step
))
10278 hscroll_step_abs
= XINT (Vhscroll_step
);
10279 if (hscroll_step_abs
< 0)
10280 hscroll_step_abs
= 0;
10283 hscroll_step_abs
= 0;
10285 while (WINDOWP (window
))
10287 struct window
*w
= XWINDOW (window
);
10289 if (WINDOWP (w
->hchild
))
10290 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10291 else if (WINDOWP (w
->vchild
))
10292 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10293 else if (w
->cursor
.vpos
>= 0)
10296 int text_area_width
;
10297 struct glyph_row
*current_cursor_row
10298 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10299 struct glyph_row
*desired_cursor_row
10300 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10301 struct glyph_row
*cursor_row
10302 = (desired_cursor_row
->enabled_p
10303 ? desired_cursor_row
10304 : current_cursor_row
);
10306 text_area_width
= window_box_width (w
, TEXT_AREA
);
10308 /* Scroll when cursor is inside this scroll margin. */
10309 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10311 if ((XFASTINT (w
->hscroll
)
10312 && w
->cursor
.x
<= h_margin
)
10313 || (cursor_row
->enabled_p
10314 && cursor_row
->truncated_on_right_p
10315 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
10319 struct buffer
*saved_current_buffer
;
10323 /* Find point in a display of infinite width. */
10324 saved_current_buffer
= current_buffer
;
10325 current_buffer
= XBUFFER (w
->buffer
);
10327 if (w
== XWINDOW (selected_window
))
10328 pt
= BUF_PT (current_buffer
);
10331 pt
= marker_position (w
->pointm
);
10332 pt
= max (BEGV
, pt
);
10336 /* Move iterator to pt starting at cursor_row->start in
10337 a line with infinite width. */
10338 init_to_row_start (&it
, w
, cursor_row
);
10339 it
.last_visible_x
= INFINITY
;
10340 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10341 current_buffer
= saved_current_buffer
;
10343 /* Position cursor in window. */
10344 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10345 hscroll
= max (0, (it
.current_x
10346 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10347 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10348 : (text_area_width
/ 2))))
10349 / FRAME_COLUMN_WIDTH (it
.f
);
10350 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10352 if (hscroll_relative_p
)
10353 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10356 wanted_x
= text_area_width
10357 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10360 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10364 if (hscroll_relative_p
)
10365 wanted_x
= text_area_width
* hscroll_step_rel
10368 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10371 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10373 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10375 /* Don't call Fset_window_hscroll if value hasn't
10376 changed because it will prevent redisplay
10378 if (XFASTINT (w
->hscroll
) != hscroll
)
10380 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10381 w
->hscroll
= make_number (hscroll
);
10390 /* Value is non-zero if hscroll of any leaf window has been changed. */
10391 return hscrolled_p
;
10395 /* Set hscroll so that cursor is visible and not inside horizontal
10396 scroll margins for all windows in the tree rooted at WINDOW. See
10397 also hscroll_window_tree above. Value is non-zero if any window's
10398 hscroll has been changed. If it has, desired matrices on the frame
10399 of WINDOW are cleared. */
10402 hscroll_windows (window
)
10403 Lisp_Object window
;
10407 if (automatic_hscrolling_p
)
10409 hscrolled_p
= hscroll_window_tree (window
);
10411 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10415 return hscrolled_p
;
10420 /************************************************************************
10422 ************************************************************************/
10424 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10425 to a non-zero value. This is sometimes handy to have in a debugger
10430 /* First and last unchanged row for try_window_id. */
10432 int debug_first_unchanged_at_end_vpos
;
10433 int debug_last_unchanged_at_beg_vpos
;
10435 /* Delta vpos and y. */
10437 int debug_dvpos
, debug_dy
;
10439 /* Delta in characters and bytes for try_window_id. */
10441 int debug_delta
, debug_delta_bytes
;
10443 /* Values of window_end_pos and window_end_vpos at the end of
10446 EMACS_INT debug_end_pos
, debug_end_vpos
;
10448 /* Append a string to W->desired_matrix->method. FMT is a printf
10449 format string. A1...A9 are a supplement for a variable-length
10450 argument list. If trace_redisplay_p is non-zero also printf the
10451 resulting string to stderr. */
10454 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10457 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10460 char *method
= w
->desired_matrix
->method
;
10461 int len
= strlen (method
);
10462 int size
= sizeof w
->desired_matrix
->method
;
10463 int remaining
= size
- len
- 1;
10465 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10466 if (len
&& remaining
)
10469 --remaining
, ++len
;
10472 strncpy (method
+ len
, buffer
, remaining
);
10474 if (trace_redisplay_p
)
10475 fprintf (stderr
, "%p (%s): %s\n",
10477 ((BUFFERP (w
->buffer
)
10478 && STRINGP (XBUFFER (w
->buffer
)->name
))
10479 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10484 #endif /* GLYPH_DEBUG */
10487 /* Value is non-zero if all changes in window W, which displays
10488 current_buffer, are in the text between START and END. START is a
10489 buffer position, END is given as a distance from Z. Used in
10490 redisplay_internal for display optimization. */
10493 text_outside_line_unchanged_p (w
, start
, end
)
10497 int unchanged_p
= 1;
10499 /* If text or overlays have changed, see where. */
10500 if (XFASTINT (w
->last_modified
) < MODIFF
10501 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10503 /* Gap in the line? */
10504 if (GPT
< start
|| Z
- GPT
< end
)
10507 /* Changes start in front of the line, or end after it? */
10509 && (BEG_UNCHANGED
< start
- 1
10510 || END_UNCHANGED
< end
))
10513 /* If selective display, can't optimize if changes start at the
10514 beginning of the line. */
10516 && INTEGERP (current_buffer
->selective_display
)
10517 && XINT (current_buffer
->selective_display
) > 0
10518 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10521 /* If there are overlays at the start or end of the line, these
10522 may have overlay strings with newlines in them. A change at
10523 START, for instance, may actually concern the display of such
10524 overlay strings as well, and they are displayed on different
10525 lines. So, quickly rule out this case. (For the future, it
10526 might be desirable to implement something more telling than
10527 just BEG/END_UNCHANGED.) */
10530 if (BEG
+ BEG_UNCHANGED
== start
10531 && overlay_touches_p (start
))
10533 if (END_UNCHANGED
== end
10534 && overlay_touches_p (Z
- end
))
10539 return unchanged_p
;
10543 /* Do a frame update, taking possible shortcuts into account. This is
10544 the main external entry point for redisplay.
10546 If the last redisplay displayed an echo area message and that message
10547 is no longer requested, we clear the echo area or bring back the
10548 mini-buffer if that is in use. */
10553 redisplay_internal (0);
10558 overlay_arrow_string_or_property (var
)
10563 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10566 return Voverlay_arrow_string
;
10569 /* Return 1 if there are any overlay-arrows in current_buffer. */
10571 overlay_arrow_in_current_buffer_p ()
10575 for (vlist
= Voverlay_arrow_variable_list
;
10577 vlist
= XCDR (vlist
))
10579 Lisp_Object var
= XCAR (vlist
);
10582 if (!SYMBOLP (var
))
10584 val
= find_symbol_value (var
);
10586 && current_buffer
== XMARKER (val
)->buffer
)
10593 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
10597 overlay_arrows_changed_p ()
10601 for (vlist
= Voverlay_arrow_variable_list
;
10603 vlist
= XCDR (vlist
))
10605 Lisp_Object var
= XCAR (vlist
);
10606 Lisp_Object val
, pstr
;
10608 if (!SYMBOLP (var
))
10610 val
= find_symbol_value (var
);
10611 if (!MARKERP (val
))
10613 if (! EQ (COERCE_MARKER (val
),
10614 Fget (var
, Qlast_arrow_position
))
10615 || ! (pstr
= overlay_arrow_string_or_property (var
),
10616 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
10622 /* Mark overlay arrows to be updated on next redisplay. */
10625 update_overlay_arrows (up_to_date
)
10630 for (vlist
= Voverlay_arrow_variable_list
;
10632 vlist
= XCDR (vlist
))
10634 Lisp_Object var
= XCAR (vlist
);
10636 if (!SYMBOLP (var
))
10639 if (up_to_date
> 0)
10641 Lisp_Object val
= find_symbol_value (var
);
10642 Fput (var
, Qlast_arrow_position
,
10643 COERCE_MARKER (val
));
10644 Fput (var
, Qlast_arrow_string
,
10645 overlay_arrow_string_or_property (var
));
10647 else if (up_to_date
< 0
10648 || !NILP (Fget (var
, Qlast_arrow_position
)))
10650 Fput (var
, Qlast_arrow_position
, Qt
);
10651 Fput (var
, Qlast_arrow_string
, Qt
);
10657 /* Return overlay arrow string to display at row.
10658 Return integer (bitmap number) for arrow bitmap in left fringe.
10659 Return nil if no overlay arrow. */
10662 overlay_arrow_at_row (it
, row
)
10664 struct glyph_row
*row
;
10668 for (vlist
= Voverlay_arrow_variable_list
;
10670 vlist
= XCDR (vlist
))
10672 Lisp_Object var
= XCAR (vlist
);
10675 if (!SYMBOLP (var
))
10678 val
= find_symbol_value (var
);
10681 && current_buffer
== XMARKER (val
)->buffer
10682 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10684 if (FRAME_WINDOW_P (it
->f
)
10685 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10687 #ifdef HAVE_WINDOW_SYSTEM
10688 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10691 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10692 return make_number (fringe_bitmap
);
10695 return make_number (-1); /* Use default arrow bitmap */
10697 return overlay_arrow_string_or_property (var
);
10704 /* Return 1 if point moved out of or into a composition. Otherwise
10705 return 0. PREV_BUF and PREV_PT are the last point buffer and
10706 position. BUF and PT are the current point buffer and position. */
10709 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10710 struct buffer
*prev_buf
, *buf
;
10715 Lisp_Object buffer
;
10717 XSETBUFFER (buffer
, buf
);
10718 /* Check a composition at the last point if point moved within the
10720 if (prev_buf
== buf
)
10723 /* Point didn't move. */
10726 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10727 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10728 && COMPOSITION_VALID_P (start
, end
, prop
)
10729 && start
< prev_pt
&& end
> prev_pt
)
10730 /* The last point was within the composition. Return 1 iff
10731 point moved out of the composition. */
10732 return (pt
<= start
|| pt
>= end
);
10735 /* Check a composition at the current point. */
10736 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10737 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10738 && COMPOSITION_VALID_P (start
, end
, prop
)
10739 && start
< pt
&& end
> pt
);
10743 /* Reconsider the setting of B->clip_changed which is displayed
10747 reconsider_clip_changes (w
, b
)
10751 if (b
->clip_changed
10752 && !NILP (w
->window_end_valid
)
10753 && w
->current_matrix
->buffer
== b
10754 && w
->current_matrix
->zv
== BUF_ZV (b
)
10755 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10756 b
->clip_changed
= 0;
10758 /* If display wasn't paused, and W is not a tool bar window, see if
10759 point has been moved into or out of a composition. In that case,
10760 we set b->clip_changed to 1 to force updating the screen. If
10761 b->clip_changed has already been set to 1, we can skip this
10763 if (!b
->clip_changed
10764 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10768 if (w
== XWINDOW (selected_window
))
10769 pt
= BUF_PT (current_buffer
);
10771 pt
= marker_position (w
->pointm
);
10773 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10774 || pt
!= XINT (w
->last_point
))
10775 && check_point_in_composition (w
->current_matrix
->buffer
,
10776 XINT (w
->last_point
),
10777 XBUFFER (w
->buffer
), pt
))
10778 b
->clip_changed
= 1;
10783 /* Select FRAME to forward the values of frame-local variables into C
10784 variables so that the redisplay routines can access those values
10788 select_frame_for_redisplay (frame
)
10791 Lisp_Object tail
, sym
, val
;
10792 Lisp_Object old
= selected_frame
;
10794 selected_frame
= frame
;
10796 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10797 if (CONSP (XCAR (tail
))
10798 && (sym
= XCAR (XCAR (tail
)),
10800 && (sym
= indirect_variable (sym
),
10801 val
= SYMBOL_VALUE (sym
),
10802 (BUFFER_LOCAL_VALUEP (val
)
10803 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10804 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10805 /* Use find_symbol_value rather than Fsymbol_value
10806 to avoid an error if it is void. */
10807 find_symbol_value (sym
);
10809 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10810 if (CONSP (XCAR (tail
))
10811 && (sym
= XCAR (XCAR (tail
)),
10813 && (sym
= indirect_variable (sym
),
10814 val
= SYMBOL_VALUE (sym
),
10815 (BUFFER_LOCAL_VALUEP (val
)
10816 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10817 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10818 find_symbol_value (sym
);
10822 #define STOP_POLLING \
10823 do { if (! polling_stopped_here) stop_polling (); \
10824 polling_stopped_here = 1; } while (0)
10826 #define RESUME_POLLING \
10827 do { if (polling_stopped_here) start_polling (); \
10828 polling_stopped_here = 0; } while (0)
10831 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10832 response to any user action; therefore, we should preserve the echo
10833 area. (Actually, our caller does that job.) Perhaps in the future
10834 avoid recentering windows if it is not necessary; currently that
10835 causes some problems. */
10838 redisplay_internal (preserve_echo_area
)
10839 int preserve_echo_area
;
10841 struct window
*w
= XWINDOW (selected_window
);
10844 int must_finish
= 0;
10845 struct text_pos tlbufpos
, tlendpos
;
10846 int number_of_visible_frames
;
10849 int polling_stopped_here
= 0;
10851 /* Non-zero means redisplay has to consider all windows on all
10852 frames. Zero means, only selected_window is considered. */
10853 int consider_all_windows_p
;
10855 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10857 /* No redisplay if running in batch mode or frame is not yet fully
10858 initialized, or redisplay is explicitly turned off by setting
10859 Vinhibit_redisplay. */
10861 || !NILP (Vinhibit_redisplay
))
10864 /* Don't examine these until after testing Vinhibit_redisplay.
10865 When Emacs is shutting down, perhaps because its connection to
10866 X has dropped, we should not look at them at all. */
10867 f
= XFRAME (w
->frame
);
10868 sf
= SELECTED_FRAME ();
10870 if (!f
->glyphs_initialized_p
)
10873 /* The flag redisplay_performed_directly_p is set by
10874 direct_output_for_insert when it already did the whole screen
10875 update necessary. */
10876 if (redisplay_performed_directly_p
)
10878 redisplay_performed_directly_p
= 0;
10879 if (!hscroll_windows (selected_window
))
10883 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (MAC_OS)
10884 if (popup_activated ())
10888 /* I don't think this happens but let's be paranoid. */
10889 if (redisplaying_p
)
10892 /* Record a function that resets redisplaying_p to its old value
10893 when we leave this function. */
10894 count
= SPECPDL_INDEX ();
10895 record_unwind_protect (unwind_redisplay
,
10896 Fcons (make_number (redisplaying_p
), selected_frame
));
10898 specbind (Qinhibit_free_realized_faces
, Qnil
);
10901 Lisp_Object tail
, frame
;
10903 FOR_EACH_FRAME (tail
, frame
)
10905 struct frame
*f
= XFRAME (frame
);
10906 f
->already_hscrolled_p
= 0;
10912 reconsider_clip_changes (w
, current_buffer
);
10913 last_escape_glyph_frame
= NULL
;
10914 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
10916 /* If new fonts have been loaded that make a glyph matrix adjustment
10917 necessary, do it. */
10918 if (fonts_changed_p
)
10920 adjust_glyphs (NULL
);
10921 ++windows_or_buffers_changed
;
10922 fonts_changed_p
= 0;
10925 /* If face_change_count is non-zero, init_iterator will free all
10926 realized faces, which includes the faces referenced from current
10927 matrices. So, we can't reuse current matrices in this case. */
10928 if (face_change_count
)
10929 ++windows_or_buffers_changed
;
10931 if (! FRAME_WINDOW_P (sf
)
10932 && previous_terminal_frame
!= sf
)
10934 /* Since frames on an ASCII terminal share the same display
10935 area, displaying a different frame means redisplay the whole
10937 windows_or_buffers_changed
++;
10938 SET_FRAME_GARBAGED (sf
);
10939 XSETFRAME (Vterminal_frame
, sf
);
10941 previous_terminal_frame
= sf
;
10943 /* Set the visible flags for all frames. Do this before checking
10944 for resized or garbaged frames; they want to know if their frames
10945 are visible. See the comment in frame.h for
10946 FRAME_SAMPLE_VISIBILITY. */
10948 Lisp_Object tail
, frame
;
10950 number_of_visible_frames
= 0;
10952 FOR_EACH_FRAME (tail
, frame
)
10954 struct frame
*f
= XFRAME (frame
);
10956 FRAME_SAMPLE_VISIBILITY (f
);
10957 if (FRAME_VISIBLE_P (f
))
10958 ++number_of_visible_frames
;
10959 clear_desired_matrices (f
);
10963 /* Notice any pending interrupt request to change frame size. */
10964 do_pending_window_change (1);
10966 /* Clear frames marked as garbaged. */
10967 if (frame_garbaged
)
10968 clear_garbaged_frames ();
10970 /* Build menubar and tool-bar items. */
10971 if (NILP (Vmemory_full
))
10972 prepare_menu_bars ();
10974 if (windows_or_buffers_changed
)
10975 update_mode_lines
++;
10977 /* Detect case that we need to write or remove a star in the mode line. */
10978 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10980 w
->update_mode_line
= Qt
;
10981 if (buffer_shared
> 1)
10982 update_mode_lines
++;
10985 /* Avoid invocation of point motion hooks by `current_column' below. */
10986 count1
= SPECPDL_INDEX ();
10987 specbind (Qinhibit_point_motion_hooks
, Qt
);
10989 /* If %c is in the mode line, update it if needed. */
10990 if (!NILP (w
->column_number_displayed
)
10991 /* This alternative quickly identifies a common case
10992 where no change is needed. */
10993 && !(PT
== XFASTINT (w
->last_point
)
10994 && XFASTINT (w
->last_modified
) >= MODIFF
10995 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10996 && (XFASTINT (w
->column_number_displayed
)
10997 != (int) current_column ())) /* iftc */
10998 w
->update_mode_line
= Qt
;
11000 unbind_to (count1
, Qnil
);
11002 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11004 /* The variable buffer_shared is set in redisplay_window and
11005 indicates that we redisplay a buffer in different windows. See
11007 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11008 || cursor_type_changed
);
11010 /* If specs for an arrow have changed, do thorough redisplay
11011 to ensure we remove any arrow that should no longer exist. */
11012 if (overlay_arrows_changed_p ())
11013 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11015 /* Normally the message* functions will have already displayed and
11016 updated the echo area, but the frame may have been trashed, or
11017 the update may have been preempted, so display the echo area
11018 again here. Checking message_cleared_p captures the case that
11019 the echo area should be cleared. */
11020 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11021 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11022 || (message_cleared_p
11023 && minibuf_level
== 0
11024 /* If the mini-window is currently selected, this means the
11025 echo-area doesn't show through. */
11026 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11028 int window_height_changed_p
= echo_area_display (0);
11031 /* If we don't display the current message, don't clear the
11032 message_cleared_p flag, because, if we did, we wouldn't clear
11033 the echo area in the next redisplay which doesn't preserve
11035 if (!display_last_displayed_message_p
)
11036 message_cleared_p
= 0;
11038 if (fonts_changed_p
)
11040 else if (window_height_changed_p
)
11042 consider_all_windows_p
= 1;
11043 ++update_mode_lines
;
11044 ++windows_or_buffers_changed
;
11046 /* If window configuration was changed, frames may have been
11047 marked garbaged. Clear them or we will experience
11048 surprises wrt scrolling. */
11049 if (frame_garbaged
)
11050 clear_garbaged_frames ();
11053 else if (EQ (selected_window
, minibuf_window
)
11054 && (current_buffer
->clip_changed
11055 || XFASTINT (w
->last_modified
) < MODIFF
11056 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11057 && resize_mini_window (w
, 0))
11059 /* Resized active mini-window to fit the size of what it is
11060 showing if its contents might have changed. */
11062 consider_all_windows_p
= 1;
11063 ++windows_or_buffers_changed
;
11064 ++update_mode_lines
;
11066 /* If window configuration was changed, frames may have been
11067 marked garbaged. Clear them or we will experience
11068 surprises wrt scrolling. */
11069 if (frame_garbaged
)
11070 clear_garbaged_frames ();
11074 /* If showing the region, and mark has changed, we must redisplay
11075 the whole window. The assignment to this_line_start_pos prevents
11076 the optimization directly below this if-statement. */
11077 if (((!NILP (Vtransient_mark_mode
)
11078 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11079 != !NILP (w
->region_showing
))
11080 || (!NILP (w
->region_showing
)
11081 && !EQ (w
->region_showing
,
11082 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11083 CHARPOS (this_line_start_pos
) = 0;
11085 /* Optimize the case that only the line containing the cursor in the
11086 selected window has changed. Variables starting with this_ are
11087 set in display_line and record information about the line
11088 containing the cursor. */
11089 tlbufpos
= this_line_start_pos
;
11090 tlendpos
= this_line_end_pos
;
11091 if (!consider_all_windows_p
11092 && CHARPOS (tlbufpos
) > 0
11093 && NILP (w
->update_mode_line
)
11094 && !current_buffer
->clip_changed
11095 && !current_buffer
->prevent_redisplay_optimizations_p
11096 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11097 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11098 /* Make sure recorded data applies to current buffer, etc. */
11099 && this_line_buffer
== current_buffer
11100 && current_buffer
== XBUFFER (w
->buffer
)
11101 && NILP (w
->force_start
)
11102 && NILP (w
->optional_new_start
)
11103 /* Point must be on the line that we have info recorded about. */
11104 && PT
>= CHARPOS (tlbufpos
)
11105 && PT
<= Z
- CHARPOS (tlendpos
)
11106 /* All text outside that line, including its final newline,
11107 must be unchanged */
11108 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11109 CHARPOS (tlendpos
)))
11111 if (CHARPOS (tlbufpos
) > BEGV
11112 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11113 && (CHARPOS (tlbufpos
) == ZV
11114 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11115 /* Former continuation line has disappeared by becoming empty */
11117 else if (XFASTINT (w
->last_modified
) < MODIFF
11118 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11119 || MINI_WINDOW_P (w
))
11121 /* We have to handle the case of continuation around a
11122 wide-column character (See the comment in indent.c around
11125 For instance, in the following case:
11127 -------- Insert --------
11128 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11129 J_I_ ==> J_I_ `^^' are cursors.
11133 As we have to redraw the line above, we should goto cancel. */
11136 int line_height_before
= this_line_pixel_height
;
11138 /* Note that start_display will handle the case that the
11139 line starting at tlbufpos is a continuation lines. */
11140 start_display (&it
, w
, tlbufpos
);
11142 /* Implementation note: It this still necessary? */
11143 if (it
.current_x
!= this_line_start_x
)
11146 TRACE ((stderr
, "trying display optimization 1\n"));
11147 w
->cursor
.vpos
= -1;
11148 overlay_arrow_seen
= 0;
11149 it
.vpos
= this_line_vpos
;
11150 it
.current_y
= this_line_y
;
11151 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11152 display_line (&it
);
11154 /* If line contains point, is not continued,
11155 and ends at same distance from eob as before, we win */
11156 if (w
->cursor
.vpos
>= 0
11157 /* Line is not continued, otherwise this_line_start_pos
11158 would have been set to 0 in display_line. */
11159 && CHARPOS (this_line_start_pos
)
11160 /* Line ends as before. */
11161 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11162 /* Line has same height as before. Otherwise other lines
11163 would have to be shifted up or down. */
11164 && this_line_pixel_height
== line_height_before
)
11166 /* If this is not the window's last line, we must adjust
11167 the charstarts of the lines below. */
11168 if (it
.current_y
< it
.last_visible_y
)
11170 struct glyph_row
*row
11171 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11172 int delta
, delta_bytes
;
11174 if (Z
- CHARPOS (tlendpos
) == ZV
)
11176 /* This line ends at end of (accessible part of)
11177 buffer. There is no newline to count. */
11179 - CHARPOS (tlendpos
)
11180 - MATRIX_ROW_START_CHARPOS (row
));
11181 delta_bytes
= (Z_BYTE
11182 - BYTEPOS (tlendpos
)
11183 - MATRIX_ROW_START_BYTEPOS (row
));
11187 /* This line ends in a newline. Must take
11188 account of the newline and the rest of the
11189 text that follows. */
11191 - CHARPOS (tlendpos
)
11192 - MATRIX_ROW_START_CHARPOS (row
));
11193 delta_bytes
= (Z_BYTE
11194 - BYTEPOS (tlendpos
)
11195 - MATRIX_ROW_START_BYTEPOS (row
));
11198 increment_matrix_positions (w
->current_matrix
,
11199 this_line_vpos
+ 1,
11200 w
->current_matrix
->nrows
,
11201 delta
, delta_bytes
);
11204 /* If this row displays text now but previously didn't,
11205 or vice versa, w->window_end_vpos may have to be
11207 if ((it
.glyph_row
- 1)->displays_text_p
)
11209 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11210 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11212 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11213 && this_line_vpos
> 0)
11214 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11215 w
->window_end_valid
= Qnil
;
11217 /* Update hint: No need to try to scroll in update_window. */
11218 w
->desired_matrix
->no_scrolling_p
= 1;
11221 *w
->desired_matrix
->method
= 0;
11222 debug_method_add (w
, "optimization 1");
11224 #ifdef HAVE_WINDOW_SYSTEM
11225 update_window_fringes (w
, 0);
11232 else if (/* Cursor position hasn't changed. */
11233 PT
== XFASTINT (w
->last_point
)
11234 /* Make sure the cursor was last displayed
11235 in this window. Otherwise we have to reposition it. */
11236 && 0 <= w
->cursor
.vpos
11237 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11241 do_pending_window_change (1);
11243 /* We used to always goto end_of_redisplay here, but this
11244 isn't enough if we have a blinking cursor. */
11245 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11246 goto end_of_redisplay
;
11250 /* If highlighting the region, or if the cursor is in the echo area,
11251 then we can't just move the cursor. */
11252 else if (! (!NILP (Vtransient_mark_mode
)
11253 && !NILP (current_buffer
->mark_active
))
11254 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11255 || highlight_nonselected_windows
)
11256 && NILP (w
->region_showing
)
11257 && NILP (Vshow_trailing_whitespace
)
11258 && !cursor_in_echo_area
)
11261 struct glyph_row
*row
;
11263 /* Skip from tlbufpos to PT and see where it is. Note that
11264 PT may be in invisible text. If so, we will end at the
11265 next visible position. */
11266 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11267 NULL
, DEFAULT_FACE_ID
);
11268 it
.current_x
= this_line_start_x
;
11269 it
.current_y
= this_line_y
;
11270 it
.vpos
= this_line_vpos
;
11272 /* The call to move_it_to stops in front of PT, but
11273 moves over before-strings. */
11274 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11276 if (it
.vpos
== this_line_vpos
11277 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11280 xassert (this_line_vpos
== it
.vpos
);
11281 xassert (this_line_y
== it
.current_y
);
11282 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11284 *w
->desired_matrix
->method
= 0;
11285 debug_method_add (w
, "optimization 3");
11294 /* Text changed drastically or point moved off of line. */
11295 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11298 CHARPOS (this_line_start_pos
) = 0;
11299 consider_all_windows_p
|= buffer_shared
> 1;
11300 ++clear_face_cache_count
;
11301 #ifdef HAVE_WINDOW_SYSTEM
11302 ++clear_image_cache_count
;
11305 /* Build desired matrices, and update the display. If
11306 consider_all_windows_p is non-zero, do it for all windows on all
11307 frames. Otherwise do it for selected_window, only. */
11309 if (consider_all_windows_p
)
11311 Lisp_Object tail
, frame
;
11313 FOR_EACH_FRAME (tail
, frame
)
11314 XFRAME (frame
)->updated_p
= 0;
11316 /* Recompute # windows showing selected buffer. This will be
11317 incremented each time such a window is displayed. */
11320 FOR_EACH_FRAME (tail
, frame
)
11322 struct frame
*f
= XFRAME (frame
);
11324 if (FRAME_WINDOW_P (f
) || f
== sf
)
11326 if (! EQ (frame
, selected_frame
))
11327 /* Select the frame, for the sake of frame-local
11329 select_frame_for_redisplay (frame
);
11331 /* Mark all the scroll bars to be removed; we'll redeem
11332 the ones we want when we redisplay their windows. */
11333 if (condemn_scroll_bars_hook
)
11334 condemn_scroll_bars_hook (f
);
11336 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11337 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11339 /* Any scroll bars which redisplay_windows should have
11340 nuked should now go away. */
11341 if (judge_scroll_bars_hook
)
11342 judge_scroll_bars_hook (f
);
11344 /* If fonts changed, display again. */
11345 /* ??? rms: I suspect it is a mistake to jump all the way
11346 back to retry here. It should just retry this frame. */
11347 if (fonts_changed_p
)
11350 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11352 /* See if we have to hscroll. */
11353 if (!f
->already_hscrolled_p
)
11355 f
->already_hscrolled_p
= 1;
11356 if (hscroll_windows (f
->root_window
))
11360 /* Prevent various kinds of signals during display
11361 update. stdio is not robust about handling
11362 signals, which can cause an apparent I/O
11364 if (interrupt_input
)
11365 unrequest_sigio ();
11368 /* Update the display. */
11369 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11370 pause
|= update_frame (f
, 0, 0);
11371 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
11383 /* Do the mark_window_display_accurate after all windows have
11384 been redisplayed because this call resets flags in buffers
11385 which are needed for proper redisplay. */
11386 FOR_EACH_FRAME (tail
, frame
)
11388 struct frame
*f
= XFRAME (frame
);
11391 mark_window_display_accurate (f
->root_window
, 1);
11392 if (frame_up_to_date_hook
)
11393 frame_up_to_date_hook (f
);
11398 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11400 Lisp_Object mini_window
;
11401 struct frame
*mini_frame
;
11403 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11404 /* Use list_of_error, not Qerror, so that
11405 we catch only errors and don't run the debugger. */
11406 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11408 redisplay_window_error
);
11410 /* Compare desired and current matrices, perform output. */
11413 /* If fonts changed, display again. */
11414 if (fonts_changed_p
)
11417 /* Prevent various kinds of signals during display update.
11418 stdio is not robust about handling signals,
11419 which can cause an apparent I/O error. */
11420 if (interrupt_input
)
11421 unrequest_sigio ();
11424 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11426 if (hscroll_windows (selected_window
))
11429 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11430 pause
= update_frame (sf
, 0, 0);
11433 /* We may have called echo_area_display at the top of this
11434 function. If the echo area is on another frame, that may
11435 have put text on a frame other than the selected one, so the
11436 above call to update_frame would not have caught it. Catch
11438 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11439 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11441 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11443 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11444 pause
|= update_frame (mini_frame
, 0, 0);
11445 if (!pause
&& hscroll_windows (mini_window
))
11450 /* If display was paused because of pending input, make sure we do a
11451 thorough update the next time. */
11454 /* Prevent the optimization at the beginning of
11455 redisplay_internal that tries a single-line update of the
11456 line containing the cursor in the selected window. */
11457 CHARPOS (this_line_start_pos
) = 0;
11459 /* Let the overlay arrow be updated the next time. */
11460 update_overlay_arrows (0);
11462 /* If we pause after scrolling, some rows in the current
11463 matrices of some windows are not valid. */
11464 if (!WINDOW_FULL_WIDTH_P (w
)
11465 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11466 update_mode_lines
= 1;
11470 if (!consider_all_windows_p
)
11472 /* This has already been done above if
11473 consider_all_windows_p is set. */
11474 mark_window_display_accurate_1 (w
, 1);
11476 /* Say overlay arrows are up to date. */
11477 update_overlay_arrows (1);
11479 if (frame_up_to_date_hook
!= 0)
11480 frame_up_to_date_hook (sf
);
11483 update_mode_lines
= 0;
11484 windows_or_buffers_changed
= 0;
11485 cursor_type_changed
= 0;
11488 /* Start SIGIO interrupts coming again. Having them off during the
11489 code above makes it less likely one will discard output, but not
11490 impossible, since there might be stuff in the system buffer here.
11491 But it is much hairier to try to do anything about that. */
11492 if (interrupt_input
)
11496 /* If a frame has become visible which was not before, redisplay
11497 again, so that we display it. Expose events for such a frame
11498 (which it gets when becoming visible) don't call the parts of
11499 redisplay constructing glyphs, so simply exposing a frame won't
11500 display anything in this case. So, we have to display these
11501 frames here explicitly. */
11504 Lisp_Object tail
, frame
;
11507 FOR_EACH_FRAME (tail
, frame
)
11509 int this_is_visible
= 0;
11511 if (XFRAME (frame
)->visible
)
11512 this_is_visible
= 1;
11513 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11514 if (XFRAME (frame
)->visible
)
11515 this_is_visible
= 1;
11517 if (this_is_visible
)
11521 if (new_count
!= number_of_visible_frames
)
11522 windows_or_buffers_changed
++;
11525 /* Change frame size now if a change is pending. */
11526 do_pending_window_change (1);
11528 /* If we just did a pending size change, or have additional
11529 visible frames, redisplay again. */
11530 if (windows_or_buffers_changed
&& !pause
)
11533 /* Clear the face cache eventually. */
11534 if (consider_all_windows_p
)
11536 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11538 clear_face_cache (0);
11539 clear_face_cache_count
= 0;
11541 #ifdef HAVE_WINDOW_SYSTEM
11542 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11544 Lisp_Object tail
, frame
;
11545 FOR_EACH_FRAME (tail
, frame
)
11547 struct frame
*f
= XFRAME (frame
);
11548 if (FRAME_WINDOW_P (f
))
11549 clear_image_cache (f
, 0);
11551 clear_image_cache_count
= 0;
11553 #endif /* HAVE_WINDOW_SYSTEM */
11557 unbind_to (count
, Qnil
);
11562 /* Redisplay, but leave alone any recent echo area message unless
11563 another message has been requested in its place.
11565 This is useful in situations where you need to redisplay but no
11566 user action has occurred, making it inappropriate for the message
11567 area to be cleared. See tracking_off and
11568 wait_reading_process_output for examples of these situations.
11570 FROM_WHERE is an integer saying from where this function was
11571 called. This is useful for debugging. */
11574 redisplay_preserve_echo_area (from_where
)
11577 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11579 if (!NILP (echo_area_buffer
[1]))
11581 /* We have a previously displayed message, but no current
11582 message. Redisplay the previous message. */
11583 display_last_displayed_message_p
= 1;
11584 redisplay_internal (1);
11585 display_last_displayed_message_p
= 0;
11588 redisplay_internal (1);
11590 if (rif
!= NULL
&& rif
->flush_display_optional
)
11591 rif
->flush_display_optional (NULL
);
11595 /* Function registered with record_unwind_protect in
11596 redisplay_internal. Reset redisplaying_p to the value it had
11597 before redisplay_internal was called, and clear
11598 prevent_freeing_realized_faces_p. It also selects the previously
11602 unwind_redisplay (val
)
11605 Lisp_Object old_redisplaying_p
, old_frame
;
11607 old_redisplaying_p
= XCAR (val
);
11608 redisplaying_p
= XFASTINT (old_redisplaying_p
);
11609 old_frame
= XCDR (val
);
11610 if (! EQ (old_frame
, selected_frame
))
11611 select_frame_for_redisplay (old_frame
);
11616 /* Mark the display of window W as accurate or inaccurate. If
11617 ACCURATE_P is non-zero mark display of W as accurate. If
11618 ACCURATE_P is zero, arrange for W to be redisplayed the next time
11619 redisplay_internal is called. */
11622 mark_window_display_accurate_1 (w
, accurate_p
)
11626 if (BUFFERP (w
->buffer
))
11628 struct buffer
*b
= XBUFFER (w
->buffer
);
11631 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
11632 w
->last_overlay_modified
11633 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
11635 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
11639 b
->clip_changed
= 0;
11640 b
->prevent_redisplay_optimizations_p
= 0;
11642 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
11643 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
11644 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
11645 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
11647 w
->current_matrix
->buffer
= b
;
11648 w
->current_matrix
->begv
= BUF_BEGV (b
);
11649 w
->current_matrix
->zv
= BUF_ZV (b
);
11651 w
->last_cursor
= w
->cursor
;
11652 w
->last_cursor_off_p
= w
->cursor_off_p
;
11654 if (w
== XWINDOW (selected_window
))
11655 w
->last_point
= make_number (BUF_PT (b
));
11657 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
11663 w
->window_end_valid
= w
->buffer
;
11664 #if 0 /* This is incorrect with variable-height lines. */
11665 xassert (XINT (w
->window_end_vpos
)
11666 < (WINDOW_TOTAL_LINES (w
)
11667 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
11669 w
->update_mode_line
= Qnil
;
11674 /* Mark the display of windows in the window tree rooted at WINDOW as
11675 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
11676 windows as accurate. If ACCURATE_P is zero, arrange for windows to
11677 be redisplayed the next time redisplay_internal is called. */
11680 mark_window_display_accurate (window
, accurate_p
)
11681 Lisp_Object window
;
11686 for (; !NILP (window
); window
= w
->next
)
11688 w
= XWINDOW (window
);
11689 mark_window_display_accurate_1 (w
, accurate_p
);
11691 if (!NILP (w
->vchild
))
11692 mark_window_display_accurate (w
->vchild
, accurate_p
);
11693 if (!NILP (w
->hchild
))
11694 mark_window_display_accurate (w
->hchild
, accurate_p
);
11699 update_overlay_arrows (1);
11703 /* Force a thorough redisplay the next time by setting
11704 last_arrow_position and last_arrow_string to t, which is
11705 unequal to any useful value of Voverlay_arrow_... */
11706 update_overlay_arrows (-1);
11711 /* Return value in display table DP (Lisp_Char_Table *) for character
11712 C. Since a display table doesn't have any parent, we don't have to
11713 follow parent. Do not call this function directly but use the
11714 macro DISP_CHAR_VECTOR. */
11717 disp_char_vector (dp
, c
)
11718 struct Lisp_Char_Table
*dp
;
11724 if (SINGLE_BYTE_CHAR_P (c
))
11725 return (dp
->contents
[c
]);
11727 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
11730 else if (code
[2] < 32)
11733 /* Here, the possible range of code[0] (== charset ID) is
11734 128..max_charset. Since the top level char table contains data
11735 for multibyte characters after 256th element, we must increment
11736 code[0] by 128 to get a correct index. */
11738 code
[3] = -1; /* anchor */
11740 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
11742 val
= dp
->contents
[code
[i
]];
11743 if (!SUB_CHAR_TABLE_P (val
))
11744 return (NILP (val
) ? dp
->defalt
: val
);
11747 /* Here, val is a sub char table. We return the default value of
11749 return (dp
->defalt
);
11754 /***********************************************************************
11756 ***********************************************************************/
11758 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11761 redisplay_windows (window
)
11762 Lisp_Object window
;
11764 while (!NILP (window
))
11766 struct window
*w
= XWINDOW (window
);
11768 if (!NILP (w
->hchild
))
11769 redisplay_windows (w
->hchild
);
11770 else if (!NILP (w
->vchild
))
11771 redisplay_windows (w
->vchild
);
11774 displayed_buffer
= XBUFFER (w
->buffer
);
11775 /* Use list_of_error, not Qerror, so that
11776 we catch only errors and don't run the debugger. */
11777 internal_condition_case_1 (redisplay_window_0
, window
,
11779 redisplay_window_error
);
11787 redisplay_window_error ()
11789 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11794 redisplay_window_0 (window
)
11795 Lisp_Object window
;
11797 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11798 redisplay_window (window
, 0);
11803 redisplay_window_1 (window
)
11804 Lisp_Object window
;
11806 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11807 redisplay_window (window
, 1);
11812 /* Increment GLYPH until it reaches END or CONDITION fails while
11813 adding (GLYPH)->pixel_width to X. */
11815 #define SKIP_GLYPHS(glyph, end, x, condition) \
11818 (x) += (glyph)->pixel_width; \
11821 while ((glyph) < (end) && (condition))
11824 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11825 DELTA is the number of bytes by which positions recorded in ROW
11826 differ from current buffer positions.
11828 Return 0 if cursor is not on this row. 1 otherwise. */
11831 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11833 struct glyph_row
*row
;
11834 struct glyph_matrix
*matrix
;
11835 int delta
, delta_bytes
, dy
, dvpos
;
11837 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11838 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11839 struct glyph
*cursor
= NULL
;
11840 /* The first glyph that starts a sequence of glyphs from string. */
11841 struct glyph
*string_start
;
11842 /* The X coordinate of string_start. */
11843 int string_start_x
;
11844 /* The last known character position. */
11845 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11846 /* The last known character position before string_start. */
11847 int string_before_pos
;
11850 int cursor_from_overlay_pos
= 0;
11851 int pt_old
= PT
- delta
;
11853 /* Skip over glyphs not having an object at the start of the row.
11854 These are special glyphs like truncation marks on terminal
11856 if (row
->displays_text_p
)
11858 && INTEGERP (glyph
->object
)
11859 && glyph
->charpos
< 0)
11861 x
+= glyph
->pixel_width
;
11865 string_start
= NULL
;
11867 && !INTEGERP (glyph
->object
)
11868 && (!BUFFERP (glyph
->object
)
11869 || (last_pos
= glyph
->charpos
) < pt_old
))
11871 if (! STRINGP (glyph
->object
))
11873 string_start
= NULL
;
11874 x
+= glyph
->pixel_width
;
11876 if (cursor_from_overlay_pos
11877 && last_pos
>= cursor_from_overlay_pos
)
11879 cursor_from_overlay_pos
= 0;
11885 if (string_start
== NULL
)
11887 string_before_pos
= last_pos
;
11888 string_start
= glyph
;
11889 string_start_x
= x
;
11891 /* Skip all glyphs from string. */
11896 if ((cursor
== NULL
|| glyph
> cursor
)
11897 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
11898 Qcursor
, (glyph
)->object
),
11900 && (pos
= string_buffer_position (w
, glyph
->object
,
11901 string_before_pos
),
11902 (pos
== 0 /* From overlay */
11903 || pos
== pt_old
)))
11905 /* Estimate overlay buffer position from the buffer
11906 positions of the glyphs before and after the overlay.
11907 Add 1 to last_pos so that if point corresponds to the
11908 glyph right after the overlay, we still use a 'cursor'
11909 property found in that overlay. */
11910 cursor_from_overlay_pos
= (pos
? 0 : last_pos
11911 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
11915 x
+= glyph
->pixel_width
;
11918 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
11922 if (cursor
!= NULL
)
11927 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
11929 /* Scan back over the ellipsis glyphs, decrementing positions. */
11930 while (glyph
> row
->glyphs
[TEXT_AREA
]
11931 && (glyph
- 1)->charpos
== last_pos
)
11932 glyph
--, x
-= glyph
->pixel_width
;
11933 /* That loop always goes one position too far,
11934 including the glyph before the ellipsis.
11935 So scan forward over that one. */
11936 x
+= glyph
->pixel_width
;
11939 else if (string_start
11940 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11942 /* We may have skipped over point because the previous glyphs
11943 are from string. As there's no easy way to know the
11944 character position of the current glyph, find the correct
11945 glyph on point by scanning from string_start again. */
11947 Lisp_Object string
;
11948 struct glyph
*stop
= glyph
;
11951 limit
= make_number (pt_old
+ 1);
11952 glyph
= string_start
;
11953 x
= string_start_x
;
11954 string
= glyph
->object
;
11955 pos
= string_buffer_position (w
, string
, string_before_pos
);
11956 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11957 because we always put cursor after overlay strings. */
11958 while (pos
== 0 && glyph
< stop
)
11960 string
= glyph
->object
;
11961 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
11963 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11966 while (glyph
< stop
)
11968 pos
= XINT (Fnext_single_char_property_change
11969 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11972 /* Skip glyphs from the same string. */
11973 string
= glyph
->object
;
11974 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
11975 /* Skip glyphs from an overlay. */
11976 while (glyph
< stop
11977 && ! string_buffer_position (w
, glyph
->object
, pos
))
11979 string
= glyph
->object
;
11980 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
11984 /* If we reached the end of the line, and end was from a string,
11985 cursor is not on this line. */
11986 if (glyph
== end
&& row
->continued_p
)
11990 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11992 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11993 w
->cursor
.y
= row
->y
+ dy
;
11995 if (w
== XWINDOW (selected_window
))
11997 if (!row
->continued_p
11998 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12001 this_line_buffer
= XBUFFER (w
->buffer
);
12003 CHARPOS (this_line_start_pos
)
12004 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12005 BYTEPOS (this_line_start_pos
)
12006 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12008 CHARPOS (this_line_end_pos
)
12009 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12010 BYTEPOS (this_line_end_pos
)
12011 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12013 this_line_y
= w
->cursor
.y
;
12014 this_line_pixel_height
= row
->height
;
12015 this_line_vpos
= w
->cursor
.vpos
;
12016 this_line_start_x
= row
->x
;
12019 CHARPOS (this_line_start_pos
) = 0;
12026 /* Run window scroll functions, if any, for WINDOW with new window
12027 start STARTP. Sets the window start of WINDOW to that position.
12029 We assume that the window's buffer is really current. */
12031 static INLINE
struct text_pos
12032 run_window_scroll_functions (window
, startp
)
12033 Lisp_Object window
;
12034 struct text_pos startp
;
12036 struct window
*w
= XWINDOW (window
);
12037 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12039 if (current_buffer
!= XBUFFER (w
->buffer
))
12042 if (!NILP (Vwindow_scroll_functions
))
12044 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12045 make_number (CHARPOS (startp
)));
12046 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12047 /* In case the hook functions switch buffers. */
12048 if (current_buffer
!= XBUFFER (w
->buffer
))
12049 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12056 /* Make sure the line containing the cursor is fully visible.
12057 A value of 1 means there is nothing to be done.
12058 (Either the line is fully visible, or it cannot be made so,
12059 or we cannot tell.)
12061 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12062 is higher than window.
12064 A value of 0 means the caller should do scrolling
12065 as if point had gone off the screen. */
12068 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12071 int current_matrix_p
;
12073 struct glyph_matrix
*matrix
;
12074 struct glyph_row
*row
;
12077 if (!make_cursor_line_fully_visible_p
)
12080 /* It's not always possible to find the cursor, e.g, when a window
12081 is full of overlay strings. Don't do anything in that case. */
12082 if (w
->cursor
.vpos
< 0)
12085 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12086 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12088 /* If the cursor row is not partially visible, there's nothing to do. */
12089 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12092 /* If the row the cursor is in is taller than the window's height,
12093 it's not clear what to do, so do nothing. */
12094 window_height
= window_box_height (w
);
12095 if (row
->height
>= window_height
)
12097 if (!force_p
|| MINI_WINDOW_P (w
)
12098 || w
->vscroll
|| w
->cursor
.vpos
== 0)
12104 /* This code used to try to scroll the window just enough to make
12105 the line visible. It returned 0 to say that the caller should
12106 allocate larger glyph matrices. */
12108 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
12110 int dy
= row
->height
- row
->visible_height
;
12113 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12115 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
12117 int dy
= - (row
->height
- row
->visible_height
);
12120 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12123 /* When we change the cursor y-position of the selected window,
12124 change this_line_y as well so that the display optimization for
12125 the cursor line of the selected window in redisplay_internal uses
12126 the correct y-position. */
12127 if (w
== XWINDOW (selected_window
))
12128 this_line_y
= w
->cursor
.y
;
12130 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
12131 redisplay with larger matrices. */
12132 if (matrix
->nrows
< required_matrix_height (w
))
12134 fonts_changed_p
= 1;
12143 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12144 non-zero means only WINDOW is redisplayed in redisplay_internal.
12145 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12146 in redisplay_window to bring a partially visible line into view in
12147 the case that only the cursor has moved.
12149 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12150 last screen line's vertical height extends past the end of the screen.
12154 1 if scrolling succeeded
12156 0 if scrolling didn't find point.
12158 -1 if new fonts have been loaded so that we must interrupt
12159 redisplay, adjust glyph matrices, and try again. */
12165 SCROLLING_NEED_LARGER_MATRICES
12169 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12170 scroll_step
, temp_scroll_step
, last_line_misfit
)
12171 Lisp_Object window
;
12172 int just_this_one_p
;
12173 EMACS_INT scroll_conservatively
, scroll_step
;
12174 int temp_scroll_step
;
12175 int last_line_misfit
;
12177 struct window
*w
= XWINDOW (window
);
12178 struct frame
*f
= XFRAME (w
->frame
);
12179 struct text_pos scroll_margin_pos
;
12180 struct text_pos pos
;
12181 struct text_pos startp
;
12183 Lisp_Object window_end
;
12184 int this_scroll_margin
;
12188 int amount_to_scroll
= 0;
12189 Lisp_Object aggressive
;
12191 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12194 debug_method_add (w
, "try_scrolling");
12197 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12199 /* Compute scroll margin height in pixels. We scroll when point is
12200 within this distance from the top or bottom of the window. */
12201 if (scroll_margin
> 0)
12203 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12204 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12207 this_scroll_margin
= 0;
12209 /* Force scroll_conservatively to have a reasonable value so it doesn't
12210 cause an overflow while computing how much to scroll. */
12211 if (scroll_conservatively
)
12212 scroll_conservatively
= min (scroll_conservatively
,
12213 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
12215 /* Compute how much we should try to scroll maximally to bring point
12217 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12218 scroll_max
= max (scroll_step
,
12219 max (scroll_conservatively
, temp_scroll_step
));
12220 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12221 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12222 /* We're trying to scroll because of aggressive scrolling
12223 but no scroll_step is set. Choose an arbitrary one. Maybe
12224 there should be a variable for this. */
12228 scroll_max
*= FRAME_LINE_HEIGHT (f
);
12230 /* Decide whether we have to scroll down. Start at the window end
12231 and move this_scroll_margin up to find the position of the scroll
12233 window_end
= Fwindow_end (window
, Qt
);
12237 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
12238 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
12240 if (this_scroll_margin
|| extra_scroll_margin_lines
)
12242 start_display (&it
, w
, scroll_margin_pos
);
12243 if (this_scroll_margin
)
12244 move_it_vertically_backward (&it
, this_scroll_margin
);
12245 if (extra_scroll_margin_lines
)
12246 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
12247 scroll_margin_pos
= it
.current
.pos
;
12250 if (PT
>= CHARPOS (scroll_margin_pos
))
12254 /* Point is in the scroll margin at the bottom of the window, or
12255 below. Compute a new window start that makes point visible. */
12257 /* Compute the distance from the scroll margin to PT.
12258 Give up if the distance is greater than scroll_max. */
12259 start_display (&it
, w
, scroll_margin_pos
);
12261 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12262 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12264 /* To make point visible, we have to move the window start
12265 down so that the line the cursor is in is visible, which
12266 means we have to add in the height of the cursor line. */
12267 dy
= line_bottom_y (&it
) - y0
;
12269 if (dy
> scroll_max
)
12270 return SCROLLING_FAILED
;
12272 /* Move the window start down. If scrolling conservatively,
12273 move it just enough down to make point visible. If
12274 scroll_step is set, move it down by scroll_step. */
12275 start_display (&it
, w
, startp
);
12277 if (scroll_conservatively
)
12278 /* Set AMOUNT_TO_SCROLL to at least one line,
12279 and at most scroll_conservatively lines. */
12281 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12282 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12283 else if (scroll_step
|| temp_scroll_step
)
12284 amount_to_scroll
= scroll_max
;
12287 aggressive
= current_buffer
->scroll_up_aggressively
;
12288 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12289 if (NUMBERP (aggressive
))
12291 double float_amount
= XFLOATINT (aggressive
) * height
;
12292 amount_to_scroll
= float_amount
;
12293 if (amount_to_scroll
== 0 && float_amount
> 0)
12294 amount_to_scroll
= 1;
12298 if (amount_to_scroll
<= 0)
12299 return SCROLLING_FAILED
;
12301 /* If moving by amount_to_scroll leaves STARTP unchanged,
12302 move it down one screen line. */
12304 move_it_vertically (&it
, amount_to_scroll
);
12305 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12306 move_it_by_lines (&it
, 1, 1);
12307 startp
= it
.current
.pos
;
12311 /* See if point is inside the scroll margin at the top of the
12313 scroll_margin_pos
= startp
;
12314 if (this_scroll_margin
)
12316 start_display (&it
, w
, startp
);
12317 move_it_vertically (&it
, this_scroll_margin
);
12318 scroll_margin_pos
= it
.current
.pos
;
12321 if (PT
< CHARPOS (scroll_margin_pos
))
12323 /* Point is in the scroll margin at the top of the window or
12324 above what is displayed in the window. */
12327 /* Compute the vertical distance from PT to the scroll
12328 margin position. Give up if distance is greater than
12330 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12331 start_display (&it
, w
, pos
);
12333 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12334 it
.last_visible_y
, -1,
12335 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12336 dy
= it
.current_y
- y0
;
12337 if (dy
> scroll_max
)
12338 return SCROLLING_FAILED
;
12340 /* Compute new window start. */
12341 start_display (&it
, w
, startp
);
12343 if (scroll_conservatively
)
12345 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12346 else if (scroll_step
|| temp_scroll_step
)
12347 amount_to_scroll
= scroll_max
;
12350 aggressive
= current_buffer
->scroll_down_aggressively
;
12351 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12352 if (NUMBERP (aggressive
))
12354 double float_amount
= XFLOATINT (aggressive
) * height
;
12355 amount_to_scroll
= float_amount
;
12356 if (amount_to_scroll
== 0 && float_amount
> 0)
12357 amount_to_scroll
= 1;
12361 if (amount_to_scroll
<= 0)
12362 return SCROLLING_FAILED
;
12364 move_it_vertically_backward (&it
, amount_to_scroll
);
12365 startp
= it
.current
.pos
;
12369 /* Run window scroll functions. */
12370 startp
= run_window_scroll_functions (window
, startp
);
12372 /* Display the window. Give up if new fonts are loaded, or if point
12374 if (!try_window (window
, startp
, 0))
12375 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12376 else if (w
->cursor
.vpos
< 0)
12378 clear_glyph_matrix (w
->desired_matrix
);
12379 rc
= SCROLLING_FAILED
;
12383 /* Maybe forget recorded base line for line number display. */
12384 if (!just_this_one_p
12385 || current_buffer
->clip_changed
12386 || BEG_UNCHANGED
< CHARPOS (startp
))
12387 w
->base_line_number
= Qnil
;
12389 /* If cursor ends up on a partially visible line,
12390 treat that as being off the bottom of the screen. */
12391 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12393 clear_glyph_matrix (w
->desired_matrix
);
12394 ++extra_scroll_margin_lines
;
12397 rc
= SCROLLING_SUCCESS
;
12404 /* Compute a suitable window start for window W if display of W starts
12405 on a continuation line. Value is non-zero if a new window start
12408 The new window start will be computed, based on W's width, starting
12409 from the start of the continued line. It is the start of the
12410 screen line with the minimum distance from the old start W->start. */
12413 compute_window_start_on_continuation_line (w
)
12416 struct text_pos pos
, start_pos
;
12417 int window_start_changed_p
= 0;
12419 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12421 /* If window start is on a continuation line... Window start may be
12422 < BEGV in case there's invisible text at the start of the
12423 buffer (M-x rmail, for example). */
12424 if (CHARPOS (start_pos
) > BEGV
12425 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12428 struct glyph_row
*row
;
12430 /* Handle the case that the window start is out of range. */
12431 if (CHARPOS (start_pos
) < BEGV
)
12432 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12433 else if (CHARPOS (start_pos
) > ZV
)
12434 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12436 /* Find the start of the continued line. This should be fast
12437 because scan_buffer is fast (newline cache). */
12438 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12439 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12440 row
, DEFAULT_FACE_ID
);
12441 reseat_at_previous_visible_line_start (&it
);
12443 /* If the line start is "too far" away from the window start,
12444 say it takes too much time to compute a new window start. */
12445 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12446 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12448 int min_distance
, distance
;
12450 /* Move forward by display lines to find the new window
12451 start. If window width was enlarged, the new start can
12452 be expected to be > the old start. If window width was
12453 decreased, the new window start will be < the old start.
12454 So, we're looking for the display line start with the
12455 minimum distance from the old window start. */
12456 pos
= it
.current
.pos
;
12457 min_distance
= INFINITY
;
12458 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12459 distance
< min_distance
)
12461 min_distance
= distance
;
12462 pos
= it
.current
.pos
;
12463 move_it_by_lines (&it
, 1, 0);
12466 /* Set the window start there. */
12467 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12468 window_start_changed_p
= 1;
12472 return window_start_changed_p
;
12476 /* Try cursor movement in case text has not changed in window WINDOW,
12477 with window start STARTP. Value is
12479 CURSOR_MOVEMENT_SUCCESS if successful
12481 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12483 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12484 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12485 we want to scroll as if scroll-step were set to 1. See the code.
12487 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12488 which case we have to abort this redisplay, and adjust matrices
12493 CURSOR_MOVEMENT_SUCCESS
,
12494 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12495 CURSOR_MOVEMENT_MUST_SCROLL
,
12496 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12500 try_cursor_movement (window
, startp
, scroll_step
)
12501 Lisp_Object window
;
12502 struct text_pos startp
;
12505 struct window
*w
= XWINDOW (window
);
12506 struct frame
*f
= XFRAME (w
->frame
);
12507 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12510 if (inhibit_try_cursor_movement
)
12514 /* Handle case where text has not changed, only point, and it has
12515 not moved off the frame. */
12516 if (/* Point may be in this window. */
12517 PT
>= CHARPOS (startp
)
12518 /* Selective display hasn't changed. */
12519 && !current_buffer
->clip_changed
12520 /* Function force-mode-line-update is used to force a thorough
12521 redisplay. It sets either windows_or_buffers_changed or
12522 update_mode_lines. So don't take a shortcut here for these
12524 && !update_mode_lines
12525 && !windows_or_buffers_changed
12526 && !cursor_type_changed
12527 /* Can't use this case if highlighting a region. When a
12528 region exists, cursor movement has to do more than just
12530 && !(!NILP (Vtransient_mark_mode
)
12531 && !NILP (current_buffer
->mark_active
))
12532 && NILP (w
->region_showing
)
12533 && NILP (Vshow_trailing_whitespace
)
12534 /* Right after splitting windows, last_point may be nil. */
12535 && INTEGERP (w
->last_point
)
12536 /* This code is not used for mini-buffer for the sake of the case
12537 of redisplaying to replace an echo area message; since in
12538 that case the mini-buffer contents per se are usually
12539 unchanged. This code is of no real use in the mini-buffer
12540 since the handling of this_line_start_pos, etc., in redisplay
12541 handles the same cases. */
12542 && !EQ (window
, minibuf_window
)
12543 /* When splitting windows or for new windows, it happens that
12544 redisplay is called with a nil window_end_vpos or one being
12545 larger than the window. This should really be fixed in
12546 window.c. I don't have this on my list, now, so we do
12547 approximately the same as the old redisplay code. --gerd. */
12548 && INTEGERP (w
->window_end_vpos
)
12549 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12550 && (FRAME_WINDOW_P (f
)
12551 || !overlay_arrow_in_current_buffer_p ()))
12553 int this_scroll_margin
, top_scroll_margin
;
12554 struct glyph_row
*row
= NULL
;
12557 debug_method_add (w
, "cursor movement");
12560 /* Scroll if point within this distance from the top or bottom
12561 of the window. This is a pixel value. */
12562 this_scroll_margin
= max (0, scroll_margin
);
12563 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12564 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12566 top_scroll_margin
= this_scroll_margin
;
12567 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12568 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12570 /* Start with the row the cursor was displayed during the last
12571 not paused redisplay. Give up if that row is not valid. */
12572 if (w
->last_cursor
.vpos
< 0
12573 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12574 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12577 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12578 if (row
->mode_line_p
)
12580 if (!row
->enabled_p
)
12581 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12584 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12587 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12589 if (PT
> XFASTINT (w
->last_point
))
12591 /* Point has moved forward. */
12592 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12593 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12595 xassert (row
->enabled_p
);
12599 /* The end position of a row equals the start position
12600 of the next row. If PT is there, we would rather
12601 display it in the next line. */
12602 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12603 && MATRIX_ROW_END_CHARPOS (row
) == PT
12604 && !cursor_row_p (w
, row
))
12607 /* If within the scroll margin, scroll. Note that
12608 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12609 the next line would be drawn, and that
12610 this_scroll_margin can be zero. */
12611 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12612 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12613 /* Line is completely visible last line in window
12614 and PT is to be set in the next line. */
12615 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12616 && PT
== MATRIX_ROW_END_CHARPOS (row
)
12617 && !row
->ends_at_zv_p
12618 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12621 else if (PT
< XFASTINT (w
->last_point
))
12623 /* Cursor has to be moved backward. Note that PT >=
12624 CHARPOS (startp) because of the outer if-statement. */
12625 while (!row
->mode_line_p
12626 && (MATRIX_ROW_START_CHARPOS (row
) > PT
12627 || (MATRIX_ROW_START_CHARPOS (row
) == PT
12628 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
12629 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
12630 row
> w
->current_matrix
->rows
12631 && (row
-1)->ends_in_newline_from_string_p
))))
12632 && (row
->y
> top_scroll_margin
12633 || CHARPOS (startp
) == BEGV
))
12635 xassert (row
->enabled_p
);
12639 /* Consider the following case: Window starts at BEGV,
12640 there is invisible, intangible text at BEGV, so that
12641 display starts at some point START > BEGV. It can
12642 happen that we are called with PT somewhere between
12643 BEGV and START. Try to handle that case. */
12644 if (row
< w
->current_matrix
->rows
12645 || row
->mode_line_p
)
12647 row
= w
->current_matrix
->rows
;
12648 if (row
->mode_line_p
)
12652 /* Due to newlines in overlay strings, we may have to
12653 skip forward over overlay strings. */
12654 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12655 && MATRIX_ROW_END_CHARPOS (row
) == PT
12656 && !cursor_row_p (w
, row
))
12659 /* If within the scroll margin, scroll. */
12660 if (row
->y
< top_scroll_margin
12661 && CHARPOS (startp
) != BEGV
)
12666 /* Cursor did not move. So don't scroll even if cursor line
12667 is partially visible, as it was so before. */
12668 rc
= CURSOR_MOVEMENT_SUCCESS
;
12671 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
12672 || PT
> MATRIX_ROW_END_CHARPOS (row
))
12674 /* if PT is not in the glyph row, give up. */
12675 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12677 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
12678 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
12679 && make_cursor_line_fully_visible_p
)
12681 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
12682 && !row
->ends_at_zv_p
12683 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12684 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12685 else if (row
->height
> window_box_height (w
))
12687 /* If we end up in a partially visible line, let's
12688 make it fully visible, except when it's taller
12689 than the window, in which case we can't do much
12692 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12696 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12697 if (!cursor_row_fully_visible_p (w
, 0, 1))
12698 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12700 rc
= CURSOR_MOVEMENT_SUCCESS
;
12704 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12709 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
12711 rc
= CURSOR_MOVEMENT_SUCCESS
;
12716 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12717 && MATRIX_ROW_START_CHARPOS (row
) == PT
12718 && cursor_row_p (w
, row
));
12727 set_vertical_scroll_bar (w
)
12730 int start
, end
, whole
;
12732 /* Calculate the start and end positions for the current window.
12733 At some point, it would be nice to choose between scrollbars
12734 which reflect the whole buffer size, with special markers
12735 indicating narrowing, and scrollbars which reflect only the
12738 Note that mini-buffers sometimes aren't displaying any text. */
12739 if (!MINI_WINDOW_P (w
)
12740 || (w
== XWINDOW (minibuf_window
)
12741 && NILP (echo_area_buffer
[0])))
12743 struct buffer
*buf
= XBUFFER (w
->buffer
);
12744 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12745 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12746 /* I don't think this is guaranteed to be right. For the
12747 moment, we'll pretend it is. */
12748 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12752 if (whole
< (end
- start
))
12753 whole
= end
- start
;
12756 start
= end
= whole
= 0;
12758 /* Indicate what this scroll bar ought to be displaying now. */
12759 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
12763 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12764 selected_window is redisplayed.
12766 We can return without actually redisplaying the window if
12767 fonts_changed_p is nonzero. In that case, redisplay_internal will
12771 redisplay_window (window
, just_this_one_p
)
12772 Lisp_Object window
;
12773 int just_this_one_p
;
12775 struct window
*w
= XWINDOW (window
);
12776 struct frame
*f
= XFRAME (w
->frame
);
12777 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12778 struct buffer
*old
= current_buffer
;
12779 struct text_pos lpoint
, opoint
, startp
;
12780 int update_mode_line
;
12783 /* Record it now because it's overwritten. */
12784 int current_matrix_up_to_date_p
= 0;
12785 int used_current_matrix_p
= 0;
12786 /* This is less strict than current_matrix_up_to_date_p.
12787 It indictes that the buffer contents and narrowing are unchanged. */
12788 int buffer_unchanged_p
= 0;
12789 int temp_scroll_step
= 0;
12790 int count
= SPECPDL_INDEX ();
12792 int centering_position
= -1;
12793 int last_line_misfit
= 0;
12794 int save_beg_unchanged
, save_end_unchanged
;
12796 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12799 /* W must be a leaf window here. */
12800 xassert (!NILP (w
->buffer
));
12802 *w
->desired_matrix
->method
= 0;
12805 specbind (Qinhibit_point_motion_hooks
, Qt
);
12807 reconsider_clip_changes (w
, buffer
);
12809 /* Has the mode line to be updated? */
12810 update_mode_line
= (!NILP (w
->update_mode_line
)
12811 || update_mode_lines
12812 || buffer
->clip_changed
12813 || buffer
->prevent_redisplay_optimizations_p
);
12815 if (MINI_WINDOW_P (w
))
12817 if (w
== XWINDOW (echo_area_window
)
12818 && !NILP (echo_area_buffer
[0]))
12820 if (update_mode_line
)
12821 /* We may have to update a tty frame's menu bar or a
12822 tool-bar. Example `M-x C-h C-h C-g'. */
12823 goto finish_menu_bars
;
12825 /* We've already displayed the echo area glyphs in this window. */
12826 goto finish_scroll_bars
;
12828 else if ((w
!= XWINDOW (minibuf_window
)
12829 || minibuf_level
== 0)
12830 /* When buffer is nonempty, redisplay window normally. */
12831 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12832 /* Quail displays non-mini buffers in minibuffer window.
12833 In that case, redisplay the window normally. */
12834 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12836 /* W is a mini-buffer window, but it's not active, so clear
12838 int yb
= window_text_bottom_y (w
);
12839 struct glyph_row
*row
;
12842 for (y
= 0, row
= w
->desired_matrix
->rows
;
12844 y
+= row
->height
, ++row
)
12845 blank_row (w
, row
, y
);
12846 goto finish_scroll_bars
;
12849 clear_glyph_matrix (w
->desired_matrix
);
12852 /* Otherwise set up data on this window; select its buffer and point
12854 /* Really select the buffer, for the sake of buffer-local
12856 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12857 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12859 save_beg_unchanged
= BEG_UNCHANGED
;
12860 save_end_unchanged
= END_UNCHANGED
;
12862 current_matrix_up_to_date_p
12863 = (!NILP (w
->window_end_valid
)
12864 && !current_buffer
->clip_changed
12865 && !current_buffer
->prevent_redisplay_optimizations_p
12866 && XFASTINT (w
->last_modified
) >= MODIFF
12867 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12870 = (!NILP (w
->window_end_valid
)
12871 && !current_buffer
->clip_changed
12872 && XFASTINT (w
->last_modified
) >= MODIFF
12873 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12875 /* When windows_or_buffers_changed is non-zero, we can't rely on
12876 the window end being valid, so set it to nil there. */
12877 if (windows_or_buffers_changed
)
12879 /* If window starts on a continuation line, maybe adjust the
12880 window start in case the window's width changed. */
12881 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12882 compute_window_start_on_continuation_line (w
);
12884 w
->window_end_valid
= Qnil
;
12887 /* Some sanity checks. */
12888 CHECK_WINDOW_END (w
);
12889 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12891 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12894 /* If %c is in mode line, update it if needed. */
12895 if (!NILP (w
->column_number_displayed
)
12896 /* This alternative quickly identifies a common case
12897 where no change is needed. */
12898 && !(PT
== XFASTINT (w
->last_point
)
12899 && XFASTINT (w
->last_modified
) >= MODIFF
12900 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12901 && (XFASTINT (w
->column_number_displayed
)
12902 != (int) current_column ())) /* iftc */
12903 update_mode_line
= 1;
12905 /* Count number of windows showing the selected buffer. An indirect
12906 buffer counts as its base buffer. */
12907 if (!just_this_one_p
)
12909 struct buffer
*current_base
, *window_base
;
12910 current_base
= current_buffer
;
12911 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12912 if (current_base
->base_buffer
)
12913 current_base
= current_base
->base_buffer
;
12914 if (window_base
->base_buffer
)
12915 window_base
= window_base
->base_buffer
;
12916 if (current_base
== window_base
)
12920 /* Point refers normally to the selected window. For any other
12921 window, set up appropriate value. */
12922 if (!EQ (window
, selected_window
))
12924 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12925 int new_pt_byte
= marker_byte_position (w
->pointm
);
12929 new_pt_byte
= BEGV_BYTE
;
12930 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
12932 else if (new_pt
> (ZV
- 1))
12935 new_pt_byte
= ZV_BYTE
;
12936 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
12939 /* We don't use SET_PT so that the point-motion hooks don't run. */
12940 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
12943 /* If any of the character widths specified in the display table
12944 have changed, invalidate the width run cache. It's true that
12945 this may be a bit late to catch such changes, but the rest of
12946 redisplay goes (non-fatally) haywire when the display table is
12947 changed, so why should we worry about doing any better? */
12948 if (current_buffer
->width_run_cache
)
12950 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
12952 if (! disptab_matches_widthtab (disptab
,
12953 XVECTOR (current_buffer
->width_table
)))
12955 invalidate_region_cache (current_buffer
,
12956 current_buffer
->width_run_cache
,
12958 recompute_width_table (current_buffer
, disptab
);
12962 /* If window-start is screwed up, choose a new one. */
12963 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12966 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12968 /* If someone specified a new starting point but did not insist,
12969 check whether it can be used. */
12970 if (!NILP (w
->optional_new_start
)
12971 && CHARPOS (startp
) >= BEGV
12972 && CHARPOS (startp
) <= ZV
)
12974 w
->optional_new_start
= Qnil
;
12975 start_display (&it
, w
, startp
);
12976 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12977 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12978 if (IT_CHARPOS (it
) == PT
)
12979 w
->force_start
= Qt
;
12980 /* IT may overshoot PT if text at PT is invisible. */
12981 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12982 w
->force_start
= Qt
;
12987 /* Handle case where place to start displaying has been specified,
12988 unless the specified location is outside the accessible range. */
12989 if (!NILP (w
->force_start
)
12990 || w
->frozen_window_start_p
)
12992 /* We set this later on if we have to adjust point. */
12996 w
->force_start
= Qnil
;
12998 w
->window_end_valid
= Qnil
;
13000 /* Forget any recorded base line for line number display. */
13001 if (!buffer_unchanged_p
)
13002 w
->base_line_number
= Qnil
;
13004 /* Redisplay the mode line. Select the buffer properly for that.
13005 Also, run the hook window-scroll-functions
13006 because we have scrolled. */
13007 /* Note, we do this after clearing force_start because
13008 if there's an error, it is better to forget about force_start
13009 than to get into an infinite loop calling the hook functions
13010 and having them get more errors. */
13011 if (!update_mode_line
13012 || ! NILP (Vwindow_scroll_functions
))
13014 update_mode_line
= 1;
13015 w
->update_mode_line
= Qt
;
13016 startp
= run_window_scroll_functions (window
, startp
);
13019 w
->last_modified
= make_number (0);
13020 w
->last_overlay_modified
= make_number (0);
13021 if (CHARPOS (startp
) < BEGV
)
13022 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
13023 else if (CHARPOS (startp
) > ZV
)
13024 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
13026 /* Redisplay, then check if cursor has been set during the
13027 redisplay. Give up if new fonts were loaded. */
13028 val
= try_window (window
, startp
, 1);
13031 w
->force_start
= Qt
;
13032 clear_glyph_matrix (w
->desired_matrix
);
13033 goto need_larger_matrices
;
13035 /* Point was outside the scroll margins. */
13037 new_vpos
= window_box_height (w
) / 2;
13039 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
13041 /* If point does not appear, try to move point so it does
13042 appear. The desired matrix has been built above, so we
13043 can use it here. */
13044 new_vpos
= window_box_height (w
) / 2;
13047 if (!cursor_row_fully_visible_p (w
, 0, 0))
13049 /* Point does appear, but on a line partly visible at end of window.
13050 Move it back to a fully-visible line. */
13051 new_vpos
= window_box_height (w
);
13054 /* If we need to move point for either of the above reasons,
13055 now actually do it. */
13058 struct glyph_row
*row
;
13060 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13061 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13064 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13065 MATRIX_ROW_START_BYTEPOS (row
));
13067 if (w
!= XWINDOW (selected_window
))
13068 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13069 else if (current_buffer
== old
)
13070 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13072 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13074 /* If we are highlighting the region, then we just changed
13075 the region, so redisplay to show it. */
13076 if (!NILP (Vtransient_mark_mode
)
13077 && !NILP (current_buffer
->mark_active
))
13079 clear_glyph_matrix (w
->desired_matrix
);
13080 if (!try_window (window
, startp
, 0))
13081 goto need_larger_matrices
;
13086 debug_method_add (w
, "forced window start");
13091 /* Handle case where text has not changed, only point, and it has
13092 not moved off the frame, and we are not retrying after hscroll.
13093 (current_matrix_up_to_date_p is nonzero when retrying.) */
13094 if (current_matrix_up_to_date_p
13095 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13096 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13100 case CURSOR_MOVEMENT_SUCCESS
:
13101 used_current_matrix_p
= 1;
13104 #if 0 /* try_cursor_movement never returns this value. */
13105 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
13106 goto need_larger_matrices
;
13109 case CURSOR_MOVEMENT_MUST_SCROLL
:
13110 goto try_to_scroll
;
13116 /* If current starting point was originally the beginning of a line
13117 but no longer is, find a new starting point. */
13118 else if (!NILP (w
->start_at_line_beg
)
13119 && !(CHARPOS (startp
) <= BEGV
13120 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13123 debug_method_add (w
, "recenter 1");
13128 /* Try scrolling with try_window_id. Value is > 0 if update has
13129 been done, it is -1 if we know that the same window start will
13130 not work. It is 0 if unsuccessful for some other reason. */
13131 else if ((tem
= try_window_id (w
)) != 0)
13134 debug_method_add (w
, "try_window_id %d", tem
);
13137 if (fonts_changed_p
)
13138 goto need_larger_matrices
;
13142 /* Otherwise try_window_id has returned -1 which means that we
13143 don't want the alternative below this comment to execute. */
13145 else if (CHARPOS (startp
) >= BEGV
13146 && CHARPOS (startp
) <= ZV
13147 && PT
>= CHARPOS (startp
)
13148 && (CHARPOS (startp
) < ZV
13149 /* Avoid starting at end of buffer. */
13150 || CHARPOS (startp
) == BEGV
13151 || (XFASTINT (w
->last_modified
) >= MODIFF
13152 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13155 /* If first window line is a continuation line, and window start
13156 is inside the modified region, but the first change is before
13157 current window start, we must select a new window start.
13159 However, if this is the result of a down-mouse event (e.g. by
13160 extending the mouse-drag-overlay), we don't want to select a
13161 new window start, since that would change the position under
13162 the mouse, resulting in an unwanted mouse-movement rather
13163 than a simple mouse-click. */
13164 if (NILP (w
->start_at_line_beg
)
13165 && NILP (do_mouse_tracking
)
13166 && CHARPOS (startp
) > BEGV
13167 && CHARPOS (startp
) > BEG
+ save_beg_unchanged
13168 && CHARPOS (startp
) <= Z
- save_end_unchanged
)
13170 w
->force_start
= Qt
;
13171 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13172 compute_window_start_on_continuation_line (w
);
13173 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13178 debug_method_add (w
, "same window start");
13181 /* Try to redisplay starting at same place as before.
13182 If point has not moved off frame, accept the results. */
13183 if (!current_matrix_up_to_date_p
13184 /* Don't use try_window_reusing_current_matrix in this case
13185 because a window scroll function can have changed the
13187 || !NILP (Vwindow_scroll_functions
)
13188 || MINI_WINDOW_P (w
)
13189 || !(used_current_matrix_p
13190 = try_window_reusing_current_matrix (w
)))
13192 IF_DEBUG (debug_method_add (w
, "1"));
13193 if (try_window (window
, startp
, 1) < 0)
13194 /* -1 means we need to scroll.
13195 0 means we need new matrices, but fonts_changed_p
13196 is set in that case, so we will detect it below. */
13197 goto try_to_scroll
;
13200 if (fonts_changed_p
)
13201 goto need_larger_matrices
;
13203 if (w
->cursor
.vpos
>= 0)
13205 if (!just_this_one_p
13206 || current_buffer
->clip_changed
13207 || BEG_UNCHANGED
< CHARPOS (startp
))
13208 /* Forget any recorded base line for line number display. */
13209 w
->base_line_number
= Qnil
;
13211 if (!cursor_row_fully_visible_p (w
, 1, 0))
13213 clear_glyph_matrix (w
->desired_matrix
);
13214 last_line_misfit
= 1;
13216 /* Drop through and scroll. */
13221 clear_glyph_matrix (w
->desired_matrix
);
13226 w
->last_modified
= make_number (0);
13227 w
->last_overlay_modified
= make_number (0);
13229 /* Redisplay the mode line. Select the buffer properly for that. */
13230 if (!update_mode_line
)
13232 update_mode_line
= 1;
13233 w
->update_mode_line
= Qt
;
13236 /* Try to scroll by specified few lines. */
13237 if ((scroll_conservatively
13239 || temp_scroll_step
13240 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13241 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13242 && !current_buffer
->clip_changed
13243 && CHARPOS (startp
) >= BEGV
13244 && CHARPOS (startp
) <= ZV
)
13246 /* The function returns -1 if new fonts were loaded, 1 if
13247 successful, 0 if not successful. */
13248 int rc
= try_scrolling (window
, just_this_one_p
,
13249 scroll_conservatively
,
13251 temp_scroll_step
, last_line_misfit
);
13254 case SCROLLING_SUCCESS
:
13257 case SCROLLING_NEED_LARGER_MATRICES
:
13258 goto need_larger_matrices
;
13260 case SCROLLING_FAILED
:
13268 /* Finally, just choose place to start which centers point */
13271 if (centering_position
< 0)
13272 centering_position
= window_box_height (w
) / 2;
13275 debug_method_add (w
, "recenter");
13278 /* w->vscroll = 0; */
13280 /* Forget any previously recorded base line for line number display. */
13281 if (!buffer_unchanged_p
)
13282 w
->base_line_number
= Qnil
;
13284 /* Move backward half the height of the window. */
13285 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13286 it
.current_y
= it
.last_visible_y
;
13287 move_it_vertically_backward (&it
, centering_position
);
13288 xassert (IT_CHARPOS (it
) >= BEGV
);
13290 /* The function move_it_vertically_backward may move over more
13291 than the specified y-distance. If it->w is small, e.g. a
13292 mini-buffer window, we may end up in front of the window's
13293 display area. Start displaying at the start of the line
13294 containing PT in this case. */
13295 if (it
.current_y
<= 0)
13297 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13298 move_it_vertically_backward (&it
, 0);
13300 /* I think this assert is bogus if buffer contains
13301 invisible text or images. KFS. */
13302 xassert (IT_CHARPOS (it
) <= PT
);
13307 it
.current_x
= it
.hpos
= 0;
13309 /* Set startp here explicitly in case that helps avoid an infinite loop
13310 in case the window-scroll-functions functions get errors. */
13311 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13313 /* Run scroll hooks. */
13314 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13316 /* Redisplay the window. */
13317 if (!current_matrix_up_to_date_p
13318 || windows_or_buffers_changed
13319 || cursor_type_changed
13320 /* Don't use try_window_reusing_current_matrix in this case
13321 because it can have changed the buffer. */
13322 || !NILP (Vwindow_scroll_functions
)
13323 || !just_this_one_p
13324 || MINI_WINDOW_P (w
)
13325 || !(used_current_matrix_p
13326 = try_window_reusing_current_matrix (w
)))
13327 try_window (window
, startp
, 0);
13329 /* If new fonts have been loaded (due to fontsets), give up. We
13330 have to start a new redisplay since we need to re-adjust glyph
13332 if (fonts_changed_p
)
13333 goto need_larger_matrices
;
13335 /* If cursor did not appear assume that the middle of the window is
13336 in the first line of the window. Do it again with the next line.
13337 (Imagine a window of height 100, displaying two lines of height
13338 60. Moving back 50 from it->last_visible_y will end in the first
13340 if (w
->cursor
.vpos
< 0)
13342 if (!NILP (w
->window_end_valid
)
13343 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13345 clear_glyph_matrix (w
->desired_matrix
);
13346 move_it_by_lines (&it
, 1, 0);
13347 try_window (window
, it
.current
.pos
, 0);
13349 else if (PT
< IT_CHARPOS (it
))
13351 clear_glyph_matrix (w
->desired_matrix
);
13352 move_it_by_lines (&it
, -1, 0);
13353 try_window (window
, it
.current
.pos
, 0);
13357 /* Not much we can do about it. */
13361 /* Consider the following case: Window starts at BEGV, there is
13362 invisible, intangible text at BEGV, so that display starts at
13363 some point START > BEGV. It can happen that we are called with
13364 PT somewhere between BEGV and START. Try to handle that case. */
13365 if (w
->cursor
.vpos
< 0)
13367 struct glyph_row
*row
= w
->current_matrix
->rows
;
13368 if (row
->mode_line_p
)
13370 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13373 if (!cursor_row_fully_visible_p (w
, 0, 0))
13375 /* If vscroll is enabled, disable it and try again. */
13379 clear_glyph_matrix (w
->desired_matrix
);
13383 /* If centering point failed to make the whole line visible,
13384 put point at the top instead. That has to make the whole line
13385 visible, if it can be done. */
13386 if (centering_position
== 0)
13389 clear_glyph_matrix (w
->desired_matrix
);
13390 centering_position
= 0;
13396 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13397 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13398 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13401 /* Display the mode line, if we must. */
13402 if ((update_mode_line
13403 /* If window not full width, must redo its mode line
13404 if (a) the window to its side is being redone and
13405 (b) we do a frame-based redisplay. This is a consequence
13406 of how inverted lines are drawn in frame-based redisplay. */
13407 || (!just_this_one_p
13408 && !FRAME_WINDOW_P (f
)
13409 && !WINDOW_FULL_WIDTH_P (w
))
13410 /* Line number to display. */
13411 || INTEGERP (w
->base_line_pos
)
13412 /* Column number is displayed and different from the one displayed. */
13413 || (!NILP (w
->column_number_displayed
)
13414 && (XFASTINT (w
->column_number_displayed
)
13415 != (int) current_column ()))) /* iftc */
13416 /* This means that the window has a mode line. */
13417 && (WINDOW_WANTS_MODELINE_P (w
)
13418 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13420 display_mode_lines (w
);
13422 /* If mode line height has changed, arrange for a thorough
13423 immediate redisplay using the correct mode line height. */
13424 if (WINDOW_WANTS_MODELINE_P (w
)
13425 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13427 fonts_changed_p
= 1;
13428 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13429 = DESIRED_MODE_LINE_HEIGHT (w
);
13432 /* If top line height has changed, arrange for a thorough
13433 immediate redisplay using the correct mode line height. */
13434 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13435 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13437 fonts_changed_p
= 1;
13438 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13439 = DESIRED_HEADER_LINE_HEIGHT (w
);
13442 if (fonts_changed_p
)
13443 goto need_larger_matrices
;
13446 if (!line_number_displayed
13447 && !BUFFERP (w
->base_line_pos
))
13449 w
->base_line_pos
= Qnil
;
13450 w
->base_line_number
= Qnil
;
13455 /* When we reach a frame's selected window, redo the frame's menu bar. */
13456 if (update_mode_line
13457 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13459 int redisplay_menu_p
= 0;
13460 int redisplay_tool_bar_p
= 0;
13462 if (FRAME_WINDOW_P (f
))
13464 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
13465 || defined (USE_GTK)
13466 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13468 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13472 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13474 if (redisplay_menu_p
)
13475 display_menu_bar (w
);
13477 #ifdef HAVE_WINDOW_SYSTEM
13479 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13481 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13482 && (FRAME_TOOL_BAR_LINES (f
) > 0
13483 || !NILP (Vauto_resize_tool_bars
));
13487 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
13489 extern int ignore_mouse_drag_p
;
13490 ignore_mouse_drag_p
= 1;
13495 #ifdef HAVE_WINDOW_SYSTEM
13496 if (FRAME_WINDOW_P (f
)
13497 && update_window_fringes (w
, (just_this_one_p
13498 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13499 || w
->pseudo_window_p
)))
13503 if (draw_window_fringes (w
, 1))
13504 x_draw_vertical_border (w
);
13508 #endif /* HAVE_WINDOW_SYSTEM */
13510 /* We go to this label, with fonts_changed_p nonzero,
13511 if it is necessary to try again using larger glyph matrices.
13512 We have to redeem the scroll bar even in this case,
13513 because the loop in redisplay_internal expects that. */
13514 need_larger_matrices
:
13516 finish_scroll_bars
:
13518 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13520 /* Set the thumb's position and size. */
13521 set_vertical_scroll_bar (w
);
13523 /* Note that we actually used the scroll bar attached to this
13524 window, so it shouldn't be deleted at the end of redisplay. */
13525 redeem_scroll_bar_hook (w
);
13528 /* Restore current_buffer and value of point in it. */
13529 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13530 set_buffer_internal_1 (old
);
13531 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
13532 shorter. This can be caused by log truncation in *Messages*. */
13533 if (CHARPOS (lpoint
) <= ZV
)
13534 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13536 unbind_to (count
, Qnil
);
13540 /* Build the complete desired matrix of WINDOW with a window start
13541 buffer position POS.
13543 Value is 1 if successful. It is zero if fonts were loaded during
13544 redisplay which makes re-adjusting glyph matrices necessary, and -1
13545 if point would appear in the scroll margins.
13546 (We check that only if CHECK_MARGINS is nonzero. */
13549 try_window (window
, pos
, check_margins
)
13550 Lisp_Object window
;
13551 struct text_pos pos
;
13554 struct window
*w
= XWINDOW (window
);
13556 struct glyph_row
*last_text_row
= NULL
;
13557 struct frame
*f
= XFRAME (w
->frame
);
13559 /* Make POS the new window start. */
13560 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13562 /* Mark cursor position as unknown. No overlay arrow seen. */
13563 w
->cursor
.vpos
= -1;
13564 overlay_arrow_seen
= 0;
13566 /* Initialize iterator and info to start at POS. */
13567 start_display (&it
, w
, pos
);
13569 /* Display all lines of W. */
13570 while (it
.current_y
< it
.last_visible_y
)
13572 if (display_line (&it
))
13573 last_text_row
= it
.glyph_row
- 1;
13574 if (fonts_changed_p
)
13578 /* Don't let the cursor end in the scroll margins. */
13580 && !MINI_WINDOW_P (w
))
13582 int this_scroll_margin
;
13584 this_scroll_margin
= max (0, scroll_margin
);
13585 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13586 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13588 if ((w
->cursor
.y
>= 0 /* not vscrolled */
13589 && w
->cursor
.y
< this_scroll_margin
13590 && CHARPOS (pos
) > BEGV
13591 && IT_CHARPOS (it
) < ZV
)
13592 /* rms: considering make_cursor_line_fully_visible_p here
13593 seems to give wrong results. We don't want to recenter
13594 when the last line is partly visible, we want to allow
13595 that case to be handled in the usual way. */
13596 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
13598 w
->cursor
.vpos
= -1;
13599 clear_glyph_matrix (w
->desired_matrix
);
13604 /* If bottom moved off end of frame, change mode line percentage. */
13605 if (XFASTINT (w
->window_end_pos
) <= 0
13606 && Z
!= IT_CHARPOS (it
))
13607 w
->update_mode_line
= Qt
;
13609 /* Set window_end_pos to the offset of the last character displayed
13610 on the window from the end of current_buffer. Set
13611 window_end_vpos to its row number. */
13614 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
13615 w
->window_end_bytepos
13616 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13618 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13620 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13621 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
13622 ->displays_text_p
);
13626 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13627 w
->window_end_pos
= make_number (Z
- ZV
);
13628 w
->window_end_vpos
= make_number (0);
13631 /* But that is not valid info until redisplay finishes. */
13632 w
->window_end_valid
= Qnil
;
13638 /************************************************************************
13639 Window redisplay reusing current matrix when buffer has not changed
13640 ************************************************************************/
13642 /* Try redisplay of window W showing an unchanged buffer with a
13643 different window start than the last time it was displayed by
13644 reusing its current matrix. Value is non-zero if successful.
13645 W->start is the new window start. */
13648 try_window_reusing_current_matrix (w
)
13651 struct frame
*f
= XFRAME (w
->frame
);
13652 struct glyph_row
*row
, *bottom_row
;
13655 struct text_pos start
, new_start
;
13656 int nrows_scrolled
, i
;
13657 struct glyph_row
*last_text_row
;
13658 struct glyph_row
*last_reused_text_row
;
13659 struct glyph_row
*start_row
;
13660 int start_vpos
, min_y
, max_y
;
13663 if (inhibit_try_window_reusing
)
13667 if (/* This function doesn't handle terminal frames. */
13668 !FRAME_WINDOW_P (f
)
13669 /* Don't try to reuse the display if windows have been split
13671 || windows_or_buffers_changed
13672 || cursor_type_changed
)
13675 /* Can't do this if region may have changed. */
13676 if ((!NILP (Vtransient_mark_mode
)
13677 && !NILP (current_buffer
->mark_active
))
13678 || !NILP (w
->region_showing
)
13679 || !NILP (Vshow_trailing_whitespace
))
13682 /* If top-line visibility has changed, give up. */
13683 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13684 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
13687 /* Give up if old or new display is scrolled vertically. We could
13688 make this function handle this, but right now it doesn't. */
13689 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13690 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
13693 /* The variable new_start now holds the new window start. The old
13694 start `start' can be determined from the current matrix. */
13695 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
13696 start
= start_row
->start
.pos
;
13697 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13699 /* Clear the desired matrix for the display below. */
13700 clear_glyph_matrix (w
->desired_matrix
);
13702 if (CHARPOS (new_start
) <= CHARPOS (start
))
13706 /* Don't use this method if the display starts with an ellipsis
13707 displayed for invisible text. It's not easy to handle that case
13708 below, and it's certainly not worth the effort since this is
13709 not a frequent case. */
13710 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
13713 IF_DEBUG (debug_method_add (w
, "twu1"));
13715 /* Display up to a row that can be reused. The variable
13716 last_text_row is set to the last row displayed that displays
13717 text. Note that it.vpos == 0 if or if not there is a
13718 header-line; it's not the same as the MATRIX_ROW_VPOS! */
13719 start_display (&it
, w
, new_start
);
13720 first_row_y
= it
.current_y
;
13721 w
->cursor
.vpos
= -1;
13722 last_text_row
= last_reused_text_row
= NULL
;
13724 while (it
.current_y
< it
.last_visible_y
13725 && !fonts_changed_p
)
13727 /* If we have reached into the characters in the START row,
13728 that means the line boundaries have changed. So we
13729 can't start copying with the row START. Maybe it will
13730 work to start copying with the following row. */
13731 while (IT_CHARPOS (it
) > CHARPOS (start
))
13733 /* Advance to the next row as the "start". */
13735 start
= start_row
->start
.pos
;
13736 /* If there are no more rows to try, or just one, give up. */
13737 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
13738 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
13739 || CHARPOS (start
) == ZV
)
13741 clear_glyph_matrix (w
->desired_matrix
);
13745 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13747 /* If we have reached alignment,
13748 we can copy the rest of the rows. */
13749 if (IT_CHARPOS (it
) == CHARPOS (start
))
13752 if (display_line (&it
))
13753 last_text_row
= it
.glyph_row
- 1;
13756 /* A value of current_y < last_visible_y means that we stopped
13757 at the previous window start, which in turn means that we
13758 have at least one reusable row. */
13759 if (it
.current_y
< it
.last_visible_y
)
13761 /* IT.vpos always starts from 0; it counts text lines. */
13762 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13764 /* Find PT if not already found in the lines displayed. */
13765 if (w
->cursor
.vpos
< 0)
13767 int dy
= it
.current_y
- start_row
->y
;
13769 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13770 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13772 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13773 dy
, nrows_scrolled
);
13776 clear_glyph_matrix (w
->desired_matrix
);
13781 /* Scroll the display. Do it before the current matrix is
13782 changed. The problem here is that update has not yet
13783 run, i.e. part of the current matrix is not up to date.
13784 scroll_run_hook will clear the cursor, and use the
13785 current matrix to get the height of the row the cursor is
13787 run
.current_y
= start_row
->y
;
13788 run
.desired_y
= it
.current_y
;
13789 run
.height
= it
.last_visible_y
- it
.current_y
;
13791 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13794 rif
->update_window_begin_hook (w
);
13795 rif
->clear_window_mouse_face (w
);
13796 rif
->scroll_run_hook (w
, &run
);
13797 rif
->update_window_end_hook (w
, 0, 0);
13801 /* Shift current matrix down by nrows_scrolled lines. */
13802 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13803 rotate_matrix (w
->current_matrix
,
13805 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13808 /* Disable lines that must be updated. */
13809 for (i
= 0; i
< nrows_scrolled
; ++i
)
13810 (start_row
+ i
)->enabled_p
= 0;
13812 /* Re-compute Y positions. */
13813 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13814 max_y
= it
.last_visible_y
;
13815 for (row
= start_row
+ nrows_scrolled
;
13819 row
->y
= it
.current_y
;
13820 row
->visible_height
= row
->height
;
13822 if (row
->y
< min_y
)
13823 row
->visible_height
-= min_y
- row
->y
;
13824 if (row
->y
+ row
->height
> max_y
)
13825 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13826 row
->redraw_fringe_bitmaps_p
= 1;
13828 it
.current_y
+= row
->height
;
13830 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13831 last_reused_text_row
= row
;
13832 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13836 /* Disable lines in the current matrix which are now
13837 below the window. */
13838 for (++row
; row
< bottom_row
; ++row
)
13839 row
->enabled_p
= row
->mode_line_p
= 0;
13842 /* Update window_end_pos etc.; last_reused_text_row is the last
13843 reused row from the current matrix containing text, if any.
13844 The value of last_text_row is the last displayed line
13845 containing text. */
13846 if (last_reused_text_row
)
13848 w
->window_end_bytepos
13849 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13851 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13853 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13854 w
->current_matrix
));
13856 else if (last_text_row
)
13858 w
->window_end_bytepos
13859 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13861 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13863 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13867 /* This window must be completely empty. */
13868 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13869 w
->window_end_pos
= make_number (Z
- ZV
);
13870 w
->window_end_vpos
= make_number (0);
13872 w
->window_end_valid
= Qnil
;
13874 /* Update hint: don't try scrolling again in update_window. */
13875 w
->desired_matrix
->no_scrolling_p
= 1;
13878 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13882 else if (CHARPOS (new_start
) > CHARPOS (start
))
13884 struct glyph_row
*pt_row
, *row
;
13885 struct glyph_row
*first_reusable_row
;
13886 struct glyph_row
*first_row_to_display
;
13888 int yb
= window_text_bottom_y (w
);
13890 /* Find the row starting at new_start, if there is one. Don't
13891 reuse a partially visible line at the end. */
13892 first_reusable_row
= start_row
;
13893 while (first_reusable_row
->enabled_p
13894 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13895 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13896 < CHARPOS (new_start
)))
13897 ++first_reusable_row
;
13899 /* Give up if there is no row to reuse. */
13900 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13901 || !first_reusable_row
->enabled_p
13902 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13903 != CHARPOS (new_start
)))
13906 /* We can reuse fully visible rows beginning with
13907 first_reusable_row to the end of the window. Set
13908 first_row_to_display to the first row that cannot be reused.
13909 Set pt_row to the row containing point, if there is any. */
13911 for (first_row_to_display
= first_reusable_row
;
13912 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13913 ++first_row_to_display
)
13915 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13916 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13917 pt_row
= first_row_to_display
;
13920 /* Start displaying at the start of first_row_to_display. */
13921 xassert (first_row_to_display
->y
< yb
);
13922 init_to_row_start (&it
, w
, first_row_to_display
);
13924 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
13926 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
13928 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
13929 + WINDOW_HEADER_LINE_HEIGHT (w
));
13931 /* Display lines beginning with first_row_to_display in the
13932 desired matrix. Set last_text_row to the last row displayed
13933 that displays text. */
13934 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
13935 if (pt_row
== NULL
)
13936 w
->cursor
.vpos
= -1;
13937 last_text_row
= NULL
;
13938 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
13939 if (display_line (&it
))
13940 last_text_row
= it
.glyph_row
- 1;
13942 /* Give up If point isn't in a row displayed or reused. */
13943 if (w
->cursor
.vpos
< 0)
13945 clear_glyph_matrix (w
->desired_matrix
);
13949 /* If point is in a reused row, adjust y and vpos of the cursor
13953 w
->cursor
.vpos
-= nrows_scrolled
;
13954 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
13957 /* Scroll the display. */
13958 run
.current_y
= first_reusable_row
->y
;
13959 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13960 run
.height
= it
.last_visible_y
- run
.current_y
;
13961 dy
= run
.current_y
- run
.desired_y
;
13966 rif
->update_window_begin_hook (w
);
13967 rif
->clear_window_mouse_face (w
);
13968 rif
->scroll_run_hook (w
, &run
);
13969 rif
->update_window_end_hook (w
, 0, 0);
13973 /* Adjust Y positions of reused rows. */
13974 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13975 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13976 max_y
= it
.last_visible_y
;
13977 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
13980 row
->visible_height
= row
->height
;
13981 if (row
->y
< min_y
)
13982 row
->visible_height
-= min_y
- row
->y
;
13983 if (row
->y
+ row
->height
> max_y
)
13984 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13985 row
->redraw_fringe_bitmaps_p
= 1;
13988 /* Scroll the current matrix. */
13989 xassert (nrows_scrolled
> 0);
13990 rotate_matrix (w
->current_matrix
,
13992 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13995 /* Disable rows not reused. */
13996 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
13997 row
->enabled_p
= 0;
13999 /* Point may have moved to a different line, so we cannot assume that
14000 the previous cursor position is valid; locate the correct row. */
14003 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14004 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
14008 w
->cursor
.y
= row
->y
;
14010 if (row
< bottom_row
)
14012 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14013 while (glyph
->charpos
< PT
)
14016 w
->cursor
.x
+= glyph
->pixel_width
;
14022 /* Adjust window end. A null value of last_text_row means that
14023 the window end is in reused rows which in turn means that
14024 only its vpos can have changed. */
14027 w
->window_end_bytepos
14028 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14030 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14032 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14037 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
14040 w
->window_end_valid
= Qnil
;
14041 w
->desired_matrix
->no_scrolling_p
= 1;
14044 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14054 /************************************************************************
14055 Window redisplay reusing current matrix when buffer has changed
14056 ************************************************************************/
14058 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14059 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14061 static struct glyph_row
*
14062 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14063 struct glyph_row
*));
14066 /* Return the last row in MATRIX displaying text. If row START is
14067 non-null, start searching with that row. IT gives the dimensions
14068 of the display. Value is null if matrix is empty; otherwise it is
14069 a pointer to the row found. */
14071 static struct glyph_row
*
14072 find_last_row_displaying_text (matrix
, it
, start
)
14073 struct glyph_matrix
*matrix
;
14075 struct glyph_row
*start
;
14077 struct glyph_row
*row
, *row_found
;
14079 /* Set row_found to the last row in IT->w's current matrix
14080 displaying text. The loop looks funny but think of partially
14083 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14084 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14086 xassert (row
->enabled_p
);
14088 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14097 /* Return the last row in the current matrix of W that is not affected
14098 by changes at the start of current_buffer that occurred since W's
14099 current matrix was built. Value is null if no such row exists.
14101 BEG_UNCHANGED us the number of characters unchanged at the start of
14102 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14103 first changed character in current_buffer. Characters at positions <
14104 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14105 when the current matrix was built. */
14107 static struct glyph_row
*
14108 find_last_unchanged_at_beg_row (w
)
14111 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14112 struct glyph_row
*row
;
14113 struct glyph_row
*row_found
= NULL
;
14114 int yb
= window_text_bottom_y (w
);
14116 /* Find the last row displaying unchanged text. */
14117 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14118 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14119 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
14121 if (/* If row ends before first_changed_pos, it is unchanged,
14122 except in some case. */
14123 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14124 /* When row ends in ZV and we write at ZV it is not
14126 && !row
->ends_at_zv_p
14127 /* When first_changed_pos is the end of a continued line,
14128 row is not unchanged because it may be no longer
14130 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14131 && (row
->continued_p
14132 || row
->exact_window_width_line_p
)))
14135 /* Stop if last visible row. */
14136 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14146 /* Find the first glyph row in the current matrix of W that is not
14147 affected by changes at the end of current_buffer since the
14148 time W's current matrix was built.
14150 Return in *DELTA the number of chars by which buffer positions in
14151 unchanged text at the end of current_buffer must be adjusted.
14153 Return in *DELTA_BYTES the corresponding number of bytes.
14155 Value is null if no such row exists, i.e. all rows are affected by
14158 static struct glyph_row
*
14159 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14161 int *delta
, *delta_bytes
;
14163 struct glyph_row
*row
;
14164 struct glyph_row
*row_found
= NULL
;
14166 *delta
= *delta_bytes
= 0;
14168 /* Display must not have been paused, otherwise the current matrix
14169 is not up to date. */
14170 if (NILP (w
->window_end_valid
))
14173 /* A value of window_end_pos >= END_UNCHANGED means that the window
14174 end is in the range of changed text. If so, there is no
14175 unchanged row at the end of W's current matrix. */
14176 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14179 /* Set row to the last row in W's current matrix displaying text. */
14180 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14182 /* If matrix is entirely empty, no unchanged row exists. */
14183 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14185 /* The value of row is the last glyph row in the matrix having a
14186 meaningful buffer position in it. The end position of row
14187 corresponds to window_end_pos. This allows us to translate
14188 buffer positions in the current matrix to current buffer
14189 positions for characters not in changed text. */
14190 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14191 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14192 int last_unchanged_pos
, last_unchanged_pos_old
;
14193 struct glyph_row
*first_text_row
14194 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14196 *delta
= Z
- Z_old
;
14197 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14199 /* Set last_unchanged_pos to the buffer position of the last
14200 character in the buffer that has not been changed. Z is the
14201 index + 1 of the last character in current_buffer, i.e. by
14202 subtracting END_UNCHANGED we get the index of the last
14203 unchanged character, and we have to add BEG to get its buffer
14205 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14206 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14208 /* Search backward from ROW for a row displaying a line that
14209 starts at a minimum position >= last_unchanged_pos_old. */
14210 for (; row
> first_text_row
; --row
)
14212 /* This used to abort, but it can happen.
14213 It is ok to just stop the search instead here. KFS. */
14214 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14217 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14222 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
14229 /* Make sure that glyph rows in the current matrix of window W
14230 reference the same glyph memory as corresponding rows in the
14231 frame's frame matrix. This function is called after scrolling W's
14232 current matrix on a terminal frame in try_window_id and
14233 try_window_reusing_current_matrix. */
14236 sync_frame_with_window_matrix_rows (w
)
14239 struct frame
*f
= XFRAME (w
->frame
);
14240 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14242 /* Preconditions: W must be a leaf window and full-width. Its frame
14243 must have a frame matrix. */
14244 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14245 xassert (WINDOW_FULL_WIDTH_P (w
));
14246 xassert (!FRAME_WINDOW_P (f
));
14248 /* If W is a full-width window, glyph pointers in W's current matrix
14249 have, by definition, to be the same as glyph pointers in the
14250 corresponding frame matrix. Note that frame matrices have no
14251 marginal areas (see build_frame_matrix). */
14252 window_row
= w
->current_matrix
->rows
;
14253 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14254 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14255 while (window_row
< window_row_end
)
14257 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14258 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14260 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14261 frame_row
->glyphs
[TEXT_AREA
] = start
;
14262 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14263 frame_row
->glyphs
[LAST_AREA
] = end
;
14265 /* Disable frame rows whose corresponding window rows have
14266 been disabled in try_window_id. */
14267 if (!window_row
->enabled_p
)
14268 frame_row
->enabled_p
= 0;
14270 ++window_row
, ++frame_row
;
14275 /* Find the glyph row in window W containing CHARPOS. Consider all
14276 rows between START and END (not inclusive). END null means search
14277 all rows to the end of the display area of W. Value is the row
14278 containing CHARPOS or null. */
14281 row_containing_pos (w
, charpos
, start
, end
, dy
)
14284 struct glyph_row
*start
, *end
;
14287 struct glyph_row
*row
= start
;
14290 /* If we happen to start on a header-line, skip that. */
14291 if (row
->mode_line_p
)
14294 if ((end
&& row
>= end
) || !row
->enabled_p
)
14297 last_y
= window_text_bottom_y (w
) - dy
;
14301 /* Give up if we have gone too far. */
14302 if (end
&& row
>= end
)
14304 /* This formerly returned if they were equal.
14305 I think that both quantities are of a "last plus one" type;
14306 if so, when they are equal, the row is within the screen. -- rms. */
14307 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14310 /* If it is in this row, return this row. */
14311 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14312 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14313 /* The end position of a row equals the start
14314 position of the next row. If CHARPOS is there, we
14315 would rather display it in the next line, except
14316 when this line ends in ZV. */
14317 && !row
->ends_at_zv_p
14318 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14319 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14326 /* Try to redisplay window W by reusing its existing display. W's
14327 current matrix must be up to date when this function is called,
14328 i.e. window_end_valid must not be nil.
14332 1 if display has been updated
14333 0 if otherwise unsuccessful
14334 -1 if redisplay with same window start is known not to succeed
14336 The following steps are performed:
14338 1. Find the last row in the current matrix of W that is not
14339 affected by changes at the start of current_buffer. If no such row
14342 2. Find the first row in W's current matrix that is not affected by
14343 changes at the end of current_buffer. Maybe there is no such row.
14345 3. Display lines beginning with the row + 1 found in step 1 to the
14346 row found in step 2 or, if step 2 didn't find a row, to the end of
14349 4. If cursor is not known to appear on the window, give up.
14351 5. If display stopped at the row found in step 2, scroll the
14352 display and current matrix as needed.
14354 6. Maybe display some lines at the end of W, if we must. This can
14355 happen under various circumstances, like a partially visible line
14356 becoming fully visible, or because newly displayed lines are displayed
14357 in smaller font sizes.
14359 7. Update W's window end information. */
14365 struct frame
*f
= XFRAME (w
->frame
);
14366 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14367 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14368 struct glyph_row
*last_unchanged_at_beg_row
;
14369 struct glyph_row
*first_unchanged_at_end_row
;
14370 struct glyph_row
*row
;
14371 struct glyph_row
*bottom_row
;
14374 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14375 struct text_pos start_pos
;
14377 int first_unchanged_at_end_vpos
= 0;
14378 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14379 struct text_pos start
;
14380 int first_changed_charpos
, last_changed_charpos
;
14383 if (inhibit_try_window_id
)
14387 /* This is handy for debugging. */
14389 #define GIVE_UP(X) \
14391 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14395 #define GIVE_UP(X) return 0
14398 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14400 /* Don't use this for mini-windows because these can show
14401 messages and mini-buffers, and we don't handle that here. */
14402 if (MINI_WINDOW_P (w
))
14405 /* This flag is used to prevent redisplay optimizations. */
14406 if (windows_or_buffers_changed
|| cursor_type_changed
)
14409 /* Verify that narrowing has not changed.
14410 Also verify that we were not told to prevent redisplay optimizations.
14411 It would be nice to further
14412 reduce the number of cases where this prevents try_window_id. */
14413 if (current_buffer
->clip_changed
14414 || current_buffer
->prevent_redisplay_optimizations_p
)
14417 /* Window must either use window-based redisplay or be full width. */
14418 if (!FRAME_WINDOW_P (f
)
14419 && (!line_ins_del_ok
14420 || !WINDOW_FULL_WIDTH_P (w
)))
14423 /* Give up if point is not known NOT to appear in W. */
14424 if (PT
< CHARPOS (start
))
14427 /* Another way to prevent redisplay optimizations. */
14428 if (XFASTINT (w
->last_modified
) == 0)
14431 /* Verify that window is not hscrolled. */
14432 if (XFASTINT (w
->hscroll
) != 0)
14435 /* Verify that display wasn't paused. */
14436 if (NILP (w
->window_end_valid
))
14439 /* Can't use this if highlighting a region because a cursor movement
14440 will do more than just set the cursor. */
14441 if (!NILP (Vtransient_mark_mode
)
14442 && !NILP (current_buffer
->mark_active
))
14445 /* Likewise if highlighting trailing whitespace. */
14446 if (!NILP (Vshow_trailing_whitespace
))
14449 /* Likewise if showing a region. */
14450 if (!NILP (w
->region_showing
))
14453 /* Can use this if overlay arrow position and or string have changed. */
14454 if (overlay_arrows_changed_p ())
14458 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14459 only if buffer has really changed. The reason is that the gap is
14460 initially at Z for freshly visited files. The code below would
14461 set end_unchanged to 0 in that case. */
14462 if (MODIFF
> SAVE_MODIFF
14463 /* This seems to happen sometimes after saving a buffer. */
14464 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14466 if (GPT
- BEG
< BEG_UNCHANGED
)
14467 BEG_UNCHANGED
= GPT
- BEG
;
14468 if (Z
- GPT
< END_UNCHANGED
)
14469 END_UNCHANGED
= Z
- GPT
;
14472 /* The position of the first and last character that has been changed. */
14473 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14474 last_changed_charpos
= Z
- END_UNCHANGED
;
14476 /* If window starts after a line end, and the last change is in
14477 front of that newline, then changes don't affect the display.
14478 This case happens with stealth-fontification. Note that although
14479 the display is unchanged, glyph positions in the matrix have to
14480 be adjusted, of course. */
14481 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14482 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14483 && ((last_changed_charpos
< CHARPOS (start
)
14484 && CHARPOS (start
) == BEGV
)
14485 || (last_changed_charpos
< CHARPOS (start
) - 1
14486 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14488 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14489 struct glyph_row
*r0
;
14491 /* Compute how many chars/bytes have been added to or removed
14492 from the buffer. */
14493 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14494 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14496 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14498 /* Give up if PT is not in the window. Note that it already has
14499 been checked at the start of try_window_id that PT is not in
14500 front of the window start. */
14501 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14504 /* If window start is unchanged, we can reuse the whole matrix
14505 as is, after adjusting glyph positions. No need to compute
14506 the window end again, since its offset from Z hasn't changed. */
14507 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14508 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14509 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14510 /* PT must not be in a partially visible line. */
14511 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14512 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14514 /* Adjust positions in the glyph matrix. */
14515 if (delta
|| delta_bytes
)
14517 struct glyph_row
*r1
14518 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14519 increment_matrix_positions (w
->current_matrix
,
14520 MATRIX_ROW_VPOS (r0
, current_matrix
),
14521 MATRIX_ROW_VPOS (r1
, current_matrix
),
14522 delta
, delta_bytes
);
14525 /* Set the cursor. */
14526 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14528 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14535 /* Handle the case that changes are all below what is displayed in
14536 the window, and that PT is in the window. This shortcut cannot
14537 be taken if ZV is visible in the window, and text has been added
14538 there that is visible in the window. */
14539 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14540 /* ZV is not visible in the window, or there are no
14541 changes at ZV, actually. */
14542 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14543 || first_changed_charpos
== last_changed_charpos
))
14545 struct glyph_row
*r0
;
14547 /* Give up if PT is not in the window. Note that it already has
14548 been checked at the start of try_window_id that PT is not in
14549 front of the window start. */
14550 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14553 /* If window start is unchanged, we can reuse the whole matrix
14554 as is, without changing glyph positions since no text has
14555 been added/removed in front of the window end. */
14556 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14557 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14558 /* PT must not be in a partially visible line. */
14559 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14560 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14562 /* We have to compute the window end anew since text
14563 can have been added/removed after it. */
14565 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14566 w
->window_end_bytepos
14567 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14569 /* Set the cursor. */
14570 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14572 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14579 /* Give up if window start is in the changed area.
14581 The condition used to read
14583 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
14585 but why that was tested escapes me at the moment. */
14586 if (CHARPOS (start
) >= first_changed_charpos
14587 && CHARPOS (start
) <= last_changed_charpos
)
14590 /* Check that window start agrees with the start of the first glyph
14591 row in its current matrix. Check this after we know the window
14592 start is not in changed text, otherwise positions would not be
14594 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14595 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
14598 /* Give up if the window ends in strings. Overlay strings
14599 at the end are difficult to handle, so don't try. */
14600 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
14601 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
14604 /* Compute the position at which we have to start displaying new
14605 lines. Some of the lines at the top of the window might be
14606 reusable because they are not displaying changed text. Find the
14607 last row in W's current matrix not affected by changes at the
14608 start of current_buffer. Value is null if changes start in the
14609 first line of window. */
14610 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
14611 if (last_unchanged_at_beg_row
)
14613 /* Avoid starting to display in the moddle of a character, a TAB
14614 for instance. This is easier than to set up the iterator
14615 exactly, and it's not a frequent case, so the additional
14616 effort wouldn't really pay off. */
14617 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
14618 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
14619 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
14620 --last_unchanged_at_beg_row
;
14622 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
14625 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
14627 start_pos
= it
.current
.pos
;
14629 /* Start displaying new lines in the desired matrix at the same
14630 vpos we would use in the current matrix, i.e. below
14631 last_unchanged_at_beg_row. */
14632 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
14634 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14635 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
14637 xassert (it
.hpos
== 0 && it
.current_x
== 0);
14641 /* There are no reusable lines at the start of the window.
14642 Start displaying in the first text line. */
14643 start_display (&it
, w
, start
);
14644 it
.vpos
= it
.first_vpos
;
14645 start_pos
= it
.current
.pos
;
14648 /* Find the first row that is not affected by changes at the end of
14649 the buffer. Value will be null if there is no unchanged row, in
14650 which case we must redisplay to the end of the window. delta
14651 will be set to the value by which buffer positions beginning with
14652 first_unchanged_at_end_row have to be adjusted due to text
14654 first_unchanged_at_end_row
14655 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
14656 IF_DEBUG (debug_delta
= delta
);
14657 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
14659 /* Set stop_pos to the buffer position up to which we will have to
14660 display new lines. If first_unchanged_at_end_row != NULL, this
14661 is the buffer position of the start of the line displayed in that
14662 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
14663 that we don't stop at a buffer position. */
14665 if (first_unchanged_at_end_row
)
14667 xassert (last_unchanged_at_beg_row
== NULL
14668 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
14670 /* If this is a continuation line, move forward to the next one
14671 that isn't. Changes in lines above affect this line.
14672 Caution: this may move first_unchanged_at_end_row to a row
14673 not displaying text. */
14674 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
14675 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14676 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14677 < it
.last_visible_y
))
14678 ++first_unchanged_at_end_row
;
14680 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14681 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14682 >= it
.last_visible_y
))
14683 first_unchanged_at_end_row
= NULL
;
14686 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
14688 first_unchanged_at_end_vpos
14689 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
14690 xassert (stop_pos
>= Z
- END_UNCHANGED
);
14693 else if (last_unchanged_at_beg_row
== NULL
)
14699 /* Either there is no unchanged row at the end, or the one we have
14700 now displays text. This is a necessary condition for the window
14701 end pos calculation at the end of this function. */
14702 xassert (first_unchanged_at_end_row
== NULL
14703 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
14705 debug_last_unchanged_at_beg_vpos
14706 = (last_unchanged_at_beg_row
14707 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
14709 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
14711 #endif /* GLYPH_DEBUG != 0 */
14714 /* Display new lines. Set last_text_row to the last new line
14715 displayed which has text on it, i.e. might end up as being the
14716 line where the window_end_vpos is. */
14717 w
->cursor
.vpos
= -1;
14718 last_text_row
= NULL
;
14719 overlay_arrow_seen
= 0;
14720 while (it
.current_y
< it
.last_visible_y
14721 && !fonts_changed_p
14722 && (first_unchanged_at_end_row
== NULL
14723 || IT_CHARPOS (it
) < stop_pos
))
14725 if (display_line (&it
))
14726 last_text_row
= it
.glyph_row
- 1;
14729 if (fonts_changed_p
)
14733 /* Compute differences in buffer positions, y-positions etc. for
14734 lines reused at the bottom of the window. Compute what we can
14736 if (first_unchanged_at_end_row
14737 /* No lines reused because we displayed everything up to the
14738 bottom of the window. */
14739 && it
.current_y
< it
.last_visible_y
)
14742 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
14744 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
14745 run
.current_y
= first_unchanged_at_end_row
->y
;
14746 run
.desired_y
= run
.current_y
+ dy
;
14747 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
14751 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
14752 first_unchanged_at_end_row
= NULL
;
14754 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14757 /* Find the cursor if not already found. We have to decide whether
14758 PT will appear on this window (it sometimes doesn't, but this is
14759 not a very frequent case.) This decision has to be made before
14760 the current matrix is altered. A value of cursor.vpos < 0 means
14761 that PT is either in one of the lines beginning at
14762 first_unchanged_at_end_row or below the window. Don't care for
14763 lines that might be displayed later at the window end; as
14764 mentioned, this is not a frequent case. */
14765 if (w
->cursor
.vpos
< 0)
14767 /* Cursor in unchanged rows at the top? */
14768 if (PT
< CHARPOS (start_pos
)
14769 && last_unchanged_at_beg_row
)
14771 row
= row_containing_pos (w
, PT
,
14772 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14773 last_unchanged_at_beg_row
+ 1, 0);
14775 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14778 /* Start from first_unchanged_at_end_row looking for PT. */
14779 else if (first_unchanged_at_end_row
)
14781 row
= row_containing_pos (w
, PT
- delta
,
14782 first_unchanged_at_end_row
, NULL
, 0);
14784 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14785 delta_bytes
, dy
, dvpos
);
14788 /* Give up if cursor was not found. */
14789 if (w
->cursor
.vpos
< 0)
14791 clear_glyph_matrix (w
->desired_matrix
);
14796 /* Don't let the cursor end in the scroll margins. */
14798 int this_scroll_margin
, cursor_height
;
14800 this_scroll_margin
= max (0, scroll_margin
);
14801 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14802 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14803 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14805 if ((w
->cursor
.y
< this_scroll_margin
14806 && CHARPOS (start
) > BEGV
)
14807 /* Old redisplay didn't take scroll margin into account at the bottom,
14808 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14809 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14810 ? cursor_height
+ this_scroll_margin
14811 : 1)) > it
.last_visible_y
)
14813 w
->cursor
.vpos
= -1;
14814 clear_glyph_matrix (w
->desired_matrix
);
14819 /* Scroll the display. Do it before changing the current matrix so
14820 that xterm.c doesn't get confused about where the cursor glyph is
14822 if (dy
&& run
.height
)
14826 if (FRAME_WINDOW_P (f
))
14828 rif
->update_window_begin_hook (w
);
14829 rif
->clear_window_mouse_face (w
);
14830 rif
->scroll_run_hook (w
, &run
);
14831 rif
->update_window_end_hook (w
, 0, 0);
14835 /* Terminal frame. In this case, dvpos gives the number of
14836 lines to scroll by; dvpos < 0 means scroll up. */
14837 int first_unchanged_at_end_vpos
14838 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14839 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14840 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14841 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14842 + window_internal_height (w
));
14844 /* Perform the operation on the screen. */
14847 /* Scroll last_unchanged_at_beg_row to the end of the
14848 window down dvpos lines. */
14849 set_terminal_window (end
);
14851 /* On dumb terminals delete dvpos lines at the end
14852 before inserting dvpos empty lines. */
14853 if (!scroll_region_ok
)
14854 ins_del_lines (end
- dvpos
, -dvpos
);
14856 /* Insert dvpos empty lines in front of
14857 last_unchanged_at_beg_row. */
14858 ins_del_lines (from
, dvpos
);
14860 else if (dvpos
< 0)
14862 /* Scroll up last_unchanged_at_beg_vpos to the end of
14863 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14864 set_terminal_window (end
);
14866 /* Delete dvpos lines in front of
14867 last_unchanged_at_beg_vpos. ins_del_lines will set
14868 the cursor to the given vpos and emit |dvpos| delete
14870 ins_del_lines (from
+ dvpos
, dvpos
);
14872 /* On a dumb terminal insert dvpos empty lines at the
14874 if (!scroll_region_ok
)
14875 ins_del_lines (end
+ dvpos
, -dvpos
);
14878 set_terminal_window (0);
14884 /* Shift reused rows of the current matrix to the right position.
14885 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14887 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14888 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14891 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14892 bottom_vpos
, dvpos
);
14893 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14896 else if (dvpos
> 0)
14898 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14899 bottom_vpos
, dvpos
);
14900 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14901 first_unchanged_at_end_vpos
+ dvpos
, 0);
14904 /* For frame-based redisplay, make sure that current frame and window
14905 matrix are in sync with respect to glyph memory. */
14906 if (!FRAME_WINDOW_P (f
))
14907 sync_frame_with_window_matrix_rows (w
);
14909 /* Adjust buffer positions in reused rows. */
14910 if (delta
|| delta_bytes
)
14911 increment_matrix_positions (current_matrix
,
14912 first_unchanged_at_end_vpos
+ dvpos
,
14913 bottom_vpos
, delta
, delta_bytes
);
14915 /* Adjust Y positions. */
14917 shift_glyph_matrix (w
, current_matrix
,
14918 first_unchanged_at_end_vpos
+ dvpos
,
14921 if (first_unchanged_at_end_row
)
14923 first_unchanged_at_end_row
+= dvpos
;
14924 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14925 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
14926 first_unchanged_at_end_row
= NULL
;
14929 /* If scrolling up, there may be some lines to display at the end of
14931 last_text_row_at_end
= NULL
;
14934 /* Scrolling up can leave for example a partially visible line
14935 at the end of the window to be redisplayed. */
14936 /* Set last_row to the glyph row in the current matrix where the
14937 window end line is found. It has been moved up or down in
14938 the matrix by dvpos. */
14939 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
14940 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
14942 /* If last_row is the window end line, it should display text. */
14943 xassert (last_row
->displays_text_p
);
14945 /* If window end line was partially visible before, begin
14946 displaying at that line. Otherwise begin displaying with the
14947 line following it. */
14948 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
14950 init_to_row_start (&it
, w
, last_row
);
14951 it
.vpos
= last_vpos
;
14952 it
.current_y
= last_row
->y
;
14956 init_to_row_end (&it
, w
, last_row
);
14957 it
.vpos
= 1 + last_vpos
;
14958 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
14962 /* We may start in a continuation line. If so, we have to
14963 get the right continuation_lines_width and current_x. */
14964 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
14965 it
.hpos
= it
.current_x
= 0;
14967 /* Display the rest of the lines at the window end. */
14968 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14969 while (it
.current_y
< it
.last_visible_y
14970 && !fonts_changed_p
)
14972 /* Is it always sure that the display agrees with lines in
14973 the current matrix? I don't think so, so we mark rows
14974 displayed invalid in the current matrix by setting their
14975 enabled_p flag to zero. */
14976 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
14977 if (display_line (&it
))
14978 last_text_row_at_end
= it
.glyph_row
- 1;
14982 /* Update window_end_pos and window_end_vpos. */
14983 if (first_unchanged_at_end_row
14984 && !last_text_row_at_end
)
14986 /* Window end line if one of the preserved rows from the current
14987 matrix. Set row to the last row displaying text in current
14988 matrix starting at first_unchanged_at_end_row, after
14990 xassert (first_unchanged_at_end_row
->displays_text_p
);
14991 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
14992 first_unchanged_at_end_row
);
14993 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
14995 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14996 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14998 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
14999 xassert (w
->window_end_bytepos
>= 0);
15000 IF_DEBUG (debug_method_add (w
, "A"));
15002 else if (last_text_row_at_end
)
15005 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
15006 w
->window_end_bytepos
15007 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
15009 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
15010 xassert (w
->window_end_bytepos
>= 0);
15011 IF_DEBUG (debug_method_add (w
, "B"));
15013 else if (last_text_row
)
15015 /* We have displayed either to the end of the window or at the
15016 end of the window, i.e. the last row with text is to be found
15017 in the desired matrix. */
15019 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15020 w
->window_end_bytepos
15021 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15023 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
15024 xassert (w
->window_end_bytepos
>= 0);
15026 else if (first_unchanged_at_end_row
== NULL
15027 && last_text_row
== NULL
15028 && last_text_row_at_end
== NULL
)
15030 /* Displayed to end of window, but no line containing text was
15031 displayed. Lines were deleted at the end of the window. */
15032 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
15033 int vpos
= XFASTINT (w
->window_end_vpos
);
15034 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
15035 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
15038 row
== NULL
&& vpos
>= first_vpos
;
15039 --vpos
, --current_row
, --desired_row
)
15041 if (desired_row
->enabled_p
)
15043 if (desired_row
->displays_text_p
)
15046 else if (current_row
->displays_text_p
)
15050 xassert (row
!= NULL
);
15051 w
->window_end_vpos
= make_number (vpos
+ 1);
15052 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15053 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15054 xassert (w
->window_end_bytepos
>= 0);
15055 IF_DEBUG (debug_method_add (w
, "C"));
15060 #if 0 /* This leads to problems, for instance when the cursor is
15061 at ZV, and the cursor line displays no text. */
15062 /* Disable rows below what's displayed in the window. This makes
15063 debugging easier. */
15064 enable_glyph_matrix_rows (current_matrix
,
15065 XFASTINT (w
->window_end_vpos
) + 1,
15069 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15070 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15072 /* Record that display has not been completed. */
15073 w
->window_end_valid
= Qnil
;
15074 w
->desired_matrix
->no_scrolling_p
= 1;
15082 /***********************************************************************
15083 More debugging support
15084 ***********************************************************************/
15088 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15089 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15090 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15093 /* Dump the contents of glyph matrix MATRIX on stderr.
15095 GLYPHS 0 means don't show glyph contents.
15096 GLYPHS 1 means show glyphs in short form
15097 GLYPHS > 1 means show glyphs in long form. */
15100 dump_glyph_matrix (matrix
, glyphs
)
15101 struct glyph_matrix
*matrix
;
15105 for (i
= 0; i
< matrix
->nrows
; ++i
)
15106 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15110 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15111 the glyph row and area where the glyph comes from. */
15114 dump_glyph (row
, glyph
, area
)
15115 struct glyph_row
*row
;
15116 struct glyph
*glyph
;
15119 if (glyph
->type
== CHAR_GLYPH
)
15122 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15123 glyph
- row
->glyphs
[TEXT_AREA
],
15126 (BUFFERP (glyph
->object
)
15128 : (STRINGP (glyph
->object
)
15131 glyph
->pixel_width
,
15133 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15137 glyph
->left_box_line_p
,
15138 glyph
->right_box_line_p
);
15140 else if (glyph
->type
== STRETCH_GLYPH
)
15143 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15144 glyph
- row
->glyphs
[TEXT_AREA
],
15147 (BUFFERP (glyph
->object
)
15149 : (STRINGP (glyph
->object
)
15152 glyph
->pixel_width
,
15156 glyph
->left_box_line_p
,
15157 glyph
->right_box_line_p
);
15159 else if (glyph
->type
== IMAGE_GLYPH
)
15162 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15163 glyph
- row
->glyphs
[TEXT_AREA
],
15166 (BUFFERP (glyph
->object
)
15168 : (STRINGP (glyph
->object
)
15171 glyph
->pixel_width
,
15175 glyph
->left_box_line_p
,
15176 glyph
->right_box_line_p
);
15178 else if (glyph
->type
== COMPOSITE_GLYPH
)
15181 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15182 glyph
- row
->glyphs
[TEXT_AREA
],
15185 (BUFFERP (glyph
->object
)
15187 : (STRINGP (glyph
->object
)
15190 glyph
->pixel_width
,
15194 glyph
->left_box_line_p
,
15195 glyph
->right_box_line_p
);
15200 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15201 GLYPHS 0 means don't show glyph contents.
15202 GLYPHS 1 means show glyphs in short form
15203 GLYPHS > 1 means show glyphs in long form. */
15206 dump_glyph_row (row
, vpos
, glyphs
)
15207 struct glyph_row
*row
;
15212 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15213 fprintf (stderr
, "======================================================================\n");
15215 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15216 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15218 MATRIX_ROW_START_CHARPOS (row
),
15219 MATRIX_ROW_END_CHARPOS (row
),
15220 row
->used
[TEXT_AREA
],
15221 row
->contains_overlapping_glyphs_p
,
15223 row
->truncated_on_left_p
,
15224 row
->truncated_on_right_p
,
15226 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15227 row
->displays_text_p
,
15230 row
->ends_in_middle_of_char_p
,
15231 row
->starts_in_middle_of_char_p
,
15237 row
->visible_height
,
15240 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15241 row
->end
.overlay_string_index
,
15242 row
->continuation_lines_width
);
15243 fprintf (stderr
, "%9d %5d\n",
15244 CHARPOS (row
->start
.string_pos
),
15245 CHARPOS (row
->end
.string_pos
));
15246 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15247 row
->end
.dpvec_index
);
15254 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15256 struct glyph
*glyph
= row
->glyphs
[area
];
15257 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15259 /* Glyph for a line end in text. */
15260 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15263 if (glyph
< glyph_end
)
15264 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15266 for (; glyph
< glyph_end
; ++glyph
)
15267 dump_glyph (row
, glyph
, area
);
15270 else if (glyphs
== 1)
15274 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15276 char *s
= (char *) alloca (row
->used
[area
] + 1);
15279 for (i
= 0; i
< row
->used
[area
]; ++i
)
15281 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15282 if (glyph
->type
== CHAR_GLYPH
15283 && glyph
->u
.ch
< 0x80
15284 && glyph
->u
.ch
>= ' ')
15285 s
[i
] = glyph
->u
.ch
;
15291 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15297 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15298 Sdump_glyph_matrix
, 0, 1, "p",
15299 doc
: /* Dump the current matrix of the selected window to stderr.
15300 Shows contents of glyph row structures. With non-nil
15301 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15302 glyphs in short form, otherwise show glyphs in long form. */)
15304 Lisp_Object glyphs
;
15306 struct window
*w
= XWINDOW (selected_window
);
15307 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15309 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15310 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15311 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15312 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15313 fprintf (stderr
, "=============================================\n");
15314 dump_glyph_matrix (w
->current_matrix
,
15315 NILP (glyphs
) ? 0 : XINT (glyphs
));
15320 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15321 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15324 struct frame
*f
= XFRAME (selected_frame
);
15325 dump_glyph_matrix (f
->current_matrix
, 1);
15330 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15331 doc
: /* Dump glyph row ROW to stderr.
15332 GLYPH 0 means don't dump glyphs.
15333 GLYPH 1 means dump glyphs in short form.
15334 GLYPH > 1 or omitted means dump glyphs in long form. */)
15336 Lisp_Object row
, glyphs
;
15338 struct glyph_matrix
*matrix
;
15341 CHECK_NUMBER (row
);
15342 matrix
= XWINDOW (selected_window
)->current_matrix
;
15344 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15345 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15347 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15352 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15353 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15354 GLYPH 0 means don't dump glyphs.
15355 GLYPH 1 means dump glyphs in short form.
15356 GLYPH > 1 or omitted means dump glyphs in long form. */)
15358 Lisp_Object row
, glyphs
;
15360 struct frame
*sf
= SELECTED_FRAME ();
15361 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15364 CHECK_NUMBER (row
);
15366 if (vpos
>= 0 && vpos
< m
->nrows
)
15367 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15368 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15373 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15374 doc
: /* Toggle tracing of redisplay.
15375 With ARG, turn tracing on if and only if ARG is positive. */)
15380 trace_redisplay_p
= !trace_redisplay_p
;
15383 arg
= Fprefix_numeric_value (arg
);
15384 trace_redisplay_p
= XINT (arg
) > 0;
15391 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15392 doc
: /* Like `format', but print result to stderr.
15393 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15398 Lisp_Object s
= Fformat (nargs
, args
);
15399 fprintf (stderr
, "%s", SDATA (s
));
15403 #endif /* GLYPH_DEBUG */
15407 /***********************************************************************
15408 Building Desired Matrix Rows
15409 ***********************************************************************/
15411 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15412 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15414 static struct glyph_row
*
15415 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15417 Lisp_Object overlay_arrow_string
;
15419 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15420 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15421 struct buffer
*old
= current_buffer
;
15422 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15423 int arrow_len
= SCHARS (overlay_arrow_string
);
15424 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15425 const unsigned char *p
;
15428 int n_glyphs_before
;
15430 set_buffer_temp (buffer
);
15431 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15432 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15433 SET_TEXT_POS (it
.position
, 0, 0);
15435 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15437 while (p
< arrow_end
)
15439 Lisp_Object face
, ilisp
;
15441 /* Get the next character. */
15443 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15445 it
.c
= *p
, it
.len
= 1;
15448 /* Get its face. */
15449 ilisp
= make_number (p
- arrow_string
);
15450 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15451 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15453 /* Compute its width, get its glyphs. */
15454 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15455 SET_TEXT_POS (it
.position
, -1, -1);
15456 PRODUCE_GLYPHS (&it
);
15458 /* If this character doesn't fit any more in the line, we have
15459 to remove some glyphs. */
15460 if (it
.current_x
> it
.last_visible_x
)
15462 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15467 set_buffer_temp (old
);
15468 return it
.glyph_row
;
15472 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15473 glyphs are only inserted for terminal frames since we can't really
15474 win with truncation glyphs when partially visible glyphs are
15475 involved. Which glyphs to insert is determined by
15476 produce_special_glyphs. */
15479 insert_left_trunc_glyphs (it
)
15482 struct it truncate_it
;
15483 struct glyph
*from
, *end
, *to
, *toend
;
15485 xassert (!FRAME_WINDOW_P (it
->f
));
15487 /* Get the truncation glyphs. */
15489 truncate_it
.current_x
= 0;
15490 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15491 truncate_it
.glyph_row
= &scratch_glyph_row
;
15492 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15493 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15494 truncate_it
.object
= make_number (0);
15495 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15497 /* Overwrite glyphs from IT with truncation glyphs. */
15498 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15499 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15500 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15501 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15506 /* There may be padding glyphs left over. Overwrite them too. */
15507 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15509 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15515 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15519 /* Compute the pixel height and width of IT->glyph_row.
15521 Most of the time, ascent and height of a display line will be equal
15522 to the max_ascent and max_height values of the display iterator
15523 structure. This is not the case if
15525 1. We hit ZV without displaying anything. In this case, max_ascent
15526 and max_height will be zero.
15528 2. We have some glyphs that don't contribute to the line height.
15529 (The glyph row flag contributes_to_line_height_p is for future
15530 pixmap extensions).
15532 The first case is easily covered by using default values because in
15533 these cases, the line height does not really matter, except that it
15534 must not be zero. */
15537 compute_line_metrics (it
)
15540 struct glyph_row
*row
= it
->glyph_row
;
15543 if (FRAME_WINDOW_P (it
->f
))
15545 int i
, min_y
, max_y
;
15547 /* The line may consist of one space only, that was added to
15548 place the cursor on it. If so, the row's height hasn't been
15550 if (row
->height
== 0)
15552 if (it
->max_ascent
+ it
->max_descent
== 0)
15553 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15554 row
->ascent
= it
->max_ascent
;
15555 row
->height
= it
->max_ascent
+ it
->max_descent
;
15556 row
->phys_ascent
= it
->max_phys_ascent
;
15557 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15558 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15561 /* Compute the width of this line. */
15562 row
->pixel_width
= row
->x
;
15563 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15564 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15566 xassert (row
->pixel_width
>= 0);
15567 xassert (row
->ascent
>= 0 && row
->height
> 0);
15569 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15570 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15572 /* If first line's physical ascent is larger than its logical
15573 ascent, use the physical ascent, and make the row taller.
15574 This makes accented characters fully visible. */
15575 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15576 && row
->phys_ascent
> row
->ascent
)
15578 row
->height
+= row
->phys_ascent
- row
->ascent
;
15579 row
->ascent
= row
->phys_ascent
;
15582 /* Compute how much of the line is visible. */
15583 row
->visible_height
= row
->height
;
15585 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
15586 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
15588 if (row
->y
< min_y
)
15589 row
->visible_height
-= min_y
- row
->y
;
15590 if (row
->y
+ row
->height
> max_y
)
15591 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15595 row
->pixel_width
= row
->used
[TEXT_AREA
];
15596 if (row
->continued_p
)
15597 row
->pixel_width
-= it
->continuation_pixel_width
;
15598 else if (row
->truncated_on_right_p
)
15599 row
->pixel_width
-= it
->truncation_pixel_width
;
15600 row
->ascent
= row
->phys_ascent
= 0;
15601 row
->height
= row
->phys_height
= row
->visible_height
= 1;
15602 row
->extra_line_spacing
= 0;
15605 /* Compute a hash code for this row. */
15607 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15608 for (i
= 0; i
< row
->used
[area
]; ++i
)
15609 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
15610 + row
->glyphs
[area
][i
].u
.val
15611 + row
->glyphs
[area
][i
].face_id
15612 + row
->glyphs
[area
][i
].padding_p
15613 + (row
->glyphs
[area
][i
].type
<< 2));
15615 it
->max_ascent
= it
->max_descent
= 0;
15616 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
15620 /* Append one space to the glyph row of iterator IT if doing a
15621 window-based redisplay. The space has the same face as
15622 IT->face_id. Value is non-zero if a space was added.
15624 This function is called to make sure that there is always one glyph
15625 at the end of a glyph row that the cursor can be set on under
15626 window-systems. (If there weren't such a glyph we would not know
15627 how wide and tall a box cursor should be displayed).
15629 At the same time this space let's a nicely handle clearing to the
15630 end of the line if the row ends in italic text. */
15633 append_space_for_newline (it
, default_face_p
)
15635 int default_face_p
;
15637 if (FRAME_WINDOW_P (it
->f
))
15639 int n
= it
->glyph_row
->used
[TEXT_AREA
];
15641 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
15642 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
15644 /* Save some values that must not be changed.
15645 Must save IT->c and IT->len because otherwise
15646 ITERATOR_AT_END_P wouldn't work anymore after
15647 append_space_for_newline has been called. */
15648 enum display_element_type saved_what
= it
->what
;
15649 int saved_c
= it
->c
, saved_len
= it
->len
;
15650 int saved_x
= it
->current_x
;
15651 int saved_face_id
= it
->face_id
;
15652 struct text_pos saved_pos
;
15653 Lisp_Object saved_object
;
15656 saved_object
= it
->object
;
15657 saved_pos
= it
->position
;
15659 it
->what
= IT_CHARACTER
;
15660 bzero (&it
->position
, sizeof it
->position
);
15661 it
->object
= make_number (0);
15665 if (default_face_p
)
15666 it
->face_id
= DEFAULT_FACE_ID
;
15667 else if (it
->face_before_selective_p
)
15668 it
->face_id
= it
->saved_face_id
;
15669 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15670 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
15672 PRODUCE_GLYPHS (it
);
15674 it
->override_ascent
= -1;
15675 it
->constrain_row_ascent_descent_p
= 0;
15676 it
->current_x
= saved_x
;
15677 it
->object
= saved_object
;
15678 it
->position
= saved_pos
;
15679 it
->what
= saved_what
;
15680 it
->face_id
= saved_face_id
;
15681 it
->len
= saved_len
;
15691 /* Extend the face of the last glyph in the text area of IT->glyph_row
15692 to the end of the display line. Called from display_line.
15693 If the glyph row is empty, add a space glyph to it so that we
15694 know the face to draw. Set the glyph row flag fill_line_p. */
15697 extend_face_to_end_of_line (it
)
15701 struct frame
*f
= it
->f
;
15703 /* If line is already filled, do nothing. */
15704 if (it
->current_x
>= it
->last_visible_x
)
15707 /* Face extension extends the background and box of IT->face_id
15708 to the end of the line. If the background equals the background
15709 of the frame, we don't have to do anything. */
15710 if (it
->face_before_selective_p
)
15711 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
15713 face
= FACE_FROM_ID (f
, it
->face_id
);
15715 if (FRAME_WINDOW_P (f
)
15716 && it
->glyph_row
->displays_text_p
15717 && face
->box
== FACE_NO_BOX
15718 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
15722 /* Set the glyph row flag indicating that the face of the last glyph
15723 in the text area has to be drawn to the end of the text area. */
15724 it
->glyph_row
->fill_line_p
= 1;
15726 /* If current character of IT is not ASCII, make sure we have the
15727 ASCII face. This will be automatically undone the next time
15728 get_next_display_element returns a multibyte character. Note
15729 that the character will always be single byte in unibyte text. */
15730 if (!SINGLE_BYTE_CHAR_P (it
->c
))
15732 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
15735 if (FRAME_WINDOW_P (f
))
15737 /* If the row is empty, add a space with the current face of IT,
15738 so that we know which face to draw. */
15739 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
15741 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
15742 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
15743 it
->glyph_row
->used
[TEXT_AREA
] = 1;
15748 /* Save some values that must not be changed. */
15749 int saved_x
= it
->current_x
;
15750 struct text_pos saved_pos
;
15751 Lisp_Object saved_object
;
15752 enum display_element_type saved_what
= it
->what
;
15753 int saved_face_id
= it
->face_id
;
15755 saved_object
= it
->object
;
15756 saved_pos
= it
->position
;
15758 it
->what
= IT_CHARACTER
;
15759 bzero (&it
->position
, sizeof it
->position
);
15760 it
->object
= make_number (0);
15763 it
->face_id
= face
->id
;
15765 PRODUCE_GLYPHS (it
);
15767 while (it
->current_x
<= it
->last_visible_x
)
15768 PRODUCE_GLYPHS (it
);
15770 /* Don't count these blanks really. It would let us insert a left
15771 truncation glyph below and make us set the cursor on them, maybe. */
15772 it
->current_x
= saved_x
;
15773 it
->object
= saved_object
;
15774 it
->position
= saved_pos
;
15775 it
->what
= saved_what
;
15776 it
->face_id
= saved_face_id
;
15781 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15782 trailing whitespace. */
15785 trailing_whitespace_p (charpos
)
15788 int bytepos
= CHAR_TO_BYTE (charpos
);
15791 while (bytepos
< ZV_BYTE
15792 && (c
= FETCH_CHAR (bytepos
),
15793 c
== ' ' || c
== '\t'))
15796 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15798 if (bytepos
!= PT_BYTE
)
15805 /* Highlight trailing whitespace, if any, in ROW. */
15808 highlight_trailing_whitespace (f
, row
)
15810 struct glyph_row
*row
;
15812 int used
= row
->used
[TEXT_AREA
];
15816 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15817 struct glyph
*glyph
= start
+ used
- 1;
15819 /* Skip over glyphs inserted to display the cursor at the
15820 end of a line, for extending the face of the last glyph
15821 to the end of the line on terminals, and for truncation
15822 and continuation glyphs. */
15823 while (glyph
>= start
15824 && glyph
->type
== CHAR_GLYPH
15825 && INTEGERP (glyph
->object
))
15828 /* If last glyph is a space or stretch, and it's trailing
15829 whitespace, set the face of all trailing whitespace glyphs in
15830 IT->glyph_row to `trailing-whitespace'. */
15832 && BUFFERP (glyph
->object
)
15833 && (glyph
->type
== STRETCH_GLYPH
15834 || (glyph
->type
== CHAR_GLYPH
15835 && glyph
->u
.ch
== ' '))
15836 && trailing_whitespace_p (glyph
->charpos
))
15838 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
15842 while (glyph
>= start
15843 && BUFFERP (glyph
->object
)
15844 && (glyph
->type
== STRETCH_GLYPH
15845 || (glyph
->type
== CHAR_GLYPH
15846 && glyph
->u
.ch
== ' ')))
15847 (glyph
--)->face_id
= face_id
;
15853 /* Value is non-zero if glyph row ROW in window W should be
15854 used to hold the cursor. */
15857 cursor_row_p (w
, row
)
15859 struct glyph_row
*row
;
15861 int cursor_row_p
= 1;
15863 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15865 /* Suppose the row ends on a string.
15866 Unless the row is continued, that means it ends on a newline
15867 in the string. If it's anything other than a display string
15868 (e.g. a before-string from an overlay), we don't want the
15869 cursor there. (This heuristic seems to give the optimal
15870 behavior for the various types of multi-line strings.) */
15871 if (CHARPOS (row
->end
.string_pos
) >= 0)
15873 if (row
->continued_p
)
15877 /* Check for `display' property. */
15878 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
15879 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
15880 struct glyph
*glyph
;
15883 for (glyph
= end
; glyph
>= beg
; --glyph
)
15884 if (STRINGP (glyph
->object
))
15887 = Fget_char_property (make_number (PT
),
15891 && display_prop_string_p (prop
, glyph
->object
));
15896 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15898 /* If the row ends in middle of a real character,
15899 and the line is continued, we want the cursor here.
15900 That's because MATRIX_ROW_END_CHARPOS would equal
15901 PT if PT is before the character. */
15902 if (!row
->ends_in_ellipsis_p
)
15903 cursor_row_p
= row
->continued_p
;
15905 /* If the row ends in an ellipsis, then
15906 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15907 We want that position to be displayed after the ellipsis. */
15910 /* If the row ends at ZV, display the cursor at the end of that
15911 row instead of at the start of the row below. */
15912 else if (row
->ends_at_zv_p
)
15918 return cursor_row_p
;
15922 /* Construct the glyph row IT->glyph_row in the desired matrix of
15923 IT->w from text at the current position of IT. See dispextern.h
15924 for an overview of struct it. Value is non-zero if
15925 IT->glyph_row displays text, as opposed to a line displaying ZV
15932 struct glyph_row
*row
= it
->glyph_row
;
15933 Lisp_Object overlay_arrow_string
;
15935 /* We always start displaying at hpos zero even if hscrolled. */
15936 xassert (it
->hpos
== 0 && it
->current_x
== 0);
15938 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
15939 >= it
->w
->desired_matrix
->nrows
)
15941 it
->w
->nrows_scale_factor
++;
15942 fonts_changed_p
= 1;
15946 /* Is IT->w showing the region? */
15947 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
15949 /* Clear the result glyph row and enable it. */
15950 prepare_desired_row (row
);
15952 row
->y
= it
->current_y
;
15953 row
->start
= it
->start
;
15954 row
->continuation_lines_width
= it
->continuation_lines_width
;
15955 row
->displays_text_p
= 1;
15956 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
15957 it
->starts_in_middle_of_char_p
= 0;
15959 /* Arrange the overlays nicely for our purposes. Usually, we call
15960 display_line on only one line at a time, in which case this
15961 can't really hurt too much, or we call it on lines which appear
15962 one after another in the buffer, in which case all calls to
15963 recenter_overlay_lists but the first will be pretty cheap. */
15964 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
15966 /* Move over display elements that are not visible because we are
15967 hscrolled. This may stop at an x-position < IT->first_visible_x
15968 if the first glyph is partially visible or if we hit a line end. */
15969 if (it
->current_x
< it
->first_visible_x
)
15971 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
15972 MOVE_TO_POS
| MOVE_TO_X
);
15975 /* Get the initial row height. This is either the height of the
15976 text hscrolled, if there is any, or zero. */
15977 row
->ascent
= it
->max_ascent
;
15978 row
->height
= it
->max_ascent
+ it
->max_descent
;
15979 row
->phys_ascent
= it
->max_phys_ascent
;
15980 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15981 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15983 /* Loop generating characters. The loop is left with IT on the next
15984 character to display. */
15987 int n_glyphs_before
, hpos_before
, x_before
;
15989 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
15991 /* Retrieve the next thing to display. Value is zero if end of
15993 if (!get_next_display_element (it
))
15995 /* Maybe add a space at the end of this line that is used to
15996 display the cursor there under X. Set the charpos of the
15997 first glyph of blank lines not corresponding to any text
15999 #ifdef HAVE_WINDOW_SYSTEM
16000 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16001 row
->exact_window_width_line_p
= 1;
16003 #endif /* HAVE_WINDOW_SYSTEM */
16004 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
16005 || row
->used
[TEXT_AREA
] == 0)
16007 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
16008 row
->displays_text_p
= 0;
16010 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
16011 && (!MINI_WINDOW_P (it
->w
)
16012 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
16013 row
->indicate_empty_line_p
= 1;
16016 it
->continuation_lines_width
= 0;
16017 row
->ends_at_zv_p
= 1;
16021 /* Now, get the metrics of what we want to display. This also
16022 generates glyphs in `row' (which is IT->glyph_row). */
16023 n_glyphs_before
= row
->used
[TEXT_AREA
];
16026 /* Remember the line height so far in case the next element doesn't
16027 fit on the line. */
16028 if (!it
->truncate_lines_p
)
16030 ascent
= it
->max_ascent
;
16031 descent
= it
->max_descent
;
16032 phys_ascent
= it
->max_phys_ascent
;
16033 phys_descent
= it
->max_phys_descent
;
16036 PRODUCE_GLYPHS (it
);
16038 /* If this display element was in marginal areas, continue with
16040 if (it
->area
!= TEXT_AREA
)
16042 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16043 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16044 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16045 row
->phys_height
= max (row
->phys_height
,
16046 it
->max_phys_ascent
+ it
->max_phys_descent
);
16047 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16048 it
->max_extra_line_spacing
);
16049 set_iterator_to_next (it
, 1);
16053 /* Does the display element fit on the line? If we truncate
16054 lines, we should draw past the right edge of the window. If
16055 we don't truncate, we want to stop so that we can display the
16056 continuation glyph before the right margin. If lines are
16057 continued, there are two possible strategies for characters
16058 resulting in more than 1 glyph (e.g. tabs): Display as many
16059 glyphs as possible in this line and leave the rest for the
16060 continuation line, or display the whole element in the next
16061 line. Original redisplay did the former, so we do it also. */
16062 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
16063 hpos_before
= it
->hpos
;
16066 if (/* Not a newline. */
16068 /* Glyphs produced fit entirely in the line. */
16069 && it
->current_x
< it
->last_visible_x
)
16071 it
->hpos
+= nglyphs
;
16072 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16073 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16074 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16075 row
->phys_height
= max (row
->phys_height
,
16076 it
->max_phys_ascent
+ it
->max_phys_descent
);
16077 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16078 it
->max_extra_line_spacing
);
16079 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
16080 row
->x
= x
- it
->first_visible_x
;
16085 struct glyph
*glyph
;
16087 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
16089 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16090 new_x
= x
+ glyph
->pixel_width
;
16092 if (/* Lines are continued. */
16093 !it
->truncate_lines_p
16094 && (/* Glyph doesn't fit on the line. */
16095 new_x
> it
->last_visible_x
16096 /* Or it fits exactly on a window system frame. */
16097 || (new_x
== it
->last_visible_x
16098 && FRAME_WINDOW_P (it
->f
))))
16100 /* End of a continued line. */
16103 || (new_x
== it
->last_visible_x
16104 && FRAME_WINDOW_P (it
->f
)))
16106 /* Current glyph is the only one on the line or
16107 fits exactly on the line. We must continue
16108 the line because we can't draw the cursor
16109 after the glyph. */
16110 row
->continued_p
= 1;
16111 it
->current_x
= new_x
;
16112 it
->continuation_lines_width
+= new_x
;
16114 if (i
== nglyphs
- 1)
16116 set_iterator_to_next (it
, 1);
16117 #ifdef HAVE_WINDOW_SYSTEM
16118 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16120 if (!get_next_display_element (it
))
16122 row
->exact_window_width_line_p
= 1;
16123 it
->continuation_lines_width
= 0;
16124 row
->continued_p
= 0;
16125 row
->ends_at_zv_p
= 1;
16127 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16129 row
->continued_p
= 0;
16130 row
->exact_window_width_line_p
= 1;
16133 #endif /* HAVE_WINDOW_SYSTEM */
16136 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16137 && !FRAME_WINDOW_P (it
->f
))
16139 /* A padding glyph that doesn't fit on this line.
16140 This means the whole character doesn't fit
16142 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16144 /* Fill the rest of the row with continuation
16145 glyphs like in 20.x. */
16146 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16147 < row
->glyphs
[1 + TEXT_AREA
])
16148 produce_special_glyphs (it
, IT_CONTINUATION
);
16150 row
->continued_p
= 1;
16151 it
->current_x
= x_before
;
16152 it
->continuation_lines_width
+= x_before
;
16154 /* Restore the height to what it was before the
16155 element not fitting on the line. */
16156 it
->max_ascent
= ascent
;
16157 it
->max_descent
= descent
;
16158 it
->max_phys_ascent
= phys_ascent
;
16159 it
->max_phys_descent
= phys_descent
;
16161 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16163 /* A TAB that extends past the right edge of the
16164 window. This produces a single glyph on
16165 window system frames. We leave the glyph in
16166 this row and let it fill the row, but don't
16167 consume the TAB. */
16168 it
->continuation_lines_width
+= it
->last_visible_x
;
16169 row
->ends_in_middle_of_char_p
= 1;
16170 row
->continued_p
= 1;
16171 glyph
->pixel_width
= it
->last_visible_x
- x
;
16172 it
->starts_in_middle_of_char_p
= 1;
16176 /* Something other than a TAB that draws past
16177 the right edge of the window. Restore
16178 positions to values before the element. */
16179 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16181 /* Display continuation glyphs. */
16182 if (!FRAME_WINDOW_P (it
->f
))
16183 produce_special_glyphs (it
, IT_CONTINUATION
);
16184 row
->continued_p
= 1;
16186 it
->current_x
= x_before
;
16187 it
->continuation_lines_width
+= x
;
16188 extend_face_to_end_of_line (it
);
16190 if (nglyphs
> 1 && i
> 0)
16192 row
->ends_in_middle_of_char_p
= 1;
16193 it
->starts_in_middle_of_char_p
= 1;
16196 /* Restore the height to what it was before the
16197 element not fitting on the line. */
16198 it
->max_ascent
= ascent
;
16199 it
->max_descent
= descent
;
16200 it
->max_phys_ascent
= phys_ascent
;
16201 it
->max_phys_descent
= phys_descent
;
16206 else if (new_x
> it
->first_visible_x
)
16208 /* Increment number of glyphs actually displayed. */
16211 if (x
< it
->first_visible_x
)
16212 /* Glyph is partially visible, i.e. row starts at
16213 negative X position. */
16214 row
->x
= x
- it
->first_visible_x
;
16218 /* Glyph is completely off the left margin of the
16219 window. This should not happen because of the
16220 move_it_in_display_line at the start of this
16221 function, unless the text display area of the
16222 window is empty. */
16223 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16227 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16228 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16229 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16230 row
->phys_height
= max (row
->phys_height
,
16231 it
->max_phys_ascent
+ it
->max_phys_descent
);
16232 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16233 it
->max_extra_line_spacing
);
16235 /* End of this display line if row is continued. */
16236 if (row
->continued_p
|| row
->ends_at_zv_p
)
16241 /* Is this a line end? If yes, we're also done, after making
16242 sure that a non-default face is extended up to the right
16243 margin of the window. */
16244 if (ITERATOR_AT_END_OF_LINE_P (it
))
16246 int used_before
= row
->used
[TEXT_AREA
];
16248 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16250 #ifdef HAVE_WINDOW_SYSTEM
16251 /* Add a space at the end of the line that is used to
16252 display the cursor there. */
16253 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16254 append_space_for_newline (it
, 0);
16255 #endif /* HAVE_WINDOW_SYSTEM */
16257 /* Extend the face to the end of the line. */
16258 extend_face_to_end_of_line (it
);
16260 /* Make sure we have the position. */
16261 if (used_before
== 0)
16262 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16264 /* Consume the line end. This skips over invisible lines. */
16265 set_iterator_to_next (it
, 1);
16266 it
->continuation_lines_width
= 0;
16270 /* Proceed with next display element. Note that this skips
16271 over lines invisible because of selective display. */
16272 set_iterator_to_next (it
, 1);
16274 /* If we truncate lines, we are done when the last displayed
16275 glyphs reach past the right margin of the window. */
16276 if (it
->truncate_lines_p
16277 && (FRAME_WINDOW_P (it
->f
)
16278 ? (it
->current_x
>= it
->last_visible_x
)
16279 : (it
->current_x
> it
->last_visible_x
)))
16281 /* Maybe add truncation glyphs. */
16282 if (!FRAME_WINDOW_P (it
->f
))
16286 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16287 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16290 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16292 row
->used
[TEXT_AREA
] = i
;
16293 produce_special_glyphs (it
, IT_TRUNCATION
);
16296 #ifdef HAVE_WINDOW_SYSTEM
16299 /* Don't truncate if we can overflow newline into fringe. */
16300 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16302 if (!get_next_display_element (it
))
16304 it
->continuation_lines_width
= 0;
16305 row
->ends_at_zv_p
= 1;
16306 row
->exact_window_width_line_p
= 1;
16309 if (ITERATOR_AT_END_OF_LINE_P (it
))
16311 row
->exact_window_width_line_p
= 1;
16312 goto at_end_of_line
;
16316 #endif /* HAVE_WINDOW_SYSTEM */
16318 row
->truncated_on_right_p
= 1;
16319 it
->continuation_lines_width
= 0;
16320 reseat_at_next_visible_line_start (it
, 0);
16321 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16322 it
->hpos
= hpos_before
;
16323 it
->current_x
= x_before
;
16328 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16329 at the left window margin. */
16330 if (it
->first_visible_x
16331 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16333 if (!FRAME_WINDOW_P (it
->f
))
16334 insert_left_trunc_glyphs (it
);
16335 row
->truncated_on_left_p
= 1;
16338 /* If the start of this line is the overlay arrow-position, then
16339 mark this glyph row as the one containing the overlay arrow.
16340 This is clearly a mess with variable size fonts. It would be
16341 better to let it be displayed like cursors under X. */
16342 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16343 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16344 !NILP (overlay_arrow_string
)))
16346 /* Overlay arrow in window redisplay is a fringe bitmap. */
16347 if (STRINGP (overlay_arrow_string
))
16349 struct glyph_row
*arrow_row
16350 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16351 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16352 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16353 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16354 struct glyph
*p2
, *end
;
16356 /* Copy the arrow glyphs. */
16357 while (glyph
< arrow_end
)
16360 /* Throw away padding glyphs. */
16362 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16363 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16369 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16374 xassert (INTEGERP (overlay_arrow_string
));
16375 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16377 overlay_arrow_seen
= 1;
16380 /* Compute pixel dimensions of this line. */
16381 compute_line_metrics (it
);
16383 /* Remember the position at which this line ends. */
16384 row
->end
= it
->current
;
16386 /* Record whether this row ends inside an ellipsis. */
16387 row
->ends_in_ellipsis_p
16388 = (it
->method
== GET_FROM_DISPLAY_VECTOR
16389 && it
->ellipsis_p
);
16391 /* Save fringe bitmaps in this row. */
16392 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
16393 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
16394 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
16395 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
16397 it
->left_user_fringe_bitmap
= 0;
16398 it
->left_user_fringe_face_id
= 0;
16399 it
->right_user_fringe_bitmap
= 0;
16400 it
->right_user_fringe_face_id
= 0;
16402 /* Maybe set the cursor. */
16403 if (it
->w
->cursor
.vpos
< 0
16404 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
16405 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
16406 && cursor_row_p (it
->w
, row
))
16407 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
16409 /* Highlight trailing whitespace. */
16410 if (!NILP (Vshow_trailing_whitespace
))
16411 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
16413 /* Prepare for the next line. This line starts horizontally at (X
16414 HPOS) = (0 0). Vertical positions are incremented. As a
16415 convenience for the caller, IT->glyph_row is set to the next
16417 it
->current_x
= it
->hpos
= 0;
16418 it
->current_y
+= row
->height
;
16421 it
->start
= it
->current
;
16422 return row
->displays_text_p
;
16427 /***********************************************************************
16429 ***********************************************************************/
16431 /* Redisplay the menu bar in the frame for window W.
16433 The menu bar of X frames that don't have X toolkit support is
16434 displayed in a special window W->frame->menu_bar_window.
16436 The menu bar of terminal frames is treated specially as far as
16437 glyph matrices are concerned. Menu bar lines are not part of
16438 windows, so the update is done directly on the frame matrix rows
16439 for the menu bar. */
16442 display_menu_bar (w
)
16445 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16450 /* Don't do all this for graphical frames. */
16452 if (!NILP (Vwindow_system
))
16455 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
16460 if (FRAME_MAC_P (f
))
16464 #ifdef USE_X_TOOLKIT
16465 xassert (!FRAME_WINDOW_P (f
));
16466 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
16467 it
.first_visible_x
= 0;
16468 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16469 #else /* not USE_X_TOOLKIT */
16470 if (FRAME_WINDOW_P (f
))
16472 /* Menu bar lines are displayed in the desired matrix of the
16473 dummy window menu_bar_window. */
16474 struct window
*menu_w
;
16475 xassert (WINDOWP (f
->menu_bar_window
));
16476 menu_w
= XWINDOW (f
->menu_bar_window
);
16477 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
16479 it
.first_visible_x
= 0;
16480 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16484 /* This is a TTY frame, i.e. character hpos/vpos are used as
16486 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
16488 it
.first_visible_x
= 0;
16489 it
.last_visible_x
= FRAME_COLS (f
);
16491 #endif /* not USE_X_TOOLKIT */
16493 if (! mode_line_inverse_video
)
16494 /* Force the menu-bar to be displayed in the default face. */
16495 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16497 /* Clear all rows of the menu bar. */
16498 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
16500 struct glyph_row
*row
= it
.glyph_row
+ i
;
16501 clear_glyph_row (row
);
16502 row
->enabled_p
= 1;
16503 row
->full_width_p
= 1;
16506 /* Display all items of the menu bar. */
16507 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
16508 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
16510 Lisp_Object string
;
16512 /* Stop at nil string. */
16513 string
= AREF (items
, i
+ 1);
16517 /* Remember where item was displayed. */
16518 AREF (items
, i
+ 3) = make_number (it
.hpos
);
16520 /* Display the item, pad with one space. */
16521 if (it
.current_x
< it
.last_visible_x
)
16522 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
16523 SCHARS (string
) + 1, 0, 0, -1);
16526 /* Fill out the line with spaces. */
16527 if (it
.current_x
< it
.last_visible_x
)
16528 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
16530 /* Compute the total height of the lines. */
16531 compute_line_metrics (&it
);
16536 /***********************************************************************
16538 ***********************************************************************/
16540 /* Redisplay mode lines in the window tree whose root is WINDOW. If
16541 FORCE is non-zero, redisplay mode lines unconditionally.
16542 Otherwise, redisplay only mode lines that are garbaged. Value is
16543 the number of windows whose mode lines were redisplayed. */
16546 redisplay_mode_lines (window
, force
)
16547 Lisp_Object window
;
16552 while (!NILP (window
))
16554 struct window
*w
= XWINDOW (window
);
16556 if (WINDOWP (w
->hchild
))
16557 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
16558 else if (WINDOWP (w
->vchild
))
16559 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
16561 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
16562 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
16564 struct text_pos lpoint
;
16565 struct buffer
*old
= current_buffer
;
16567 /* Set the window's buffer for the mode line display. */
16568 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16569 set_buffer_internal_1 (XBUFFER (w
->buffer
));
16571 /* Point refers normally to the selected window. For any
16572 other window, set up appropriate value. */
16573 if (!EQ (window
, selected_window
))
16575 struct text_pos pt
;
16577 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
16578 if (CHARPOS (pt
) < BEGV
)
16579 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16580 else if (CHARPOS (pt
) > (ZV
- 1))
16581 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
16583 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
16586 /* Display mode lines. */
16587 clear_glyph_matrix (w
->desired_matrix
);
16588 if (display_mode_lines (w
))
16591 w
->must_be_updated_p
= 1;
16594 /* Restore old settings. */
16595 set_buffer_internal_1 (old
);
16596 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16606 /* Display the mode and/or top line of window W. Value is the number
16607 of mode lines displayed. */
16610 display_mode_lines (w
)
16613 Lisp_Object old_selected_window
, old_selected_frame
;
16616 old_selected_frame
= selected_frame
;
16617 selected_frame
= w
->frame
;
16618 old_selected_window
= selected_window
;
16619 XSETWINDOW (selected_window
, w
);
16621 /* These will be set while the mode line specs are processed. */
16622 line_number_displayed
= 0;
16623 w
->column_number_displayed
= Qnil
;
16625 if (WINDOW_WANTS_MODELINE_P (w
))
16627 struct window
*sel_w
= XWINDOW (old_selected_window
);
16629 /* Select mode line face based on the real selected window. */
16630 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
16631 current_buffer
->mode_line_format
);
16635 if (WINDOW_WANTS_HEADER_LINE_P (w
))
16637 display_mode_line (w
, HEADER_LINE_FACE_ID
,
16638 current_buffer
->header_line_format
);
16642 selected_frame
= old_selected_frame
;
16643 selected_window
= old_selected_window
;
16648 /* Display mode or top line of window W. FACE_ID specifies which line
16649 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
16650 FORMAT is the mode line format to display. Value is the pixel
16651 height of the mode line displayed. */
16654 display_mode_line (w
, face_id
, format
)
16656 enum face_id face_id
;
16657 Lisp_Object format
;
16661 int count
= SPECPDL_INDEX ();
16663 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16664 /* Don't extend on a previously drawn mode-line.
16665 This may happen if called from pos_visible_p. */
16666 it
.glyph_row
->enabled_p
= 0;
16667 prepare_desired_row (it
.glyph_row
);
16669 it
.glyph_row
->mode_line_p
= 1;
16671 if (! mode_line_inverse_video
)
16672 /* Force the mode-line to be displayed in the default face. */
16673 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16675 record_unwind_protect (unwind_format_mode_line
,
16676 format_mode_line_unwind_data (NULL
, 0));
16678 mode_line_target
= MODE_LINE_DISPLAY
;
16680 /* Temporarily make frame's keyboard the current kboard so that
16681 kboard-local variables in the mode_line_format will get the right
16683 push_frame_kboard (it
.f
);
16684 record_unwind_save_match_data ();
16685 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16686 pop_frame_kboard ();
16688 unbind_to (count
, Qnil
);
16690 /* Fill up with spaces. */
16691 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
16693 compute_line_metrics (&it
);
16694 it
.glyph_row
->full_width_p
= 1;
16695 it
.glyph_row
->continued_p
= 0;
16696 it
.glyph_row
->truncated_on_left_p
= 0;
16697 it
.glyph_row
->truncated_on_right_p
= 0;
16699 /* Make a 3D mode-line have a shadow at its right end. */
16700 face
= FACE_FROM_ID (it
.f
, face_id
);
16701 extend_face_to_end_of_line (&it
);
16702 if (face
->box
!= FACE_NO_BOX
)
16704 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
16705 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
16706 last
->right_box_line_p
= 1;
16709 return it
.glyph_row
->height
;
16712 /* Move element ELT in LIST to the front of LIST.
16713 Return the updated list. */
16716 move_elt_to_front (elt
, list
)
16717 Lisp_Object elt
, list
;
16719 register Lisp_Object tail
, prev
;
16720 register Lisp_Object tem
;
16724 while (CONSP (tail
))
16730 /* Splice out the link TAIL. */
16732 list
= XCDR (tail
);
16734 Fsetcdr (prev
, XCDR (tail
));
16736 /* Now make it the first. */
16737 Fsetcdr (tail
, list
);
16742 tail
= XCDR (tail
);
16746 /* Not found--return unchanged LIST. */
16750 /* Contribute ELT to the mode line for window IT->w. How it
16751 translates into text depends on its data type.
16753 IT describes the display environment in which we display, as usual.
16755 DEPTH is the depth in recursion. It is used to prevent
16756 infinite recursion here.
16758 FIELD_WIDTH is the number of characters the display of ELT should
16759 occupy in the mode line, and PRECISION is the maximum number of
16760 characters to display from ELT's representation. See
16761 display_string for details.
16763 Returns the hpos of the end of the text generated by ELT.
16765 PROPS is a property list to add to any string we encounter.
16767 If RISKY is nonzero, remove (disregard) any properties in any string
16768 we encounter, and ignore :eval and :propertize.
16770 The global variable `mode_line_target' determines whether the
16771 output is passed to `store_mode_line_noprop',
16772 `store_mode_line_string', or `display_string'. */
16775 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
16778 int field_width
, precision
;
16779 Lisp_Object elt
, props
;
16782 int n
= 0, field
, prec
;
16787 elt
= build_string ("*too-deep*");
16791 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
16795 /* A string: output it and check for %-constructs within it. */
16799 if (SCHARS (elt
) > 0
16800 && (!NILP (props
) || risky
))
16802 Lisp_Object oprops
, aelt
;
16803 oprops
= Ftext_properties_at (make_number (0), elt
);
16805 /* If the starting string's properties are not what
16806 we want, translate the string. Also, if the string
16807 is risky, do that anyway. */
16809 if (NILP (Fequal (props
, oprops
)) || risky
)
16811 /* If the starting string has properties,
16812 merge the specified ones onto the existing ones. */
16813 if (! NILP (oprops
) && !risky
)
16817 oprops
= Fcopy_sequence (oprops
);
16819 while (CONSP (tem
))
16821 oprops
= Fplist_put (oprops
, XCAR (tem
),
16822 XCAR (XCDR (tem
)));
16823 tem
= XCDR (XCDR (tem
));
16828 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
16829 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
16831 /* AELT is what we want. Move it to the front
16832 without consing. */
16834 mode_line_proptrans_alist
16835 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
16841 /* If AELT has the wrong props, it is useless.
16842 so get rid of it. */
16844 mode_line_proptrans_alist
16845 = Fdelq (aelt
, mode_line_proptrans_alist
);
16847 elt
= Fcopy_sequence (elt
);
16848 Fset_text_properties (make_number (0), Flength (elt
),
16850 /* Add this item to mode_line_proptrans_alist. */
16851 mode_line_proptrans_alist
16852 = Fcons (Fcons (elt
, props
),
16853 mode_line_proptrans_alist
);
16854 /* Truncate mode_line_proptrans_alist
16855 to at most 50 elements. */
16856 tem
= Fnthcdr (make_number (50),
16857 mode_line_proptrans_alist
);
16859 XSETCDR (tem
, Qnil
);
16868 prec
= precision
- n
;
16869 switch (mode_line_target
)
16871 case MODE_LINE_NOPROP
:
16872 case MODE_LINE_TITLE
:
16873 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
16875 case MODE_LINE_STRING
:
16876 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
16878 case MODE_LINE_DISPLAY
:
16879 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
16880 0, prec
, 0, STRING_MULTIBYTE (elt
));
16887 /* Handle the non-literal case. */
16889 while ((precision
<= 0 || n
< precision
)
16890 && SREF (elt
, offset
) != 0
16891 && (mode_line_target
!= MODE_LINE_DISPLAY
16892 || it
->current_x
< it
->last_visible_x
))
16894 int last_offset
= offset
;
16896 /* Advance to end of string or next format specifier. */
16897 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
16900 if (offset
- 1 != last_offset
)
16902 int nchars
, nbytes
;
16904 /* Output to end of string or up to '%'. Field width
16905 is length of string. Don't output more than
16906 PRECISION allows us. */
16909 prec
= c_string_width (SDATA (elt
) + last_offset
,
16910 offset
- last_offset
, precision
- n
,
16913 switch (mode_line_target
)
16915 case MODE_LINE_NOPROP
:
16916 case MODE_LINE_TITLE
:
16917 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
16919 case MODE_LINE_STRING
:
16921 int bytepos
= last_offset
;
16922 int charpos
= string_byte_to_char (elt
, bytepos
);
16923 int endpos
= (precision
<= 0
16924 ? string_byte_to_char (elt
, offset
)
16925 : charpos
+ nchars
);
16927 n
+= store_mode_line_string (NULL
,
16928 Fsubstring (elt
, make_number (charpos
),
16929 make_number (endpos
)),
16933 case MODE_LINE_DISPLAY
:
16935 int bytepos
= last_offset
;
16936 int charpos
= string_byte_to_char (elt
, bytepos
);
16938 if (precision
<= 0)
16939 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
16940 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
16942 STRING_MULTIBYTE (elt
));
16947 else /* c == '%' */
16949 int percent_position
= offset
;
16951 /* Get the specified minimum width. Zero means
16954 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
16955 field
= field
* 10 + c
- '0';
16957 /* Don't pad beyond the total padding allowed. */
16958 if (field_width
- n
> 0 && field
> field_width
- n
)
16959 field
= field_width
- n
;
16961 /* Note that either PRECISION <= 0 or N < PRECISION. */
16962 prec
= precision
- n
;
16965 n
+= display_mode_element (it
, depth
, field
, prec
,
16966 Vglobal_mode_string
, props
,
16971 int bytepos
, charpos
;
16972 unsigned char *spec
;
16974 bytepos
= percent_position
;
16975 charpos
= (STRING_MULTIBYTE (elt
)
16976 ? string_byte_to_char (elt
, bytepos
)
16980 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
16982 switch (mode_line_target
)
16984 case MODE_LINE_NOPROP
:
16985 case MODE_LINE_TITLE
:
16986 n
+= store_mode_line_noprop (spec
, field
, prec
);
16988 case MODE_LINE_STRING
:
16990 int len
= strlen (spec
);
16991 Lisp_Object tem
= make_string (spec
, len
);
16992 props
= Ftext_properties_at (make_number (charpos
), elt
);
16993 /* Should only keep face property in props */
16994 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
16997 case MODE_LINE_DISPLAY
:
16999 int nglyphs_before
, nwritten
;
17001 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17002 nwritten
= display_string (spec
, Qnil
, elt
,
17007 /* Assign to the glyphs written above the
17008 string where the `%x' came from, position
17012 struct glyph
*glyph
17013 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
17017 for (i
= 0; i
< nwritten
; ++i
)
17019 glyph
[i
].object
= elt
;
17020 glyph
[i
].charpos
= charpos
;
17037 /* A symbol: process the value of the symbol recursively
17038 as if it appeared here directly. Avoid error if symbol void.
17039 Special case: if value of symbol is a string, output the string
17042 register Lisp_Object tem
;
17044 /* If the variable is not marked as risky to set
17045 then its contents are risky to use. */
17046 if (NILP (Fget (elt
, Qrisky_local_variable
)))
17049 tem
= Fboundp (elt
);
17052 tem
= Fsymbol_value (elt
);
17053 /* If value is a string, output that string literally:
17054 don't check for % within it. */
17058 if (!EQ (tem
, elt
))
17060 /* Give up right away for nil or t. */
17070 register Lisp_Object car
, tem
;
17072 /* A cons cell: five distinct cases.
17073 If first element is :eval or :propertize, do something special.
17074 If first element is a string or a cons, process all the elements
17075 and effectively concatenate them.
17076 If first element is a negative number, truncate displaying cdr to
17077 at most that many characters. If positive, pad (with spaces)
17078 to at least that many characters.
17079 If first element is a symbol, process the cadr or caddr recursively
17080 according to whether the symbol's value is non-nil or nil. */
17082 if (EQ (car
, QCeval
))
17084 /* An element of the form (:eval FORM) means evaluate FORM
17085 and use the result as mode line elements. */
17090 if (CONSP (XCDR (elt
)))
17093 spec
= safe_eval (XCAR (XCDR (elt
)));
17094 n
+= display_mode_element (it
, depth
, field_width
- n
,
17095 precision
- n
, spec
, props
,
17099 else if (EQ (car
, QCpropertize
))
17101 /* An element of the form (:propertize ELT PROPS...)
17102 means display ELT but applying properties PROPS. */
17107 if (CONSP (XCDR (elt
)))
17108 n
+= display_mode_element (it
, depth
, field_width
- n
,
17109 precision
- n
, XCAR (XCDR (elt
)),
17110 XCDR (XCDR (elt
)), risky
);
17112 else if (SYMBOLP (car
))
17114 tem
= Fboundp (car
);
17118 /* elt is now the cdr, and we know it is a cons cell.
17119 Use its car if CAR has a non-nil value. */
17122 tem
= Fsymbol_value (car
);
17129 /* Symbol's value is nil (or symbol is unbound)
17130 Get the cddr of the original list
17131 and if possible find the caddr and use that. */
17135 else if (!CONSP (elt
))
17140 else if (INTEGERP (car
))
17142 register int lim
= XINT (car
);
17146 /* Negative int means reduce maximum width. */
17147 if (precision
<= 0)
17150 precision
= min (precision
, -lim
);
17154 /* Padding specified. Don't let it be more than
17155 current maximum. */
17157 lim
= min (precision
, lim
);
17159 /* If that's more padding than already wanted, queue it.
17160 But don't reduce padding already specified even if
17161 that is beyond the current truncation point. */
17162 field_width
= max (lim
, field_width
);
17166 else if (STRINGP (car
) || CONSP (car
))
17168 register int limit
= 50;
17169 /* Limit is to protect against circular lists. */
17172 && (precision
<= 0 || n
< precision
))
17174 n
+= display_mode_element (it
, depth
,
17175 /* Do padding only after the last
17176 element in the list. */
17177 (! CONSP (XCDR (elt
))
17180 precision
- n
, XCAR (elt
),
17190 elt
= build_string ("*invalid*");
17194 /* Pad to FIELD_WIDTH. */
17195 if (field_width
> 0 && n
< field_width
)
17197 switch (mode_line_target
)
17199 case MODE_LINE_NOPROP
:
17200 case MODE_LINE_TITLE
:
17201 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17203 case MODE_LINE_STRING
:
17204 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17206 case MODE_LINE_DISPLAY
:
17207 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17216 /* Store a mode-line string element in mode_line_string_list.
17218 If STRING is non-null, display that C string. Otherwise, the Lisp
17219 string LISP_STRING is displayed.
17221 FIELD_WIDTH is the minimum number of output glyphs to produce.
17222 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17223 with spaces. FIELD_WIDTH <= 0 means don't pad.
17225 PRECISION is the maximum number of characters to output from
17226 STRING. PRECISION <= 0 means don't truncate the string.
17228 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17229 properties to the string.
17231 PROPS are the properties to add to the string.
17232 The mode_line_string_face face property is always added to the string.
17236 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17238 Lisp_Object lisp_string
;
17247 if (string
!= NULL
)
17249 len
= strlen (string
);
17250 if (precision
> 0 && len
> precision
)
17252 lisp_string
= make_string (string
, len
);
17254 props
= mode_line_string_face_prop
;
17255 else if (!NILP (mode_line_string_face
))
17257 Lisp_Object face
= Fplist_get (props
, Qface
);
17258 props
= Fcopy_sequence (props
);
17260 face
= mode_line_string_face
;
17262 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17263 props
= Fplist_put (props
, Qface
, face
);
17265 Fadd_text_properties (make_number (0), make_number (len
),
17266 props
, lisp_string
);
17270 len
= XFASTINT (Flength (lisp_string
));
17271 if (precision
> 0 && len
> precision
)
17274 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17277 if (!NILP (mode_line_string_face
))
17281 props
= Ftext_properties_at (make_number (0), lisp_string
);
17282 face
= Fplist_get (props
, Qface
);
17284 face
= mode_line_string_face
;
17286 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17287 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17289 lisp_string
= Fcopy_sequence (lisp_string
);
17292 Fadd_text_properties (make_number (0), make_number (len
),
17293 props
, lisp_string
);
17298 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17302 if (field_width
> len
)
17304 field_width
-= len
;
17305 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17307 Fadd_text_properties (make_number (0), make_number (field_width
),
17308 props
, lisp_string
);
17309 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17317 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17319 doc
: /* Format a string out of a mode line format specification.
17320 First arg FORMAT specifies the mode line format (see `mode-line-format'
17321 for details) to use.
17323 Optional second arg FACE specifies the face property to put
17324 on all characters for which no face is specified.
17325 The value t means whatever face the window's mode line currently uses
17326 \(either `mode-line' or `mode-line-inactive', depending).
17327 A value of nil means the default is no face property.
17328 If FACE is an integer, the value string has no text properties.
17330 Optional third and fourth args WINDOW and BUFFER specify the window
17331 and buffer to use as the context for the formatting (defaults
17332 are the selected window and the window's buffer). */)
17333 (format
, face
, window
, buffer
)
17334 Lisp_Object format
, face
, window
, buffer
;
17339 struct buffer
*old_buffer
= NULL
;
17341 int no_props
= INTEGERP (face
);
17342 int count
= SPECPDL_INDEX ();
17344 int string_start
= 0;
17347 window
= selected_window
;
17348 CHECK_WINDOW (window
);
17349 w
= XWINDOW (window
);
17352 buffer
= w
->buffer
;
17353 CHECK_BUFFER (buffer
);
17356 return build_string ("");
17364 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
17365 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
17369 face_id
= DEFAULT_FACE_ID
;
17371 if (XBUFFER (buffer
) != current_buffer
)
17372 old_buffer
= current_buffer
;
17374 /* Save things including mode_line_proptrans_alist,
17375 and set that to nil so that we don't alter the outer value. */
17376 record_unwind_protect (unwind_format_mode_line
,
17377 format_mode_line_unwind_data (old_buffer
, 1));
17378 mode_line_proptrans_alist
= Qnil
;
17381 set_buffer_internal_1 (XBUFFER (buffer
));
17383 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17387 mode_line_target
= MODE_LINE_NOPROP
;
17388 mode_line_string_face_prop
= Qnil
;
17389 mode_line_string_list
= Qnil
;
17390 string_start
= MODE_LINE_NOPROP_LEN (0);
17394 mode_line_target
= MODE_LINE_STRING
;
17395 mode_line_string_list
= Qnil
;
17396 mode_line_string_face
= face
;
17397 mode_line_string_face_prop
17398 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
17401 push_frame_kboard (it
.f
);
17402 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17403 pop_frame_kboard ();
17407 len
= MODE_LINE_NOPROP_LEN (string_start
);
17408 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
17412 mode_line_string_list
= Fnreverse (mode_line_string_list
);
17413 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
17414 make_string ("", 0));
17417 unbind_to (count
, Qnil
);
17421 /* Write a null-terminated, right justified decimal representation of
17422 the positive integer D to BUF using a minimal field width WIDTH. */
17425 pint2str (buf
, width
, d
)
17426 register char *buf
;
17427 register int width
;
17430 register char *p
= buf
;
17438 *p
++ = d
% 10 + '0';
17443 for (width
-= (int) (p
- buf
); width
> 0; --width
)
17454 /* Write a null-terminated, right justified decimal and "human
17455 readable" representation of the nonnegative integer D to BUF using
17456 a minimal field width WIDTH. D should be smaller than 999.5e24. */
17458 static const char power_letter
[] =
17472 pint2hrstr (buf
, width
, d
)
17477 /* We aim to represent the nonnegative integer D as
17478 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
17481 /* -1 means: do not use TENTHS. */
17485 /* Length of QUOTIENT.TENTHS as a string. */
17491 if (1000 <= quotient
)
17493 /* Scale to the appropriate EXPONENT. */
17496 remainder
= quotient
% 1000;
17500 while (1000 <= quotient
);
17502 /* Round to nearest and decide whether to use TENTHS or not. */
17505 tenths
= remainder
/ 100;
17506 if (50 <= remainder
% 100)
17513 if (quotient
== 10)
17521 if (500 <= remainder
)
17523 if (quotient
< 999)
17534 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
17535 if (tenths
== -1 && quotient
<= 99)
17542 p
= psuffix
= buf
+ max (width
, length
);
17544 /* Print EXPONENT. */
17546 *psuffix
++ = power_letter
[exponent
];
17549 /* Print TENTHS. */
17552 *--p
= '0' + tenths
;
17556 /* Print QUOTIENT. */
17559 int digit
= quotient
% 10;
17560 *--p
= '0' + digit
;
17562 while ((quotient
/= 10) != 0);
17564 /* Print leading spaces. */
17569 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
17570 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
17571 type of CODING_SYSTEM. Return updated pointer into BUF. */
17573 static unsigned char invalid_eol_type
[] = "(*invalid*)";
17576 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
17577 Lisp_Object coding_system
;
17578 register char *buf
;
17582 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
17583 const unsigned char *eol_str
;
17585 /* The EOL conversion we are using. */
17586 Lisp_Object eoltype
;
17588 val
= Fget (coding_system
, Qcoding_system
);
17591 if (!VECTORP (val
)) /* Not yet decided. */
17596 eoltype
= eol_mnemonic_undecided
;
17597 /* Don't mention EOL conversion if it isn't decided. */
17601 Lisp_Object eolvalue
;
17603 eolvalue
= Fget (coding_system
, Qeol_type
);
17606 *buf
++ = XFASTINT (AREF (val
, 1));
17610 /* The EOL conversion that is normal on this system. */
17612 if (NILP (eolvalue
)) /* Not yet decided. */
17613 eoltype
= eol_mnemonic_undecided
;
17614 else if (VECTORP (eolvalue
)) /* Not yet decided. */
17615 eoltype
= eol_mnemonic_undecided
;
17616 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
17617 eoltype
= (XFASTINT (eolvalue
) == 0
17618 ? eol_mnemonic_unix
17619 : (XFASTINT (eolvalue
) == 1
17620 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
17626 /* Mention the EOL conversion if it is not the usual one. */
17627 if (STRINGP (eoltype
))
17629 eol_str
= SDATA (eoltype
);
17630 eol_str_len
= SBYTES (eoltype
);
17632 else if (INTEGERP (eoltype
)
17633 && CHAR_VALID_P (XINT (eoltype
), 0))
17635 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
17636 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
17641 eol_str
= invalid_eol_type
;
17642 eol_str_len
= sizeof (invalid_eol_type
) - 1;
17644 bcopy (eol_str
, buf
, eol_str_len
);
17645 buf
+= eol_str_len
;
17651 /* Return a string for the output of a mode line %-spec for window W,
17652 generated by character C. PRECISION >= 0 means don't return a
17653 string longer than that value. FIELD_WIDTH > 0 means pad the
17654 string returned with spaces to that value. Return 1 in *MULTIBYTE
17655 if the result is multibyte text.
17657 Note we operate on the current buffer for most purposes,
17658 the exception being w->base_line_pos. */
17660 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
17663 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
17666 int field_width
, precision
;
17670 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17671 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
17672 struct buffer
*b
= current_buffer
;
17680 if (!NILP (b
->read_only
))
17682 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17687 /* This differs from %* only for a modified read-only buffer. */
17688 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17690 if (!NILP (b
->read_only
))
17695 /* This differs from %* in ignoring read-only-ness. */
17696 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17708 if (command_loop_level
> 5)
17710 p
= decode_mode_spec_buf
;
17711 for (i
= 0; i
< command_loop_level
; i
++)
17714 return decode_mode_spec_buf
;
17722 if (command_loop_level
> 5)
17724 p
= decode_mode_spec_buf
;
17725 for (i
= 0; i
< command_loop_level
; i
++)
17728 return decode_mode_spec_buf
;
17735 /* Let lots_of_dashes be a string of infinite length. */
17736 if (mode_line_target
== MODE_LINE_NOPROP
||
17737 mode_line_target
== MODE_LINE_STRING
)
17739 if (field_width
<= 0
17740 || field_width
> sizeof (lots_of_dashes
))
17742 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
17743 decode_mode_spec_buf
[i
] = '-';
17744 decode_mode_spec_buf
[i
] = '\0';
17745 return decode_mode_spec_buf
;
17748 return lots_of_dashes
;
17756 /* %c and %l are ignored in `frame-title-format'.
17757 (In redisplay_internal, the frame title is drawn _before_ the
17758 windows are updated, so the stuff which depends on actual
17759 window contents (such as %l) may fail to render properly, or
17760 even crash emacs.) */
17761 if (mode_line_target
== MODE_LINE_TITLE
)
17765 int col
= (int) current_column (); /* iftc */
17766 w
->column_number_displayed
= make_number (col
);
17767 pint2str (decode_mode_spec_buf
, field_width
, col
);
17768 return decode_mode_spec_buf
;
17772 #ifndef SYSTEM_MALLOC
17774 if (NILP (Vmemory_full
))
17777 return "!MEM FULL! ";
17784 /* %F displays the frame name. */
17785 if (!NILP (f
->title
))
17786 return (char *) SDATA (f
->title
);
17787 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
17788 return (char *) SDATA (f
->name
);
17797 int size
= ZV
- BEGV
;
17798 pint2str (decode_mode_spec_buf
, field_width
, size
);
17799 return decode_mode_spec_buf
;
17804 int size
= ZV
- BEGV
;
17805 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
17806 return decode_mode_spec_buf
;
17811 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
17812 int topline
, nlines
, junk
, height
;
17814 /* %c and %l are ignored in `frame-title-format'. */
17815 if (mode_line_target
== MODE_LINE_TITLE
)
17818 startpos
= XMARKER (w
->start
)->charpos
;
17819 startpos_byte
= marker_byte_position (w
->start
);
17820 height
= WINDOW_TOTAL_LINES (w
);
17822 /* If we decided that this buffer isn't suitable for line numbers,
17823 don't forget that too fast. */
17824 if (EQ (w
->base_line_pos
, w
->buffer
))
17826 /* But do forget it, if the window shows a different buffer now. */
17827 else if (BUFFERP (w
->base_line_pos
))
17828 w
->base_line_pos
= Qnil
;
17830 /* If the buffer is very big, don't waste time. */
17831 if (INTEGERP (Vline_number_display_limit
)
17832 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
17834 w
->base_line_pos
= Qnil
;
17835 w
->base_line_number
= Qnil
;
17839 if (!NILP (w
->base_line_number
)
17840 && !NILP (w
->base_line_pos
)
17841 && XFASTINT (w
->base_line_pos
) <= startpos
)
17843 line
= XFASTINT (w
->base_line_number
);
17844 linepos
= XFASTINT (w
->base_line_pos
);
17845 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
17850 linepos
= BUF_BEGV (b
);
17851 linepos_byte
= BUF_BEGV_BYTE (b
);
17854 /* Count lines from base line to window start position. */
17855 nlines
= display_count_lines (linepos
, linepos_byte
,
17859 topline
= nlines
+ line
;
17861 /* Determine a new base line, if the old one is too close
17862 or too far away, or if we did not have one.
17863 "Too close" means it's plausible a scroll-down would
17864 go back past it. */
17865 if (startpos
== BUF_BEGV (b
))
17867 w
->base_line_number
= make_number (topline
);
17868 w
->base_line_pos
= make_number (BUF_BEGV (b
));
17870 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
17871 || linepos
== BUF_BEGV (b
))
17873 int limit
= BUF_BEGV (b
);
17874 int limit_byte
= BUF_BEGV_BYTE (b
);
17876 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
17878 if (startpos
- distance
> limit
)
17880 limit
= startpos
- distance
;
17881 limit_byte
= CHAR_TO_BYTE (limit
);
17884 nlines
= display_count_lines (startpos
, startpos_byte
,
17886 - (height
* 2 + 30),
17888 /* If we couldn't find the lines we wanted within
17889 line_number_display_limit_width chars per line,
17890 give up on line numbers for this window. */
17891 if (position
== limit_byte
&& limit
== startpos
- distance
)
17893 w
->base_line_pos
= w
->buffer
;
17894 w
->base_line_number
= Qnil
;
17898 w
->base_line_number
= make_number (topline
- nlines
);
17899 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
17902 /* Now count lines from the start pos to point. */
17903 nlines
= display_count_lines (startpos
, startpos_byte
,
17904 PT_BYTE
, PT
, &junk
);
17906 /* Record that we did display the line number. */
17907 line_number_displayed
= 1;
17909 /* Make the string to show. */
17910 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
17911 return decode_mode_spec_buf
;
17914 char* p
= decode_mode_spec_buf
;
17915 int pad
= field_width
- 2;
17921 return decode_mode_spec_buf
;
17927 obj
= b
->mode_name
;
17931 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
17937 int pos
= marker_position (w
->start
);
17938 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17940 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
17942 if (pos
<= BUF_BEGV (b
))
17947 else if (pos
<= BUF_BEGV (b
))
17951 if (total
> 1000000)
17952 /* Do it differently for a large value, to avoid overflow. */
17953 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17955 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17956 /* We can't normally display a 3-digit number,
17957 so get us a 2-digit number that is close. */
17960 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17961 return decode_mode_spec_buf
;
17965 /* Display percentage of size above the bottom of the screen. */
17968 int toppos
= marker_position (w
->start
);
17969 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
17970 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17972 if (botpos
>= BUF_ZV (b
))
17974 if (toppos
<= BUF_BEGV (b
))
17981 if (total
> 1000000)
17982 /* Do it differently for a large value, to avoid overflow. */
17983 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17985 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17986 /* We can't normally display a 3-digit number,
17987 so get us a 2-digit number that is close. */
17990 if (toppos
<= BUF_BEGV (b
))
17991 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
17993 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17994 return decode_mode_spec_buf
;
17999 /* status of process */
18000 obj
= Fget_buffer_process (Fcurrent_buffer ());
18002 return "no process";
18003 #ifdef subprocesses
18004 obj
= Fsymbol_name (Fprocess_status (obj
));
18008 case 't': /* indicate TEXT or BINARY */
18009 #ifdef MODE_LINE_BINARY_TEXT
18010 return MODE_LINE_BINARY_TEXT (b
);
18016 /* coding-system (not including end-of-line format) */
18018 /* coding-system (including end-of-line type) */
18020 int eol_flag
= (c
== 'Z');
18021 char *p
= decode_mode_spec_buf
;
18023 if (! FRAME_WINDOW_P (f
))
18025 /* No need to mention EOL here--the terminal never needs
18026 to do EOL conversion. */
18027 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
18028 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
18030 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
18033 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
18034 #ifdef subprocesses
18035 obj
= Fget_buffer_process (Fcurrent_buffer ());
18036 if (PROCESSP (obj
))
18038 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
18040 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
18043 #endif /* subprocesses */
18046 return decode_mode_spec_buf
;
18052 *multibyte
= STRING_MULTIBYTE (obj
);
18053 return (char *) SDATA (obj
);
18060 /* Count up to COUNT lines starting from START / START_BYTE.
18061 But don't go beyond LIMIT_BYTE.
18062 Return the number of lines thus found (always nonnegative).
18064 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
18067 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
18068 int start
, start_byte
, limit_byte
, count
;
18071 register unsigned char *cursor
;
18072 unsigned char *base
;
18074 register int ceiling
;
18075 register unsigned char *ceiling_addr
;
18076 int orig_count
= count
;
18078 /* If we are not in selective display mode,
18079 check only for newlines. */
18080 int selective_display
= (!NILP (current_buffer
->selective_display
)
18081 && !INTEGERP (current_buffer
->selective_display
));
18085 while (start_byte
< limit_byte
)
18087 ceiling
= BUFFER_CEILING_OF (start_byte
);
18088 ceiling
= min (limit_byte
- 1, ceiling
);
18089 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
18090 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
18093 if (selective_display
)
18094 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
18097 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
18100 if (cursor
!= ceiling_addr
)
18104 start_byte
+= cursor
- base
+ 1;
18105 *byte_pos_ptr
= start_byte
;
18109 if (++cursor
== ceiling_addr
)
18115 start_byte
+= cursor
- base
;
18120 while (start_byte
> limit_byte
)
18122 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18123 ceiling
= max (limit_byte
, ceiling
);
18124 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18125 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18128 if (selective_display
)
18129 while (--cursor
!= ceiling_addr
18130 && *cursor
!= '\n' && *cursor
!= 015)
18133 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18136 if (cursor
!= ceiling_addr
)
18140 start_byte
+= cursor
- base
+ 1;
18141 *byte_pos_ptr
= start_byte
;
18142 /* When scanning backwards, we should
18143 not count the newline posterior to which we stop. */
18144 return - orig_count
- 1;
18150 /* Here we add 1 to compensate for the last decrement
18151 of CURSOR, which took it past the valid range. */
18152 start_byte
+= cursor
- base
+ 1;
18156 *byte_pos_ptr
= limit_byte
;
18159 return - orig_count
+ count
;
18160 return orig_count
- count
;
18166 /***********************************************************************
18168 ***********************************************************************/
18170 /* Display a NUL-terminated string, starting with index START.
18172 If STRING is non-null, display that C string. Otherwise, the Lisp
18173 string LISP_STRING is displayed.
18175 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18176 FACE_STRING. Display STRING or LISP_STRING with the face at
18177 FACE_STRING_POS in FACE_STRING:
18179 Display the string in the environment given by IT, but use the
18180 standard display table, temporarily.
18182 FIELD_WIDTH is the minimum number of output glyphs to produce.
18183 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18184 with spaces. If STRING has more characters, more than FIELD_WIDTH
18185 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18187 PRECISION is the maximum number of characters to output from
18188 STRING. PRECISION < 0 means don't truncate the string.
18190 This is roughly equivalent to printf format specifiers:
18192 FIELD_WIDTH PRECISION PRINTF
18193 ----------------------------------------
18199 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18200 display them, and < 0 means obey the current buffer's value of
18201 enable_multibyte_characters.
18203 Value is the number of columns displayed. */
18206 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18207 start
, it
, field_width
, precision
, max_x
, multibyte
)
18208 unsigned char *string
;
18209 Lisp_Object lisp_string
;
18210 Lisp_Object face_string
;
18211 int face_string_pos
;
18214 int field_width
, precision
, max_x
;
18217 int hpos_at_start
= it
->hpos
;
18218 int saved_face_id
= it
->face_id
;
18219 struct glyph_row
*row
= it
->glyph_row
;
18221 /* Initialize the iterator IT for iteration over STRING beginning
18222 with index START. */
18223 reseat_to_string (it
, string
, lisp_string
, start
,
18224 precision
, field_width
, multibyte
);
18226 /* If displaying STRING, set up the face of the iterator
18227 from LISP_STRING, if that's given. */
18228 if (STRINGP (face_string
))
18234 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18235 0, it
->region_beg_charpos
,
18236 it
->region_end_charpos
,
18237 &endptr
, it
->base_face_id
, 0);
18238 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18239 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18242 /* Set max_x to the maximum allowed X position. Don't let it go
18243 beyond the right edge of the window. */
18245 max_x
= it
->last_visible_x
;
18247 max_x
= min (max_x
, it
->last_visible_x
);
18249 /* Skip over display elements that are not visible. because IT->w is
18251 if (it
->current_x
< it
->first_visible_x
)
18252 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18253 MOVE_TO_POS
| MOVE_TO_X
);
18255 row
->ascent
= it
->max_ascent
;
18256 row
->height
= it
->max_ascent
+ it
->max_descent
;
18257 row
->phys_ascent
= it
->max_phys_ascent
;
18258 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18259 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18261 /* This condition is for the case that we are called with current_x
18262 past last_visible_x. */
18263 while (it
->current_x
< max_x
)
18265 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18267 /* Get the next display element. */
18268 if (!get_next_display_element (it
))
18271 /* Produce glyphs. */
18272 x_before
= it
->current_x
;
18273 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18274 PRODUCE_GLYPHS (it
);
18276 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18279 while (i
< nglyphs
)
18281 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18283 if (!it
->truncate_lines_p
18284 && x
+ glyph
->pixel_width
> max_x
)
18286 /* End of continued line or max_x reached. */
18287 if (CHAR_GLYPH_PADDING_P (*glyph
))
18289 /* A wide character is unbreakable. */
18290 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18291 it
->current_x
= x_before
;
18295 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18300 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
18302 /* Glyph is at least partially visible. */
18304 if (x
< it
->first_visible_x
)
18305 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18309 /* Glyph is off the left margin of the display area.
18310 Should not happen. */
18314 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18315 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18316 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18317 row
->phys_height
= max (row
->phys_height
,
18318 it
->max_phys_ascent
+ it
->max_phys_descent
);
18319 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18320 it
->max_extra_line_spacing
);
18321 x
+= glyph
->pixel_width
;
18325 /* Stop if max_x reached. */
18329 /* Stop at line ends. */
18330 if (ITERATOR_AT_END_OF_LINE_P (it
))
18332 it
->continuation_lines_width
= 0;
18336 set_iterator_to_next (it
, 1);
18338 /* Stop if truncating at the right edge. */
18339 if (it
->truncate_lines_p
18340 && it
->current_x
>= it
->last_visible_x
)
18342 /* Add truncation mark, but don't do it if the line is
18343 truncated at a padding space. */
18344 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18346 if (!FRAME_WINDOW_P (it
->f
))
18350 if (it
->current_x
> it
->last_visible_x
)
18352 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18353 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18355 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18357 row
->used
[TEXT_AREA
] = i
;
18358 produce_special_glyphs (it
, IT_TRUNCATION
);
18361 produce_special_glyphs (it
, IT_TRUNCATION
);
18363 it
->glyph_row
->truncated_on_right_p
= 1;
18369 /* Maybe insert a truncation at the left. */
18370 if (it
->first_visible_x
18371 && IT_CHARPOS (*it
) > 0)
18373 if (!FRAME_WINDOW_P (it
->f
))
18374 insert_left_trunc_glyphs (it
);
18375 it
->glyph_row
->truncated_on_left_p
= 1;
18378 it
->face_id
= saved_face_id
;
18380 /* Value is number of columns displayed. */
18381 return it
->hpos
- hpos_at_start
;
18386 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
18387 appears as an element of LIST or as the car of an element of LIST.
18388 If PROPVAL is a list, compare each element against LIST in that
18389 way, and return 1/2 if any element of PROPVAL is found in LIST.
18390 Otherwise return 0. This function cannot quit.
18391 The return value is 2 if the text is invisible but with an ellipsis
18392 and 1 if it's invisible and without an ellipsis. */
18395 invisible_p (propval
, list
)
18396 register Lisp_Object propval
;
18399 register Lisp_Object tail
, proptail
;
18401 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18403 register Lisp_Object tem
;
18405 if (EQ (propval
, tem
))
18407 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
18408 return NILP (XCDR (tem
)) ? 1 : 2;
18411 if (CONSP (propval
))
18413 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
18415 Lisp_Object propelt
;
18416 propelt
= XCAR (proptail
);
18417 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18419 register Lisp_Object tem
;
18421 if (EQ (propelt
, tem
))
18423 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
18424 return NILP (XCDR (tem
)) ? 1 : 2;
18432 /* Calculate a width or height in pixels from a specification using
18433 the following elements:
18436 NUM - a (fractional) multiple of the default font width/height
18437 (NUM) - specifies exactly NUM pixels
18438 UNIT - a fixed number of pixels, see below.
18439 ELEMENT - size of a display element in pixels, see below.
18440 (NUM . SPEC) - equals NUM * SPEC
18441 (+ SPEC SPEC ...) - add pixel values
18442 (- SPEC SPEC ...) - subtract pixel values
18443 (- SPEC) - negate pixel value
18446 INT or FLOAT - a number constant
18447 SYMBOL - use symbol's (buffer local) variable binding.
18450 in - pixels per inch *)
18451 mm - pixels per 1/1000 meter *)
18452 cm - pixels per 1/100 meter *)
18453 width - width of current font in pixels.
18454 height - height of current font in pixels.
18456 *) using the ratio(s) defined in display-pixels-per-inch.
18460 left-fringe - left fringe width in pixels
18461 right-fringe - right fringe width in pixels
18463 left-margin - left margin width in pixels
18464 right-margin - right margin width in pixels
18466 scroll-bar - scroll-bar area width in pixels
18470 Pixels corresponding to 5 inches:
18473 Total width of non-text areas on left side of window (if scroll-bar is on left):
18474 '(space :width (+ left-fringe left-margin scroll-bar))
18476 Align to first text column (in header line):
18477 '(space :align-to 0)
18479 Align to middle of text area minus half the width of variable `my-image'
18480 containing a loaded image:
18481 '(space :align-to (0.5 . (- text my-image)))
18483 Width of left margin minus width of 1 character in the default font:
18484 '(space :width (- left-margin 1))
18486 Width of left margin minus width of 2 characters in the current font:
18487 '(space :width (- left-margin (2 . width)))
18489 Center 1 character over left-margin (in header line):
18490 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
18492 Different ways to express width of left fringe plus left margin minus one pixel:
18493 '(space :width (- (+ left-fringe left-margin) (1)))
18494 '(space :width (+ left-fringe left-margin (- (1))))
18495 '(space :width (+ left-fringe left-margin (-1)))
18499 #define NUMVAL(X) \
18500 ((INTEGERP (X) || FLOATP (X)) \
18505 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
18510 int width_p
, *align_to
;
18514 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
18515 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
18518 return OK_PIXELS (0);
18520 if (SYMBOLP (prop
))
18522 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18524 char *unit
= SDATA (SYMBOL_NAME (prop
));
18526 if (unit
[0] == 'i' && unit
[1] == 'n')
18528 else if (unit
[0] == 'm' && unit
[1] == 'm')
18530 else if (unit
[0] == 'c' && unit
[1] == 'm')
18537 #ifdef HAVE_WINDOW_SYSTEM
18538 if (FRAME_WINDOW_P (it
->f
)
18540 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
18541 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
18543 return OK_PIXELS (ppi
/ pixels
);
18546 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18547 || (CONSP (Vdisplay_pixels_per_inch
)
18549 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18550 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18552 return OK_PIXELS (ppi
/ pixels
);
18558 #ifdef HAVE_WINDOW_SYSTEM
18559 if (EQ (prop
, Qheight
))
18560 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
18561 if (EQ (prop
, Qwidth
))
18562 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
18564 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
18565 return OK_PIXELS (1);
18568 if (EQ (prop
, Qtext
))
18569 return OK_PIXELS (width_p
18570 ? window_box_width (it
->w
, TEXT_AREA
)
18571 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
18573 if (align_to
&& *align_to
< 0)
18576 if (EQ (prop
, Qleft
))
18577 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
18578 if (EQ (prop
, Qright
))
18579 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
18580 if (EQ (prop
, Qcenter
))
18581 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
18582 + window_box_width (it
->w
, TEXT_AREA
) / 2);
18583 if (EQ (prop
, Qleft_fringe
))
18584 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18585 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
18586 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
18587 if (EQ (prop
, Qright_fringe
))
18588 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18589 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18590 : window_box_right_offset (it
->w
, TEXT_AREA
));
18591 if (EQ (prop
, Qleft_margin
))
18592 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
18593 if (EQ (prop
, Qright_margin
))
18594 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
18595 if (EQ (prop
, Qscroll_bar
))
18596 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18598 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18599 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18600 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18605 if (EQ (prop
, Qleft_fringe
))
18606 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18607 if (EQ (prop
, Qright_fringe
))
18608 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18609 if (EQ (prop
, Qleft_margin
))
18610 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18611 if (EQ (prop
, Qright_margin
))
18612 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18613 if (EQ (prop
, Qscroll_bar
))
18614 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18617 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18620 if (INTEGERP (prop
) || FLOATP (prop
))
18622 int base_unit
= (width_p
18623 ? FRAME_COLUMN_WIDTH (it
->f
)
18624 : FRAME_LINE_HEIGHT (it
->f
));
18625 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18630 Lisp_Object car
= XCAR (prop
);
18631 Lisp_Object cdr
= XCDR (prop
);
18635 #ifdef HAVE_WINDOW_SYSTEM
18636 if (valid_image_p (prop
))
18638 int id
= lookup_image (it
->f
, prop
);
18639 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
18641 return OK_PIXELS (width_p
? img
->width
: img
->height
);
18644 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18650 while (CONSP (cdr
))
18652 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
18653 font
, width_p
, align_to
))
18656 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18661 if (EQ (car
, Qminus
))
18663 return OK_PIXELS (pixels
);
18666 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18669 if (INTEGERP (car
) || FLOATP (car
))
18672 pixels
= XFLOATINT (car
);
18674 return OK_PIXELS (pixels
);
18675 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
18676 font
, width_p
, align_to
))
18677 return OK_PIXELS (pixels
* fact
);
18688 /***********************************************************************
18690 ***********************************************************************/
18692 #ifdef HAVE_WINDOW_SYSTEM
18697 dump_glyph_string (s
)
18698 struct glyph_string
*s
;
18700 fprintf (stderr
, "glyph string\n");
18701 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
18702 s
->x
, s
->y
, s
->width
, s
->height
);
18703 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
18704 fprintf (stderr
, " hl = %d\n", s
->hl
);
18705 fprintf (stderr
, " left overhang = %d, right = %d\n",
18706 s
->left_overhang
, s
->right_overhang
);
18707 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
18708 fprintf (stderr
, " extends to end of line = %d\n",
18709 s
->extends_to_end_of_line_p
);
18710 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
18711 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
18714 #endif /* GLYPH_DEBUG */
18716 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
18717 of XChar2b structures for S; it can't be allocated in
18718 init_glyph_string because it must be allocated via `alloca'. W
18719 is the window on which S is drawn. ROW and AREA are the glyph row
18720 and area within the row from which S is constructed. START is the
18721 index of the first glyph structure covered by S. HL is a
18722 face-override for drawing S. */
18725 #define OPTIONAL_HDC(hdc) hdc,
18726 #define DECLARE_HDC(hdc) HDC hdc;
18727 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
18728 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
18731 #ifndef OPTIONAL_HDC
18732 #define OPTIONAL_HDC(hdc)
18733 #define DECLARE_HDC(hdc)
18734 #define ALLOCATE_HDC(hdc, f)
18735 #define RELEASE_HDC(hdc, f)
18739 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
18740 struct glyph_string
*s
;
18744 struct glyph_row
*row
;
18745 enum glyph_row_area area
;
18747 enum draw_glyphs_face hl
;
18749 bzero (s
, sizeof *s
);
18751 s
->f
= XFRAME (w
->frame
);
18755 s
->display
= FRAME_X_DISPLAY (s
->f
);
18756 s
->window
= FRAME_X_WINDOW (s
->f
);
18757 s
->char2b
= char2b
;
18761 s
->first_glyph
= row
->glyphs
[area
] + start
;
18762 s
->height
= row
->height
;
18763 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
18765 /* Display the internal border below the tool-bar window. */
18766 if (WINDOWP (s
->f
->tool_bar_window
)
18767 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
18768 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
18770 s
->ybase
= s
->y
+ row
->ascent
;
18774 /* Append the list of glyph strings with head H and tail T to the list
18775 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
18778 append_glyph_string_lists (head
, tail
, h
, t
)
18779 struct glyph_string
**head
, **tail
;
18780 struct glyph_string
*h
, *t
;
18794 /* Prepend the list of glyph strings with head H and tail T to the
18795 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
18799 prepend_glyph_string_lists (head
, tail
, h
, t
)
18800 struct glyph_string
**head
, **tail
;
18801 struct glyph_string
*h
, *t
;
18815 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
18816 Set *HEAD and *TAIL to the resulting list. */
18819 append_glyph_string (head
, tail
, s
)
18820 struct glyph_string
**head
, **tail
;
18821 struct glyph_string
*s
;
18823 s
->next
= s
->prev
= NULL
;
18824 append_glyph_string_lists (head
, tail
, s
, s
);
18828 /* Get face and two-byte form of character glyph GLYPH on frame F.
18829 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
18830 a pointer to a realized face that is ready for display. */
18832 static INLINE
struct face
*
18833 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
18835 struct glyph
*glyph
;
18841 xassert (glyph
->type
== CHAR_GLYPH
);
18842 face
= FACE_FROM_ID (f
, glyph
->face_id
);
18847 if (!glyph
->multibyte_p
)
18849 /* Unibyte case. We don't have to encode, but we have to make
18850 sure to use a face suitable for unibyte. */
18851 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18853 else if (glyph
->u
.ch
< 128)
18855 /* Case of ASCII in a face known to fit ASCII. */
18856 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18860 int c1
, c2
, charset
;
18862 /* Split characters into bytes. If c2 is -1 afterwards, C is
18863 really a one-byte character so that byte1 is zero. */
18864 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
18866 STORE_XCHAR2B (char2b
, c1
, c2
);
18868 STORE_XCHAR2B (char2b
, 0, c1
);
18870 /* Maybe encode the character in *CHAR2B. */
18871 if (charset
!= CHARSET_ASCII
)
18873 struct font_info
*font_info
18874 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18877 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
18881 /* Make sure X resources of the face are allocated. */
18882 xassert (face
!= NULL
);
18883 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18888 /* Fill glyph string S with composition components specified by S->cmp.
18890 FACES is an array of faces for all components of this composition.
18891 S->gidx is the index of the first component for S.
18893 OVERLAPS non-zero means S should draw the foreground only, and use
18894 its physical height for clipping. See also draw_glyphs.
18896 Value is the index of a component not in S. */
18899 fill_composite_glyph_string (s
, faces
, overlaps
)
18900 struct glyph_string
*s
;
18901 struct face
**faces
;
18908 s
->for_overlaps
= overlaps
;
18910 s
->face
= faces
[s
->gidx
];
18911 s
->font
= s
->face
->font
;
18912 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18914 /* For all glyphs of this composition, starting at the offset
18915 S->gidx, until we reach the end of the definition or encounter a
18916 glyph that requires the different face, add it to S. */
18918 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
18921 /* All glyph strings for the same composition has the same width,
18922 i.e. the width set for the first component of the composition. */
18924 s
->width
= s
->first_glyph
->pixel_width
;
18926 /* If the specified font could not be loaded, use the frame's
18927 default font, but record the fact that we couldn't load it in
18928 the glyph string so that we can draw rectangles for the
18929 characters of the glyph string. */
18930 if (s
->font
== NULL
)
18932 s
->font_not_found_p
= 1;
18933 s
->font
= FRAME_FONT (s
->f
);
18936 /* Adjust base line for subscript/superscript text. */
18937 s
->ybase
+= s
->first_glyph
->voffset
;
18939 xassert (s
->face
&& s
->face
->gc
);
18941 /* This glyph string must always be drawn with 16-bit functions. */
18944 return s
->gidx
+ s
->nchars
;
18948 /* Fill glyph string S from a sequence of character glyphs.
18950 FACE_ID is the face id of the string. START is the index of the
18951 first glyph to consider, END is the index of the last + 1.
18952 OVERLAPS non-zero means S should draw the foreground only, and use
18953 its physical height for clipping. See also draw_glyphs.
18955 Value is the index of the first glyph not in S. */
18958 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
18959 struct glyph_string
*s
;
18961 int start
, end
, overlaps
;
18963 struct glyph
*glyph
, *last
;
18965 int glyph_not_available_p
;
18967 xassert (s
->f
== XFRAME (s
->w
->frame
));
18968 xassert (s
->nchars
== 0);
18969 xassert (start
>= 0 && end
> start
);
18971 s
->for_overlaps
= overlaps
,
18972 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18973 last
= s
->row
->glyphs
[s
->area
] + end
;
18974 voffset
= glyph
->voffset
;
18976 glyph_not_available_p
= glyph
->glyph_not_available_p
;
18978 while (glyph
< last
18979 && glyph
->type
== CHAR_GLYPH
18980 && glyph
->voffset
== voffset
18981 /* Same face id implies same font, nowadays. */
18982 && glyph
->face_id
== face_id
18983 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
18987 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
18988 s
->char2b
+ s
->nchars
,
18990 s
->two_byte_p
= two_byte_p
;
18992 xassert (s
->nchars
<= end
- start
);
18993 s
->width
+= glyph
->pixel_width
;
18997 s
->font
= s
->face
->font
;
18998 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
19000 /* If the specified font could not be loaded, use the frame's font,
19001 but record the fact that we couldn't load it in
19002 S->font_not_found_p so that we can draw rectangles for the
19003 characters of the glyph string. */
19004 if (s
->font
== NULL
|| glyph_not_available_p
)
19006 s
->font_not_found_p
= 1;
19007 s
->font
= FRAME_FONT (s
->f
);
19010 /* Adjust base line for subscript/superscript text. */
19011 s
->ybase
+= voffset
;
19013 xassert (s
->face
&& s
->face
->gc
);
19014 return glyph
- s
->row
->glyphs
[s
->area
];
19018 /* Fill glyph string S from image glyph S->first_glyph. */
19021 fill_image_glyph_string (s
)
19022 struct glyph_string
*s
;
19024 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
19025 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
19027 s
->slice
= s
->first_glyph
->slice
;
19028 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
19029 s
->font
= s
->face
->font
;
19030 s
->width
= s
->first_glyph
->pixel_width
;
19032 /* Adjust base line for subscript/superscript text. */
19033 s
->ybase
+= s
->first_glyph
->voffset
;
19037 /* Fill glyph string S from a sequence of stretch glyphs.
19039 ROW is the glyph row in which the glyphs are found, AREA is the
19040 area within the row. START is the index of the first glyph to
19041 consider, END is the index of the last + 1.
19043 Value is the index of the first glyph not in S. */
19046 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
19047 struct glyph_string
*s
;
19048 struct glyph_row
*row
;
19049 enum glyph_row_area area
;
19052 struct glyph
*glyph
, *last
;
19053 int voffset
, face_id
;
19055 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
19057 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19058 last
= s
->row
->glyphs
[s
->area
] + end
;
19059 face_id
= glyph
->face_id
;
19060 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19061 s
->font
= s
->face
->font
;
19062 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
19063 s
->width
= glyph
->pixel_width
;
19065 voffset
= glyph
->voffset
;
19069 && glyph
->type
== STRETCH_GLYPH
19070 && glyph
->voffset
== voffset
19071 && glyph
->face_id
== face_id
);
19073 s
->width
+= glyph
->pixel_width
;
19075 /* Adjust base line for subscript/superscript text. */
19076 s
->ybase
+= voffset
;
19078 /* The case that face->gc == 0 is handled when drawing the glyph
19079 string by calling PREPARE_FACE_FOR_DISPLAY. */
19081 return glyph
- s
->row
->glyphs
[s
->area
];
19086 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
19087 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
19088 assumed to be zero. */
19091 x_get_glyph_overhangs (glyph
, f
, left
, right
)
19092 struct glyph
*glyph
;
19096 *left
= *right
= 0;
19098 if (glyph
->type
== CHAR_GLYPH
)
19102 struct font_info
*font_info
;
19106 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
19108 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
19109 if (font
/* ++KFS: Should this be font_info ? */
19110 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
19112 if (pcm
->rbearing
> pcm
->width
)
19113 *right
= pcm
->rbearing
- pcm
->width
;
19114 if (pcm
->lbearing
< 0)
19115 *left
= -pcm
->lbearing
;
19121 /* Return the index of the first glyph preceding glyph string S that
19122 is overwritten by S because of S's left overhang. Value is -1
19123 if no glyphs are overwritten. */
19126 left_overwritten (s
)
19127 struct glyph_string
*s
;
19131 if (s
->left_overhang
)
19134 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19135 int first
= s
->first_glyph
- glyphs
;
19137 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19138 x
-= glyphs
[i
].pixel_width
;
19149 /* Return the index of the first glyph preceding glyph string S that
19150 is overwriting S because of its right overhang. Value is -1 if no
19151 glyph in front of S overwrites S. */
19154 left_overwriting (s
)
19155 struct glyph_string
*s
;
19158 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19159 int first
= s
->first_glyph
- glyphs
;
19163 for (i
= first
- 1; i
>= 0; --i
)
19166 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19169 x
-= glyphs
[i
].pixel_width
;
19176 /* Return the index of the last glyph following glyph string S that is
19177 not overwritten by S because of S's right overhang. Value is -1 if
19178 no such glyph is found. */
19181 right_overwritten (s
)
19182 struct glyph_string
*s
;
19186 if (s
->right_overhang
)
19189 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19190 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19191 int end
= s
->row
->used
[s
->area
];
19193 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19194 x
+= glyphs
[i
].pixel_width
;
19203 /* Return the index of the last glyph following glyph string S that
19204 overwrites S because of its left overhang. Value is negative
19205 if no such glyph is found. */
19208 right_overwriting (s
)
19209 struct glyph_string
*s
;
19212 int end
= s
->row
->used
[s
->area
];
19213 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19214 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19218 for (i
= first
; i
< end
; ++i
)
19221 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19224 x
+= glyphs
[i
].pixel_width
;
19231 /* Get face and two-byte form of character C in face FACE_ID on frame
19232 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19233 means we want to display multibyte text. DISPLAY_P non-zero means
19234 make sure that X resources for the face returned are allocated.
19235 Value is a pointer to a realized face that is ready for display if
19236 DISPLAY_P is non-zero. */
19238 static INLINE
struct face
*
19239 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19243 int multibyte_p
, display_p
;
19245 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19249 /* Unibyte case. We don't have to encode, but we have to make
19250 sure to use a face suitable for unibyte. */
19251 STORE_XCHAR2B (char2b
, 0, c
);
19252 face_id
= FACE_FOR_CHAR (f
, face
, c
);
19253 face
= FACE_FROM_ID (f
, face_id
);
19257 /* Case of ASCII in a face known to fit ASCII. */
19258 STORE_XCHAR2B (char2b
, 0, c
);
19262 int c1
, c2
, charset
;
19264 /* Split characters into bytes. If c2 is -1 afterwards, C is
19265 really a one-byte character so that byte1 is zero. */
19266 SPLIT_CHAR (c
, charset
, c1
, c2
);
19268 STORE_XCHAR2B (char2b
, c1
, c2
);
19270 STORE_XCHAR2B (char2b
, 0, c1
);
19272 /* Maybe encode the character in *CHAR2B. */
19273 if (face
->font
!= NULL
)
19275 struct font_info
*font_info
19276 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
19278 rif
->encode_char (c
, char2b
, font_info
, 0);
19282 /* Make sure X resources of the face are allocated. */
19283 #ifdef HAVE_X_WINDOWS
19287 xassert (face
!= NULL
);
19288 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19295 /* Set background width of glyph string S. START is the index of the
19296 first glyph following S. LAST_X is the right-most x-position + 1
19297 in the drawing area. */
19300 set_glyph_string_background_width (s
, start
, last_x
)
19301 struct glyph_string
*s
;
19305 /* If the face of this glyph string has to be drawn to the end of
19306 the drawing area, set S->extends_to_end_of_line_p. */
19308 if (start
== s
->row
->used
[s
->area
]
19309 && s
->area
== TEXT_AREA
19310 && ((s
->row
->fill_line_p
19311 && (s
->hl
== DRAW_NORMAL_TEXT
19312 || s
->hl
== DRAW_IMAGE_RAISED
19313 || s
->hl
== DRAW_IMAGE_SUNKEN
))
19314 || s
->hl
== DRAW_MOUSE_FACE
))
19315 s
->extends_to_end_of_line_p
= 1;
19317 /* If S extends its face to the end of the line, set its
19318 background_width to the distance to the right edge of the drawing
19320 if (s
->extends_to_end_of_line_p
)
19321 s
->background_width
= last_x
- s
->x
+ 1;
19323 s
->background_width
= s
->width
;
19327 /* Compute overhangs and x-positions for glyph string S and its
19328 predecessors, or successors. X is the starting x-position for S.
19329 BACKWARD_P non-zero means process predecessors. */
19332 compute_overhangs_and_x (s
, x
, backward_p
)
19333 struct glyph_string
*s
;
19341 if (rif
->compute_glyph_string_overhangs
)
19342 rif
->compute_glyph_string_overhangs (s
);
19352 if (rif
->compute_glyph_string_overhangs
)
19353 rif
->compute_glyph_string_overhangs (s
);
19363 /* The following macros are only called from draw_glyphs below.
19364 They reference the following parameters of that function directly:
19365 `w', `row', `area', and `overlap_p'
19366 as well as the following local variables:
19367 `s', `f', and `hdc' (in W32) */
19370 /* On W32, silently add local `hdc' variable to argument list of
19371 init_glyph_string. */
19372 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19373 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
19375 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19376 init_glyph_string (s, char2b, w, row, area, start, hl)
19379 /* Add a glyph string for a stretch glyph to the list of strings
19380 between HEAD and TAIL. START is the index of the stretch glyph in
19381 row area AREA of glyph row ROW. END is the index of the last glyph
19382 in that glyph row area. X is the current output position assigned
19383 to the new glyph string constructed. HL overrides that face of the
19384 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19385 is the right-most x-position of the drawing area. */
19387 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
19388 and below -- keep them on one line. */
19389 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19392 s = (struct glyph_string *) alloca (sizeof *s); \
19393 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19394 START = fill_stretch_glyph_string (s, row, area, START, END); \
19395 append_glyph_string (&HEAD, &TAIL, s); \
19401 /* Add a glyph string for an image glyph to the list of strings
19402 between HEAD and TAIL. START is the index of the image glyph in
19403 row area AREA of glyph row ROW. END is the index of the last glyph
19404 in that glyph row area. X is the current output position assigned
19405 to the new glyph string constructed. HL overrides that face of the
19406 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19407 is the right-most x-position of the drawing area. */
19409 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19412 s = (struct glyph_string *) alloca (sizeof *s); \
19413 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19414 fill_image_glyph_string (s); \
19415 append_glyph_string (&HEAD, &TAIL, s); \
19422 /* Add a glyph string for a sequence of character glyphs to the list
19423 of strings between HEAD and TAIL. START is the index of the first
19424 glyph in row area AREA of glyph row ROW that is part of the new
19425 glyph string. END is the index of the last glyph in that glyph row
19426 area. X is the current output position assigned to the new glyph
19427 string constructed. HL overrides that face of the glyph; e.g. it
19428 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
19429 right-most x-position of the drawing area. */
19431 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19437 c = (row)->glyphs[area][START].u.ch; \
19438 face_id = (row)->glyphs[area][START].face_id; \
19440 s = (struct glyph_string *) alloca (sizeof *s); \
19441 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
19442 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
19443 append_glyph_string (&HEAD, &TAIL, s); \
19445 START = fill_glyph_string (s, face_id, START, END, overlaps); \
19450 /* Add a glyph string for a composite sequence to the list of strings
19451 between HEAD and TAIL. START is the index of the first glyph in
19452 row area AREA of glyph row ROW that is part of the new glyph
19453 string. END is the index of the last glyph in that glyph row area.
19454 X is the current output position assigned to the new glyph string
19455 constructed. HL overrides that face of the glyph; e.g. it is
19456 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
19457 x-position of the drawing area. */
19459 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19461 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
19462 int face_id = (row)->glyphs[area][START].face_id; \
19463 struct face *base_face = FACE_FROM_ID (f, face_id); \
19464 struct composition *cmp = composition_table[cmp_id]; \
19465 int glyph_len = cmp->glyph_len; \
19467 struct face **faces; \
19468 struct glyph_string *first_s = NULL; \
19471 base_face = base_face->ascii_face; \
19472 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
19473 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
19474 /* At first, fill in `char2b' and `faces'. */ \
19475 for (n = 0; n < glyph_len; n++) \
19477 int c = COMPOSITION_GLYPH (cmp, n); \
19478 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
19479 faces[n] = FACE_FROM_ID (f, this_face_id); \
19480 get_char_face_and_encoding (f, c, this_face_id, \
19481 char2b + n, 1, 1); \
19484 /* Make glyph_strings for each glyph sequence that is drawable by \
19485 the same face, and append them to HEAD/TAIL. */ \
19486 for (n = 0; n < cmp->glyph_len;) \
19488 s = (struct glyph_string *) alloca (sizeof *s); \
19489 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
19490 append_glyph_string (&(HEAD), &(TAIL), s); \
19498 n = fill_composite_glyph_string (s, faces, overlaps); \
19506 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
19507 of AREA of glyph row ROW on window W between indices START and END.
19508 HL overrides the face for drawing glyph strings, e.g. it is
19509 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
19510 x-positions of the drawing area.
19512 This is an ugly monster macro construct because we must use alloca
19513 to allocate glyph strings (because draw_glyphs can be called
19514 asynchronously). */
19516 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19519 HEAD = TAIL = NULL; \
19520 while (START < END) \
19522 struct glyph *first_glyph = (row)->glyphs[area] + START; \
19523 switch (first_glyph->type) \
19526 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
19530 case COMPOSITE_GLYPH: \
19531 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
19535 case STRETCH_GLYPH: \
19536 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
19540 case IMAGE_GLYPH: \
19541 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
19549 set_glyph_string_background_width (s, START, LAST_X); \
19556 /* Draw glyphs between START and END in AREA of ROW on window W,
19557 starting at x-position X. X is relative to AREA in W. HL is a
19558 face-override with the following meaning:
19560 DRAW_NORMAL_TEXT draw normally
19561 DRAW_CURSOR draw in cursor face
19562 DRAW_MOUSE_FACE draw in mouse face.
19563 DRAW_INVERSE_VIDEO draw in mode line face
19564 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
19565 DRAW_IMAGE_RAISED draw an image with a raised relief around it
19567 If OVERLAPS is non-zero, draw only the foreground of characters and
19568 clip to the physical height of ROW. Non-zero value also defines
19569 the overlapping part to be drawn:
19571 OVERLAPS_PRED overlap with preceding rows
19572 OVERLAPS_SUCC overlap with succeeding rows
19573 OVERLAPS_BOTH overlap with both preceding/succeeding rows
19574 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
19576 Value is the x-position reached, relative to AREA of W. */
19579 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
19582 struct glyph_row
*row
;
19583 enum glyph_row_area area
;
19585 enum draw_glyphs_face hl
;
19588 struct glyph_string
*head
, *tail
;
19589 struct glyph_string
*s
;
19590 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
19591 int last_x
, area_width
;
19594 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19597 ALLOCATE_HDC (hdc
, f
);
19599 /* Let's rather be paranoid than getting a SEGV. */
19600 end
= min (end
, row
->used
[area
]);
19601 start
= max (0, start
);
19602 start
= min (end
, start
);
19604 /* Translate X to frame coordinates. Set last_x to the right
19605 end of the drawing area. */
19606 if (row
->full_width_p
)
19608 /* X is relative to the left edge of W, without scroll bars
19610 x
+= WINDOW_LEFT_EDGE_X (w
);
19611 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
19615 int area_left
= window_box_left (w
, area
);
19617 area_width
= window_box_width (w
, area
);
19618 last_x
= area_left
+ area_width
;
19621 /* Build a doubly-linked list of glyph_string structures between
19622 head and tail from what we have to draw. Note that the macro
19623 BUILD_GLYPH_STRINGS will modify its start parameter. That's
19624 the reason we use a separate variable `i'. */
19626 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
19628 x_reached
= tail
->x
+ tail
->background_width
;
19632 /* If there are any glyphs with lbearing < 0 or rbearing > width in
19633 the row, redraw some glyphs in front or following the glyph
19634 strings built above. */
19635 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
19638 struct glyph_string
*h
, *t
;
19640 /* Compute overhangs for all glyph strings. */
19641 if (rif
->compute_glyph_string_overhangs
)
19642 for (s
= head
; s
; s
= s
->next
)
19643 rif
->compute_glyph_string_overhangs (s
);
19645 /* Prepend glyph strings for glyphs in front of the first glyph
19646 string that are overwritten because of the first glyph
19647 string's left overhang. The background of all strings
19648 prepended must be drawn because the first glyph string
19650 i
= left_overwritten (head
);
19654 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
19655 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19657 compute_overhangs_and_x (t
, head
->x
, 1);
19658 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19662 /* Prepend glyph strings for glyphs in front of the first glyph
19663 string that overwrite that glyph string because of their
19664 right overhang. For these strings, only the foreground must
19665 be drawn, because it draws over the glyph string at `head'.
19666 The background must not be drawn because this would overwrite
19667 right overhangs of preceding glyphs for which no glyph
19669 i
= left_overwriting (head
);
19673 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
19674 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19675 for (s
= h
; s
; s
= s
->next
)
19676 s
->background_filled_p
= 1;
19677 compute_overhangs_and_x (t
, head
->x
, 1);
19678 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19681 /* Append glyphs strings for glyphs following the last glyph
19682 string tail that are overwritten by tail. The background of
19683 these strings has to be drawn because tail's foreground draws
19685 i
= right_overwritten (tail
);
19688 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19689 DRAW_NORMAL_TEXT
, x
, last_x
);
19690 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19691 append_glyph_string_lists (&head
, &tail
, h
, t
);
19695 /* Append glyph strings for glyphs following the last glyph
19696 string tail that overwrite tail. The foreground of such
19697 glyphs has to be drawn because it writes into the background
19698 of tail. The background must not be drawn because it could
19699 paint over the foreground of following glyphs. */
19700 i
= right_overwriting (tail
);
19704 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19705 DRAW_NORMAL_TEXT
, x
, last_x
);
19706 for (s
= h
; s
; s
= s
->next
)
19707 s
->background_filled_p
= 1;
19708 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19709 append_glyph_string_lists (&head
, &tail
, h
, t
);
19711 if (clip_head
|| clip_tail
)
19712 for (s
= head
; s
; s
= s
->next
)
19714 s
->clip_head
= clip_head
;
19715 s
->clip_tail
= clip_tail
;
19719 /* Draw all strings. */
19720 for (s
= head
; s
; s
= s
->next
)
19721 rif
->draw_glyph_string (s
);
19723 if (area
== TEXT_AREA
19724 && !row
->full_width_p
19725 /* When drawing overlapping rows, only the glyph strings'
19726 foreground is drawn, which doesn't erase a cursor
19730 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
19731 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
19732 : (tail
? tail
->x
+ tail
->background_width
: x
));
19734 int text_left
= window_box_left (w
, TEXT_AREA
);
19738 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
19739 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
19742 /* Value is the x-position up to which drawn, relative to AREA of W.
19743 This doesn't include parts drawn because of overhangs. */
19744 if (row
->full_width_p
)
19745 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
19747 x_reached
-= window_box_left (w
, area
);
19749 RELEASE_HDC (hdc
, f
);
19754 /* Expand row matrix if too narrow. Don't expand if area
19757 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
19759 if (!fonts_changed_p \
19760 && (it->glyph_row->glyphs[area] \
19761 < it->glyph_row->glyphs[area + 1])) \
19763 it->w->ncols_scale_factor++; \
19764 fonts_changed_p = 1; \
19768 /* Store one glyph for IT->char_to_display in IT->glyph_row.
19769 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19775 struct glyph
*glyph
;
19776 enum glyph_row_area area
= it
->area
;
19778 xassert (it
->glyph_row
);
19779 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
19781 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19782 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19784 glyph
->charpos
= CHARPOS (it
->position
);
19785 glyph
->object
= it
->object
;
19786 glyph
->pixel_width
= it
->pixel_width
;
19787 glyph
->ascent
= it
->ascent
;
19788 glyph
->descent
= it
->descent
;
19789 glyph
->voffset
= it
->voffset
;
19790 glyph
->type
= CHAR_GLYPH
;
19791 glyph
->multibyte_p
= it
->multibyte_p
;
19792 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19793 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19794 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19795 || it
->phys_descent
> it
->descent
);
19796 glyph
->padding_p
= 0;
19797 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
19798 glyph
->face_id
= it
->face_id
;
19799 glyph
->u
.ch
= it
->char_to_display
;
19800 glyph
->slice
= null_glyph_slice
;
19801 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19802 ++it
->glyph_row
->used
[area
];
19805 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19808 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
19809 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19812 append_composite_glyph (it
)
19815 struct glyph
*glyph
;
19816 enum glyph_row_area area
= it
->area
;
19818 xassert (it
->glyph_row
);
19820 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19821 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19823 glyph
->charpos
= CHARPOS (it
->position
);
19824 glyph
->object
= it
->object
;
19825 glyph
->pixel_width
= it
->pixel_width
;
19826 glyph
->ascent
= it
->ascent
;
19827 glyph
->descent
= it
->descent
;
19828 glyph
->voffset
= it
->voffset
;
19829 glyph
->type
= COMPOSITE_GLYPH
;
19830 glyph
->multibyte_p
= it
->multibyte_p
;
19831 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19832 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19833 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19834 || it
->phys_descent
> it
->descent
);
19835 glyph
->padding_p
= 0;
19836 glyph
->glyph_not_available_p
= 0;
19837 glyph
->face_id
= it
->face_id
;
19838 glyph
->u
.cmp_id
= it
->cmp_id
;
19839 glyph
->slice
= null_glyph_slice
;
19840 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19841 ++it
->glyph_row
->used
[area
];
19844 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19848 /* Change IT->ascent and IT->height according to the setting of
19852 take_vertical_position_into_account (it
)
19857 if (it
->voffset
< 0)
19858 /* Increase the ascent so that we can display the text higher
19860 it
->ascent
-= it
->voffset
;
19862 /* Increase the descent so that we can display the text lower
19864 it
->descent
+= it
->voffset
;
19869 /* Produce glyphs/get display metrics for the image IT is loaded with.
19870 See the description of struct display_iterator in dispextern.h for
19871 an overview of struct display_iterator. */
19874 produce_image_glyph (it
)
19879 int glyph_ascent
, crop
;
19880 struct glyph_slice slice
;
19882 xassert (it
->what
== IT_IMAGE
);
19884 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19886 /* Make sure X resources of the face is loaded. */
19887 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19889 if (it
->image_id
< 0)
19891 /* Fringe bitmap. */
19892 it
->ascent
= it
->phys_ascent
= 0;
19893 it
->descent
= it
->phys_descent
= 0;
19894 it
->pixel_width
= 0;
19899 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
19901 /* Make sure X resources of the image is loaded. */
19902 prepare_image_for_display (it
->f
, img
);
19904 slice
.x
= slice
.y
= 0;
19905 slice
.width
= img
->width
;
19906 slice
.height
= img
->height
;
19908 if (INTEGERP (it
->slice
.x
))
19909 slice
.x
= XINT (it
->slice
.x
);
19910 else if (FLOATP (it
->slice
.x
))
19911 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
19913 if (INTEGERP (it
->slice
.y
))
19914 slice
.y
= XINT (it
->slice
.y
);
19915 else if (FLOATP (it
->slice
.y
))
19916 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
19918 if (INTEGERP (it
->slice
.width
))
19919 slice
.width
= XINT (it
->slice
.width
);
19920 else if (FLOATP (it
->slice
.width
))
19921 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
19923 if (INTEGERP (it
->slice
.height
))
19924 slice
.height
= XINT (it
->slice
.height
);
19925 else if (FLOATP (it
->slice
.height
))
19926 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
19928 if (slice
.x
>= img
->width
)
19929 slice
.x
= img
->width
;
19930 if (slice
.y
>= img
->height
)
19931 slice
.y
= img
->height
;
19932 if (slice
.x
+ slice
.width
>= img
->width
)
19933 slice
.width
= img
->width
- slice
.x
;
19934 if (slice
.y
+ slice
.height
> img
->height
)
19935 slice
.height
= img
->height
- slice
.y
;
19937 if (slice
.width
== 0 || slice
.height
== 0)
19940 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
19942 it
->descent
= slice
.height
- glyph_ascent
;
19944 it
->descent
+= img
->vmargin
;
19945 if (slice
.y
+ slice
.height
== img
->height
)
19946 it
->descent
+= img
->vmargin
;
19947 it
->phys_descent
= it
->descent
;
19949 it
->pixel_width
= slice
.width
;
19951 it
->pixel_width
+= img
->hmargin
;
19952 if (slice
.x
+ slice
.width
== img
->width
)
19953 it
->pixel_width
+= img
->hmargin
;
19955 /* It's quite possible for images to have an ascent greater than
19956 their height, so don't get confused in that case. */
19957 if (it
->descent
< 0)
19960 #if 0 /* this breaks image tiling */
19961 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
19962 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
19963 if (face_ascent
> it
->ascent
)
19964 it
->ascent
= it
->phys_ascent
= face_ascent
;
19969 if (face
->box
!= FACE_NO_BOX
)
19971 if (face
->box_line_width
> 0)
19974 it
->ascent
+= face
->box_line_width
;
19975 if (slice
.y
+ slice
.height
== img
->height
)
19976 it
->descent
+= face
->box_line_width
;
19979 if (it
->start_of_box_run_p
&& slice
.x
== 0)
19980 it
->pixel_width
+= abs (face
->box_line_width
);
19981 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
19982 it
->pixel_width
+= abs (face
->box_line_width
);
19985 take_vertical_position_into_account (it
);
19987 /* Automatically crop wide image glyphs at right edge so we can
19988 draw the cursor on same display row. */
19989 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
19990 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
19992 it
->pixel_width
-= crop
;
19993 slice
.width
-= crop
;
19998 struct glyph
*glyph
;
19999 enum glyph_row_area area
= it
->area
;
20001 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20002 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20004 glyph
->charpos
= CHARPOS (it
->position
);
20005 glyph
->object
= it
->object
;
20006 glyph
->pixel_width
= it
->pixel_width
;
20007 glyph
->ascent
= glyph_ascent
;
20008 glyph
->descent
= it
->descent
;
20009 glyph
->voffset
= it
->voffset
;
20010 glyph
->type
= IMAGE_GLYPH
;
20011 glyph
->multibyte_p
= it
->multibyte_p
;
20012 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20013 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20014 glyph
->overlaps_vertically_p
= 0;
20015 glyph
->padding_p
= 0;
20016 glyph
->glyph_not_available_p
= 0;
20017 glyph
->face_id
= it
->face_id
;
20018 glyph
->u
.img_id
= img
->id
;
20019 glyph
->slice
= slice
;
20020 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20021 ++it
->glyph_row
->used
[area
];
20024 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20029 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
20030 of the glyph, WIDTH and HEIGHT are the width and height of the
20031 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
20034 append_stretch_glyph (it
, object
, width
, height
, ascent
)
20036 Lisp_Object object
;
20040 struct glyph
*glyph
;
20041 enum glyph_row_area area
= it
->area
;
20043 xassert (ascent
>= 0 && ascent
<= height
);
20045 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20046 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20048 glyph
->charpos
= CHARPOS (it
->position
);
20049 glyph
->object
= object
;
20050 glyph
->pixel_width
= width
;
20051 glyph
->ascent
= ascent
;
20052 glyph
->descent
= height
- ascent
;
20053 glyph
->voffset
= it
->voffset
;
20054 glyph
->type
= STRETCH_GLYPH
;
20055 glyph
->multibyte_p
= it
->multibyte_p
;
20056 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20057 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20058 glyph
->overlaps_vertically_p
= 0;
20059 glyph
->padding_p
= 0;
20060 glyph
->glyph_not_available_p
= 0;
20061 glyph
->face_id
= it
->face_id
;
20062 glyph
->u
.stretch
.ascent
= ascent
;
20063 glyph
->u
.stretch
.height
= height
;
20064 glyph
->slice
= null_glyph_slice
;
20065 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20066 ++it
->glyph_row
->used
[area
];
20069 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20073 /* Produce a stretch glyph for iterator IT. IT->object is the value
20074 of the glyph property displayed. The value must be a list
20075 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
20078 1. `:width WIDTH' specifies that the space should be WIDTH *
20079 canonical char width wide. WIDTH may be an integer or floating
20082 2. `:relative-width FACTOR' specifies that the width of the stretch
20083 should be computed from the width of the first character having the
20084 `glyph' property, and should be FACTOR times that width.
20086 3. `:align-to HPOS' specifies that the space should be wide enough
20087 to reach HPOS, a value in canonical character units.
20089 Exactly one of the above pairs must be present.
20091 4. `:height HEIGHT' specifies that the height of the stretch produced
20092 should be HEIGHT, measured in canonical character units.
20094 5. `:relative-height FACTOR' specifies that the height of the
20095 stretch should be FACTOR times the height of the characters having
20096 the glyph property.
20098 Either none or exactly one of 4 or 5 must be present.
20100 6. `:ascent ASCENT' specifies that ASCENT percent of the height
20101 of the stretch should be used for the ascent of the stretch.
20102 ASCENT must be in the range 0 <= ASCENT <= 100. */
20105 produce_stretch_glyph (it
)
20108 /* (space :width WIDTH :height HEIGHT ...) */
20109 Lisp_Object prop
, plist
;
20110 int width
= 0, height
= 0, align_to
= -1;
20111 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
20114 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20115 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
20117 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20119 /* List should start with `space'. */
20120 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
20121 plist
= XCDR (it
->object
);
20123 /* Compute the width of the stretch. */
20124 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
20125 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
20127 /* Absolute width `:width WIDTH' specified and valid. */
20128 zero_width_ok_p
= 1;
20131 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20134 /* Relative width `:relative-width FACTOR' specified and valid.
20135 Compute the width of the characters having the `glyph'
20138 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20141 if (it
->multibyte_p
)
20143 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
20144 - IT_BYTEPOS (*it
));
20145 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
20148 it2
.c
= *p
, it2
.len
= 1;
20150 it2
.glyph_row
= NULL
;
20151 it2
.what
= IT_CHARACTER
;
20152 x_produce_glyphs (&it2
);
20153 width
= NUMVAL (prop
) * it2
.pixel_width
;
20155 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20156 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20158 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20159 align_to
= (align_to
< 0
20161 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20162 else if (align_to
< 0)
20163 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20164 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20165 zero_width_ok_p
= 1;
20168 /* Nothing specified -> width defaults to canonical char width. */
20169 width
= FRAME_COLUMN_WIDTH (it
->f
);
20171 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20174 /* Compute height. */
20175 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20176 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20179 zero_height_ok_p
= 1;
20181 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20183 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20185 height
= FONT_HEIGHT (font
);
20187 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20190 /* Compute percentage of height used for ascent. If
20191 `:ascent ASCENT' is present and valid, use that. Otherwise,
20192 derive the ascent from the font in use. */
20193 if (prop
= Fplist_get (plist
, QCascent
),
20194 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20195 ascent
= height
* NUMVAL (prop
) / 100.0;
20196 else if (!NILP (prop
)
20197 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20198 ascent
= min (max (0, (int)tem
), height
);
20200 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
20202 if (width
> 0 && !it
->truncate_lines_p
20203 && it
->current_x
+ width
> it
->last_visible_x
)
20204 width
= it
->last_visible_x
- it
->current_x
- 1;
20206 if (width
> 0 && height
> 0 && it
->glyph_row
)
20208 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
20209 if (!STRINGP (object
))
20210 object
= it
->w
->buffer
;
20211 append_stretch_glyph (it
, object
, width
, height
, ascent
);
20214 it
->pixel_width
= width
;
20215 it
->ascent
= it
->phys_ascent
= ascent
;
20216 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
20217 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
20219 take_vertical_position_into_account (it
);
20222 /* Get line-height and line-spacing property at point.
20223 If line-height has format (HEIGHT TOTAL), return TOTAL
20224 in TOTAL_HEIGHT. */
20227 get_line_height_property (it
, prop
)
20231 Lisp_Object position
;
20233 if (STRINGP (it
->object
))
20234 position
= make_number (IT_STRING_CHARPOS (*it
));
20235 else if (BUFFERP (it
->object
))
20236 position
= make_number (IT_CHARPOS (*it
));
20240 return Fget_char_property (position
, prop
, it
->object
);
20243 /* Calculate line-height and line-spacing properties.
20244 An integer value specifies explicit pixel value.
20245 A float value specifies relative value to current face height.
20246 A cons (float . face-name) specifies relative value to
20247 height of specified face font.
20249 Returns height in pixels, or nil. */
20253 calc_line_height_property (it
, val
, font
, boff
, override
)
20257 int boff
, override
;
20259 Lisp_Object face_name
= Qnil
;
20260 int ascent
, descent
, height
;
20262 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
20267 face_name
= XCAR (val
);
20269 if (!NUMBERP (val
))
20270 val
= make_number (1);
20271 if (NILP (face_name
))
20273 height
= it
->ascent
+ it
->descent
;
20278 if (NILP (face_name
))
20280 font
= FRAME_FONT (it
->f
);
20281 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20283 else if (EQ (face_name
, Qt
))
20291 struct font_info
*font_info
;
20293 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
20295 return make_number (-1);
20297 face
= FACE_FROM_ID (it
->f
, face_id
);
20300 return make_number (-1);
20302 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20303 boff
= font_info
->baseline_offset
;
20304 if (font_info
->vertical_centering
)
20305 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20308 ascent
= FONT_BASE (font
) + boff
;
20309 descent
= FONT_DESCENT (font
) - boff
;
20313 it
->override_ascent
= ascent
;
20314 it
->override_descent
= descent
;
20315 it
->override_boff
= boff
;
20318 height
= ascent
+ descent
;
20322 height
= (int)(XFLOAT_DATA (val
) * height
);
20323 else if (INTEGERP (val
))
20324 height
*= XINT (val
);
20326 return make_number (height
);
20331 Produce glyphs/get display metrics for the display element IT is
20332 loaded with. See the description of struct it in dispextern.h
20333 for an overview of struct it. */
20336 x_produce_glyphs (it
)
20339 int extra_line_spacing
= it
->extra_line_spacing
;
20341 it
->glyph_not_available_p
= 0;
20343 if (it
->what
== IT_CHARACTER
)
20347 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20349 int font_not_found_p
;
20350 struct font_info
*font_info
;
20351 int boff
; /* baseline offset */
20352 /* We may change it->multibyte_p upon unibyte<->multibyte
20353 conversion. So, save the current value now and restore it
20356 Note: It seems that we don't have to record multibyte_p in
20357 struct glyph because the character code itself tells if or
20358 not the character is multibyte. Thus, in the future, we must
20359 consider eliminating the field `multibyte_p' in the struct
20361 int saved_multibyte_p
= it
->multibyte_p
;
20363 /* Maybe translate single-byte characters to multibyte, or the
20365 it
->char_to_display
= it
->c
;
20366 if (!ASCII_BYTE_P (it
->c
))
20368 if (unibyte_display_via_language_environment
20369 && SINGLE_BYTE_CHAR_P (it
->c
)
20371 || !NILP (Vnonascii_translation_table
)))
20373 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20374 it
->multibyte_p
= 1;
20375 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20376 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20378 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
20379 && !it
->multibyte_p
)
20381 it
->multibyte_p
= 1;
20382 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20383 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20387 /* Get font to use. Encode IT->char_to_display. */
20388 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20389 &char2b
, it
->multibyte_p
, 0);
20392 /* When no suitable font found, use the default font. */
20393 font_not_found_p
= font
== NULL
;
20394 if (font_not_found_p
)
20396 font
= FRAME_FONT (it
->f
);
20397 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20402 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20403 boff
= font_info
->baseline_offset
;
20404 if (font_info
->vertical_centering
)
20405 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20408 if (it
->char_to_display
>= ' '
20409 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
20411 /* Either unibyte or ASCII. */
20416 pcm
= rif
->per_char_metric (font
, &char2b
,
20417 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
20419 if (it
->override_ascent
>= 0)
20421 it
->ascent
= it
->override_ascent
;
20422 it
->descent
= it
->override_descent
;
20423 boff
= it
->override_boff
;
20427 it
->ascent
= FONT_BASE (font
) + boff
;
20428 it
->descent
= FONT_DESCENT (font
) - boff
;
20433 it
->phys_ascent
= pcm
->ascent
+ boff
;
20434 it
->phys_descent
= pcm
->descent
- boff
;
20435 it
->pixel_width
= pcm
->width
;
20439 it
->glyph_not_available_p
= 1;
20440 it
->phys_ascent
= it
->ascent
;
20441 it
->phys_descent
= it
->descent
;
20442 it
->pixel_width
= FONT_WIDTH (font
);
20445 if (it
->constrain_row_ascent_descent_p
)
20447 if (it
->descent
> it
->max_descent
)
20449 it
->ascent
+= it
->descent
- it
->max_descent
;
20450 it
->descent
= it
->max_descent
;
20452 if (it
->ascent
> it
->max_ascent
)
20454 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20455 it
->ascent
= it
->max_ascent
;
20457 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20458 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20459 extra_line_spacing
= 0;
20462 /* If this is a space inside a region of text with
20463 `space-width' property, change its width. */
20464 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
20466 it
->pixel_width
*= XFLOATINT (it
->space_width
);
20468 /* If face has a box, add the box thickness to the character
20469 height. If character has a box line to the left and/or
20470 right, add the box line width to the character's width. */
20471 if (face
->box
!= FACE_NO_BOX
)
20473 int thick
= face
->box_line_width
;
20477 it
->ascent
+= thick
;
20478 it
->descent
+= thick
;
20483 if (it
->start_of_box_run_p
)
20484 it
->pixel_width
+= thick
;
20485 if (it
->end_of_box_run_p
)
20486 it
->pixel_width
+= thick
;
20489 /* If face has an overline, add the height of the overline
20490 (1 pixel) and a 1 pixel margin to the character height. */
20491 if (face
->overline_p
)
20492 it
->ascent
+= overline_margin
;
20494 if (it
->constrain_row_ascent_descent_p
)
20496 if (it
->ascent
> it
->max_ascent
)
20497 it
->ascent
= it
->max_ascent
;
20498 if (it
->descent
> it
->max_descent
)
20499 it
->descent
= it
->max_descent
;
20502 take_vertical_position_into_account (it
);
20504 /* If we have to actually produce glyphs, do it. */
20509 /* Translate a space with a `space-width' property
20510 into a stretch glyph. */
20511 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
20512 / FONT_HEIGHT (font
));
20513 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20514 it
->ascent
+ it
->descent
, ascent
);
20519 /* If characters with lbearing or rbearing are displayed
20520 in this line, record that fact in a flag of the
20521 glyph row. This is used to optimize X output code. */
20522 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
20523 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20526 else if (it
->char_to_display
== '\n')
20528 /* A newline has no width but we need the height of the line.
20529 But if previous part of the line set a height, don't
20530 increase that height */
20532 Lisp_Object height
;
20533 Lisp_Object total_height
= Qnil
;
20535 it
->override_ascent
= -1;
20536 it
->pixel_width
= 0;
20539 height
= get_line_height_property(it
, Qline_height
);
20540 /* Split (line-height total-height) list */
20542 && CONSP (XCDR (height
))
20543 && NILP (XCDR (XCDR (height
))))
20545 total_height
= XCAR (XCDR (height
));
20546 height
= XCAR (height
);
20548 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
20550 if (it
->override_ascent
>= 0)
20552 it
->ascent
= it
->override_ascent
;
20553 it
->descent
= it
->override_descent
;
20554 boff
= it
->override_boff
;
20558 it
->ascent
= FONT_BASE (font
) + boff
;
20559 it
->descent
= FONT_DESCENT (font
) - boff
;
20562 if (EQ (height
, Qt
))
20564 if (it
->descent
> it
->max_descent
)
20566 it
->ascent
+= it
->descent
- it
->max_descent
;
20567 it
->descent
= it
->max_descent
;
20569 if (it
->ascent
> it
->max_ascent
)
20571 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20572 it
->ascent
= it
->max_ascent
;
20574 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20575 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20576 it
->constrain_row_ascent_descent_p
= 1;
20577 extra_line_spacing
= 0;
20581 Lisp_Object spacing
;
20583 it
->phys_ascent
= it
->ascent
;
20584 it
->phys_descent
= it
->descent
;
20586 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
20587 && face
->box
!= FACE_NO_BOX
20588 && face
->box_line_width
> 0)
20590 it
->ascent
+= face
->box_line_width
;
20591 it
->descent
+= face
->box_line_width
;
20594 && XINT (height
) > it
->ascent
+ it
->descent
)
20595 it
->ascent
= XINT (height
) - it
->descent
;
20597 if (!NILP (total_height
))
20598 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
20601 spacing
= get_line_height_property(it
, Qline_spacing
);
20602 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
20604 if (INTEGERP (spacing
))
20606 extra_line_spacing
= XINT (spacing
);
20607 if (!NILP (total_height
))
20608 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
20612 else if (it
->char_to_display
== '\t')
20614 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
20615 int x
= it
->current_x
+ it
->continuation_lines_width
;
20616 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
20618 /* If the distance from the current position to the next tab
20619 stop is less than a space character width, use the
20620 tab stop after that. */
20621 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
20622 next_tab_x
+= tab_width
;
20624 it
->pixel_width
= next_tab_x
- x
;
20626 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
20627 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20631 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20632 it
->ascent
+ it
->descent
, it
->ascent
);
20637 /* A multi-byte character. Assume that the display width of the
20638 character is the width of the character multiplied by the
20639 width of the font. */
20641 /* If we found a font, this font should give us the right
20642 metrics. If we didn't find a font, use the frame's
20643 default font and calculate the width of the character
20644 from the charset width; this is what old redisplay code
20647 pcm
= rif
->per_char_metric (font
, &char2b
,
20648 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
20650 if (font_not_found_p
|| !pcm
)
20652 int charset
= CHAR_CHARSET (it
->char_to_display
);
20654 it
->glyph_not_available_p
= 1;
20655 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
20656 * CHARSET_WIDTH (charset
));
20657 it
->phys_ascent
= FONT_BASE (font
) + boff
;
20658 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20662 it
->pixel_width
= pcm
->width
;
20663 it
->phys_ascent
= pcm
->ascent
+ boff
;
20664 it
->phys_descent
= pcm
->descent
- boff
;
20666 && (pcm
->lbearing
< 0
20667 || pcm
->rbearing
> pcm
->width
))
20668 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20671 it
->ascent
= FONT_BASE (font
) + boff
;
20672 it
->descent
= FONT_DESCENT (font
) - boff
;
20673 if (face
->box
!= FACE_NO_BOX
)
20675 int thick
= face
->box_line_width
;
20679 it
->ascent
+= thick
;
20680 it
->descent
+= thick
;
20685 if (it
->start_of_box_run_p
)
20686 it
->pixel_width
+= thick
;
20687 if (it
->end_of_box_run_p
)
20688 it
->pixel_width
+= thick
;
20691 /* If face has an overline, add the height of the overline
20692 (1 pixel) and a 1 pixel margin to the character height. */
20693 if (face
->overline_p
)
20694 it
->ascent
+= overline_margin
;
20696 take_vertical_position_into_account (it
);
20701 it
->multibyte_p
= saved_multibyte_p
;
20703 else if (it
->what
== IT_COMPOSITION
)
20705 /* Note: A composition is represented as one glyph in the
20706 glyph matrix. There are no padding glyphs. */
20709 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20711 int font_not_found_p
;
20712 struct font_info
*font_info
;
20713 int boff
; /* baseline offset */
20714 struct composition
*cmp
= composition_table
[it
->cmp_id
];
20716 /* Maybe translate single-byte characters to multibyte. */
20717 it
->char_to_display
= it
->c
;
20718 if (unibyte_display_via_language_environment
20719 && SINGLE_BYTE_CHAR_P (it
->c
)
20722 && !NILP (Vnonascii_translation_table
))))
20724 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20727 /* Get face and font to use. Encode IT->char_to_display. */
20728 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20729 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20730 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20731 &char2b
, it
->multibyte_p
, 0);
20734 /* When no suitable font found, use the default font. */
20735 font_not_found_p
= font
== NULL
;
20736 if (font_not_found_p
)
20738 font
= FRAME_FONT (it
->f
);
20739 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20744 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20745 boff
= font_info
->baseline_offset
;
20746 if (font_info
->vertical_centering
)
20747 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20750 /* There are no padding glyphs, so there is only one glyph to
20751 produce for the composition. Important is that pixel_width,
20752 ascent and descent are the values of what is drawn by
20753 draw_glyphs (i.e. the values of the overall glyphs composed). */
20756 /* If we have not yet calculated pixel size data of glyphs of
20757 the composition for the current face font, calculate them
20758 now. Theoretically, we have to check all fonts for the
20759 glyphs, but that requires much time and memory space. So,
20760 here we check only the font of the first glyph. This leads
20761 to incorrect display very rarely, and C-l (recenter) can
20762 correct the display anyway. */
20763 if (cmp
->font
!= (void *) font
)
20765 /* Ascent and descent of the font of the first character of
20766 this composition (adjusted by baseline offset). Ascent
20767 and descent of overall glyphs should not be less than
20768 them respectively. */
20769 int font_ascent
= FONT_BASE (font
) + boff
;
20770 int font_descent
= FONT_DESCENT (font
) - boff
;
20771 /* Bounding box of the overall glyphs. */
20772 int leftmost
, rightmost
, lowest
, highest
;
20773 int i
, width
, ascent
, descent
;
20775 cmp
->font
= (void *) font
;
20777 /* Initialize the bounding box. */
20779 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20780 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
20782 width
= pcm
->width
;
20783 ascent
= pcm
->ascent
;
20784 descent
= pcm
->descent
;
20788 width
= FONT_WIDTH (font
);
20789 ascent
= FONT_BASE (font
);
20790 descent
= FONT_DESCENT (font
);
20794 lowest
= - descent
+ boff
;
20795 highest
= ascent
+ boff
;
20799 && font_info
->default_ascent
20800 && CHAR_TABLE_P (Vuse_default_ascent
)
20801 && !NILP (Faref (Vuse_default_ascent
,
20802 make_number (it
->char_to_display
))))
20803 highest
= font_info
->default_ascent
+ boff
;
20805 /* Draw the first glyph at the normal position. It may be
20806 shifted to right later if some other glyphs are drawn at
20808 cmp
->offsets
[0] = 0;
20809 cmp
->offsets
[1] = boff
;
20811 /* Set cmp->offsets for the remaining glyphs. */
20812 for (i
= 1; i
< cmp
->glyph_len
; i
++)
20814 int left
, right
, btm
, top
;
20815 int ch
= COMPOSITION_GLYPH (cmp
, i
);
20816 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
20818 face
= FACE_FROM_ID (it
->f
, face_id
);
20819 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
20820 &char2b
, it
->multibyte_p
, 0);
20824 font
= FRAME_FONT (it
->f
);
20825 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20831 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20832 boff
= font_info
->baseline_offset
;
20833 if (font_info
->vertical_centering
)
20834 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20838 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20839 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
20841 width
= pcm
->width
;
20842 ascent
= pcm
->ascent
;
20843 descent
= pcm
->descent
;
20847 width
= FONT_WIDTH (font
);
20852 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
20854 /* Relative composition with or without
20855 alternate chars. */
20856 left
= (leftmost
+ rightmost
- width
) / 2;
20857 btm
= - descent
+ boff
;
20858 if (font_info
&& font_info
->relative_compose
20859 && (! CHAR_TABLE_P (Vignore_relative_composition
)
20860 || NILP (Faref (Vignore_relative_composition
,
20861 make_number (ch
)))))
20864 if (- descent
>= font_info
->relative_compose
)
20865 /* One extra pixel between two glyphs. */
20867 else if (ascent
<= 0)
20868 /* One extra pixel between two glyphs. */
20869 btm
= lowest
- 1 - ascent
- descent
;
20874 /* A composition rule is specified by an integer
20875 value that encodes global and new reference
20876 points (GREF and NREF). GREF and NREF are
20877 specified by numbers as below:
20879 0---1---2 -- ascent
20883 9--10--11 -- center
20885 ---3---4---5--- baseline
20887 6---7---8 -- descent
20889 int rule
= COMPOSITION_RULE (cmp
, i
);
20890 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
20892 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
20893 grefx
= gref
% 3, nrefx
= nref
% 3;
20894 grefy
= gref
/ 3, nrefy
= nref
/ 3;
20897 + grefx
* (rightmost
- leftmost
) / 2
20898 - nrefx
* width
/ 2);
20899 btm
= ((grefy
== 0 ? highest
20901 : grefy
== 2 ? lowest
20902 : (highest
+ lowest
) / 2)
20903 - (nrefy
== 0 ? ascent
+ descent
20904 : nrefy
== 1 ? descent
- boff
20906 : (ascent
+ descent
) / 2));
20909 cmp
->offsets
[i
* 2] = left
;
20910 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
20912 /* Update the bounding box of the overall glyphs. */
20913 right
= left
+ width
;
20914 top
= btm
+ descent
+ ascent
;
20915 if (left
< leftmost
)
20917 if (right
> rightmost
)
20925 /* If there are glyphs whose x-offsets are negative,
20926 shift all glyphs to the right and make all x-offsets
20930 for (i
= 0; i
< cmp
->glyph_len
; i
++)
20931 cmp
->offsets
[i
* 2] -= leftmost
;
20932 rightmost
-= leftmost
;
20935 cmp
->pixel_width
= rightmost
;
20936 cmp
->ascent
= highest
;
20937 cmp
->descent
= - lowest
;
20938 if (cmp
->ascent
< font_ascent
)
20939 cmp
->ascent
= font_ascent
;
20940 if (cmp
->descent
< font_descent
)
20941 cmp
->descent
= font_descent
;
20944 it
->pixel_width
= cmp
->pixel_width
;
20945 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
20946 it
->descent
= it
->phys_descent
= cmp
->descent
;
20948 if (face
->box
!= FACE_NO_BOX
)
20950 int thick
= face
->box_line_width
;
20954 it
->ascent
+= thick
;
20955 it
->descent
+= thick
;
20960 if (it
->start_of_box_run_p
)
20961 it
->pixel_width
+= thick
;
20962 if (it
->end_of_box_run_p
)
20963 it
->pixel_width
+= thick
;
20966 /* If face has an overline, add the height of the overline
20967 (1 pixel) and a 1 pixel margin to the character height. */
20968 if (face
->overline_p
)
20969 it
->ascent
+= overline_margin
;
20971 take_vertical_position_into_account (it
);
20974 append_composite_glyph (it
);
20976 else if (it
->what
== IT_IMAGE
)
20977 produce_image_glyph (it
);
20978 else if (it
->what
== IT_STRETCH
)
20979 produce_stretch_glyph (it
);
20981 /* Accumulate dimensions. Note: can't assume that it->descent > 0
20982 because this isn't true for images with `:ascent 100'. */
20983 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
20984 if (it
->area
== TEXT_AREA
)
20985 it
->current_x
+= it
->pixel_width
;
20987 if (extra_line_spacing
> 0)
20989 it
->descent
+= extra_line_spacing
;
20990 if (extra_line_spacing
> it
->max_extra_line_spacing
)
20991 it
->max_extra_line_spacing
= extra_line_spacing
;
20994 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
20995 it
->max_descent
= max (it
->max_descent
, it
->descent
);
20996 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
20997 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
21001 Output LEN glyphs starting at START at the nominal cursor position.
21002 Advance the nominal cursor over the text. The global variable
21003 updated_window contains the window being updated, updated_row is
21004 the glyph row being updated, and updated_area is the area of that
21005 row being updated. */
21008 x_write_glyphs (start
, len
)
21009 struct glyph
*start
;
21014 xassert (updated_window
&& updated_row
);
21017 /* Write glyphs. */
21019 hpos
= start
- updated_row
->glyphs
[updated_area
];
21020 x
= draw_glyphs (updated_window
, output_cursor
.x
,
21021 updated_row
, updated_area
,
21023 DRAW_NORMAL_TEXT
, 0);
21025 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
21026 if (updated_area
== TEXT_AREA
21027 && updated_window
->phys_cursor_on_p
21028 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
21029 && updated_window
->phys_cursor
.hpos
>= hpos
21030 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
21031 updated_window
->phys_cursor_on_p
= 0;
21035 /* Advance the output cursor. */
21036 output_cursor
.hpos
+= len
;
21037 output_cursor
.x
= x
;
21042 Insert LEN glyphs from START at the nominal cursor position. */
21045 x_insert_glyphs (start
, len
)
21046 struct glyph
*start
;
21051 int line_height
, shift_by_width
, shifted_region_width
;
21052 struct glyph_row
*row
;
21053 struct glyph
*glyph
;
21054 int frame_x
, frame_y
, hpos
;
21056 xassert (updated_window
&& updated_row
);
21058 w
= updated_window
;
21059 f
= XFRAME (WINDOW_FRAME (w
));
21061 /* Get the height of the line we are in. */
21063 line_height
= row
->height
;
21065 /* Get the width of the glyphs to insert. */
21066 shift_by_width
= 0;
21067 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
21068 shift_by_width
+= glyph
->pixel_width
;
21070 /* Get the width of the region to shift right. */
21071 shifted_region_width
= (window_box_width (w
, updated_area
)
21076 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
21077 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
21079 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
21080 line_height
, shift_by_width
);
21082 /* Write the glyphs. */
21083 hpos
= start
- row
->glyphs
[updated_area
];
21084 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
21086 DRAW_NORMAL_TEXT
, 0);
21088 /* Advance the output cursor. */
21089 output_cursor
.hpos
+= len
;
21090 output_cursor
.x
+= shift_by_width
;
21096 Erase the current text line from the nominal cursor position
21097 (inclusive) to pixel column TO_X (exclusive). The idea is that
21098 everything from TO_X onward is already erased.
21100 TO_X is a pixel position relative to updated_area of
21101 updated_window. TO_X == -1 means clear to the end of this area. */
21104 x_clear_end_of_line (to_x
)
21108 struct window
*w
= updated_window
;
21109 int max_x
, min_y
, max_y
;
21110 int from_x
, from_y
, to_y
;
21112 xassert (updated_window
&& updated_row
);
21113 f
= XFRAME (w
->frame
);
21115 if (updated_row
->full_width_p
)
21116 max_x
= WINDOW_TOTAL_WIDTH (w
);
21118 max_x
= window_box_width (w
, updated_area
);
21119 max_y
= window_text_bottom_y (w
);
21121 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
21122 of window. For TO_X > 0, truncate to end of drawing area. */
21128 to_x
= min (to_x
, max_x
);
21130 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
21132 /* Notice if the cursor will be cleared by this operation. */
21133 if (!updated_row
->full_width_p
)
21134 notice_overwritten_cursor (w
, updated_area
,
21135 output_cursor
.x
, -1,
21137 MATRIX_ROW_BOTTOM_Y (updated_row
));
21139 from_x
= output_cursor
.x
;
21141 /* Translate to frame coordinates. */
21142 if (updated_row
->full_width_p
)
21144 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
21145 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
21149 int area_left
= window_box_left (w
, updated_area
);
21150 from_x
+= area_left
;
21154 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
21155 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
21156 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
21158 /* Prevent inadvertently clearing to end of the X window. */
21159 if (to_x
> from_x
&& to_y
> from_y
)
21162 rif
->clear_frame_area (f
, from_x
, from_y
,
21163 to_x
- from_x
, to_y
- from_y
);
21168 #endif /* HAVE_WINDOW_SYSTEM */
21172 /***********************************************************************
21174 ***********************************************************************/
21176 /* Value is the internal representation of the specified cursor type
21177 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
21178 of the bar cursor. */
21180 static enum text_cursor_kinds
21181 get_specified_cursor_type (arg
, width
)
21185 enum text_cursor_kinds type
;
21190 if (EQ (arg
, Qbox
))
21191 return FILLED_BOX_CURSOR
;
21193 if (EQ (arg
, Qhollow
))
21194 return HOLLOW_BOX_CURSOR
;
21196 if (EQ (arg
, Qbar
))
21203 && EQ (XCAR (arg
), Qbar
)
21204 && INTEGERP (XCDR (arg
))
21205 && XINT (XCDR (arg
)) >= 0)
21207 *width
= XINT (XCDR (arg
));
21211 if (EQ (arg
, Qhbar
))
21214 return HBAR_CURSOR
;
21218 && EQ (XCAR (arg
), Qhbar
)
21219 && INTEGERP (XCDR (arg
))
21220 && XINT (XCDR (arg
)) >= 0)
21222 *width
= XINT (XCDR (arg
));
21223 return HBAR_CURSOR
;
21226 /* Treat anything unknown as "hollow box cursor".
21227 It was bad to signal an error; people have trouble fixing
21228 .Xdefaults with Emacs, when it has something bad in it. */
21229 type
= HOLLOW_BOX_CURSOR
;
21234 /* Set the default cursor types for specified frame. */
21236 set_frame_cursor_types (f
, arg
)
21243 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
21244 FRAME_CURSOR_WIDTH (f
) = width
;
21246 /* By default, set up the blink-off state depending on the on-state. */
21248 tem
= Fassoc (arg
, Vblink_cursor_alist
);
21251 FRAME_BLINK_OFF_CURSOR (f
)
21252 = get_specified_cursor_type (XCDR (tem
), &width
);
21253 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
21256 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
21260 /* Return the cursor we want to be displayed in window W. Return
21261 width of bar/hbar cursor through WIDTH arg. Return with
21262 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
21263 (i.e. if the `system caret' should track this cursor).
21265 In a mini-buffer window, we want the cursor only to appear if we
21266 are reading input from this window. For the selected window, we
21267 want the cursor type given by the frame parameter or buffer local
21268 setting of cursor-type. If explicitly marked off, draw no cursor.
21269 In all other cases, we want a hollow box cursor. */
21271 static enum text_cursor_kinds
21272 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
21274 struct glyph
*glyph
;
21276 int *active_cursor
;
21278 struct frame
*f
= XFRAME (w
->frame
);
21279 struct buffer
*b
= XBUFFER (w
->buffer
);
21280 int cursor_type
= DEFAULT_CURSOR
;
21281 Lisp_Object alt_cursor
;
21282 int non_selected
= 0;
21284 *active_cursor
= 1;
21287 if (cursor_in_echo_area
21288 && FRAME_HAS_MINIBUF_P (f
)
21289 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
21291 if (w
== XWINDOW (echo_area_window
))
21293 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
21295 *width
= FRAME_CURSOR_WIDTH (f
);
21296 return FRAME_DESIRED_CURSOR (f
);
21299 return get_specified_cursor_type (b
->cursor_type
, width
);
21302 *active_cursor
= 0;
21306 /* Detect a nonselected window or nonselected frame. */
21307 else if (w
!= XWINDOW (f
->selected_window
)
21308 #ifdef HAVE_WINDOW_SYSTEM
21309 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
21313 *active_cursor
= 0;
21315 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
21321 /* Never display a cursor in a window in which cursor-type is nil. */
21322 if (NILP (b
->cursor_type
))
21325 /* Get the normal cursor type for this window. */
21326 if (EQ (b
->cursor_type
, Qt
))
21328 cursor_type
= FRAME_DESIRED_CURSOR (f
);
21329 *width
= FRAME_CURSOR_WIDTH (f
);
21332 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
21334 /* Use cursor-in-non-selected-windows instead
21335 for non-selected window or frame. */
21338 alt_cursor
= b
->cursor_in_non_selected_windows
;
21339 if (!EQ (Qt
, alt_cursor
))
21340 return get_specified_cursor_type (alt_cursor
, width
);
21341 /* t means modify the normal cursor type. */
21342 if (cursor_type
== FILLED_BOX_CURSOR
)
21343 cursor_type
= HOLLOW_BOX_CURSOR
;
21344 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
21346 return cursor_type
;
21349 /* Use normal cursor if not blinked off. */
21350 if (!w
->cursor_off_p
)
21352 #ifdef HAVE_WINDOW_SYSTEM
21353 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21355 if (cursor_type
== FILLED_BOX_CURSOR
)
21357 /* Using a block cursor on large images can be very annoying.
21358 So use a hollow cursor for "large" images.
21359 If image is not transparent (no mask), also use hollow cursor. */
21360 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21361 if (img
!= NULL
&& IMAGEP (img
->spec
))
21363 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
21364 where N = size of default frame font size.
21365 This should cover most of the "tiny" icons people may use. */
21367 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
21368 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
21369 cursor_type
= HOLLOW_BOX_CURSOR
;
21372 else if (cursor_type
!= NO_CURSOR
)
21374 /* Display current only supports BOX and HOLLOW cursors for images.
21375 So for now, unconditionally use a HOLLOW cursor when cursor is
21376 not a solid box cursor. */
21377 cursor_type
= HOLLOW_BOX_CURSOR
;
21381 return cursor_type
;
21384 /* Cursor is blinked off, so determine how to "toggle" it. */
21386 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
21387 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
21388 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
21390 /* Then see if frame has specified a specific blink off cursor type. */
21391 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
21393 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
21394 return FRAME_BLINK_OFF_CURSOR (f
);
21398 /* Some people liked having a permanently visible blinking cursor,
21399 while others had very strong opinions against it. So it was
21400 decided to remove it. KFS 2003-09-03 */
21402 /* Finally perform built-in cursor blinking:
21403 filled box <-> hollow box
21404 wide [h]bar <-> narrow [h]bar
21405 narrow [h]bar <-> no cursor
21406 other type <-> no cursor */
21408 if (cursor_type
== FILLED_BOX_CURSOR
)
21409 return HOLLOW_BOX_CURSOR
;
21411 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
21414 return cursor_type
;
21422 #ifdef HAVE_WINDOW_SYSTEM
21424 /* Notice when the text cursor of window W has been completely
21425 overwritten by a drawing operation that outputs glyphs in AREA
21426 starting at X0 and ending at X1 in the line starting at Y0 and
21427 ending at Y1. X coordinates are area-relative. X1 < 0 means all
21428 the rest of the line after X0 has been written. Y coordinates
21429 are window-relative. */
21432 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
21434 enum glyph_row_area area
;
21435 int x0
, y0
, x1
, y1
;
21437 int cx0
, cx1
, cy0
, cy1
;
21438 struct glyph_row
*row
;
21440 if (!w
->phys_cursor_on_p
)
21442 if (area
!= TEXT_AREA
)
21445 if (w
->phys_cursor
.vpos
< 0
21446 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
21447 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
21448 !(row
->enabled_p
&& row
->displays_text_p
)))
21451 if (row
->cursor_in_fringe_p
)
21453 row
->cursor_in_fringe_p
= 0;
21454 draw_fringe_bitmap (w
, row
, 0);
21455 w
->phys_cursor_on_p
= 0;
21459 cx0
= w
->phys_cursor
.x
;
21460 cx1
= cx0
+ w
->phys_cursor_width
;
21461 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
21464 /* The cursor image will be completely removed from the
21465 screen if the output area intersects the cursor area in
21466 y-direction. When we draw in [y0 y1[, and some part of
21467 the cursor is at y < y0, that part must have been drawn
21468 before. When scrolling, the cursor is erased before
21469 actually scrolling, so we don't come here. When not
21470 scrolling, the rows above the old cursor row must have
21471 changed, and in this case these rows must have written
21472 over the cursor image.
21474 Likewise if part of the cursor is below y1, with the
21475 exception of the cursor being in the first blank row at
21476 the buffer and window end because update_text_area
21477 doesn't draw that row. (Except when it does, but
21478 that's handled in update_text_area.) */
21480 cy0
= w
->phys_cursor
.y
;
21481 cy1
= cy0
+ w
->phys_cursor_height
;
21482 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
21485 w
->phys_cursor_on_p
= 0;
21488 #endif /* HAVE_WINDOW_SYSTEM */
21491 /************************************************************************
21493 ************************************************************************/
21495 #ifdef HAVE_WINDOW_SYSTEM
21498 Fix the display of area AREA of overlapping row ROW in window W
21499 with respect to the overlapping part OVERLAPS. */
21502 x_fix_overlapping_area (w
, row
, area
, overlaps
)
21504 struct glyph_row
*row
;
21505 enum glyph_row_area area
;
21513 for (i
= 0; i
< row
->used
[area
];)
21515 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
21517 int start
= i
, start_x
= x
;
21521 x
+= row
->glyphs
[area
][i
].pixel_width
;
21524 while (i
< row
->used
[area
]
21525 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
21527 draw_glyphs (w
, start_x
, row
, area
,
21529 DRAW_NORMAL_TEXT
, overlaps
);
21533 x
+= row
->glyphs
[area
][i
].pixel_width
;
21543 Draw the cursor glyph of window W in glyph row ROW. See the
21544 comment of draw_glyphs for the meaning of HL. */
21547 draw_phys_cursor_glyph (w
, row
, hl
)
21549 struct glyph_row
*row
;
21550 enum draw_glyphs_face hl
;
21552 /* If cursor hpos is out of bounds, don't draw garbage. This can
21553 happen in mini-buffer windows when switching between echo area
21554 glyphs and mini-buffer. */
21555 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
21557 int on_p
= w
->phys_cursor_on_p
;
21559 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
21560 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
21562 w
->phys_cursor_on_p
= on_p
;
21564 if (hl
== DRAW_CURSOR
)
21565 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21566 /* When we erase the cursor, and ROW is overlapped by other
21567 rows, make sure that these overlapping parts of other rows
21569 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
21571 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21573 if (row
> w
->current_matrix
->rows
21574 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
21575 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
21576 OVERLAPS_ERASED_CURSOR
);
21578 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
21579 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
21580 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
21581 OVERLAPS_ERASED_CURSOR
);
21588 Erase the image of a cursor of window W from the screen. */
21591 erase_phys_cursor (w
)
21594 struct frame
*f
= XFRAME (w
->frame
);
21595 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21596 int hpos
= w
->phys_cursor
.hpos
;
21597 int vpos
= w
->phys_cursor
.vpos
;
21598 int mouse_face_here_p
= 0;
21599 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
21600 struct glyph_row
*cursor_row
;
21601 struct glyph
*cursor_glyph
;
21602 enum draw_glyphs_face hl
;
21604 /* No cursor displayed or row invalidated => nothing to do on the
21606 if (w
->phys_cursor_type
== NO_CURSOR
)
21607 goto mark_cursor_off
;
21609 /* VPOS >= active_glyphs->nrows means that window has been resized.
21610 Don't bother to erase the cursor. */
21611 if (vpos
>= active_glyphs
->nrows
)
21612 goto mark_cursor_off
;
21614 /* If row containing cursor is marked invalid, there is nothing we
21616 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
21617 if (!cursor_row
->enabled_p
)
21618 goto mark_cursor_off
;
21620 /* If line spacing is > 0, old cursor may only be partially visible in
21621 window after split-window. So adjust visible height. */
21622 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
21623 window_text_bottom_y (w
) - cursor_row
->y
);
21625 /* If row is completely invisible, don't attempt to delete a cursor which
21626 isn't there. This can happen if cursor is at top of a window, and
21627 we switch to a buffer with a header line in that window. */
21628 if (cursor_row
->visible_height
<= 0)
21629 goto mark_cursor_off
;
21631 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
21632 if (cursor_row
->cursor_in_fringe_p
)
21634 cursor_row
->cursor_in_fringe_p
= 0;
21635 draw_fringe_bitmap (w
, cursor_row
, 0);
21636 goto mark_cursor_off
;
21639 /* This can happen when the new row is shorter than the old one.
21640 In this case, either draw_glyphs or clear_end_of_line
21641 should have cleared the cursor. Note that we wouldn't be
21642 able to erase the cursor in this case because we don't have a
21643 cursor glyph at hand. */
21644 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
21645 goto mark_cursor_off
;
21647 /* If the cursor is in the mouse face area, redisplay that when
21648 we clear the cursor. */
21649 if (! NILP (dpyinfo
->mouse_face_window
)
21650 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
21651 && (vpos
> dpyinfo
->mouse_face_beg_row
21652 || (vpos
== dpyinfo
->mouse_face_beg_row
21653 && hpos
>= dpyinfo
->mouse_face_beg_col
))
21654 && (vpos
< dpyinfo
->mouse_face_end_row
21655 || (vpos
== dpyinfo
->mouse_face_end_row
21656 && hpos
< dpyinfo
->mouse_face_end_col
))
21657 /* Don't redraw the cursor's spot in mouse face if it is at the
21658 end of a line (on a newline). The cursor appears there, but
21659 mouse highlighting does not. */
21660 && cursor_row
->used
[TEXT_AREA
] > hpos
)
21661 mouse_face_here_p
= 1;
21663 /* Maybe clear the display under the cursor. */
21664 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
21667 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
21670 cursor_glyph
= get_phys_cursor_glyph (w
);
21671 if (cursor_glyph
== NULL
)
21672 goto mark_cursor_off
;
21674 width
= cursor_glyph
->pixel_width
;
21675 left_x
= window_box_left_offset (w
, TEXT_AREA
);
21676 x
= w
->phys_cursor
.x
;
21678 width
-= left_x
- x
;
21679 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
21680 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
21681 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
21684 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
21687 /* Erase the cursor by redrawing the character underneath it. */
21688 if (mouse_face_here_p
)
21689 hl
= DRAW_MOUSE_FACE
;
21691 hl
= DRAW_NORMAL_TEXT
;
21692 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
21695 w
->phys_cursor_on_p
= 0;
21696 w
->phys_cursor_type
= NO_CURSOR
;
21701 Display or clear cursor of window W. If ON is zero, clear the
21702 cursor. If it is non-zero, display the cursor. If ON is nonzero,
21703 where to put the cursor is specified by HPOS, VPOS, X and Y. */
21706 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
21708 int on
, hpos
, vpos
, x
, y
;
21710 struct frame
*f
= XFRAME (w
->frame
);
21711 int new_cursor_type
;
21712 int new_cursor_width
;
21714 struct glyph_row
*glyph_row
;
21715 struct glyph
*glyph
;
21717 /* This is pointless on invisible frames, and dangerous on garbaged
21718 windows and frames; in the latter case, the frame or window may
21719 be in the midst of changing its size, and x and y may be off the
21721 if (! FRAME_VISIBLE_P (f
)
21722 || FRAME_GARBAGED_P (f
)
21723 || vpos
>= w
->current_matrix
->nrows
21724 || hpos
>= w
->current_matrix
->matrix_w
)
21727 /* If cursor is off and we want it off, return quickly. */
21728 if (!on
&& !w
->phys_cursor_on_p
)
21731 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
21732 /* If cursor row is not enabled, we don't really know where to
21733 display the cursor. */
21734 if (!glyph_row
->enabled_p
)
21736 w
->phys_cursor_on_p
= 0;
21741 if (!glyph_row
->exact_window_width_line_p
21742 || hpos
< glyph_row
->used
[TEXT_AREA
])
21743 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
21745 xassert (interrupt_input_blocked
);
21747 /* Set new_cursor_type to the cursor we want to be displayed. */
21748 new_cursor_type
= get_window_cursor_type (w
, glyph
,
21749 &new_cursor_width
, &active_cursor
);
21751 /* If cursor is currently being shown and we don't want it to be or
21752 it is in the wrong place, or the cursor type is not what we want,
21754 if (w
->phys_cursor_on_p
21756 || w
->phys_cursor
.x
!= x
21757 || w
->phys_cursor
.y
!= y
21758 || new_cursor_type
!= w
->phys_cursor_type
21759 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
21760 && new_cursor_width
!= w
->phys_cursor_width
)))
21761 erase_phys_cursor (w
);
21763 /* Don't check phys_cursor_on_p here because that flag is only set
21764 to zero in some cases where we know that the cursor has been
21765 completely erased, to avoid the extra work of erasing the cursor
21766 twice. In other words, phys_cursor_on_p can be 1 and the cursor
21767 still not be visible, or it has only been partly erased. */
21770 w
->phys_cursor_ascent
= glyph_row
->ascent
;
21771 w
->phys_cursor_height
= glyph_row
->height
;
21773 /* Set phys_cursor_.* before x_draw_.* is called because some
21774 of them may need the information. */
21775 w
->phys_cursor
.x
= x
;
21776 w
->phys_cursor
.y
= glyph_row
->y
;
21777 w
->phys_cursor
.hpos
= hpos
;
21778 w
->phys_cursor
.vpos
= vpos
;
21781 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
21782 new_cursor_type
, new_cursor_width
,
21783 on
, active_cursor
);
21787 /* Switch the display of W's cursor on or off, according to the value
21791 update_window_cursor (w
, on
)
21795 /* Don't update cursor in windows whose frame is in the process
21796 of being deleted. */
21797 if (w
->current_matrix
)
21800 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21801 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21807 /* Call update_window_cursor with parameter ON_P on all leaf windows
21808 in the window tree rooted at W. */
21811 update_cursor_in_window_tree (w
, on_p
)
21817 if (!NILP (w
->hchild
))
21818 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
21819 else if (!NILP (w
->vchild
))
21820 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
21822 update_window_cursor (w
, on_p
);
21824 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
21830 Display the cursor on window W, or clear it, according to ON_P.
21831 Don't change the cursor's position. */
21834 x_update_cursor (f
, on_p
)
21838 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
21843 Clear the cursor of window W to background color, and mark the
21844 cursor as not shown. This is used when the text where the cursor
21845 is is about to be rewritten. */
21851 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
21852 update_window_cursor (w
, 0);
21857 Display the active region described by mouse_face_* according to DRAW. */
21860 show_mouse_face (dpyinfo
, draw
)
21861 Display_Info
*dpyinfo
;
21862 enum draw_glyphs_face draw
;
21864 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
21865 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21867 if (/* If window is in the process of being destroyed, don't bother
21869 w
->current_matrix
!= NULL
21870 /* Don't update mouse highlight if hidden */
21871 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
21872 /* Recognize when we are called to operate on rows that don't exist
21873 anymore. This can happen when a window is split. */
21874 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
21876 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
21877 struct glyph_row
*row
, *first
, *last
;
21879 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
21880 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
21882 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
21884 int start_hpos
, end_hpos
, start_x
;
21886 /* For all but the first row, the highlight starts at column 0. */
21889 start_hpos
= dpyinfo
->mouse_face_beg_col
;
21890 start_x
= dpyinfo
->mouse_face_beg_x
;
21899 end_hpos
= dpyinfo
->mouse_face_end_col
;
21902 end_hpos
= row
->used
[TEXT_AREA
];
21903 if (draw
== DRAW_NORMAL_TEXT
)
21904 row
->fill_line_p
= 1; /* Clear to end of line */
21907 if (end_hpos
> start_hpos
)
21909 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
21910 start_hpos
, end_hpos
,
21914 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
21918 /* When we've written over the cursor, arrange for it to
21919 be displayed again. */
21920 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
21923 display_and_set_cursor (w
, 1,
21924 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21925 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21930 /* Change the mouse cursor. */
21931 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
21932 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
21933 else if (draw
== DRAW_MOUSE_FACE
)
21934 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
21936 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
21940 Clear out the mouse-highlighted active region.
21941 Redraw it un-highlighted first. Value is non-zero if mouse
21942 face was actually drawn unhighlighted. */
21945 clear_mouse_face (dpyinfo
)
21946 Display_Info
*dpyinfo
;
21950 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
21952 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
21956 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21957 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21958 dpyinfo
->mouse_face_window
= Qnil
;
21959 dpyinfo
->mouse_face_overlay
= Qnil
;
21965 Non-zero if physical cursor of window W is within mouse face. */
21968 cursor_in_mouse_face_p (w
)
21971 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21972 int in_mouse_face
= 0;
21974 if (WINDOWP (dpyinfo
->mouse_face_window
)
21975 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
21977 int hpos
= w
->phys_cursor
.hpos
;
21978 int vpos
= w
->phys_cursor
.vpos
;
21980 if (vpos
>= dpyinfo
->mouse_face_beg_row
21981 && vpos
<= dpyinfo
->mouse_face_end_row
21982 && (vpos
> dpyinfo
->mouse_face_beg_row
21983 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21984 && (vpos
< dpyinfo
->mouse_face_end_row
21985 || hpos
< dpyinfo
->mouse_face_end_col
21986 || dpyinfo
->mouse_face_past_end
))
21990 return in_mouse_face
;
21996 /* Find the glyph matrix position of buffer position CHARPOS in window
21997 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
21998 current glyphs must be up to date. If CHARPOS is above window
21999 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
22000 of last line in W. In the row containing CHARPOS, stop before glyphs
22001 having STOP as object. */
22003 #if 1 /* This is a version of fast_find_position that's more correct
22004 in the presence of hscrolling, for example. I didn't install
22005 it right away because the problem fixed is minor, it failed
22006 in 20.x as well, and I think it's too risky to install
22007 so near the release of 21.1. 2001-09-25 gerd. */
22010 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
22013 int *hpos
, *vpos
, *x
, *y
;
22016 struct glyph_row
*row
, *first
;
22017 struct glyph
*glyph
, *end
;
22020 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22021 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
22026 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
22030 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
22033 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22037 /* If whole rows or last part of a row came from a display overlay,
22038 row_containing_pos will skip over such rows because their end pos
22039 equals the start pos of the overlay or interval.
22041 Move back if we have a STOP object and previous row's
22042 end glyph came from STOP. */
22045 struct glyph_row
*prev
;
22046 while ((prev
= row
- 1, prev
>= first
)
22047 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
22048 && prev
->used
[TEXT_AREA
] > 0)
22050 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
22051 glyph
= beg
+ prev
->used
[TEXT_AREA
];
22052 while (--glyph
>= beg
22053 && INTEGERP (glyph
->object
));
22055 || !EQ (stop
, glyph
->object
))
22063 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22065 glyph
= row
->glyphs
[TEXT_AREA
];
22066 end
= glyph
+ row
->used
[TEXT_AREA
];
22068 /* Skip over glyphs not having an object at the start of the row.
22069 These are special glyphs like truncation marks on terminal
22071 if (row
->displays_text_p
)
22073 && INTEGERP (glyph
->object
)
22074 && !EQ (stop
, glyph
->object
)
22075 && glyph
->charpos
< 0)
22077 *x
+= glyph
->pixel_width
;
22082 && !INTEGERP (glyph
->object
)
22083 && !EQ (stop
, glyph
->object
)
22084 && (!BUFFERP (glyph
->object
)
22085 || glyph
->charpos
< charpos
))
22087 *x
+= glyph
->pixel_width
;
22091 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
22098 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
22101 int *hpos
, *vpos
, *x
, *y
;
22106 int maybe_next_line_p
= 0;
22107 int line_start_position
;
22108 int yb
= window_text_bottom_y (w
);
22109 struct glyph_row
*row
, *best_row
;
22110 int row_vpos
, best_row_vpos
;
22113 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22114 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22116 while (row
->y
< yb
)
22118 if (row
->used
[TEXT_AREA
])
22119 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
22121 line_start_position
= 0;
22123 if (line_start_position
> pos
)
22125 /* If the position sought is the end of the buffer,
22126 don't include the blank lines at the bottom of the window. */
22127 else if (line_start_position
== pos
22128 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
22130 maybe_next_line_p
= 1;
22133 else if (line_start_position
> 0)
22136 best_row_vpos
= row_vpos
;
22139 if (row
->y
+ row
->height
>= yb
)
22146 /* Find the right column within BEST_ROW. */
22148 current_x
= best_row
->x
;
22149 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
22151 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
22152 int charpos
= glyph
->charpos
;
22154 if (BUFFERP (glyph
->object
))
22156 if (charpos
== pos
)
22159 *vpos
= best_row_vpos
;
22164 else if (charpos
> pos
)
22167 else if (EQ (glyph
->object
, stop
))
22172 current_x
+= glyph
->pixel_width
;
22175 /* If we're looking for the end of the buffer,
22176 and we didn't find it in the line we scanned,
22177 use the start of the following line. */
22178 if (maybe_next_line_p
)
22183 current_x
= best_row
->x
;
22186 *vpos
= best_row_vpos
;
22187 *hpos
= lastcol
+ 1;
22196 /* Find the position of the glyph for position POS in OBJECT in
22197 window W's current matrix, and return in *X, *Y the pixel
22198 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
22200 RIGHT_P non-zero means return the position of the right edge of the
22201 glyph, RIGHT_P zero means return the left edge position.
22203 If no glyph for POS exists in the matrix, return the position of
22204 the glyph with the next smaller position that is in the matrix, if
22205 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
22206 exists in the matrix, return the position of the glyph with the
22207 next larger position in OBJECT.
22209 Value is non-zero if a glyph was found. */
22212 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
22215 Lisp_Object object
;
22216 int *hpos
, *vpos
, *x
, *y
;
22219 int yb
= window_text_bottom_y (w
);
22220 struct glyph_row
*r
;
22221 struct glyph
*best_glyph
= NULL
;
22222 struct glyph_row
*best_row
= NULL
;
22225 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22226 r
->enabled_p
&& r
->y
< yb
;
22229 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
22230 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
22233 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
22234 if (EQ (g
->object
, object
))
22236 if (g
->charpos
== pos
)
22243 else if (best_glyph
== NULL
22244 || ((abs (g
->charpos
- pos
)
22245 < abs (best_glyph
->charpos
- pos
))
22248 : g
->charpos
> pos
)))
22262 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
22266 *x
+= best_glyph
->pixel_width
;
22271 *vpos
= best_row
- w
->current_matrix
->rows
;
22274 return best_glyph
!= NULL
;
22278 /* See if position X, Y is within a hot-spot of an image. */
22281 on_hot_spot_p (hot_spot
, x
, y
)
22282 Lisp_Object hot_spot
;
22285 if (!CONSP (hot_spot
))
22288 if (EQ (XCAR (hot_spot
), Qrect
))
22290 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
22291 Lisp_Object rect
= XCDR (hot_spot
);
22295 if (!CONSP (XCAR (rect
)))
22297 if (!CONSP (XCDR (rect
)))
22299 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
22301 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
22303 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
22305 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
22309 else if (EQ (XCAR (hot_spot
), Qcircle
))
22311 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
22312 Lisp_Object circ
= XCDR (hot_spot
);
22313 Lisp_Object lr
, lx0
, ly0
;
22315 && CONSP (XCAR (circ
))
22316 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
22317 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
22318 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
22320 double r
= XFLOATINT (lr
);
22321 double dx
= XINT (lx0
) - x
;
22322 double dy
= XINT (ly0
) - y
;
22323 return (dx
* dx
+ dy
* dy
<= r
* r
);
22326 else if (EQ (XCAR (hot_spot
), Qpoly
))
22328 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
22329 if (VECTORP (XCDR (hot_spot
)))
22331 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
22332 Lisp_Object
*poly
= v
->contents
;
22336 Lisp_Object lx
, ly
;
22339 /* Need an even number of coordinates, and at least 3 edges. */
22340 if (n
< 6 || n
& 1)
22343 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
22344 If count is odd, we are inside polygon. Pixels on edges
22345 may or may not be included depending on actual geometry of the
22347 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
22348 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
22350 x0
= XINT (lx
), y0
= XINT (ly
);
22351 for (i
= 0; i
< n
; i
+= 2)
22353 int x1
= x0
, y1
= y0
;
22354 if ((lx
= poly
[i
], !INTEGERP (lx
))
22355 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
22357 x0
= XINT (lx
), y0
= XINT (ly
);
22359 /* Does this segment cross the X line? */
22367 if (y
> y0
&& y
> y1
)
22369 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
22375 /* If we don't understand the format, pretend we're not in the hot-spot. */
22380 find_hot_spot (map
, x
, y
)
22384 while (CONSP (map
))
22386 if (CONSP (XCAR (map
))
22387 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
22395 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
22397 doc
: /* Lookup in image map MAP coordinates X and Y.
22398 An image map is an alist where each element has the format (AREA ID PLIST).
22399 An AREA is specified as either a rectangle, a circle, or a polygon:
22400 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
22401 pixel coordinates of the upper left and bottom right corners.
22402 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
22403 and the radius of the circle; r may be a float or integer.
22404 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
22405 vector describes one corner in the polygon.
22406 Returns the alist element for the first matching AREA in MAP. */)
22417 return find_hot_spot (map
, XINT (x
), XINT (y
));
22421 /* Display frame CURSOR, optionally using shape defined by POINTER. */
22423 define_frame_cursor1 (f
, cursor
, pointer
)
22426 Lisp_Object pointer
;
22428 /* Do not change cursor shape while dragging mouse. */
22429 if (!NILP (do_mouse_tracking
))
22432 if (!NILP (pointer
))
22434 if (EQ (pointer
, Qarrow
))
22435 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22436 else if (EQ (pointer
, Qhand
))
22437 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
22438 else if (EQ (pointer
, Qtext
))
22439 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22440 else if (EQ (pointer
, intern ("hdrag")))
22441 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22442 #ifdef HAVE_X_WINDOWS
22443 else if (EQ (pointer
, intern ("vdrag")))
22444 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
22446 else if (EQ (pointer
, intern ("hourglass")))
22447 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
22448 else if (EQ (pointer
, Qmodeline
))
22449 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
22451 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22454 if (cursor
!= No_Cursor
)
22455 rif
->define_frame_cursor (f
, cursor
);
22458 /* Take proper action when mouse has moved to the mode or header line
22459 or marginal area AREA of window W, x-position X and y-position Y.
22460 X is relative to the start of the text display area of W, so the
22461 width of bitmap areas and scroll bars must be subtracted to get a
22462 position relative to the start of the mode line. */
22465 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
22466 Lisp_Object window
;
22468 enum window_part area
;
22470 struct window
*w
= XWINDOW (window
);
22471 struct frame
*f
= XFRAME (w
->frame
);
22472 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22473 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22474 Lisp_Object pointer
= Qnil
;
22475 int charpos
, dx
, dy
, width
, height
;
22476 Lisp_Object string
, object
= Qnil
;
22477 Lisp_Object pos
, help
;
22479 Lisp_Object mouse_face
;
22480 int original_x_pixel
= x
;
22481 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
22482 struct glyph_row
*row
;
22484 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
22489 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
22490 &object
, &dx
, &dy
, &width
, &height
);
22492 row
= (area
== ON_MODE_LINE
22493 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
22494 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
22497 if (row
->mode_line_p
&& row
->enabled_p
)
22499 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
22500 end
= glyph
+ row
->used
[TEXT_AREA
];
22502 for (x0
= original_x_pixel
;
22503 glyph
< end
&& x0
>= glyph
->pixel_width
;
22505 x0
-= glyph
->pixel_width
;
22513 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
22514 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
22515 &object
, &dx
, &dy
, &width
, &height
);
22520 if (IMAGEP (object
))
22522 Lisp_Object image_map
, hotspot
;
22523 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
22525 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
22527 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22529 Lisp_Object area_id
, plist
;
22531 area_id
= XCAR (hotspot
);
22532 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22533 If so, we could look for mouse-enter, mouse-leave
22534 properties in PLIST (and do something...). */
22535 hotspot
= XCDR (hotspot
);
22536 if (CONSP (hotspot
)
22537 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22539 pointer
= Fplist_get (plist
, Qpointer
);
22540 if (NILP (pointer
))
22542 help
= Fplist_get (plist
, Qhelp_echo
);
22545 help_echo_string
= help
;
22546 /* Is this correct? ++kfs */
22547 XSETWINDOW (help_echo_window
, w
);
22548 help_echo_object
= w
->buffer
;
22549 help_echo_pos
= charpos
;
22553 if (NILP (pointer
))
22554 pointer
= Fplist_get (XCDR (object
), QCpointer
);
22557 if (STRINGP (string
))
22559 pos
= make_number (charpos
);
22560 /* If we're on a string with `help-echo' text property, arrange
22561 for the help to be displayed. This is done by setting the
22562 global variable help_echo_string to the help string. */
22565 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
22568 help_echo_string
= help
;
22569 XSETWINDOW (help_echo_window
, w
);
22570 help_echo_object
= string
;
22571 help_echo_pos
= charpos
;
22575 if (NILP (pointer
))
22576 pointer
= Fget_text_property (pos
, Qpointer
, string
);
22578 /* Change the mouse pointer according to what is under X/Y. */
22579 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
22582 map
= Fget_text_property (pos
, Qlocal_map
, string
);
22583 if (!KEYMAPP (map
))
22584 map
= Fget_text_property (pos
, Qkeymap
, string
);
22585 if (!KEYMAPP (map
))
22586 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
22589 /* Change the mouse face according to what is under X/Y. */
22590 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
22591 if (!NILP (mouse_face
)
22592 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22597 struct glyph
* tmp_glyph
;
22601 int total_pixel_width
;
22606 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
22607 Qmouse_face
, string
, Qnil
);
22609 b
= make_number (0);
22611 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
22613 e
= make_number (SCHARS (string
));
22615 /* Calculate the position(glyph position: GPOS) of GLYPH in
22616 displayed string. GPOS is different from CHARPOS.
22618 CHARPOS is the position of glyph in internal string
22619 object. A mode line string format has structures which
22620 is converted to a flatten by emacs lisp interpreter.
22621 The internal string is an element of the structures.
22622 The displayed string is the flatten string. */
22624 if (glyph
> row_start_glyph
)
22626 tmp_glyph
= glyph
- 1;
22627 while (tmp_glyph
>= row_start_glyph
22628 && tmp_glyph
->charpos
>= XINT (b
)
22629 && EQ (tmp_glyph
->object
, glyph
->object
))
22636 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
22637 displayed string holding GLYPH.
22639 GSEQ_LENGTH is different from SCHARS (STRING).
22640 SCHARS (STRING) returns the length of the internal string. */
22641 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
22642 tmp_glyph
->charpos
< XINT (e
);
22643 tmp_glyph
++, gseq_length
++)
22645 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22649 total_pixel_width
= 0;
22650 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
22651 total_pixel_width
+= tmp_glyph
->pixel_width
;
22653 /* Pre calculation of re-rendering position */
22655 hpos
= (area
== ON_MODE_LINE
22656 ? (w
->current_matrix
)->nrows
- 1
22659 /* If the re-rendering position is included in the last
22660 re-rendering area, we should do nothing. */
22661 if ( EQ (window
, dpyinfo
->mouse_face_window
)
22662 && dpyinfo
->mouse_face_beg_col
<= vpos
22663 && vpos
< dpyinfo
->mouse_face_end_col
22664 && dpyinfo
->mouse_face_beg_row
== hpos
)
22667 if (clear_mouse_face (dpyinfo
))
22668 cursor
= No_Cursor
;
22670 dpyinfo
->mouse_face_beg_col
= vpos
;
22671 dpyinfo
->mouse_face_beg_row
= hpos
;
22673 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
22674 dpyinfo
->mouse_face_beg_y
= 0;
22676 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
22677 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
22679 dpyinfo
->mouse_face_end_x
= 0;
22680 dpyinfo
->mouse_face_end_y
= 0;
22682 dpyinfo
->mouse_face_past_end
= 0;
22683 dpyinfo
->mouse_face_window
= window
;
22685 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
22688 glyph
->face_id
, 1);
22689 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22691 if (NILP (pointer
))
22694 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22695 clear_mouse_face (dpyinfo
);
22697 define_frame_cursor1 (f
, cursor
, pointer
);
22702 Take proper action when the mouse has moved to position X, Y on
22703 frame F as regards highlighting characters that have mouse-face
22704 properties. Also de-highlighting chars where the mouse was before.
22705 X and Y can be negative or out of range. */
22708 note_mouse_highlight (f
, x
, y
)
22712 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22713 enum window_part part
;
22714 Lisp_Object window
;
22716 Cursor cursor
= No_Cursor
;
22717 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
22720 /* When a menu is active, don't highlight because this looks odd. */
22721 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (MAC_OS)
22722 if (popup_activated ())
22726 if (NILP (Vmouse_highlight
)
22727 || !f
->glyphs_initialized_p
)
22730 dpyinfo
->mouse_face_mouse_x
= x
;
22731 dpyinfo
->mouse_face_mouse_y
= y
;
22732 dpyinfo
->mouse_face_mouse_frame
= f
;
22734 if (dpyinfo
->mouse_face_defer
)
22737 if (gc_in_progress
)
22739 dpyinfo
->mouse_face_deferred_gc
= 1;
22743 /* Which window is that in? */
22744 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
22746 /* If we were displaying active text in another window, clear that.
22747 Also clear if we move out of text area in same window. */
22748 if (! EQ (window
, dpyinfo
->mouse_face_window
)
22749 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
22750 && !NILP (dpyinfo
->mouse_face_window
)))
22751 clear_mouse_face (dpyinfo
);
22753 /* Not on a window -> return. */
22754 if (!WINDOWP (window
))
22757 /* Reset help_echo_string. It will get recomputed below. */
22758 help_echo_string
= Qnil
;
22760 /* Convert to window-relative pixel coordinates. */
22761 w
= XWINDOW (window
);
22762 frame_to_window_pixel_xy (w
, &x
, &y
);
22764 /* Handle tool-bar window differently since it doesn't display a
22766 if (EQ (window
, f
->tool_bar_window
))
22768 note_tool_bar_highlight (f
, x
, y
);
22772 /* Mouse is on the mode, header line or margin? */
22773 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
22774 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
22776 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
22780 if (part
== ON_VERTICAL_BORDER
)
22782 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22783 help_echo_string
= build_string ("drag-mouse-1: resize");
22785 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
22786 || part
== ON_SCROLL_BAR
)
22787 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22789 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22791 /* Are we in a window whose display is up to date?
22792 And verify the buffer's text has not changed. */
22793 b
= XBUFFER (w
->buffer
);
22794 if (part
== ON_TEXT
22795 && EQ (w
->window_end_valid
, w
->buffer
)
22796 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
22797 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
22799 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
22800 struct glyph
*glyph
;
22801 Lisp_Object object
;
22802 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
22803 Lisp_Object
*overlay_vec
= NULL
;
22805 struct buffer
*obuf
;
22806 int obegv
, ozv
, same_region
;
22808 /* Find the glyph under X/Y. */
22809 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
22811 /* Look for :pointer property on image. */
22812 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22814 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22815 if (img
!= NULL
&& IMAGEP (img
->spec
))
22817 Lisp_Object image_map
, hotspot
;
22818 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
22820 && (hotspot
= find_hot_spot (image_map
,
22821 glyph
->slice
.x
+ dx
,
22822 glyph
->slice
.y
+ dy
),
22824 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22826 Lisp_Object area_id
, plist
;
22828 area_id
= XCAR (hotspot
);
22829 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22830 If so, we could look for mouse-enter, mouse-leave
22831 properties in PLIST (and do something...). */
22832 hotspot
= XCDR (hotspot
);
22833 if (CONSP (hotspot
)
22834 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22836 pointer
= Fplist_get (plist
, Qpointer
);
22837 if (NILP (pointer
))
22839 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
22840 if (!NILP (help_echo_string
))
22842 help_echo_window
= window
;
22843 help_echo_object
= glyph
->object
;
22844 help_echo_pos
= glyph
->charpos
;
22848 if (NILP (pointer
))
22849 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
22853 /* Clear mouse face if X/Y not over text. */
22855 || area
!= TEXT_AREA
22856 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
22858 if (clear_mouse_face (dpyinfo
))
22859 cursor
= No_Cursor
;
22860 if (NILP (pointer
))
22862 if (area
!= TEXT_AREA
)
22863 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22865 pointer
= Vvoid_text_area_pointer
;
22870 pos
= glyph
->charpos
;
22871 object
= glyph
->object
;
22872 if (!STRINGP (object
) && !BUFFERP (object
))
22875 /* If we get an out-of-range value, return now; avoid an error. */
22876 if (BUFFERP (object
) && pos
> BUF_Z (b
))
22879 /* Make the window's buffer temporarily current for
22880 overlays_at and compute_char_face. */
22881 obuf
= current_buffer
;
22882 current_buffer
= b
;
22888 /* Is this char mouse-active or does it have help-echo? */
22889 position
= make_number (pos
);
22891 if (BUFFERP (object
))
22893 /* Put all the overlays we want in a vector in overlay_vec. */
22894 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
22895 /* Sort overlays into increasing priority order. */
22896 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
22901 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
22902 && vpos
>= dpyinfo
->mouse_face_beg_row
22903 && vpos
<= dpyinfo
->mouse_face_end_row
22904 && (vpos
> dpyinfo
->mouse_face_beg_row
22905 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22906 && (vpos
< dpyinfo
->mouse_face_end_row
22907 || hpos
< dpyinfo
->mouse_face_end_col
22908 || dpyinfo
->mouse_face_past_end
));
22911 cursor
= No_Cursor
;
22913 /* Check mouse-face highlighting. */
22915 /* If there exists an overlay with mouse-face overlapping
22916 the one we are currently highlighting, we have to
22917 check if we enter the overlapping overlay, and then
22918 highlight only that. */
22919 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
22920 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
22922 /* Find the highest priority overlay that has a mouse-face
22925 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
22927 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
22928 if (!NILP (mouse_face
))
22929 overlay
= overlay_vec
[i
];
22932 /* If we're actually highlighting the same overlay as
22933 before, there's no need to do that again. */
22934 if (!NILP (overlay
)
22935 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
22936 goto check_help_echo
;
22938 dpyinfo
->mouse_face_overlay
= overlay
;
22940 /* Clear the display of the old active region, if any. */
22941 if (clear_mouse_face (dpyinfo
))
22942 cursor
= No_Cursor
;
22944 /* If no overlay applies, get a text property. */
22945 if (NILP (overlay
))
22946 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
22948 /* Handle the overlay case. */
22949 if (!NILP (overlay
))
22951 /* Find the range of text around this char that
22952 should be active. */
22953 Lisp_Object before
, after
;
22956 before
= Foverlay_start (overlay
);
22957 after
= Foverlay_end (overlay
);
22958 /* Record this as the current active region. */
22959 fast_find_position (w
, XFASTINT (before
),
22960 &dpyinfo
->mouse_face_beg_col
,
22961 &dpyinfo
->mouse_face_beg_row
,
22962 &dpyinfo
->mouse_face_beg_x
,
22963 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22965 dpyinfo
->mouse_face_past_end
22966 = !fast_find_position (w
, XFASTINT (after
),
22967 &dpyinfo
->mouse_face_end_col
,
22968 &dpyinfo
->mouse_face_end_row
,
22969 &dpyinfo
->mouse_face_end_x
,
22970 &dpyinfo
->mouse_face_end_y
, Qnil
);
22971 dpyinfo
->mouse_face_window
= window
;
22973 dpyinfo
->mouse_face_face_id
22974 = face_at_buffer_position (w
, pos
, 0, 0,
22976 !dpyinfo
->mouse_face_hidden
);
22978 /* Display it as active. */
22979 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22980 cursor
= No_Cursor
;
22982 /* Handle the text property case. */
22983 else if (!NILP (mouse_face
) && BUFFERP (object
))
22985 /* Find the range of text around this char that
22986 should be active. */
22987 Lisp_Object before
, after
, beginning
, end
;
22990 beginning
= Fmarker_position (w
->start
);
22991 end
= make_number (BUF_Z (XBUFFER (object
))
22992 - XFASTINT (w
->window_end_pos
));
22994 = Fprevious_single_property_change (make_number (pos
+ 1),
22996 object
, beginning
);
22998 = Fnext_single_property_change (position
, Qmouse_face
,
23001 /* Record this as the current active region. */
23002 fast_find_position (w
, XFASTINT (before
),
23003 &dpyinfo
->mouse_face_beg_col
,
23004 &dpyinfo
->mouse_face_beg_row
,
23005 &dpyinfo
->mouse_face_beg_x
,
23006 &dpyinfo
->mouse_face_beg_y
, Qnil
);
23007 dpyinfo
->mouse_face_past_end
23008 = !fast_find_position (w
, XFASTINT (after
),
23009 &dpyinfo
->mouse_face_end_col
,
23010 &dpyinfo
->mouse_face_end_row
,
23011 &dpyinfo
->mouse_face_end_x
,
23012 &dpyinfo
->mouse_face_end_y
, Qnil
);
23013 dpyinfo
->mouse_face_window
= window
;
23015 if (BUFFERP (object
))
23016 dpyinfo
->mouse_face_face_id
23017 = face_at_buffer_position (w
, pos
, 0, 0,
23019 !dpyinfo
->mouse_face_hidden
);
23021 /* Display it as active. */
23022 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23023 cursor
= No_Cursor
;
23025 else if (!NILP (mouse_face
) && STRINGP (object
))
23030 b
= Fprevious_single_property_change (make_number (pos
+ 1),
23033 e
= Fnext_single_property_change (position
, Qmouse_face
,
23036 b
= make_number (0);
23038 e
= make_number (SCHARS (object
) - 1);
23040 fast_find_string_pos (w
, XINT (b
), object
,
23041 &dpyinfo
->mouse_face_beg_col
,
23042 &dpyinfo
->mouse_face_beg_row
,
23043 &dpyinfo
->mouse_face_beg_x
,
23044 &dpyinfo
->mouse_face_beg_y
, 0);
23045 fast_find_string_pos (w
, XINT (e
), object
,
23046 &dpyinfo
->mouse_face_end_col
,
23047 &dpyinfo
->mouse_face_end_row
,
23048 &dpyinfo
->mouse_face_end_x
,
23049 &dpyinfo
->mouse_face_end_y
, 1);
23050 dpyinfo
->mouse_face_past_end
= 0;
23051 dpyinfo
->mouse_face_window
= window
;
23052 dpyinfo
->mouse_face_face_id
23053 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
23054 glyph
->face_id
, 1);
23055 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23056 cursor
= No_Cursor
;
23058 else if (STRINGP (object
) && NILP (mouse_face
))
23060 /* A string which doesn't have mouse-face, but
23061 the text ``under'' it might have. */
23062 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
23063 int start
= MATRIX_ROW_START_CHARPOS (r
);
23065 pos
= string_buffer_position (w
, object
, start
);
23067 mouse_face
= get_char_property_and_overlay (make_number (pos
),
23071 if (!NILP (mouse_face
) && !NILP (overlay
))
23073 Lisp_Object before
= Foverlay_start (overlay
);
23074 Lisp_Object after
= Foverlay_end (overlay
);
23077 /* Note that we might not be able to find position
23078 BEFORE in the glyph matrix if the overlay is
23079 entirely covered by a `display' property. In
23080 this case, we overshoot. So let's stop in
23081 the glyph matrix before glyphs for OBJECT. */
23082 fast_find_position (w
, XFASTINT (before
),
23083 &dpyinfo
->mouse_face_beg_col
,
23084 &dpyinfo
->mouse_face_beg_row
,
23085 &dpyinfo
->mouse_face_beg_x
,
23086 &dpyinfo
->mouse_face_beg_y
,
23089 dpyinfo
->mouse_face_past_end
23090 = !fast_find_position (w
, XFASTINT (after
),
23091 &dpyinfo
->mouse_face_end_col
,
23092 &dpyinfo
->mouse_face_end_row
,
23093 &dpyinfo
->mouse_face_end_x
,
23094 &dpyinfo
->mouse_face_end_y
,
23096 dpyinfo
->mouse_face_window
= window
;
23097 dpyinfo
->mouse_face_face_id
23098 = face_at_buffer_position (w
, pos
, 0, 0,
23100 !dpyinfo
->mouse_face_hidden
);
23102 /* Display it as active. */
23103 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23104 cursor
= No_Cursor
;
23111 /* Look for a `help-echo' property. */
23112 if (NILP (help_echo_string
)) {
23113 Lisp_Object help
, overlay
;
23115 /* Check overlays first. */
23116 help
= overlay
= Qnil
;
23117 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
23119 overlay
= overlay_vec
[i
];
23120 help
= Foverlay_get (overlay
, Qhelp_echo
);
23125 help_echo_string
= help
;
23126 help_echo_window
= window
;
23127 help_echo_object
= overlay
;
23128 help_echo_pos
= pos
;
23132 Lisp_Object object
= glyph
->object
;
23133 int charpos
= glyph
->charpos
;
23135 /* Try text properties. */
23136 if (STRINGP (object
)
23138 && charpos
< SCHARS (object
))
23140 help
= Fget_text_property (make_number (charpos
),
23141 Qhelp_echo
, object
);
23144 /* If the string itself doesn't specify a help-echo,
23145 see if the buffer text ``under'' it does. */
23146 struct glyph_row
*r
23147 = MATRIX_ROW (w
->current_matrix
, vpos
);
23148 int start
= MATRIX_ROW_START_CHARPOS (r
);
23149 int pos
= string_buffer_position (w
, object
, start
);
23152 help
= Fget_char_property (make_number (pos
),
23153 Qhelp_echo
, w
->buffer
);
23157 object
= w
->buffer
;
23162 else if (BUFFERP (object
)
23165 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23170 help_echo_string
= help
;
23171 help_echo_window
= window
;
23172 help_echo_object
= object
;
23173 help_echo_pos
= charpos
;
23178 /* Look for a `pointer' property. */
23179 if (NILP (pointer
))
23181 /* Check overlays first. */
23182 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23183 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23185 if (NILP (pointer
))
23187 Lisp_Object object
= glyph
->object
;
23188 int charpos
= glyph
->charpos
;
23190 /* Try text properties. */
23191 if (STRINGP (object
)
23193 && charpos
< SCHARS (object
))
23195 pointer
= Fget_text_property (make_number (charpos
),
23197 if (NILP (pointer
))
23199 /* If the string itself doesn't specify a pointer,
23200 see if the buffer text ``under'' it does. */
23201 struct glyph_row
*r
23202 = MATRIX_ROW (w
->current_matrix
, vpos
);
23203 int start
= MATRIX_ROW_START_CHARPOS (r
);
23204 int pos
= string_buffer_position (w
, object
, start
);
23206 pointer
= Fget_char_property (make_number (pos
),
23207 Qpointer
, w
->buffer
);
23210 else if (BUFFERP (object
)
23213 pointer
= Fget_text_property (make_number (charpos
),
23220 current_buffer
= obuf
;
23225 define_frame_cursor1 (f
, cursor
, pointer
);
23230 Clear any mouse-face on window W. This function is part of the
23231 redisplay interface, and is called from try_window_id and similar
23232 functions to ensure the mouse-highlight is off. */
23235 x_clear_window_mouse_face (w
)
23238 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23239 Lisp_Object window
;
23242 XSETWINDOW (window
, w
);
23243 if (EQ (window
, dpyinfo
->mouse_face_window
))
23244 clear_mouse_face (dpyinfo
);
23250 Just discard the mouse face information for frame F, if any.
23251 This is used when the size of F is changed. */
23254 cancel_mouse_face (f
)
23257 Lisp_Object window
;
23258 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23260 window
= dpyinfo
->mouse_face_window
;
23261 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
23263 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23264 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23265 dpyinfo
->mouse_face_window
= Qnil
;
23270 #endif /* HAVE_WINDOW_SYSTEM */
23273 /***********************************************************************
23275 ***********************************************************************/
23277 #ifdef HAVE_WINDOW_SYSTEM
23279 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
23280 which intersects rectangle R. R is in window-relative coordinates. */
23283 expose_area (w
, row
, r
, area
)
23285 struct glyph_row
*row
;
23287 enum glyph_row_area area
;
23289 struct glyph
*first
= row
->glyphs
[area
];
23290 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
23291 struct glyph
*last
;
23292 int first_x
, start_x
, x
;
23294 if (area
== TEXT_AREA
&& row
->fill_line_p
)
23295 /* If row extends face to end of line write the whole line. */
23296 draw_glyphs (w
, 0, row
, area
,
23297 0, row
->used
[area
],
23298 DRAW_NORMAL_TEXT
, 0);
23301 /* Set START_X to the window-relative start position for drawing glyphs of
23302 AREA. The first glyph of the text area can be partially visible.
23303 The first glyphs of other areas cannot. */
23304 start_x
= window_box_left_offset (w
, area
);
23306 if (area
== TEXT_AREA
)
23309 /* Find the first glyph that must be redrawn. */
23311 && x
+ first
->pixel_width
< r
->x
)
23313 x
+= first
->pixel_width
;
23317 /* Find the last one. */
23321 && x
< r
->x
+ r
->width
)
23323 x
+= last
->pixel_width
;
23329 draw_glyphs (w
, first_x
- start_x
, row
, area
,
23330 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
23331 DRAW_NORMAL_TEXT
, 0);
23336 /* Redraw the parts of the glyph row ROW on window W intersecting
23337 rectangle R. R is in window-relative coordinates. Value is
23338 non-zero if mouse-face was overwritten. */
23341 expose_line (w
, row
, r
)
23343 struct glyph_row
*row
;
23346 xassert (row
->enabled_p
);
23348 if (row
->mode_line_p
|| w
->pseudo_window_p
)
23349 draw_glyphs (w
, 0, row
, TEXT_AREA
,
23350 0, row
->used
[TEXT_AREA
],
23351 DRAW_NORMAL_TEXT
, 0);
23354 if (row
->used
[LEFT_MARGIN_AREA
])
23355 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
23356 if (row
->used
[TEXT_AREA
])
23357 expose_area (w
, row
, r
, TEXT_AREA
);
23358 if (row
->used
[RIGHT_MARGIN_AREA
])
23359 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
23360 draw_row_fringe_bitmaps (w
, row
);
23363 return row
->mouse_face_p
;
23367 /* Redraw those parts of glyphs rows during expose event handling that
23368 overlap other rows. Redrawing of an exposed line writes over parts
23369 of lines overlapping that exposed line; this function fixes that.
23371 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
23372 row in W's current matrix that is exposed and overlaps other rows.
23373 LAST_OVERLAPPING_ROW is the last such row. */
23376 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
23378 struct glyph_row
*first_overlapping_row
;
23379 struct glyph_row
*last_overlapping_row
;
23381 struct glyph_row
*row
;
23383 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
23384 if (row
->overlapping_p
)
23386 xassert (row
->enabled_p
&& !row
->mode_line_p
);
23388 if (row
->used
[LEFT_MARGIN_AREA
])
23389 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
23391 if (row
->used
[TEXT_AREA
])
23392 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
23394 if (row
->used
[RIGHT_MARGIN_AREA
])
23395 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
23400 /* Return non-zero if W's cursor intersects rectangle R. */
23403 phys_cursor_in_rect_p (w
, r
)
23407 XRectangle cr
, result
;
23408 struct glyph
*cursor_glyph
;
23410 cursor_glyph
= get_phys_cursor_glyph (w
);
23413 /* r is relative to W's box, but w->phys_cursor.x is relative
23414 to left edge of W's TEXT area. Adjust it. */
23415 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
23416 cr
.y
= w
->phys_cursor
.y
;
23417 cr
.width
= cursor_glyph
->pixel_width
;
23418 cr
.height
= w
->phys_cursor_height
;
23419 /* ++KFS: W32 version used W32-specific IntersectRect here, but
23420 I assume the effect is the same -- and this is portable. */
23421 return x_intersect_rectangles (&cr
, r
, &result
);
23429 Draw a vertical window border to the right of window W if W doesn't
23430 have vertical scroll bars. */
23433 x_draw_vertical_border (w
)
23436 /* We could do better, if we knew what type of scroll-bar the adjacent
23437 windows (on either side) have... But we don't :-(
23438 However, I think this works ok. ++KFS 2003-04-25 */
23440 /* Redraw borders between horizontally adjacent windows. Don't
23441 do it for frames with vertical scroll bars because either the
23442 right scroll bar of a window, or the left scroll bar of its
23443 neighbor will suffice as a border. */
23444 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
23447 if (!WINDOW_RIGHTMOST_P (w
)
23448 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
23450 int x0
, x1
, y0
, y1
;
23452 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23455 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23458 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
23460 else if (!WINDOW_LEFTMOST_P (w
)
23461 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
23463 int x0
, x1
, y0
, y1
;
23465 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23468 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23471 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
23476 /* Redraw the part of window W intersection rectangle FR. Pixel
23477 coordinates in FR are frame-relative. Call this function with
23478 input blocked. Value is non-zero if the exposure overwrites
23482 expose_window (w
, fr
)
23486 struct frame
*f
= XFRAME (w
->frame
);
23488 int mouse_face_overwritten_p
= 0;
23490 /* If window is not yet fully initialized, do nothing. This can
23491 happen when toolkit scroll bars are used and a window is split.
23492 Reconfiguring the scroll bar will generate an expose for a newly
23494 if (w
->current_matrix
== NULL
)
23497 /* When we're currently updating the window, display and current
23498 matrix usually don't agree. Arrange for a thorough display
23500 if (w
== updated_window
)
23502 SET_FRAME_GARBAGED (f
);
23506 /* Frame-relative pixel rectangle of W. */
23507 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
23508 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
23509 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
23510 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
23512 if (x_intersect_rectangles (fr
, &wr
, &r
))
23514 int yb
= window_text_bottom_y (w
);
23515 struct glyph_row
*row
;
23516 int cursor_cleared_p
;
23517 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
23519 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
23520 r
.x
, r
.y
, r
.width
, r
.height
));
23522 /* Convert to window coordinates. */
23523 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
23524 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
23526 /* Turn off the cursor. */
23527 if (!w
->pseudo_window_p
23528 && phys_cursor_in_rect_p (w
, &r
))
23530 x_clear_cursor (w
);
23531 cursor_cleared_p
= 1;
23534 cursor_cleared_p
= 0;
23536 /* Update lines intersecting rectangle R. */
23537 first_overlapping_row
= last_overlapping_row
= NULL
;
23538 for (row
= w
->current_matrix
->rows
;
23543 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
23545 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
23546 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
23547 || (r
.y
>= y0
&& r
.y
< y1
)
23548 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
23550 /* A header line may be overlapping, but there is no need
23551 to fix overlapping areas for them. KFS 2005-02-12 */
23552 if (row
->overlapping_p
&& !row
->mode_line_p
)
23554 if (first_overlapping_row
== NULL
)
23555 first_overlapping_row
= row
;
23556 last_overlapping_row
= row
;
23559 if (expose_line (w
, row
, &r
))
23560 mouse_face_overwritten_p
= 1;
23567 /* Display the mode line if there is one. */
23568 if (WINDOW_WANTS_MODELINE_P (w
)
23569 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
23571 && row
->y
< r
.y
+ r
.height
)
23573 if (expose_line (w
, row
, &r
))
23574 mouse_face_overwritten_p
= 1;
23577 if (!w
->pseudo_window_p
)
23579 /* Fix the display of overlapping rows. */
23580 if (first_overlapping_row
)
23581 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
23583 /* Draw border between windows. */
23584 x_draw_vertical_border (w
);
23586 /* Turn the cursor on again. */
23587 if (cursor_cleared_p
)
23588 update_window_cursor (w
, 1);
23592 return mouse_face_overwritten_p
;
23597 /* Redraw (parts) of all windows in the window tree rooted at W that
23598 intersect R. R contains frame pixel coordinates. Value is
23599 non-zero if the exposure overwrites mouse-face. */
23602 expose_window_tree (w
, r
)
23606 struct frame
*f
= XFRAME (w
->frame
);
23607 int mouse_face_overwritten_p
= 0;
23609 while (w
&& !FRAME_GARBAGED_P (f
))
23611 if (!NILP (w
->hchild
))
23612 mouse_face_overwritten_p
23613 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
23614 else if (!NILP (w
->vchild
))
23615 mouse_face_overwritten_p
23616 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
23618 mouse_face_overwritten_p
|= expose_window (w
, r
);
23620 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
23623 return mouse_face_overwritten_p
;
23628 Redisplay an exposed area of frame F. X and Y are the upper-left
23629 corner of the exposed rectangle. W and H are width and height of
23630 the exposed area. All are pixel values. W or H zero means redraw
23631 the entire frame. */
23634 expose_frame (f
, x
, y
, w
, h
)
23639 int mouse_face_overwritten_p
= 0;
23641 TRACE ((stderr
, "expose_frame "));
23643 /* No need to redraw if frame will be redrawn soon. */
23644 if (FRAME_GARBAGED_P (f
))
23646 TRACE ((stderr
, " garbaged\n"));
23650 /* If basic faces haven't been realized yet, there is no point in
23651 trying to redraw anything. This can happen when we get an expose
23652 event while Emacs is starting, e.g. by moving another window. */
23653 if (FRAME_FACE_CACHE (f
) == NULL
23654 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
23656 TRACE ((stderr
, " no faces\n"));
23660 if (w
== 0 || h
== 0)
23663 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
23664 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
23674 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
23675 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
23677 if (WINDOWP (f
->tool_bar_window
))
23678 mouse_face_overwritten_p
23679 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
23681 #ifdef HAVE_X_WINDOWS
23683 #ifndef USE_X_TOOLKIT
23684 if (WINDOWP (f
->menu_bar_window
))
23685 mouse_face_overwritten_p
23686 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
23687 #endif /* not USE_X_TOOLKIT */
23691 /* Some window managers support a focus-follows-mouse style with
23692 delayed raising of frames. Imagine a partially obscured frame,
23693 and moving the mouse into partially obscured mouse-face on that
23694 frame. The visible part of the mouse-face will be highlighted,
23695 then the WM raises the obscured frame. With at least one WM, KDE
23696 2.1, Emacs is not getting any event for the raising of the frame
23697 (even tried with SubstructureRedirectMask), only Expose events.
23698 These expose events will draw text normally, i.e. not
23699 highlighted. Which means we must redo the highlight here.
23700 Subsume it under ``we love X''. --gerd 2001-08-15 */
23701 /* Included in Windows version because Windows most likely does not
23702 do the right thing if any third party tool offers
23703 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
23704 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
23706 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23707 if (f
== dpyinfo
->mouse_face_mouse_frame
)
23709 int x
= dpyinfo
->mouse_face_mouse_x
;
23710 int y
= dpyinfo
->mouse_face_mouse_y
;
23711 clear_mouse_face (dpyinfo
);
23712 note_mouse_highlight (f
, x
, y
);
23719 Determine the intersection of two rectangles R1 and R2. Return
23720 the intersection in *RESULT. Value is non-zero if RESULT is not
23724 x_intersect_rectangles (r1
, r2
, result
)
23725 XRectangle
*r1
, *r2
, *result
;
23727 XRectangle
*left
, *right
;
23728 XRectangle
*upper
, *lower
;
23729 int intersection_p
= 0;
23731 /* Rearrange so that R1 is the left-most rectangle. */
23733 left
= r1
, right
= r2
;
23735 left
= r2
, right
= r1
;
23737 /* X0 of the intersection is right.x0, if this is inside R1,
23738 otherwise there is no intersection. */
23739 if (right
->x
<= left
->x
+ left
->width
)
23741 result
->x
= right
->x
;
23743 /* The right end of the intersection is the minimum of the
23744 the right ends of left and right. */
23745 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
23748 /* Same game for Y. */
23750 upper
= r1
, lower
= r2
;
23752 upper
= r2
, lower
= r1
;
23754 /* The upper end of the intersection is lower.y0, if this is inside
23755 of upper. Otherwise, there is no intersection. */
23756 if (lower
->y
<= upper
->y
+ upper
->height
)
23758 result
->y
= lower
->y
;
23760 /* The lower end of the intersection is the minimum of the lower
23761 ends of upper and lower. */
23762 result
->height
= (min (lower
->y
+ lower
->height
,
23763 upper
->y
+ upper
->height
)
23765 intersection_p
= 1;
23769 return intersection_p
;
23772 #endif /* HAVE_WINDOW_SYSTEM */
23775 /***********************************************************************
23777 ***********************************************************************/
23782 Vwith_echo_area_save_vector
= Qnil
;
23783 staticpro (&Vwith_echo_area_save_vector
);
23785 Vmessage_stack
= Qnil
;
23786 staticpro (&Vmessage_stack
);
23788 Qinhibit_redisplay
= intern ("inhibit-redisplay");
23789 staticpro (&Qinhibit_redisplay
);
23791 message_dolog_marker1
= Fmake_marker ();
23792 staticpro (&message_dolog_marker1
);
23793 message_dolog_marker2
= Fmake_marker ();
23794 staticpro (&message_dolog_marker2
);
23795 message_dolog_marker3
= Fmake_marker ();
23796 staticpro (&message_dolog_marker3
);
23799 defsubr (&Sdump_frame_glyph_matrix
);
23800 defsubr (&Sdump_glyph_matrix
);
23801 defsubr (&Sdump_glyph_row
);
23802 defsubr (&Sdump_tool_bar_row
);
23803 defsubr (&Strace_redisplay
);
23804 defsubr (&Strace_to_stderr
);
23806 #ifdef HAVE_WINDOW_SYSTEM
23807 defsubr (&Stool_bar_lines_needed
);
23808 defsubr (&Slookup_image_map
);
23810 defsubr (&Sformat_mode_line
);
23812 staticpro (&Qmenu_bar_update_hook
);
23813 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
23815 staticpro (&Qoverriding_terminal_local_map
);
23816 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
23818 staticpro (&Qoverriding_local_map
);
23819 Qoverriding_local_map
= intern ("overriding-local-map");
23821 staticpro (&Qwindow_scroll_functions
);
23822 Qwindow_scroll_functions
= intern ("window-scroll-functions");
23824 staticpro (&Qredisplay_end_trigger_functions
);
23825 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
23827 staticpro (&Qinhibit_point_motion_hooks
);
23828 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
23830 QCdata
= intern (":data");
23831 staticpro (&QCdata
);
23832 Qdisplay
= intern ("display");
23833 staticpro (&Qdisplay
);
23834 Qspace_width
= intern ("space-width");
23835 staticpro (&Qspace_width
);
23836 Qraise
= intern ("raise");
23837 staticpro (&Qraise
);
23838 Qslice
= intern ("slice");
23839 staticpro (&Qslice
);
23840 Qspace
= intern ("space");
23841 staticpro (&Qspace
);
23842 Qmargin
= intern ("margin");
23843 staticpro (&Qmargin
);
23844 Qpointer
= intern ("pointer");
23845 staticpro (&Qpointer
);
23846 Qleft_margin
= intern ("left-margin");
23847 staticpro (&Qleft_margin
);
23848 Qright_margin
= intern ("right-margin");
23849 staticpro (&Qright_margin
);
23850 Qcenter
= intern ("center");
23851 staticpro (&Qcenter
);
23852 Qline_height
= intern ("line-height");
23853 staticpro (&Qline_height
);
23854 QCalign_to
= intern (":align-to");
23855 staticpro (&QCalign_to
);
23856 QCrelative_width
= intern (":relative-width");
23857 staticpro (&QCrelative_width
);
23858 QCrelative_height
= intern (":relative-height");
23859 staticpro (&QCrelative_height
);
23860 QCeval
= intern (":eval");
23861 staticpro (&QCeval
);
23862 QCpropertize
= intern (":propertize");
23863 staticpro (&QCpropertize
);
23864 QCfile
= intern (":file");
23865 staticpro (&QCfile
);
23866 Qfontified
= intern ("fontified");
23867 staticpro (&Qfontified
);
23868 Qfontification_functions
= intern ("fontification-functions");
23869 staticpro (&Qfontification_functions
);
23870 Qtrailing_whitespace
= intern ("trailing-whitespace");
23871 staticpro (&Qtrailing_whitespace
);
23872 Qescape_glyph
= intern ("escape-glyph");
23873 staticpro (&Qescape_glyph
);
23874 Qnobreak_space
= intern ("nobreak-space");
23875 staticpro (&Qnobreak_space
);
23876 Qimage
= intern ("image");
23877 staticpro (&Qimage
);
23878 QCmap
= intern (":map");
23879 staticpro (&QCmap
);
23880 QCpointer
= intern (":pointer");
23881 staticpro (&QCpointer
);
23882 Qrect
= intern ("rect");
23883 staticpro (&Qrect
);
23884 Qcircle
= intern ("circle");
23885 staticpro (&Qcircle
);
23886 Qpoly
= intern ("poly");
23887 staticpro (&Qpoly
);
23888 Qmessage_truncate_lines
= intern ("message-truncate-lines");
23889 staticpro (&Qmessage_truncate_lines
);
23890 Qgrow_only
= intern ("grow-only");
23891 staticpro (&Qgrow_only
);
23892 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
23893 staticpro (&Qinhibit_menubar_update
);
23894 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
23895 staticpro (&Qinhibit_eval_during_redisplay
);
23896 Qposition
= intern ("position");
23897 staticpro (&Qposition
);
23898 Qbuffer_position
= intern ("buffer-position");
23899 staticpro (&Qbuffer_position
);
23900 Qobject
= intern ("object");
23901 staticpro (&Qobject
);
23902 Qbar
= intern ("bar");
23904 Qhbar
= intern ("hbar");
23905 staticpro (&Qhbar
);
23906 Qbox
= intern ("box");
23908 Qhollow
= intern ("hollow");
23909 staticpro (&Qhollow
);
23910 Qhand
= intern ("hand");
23911 staticpro (&Qhand
);
23912 Qarrow
= intern ("arrow");
23913 staticpro (&Qarrow
);
23914 Qtext
= intern ("text");
23915 staticpro (&Qtext
);
23916 Qrisky_local_variable
= intern ("risky-local-variable");
23917 staticpro (&Qrisky_local_variable
);
23918 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
23919 staticpro (&Qinhibit_free_realized_faces
);
23921 list_of_error
= Fcons (Fcons (intern ("error"),
23922 Fcons (intern ("void-variable"), Qnil
)),
23924 staticpro (&list_of_error
);
23926 Qlast_arrow_position
= intern ("last-arrow-position");
23927 staticpro (&Qlast_arrow_position
);
23928 Qlast_arrow_string
= intern ("last-arrow-string");
23929 staticpro (&Qlast_arrow_string
);
23931 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
23932 staticpro (&Qoverlay_arrow_string
);
23933 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
23934 staticpro (&Qoverlay_arrow_bitmap
);
23936 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
23937 staticpro (&echo_buffer
[0]);
23938 staticpro (&echo_buffer
[1]);
23940 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
23941 staticpro (&echo_area_buffer
[0]);
23942 staticpro (&echo_area_buffer
[1]);
23944 Vmessages_buffer_name
= build_string ("*Messages*");
23945 staticpro (&Vmessages_buffer_name
);
23947 mode_line_proptrans_alist
= Qnil
;
23948 staticpro (&mode_line_proptrans_alist
);
23949 mode_line_string_list
= Qnil
;
23950 staticpro (&mode_line_string_list
);
23951 mode_line_string_face
= Qnil
;
23952 staticpro (&mode_line_string_face
);
23953 mode_line_string_face_prop
= Qnil
;
23954 staticpro (&mode_line_string_face_prop
);
23955 Vmode_line_unwind_vector
= Qnil
;
23956 staticpro (&Vmode_line_unwind_vector
);
23958 help_echo_string
= Qnil
;
23959 staticpro (&help_echo_string
);
23960 help_echo_object
= Qnil
;
23961 staticpro (&help_echo_object
);
23962 help_echo_window
= Qnil
;
23963 staticpro (&help_echo_window
);
23964 previous_help_echo_string
= Qnil
;
23965 staticpro (&previous_help_echo_string
);
23966 help_echo_pos
= -1;
23968 #ifdef HAVE_WINDOW_SYSTEM
23969 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
23970 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
23971 For example, if a block cursor is over a tab, it will be drawn as
23972 wide as that tab on the display. */);
23973 x_stretch_cursor_p
= 0;
23976 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
23977 doc
: /* *Non-nil means highlight trailing whitespace.
23978 The face used for trailing whitespace is `trailing-whitespace'. */);
23979 Vshow_trailing_whitespace
= Qnil
;
23981 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
23982 doc
: /* *Control highlighting of nobreak space and soft hyphen.
23983 A value of t means highlight the character itself (for nobreak space,
23984 use face `nobreak-space').
23985 A value of nil means no highlighting.
23986 Other values mean display the escape glyph followed by an ordinary
23987 space or ordinary hyphen. */);
23988 Vnobreak_char_display
= Qt
;
23990 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
23991 doc
: /* *The pointer shape to show in void text areas.
23992 A value of nil means to show the text pointer. Other options are `arrow',
23993 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
23994 Vvoid_text_area_pointer
= Qarrow
;
23996 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
23997 doc
: /* Non-nil means don't actually do any redisplay.
23998 This is used for internal purposes. */);
23999 Vinhibit_redisplay
= Qnil
;
24001 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
24002 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
24003 Vglobal_mode_string
= Qnil
;
24005 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
24006 doc
: /* Marker for where to display an arrow on top of the buffer text.
24007 This must be the beginning of a line in order to work.
24008 See also `overlay-arrow-string'. */);
24009 Voverlay_arrow_position
= Qnil
;
24011 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
24012 doc
: /* String to display as an arrow in non-window frames.
24013 See also `overlay-arrow-position'. */);
24014 Voverlay_arrow_string
= build_string ("=>");
24016 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
24017 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
24018 The symbols on this list are examined during redisplay to determine
24019 where to display overlay arrows. */);
24020 Voverlay_arrow_variable_list
24021 = Fcons (intern ("overlay-arrow-position"), Qnil
);
24023 DEFVAR_INT ("scroll-step", &scroll_step
,
24024 doc
: /* *The number of lines to try scrolling a window by when point moves out.
24025 If that fails to bring point back on frame, point is centered instead.
24026 If this is zero, point is always centered after it moves off frame.
24027 If you want scrolling to always be a line at a time, you should set
24028 `scroll-conservatively' to a large value rather than set this to 1. */);
24030 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
24031 doc
: /* *Scroll up to this many lines, to bring point back on screen.
24032 A value of zero means to scroll the text to center point vertically
24033 in the window. */);
24034 scroll_conservatively
= 0;
24036 DEFVAR_INT ("scroll-margin", &scroll_margin
,
24037 doc
: /* *Number of lines of margin at the top and bottom of a window.
24038 Recenter the window whenever point gets within this many lines
24039 of the top or bottom of the window. */);
24042 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
24043 doc
: /* Pixels per inch value for non-window system displays.
24044 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
24045 Vdisplay_pixels_per_inch
= make_float (72.0);
24048 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
24051 DEFVAR_BOOL ("truncate-partial-width-windows",
24052 &truncate_partial_width_windows
,
24053 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
24054 truncate_partial_width_windows
= 1;
24056 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
24057 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
24058 Any other value means to use the appropriate face, `mode-line',
24059 `header-line', or `menu' respectively. */);
24060 mode_line_inverse_video
= 1;
24062 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
24063 doc
: /* *Maximum buffer size for which line number should be displayed.
24064 If the buffer is bigger than this, the line number does not appear
24065 in the mode line. A value of nil means no limit. */);
24066 Vline_number_display_limit
= Qnil
;
24068 DEFVAR_INT ("line-number-display-limit-width",
24069 &line_number_display_limit_width
,
24070 doc
: /* *Maximum line width (in characters) for line number display.
24071 If the average length of the lines near point is bigger than this, then the
24072 line number may be omitted from the mode line. */);
24073 line_number_display_limit_width
= 200;
24075 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
24076 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
24077 highlight_nonselected_windows
= 0;
24079 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
24080 doc
: /* Non-nil if more than one frame is visible on this display.
24081 Minibuffer-only frames don't count, but iconified frames do.
24082 This variable is not guaranteed to be accurate except while processing
24083 `frame-title-format' and `icon-title-format'. */);
24085 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
24086 doc
: /* Template for displaying the title bar of visible frames.
24087 \(Assuming the window manager supports this feature.)
24089 This variable has the same structure as `mode-line-format', except that
24090 the %c and %l constructs are ignored. It is used only on frames for
24091 which no explicit name has been set \(see `modify-frame-parameters'). */);
24093 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
24094 doc
: /* Template for displaying the title bar of an iconified frame.
24095 \(Assuming the window manager supports this feature.)
24096 This variable has the same structure as `mode-line-format' (which see),
24097 and is used only on frames for which no explicit name has been set
24098 \(see `modify-frame-parameters'). */);
24100 = Vframe_title_format
24101 = Fcons (intern ("multiple-frames"),
24102 Fcons (build_string ("%b"),
24103 Fcons (Fcons (empty_string
,
24104 Fcons (intern ("invocation-name"),
24105 Fcons (build_string ("@"),
24106 Fcons (intern ("system-name"),
24110 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
24111 doc
: /* Maximum number of lines to keep in the message log buffer.
24112 If nil, disable message logging. If t, log messages but don't truncate
24113 the buffer when it becomes large. */);
24114 Vmessage_log_max
= make_number (100);
24116 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
24117 doc
: /* Functions called before redisplay, if window sizes have changed.
24118 The value should be a list of functions that take one argument.
24119 Just before redisplay, for each frame, if any of its windows have changed
24120 size since the last redisplay, or have been split or deleted,
24121 all the functions in the list are called, with the frame as argument. */);
24122 Vwindow_size_change_functions
= Qnil
;
24124 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
24125 doc
: /* List of functions to call before redisplaying a window with scrolling.
24126 Each function is called with two arguments, the window
24127 and its new display-start position. Note that the value of `window-end'
24128 is not valid when these functions are called. */);
24129 Vwindow_scroll_functions
= Qnil
;
24131 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
24132 doc
: /* Functions called when redisplay of a window reaches the end trigger.
24133 Each function is called with two arguments, the window and the end trigger value.
24134 See `set-window-redisplay-end-trigger'. */);
24135 Vredisplay_end_trigger_functions
= Qnil
;
24137 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
24138 doc
: /* *Non-nil means autoselect window with mouse pointer.
24139 If nil, do not autoselect windows.
24140 A positive number means delay autoselection by that many seconds: a
24141 window is autoselected only after the mouse has remained in that
24142 window for the duration of the delay.
24143 A negative number has a similar effect, but causes windows to be
24144 autoselected only after the mouse has stopped moving. \(Because of
24145 the way Emacs compares mouse events, you will occasionally wait twice
24146 that time before the window gets selected.\)
24147 Any other value means to autoselect window instantaneously when the
24148 mouse pointer enters it.
24150 Autoselection selects the minibuffer only if it is active, and never
24151 unselects the minibuffer if it is active.
24153 When customizing this variable make sure that the actual value of
24154 `focus-follows-mouse' matches the behavior of your window manager. */);
24155 Vmouse_autoselect_window
= Qnil
;
24157 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
24158 doc
: /* *Non-nil means automatically resize tool-bars.
24159 This dynamically changes the tool-bar's height to the minimum height
24160 that is needed to make all tool-bar items visible.
24161 If value is `grow-only', the tool-bar's height is only increased
24162 automatically; to decrease the tool-bar height, use \\[recenter]. */);
24163 Vauto_resize_tool_bars
= Qt
;
24165 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
24166 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
24167 auto_raise_tool_bar_buttons_p
= 1;
24169 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
24170 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
24171 make_cursor_line_fully_visible_p
= 1;
24173 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
24174 doc
: /* *Border below tool-bar in pixels.
24175 If an integer, use it as the height of the border.
24176 If it is one of `internal-border-width' or `border-width', use the
24177 value of the corresponding frame parameter.
24178 Otherwise, no border is added below the tool-bar. */);
24179 Vtool_bar_border
= Qinternal_border_width
;
24181 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
24182 doc
: /* *Margin around tool-bar buttons in pixels.
24183 If an integer, use that for both horizontal and vertical margins.
24184 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
24185 HORZ specifying the horizontal margin, and VERT specifying the
24186 vertical margin. */);
24187 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
24189 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
24190 doc
: /* *Relief thickness of tool-bar buttons. */);
24191 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
24193 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
24194 doc
: /* List of functions to call to fontify regions of text.
24195 Each function is called with one argument POS. Functions must
24196 fontify a region starting at POS in the current buffer, and give
24197 fontified regions the property `fontified'. */);
24198 Vfontification_functions
= Qnil
;
24199 Fmake_variable_buffer_local (Qfontification_functions
);
24201 DEFVAR_BOOL ("unibyte-display-via-language-environment",
24202 &unibyte_display_via_language_environment
,
24203 doc
: /* *Non-nil means display unibyte text according to language environment.
24204 Specifically this means that unibyte non-ASCII characters
24205 are displayed by converting them to the equivalent multibyte characters
24206 according to the current language environment. As a result, they are
24207 displayed according to the current fontset. */);
24208 unibyte_display_via_language_environment
= 0;
24210 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
24211 doc
: /* *Maximum height for resizing mini-windows.
24212 If a float, it specifies a fraction of the mini-window frame's height.
24213 If an integer, it specifies a number of lines. */);
24214 Vmax_mini_window_height
= make_float (0.25);
24216 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
24217 doc
: /* *How to resize mini-windows.
24218 A value of nil means don't automatically resize mini-windows.
24219 A value of t means resize them to fit the text displayed in them.
24220 A value of `grow-only', the default, means let mini-windows grow
24221 only, until their display becomes empty, at which point the windows
24222 go back to their normal size. */);
24223 Vresize_mini_windows
= Qgrow_only
;
24225 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
24226 doc
: /* Alist specifying how to blink the cursor off.
24227 Each element has the form (ON-STATE . OFF-STATE). Whenever the
24228 `cursor-type' frame-parameter or variable equals ON-STATE,
24229 comparing using `equal', Emacs uses OFF-STATE to specify
24230 how to blink it off. ON-STATE and OFF-STATE are values for
24231 the `cursor-type' frame parameter.
24233 If a frame's ON-STATE has no entry in this list,
24234 the frame's other specifications determine how to blink the cursor off. */);
24235 Vblink_cursor_alist
= Qnil
;
24237 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
24238 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
24239 automatic_hscrolling_p
= 1;
24241 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
24242 doc
: /* *How many columns away from the window edge point is allowed to get
24243 before automatic hscrolling will horizontally scroll the window. */);
24244 hscroll_margin
= 5;
24246 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
24247 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
24248 When point is less than `hscroll-margin' columns from the window
24249 edge, automatic hscrolling will scroll the window by the amount of columns
24250 determined by this variable. If its value is a positive integer, scroll that
24251 many columns. If it's a positive floating-point number, it specifies the
24252 fraction of the window's width to scroll. If it's nil or zero, point will be
24253 centered horizontally after the scroll. Any other value, including negative
24254 numbers, are treated as if the value were zero.
24256 Automatic hscrolling always moves point outside the scroll margin, so if
24257 point was more than scroll step columns inside the margin, the window will
24258 scroll more than the value given by the scroll step.
24260 Note that the lower bound for automatic hscrolling specified by `scroll-left'
24261 and `scroll-right' overrides this variable's effect. */);
24262 Vhscroll_step
= make_number (0);
24264 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
24265 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
24266 Bind this around calls to `message' to let it take effect. */);
24267 message_truncate_lines
= 0;
24269 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
24270 doc
: /* Normal hook run to update the menu bar definitions.
24271 Redisplay runs this hook before it redisplays the menu bar.
24272 This is used to update submenus such as Buffers,
24273 whose contents depend on various data. */);
24274 Vmenu_bar_update_hook
= Qnil
;
24276 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
24277 doc
: /* Frame for which we are updating a menu.
24278 The enable predicate for a menu binding should check this variable. */);
24279 Vmenu_updating_frame
= Qnil
;
24281 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
24282 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
24283 inhibit_menubar_update
= 0;
24285 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
24286 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
24287 inhibit_eval_during_redisplay
= 0;
24289 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
24290 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
24291 inhibit_free_realized_faces
= 0;
24294 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
24295 doc
: /* Inhibit try_window_id display optimization. */);
24296 inhibit_try_window_id
= 0;
24298 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
24299 doc
: /* Inhibit try_window_reusing display optimization. */);
24300 inhibit_try_window_reusing
= 0;
24302 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
24303 doc
: /* Inhibit try_cursor_movement display optimization. */);
24304 inhibit_try_cursor_movement
= 0;
24305 #endif /* GLYPH_DEBUG */
24307 DEFVAR_INT ("overline-margin", &overline_margin
,
24308 doc
: /* *Space between overline and text, in pixels.
24309 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
24310 margin to the caracter height. */);
24311 overline_margin
= 2;
24315 /* Initialize this module when Emacs starts. */
24320 Lisp_Object root_window
;
24321 struct window
*mini_w
;
24323 current_header_line_height
= current_mode_line_height
= -1;
24325 CHARPOS (this_line_start_pos
) = 0;
24327 mini_w
= XWINDOW (minibuf_window
);
24328 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
24330 if (!noninteractive
)
24332 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
24335 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
24336 set_window_height (root_window
,
24337 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
24339 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
24340 set_window_height (minibuf_window
, 1, 0);
24342 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
24343 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
24345 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
24346 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
24347 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
24349 /* The default ellipsis glyphs `...'. */
24350 for (i
= 0; i
< 3; ++i
)
24351 default_invis_vector
[i
] = make_number ('.');
24355 /* Allocate the buffer for frame titles.
24356 Also used for `format-mode-line'. */
24358 mode_line_noprop_buf
= (char *) xmalloc (size
);
24359 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
24360 mode_line_noprop_ptr
= mode_line_noprop_buf
;
24361 mode_line_target
= MODE_LINE_DISPLAY
;
24364 help_echo_showing_p
= 0;
24368 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
24369 (do not change this comment) */