1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay do? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking an iterator structure (struct it)
126 Iteration over things to be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator.
128 Calls to get_next_display_element fill the iterator structure with
129 relevant information about the next thing to display. Calls to
130 set_iterator_to_next move the iterator to the next thing.
132 Besides this, an iterator also contains information about the
133 display environment in which glyphs for display elements are to be
134 produced. It has fields for the width and height of the display,
135 the information whether long lines are truncated or continued, a
136 current X and Y position, and lots of other stuff you can better
139 Glyphs in a desired matrix are normally constructed in a loop
140 calling get_next_display_element and then produce_glyphs. The call
141 to produce_glyphs will fill the iterator structure with pixel
142 information about the element being displayed and at the same time
143 produce glyphs for it. If the display element fits on the line
144 being displayed, set_iterator_to_next is called next, otherwise the
145 glyphs produced are discarded.
150 That just couldn't be all, could it? What about terminal types not
151 supporting operations on sub-windows of the screen? To update the
152 display on such a terminal, window-based glyph matrices are not
153 well suited. To be able to reuse part of the display (scrolling
154 lines up and down), we must instead have a view of the whole
155 screen. This is what `frame matrices' are for. They are a trick.
157 Frames on terminals like above have a glyph pool. Windows on such
158 a frame sub-allocate their glyph memory from their frame's glyph
159 pool. The frame itself is given its own glyph matrices. By
160 coincidence---or maybe something else---rows in window glyph
161 matrices are slices of corresponding rows in frame matrices. Thus
162 writing to window matrices implicitly updates a frame matrix which
163 provides us with the view of the whole screen that we originally
164 wanted to have without having to move many bytes around. To be
165 honest, there is a little bit more done, but not much more. If you
166 plan to extend that code, take a look at dispnew.c. The function
167 build_frame_matrix is a good starting point. */
173 #include "keyboard.h"
176 #include "termchar.h"
177 #include "dispextern.h"
181 #include "commands.h"
185 #include "termhooks.h"
186 #include "intervals.h"
189 #include "region-cache.h"
191 #include "blockinput.h"
193 #ifdef HAVE_X_WINDOWS
203 #ifndef FRAME_X_OUTPUT
204 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
207 #define INFINITY 10000000
209 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
211 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
212 extern int pending_menu_activation
;
215 extern int interrupt_input
;
216 extern int command_loop_level
;
218 extern Lisp_Object do_mouse_tracking
;
220 extern int minibuffer_auto_raise
;
221 extern Lisp_Object Vminibuffer_list
;
223 extern Lisp_Object Qface
;
224 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
226 extern Lisp_Object Voverriding_local_map
;
227 extern Lisp_Object Voverriding_local_map_menu_flag
;
228 extern Lisp_Object Qmenu_item
;
229 extern Lisp_Object Qwhen
;
230 extern Lisp_Object Qhelp_echo
;
232 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
233 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
234 Lisp_Object Qredisplay_end_trigger_functions
;
235 Lisp_Object Qinhibit_point_motion_hooks
;
236 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
237 Lisp_Object Qfontified
;
238 Lisp_Object Qgrow_only
;
239 Lisp_Object Qinhibit_eval_during_redisplay
;
240 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
243 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
246 Lisp_Object Qarrow
, Qhand
, Qtext
;
248 Lisp_Object Qrisky_local_variable
;
250 /* Holds the list (error). */
251 Lisp_Object list_of_error
;
253 /* Functions called to fontify regions of text. */
255 Lisp_Object Vfontification_functions
;
256 Lisp_Object Qfontification_functions
;
258 /* Non-zero means automatically select any window when the mouse
259 cursor moves into it. */
260 int mouse_autoselect_window
;
262 /* Non-zero means draw tool bar buttons raised when the mouse moves
265 int auto_raise_tool_bar_buttons_p
;
267 /* Non-zero means to reposition window if cursor line is only partially visible. */
269 int make_cursor_line_fully_visible_p
;
271 /* Margin around tool bar buttons in pixels. */
273 Lisp_Object Vtool_bar_button_margin
;
275 /* Thickness of shadow to draw around tool bar buttons. */
277 EMACS_INT tool_bar_button_relief
;
279 /* Non-zero means automatically resize tool-bars so that all tool-bar
280 items are visible, and no blank lines remain. */
282 int auto_resize_tool_bars_p
;
284 /* Non-zero means draw block and hollow cursor as wide as the glyph
285 under it. For example, if a block cursor is over a tab, it will be
286 drawn as wide as that tab on the display. */
288 int x_stretch_cursor_p
;
290 /* Non-nil means don't actually do any redisplay. */
292 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
294 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
296 int inhibit_eval_during_redisplay
;
298 /* Names of text properties relevant for redisplay. */
300 Lisp_Object Qdisplay
;
301 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
303 /* Symbols used in text property values. */
305 Lisp_Object Vdisplay_pixels_per_inch
;
306 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
307 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
310 Lisp_Object Qmargin
, Qpointer
;
311 Lisp_Object Qline_height
;
312 extern Lisp_Object Qheight
;
313 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
314 extern Lisp_Object Qscroll_bar
;
315 extern Lisp_Object Qcursor
;
317 /* Non-nil means highlight trailing whitespace. */
319 Lisp_Object Vshow_trailing_whitespace
;
321 /* Non-nil means escape non-break space and hyphens. */
323 Lisp_Object Vnobreak_char_display
;
325 #ifdef HAVE_WINDOW_SYSTEM
326 extern Lisp_Object Voverflow_newline_into_fringe
;
328 /* Test if overflow newline into fringe. Called with iterator IT
329 at or past right window margin, and with IT->current_x set. */
331 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
332 (!NILP (Voverflow_newline_into_fringe) \
333 && FRAME_WINDOW_P (it->f) \
334 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
335 && it->current_x == it->last_visible_x)
337 #endif /* HAVE_WINDOW_SYSTEM */
339 /* Non-nil means show the text cursor in void text areas
340 i.e. in blank areas after eol and eob. This used to be
341 the default in 21.3. */
343 Lisp_Object Vvoid_text_area_pointer
;
345 /* Name of the face used to highlight trailing whitespace. */
347 Lisp_Object Qtrailing_whitespace
;
349 /* Name and number of the face used to highlight escape glyphs. */
351 Lisp_Object Qescape_glyph
;
353 /* Name and number of the face used to highlight non-breaking spaces. */
355 Lisp_Object Qnobreak_space
;
357 /* The symbol `image' which is the car of the lists used to represent
362 /* The image map types. */
363 Lisp_Object QCmap
, QCpointer
;
364 Lisp_Object Qrect
, Qcircle
, Qpoly
;
366 /* Non-zero means print newline to stdout before next mini-buffer
369 int noninteractive_need_newline
;
371 /* Non-zero means print newline to message log before next message. */
373 static int message_log_need_newline
;
375 /* Three markers that message_dolog uses.
376 It could allocate them itself, but that causes trouble
377 in handling memory-full errors. */
378 static Lisp_Object message_dolog_marker1
;
379 static Lisp_Object message_dolog_marker2
;
380 static Lisp_Object message_dolog_marker3
;
382 /* The buffer position of the first character appearing entirely or
383 partially on the line of the selected window which contains the
384 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
385 redisplay optimization in redisplay_internal. */
387 static struct text_pos this_line_start_pos
;
389 /* Number of characters past the end of the line above, including the
390 terminating newline. */
392 static struct text_pos this_line_end_pos
;
394 /* The vertical positions and the height of this line. */
396 static int this_line_vpos
;
397 static int this_line_y
;
398 static int this_line_pixel_height
;
400 /* X position at which this display line starts. Usually zero;
401 negative if first character is partially visible. */
403 static int this_line_start_x
;
405 /* Buffer that this_line_.* variables are referring to. */
407 static struct buffer
*this_line_buffer
;
409 /* Nonzero means truncate lines in all windows less wide than the
412 int truncate_partial_width_windows
;
414 /* A flag to control how to display unibyte 8-bit character. */
416 int unibyte_display_via_language_environment
;
418 /* Nonzero means we have more than one non-mini-buffer-only frame.
419 Not guaranteed to be accurate except while parsing
420 frame-title-format. */
424 Lisp_Object Vglobal_mode_string
;
427 /* List of variables (symbols) which hold markers for overlay arrows.
428 The symbols on this list are examined during redisplay to determine
429 where to display overlay arrows. */
431 Lisp_Object Voverlay_arrow_variable_list
;
433 /* Marker for where to display an arrow on top of the buffer text. */
435 Lisp_Object Voverlay_arrow_position
;
437 /* String to display for the arrow. Only used on terminal frames. */
439 Lisp_Object Voverlay_arrow_string
;
441 /* Values of those variables at last redisplay are stored as
442 properties on `overlay-arrow-position' symbol. However, if
443 Voverlay_arrow_position is a marker, last-arrow-position is its
444 numerical position. */
446 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
448 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
449 properties on a symbol in overlay-arrow-variable-list. */
451 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
453 /* Like mode-line-format, but for the title bar on a visible frame. */
455 Lisp_Object Vframe_title_format
;
457 /* Like mode-line-format, but for the title bar on an iconified frame. */
459 Lisp_Object Vicon_title_format
;
461 /* List of functions to call when a window's size changes. These
462 functions get one arg, a frame on which one or more windows' sizes
465 static Lisp_Object Vwindow_size_change_functions
;
467 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
469 /* Nonzero if an overlay arrow has been displayed in this window. */
471 static int overlay_arrow_seen
;
473 /* Nonzero means highlight the region even in nonselected windows. */
475 int highlight_nonselected_windows
;
477 /* If cursor motion alone moves point off frame, try scrolling this
478 many lines up or down if that will bring it back. */
480 static EMACS_INT scroll_step
;
482 /* Nonzero means scroll just far enough to bring point back on the
483 screen, when appropriate. */
485 static EMACS_INT scroll_conservatively
;
487 /* Recenter the window whenever point gets within this many lines of
488 the top or bottom of the window. This value is translated into a
489 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
490 that there is really a fixed pixel height scroll margin. */
492 EMACS_INT scroll_margin
;
494 /* Number of windows showing the buffer of the selected window (or
495 another buffer with the same base buffer). keyboard.c refers to
500 /* Vector containing glyphs for an ellipsis `...'. */
502 static Lisp_Object default_invis_vector
[3];
504 /* Zero means display the mode-line/header-line/menu-bar in the default face
505 (this slightly odd definition is for compatibility with previous versions
506 of emacs), non-zero means display them using their respective faces.
508 This variable is deprecated. */
510 int mode_line_inverse_video
;
512 /* Prompt to display in front of the mini-buffer contents. */
514 Lisp_Object minibuf_prompt
;
516 /* Width of current mini-buffer prompt. Only set after display_line
517 of the line that contains the prompt. */
519 int minibuf_prompt_width
;
521 /* This is the window where the echo area message was displayed. It
522 is always a mini-buffer window, but it may not be the same window
523 currently active as a mini-buffer. */
525 Lisp_Object echo_area_window
;
527 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
528 pushes the current message and the value of
529 message_enable_multibyte on the stack, the function restore_message
530 pops the stack and displays MESSAGE again. */
532 Lisp_Object Vmessage_stack
;
534 /* Nonzero means multibyte characters were enabled when the echo area
535 message was specified. */
537 int message_enable_multibyte
;
539 /* Nonzero if we should redraw the mode lines on the next redisplay. */
541 int update_mode_lines
;
543 /* Nonzero if window sizes or contents have changed since last
544 redisplay that finished. */
546 int windows_or_buffers_changed
;
548 /* Nonzero means a frame's cursor type has been changed. */
550 int cursor_type_changed
;
552 /* Nonzero after display_mode_line if %l was used and it displayed a
555 int line_number_displayed
;
557 /* Maximum buffer size for which to display line numbers. */
559 Lisp_Object Vline_number_display_limit
;
561 /* Line width to consider when repositioning for line number display. */
563 static EMACS_INT line_number_display_limit_width
;
565 /* Number of lines to keep in the message log buffer. t means
566 infinite. nil means don't log at all. */
568 Lisp_Object Vmessage_log_max
;
570 /* The name of the *Messages* buffer, a string. */
572 static Lisp_Object Vmessages_buffer_name
;
574 /* Current, index 0, and last displayed echo area message. Either
575 buffers from echo_buffers, or nil to indicate no message. */
577 Lisp_Object echo_area_buffer
[2];
579 /* The buffers referenced from echo_area_buffer. */
581 static Lisp_Object echo_buffer
[2];
583 /* A vector saved used in with_area_buffer to reduce consing. */
585 static Lisp_Object Vwith_echo_area_save_vector
;
587 /* Non-zero means display_echo_area should display the last echo area
588 message again. Set by redisplay_preserve_echo_area. */
590 static int display_last_displayed_message_p
;
592 /* Nonzero if echo area is being used by print; zero if being used by
595 int message_buf_print
;
597 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
599 Lisp_Object Qinhibit_menubar_update
;
600 int inhibit_menubar_update
;
602 /* Maximum height for resizing mini-windows. Either a float
603 specifying a fraction of the available height, or an integer
604 specifying a number of lines. */
606 Lisp_Object Vmax_mini_window_height
;
608 /* Non-zero means messages should be displayed with truncated
609 lines instead of being continued. */
611 int message_truncate_lines
;
612 Lisp_Object Qmessage_truncate_lines
;
614 /* Set to 1 in clear_message to make redisplay_internal aware
615 of an emptied echo area. */
617 static int message_cleared_p
;
619 /* How to blink the default frame cursor off. */
620 Lisp_Object Vblink_cursor_alist
;
622 /* A scratch glyph row with contents used for generating truncation
623 glyphs. Also used in direct_output_for_insert. */
625 #define MAX_SCRATCH_GLYPHS 100
626 struct glyph_row scratch_glyph_row
;
627 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
629 /* Ascent and height of the last line processed by move_it_to. */
631 static int last_max_ascent
, last_height
;
633 /* Non-zero if there's a help-echo in the echo area. */
635 int help_echo_showing_p
;
637 /* If >= 0, computed, exact values of mode-line and header-line height
638 to use in the macros CURRENT_MODE_LINE_HEIGHT and
639 CURRENT_HEADER_LINE_HEIGHT. */
641 int current_mode_line_height
, current_header_line_height
;
643 /* The maximum distance to look ahead for text properties. Values
644 that are too small let us call compute_char_face and similar
645 functions too often which is expensive. Values that are too large
646 let us call compute_char_face and alike too often because we
647 might not be interested in text properties that far away. */
649 #define TEXT_PROP_DISTANCE_LIMIT 100
653 /* Variables to turn off display optimizations from Lisp. */
655 int inhibit_try_window_id
, inhibit_try_window_reusing
;
656 int inhibit_try_cursor_movement
;
658 /* Non-zero means print traces of redisplay if compiled with
661 int trace_redisplay_p
;
663 #endif /* GLYPH_DEBUG */
665 #ifdef DEBUG_TRACE_MOVE
666 /* Non-zero means trace with TRACE_MOVE to stderr. */
669 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
671 #define TRACE_MOVE(x) (void) 0
674 /* Non-zero means automatically scroll windows horizontally to make
677 int automatic_hscrolling_p
;
679 /* How close to the margin can point get before the window is scrolled
681 EMACS_INT hscroll_margin
;
683 /* How much to scroll horizontally when point is inside the above margin. */
684 Lisp_Object Vhscroll_step
;
686 /* The variable `resize-mini-windows'. If nil, don't resize
687 mini-windows. If t, always resize them to fit the text they
688 display. If `grow-only', let mini-windows grow only until they
691 Lisp_Object Vresize_mini_windows
;
693 /* Buffer being redisplayed -- for redisplay_window_error. */
695 struct buffer
*displayed_buffer
;
697 /* Value returned from text property handlers (see below). */
702 HANDLED_RECOMPUTE_PROPS
,
703 HANDLED_OVERLAY_STRING_CONSUMED
,
707 /* A description of text properties that redisplay is interested
712 /* The name of the property. */
715 /* A unique index for the property. */
718 /* A handler function called to set up iterator IT from the property
719 at IT's current position. Value is used to steer handle_stop. */
720 enum prop_handled (*handler
) P_ ((struct it
*it
));
723 static enum prop_handled handle_face_prop
P_ ((struct it
*));
724 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
725 static enum prop_handled handle_display_prop
P_ ((struct it
*));
726 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
727 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
728 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
730 /* Properties handled by iterators. */
732 static struct props it_props
[] =
734 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
735 /* Handle `face' before `display' because some sub-properties of
736 `display' need to know the face. */
737 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
738 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
739 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
740 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
744 /* Value is the position described by X. If X is a marker, value is
745 the marker_position of X. Otherwise, value is X. */
747 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
749 /* Enumeration returned by some move_it_.* functions internally. */
753 /* Not used. Undefined value. */
756 /* Move ended at the requested buffer position or ZV. */
757 MOVE_POS_MATCH_OR_ZV
,
759 /* Move ended at the requested X pixel position. */
762 /* Move within a line ended at the end of a line that must be
766 /* Move within a line ended at the end of a line that would
767 be displayed truncated. */
770 /* Move within a line ended at a line end. */
774 /* This counter is used to clear the face cache every once in a while
775 in redisplay_internal. It is incremented for each redisplay.
776 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
779 #define CLEAR_FACE_CACHE_COUNT 500
780 static int clear_face_cache_count
;
782 /* Similarly for the image cache. */
784 #ifdef HAVE_WINDOW_SYSTEM
785 #define CLEAR_IMAGE_CACHE_COUNT 101
786 static int clear_image_cache_count
;
789 /* Non-zero while redisplay_internal is in progress. */
793 /* Non-zero means don't free realized faces. Bound while freeing
794 realized faces is dangerous because glyph matrices might still
797 int inhibit_free_realized_faces
;
798 Lisp_Object Qinhibit_free_realized_faces
;
800 /* If a string, XTread_socket generates an event to display that string.
801 (The display is done in read_char.) */
803 Lisp_Object help_echo_string
;
804 Lisp_Object help_echo_window
;
805 Lisp_Object help_echo_object
;
808 /* Temporary variable for XTread_socket. */
810 Lisp_Object previous_help_echo_string
;
812 /* Null glyph slice */
814 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
817 /* Function prototypes. */
819 static void setup_for_ellipsis
P_ ((struct it
*, int));
820 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
821 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
822 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
823 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
824 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
825 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
828 static int invisible_text_between_p
P_ ((struct it
*, int, int));
831 static void pint2str
P_ ((char *, int, int));
832 static void pint2hrstr
P_ ((char *, int, int));
833 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
835 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
836 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
837 static void store_mode_line_noprop_char
P_ ((char));
838 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
839 static void x_consider_frame_title
P_ ((Lisp_Object
));
840 static void handle_stop
P_ ((struct it
*));
841 static int tool_bar_lines_needed
P_ ((struct frame
*));
842 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
843 static void ensure_echo_area_buffers
P_ ((void));
844 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
845 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
846 static int with_echo_area_buffer
P_ ((struct window
*, int,
847 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
848 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
849 static void clear_garbaged_frames
P_ ((void));
850 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
851 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
852 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
853 static int display_echo_area
P_ ((struct window
*));
854 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
855 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
856 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
857 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
858 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
860 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
861 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
862 static void insert_left_trunc_glyphs
P_ ((struct it
*));
863 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
865 static void extend_face_to_end_of_line
P_ ((struct it
*));
866 static int append_space_for_newline
P_ ((struct it
*, int));
867 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
868 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
869 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
870 static int trailing_whitespace_p
P_ ((int));
871 static int message_log_check_duplicate
P_ ((int, int, int, int));
872 static void push_it
P_ ((struct it
*));
873 static void pop_it
P_ ((struct it
*));
874 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
875 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
876 static void redisplay_internal
P_ ((int));
877 static int echo_area_display
P_ ((int));
878 static void redisplay_windows
P_ ((Lisp_Object
));
879 static void redisplay_window
P_ ((Lisp_Object
, int));
880 static Lisp_Object
redisplay_window_error ();
881 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
882 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
883 static void update_menu_bar
P_ ((struct frame
*, int));
884 static int try_window_reusing_current_matrix
P_ ((struct window
*));
885 static int try_window_id
P_ ((struct window
*));
886 static int display_line
P_ ((struct it
*));
887 static int display_mode_lines
P_ ((struct window
*));
888 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
889 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
890 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
891 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
892 static void display_menu_bar
P_ ((struct window
*));
893 static int display_count_lines
P_ ((int, int, int, int, int *));
894 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
895 int, int, struct it
*, int, int, int, int));
896 static void compute_line_metrics
P_ ((struct it
*));
897 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
898 static int get_overlay_strings
P_ ((struct it
*, int));
899 static void next_overlay_string
P_ ((struct it
*));
900 static void reseat
P_ ((struct it
*, struct text_pos
, int));
901 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
902 static void back_to_previous_visible_line_start
P_ ((struct it
*));
903 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
904 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
905 static int next_element_from_ellipsis
P_ ((struct it
*));
906 static int next_element_from_display_vector
P_ ((struct it
*));
907 static int next_element_from_string
P_ ((struct it
*));
908 static int next_element_from_c_string
P_ ((struct it
*));
909 static int next_element_from_buffer
P_ ((struct it
*));
910 static int next_element_from_composition
P_ ((struct it
*));
911 static int next_element_from_image
P_ ((struct it
*));
912 static int next_element_from_stretch
P_ ((struct it
*));
913 static void load_overlay_strings
P_ ((struct it
*, int));
914 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
915 struct display_pos
*));
916 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
917 Lisp_Object
, int, int, int, int));
918 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
920 void move_it_vertically_backward
P_ ((struct it
*, int));
921 static void init_to_row_start
P_ ((struct it
*, struct window
*,
922 struct glyph_row
*));
923 static int init_to_row_end
P_ ((struct it
*, struct window
*,
924 struct glyph_row
*));
925 static void back_to_previous_line_start
P_ ((struct it
*));
926 static int forward_to_next_line_start
P_ ((struct it
*, int *));
927 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
929 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
930 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
931 static int number_of_chars
P_ ((unsigned char *, int));
932 static void compute_stop_pos
P_ ((struct it
*));
933 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
935 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
936 static int next_overlay_change
P_ ((int));
937 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
938 Lisp_Object
, struct text_pos
*,
940 static int underlying_face_id
P_ ((struct it
*));
941 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
944 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
945 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
947 #ifdef HAVE_WINDOW_SYSTEM
949 static void update_tool_bar
P_ ((struct frame
*, int));
950 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
951 static int redisplay_tool_bar
P_ ((struct frame
*));
952 static void display_tool_bar_line
P_ ((struct it
*));
953 static void notice_overwritten_cursor
P_ ((struct window
*,
955 int, int, int, int));
959 #endif /* HAVE_WINDOW_SYSTEM */
962 /***********************************************************************
963 Window display dimensions
964 ***********************************************************************/
966 /* Return the bottom boundary y-position for text lines in window W.
967 This is the first y position at which a line cannot start.
968 It is relative to the top of the window.
970 This is the height of W minus the height of a mode line, if any. */
973 window_text_bottom_y (w
)
976 int height
= WINDOW_TOTAL_HEIGHT (w
);
978 if (WINDOW_WANTS_MODELINE_P (w
))
979 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
983 /* Return the pixel width of display area AREA of window W. AREA < 0
984 means return the total width of W, not including fringes to
985 the left and right of the window. */
988 window_box_width (w
, area
)
992 int cols
= XFASTINT (w
->total_cols
);
995 if (!w
->pseudo_window_p
)
997 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
999 if (area
== TEXT_AREA
)
1001 if (INTEGERP (w
->left_margin_cols
))
1002 cols
-= XFASTINT (w
->left_margin_cols
);
1003 if (INTEGERP (w
->right_margin_cols
))
1004 cols
-= XFASTINT (w
->right_margin_cols
);
1005 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1007 else if (area
== LEFT_MARGIN_AREA
)
1009 cols
= (INTEGERP (w
->left_margin_cols
)
1010 ? XFASTINT (w
->left_margin_cols
) : 0);
1013 else if (area
== RIGHT_MARGIN_AREA
)
1015 cols
= (INTEGERP (w
->right_margin_cols
)
1016 ? XFASTINT (w
->right_margin_cols
) : 0);
1021 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1025 /* Return the pixel height of the display area of window W, not
1026 including mode lines of W, if any. */
1029 window_box_height (w
)
1032 struct frame
*f
= XFRAME (w
->frame
);
1033 int height
= WINDOW_TOTAL_HEIGHT (w
);
1035 xassert (height
>= 0);
1037 /* Note: the code below that determines the mode-line/header-line
1038 height is essentially the same as that contained in the macro
1039 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1040 the appropriate glyph row has its `mode_line_p' flag set,
1041 and if it doesn't, uses estimate_mode_line_height instead. */
1043 if (WINDOW_WANTS_MODELINE_P (w
))
1045 struct glyph_row
*ml_row
1046 = (w
->current_matrix
&& w
->current_matrix
->rows
1047 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1049 if (ml_row
&& ml_row
->mode_line_p
)
1050 height
-= ml_row
->height
;
1052 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1055 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1057 struct glyph_row
*hl_row
1058 = (w
->current_matrix
&& w
->current_matrix
->rows
1059 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1061 if (hl_row
&& hl_row
->mode_line_p
)
1062 height
-= hl_row
->height
;
1064 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1067 /* With a very small font and a mode-line that's taller than
1068 default, we might end up with a negative height. */
1069 return max (0, height
);
1072 /* Return the window-relative coordinate of the left edge of display
1073 area AREA of window W. AREA < 0 means return the left edge of the
1074 whole window, to the right of the left fringe of W. */
1077 window_box_left_offset (w
, area
)
1083 if (w
->pseudo_window_p
)
1086 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1088 if (area
== TEXT_AREA
)
1089 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1090 + window_box_width (w
, LEFT_MARGIN_AREA
));
1091 else if (area
== RIGHT_MARGIN_AREA
)
1092 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1093 + window_box_width (w
, LEFT_MARGIN_AREA
)
1094 + window_box_width (w
, TEXT_AREA
)
1095 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1097 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1098 else if (area
== LEFT_MARGIN_AREA
1099 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1100 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1106 /* Return the window-relative coordinate of the right edge of display
1107 area AREA of window W. AREA < 0 means return the left edge of the
1108 whole window, to the left of the right fringe of W. */
1111 window_box_right_offset (w
, area
)
1115 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1118 /* Return the frame-relative coordinate of the left edge of display
1119 area AREA of window W. AREA < 0 means return the left edge of the
1120 whole window, to the right of the left fringe of W. */
1123 window_box_left (w
, area
)
1127 struct frame
*f
= XFRAME (w
->frame
);
1130 if (w
->pseudo_window_p
)
1131 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1133 x
= (WINDOW_LEFT_EDGE_X (w
)
1134 + window_box_left_offset (w
, area
));
1140 /* Return the frame-relative coordinate of the right edge of display
1141 area AREA of window W. AREA < 0 means return the left edge of the
1142 whole window, to the left of the right fringe of W. */
1145 window_box_right (w
, area
)
1149 return window_box_left (w
, area
) + window_box_width (w
, area
);
1152 /* Get the bounding box of the display area AREA of window W, without
1153 mode lines, in frame-relative coordinates. AREA < 0 means the
1154 whole window, not including the left and right fringes of
1155 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1156 coordinates of the upper-left corner of the box. Return in
1157 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1160 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1163 int *box_x
, *box_y
, *box_width
, *box_height
;
1166 *box_width
= window_box_width (w
, area
);
1168 *box_height
= window_box_height (w
);
1170 *box_x
= window_box_left (w
, area
);
1173 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1174 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1175 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1180 /* Get the bounding box of the display area AREA of window W, without
1181 mode lines. AREA < 0 means the whole window, not including the
1182 left and right fringe of the window. Return in *TOP_LEFT_X
1183 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1184 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1185 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1189 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1190 bottom_right_x
, bottom_right_y
)
1193 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1195 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1197 *bottom_right_x
+= *top_left_x
;
1198 *bottom_right_y
+= *top_left_y
;
1203 /***********************************************************************
1205 ***********************************************************************/
1207 /* Return the bottom y-position of the line the iterator IT is in.
1208 This can modify IT's settings. */
1214 int line_height
= it
->max_ascent
+ it
->max_descent
;
1215 int line_top_y
= it
->current_y
;
1217 if (line_height
== 0)
1220 line_height
= last_height
;
1221 else if (IT_CHARPOS (*it
) < ZV
)
1223 move_it_by_lines (it
, 1, 1);
1224 line_height
= (it
->max_ascent
|| it
->max_descent
1225 ? it
->max_ascent
+ it
->max_descent
1230 struct glyph_row
*row
= it
->glyph_row
;
1232 /* Use the default character height. */
1233 it
->glyph_row
= NULL
;
1234 it
->what
= IT_CHARACTER
;
1237 PRODUCE_GLYPHS (it
);
1238 line_height
= it
->ascent
+ it
->descent
;
1239 it
->glyph_row
= row
;
1243 return line_top_y
+ line_height
;
1247 /* Return 1 if position CHARPOS is visible in window W.
1248 If visible, set *X and *Y to pixel coordinates of top left corner.
1249 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1250 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1251 and header-lines heights. */
1254 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, exact_mode_line_heights_p
)
1256 int charpos
, *x
, *y
, *rtop
, *rbot
, exact_mode_line_heights_p
;
1259 struct text_pos top
;
1261 struct buffer
*old_buffer
= NULL
;
1266 if (XBUFFER (w
->buffer
) != current_buffer
)
1268 old_buffer
= current_buffer
;
1269 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1272 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1274 /* Compute exact mode line heights, if requested. */
1275 if (exact_mode_line_heights_p
)
1277 if (WINDOW_WANTS_MODELINE_P (w
))
1278 current_mode_line_height
1279 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1280 current_buffer
->mode_line_format
);
1282 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1283 current_header_line_height
1284 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1285 current_buffer
->header_line_format
);
1288 start_display (&it
, w
, top
);
1289 move_it_to (&it
, charpos
, -1, it
.last_visible_y
, -1,
1290 MOVE_TO_POS
| MOVE_TO_Y
);
1292 /* Note that we may overshoot because of invisible text. */
1293 if (IT_CHARPOS (it
) >= charpos
)
1295 int top_x
= it
.current_x
;
1296 int top_y
= it
.current_y
;
1297 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1298 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1300 if (top_y
< window_top_y
)
1301 visible_p
= bottom_y
> window_top_y
;
1302 else if (top_y
< it
.last_visible_y
)
1307 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1308 *rtop
= max (0, window_top_y
- top_y
);
1309 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1317 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1318 move_it_by_lines (&it
, 1, 0);
1319 if (charpos
< IT_CHARPOS (it
))
1322 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1324 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1325 *rtop
= max (0, -it2
.current_y
);
1326 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1327 - it
.last_visible_y
));
1332 set_buffer_internal_1 (old_buffer
);
1334 current_header_line_height
= current_mode_line_height
= -1;
1340 /* Return the next character from STR which is MAXLEN bytes long.
1341 Return in *LEN the length of the character. This is like
1342 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1343 we find one, we return a `?', but with the length of the invalid
1347 string_char_and_length (str
, maxlen
, len
)
1348 const unsigned char *str
;
1353 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1354 if (!CHAR_VALID_P (c
, 1))
1355 /* We may not change the length here because other places in Emacs
1356 don't use this function, i.e. they silently accept invalid
1365 /* Given a position POS containing a valid character and byte position
1366 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1368 static struct text_pos
1369 string_pos_nchars_ahead (pos
, string
, nchars
)
1370 struct text_pos pos
;
1374 xassert (STRINGP (string
) && nchars
>= 0);
1376 if (STRING_MULTIBYTE (string
))
1378 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1379 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1384 string_char_and_length (p
, rest
, &len
);
1385 p
+= len
, rest
-= len
;
1386 xassert (rest
>= 0);
1388 BYTEPOS (pos
) += len
;
1392 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1398 /* Value is the text position, i.e. character and byte position,
1399 for character position CHARPOS in STRING. */
1401 static INLINE
struct text_pos
1402 string_pos (charpos
, string
)
1406 struct text_pos pos
;
1407 xassert (STRINGP (string
));
1408 xassert (charpos
>= 0);
1409 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1414 /* Value is a text position, i.e. character and byte position, for
1415 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1416 means recognize multibyte characters. */
1418 static struct text_pos
1419 c_string_pos (charpos
, s
, multibyte_p
)
1424 struct text_pos pos
;
1426 xassert (s
!= NULL
);
1427 xassert (charpos
>= 0);
1431 int rest
= strlen (s
), len
;
1433 SET_TEXT_POS (pos
, 0, 0);
1436 string_char_and_length (s
, rest
, &len
);
1437 s
+= len
, rest
-= len
;
1438 xassert (rest
>= 0);
1440 BYTEPOS (pos
) += len
;
1444 SET_TEXT_POS (pos
, charpos
, charpos
);
1450 /* Value is the number of characters in C string S. MULTIBYTE_P
1451 non-zero means recognize multibyte characters. */
1454 number_of_chars (s
, multibyte_p
)
1462 int rest
= strlen (s
), len
;
1463 unsigned char *p
= (unsigned char *) s
;
1465 for (nchars
= 0; rest
> 0; ++nchars
)
1467 string_char_and_length (p
, rest
, &len
);
1468 rest
-= len
, p
+= len
;
1472 nchars
= strlen (s
);
1478 /* Compute byte position NEWPOS->bytepos corresponding to
1479 NEWPOS->charpos. POS is a known position in string STRING.
1480 NEWPOS->charpos must be >= POS.charpos. */
1483 compute_string_pos (newpos
, pos
, string
)
1484 struct text_pos
*newpos
, pos
;
1487 xassert (STRINGP (string
));
1488 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1490 if (STRING_MULTIBYTE (string
))
1491 *newpos
= string_pos_nchars_ahead (pos
, string
,
1492 CHARPOS (*newpos
) - CHARPOS (pos
));
1494 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1498 Return an estimation of the pixel height of mode or top lines on
1499 frame F. FACE_ID specifies what line's height to estimate. */
1502 estimate_mode_line_height (f
, face_id
)
1504 enum face_id face_id
;
1506 #ifdef HAVE_WINDOW_SYSTEM
1507 if (FRAME_WINDOW_P (f
))
1509 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1511 /* This function is called so early when Emacs starts that the face
1512 cache and mode line face are not yet initialized. */
1513 if (FRAME_FACE_CACHE (f
))
1515 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1519 height
= FONT_HEIGHT (face
->font
);
1520 if (face
->box_line_width
> 0)
1521 height
+= 2 * face
->box_line_width
;
1532 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1533 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1534 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1535 not force the value into range. */
1538 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1540 register int pix_x
, pix_y
;
1542 NativeRectangle
*bounds
;
1546 #ifdef HAVE_WINDOW_SYSTEM
1547 if (FRAME_WINDOW_P (f
))
1549 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1550 even for negative values. */
1552 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1554 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1556 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1557 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1560 STORE_NATIVE_RECT (*bounds
,
1561 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1562 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1563 FRAME_COLUMN_WIDTH (f
) - 1,
1564 FRAME_LINE_HEIGHT (f
) - 1);
1570 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1571 pix_x
= FRAME_TOTAL_COLS (f
);
1575 else if (pix_y
> FRAME_LINES (f
))
1576 pix_y
= FRAME_LINES (f
);
1586 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1587 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1588 can't tell the positions because W's display is not up to date,
1592 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1595 int *frame_x
, *frame_y
;
1597 #ifdef HAVE_WINDOW_SYSTEM
1598 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1602 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1603 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1605 if (display_completed
)
1607 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1608 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1609 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1615 hpos
+= glyph
->pixel_width
;
1619 /* If first glyph is partially visible, its first visible position is still 0. */
1631 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1632 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1643 #ifdef HAVE_WINDOW_SYSTEM
1645 /* Find the glyph under window-relative coordinates X/Y in window W.
1646 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1647 strings. Return in *HPOS and *VPOS the row and column number of
1648 the glyph found. Return in *AREA the glyph area containing X.
1649 Value is a pointer to the glyph found or null if X/Y is not on
1650 text, or we can't tell because W's current matrix is not up to
1653 static struct glyph
*
1654 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1657 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1659 struct glyph
*glyph
, *end
;
1660 struct glyph_row
*row
= NULL
;
1663 /* Find row containing Y. Give up if some row is not enabled. */
1664 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1666 row
= MATRIX_ROW (w
->current_matrix
, i
);
1667 if (!row
->enabled_p
)
1669 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1676 /* Give up if Y is not in the window. */
1677 if (i
== w
->current_matrix
->nrows
)
1680 /* Get the glyph area containing X. */
1681 if (w
->pseudo_window_p
)
1688 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1690 *area
= LEFT_MARGIN_AREA
;
1691 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1693 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1696 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1700 *area
= RIGHT_MARGIN_AREA
;
1701 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1705 /* Find glyph containing X. */
1706 glyph
= row
->glyphs
[*area
];
1707 end
= glyph
+ row
->used
[*area
];
1709 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1711 x
-= glyph
->pixel_width
;
1721 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1724 *hpos
= glyph
- row
->glyphs
[*area
];
1730 Convert frame-relative x/y to coordinates relative to window W.
1731 Takes pseudo-windows into account. */
1734 frame_to_window_pixel_xy (w
, x
, y
)
1738 if (w
->pseudo_window_p
)
1740 /* A pseudo-window is always full-width, and starts at the
1741 left edge of the frame, plus a frame border. */
1742 struct frame
*f
= XFRAME (w
->frame
);
1743 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1744 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1748 *x
-= WINDOW_LEFT_EDGE_X (w
);
1749 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1754 Return in *R the clipping rectangle for glyph string S. */
1757 get_glyph_string_clip_rect (s
, nr
)
1758 struct glyph_string
*s
;
1759 NativeRectangle
*nr
;
1763 if (s
->row
->full_width_p
)
1765 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1766 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1767 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1769 /* Unless displaying a mode or menu bar line, which are always
1770 fully visible, clip to the visible part of the row. */
1771 if (s
->w
->pseudo_window_p
)
1772 r
.height
= s
->row
->visible_height
;
1774 r
.height
= s
->height
;
1778 /* This is a text line that may be partially visible. */
1779 r
.x
= window_box_left (s
->w
, s
->area
);
1780 r
.width
= window_box_width (s
->w
, s
->area
);
1781 r
.height
= s
->row
->visible_height
;
1785 if (r
.x
< s
->clip_head
->x
)
1787 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1788 r
.width
-= s
->clip_head
->x
- r
.x
;
1791 r
.x
= s
->clip_head
->x
;
1794 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1796 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1797 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1802 /* If S draws overlapping rows, it's sufficient to use the top and
1803 bottom of the window for clipping because this glyph string
1804 intentionally draws over other lines. */
1805 if (s
->for_overlaps_p
)
1807 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1808 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1812 /* Don't use S->y for clipping because it doesn't take partially
1813 visible lines into account. For example, it can be negative for
1814 partially visible lines at the top of a window. */
1815 if (!s
->row
->full_width_p
1816 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1817 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1819 r
.y
= max (0, s
->row
->y
);
1821 /* If drawing a tool-bar window, draw it over the internal border
1822 at the top of the window. */
1823 if (WINDOWP (s
->f
->tool_bar_window
)
1824 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1825 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1828 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1830 /* If drawing the cursor, don't let glyph draw outside its
1831 advertised boundaries. Cleartype does this under some circumstances. */
1832 if (s
->hl
== DRAW_CURSOR
)
1834 struct glyph
*glyph
= s
->first_glyph
;
1839 r
.width
-= s
->x
- r
.x
;
1842 r
.width
= min (r
.width
, glyph
->pixel_width
);
1844 /* If r.y is below window bottom, ensure that we still see a cursor. */
1845 height
= min (glyph
->ascent
+ glyph
->descent
,
1846 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1847 max_y
= window_text_bottom_y (s
->w
) - height
;
1848 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1849 if (s
->ybase
- glyph
->ascent
> max_y
)
1856 /* Don't draw cursor glyph taller than our actual glyph. */
1857 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1858 if (height
< r
.height
)
1860 max_y
= r
.y
+ r
.height
;
1861 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1862 r
.height
= min (max_y
- r
.y
, height
);
1867 #ifdef CONVERT_FROM_XRECT
1868 CONVERT_FROM_XRECT (r
, *nr
);
1876 Return the position and height of the phys cursor in window W.
1877 Set w->phys_cursor_width to width of phys cursor.
1881 get_phys_cursor_geometry (w
, row
, glyph
, heightp
)
1883 struct glyph_row
*row
;
1884 struct glyph
*glyph
;
1887 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1888 int y
, wd
, h
, h0
, y0
;
1890 /* Compute the width of the rectangle to draw. If on a stretch
1891 glyph, and `x-stretch-block-cursor' is nil, don't draw a
1892 rectangle as wide as the glyph, but use a canonical character
1894 wd
= glyph
->pixel_width
- 1;
1898 if (glyph
->type
== STRETCH_GLYPH
1899 && !x_stretch_cursor_p
)
1900 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
1901 w
->phys_cursor_width
= wd
;
1903 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
1905 /* If y is below window bottom, ensure that we still see a cursor. */
1906 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
1908 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
1909 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
1911 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
1914 h
= max (h
- (y0
- y
) + 1, h0
);
1919 y0
= window_text_bottom_y (w
) - h0
;
1928 return WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
1932 #endif /* HAVE_WINDOW_SYSTEM */
1935 /***********************************************************************
1936 Lisp form evaluation
1937 ***********************************************************************/
1939 /* Error handler for safe_eval and safe_call. */
1942 safe_eval_handler (arg
)
1945 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1950 /* Evaluate SEXPR and return the result, or nil if something went
1951 wrong. Prevent redisplay during the evaluation. */
1959 if (inhibit_eval_during_redisplay
)
1963 int count
= SPECPDL_INDEX ();
1964 struct gcpro gcpro1
;
1967 specbind (Qinhibit_redisplay
, Qt
);
1968 /* Use Qt to ensure debugger does not run,
1969 so there is no possibility of wanting to redisplay. */
1970 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1973 val
= unbind_to (count
, val
);
1980 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1981 Return the result, or nil if something went wrong. Prevent
1982 redisplay during the evaluation. */
1985 safe_call (nargs
, args
)
1991 if (inhibit_eval_during_redisplay
)
1995 int count
= SPECPDL_INDEX ();
1996 struct gcpro gcpro1
;
1999 gcpro1
.nvars
= nargs
;
2000 specbind (Qinhibit_redisplay
, Qt
);
2001 /* Use Qt to ensure debugger does not run,
2002 so there is no possibility of wanting to redisplay. */
2003 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2006 val
= unbind_to (count
, val
);
2013 /* Call function FN with one argument ARG.
2014 Return the result, or nil if something went wrong. */
2017 safe_call1 (fn
, arg
)
2018 Lisp_Object fn
, arg
;
2020 Lisp_Object args
[2];
2023 return safe_call (2, args
);
2028 /***********************************************************************
2030 ***********************************************************************/
2034 /* Define CHECK_IT to perform sanity checks on iterators.
2035 This is for debugging. It is too slow to do unconditionally. */
2041 if (it
->method
== GET_FROM_STRING
)
2043 xassert (STRINGP (it
->string
));
2044 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2048 xassert (IT_STRING_CHARPOS (*it
) < 0);
2049 if (it
->method
== GET_FROM_BUFFER
)
2051 /* Check that character and byte positions agree. */
2052 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2057 xassert (it
->current
.dpvec_index
>= 0);
2059 xassert (it
->current
.dpvec_index
< 0);
2062 #define CHECK_IT(IT) check_it ((IT))
2066 #define CHECK_IT(IT) (void) 0
2073 /* Check that the window end of window W is what we expect it
2074 to be---the last row in the current matrix displaying text. */
2077 check_window_end (w
)
2080 if (!MINI_WINDOW_P (w
)
2081 && !NILP (w
->window_end_valid
))
2083 struct glyph_row
*row
;
2084 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2085 XFASTINT (w
->window_end_vpos
)),
2087 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2088 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2092 #define CHECK_WINDOW_END(W) check_window_end ((W))
2094 #else /* not GLYPH_DEBUG */
2096 #define CHECK_WINDOW_END(W) (void) 0
2098 #endif /* not GLYPH_DEBUG */
2102 /***********************************************************************
2103 Iterator initialization
2104 ***********************************************************************/
2106 /* Initialize IT for displaying current_buffer in window W, starting
2107 at character position CHARPOS. CHARPOS < 0 means that no buffer
2108 position is specified which is useful when the iterator is assigned
2109 a position later. BYTEPOS is the byte position corresponding to
2110 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2112 If ROW is not null, calls to produce_glyphs with IT as parameter
2113 will produce glyphs in that row.
2115 BASE_FACE_ID is the id of a base face to use. It must be one of
2116 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2117 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2118 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2120 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2121 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2122 will be initialized to use the corresponding mode line glyph row of
2123 the desired matrix of W. */
2126 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2129 int charpos
, bytepos
;
2130 struct glyph_row
*row
;
2131 enum face_id base_face_id
;
2133 int highlight_region_p
;
2135 /* Some precondition checks. */
2136 xassert (w
!= NULL
&& it
!= NULL
);
2137 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2140 /* If face attributes have been changed since the last redisplay,
2141 free realized faces now because they depend on face definitions
2142 that might have changed. Don't free faces while there might be
2143 desired matrices pending which reference these faces. */
2144 if (face_change_count
&& !inhibit_free_realized_faces
)
2146 face_change_count
= 0;
2147 free_all_realized_faces (Qnil
);
2150 /* Use one of the mode line rows of W's desired matrix if
2154 if (base_face_id
== MODE_LINE_FACE_ID
2155 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2156 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2157 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2158 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2162 bzero (it
, sizeof *it
);
2163 it
->current
.overlay_string_index
= -1;
2164 it
->current
.dpvec_index
= -1;
2165 it
->base_face_id
= base_face_id
;
2167 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2169 /* The window in which we iterate over current_buffer: */
2170 XSETWINDOW (it
->window
, w
);
2172 it
->f
= XFRAME (w
->frame
);
2174 /* Extra space between lines (on window systems only). */
2175 if (base_face_id
== DEFAULT_FACE_ID
2176 && FRAME_WINDOW_P (it
->f
))
2178 if (NATNUMP (current_buffer
->extra_line_spacing
))
2179 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2180 else if (FLOATP (current_buffer
->extra_line_spacing
))
2181 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2182 * FRAME_LINE_HEIGHT (it
->f
));
2183 else if (it
->f
->extra_line_spacing
> 0)
2184 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2185 it
->max_extra_line_spacing
= 0;
2188 /* If realized faces have been removed, e.g. because of face
2189 attribute changes of named faces, recompute them. When running
2190 in batch mode, the face cache of the initial frame is null. If
2191 we happen to get called, make a dummy face cache. */
2192 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2193 init_frame_faces (it
->f
);
2194 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2195 recompute_basic_faces (it
->f
);
2197 /* Current value of the `slice', `space-width', and 'height' properties. */
2198 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2199 it
->space_width
= Qnil
;
2200 it
->font_height
= Qnil
;
2201 it
->override_ascent
= -1;
2203 /* Are control characters displayed as `^C'? */
2204 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2206 /* -1 means everything between a CR and the following line end
2207 is invisible. >0 means lines indented more than this value are
2209 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2210 ? XFASTINT (current_buffer
->selective_display
)
2211 : (!NILP (current_buffer
->selective_display
)
2213 it
->selective_display_ellipsis_p
2214 = !NILP (current_buffer
->selective_display_ellipses
);
2216 /* Display table to use. */
2217 it
->dp
= window_display_table (w
);
2219 /* Are multibyte characters enabled in current_buffer? */
2220 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2222 /* Non-zero if we should highlight the region. */
2224 = (!NILP (Vtransient_mark_mode
)
2225 && !NILP (current_buffer
->mark_active
)
2226 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2228 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2229 start and end of a visible region in window IT->w. Set both to
2230 -1 to indicate no region. */
2231 if (highlight_region_p
2232 /* Maybe highlight only in selected window. */
2233 && (/* Either show region everywhere. */
2234 highlight_nonselected_windows
2235 /* Or show region in the selected window. */
2236 || w
== XWINDOW (selected_window
)
2237 /* Or show the region if we are in the mini-buffer and W is
2238 the window the mini-buffer refers to. */
2239 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2240 && WINDOWP (minibuf_selected_window
)
2241 && w
== XWINDOW (minibuf_selected_window
))))
2243 int charpos
= marker_position (current_buffer
->mark
);
2244 it
->region_beg_charpos
= min (PT
, charpos
);
2245 it
->region_end_charpos
= max (PT
, charpos
);
2248 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2250 /* Get the position at which the redisplay_end_trigger hook should
2251 be run, if it is to be run at all. */
2252 if (MARKERP (w
->redisplay_end_trigger
)
2253 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2254 it
->redisplay_end_trigger_charpos
2255 = marker_position (w
->redisplay_end_trigger
);
2256 else if (INTEGERP (w
->redisplay_end_trigger
))
2257 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2259 /* Correct bogus values of tab_width. */
2260 it
->tab_width
= XINT (current_buffer
->tab_width
);
2261 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2264 /* Are lines in the display truncated? */
2265 it
->truncate_lines_p
2266 = (base_face_id
!= DEFAULT_FACE_ID
2267 || XINT (it
->w
->hscroll
)
2268 || (truncate_partial_width_windows
2269 && !WINDOW_FULL_WIDTH_P (it
->w
))
2270 || !NILP (current_buffer
->truncate_lines
));
2272 /* Get dimensions of truncation and continuation glyphs. These are
2273 displayed as fringe bitmaps under X, so we don't need them for such
2275 if (!FRAME_WINDOW_P (it
->f
))
2277 if (it
->truncate_lines_p
)
2279 /* We will need the truncation glyph. */
2280 xassert (it
->glyph_row
== NULL
);
2281 produce_special_glyphs (it
, IT_TRUNCATION
);
2282 it
->truncation_pixel_width
= it
->pixel_width
;
2286 /* We will need the continuation glyph. */
2287 xassert (it
->glyph_row
== NULL
);
2288 produce_special_glyphs (it
, IT_CONTINUATION
);
2289 it
->continuation_pixel_width
= it
->pixel_width
;
2292 /* Reset these values to zero because the produce_special_glyphs
2293 above has changed them. */
2294 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2295 it
->phys_ascent
= it
->phys_descent
= 0;
2298 /* Set this after getting the dimensions of truncation and
2299 continuation glyphs, so that we don't produce glyphs when calling
2300 produce_special_glyphs, above. */
2301 it
->glyph_row
= row
;
2302 it
->area
= TEXT_AREA
;
2304 /* Get the dimensions of the display area. The display area
2305 consists of the visible window area plus a horizontally scrolled
2306 part to the left of the window. All x-values are relative to the
2307 start of this total display area. */
2308 if (base_face_id
!= DEFAULT_FACE_ID
)
2310 /* Mode lines, menu bar in terminal frames. */
2311 it
->first_visible_x
= 0;
2312 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2317 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2318 it
->last_visible_x
= (it
->first_visible_x
2319 + window_box_width (w
, TEXT_AREA
));
2321 /* If we truncate lines, leave room for the truncator glyph(s) at
2322 the right margin. Otherwise, leave room for the continuation
2323 glyph(s). Truncation and continuation glyphs are not inserted
2324 for window-based redisplay. */
2325 if (!FRAME_WINDOW_P (it
->f
))
2327 if (it
->truncate_lines_p
)
2328 it
->last_visible_x
-= it
->truncation_pixel_width
;
2330 it
->last_visible_x
-= it
->continuation_pixel_width
;
2333 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2334 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2337 /* Leave room for a border glyph. */
2338 if (!FRAME_WINDOW_P (it
->f
)
2339 && !WINDOW_RIGHTMOST_P (it
->w
))
2340 it
->last_visible_x
-= 1;
2342 it
->last_visible_y
= window_text_bottom_y (w
);
2344 /* For mode lines and alike, arrange for the first glyph having a
2345 left box line if the face specifies a box. */
2346 if (base_face_id
!= DEFAULT_FACE_ID
)
2350 it
->face_id
= base_face_id
;
2352 /* If we have a boxed mode line, make the first character appear
2353 with a left box line. */
2354 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2355 if (face
->box
!= FACE_NO_BOX
)
2356 it
->start_of_box_run_p
= 1;
2359 /* If a buffer position was specified, set the iterator there,
2360 getting overlays and face properties from that position. */
2361 if (charpos
>= BUF_BEG (current_buffer
))
2363 it
->end_charpos
= ZV
;
2365 IT_CHARPOS (*it
) = charpos
;
2367 /* Compute byte position if not specified. */
2368 if (bytepos
< charpos
)
2369 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2371 IT_BYTEPOS (*it
) = bytepos
;
2373 it
->start
= it
->current
;
2375 /* Compute faces etc. */
2376 reseat (it
, it
->current
.pos
, 1);
2383 /* Initialize IT for the display of window W with window start POS. */
2386 start_display (it
, w
, pos
)
2389 struct text_pos pos
;
2391 struct glyph_row
*row
;
2392 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2394 row
= w
->desired_matrix
->rows
+ first_vpos
;
2395 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2396 it
->first_vpos
= first_vpos
;
2398 if (!it
->truncate_lines_p
)
2400 int start_at_line_beg_p
;
2401 int first_y
= it
->current_y
;
2403 /* If window start is not at a line start, skip forward to POS to
2404 get the correct continuation lines width. */
2405 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2406 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2407 if (!start_at_line_beg_p
)
2411 reseat_at_previous_visible_line_start (it
);
2412 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2414 new_x
= it
->current_x
+ it
->pixel_width
;
2416 /* If lines are continued, this line may end in the middle
2417 of a multi-glyph character (e.g. a control character
2418 displayed as \003, or in the middle of an overlay
2419 string). In this case move_it_to above will not have
2420 taken us to the start of the continuation line but to the
2421 end of the continued line. */
2422 if (it
->current_x
> 0
2423 && !it
->truncate_lines_p
/* Lines are continued. */
2424 && (/* And glyph doesn't fit on the line. */
2425 new_x
> it
->last_visible_x
2426 /* Or it fits exactly and we're on a window
2428 || (new_x
== it
->last_visible_x
2429 && FRAME_WINDOW_P (it
->f
))))
2431 if (it
->current
.dpvec_index
>= 0
2432 || it
->current
.overlay_string_index
>= 0)
2434 set_iterator_to_next (it
, 1);
2435 move_it_in_display_line_to (it
, -1, -1, 0);
2438 it
->continuation_lines_width
+= it
->current_x
;
2441 /* We're starting a new display line, not affected by the
2442 height of the continued line, so clear the appropriate
2443 fields in the iterator structure. */
2444 it
->max_ascent
= it
->max_descent
= 0;
2445 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2447 it
->current_y
= first_y
;
2449 it
->current_x
= it
->hpos
= 0;
2453 #if 0 /* Don't assert the following because start_display is sometimes
2454 called intentionally with a window start that is not at a
2455 line start. Please leave this code in as a comment. */
2457 /* Window start should be on a line start, now. */
2458 xassert (it
->continuation_lines_width
2459 || IT_CHARPOS (it
) == BEGV
2460 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2465 /* Return 1 if POS is a position in ellipses displayed for invisible
2466 text. W is the window we display, for text property lookup. */
2469 in_ellipses_for_invisible_text_p (pos
, w
)
2470 struct display_pos
*pos
;
2473 Lisp_Object prop
, window
;
2475 int charpos
= CHARPOS (pos
->pos
);
2477 /* If POS specifies a position in a display vector, this might
2478 be for an ellipsis displayed for invisible text. We won't
2479 get the iterator set up for delivering that ellipsis unless
2480 we make sure that it gets aware of the invisible text. */
2481 if (pos
->dpvec_index
>= 0
2482 && pos
->overlay_string_index
< 0
2483 && CHARPOS (pos
->string_pos
) < 0
2485 && (XSETWINDOW (window
, w
),
2486 prop
= Fget_char_property (make_number (charpos
),
2487 Qinvisible
, window
),
2488 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2490 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2492 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2499 /* Initialize IT for stepping through current_buffer in window W,
2500 starting at position POS that includes overlay string and display
2501 vector/ control character translation position information. Value
2502 is zero if there are overlay strings with newlines at POS. */
2505 init_from_display_pos (it
, w
, pos
)
2508 struct display_pos
*pos
;
2510 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2511 int i
, overlay_strings_with_newlines
= 0;
2513 /* If POS specifies a position in a display vector, this might
2514 be for an ellipsis displayed for invisible text. We won't
2515 get the iterator set up for delivering that ellipsis unless
2516 we make sure that it gets aware of the invisible text. */
2517 if (in_ellipses_for_invisible_text_p (pos
, w
))
2523 /* Keep in mind: the call to reseat in init_iterator skips invisible
2524 text, so we might end up at a position different from POS. This
2525 is only a problem when POS is a row start after a newline and an
2526 overlay starts there with an after-string, and the overlay has an
2527 invisible property. Since we don't skip invisible text in
2528 display_line and elsewhere immediately after consuming the
2529 newline before the row start, such a POS will not be in a string,
2530 but the call to init_iterator below will move us to the
2532 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2534 /* This only scans the current chunk -- it should scan all chunks.
2535 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2536 to 16 in 22.1 to make this a lesser problem. */
2537 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2539 const char *s
= SDATA (it
->overlay_strings
[i
]);
2540 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2542 while (s
< e
&& *s
!= '\n')
2547 overlay_strings_with_newlines
= 1;
2552 /* If position is within an overlay string, set up IT to the right
2554 if (pos
->overlay_string_index
>= 0)
2558 /* If the first overlay string happens to have a `display'
2559 property for an image, the iterator will be set up for that
2560 image, and we have to undo that setup first before we can
2561 correct the overlay string index. */
2562 if (it
->method
== GET_FROM_IMAGE
)
2565 /* We already have the first chunk of overlay strings in
2566 IT->overlay_strings. Load more until the one for
2567 pos->overlay_string_index is in IT->overlay_strings. */
2568 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2570 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2571 it
->current
.overlay_string_index
= 0;
2574 load_overlay_strings (it
, 0);
2575 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2579 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2580 relative_index
= (it
->current
.overlay_string_index
2581 % OVERLAY_STRING_CHUNK_SIZE
);
2582 it
->string
= it
->overlay_strings
[relative_index
];
2583 xassert (STRINGP (it
->string
));
2584 it
->current
.string_pos
= pos
->string_pos
;
2585 it
->method
= GET_FROM_STRING
;
2588 #if 0 /* This is bogus because POS not having an overlay string
2589 position does not mean it's after the string. Example: A
2590 line starting with a before-string and initialization of IT
2591 to the previous row's end position. */
2592 else if (it
->current
.overlay_string_index
>= 0)
2594 /* If POS says we're already after an overlay string ending at
2595 POS, make sure to pop the iterator because it will be in
2596 front of that overlay string. When POS is ZV, we've thereby
2597 also ``processed'' overlay strings at ZV. */
2600 it
->current
.overlay_string_index
= -1;
2601 it
->method
= GET_FROM_BUFFER
;
2602 if (CHARPOS (pos
->pos
) == ZV
)
2603 it
->overlay_strings_at_end_processed_p
= 1;
2607 if (CHARPOS (pos
->string_pos
) >= 0)
2609 /* Recorded position is not in an overlay string, but in another
2610 string. This can only be a string from a `display' property.
2611 IT should already be filled with that string. */
2612 it
->current
.string_pos
= pos
->string_pos
;
2613 xassert (STRINGP (it
->string
));
2616 /* Restore position in display vector translations, control
2617 character translations or ellipses. */
2618 if (pos
->dpvec_index
>= 0)
2620 if (it
->dpvec
== NULL
)
2621 get_next_display_element (it
);
2622 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2623 it
->current
.dpvec_index
= pos
->dpvec_index
;
2627 return !overlay_strings_with_newlines
;
2631 /* Initialize IT for stepping through current_buffer in window W
2632 starting at ROW->start. */
2635 init_to_row_start (it
, w
, row
)
2638 struct glyph_row
*row
;
2640 init_from_display_pos (it
, w
, &row
->start
);
2641 it
->start
= row
->start
;
2642 it
->continuation_lines_width
= row
->continuation_lines_width
;
2647 /* Initialize IT for stepping through current_buffer in window W
2648 starting in the line following ROW, i.e. starting at ROW->end.
2649 Value is zero if there are overlay strings with newlines at ROW's
2653 init_to_row_end (it
, w
, row
)
2656 struct glyph_row
*row
;
2660 if (init_from_display_pos (it
, w
, &row
->end
))
2662 if (row
->continued_p
)
2663 it
->continuation_lines_width
2664 = row
->continuation_lines_width
+ row
->pixel_width
;
2675 /***********************************************************************
2677 ***********************************************************************/
2679 /* Called when IT reaches IT->stop_charpos. Handle text property and
2680 overlay changes. Set IT->stop_charpos to the next position where
2687 enum prop_handled handled
;
2688 int handle_overlay_change_p
= 1;
2692 it
->current
.dpvec_index
= -1;
2694 /* Use face of preceding text for ellipsis (if invisible) */
2695 if (it
->selective_display_ellipsis_p
)
2696 it
->saved_face_id
= it
->face_id
;
2700 handled
= HANDLED_NORMALLY
;
2702 /* Call text property handlers. */
2703 for (p
= it_props
; p
->handler
; ++p
)
2705 handled
= p
->handler (it
);
2707 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2709 else if (handled
== HANDLED_RETURN
)
2711 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2712 handle_overlay_change_p
= 0;
2715 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2717 /* Don't check for overlay strings below when set to deliver
2718 characters from a display vector. */
2719 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
2720 handle_overlay_change_p
= 0;
2722 /* Handle overlay changes. */
2723 if (handle_overlay_change_p
)
2724 handled
= handle_overlay_change (it
);
2726 /* Determine where to stop next. */
2727 if (handled
== HANDLED_NORMALLY
)
2728 compute_stop_pos (it
);
2731 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2735 /* Compute IT->stop_charpos from text property and overlay change
2736 information for IT's current position. */
2739 compute_stop_pos (it
)
2742 register INTERVAL iv
, next_iv
;
2743 Lisp_Object object
, limit
, position
;
2745 /* If nowhere else, stop at the end. */
2746 it
->stop_charpos
= it
->end_charpos
;
2748 if (STRINGP (it
->string
))
2750 /* Strings are usually short, so don't limit the search for
2752 object
= it
->string
;
2754 position
= make_number (IT_STRING_CHARPOS (*it
));
2760 /* If next overlay change is in front of the current stop pos
2761 (which is IT->end_charpos), stop there. Note: value of
2762 next_overlay_change is point-max if no overlay change
2764 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2765 if (charpos
< it
->stop_charpos
)
2766 it
->stop_charpos
= charpos
;
2768 /* If showing the region, we have to stop at the region
2769 start or end because the face might change there. */
2770 if (it
->region_beg_charpos
> 0)
2772 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2773 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2774 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2775 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2778 /* Set up variables for computing the stop position from text
2779 property changes. */
2780 XSETBUFFER (object
, current_buffer
);
2781 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2782 position
= make_number (IT_CHARPOS (*it
));
2786 /* Get the interval containing IT's position. Value is a null
2787 interval if there isn't such an interval. */
2788 iv
= validate_interval_range (object
, &position
, &position
, 0);
2789 if (!NULL_INTERVAL_P (iv
))
2791 Lisp_Object values_here
[LAST_PROP_IDX
];
2794 /* Get properties here. */
2795 for (p
= it_props
; p
->handler
; ++p
)
2796 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2798 /* Look for an interval following iv that has different
2800 for (next_iv
= next_interval (iv
);
2801 (!NULL_INTERVAL_P (next_iv
)
2803 || XFASTINT (limit
) > next_iv
->position
));
2804 next_iv
= next_interval (next_iv
))
2806 for (p
= it_props
; p
->handler
; ++p
)
2808 Lisp_Object new_value
;
2810 new_value
= textget (next_iv
->plist
, *p
->name
);
2811 if (!EQ (values_here
[p
->idx
], new_value
))
2819 if (!NULL_INTERVAL_P (next_iv
))
2821 if (INTEGERP (limit
)
2822 && next_iv
->position
>= XFASTINT (limit
))
2823 /* No text property change up to limit. */
2824 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2826 /* Text properties change in next_iv. */
2827 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2831 xassert (STRINGP (it
->string
)
2832 || (it
->stop_charpos
>= BEGV
2833 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2837 /* Return the position of the next overlay change after POS in
2838 current_buffer. Value is point-max if no overlay change
2839 follows. This is like `next-overlay-change' but doesn't use
2843 next_overlay_change (pos
)
2848 Lisp_Object
*overlays
;
2851 /* Get all overlays at the given position. */
2852 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
2854 /* If any of these overlays ends before endpos,
2855 use its ending point instead. */
2856 for (i
= 0; i
< noverlays
; ++i
)
2861 oend
= OVERLAY_END (overlays
[i
]);
2862 oendpos
= OVERLAY_POSITION (oend
);
2863 endpos
= min (endpos
, oendpos
);
2871 /***********************************************************************
2873 ***********************************************************************/
2875 /* Handle changes in the `fontified' property of the current buffer by
2876 calling hook functions from Qfontification_functions to fontify
2879 static enum prop_handled
2880 handle_fontified_prop (it
)
2883 Lisp_Object prop
, pos
;
2884 enum prop_handled handled
= HANDLED_NORMALLY
;
2886 /* Get the value of the `fontified' property at IT's current buffer
2887 position. (The `fontified' property doesn't have a special
2888 meaning in strings.) If the value is nil, call functions from
2889 Qfontification_functions. */
2890 if (!STRINGP (it
->string
)
2892 && !NILP (Vfontification_functions
)
2893 && !NILP (Vrun_hooks
)
2894 && (pos
= make_number (IT_CHARPOS (*it
)),
2895 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2898 int count
= SPECPDL_INDEX ();
2901 val
= Vfontification_functions
;
2902 specbind (Qfontification_functions
, Qnil
);
2904 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2905 safe_call1 (val
, pos
);
2908 Lisp_Object globals
, fn
;
2909 struct gcpro gcpro1
, gcpro2
;
2912 GCPRO2 (val
, globals
);
2914 for (; CONSP (val
); val
= XCDR (val
))
2920 /* A value of t indicates this hook has a local
2921 binding; it means to run the global binding too.
2922 In a global value, t should not occur. If it
2923 does, we must ignore it to avoid an endless
2925 for (globals
= Fdefault_value (Qfontification_functions
);
2927 globals
= XCDR (globals
))
2929 fn
= XCAR (globals
);
2931 safe_call1 (fn
, pos
);
2935 safe_call1 (fn
, pos
);
2941 unbind_to (count
, Qnil
);
2943 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2944 something. This avoids an endless loop if they failed to
2945 fontify the text for which reason ever. */
2946 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2947 handled
= HANDLED_RECOMPUTE_PROPS
;
2955 /***********************************************************************
2957 ***********************************************************************/
2959 /* Set up iterator IT from face properties at its current position.
2960 Called from handle_stop. */
2962 static enum prop_handled
2963 handle_face_prop (it
)
2966 int new_face_id
, next_stop
;
2968 if (!STRINGP (it
->string
))
2971 = face_at_buffer_position (it
->w
,
2973 it
->region_beg_charpos
,
2974 it
->region_end_charpos
,
2977 + TEXT_PROP_DISTANCE_LIMIT
),
2980 /* Is this a start of a run of characters with box face?
2981 Caveat: this can be called for a freshly initialized
2982 iterator; face_id is -1 in this case. We know that the new
2983 face will not change until limit, i.e. if the new face has a
2984 box, all characters up to limit will have one. But, as
2985 usual, we don't know whether limit is really the end. */
2986 if (new_face_id
!= it
->face_id
)
2988 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2990 /* If new face has a box but old face has not, this is
2991 the start of a run of characters with box, i.e. it has
2992 a shadow on the left side. The value of face_id of the
2993 iterator will be -1 if this is the initial call that gets
2994 the face. In this case, we have to look in front of IT's
2995 position and see whether there is a face != new_face_id. */
2996 it
->start_of_box_run_p
2997 = (new_face
->box
!= FACE_NO_BOX
2998 && (it
->face_id
>= 0
2999 || IT_CHARPOS (*it
) == BEG
3000 || new_face_id
!= face_before_it_pos (it
)));
3001 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3006 int base_face_id
, bufpos
;
3008 if (it
->current
.overlay_string_index
>= 0)
3009 bufpos
= IT_CHARPOS (*it
);
3013 /* For strings from a buffer, i.e. overlay strings or strings
3014 from a `display' property, use the face at IT's current
3015 buffer position as the base face to merge with, so that
3016 overlay strings appear in the same face as surrounding
3017 text, unless they specify their own faces. */
3018 base_face_id
= underlying_face_id (it
);
3020 new_face_id
= face_at_string_position (it
->w
,
3022 IT_STRING_CHARPOS (*it
),
3024 it
->region_beg_charpos
,
3025 it
->region_end_charpos
,
3029 #if 0 /* This shouldn't be neccessary. Let's check it. */
3030 /* If IT is used to display a mode line we would really like to
3031 use the mode line face instead of the frame's default face. */
3032 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3033 && new_face_id
== DEFAULT_FACE_ID
)
3034 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3037 /* Is this a start of a run of characters with box? Caveat:
3038 this can be called for a freshly allocated iterator; face_id
3039 is -1 is this case. We know that the new face will not
3040 change until the next check pos, i.e. if the new face has a
3041 box, all characters up to that position will have a
3042 box. But, as usual, we don't know whether that position
3043 is really the end. */
3044 if (new_face_id
!= it
->face_id
)
3046 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3047 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3049 /* If new face has a box but old face hasn't, this is the
3050 start of a run of characters with box, i.e. it has a
3051 shadow on the left side. */
3052 it
->start_of_box_run_p
3053 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3054 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3058 it
->face_id
= new_face_id
;
3059 return HANDLED_NORMALLY
;
3063 /* Return the ID of the face ``underlying'' IT's current position,
3064 which is in a string. If the iterator is associated with a
3065 buffer, return the face at IT's current buffer position.
3066 Otherwise, use the iterator's base_face_id. */
3069 underlying_face_id (it
)
3072 int face_id
= it
->base_face_id
, i
;
3074 xassert (STRINGP (it
->string
));
3076 for (i
= it
->sp
- 1; i
>= 0; --i
)
3077 if (NILP (it
->stack
[i
].string
))
3078 face_id
= it
->stack
[i
].face_id
;
3084 /* Compute the face one character before or after the current position
3085 of IT. BEFORE_P non-zero means get the face in front of IT's
3086 position. Value is the id of the face. */
3089 face_before_or_after_it_pos (it
, before_p
)
3094 int next_check_charpos
;
3095 struct text_pos pos
;
3097 xassert (it
->s
== NULL
);
3099 if (STRINGP (it
->string
))
3101 int bufpos
, base_face_id
;
3103 /* No face change past the end of the string (for the case
3104 we are padding with spaces). No face change before the
3106 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3107 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3110 /* Set pos to the position before or after IT's current position. */
3112 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3114 /* For composition, we must check the character after the
3116 pos
= (it
->what
== IT_COMPOSITION
3117 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3118 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3120 if (it
->current
.overlay_string_index
>= 0)
3121 bufpos
= IT_CHARPOS (*it
);
3125 base_face_id
= underlying_face_id (it
);
3127 /* Get the face for ASCII, or unibyte. */
3128 face_id
= face_at_string_position (it
->w
,
3132 it
->region_beg_charpos
,
3133 it
->region_end_charpos
,
3134 &next_check_charpos
,
3137 /* Correct the face for charsets different from ASCII. Do it
3138 for the multibyte case only. The face returned above is
3139 suitable for unibyte text if IT->string is unibyte. */
3140 if (STRING_MULTIBYTE (it
->string
))
3142 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3143 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3145 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3147 c
= string_char_and_length (p
, rest
, &len
);
3148 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3153 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3154 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3157 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3158 pos
= it
->current
.pos
;
3161 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3164 if (it
->what
== IT_COMPOSITION
)
3165 /* For composition, we must check the position after the
3167 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3169 INC_TEXT_POS (pos
, it
->multibyte_p
);
3172 /* Determine face for CHARSET_ASCII, or unibyte. */
3173 face_id
= face_at_buffer_position (it
->w
,
3175 it
->region_beg_charpos
,
3176 it
->region_end_charpos
,
3177 &next_check_charpos
,
3180 /* Correct the face for charsets different from ASCII. Do it
3181 for the multibyte case only. The face returned above is
3182 suitable for unibyte text if current_buffer is unibyte. */
3183 if (it
->multibyte_p
)
3185 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3186 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3187 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3196 /***********************************************************************
3198 ***********************************************************************/
3200 /* Set up iterator IT from invisible properties at its current
3201 position. Called from handle_stop. */
3203 static enum prop_handled
3204 handle_invisible_prop (it
)
3207 enum prop_handled handled
= HANDLED_NORMALLY
;
3209 if (STRINGP (it
->string
))
3211 extern Lisp_Object Qinvisible
;
3212 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3214 /* Get the value of the invisible text property at the
3215 current position. Value will be nil if there is no such
3217 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3218 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3221 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3223 handled
= HANDLED_RECOMPUTE_PROPS
;
3225 /* Get the position at which the next change of the
3226 invisible text property can be found in IT->string.
3227 Value will be nil if the property value is the same for
3228 all the rest of IT->string. */
3229 XSETINT (limit
, SCHARS (it
->string
));
3230 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3233 /* Text at current position is invisible. The next
3234 change in the property is at position end_charpos.
3235 Move IT's current position to that position. */
3236 if (INTEGERP (end_charpos
)
3237 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3239 struct text_pos old
;
3240 old
= it
->current
.string_pos
;
3241 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3242 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3246 /* The rest of the string is invisible. If this is an
3247 overlay string, proceed with the next overlay string
3248 or whatever comes and return a character from there. */
3249 if (it
->current
.overlay_string_index
>= 0)
3251 next_overlay_string (it
);
3252 /* Don't check for overlay strings when we just
3253 finished processing them. */
3254 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3258 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3259 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3266 int invis_p
, newpos
, next_stop
, start_charpos
;
3267 Lisp_Object pos
, prop
, overlay
;
3269 /* First of all, is there invisible text at this position? */
3270 start_charpos
= IT_CHARPOS (*it
);
3271 pos
= make_number (IT_CHARPOS (*it
));
3272 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3274 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3276 /* If we are on invisible text, skip over it. */
3277 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3279 /* Record whether we have to display an ellipsis for the
3281 int display_ellipsis_p
= invis_p
== 2;
3283 handled
= HANDLED_RECOMPUTE_PROPS
;
3285 /* Loop skipping over invisible text. The loop is left at
3286 ZV or with IT on the first char being visible again. */
3289 /* Try to skip some invisible text. Return value is the
3290 position reached which can be equal to IT's position
3291 if there is nothing invisible here. This skips both
3292 over invisible text properties and overlays with
3293 invisible property. */
3294 newpos
= skip_invisible (IT_CHARPOS (*it
),
3295 &next_stop
, ZV
, it
->window
);
3297 /* If we skipped nothing at all we weren't at invisible
3298 text in the first place. If everything to the end of
3299 the buffer was skipped, end the loop. */
3300 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3304 /* We skipped some characters but not necessarily
3305 all there are. Check if we ended up on visible
3306 text. Fget_char_property returns the property of
3307 the char before the given position, i.e. if we
3308 get invis_p = 0, this means that the char at
3309 newpos is visible. */
3310 pos
= make_number (newpos
);
3311 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3312 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3315 /* If we ended up on invisible text, proceed to
3316 skip starting with next_stop. */
3318 IT_CHARPOS (*it
) = next_stop
;
3322 /* The position newpos is now either ZV or on visible text. */
3323 IT_CHARPOS (*it
) = newpos
;
3324 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3326 /* If there are before-strings at the start of invisible
3327 text, and the text is invisible because of a text
3328 property, arrange to show before-strings because 20.x did
3329 it that way. (If the text is invisible because of an
3330 overlay property instead of a text property, this is
3331 already handled in the overlay code.) */
3333 && get_overlay_strings (it
, start_charpos
))
3335 handled
= HANDLED_RECOMPUTE_PROPS
;
3336 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3338 else if (display_ellipsis_p
)
3339 setup_for_ellipsis (it
, 0);
3347 /* Make iterator IT return `...' next.
3348 Replaces LEN characters from buffer. */
3351 setup_for_ellipsis (it
, len
)
3355 /* Use the display table definition for `...'. Invalid glyphs
3356 will be handled by the method returning elements from dpvec. */
3357 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3359 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3360 it
->dpvec
= v
->contents
;
3361 it
->dpend
= v
->contents
+ v
->size
;
3365 /* Default `...'. */
3366 it
->dpvec
= default_invis_vector
;
3367 it
->dpend
= default_invis_vector
+ 3;
3370 it
->dpvec_char_len
= len
;
3371 it
->current
.dpvec_index
= 0;
3372 it
->dpvec_face_id
= -1;
3374 /* Remember the current face id in case glyphs specify faces.
3375 IT's face is restored in set_iterator_to_next.
3376 saved_face_id was set to preceding char's face in handle_stop. */
3377 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3378 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3380 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3386 /***********************************************************************
3388 ***********************************************************************/
3390 /* Set up iterator IT from `display' property at its current position.
3391 Called from handle_stop.
3392 We return HANDLED_RETURN if some part of the display property
3393 overrides the display of the buffer text itself.
3394 Otherwise we return HANDLED_NORMALLY. */
3396 static enum prop_handled
3397 handle_display_prop (it
)
3400 Lisp_Object prop
, object
;
3401 struct text_pos
*position
;
3402 /* Nonzero if some property replaces the display of the text itself. */
3403 int display_replaced_p
= 0;
3405 if (STRINGP (it
->string
))
3407 object
= it
->string
;
3408 position
= &it
->current
.string_pos
;
3412 object
= it
->w
->buffer
;
3413 position
= &it
->current
.pos
;
3416 /* Reset those iterator values set from display property values. */
3417 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3418 it
->space_width
= Qnil
;
3419 it
->font_height
= Qnil
;
3422 /* We don't support recursive `display' properties, i.e. string
3423 values that have a string `display' property, that have a string
3424 `display' property etc. */
3425 if (!it
->string_from_display_prop_p
)
3426 it
->area
= TEXT_AREA
;
3428 prop
= Fget_char_property (make_number (position
->charpos
),
3431 return HANDLED_NORMALLY
;
3434 /* Simple properties. */
3435 && !EQ (XCAR (prop
), Qimage
)
3436 && !EQ (XCAR (prop
), Qspace
)
3437 && !EQ (XCAR (prop
), Qwhen
)
3438 && !EQ (XCAR (prop
), Qslice
)
3439 && !EQ (XCAR (prop
), Qspace_width
)
3440 && !EQ (XCAR (prop
), Qheight
)
3441 && !EQ (XCAR (prop
), Qraise
)
3442 /* Marginal area specifications. */
3443 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3444 && !EQ (XCAR (prop
), Qleft_fringe
)
3445 && !EQ (XCAR (prop
), Qright_fringe
)
3446 && !NILP (XCAR (prop
)))
3448 for (; CONSP (prop
); prop
= XCDR (prop
))
3450 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3451 position
, display_replaced_p
))
3452 display_replaced_p
= 1;
3455 else if (VECTORP (prop
))
3458 for (i
= 0; i
< ASIZE (prop
); ++i
)
3459 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3460 position
, display_replaced_p
))
3461 display_replaced_p
= 1;
3465 int ret
= handle_single_display_spec (it
, prop
, object
, position
, 0);
3466 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3467 return HANDLED_RECOMPUTE_PROPS
;
3469 display_replaced_p
= 1;
3472 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3476 /* Value is the position of the end of the `display' property starting
3477 at START_POS in OBJECT. */
3479 static struct text_pos
3480 display_prop_end (it
, object
, start_pos
)
3483 struct text_pos start_pos
;
3486 struct text_pos end_pos
;
3488 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3489 Qdisplay
, object
, Qnil
);
3490 CHARPOS (end_pos
) = XFASTINT (end
);
3491 if (STRINGP (object
))
3492 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3494 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3500 /* Set up IT from a single `display' specification PROP. OBJECT
3501 is the object in which the `display' property was found. *POSITION
3502 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3503 means that we previously saw a display specification which already
3504 replaced text display with something else, for example an image;
3505 we ignore such properties after the first one has been processed.
3507 If PROP is a `space' or `image' specification, and in some other
3508 cases too, set *POSITION to the position where the `display'
3511 Value is non-zero if something was found which replaces the display
3512 of buffer or string text. Specifically, the value is -1 if that
3513 "something" is "nothing". */
3516 handle_single_display_spec (it
, spec
, object
, position
,
3517 display_replaced_before_p
)
3521 struct text_pos
*position
;
3522 int display_replaced_before_p
;
3525 Lisp_Object location
, value
;
3526 struct text_pos start_pos
;
3529 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3530 If the result is non-nil, use VALUE instead of SPEC. */
3532 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3541 if (!NILP (form
) && !EQ (form
, Qt
))
3543 int count
= SPECPDL_INDEX ();
3544 struct gcpro gcpro1
;
3546 /* Bind `object' to the object having the `display' property, a
3547 buffer or string. Bind `position' to the position in the
3548 object where the property was found, and `buffer-position'
3549 to the current position in the buffer. */
3550 specbind (Qobject
, object
);
3551 specbind (Qposition
, make_number (CHARPOS (*position
)));
3552 specbind (Qbuffer_position
,
3553 make_number (STRINGP (object
)
3554 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3556 form
= safe_eval (form
);
3558 unbind_to (count
, Qnil
);
3564 /* Handle `(height HEIGHT)' specifications. */
3566 && EQ (XCAR (spec
), Qheight
)
3567 && CONSP (XCDR (spec
)))
3569 if (!FRAME_WINDOW_P (it
->f
))
3572 it
->font_height
= XCAR (XCDR (spec
));
3573 if (!NILP (it
->font_height
))
3575 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3576 int new_height
= -1;
3578 if (CONSP (it
->font_height
)
3579 && (EQ (XCAR (it
->font_height
), Qplus
)
3580 || EQ (XCAR (it
->font_height
), Qminus
))
3581 && CONSP (XCDR (it
->font_height
))
3582 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3584 /* `(+ N)' or `(- N)' where N is an integer. */
3585 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3586 if (EQ (XCAR (it
->font_height
), Qplus
))
3588 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3590 else if (FUNCTIONP (it
->font_height
))
3592 /* Call function with current height as argument.
3593 Value is the new height. */
3595 height
= safe_call1 (it
->font_height
,
3596 face
->lface
[LFACE_HEIGHT_INDEX
]);
3597 if (NUMBERP (height
))
3598 new_height
= XFLOATINT (height
);
3600 else if (NUMBERP (it
->font_height
))
3602 /* Value is a multiple of the canonical char height. */
3605 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3606 new_height
= (XFLOATINT (it
->font_height
)
3607 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3611 /* Evaluate IT->font_height with `height' bound to the
3612 current specified height to get the new height. */
3613 int count
= SPECPDL_INDEX ();
3615 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3616 value
= safe_eval (it
->font_height
);
3617 unbind_to (count
, Qnil
);
3619 if (NUMBERP (value
))
3620 new_height
= XFLOATINT (value
);
3624 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3630 /* Handle `(space_width WIDTH)'. */
3632 && EQ (XCAR (spec
), Qspace_width
)
3633 && CONSP (XCDR (spec
)))
3635 if (!FRAME_WINDOW_P (it
->f
))
3638 value
= XCAR (XCDR (spec
));
3639 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3640 it
->space_width
= value
;
3645 /* Handle `(slice X Y WIDTH HEIGHT)'. */
3647 && EQ (XCAR (spec
), Qslice
))
3651 if (!FRAME_WINDOW_P (it
->f
))
3654 if (tem
= XCDR (spec
), CONSP (tem
))
3656 it
->slice
.x
= XCAR (tem
);
3657 if (tem
= XCDR (tem
), CONSP (tem
))
3659 it
->slice
.y
= XCAR (tem
);
3660 if (tem
= XCDR (tem
), CONSP (tem
))
3662 it
->slice
.width
= XCAR (tem
);
3663 if (tem
= XCDR (tem
), CONSP (tem
))
3664 it
->slice
.height
= XCAR (tem
);
3672 /* Handle `(raise FACTOR)'. */
3674 && EQ (XCAR (spec
), Qraise
)
3675 && CONSP (XCDR (spec
)))
3677 if (!FRAME_WINDOW_P (it
->f
))
3680 #ifdef HAVE_WINDOW_SYSTEM
3681 value
= XCAR (XCDR (spec
));
3682 if (NUMBERP (value
))
3684 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3685 it
->voffset
= - (XFLOATINT (value
)
3686 * (FONT_HEIGHT (face
->font
)));
3688 #endif /* HAVE_WINDOW_SYSTEM */
3693 /* Don't handle the other kinds of display specifications
3694 inside a string that we got from a `display' property. */
3695 if (it
->string_from_display_prop_p
)
3698 /* Characters having this form of property are not displayed, so
3699 we have to find the end of the property. */
3700 start_pos
= *position
;
3701 *position
= display_prop_end (it
, object
, start_pos
);
3704 /* Stop the scan at that end position--we assume that all
3705 text properties change there. */
3706 it
->stop_charpos
= position
->charpos
;
3708 /* Handle `(left-fringe BITMAP [FACE])'
3709 and `(right-fringe BITMAP [FACE])'. */
3711 && (EQ (XCAR (spec
), Qleft_fringe
)
3712 || EQ (XCAR (spec
), Qright_fringe
))
3713 && CONSP (XCDR (spec
)))
3715 int face_id
= DEFAULT_FACE_ID
;
3718 if (!FRAME_WINDOW_P (it
->f
))
3719 /* If we return here, POSITION has been advanced
3720 across the text with this property. */
3723 #ifdef HAVE_WINDOW_SYSTEM
3724 value
= XCAR (XCDR (spec
));
3725 if (!SYMBOLP (value
)
3726 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
3727 /* If we return here, POSITION has been advanced
3728 across the text with this property. */
3731 if (CONSP (XCDR (XCDR (spec
))))
3733 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
3734 int face_id2
= lookup_derived_face (it
->f
, face_name
,
3735 'A', FRINGE_FACE_ID
, 0);
3740 /* Save current settings of IT so that we can restore them
3741 when we are finished with the glyph property value. */
3745 it
->area
= TEXT_AREA
;
3746 it
->what
= IT_IMAGE
;
3747 it
->image_id
= -1; /* no image */
3748 it
->position
= start_pos
;
3749 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3750 it
->method
= GET_FROM_IMAGE
;
3751 it
->face_id
= face_id
;
3753 /* Say that we haven't consumed the characters with
3754 `display' property yet. The call to pop_it in
3755 set_iterator_to_next will clean this up. */
3756 *position
= start_pos
;
3758 if (EQ (XCAR (spec
), Qleft_fringe
))
3760 it
->left_user_fringe_bitmap
= fringe_bitmap
;
3761 it
->left_user_fringe_face_id
= face_id
;
3765 it
->right_user_fringe_bitmap
= fringe_bitmap
;
3766 it
->right_user_fringe_face_id
= face_id
;
3768 #endif /* HAVE_WINDOW_SYSTEM */
3772 /* Prepare to handle `((margin left-margin) ...)',
3773 `((margin right-margin) ...)' and `((margin nil) ...)'
3774 prefixes for display specifications. */
3775 location
= Qunbound
;
3776 if (CONSP (spec
) && CONSP (XCAR (spec
)))
3780 value
= XCDR (spec
);
3782 value
= XCAR (value
);
3785 if (EQ (XCAR (tem
), Qmargin
)
3786 && (tem
= XCDR (tem
),
3787 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3789 || EQ (tem
, Qleft_margin
)
3790 || EQ (tem
, Qright_margin
))))
3794 if (EQ (location
, Qunbound
))
3800 /* After this point, VALUE is the property after any
3801 margin prefix has been stripped. It must be a string,
3802 an image specification, or `(space ...)'.
3804 LOCATION specifies where to display: `left-margin',
3805 `right-margin' or nil. */
3807 valid_p
= (STRINGP (value
)
3808 #ifdef HAVE_WINDOW_SYSTEM
3809 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
3810 #endif /* not HAVE_WINDOW_SYSTEM */
3811 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
3813 if (valid_p
&& !display_replaced_before_p
)
3815 /* Save current settings of IT so that we can restore them
3816 when we are finished with the glyph property value. */
3818 if (NILP (location
))
3819 it
->area
= TEXT_AREA
;
3820 else if (EQ (location
, Qleft_margin
))
3821 it
->area
= LEFT_MARGIN_AREA
;
3823 it
->area
= RIGHT_MARGIN_AREA
;
3825 if (STRINGP (value
))
3827 if (SCHARS (value
) == 0)
3830 return -1; /* Replaced by "", i.e. nothing. */
3833 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3834 it
->current
.overlay_string_index
= -1;
3835 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3836 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3837 it
->method
= GET_FROM_STRING
;
3838 it
->stop_charpos
= 0;
3839 it
->string_from_display_prop_p
= 1;
3840 /* Say that we haven't consumed the characters with
3841 `display' property yet. The call to pop_it in
3842 set_iterator_to_next will clean this up. */
3843 *position
= start_pos
;
3845 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3847 it
->method
= GET_FROM_STRETCH
;
3849 it
->current
.pos
= it
->position
= start_pos
;
3852 #ifdef HAVE_WINDOW_SYSTEM
3855 it
->what
= IT_IMAGE
;
3856 it
->image_id
= lookup_image (it
->f
, value
);
3857 it
->position
= start_pos
;
3858 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3859 it
->method
= GET_FROM_IMAGE
;
3861 /* Say that we haven't consumed the characters with
3862 `display' property yet. The call to pop_it in
3863 set_iterator_to_next will clean this up. */
3864 *position
= start_pos
;
3866 #endif /* HAVE_WINDOW_SYSTEM */
3871 /* Invalid property or property not supported. Restore
3872 POSITION to what it was before. */
3873 *position
= start_pos
;
3878 /* Check if SPEC is a display sub-property value whose text should be
3879 treated as intangible. */
3882 single_display_spec_intangible_p (prop
)
3885 /* Skip over `when FORM'. */
3886 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3900 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3901 we don't need to treat text as intangible. */
3902 if (EQ (XCAR (prop
), Qmargin
))
3910 || EQ (XCAR (prop
), Qleft_margin
)
3911 || EQ (XCAR (prop
), Qright_margin
))
3915 return (CONSP (prop
)
3916 && (EQ (XCAR (prop
), Qimage
)
3917 || EQ (XCAR (prop
), Qspace
)));
3921 /* Check if PROP is a display property value whose text should be
3922 treated as intangible. */
3925 display_prop_intangible_p (prop
)
3929 && CONSP (XCAR (prop
))
3930 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3932 /* A list of sub-properties. */
3933 while (CONSP (prop
))
3935 if (single_display_spec_intangible_p (XCAR (prop
)))
3940 else if (VECTORP (prop
))
3942 /* A vector of sub-properties. */
3944 for (i
= 0; i
< ASIZE (prop
); ++i
)
3945 if (single_display_spec_intangible_p (AREF (prop
, i
)))
3949 return single_display_spec_intangible_p (prop
);
3955 /* Return 1 if PROP is a display sub-property value containing STRING. */
3958 single_display_spec_string_p (prop
, string
)
3959 Lisp_Object prop
, string
;
3961 if (EQ (string
, prop
))
3964 /* Skip over `when FORM'. */
3965 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3974 /* Skip over `margin LOCATION'. */
3975 if (EQ (XCAR (prop
), Qmargin
))
3986 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3990 /* Return 1 if STRING appears in the `display' property PROP. */
3993 display_prop_string_p (prop
, string
)
3994 Lisp_Object prop
, string
;
3997 && CONSP (XCAR (prop
))
3998 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4000 /* A list of sub-properties. */
4001 while (CONSP (prop
))
4003 if (single_display_spec_string_p (XCAR (prop
), string
))
4008 else if (VECTORP (prop
))
4010 /* A vector of sub-properties. */
4012 for (i
= 0; i
< ASIZE (prop
); ++i
)
4013 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4017 return single_display_spec_string_p (prop
, string
);
4023 /* Determine from which buffer position in W's buffer STRING comes
4024 from. AROUND_CHARPOS is an approximate position where it could
4025 be from. Value is the buffer position or 0 if it couldn't be
4028 W's buffer must be current.
4030 This function is necessary because we don't record buffer positions
4031 in glyphs generated from strings (to keep struct glyph small).
4032 This function may only use code that doesn't eval because it is
4033 called asynchronously from note_mouse_highlight. */
4036 string_buffer_position (w
, string
, around_charpos
)
4041 Lisp_Object limit
, prop
, pos
;
4042 const int MAX_DISTANCE
= 1000;
4045 pos
= make_number (around_charpos
);
4046 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4047 while (!found
&& !EQ (pos
, limit
))
4049 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4050 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4053 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4058 pos
= make_number (around_charpos
);
4059 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4060 while (!found
&& !EQ (pos
, limit
))
4062 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4063 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4066 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4071 return found
? XINT (pos
) : 0;
4076 /***********************************************************************
4077 `composition' property
4078 ***********************************************************************/
4080 /* Set up iterator IT from `composition' property at its current
4081 position. Called from handle_stop. */
4083 static enum prop_handled
4084 handle_composition_prop (it
)
4087 Lisp_Object prop
, string
;
4088 int pos
, pos_byte
, end
;
4089 enum prop_handled handled
= HANDLED_NORMALLY
;
4091 if (STRINGP (it
->string
))
4093 pos
= IT_STRING_CHARPOS (*it
);
4094 pos_byte
= IT_STRING_BYTEPOS (*it
);
4095 string
= it
->string
;
4099 pos
= IT_CHARPOS (*it
);
4100 pos_byte
= IT_BYTEPOS (*it
);
4104 /* If there's a valid composition and point is not inside of the
4105 composition (in the case that the composition is from the current
4106 buffer), draw a glyph composed from the composition components. */
4107 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
4108 && COMPOSITION_VALID_P (pos
, end
, prop
)
4109 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
4111 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4115 it
->method
= GET_FROM_COMPOSITION
;
4117 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4118 /* For a terminal, draw only the first character of the
4120 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4121 it
->len
= (STRINGP (it
->string
)
4122 ? string_char_to_byte (it
->string
, end
)
4123 : CHAR_TO_BYTE (end
)) - pos_byte
;
4124 it
->stop_charpos
= end
;
4125 handled
= HANDLED_RETURN
;
4134 /***********************************************************************
4136 ***********************************************************************/
4138 /* The following structure is used to record overlay strings for
4139 later sorting in load_overlay_strings. */
4141 struct overlay_entry
4143 Lisp_Object overlay
;
4150 /* Set up iterator IT from overlay strings at its current position.
4151 Called from handle_stop. */
4153 static enum prop_handled
4154 handle_overlay_change (it
)
4157 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4158 return HANDLED_RECOMPUTE_PROPS
;
4160 return HANDLED_NORMALLY
;
4164 /* Set up the next overlay string for delivery by IT, if there is an
4165 overlay string to deliver. Called by set_iterator_to_next when the
4166 end of the current overlay string is reached. If there are more
4167 overlay strings to display, IT->string and
4168 IT->current.overlay_string_index are set appropriately here.
4169 Otherwise IT->string is set to nil. */
4172 next_overlay_string (it
)
4175 ++it
->current
.overlay_string_index
;
4176 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4178 /* No more overlay strings. Restore IT's settings to what
4179 they were before overlay strings were processed, and
4180 continue to deliver from current_buffer. */
4181 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4184 xassert (it
->stop_charpos
>= BEGV
4185 && it
->stop_charpos
<= it
->end_charpos
);
4187 it
->current
.overlay_string_index
= -1;
4188 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4189 it
->n_overlay_strings
= 0;
4190 it
->method
= GET_FROM_BUFFER
;
4192 /* If we're at the end of the buffer, record that we have
4193 processed the overlay strings there already, so that
4194 next_element_from_buffer doesn't try it again. */
4195 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4196 it
->overlay_strings_at_end_processed_p
= 1;
4198 /* If we have to display `...' for invisible text, set
4199 the iterator up for that. */
4200 if (display_ellipsis_p
)
4201 setup_for_ellipsis (it
, 0);
4205 /* There are more overlay strings to process. If
4206 IT->current.overlay_string_index has advanced to a position
4207 where we must load IT->overlay_strings with more strings, do
4209 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4211 if (it
->current
.overlay_string_index
&& i
== 0)
4212 load_overlay_strings (it
, 0);
4214 /* Initialize IT to deliver display elements from the overlay
4216 it
->string
= it
->overlay_strings
[i
];
4217 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4218 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4219 it
->method
= GET_FROM_STRING
;
4220 it
->stop_charpos
= 0;
4227 /* Compare two overlay_entry structures E1 and E2. Used as a
4228 comparison function for qsort in load_overlay_strings. Overlay
4229 strings for the same position are sorted so that
4231 1. All after-strings come in front of before-strings, except
4232 when they come from the same overlay.
4234 2. Within after-strings, strings are sorted so that overlay strings
4235 from overlays with higher priorities come first.
4237 2. Within before-strings, strings are sorted so that overlay
4238 strings from overlays with higher priorities come last.
4240 Value is analogous to strcmp. */
4244 compare_overlay_entries (e1
, e2
)
4247 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4248 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4251 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4253 /* Let after-strings appear in front of before-strings if
4254 they come from different overlays. */
4255 if (EQ (entry1
->overlay
, entry2
->overlay
))
4256 result
= entry1
->after_string_p
? 1 : -1;
4258 result
= entry1
->after_string_p
? -1 : 1;
4260 else if (entry1
->after_string_p
)
4261 /* After-strings sorted in order of decreasing priority. */
4262 result
= entry2
->priority
- entry1
->priority
;
4264 /* Before-strings sorted in order of increasing priority. */
4265 result
= entry1
->priority
- entry2
->priority
;
4271 /* Load the vector IT->overlay_strings with overlay strings from IT's
4272 current buffer position, or from CHARPOS if that is > 0. Set
4273 IT->n_overlays to the total number of overlay strings found.
4275 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4276 a time. On entry into load_overlay_strings,
4277 IT->current.overlay_string_index gives the number of overlay
4278 strings that have already been loaded by previous calls to this
4281 IT->add_overlay_start contains an additional overlay start
4282 position to consider for taking overlay strings from, if non-zero.
4283 This position comes into play when the overlay has an `invisible'
4284 property, and both before and after-strings. When we've skipped to
4285 the end of the overlay, because of its `invisible' property, we
4286 nevertheless want its before-string to appear.
4287 IT->add_overlay_start will contain the overlay start position
4290 Overlay strings are sorted so that after-string strings come in
4291 front of before-string strings. Within before and after-strings,
4292 strings are sorted by overlay priority. See also function
4293 compare_overlay_entries. */
4296 load_overlay_strings (it
, charpos
)
4300 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4301 Lisp_Object overlay
, window
, str
, invisible
;
4302 struct Lisp_Overlay
*ov
;
4305 int n
= 0, i
, j
, invis_p
;
4306 struct overlay_entry
*entries
4307 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4310 charpos
= IT_CHARPOS (*it
);
4312 /* Append the overlay string STRING of overlay OVERLAY to vector
4313 `entries' which has size `size' and currently contains `n'
4314 elements. AFTER_P non-zero means STRING is an after-string of
4316 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4319 Lisp_Object priority; \
4323 int new_size = 2 * size; \
4324 struct overlay_entry *old = entries; \
4326 (struct overlay_entry *) alloca (new_size \
4327 * sizeof *entries); \
4328 bcopy (old, entries, size * sizeof *entries); \
4332 entries[n].string = (STRING); \
4333 entries[n].overlay = (OVERLAY); \
4334 priority = Foverlay_get ((OVERLAY), Qpriority); \
4335 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4336 entries[n].after_string_p = (AFTER_P); \
4341 /* Process overlay before the overlay center. */
4342 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4344 XSETMISC (overlay
, ov
);
4345 xassert (OVERLAYP (overlay
));
4346 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4347 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4352 /* Skip this overlay if it doesn't start or end at IT's current
4354 if (end
!= charpos
&& start
!= charpos
)
4357 /* Skip this overlay if it doesn't apply to IT->w. */
4358 window
= Foverlay_get (overlay
, Qwindow
);
4359 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4362 /* If the text ``under'' the overlay is invisible, both before-
4363 and after-strings from this overlay are visible; start and
4364 end position are indistinguishable. */
4365 invisible
= Foverlay_get (overlay
, Qinvisible
);
4366 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4368 /* If overlay has a non-empty before-string, record it. */
4369 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4370 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4372 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4374 /* If overlay has a non-empty after-string, record it. */
4375 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4376 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4378 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4381 /* Process overlays after the overlay center. */
4382 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4384 XSETMISC (overlay
, ov
);
4385 xassert (OVERLAYP (overlay
));
4386 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4387 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4389 if (start
> charpos
)
4392 /* Skip this overlay if it doesn't start or end at IT's current
4394 if (end
!= charpos
&& start
!= charpos
)
4397 /* Skip this overlay if it doesn't apply to IT->w. */
4398 window
= Foverlay_get (overlay
, Qwindow
);
4399 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4402 /* If the text ``under'' the overlay is invisible, it has a zero
4403 dimension, and both before- and after-strings apply. */
4404 invisible
= Foverlay_get (overlay
, Qinvisible
);
4405 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4407 /* If overlay has a non-empty before-string, record it. */
4408 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4409 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4411 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4413 /* If overlay has a non-empty after-string, record it. */
4414 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4415 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4417 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4420 #undef RECORD_OVERLAY_STRING
4424 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4426 /* Record the total number of strings to process. */
4427 it
->n_overlay_strings
= n
;
4429 /* IT->current.overlay_string_index is the number of overlay strings
4430 that have already been consumed by IT. Copy some of the
4431 remaining overlay strings to IT->overlay_strings. */
4433 j
= it
->current
.overlay_string_index
;
4434 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4435 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4441 /* Get the first chunk of overlay strings at IT's current buffer
4442 position, or at CHARPOS if that is > 0. Value is non-zero if at
4443 least one overlay string was found. */
4446 get_overlay_strings (it
, charpos
)
4450 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4451 process. This fills IT->overlay_strings with strings, and sets
4452 IT->n_overlay_strings to the total number of strings to process.
4453 IT->pos.overlay_string_index has to be set temporarily to zero
4454 because load_overlay_strings needs this; it must be set to -1
4455 when no overlay strings are found because a zero value would
4456 indicate a position in the first overlay string. */
4457 it
->current
.overlay_string_index
= 0;
4458 load_overlay_strings (it
, charpos
);
4460 /* If we found overlay strings, set up IT to deliver display
4461 elements from the first one. Otherwise set up IT to deliver
4462 from current_buffer. */
4463 if (it
->n_overlay_strings
)
4465 /* Make sure we know settings in current_buffer, so that we can
4466 restore meaningful values when we're done with the overlay
4468 compute_stop_pos (it
);
4469 xassert (it
->face_id
>= 0);
4471 /* Save IT's settings. They are restored after all overlay
4472 strings have been processed. */
4473 xassert (it
->sp
== 0);
4476 /* Set up IT to deliver display elements from the first overlay
4478 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4479 it
->string
= it
->overlay_strings
[0];
4480 it
->stop_charpos
= 0;
4481 xassert (STRINGP (it
->string
));
4482 it
->end_charpos
= SCHARS (it
->string
);
4483 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4484 it
->method
= GET_FROM_STRING
;
4489 it
->current
.overlay_string_index
= -1;
4490 it
->method
= GET_FROM_BUFFER
;
4495 /* Value is non-zero if we found at least one overlay string. */
4496 return STRINGP (it
->string
);
4501 /***********************************************************************
4502 Saving and restoring state
4503 ***********************************************************************/
4505 /* Save current settings of IT on IT->stack. Called, for example,
4506 before setting up IT for an overlay string, to be able to restore
4507 IT's settings to what they were after the overlay string has been
4514 struct iterator_stack_entry
*p
;
4516 xassert (it
->sp
< 2);
4517 p
= it
->stack
+ it
->sp
;
4519 p
->stop_charpos
= it
->stop_charpos
;
4520 xassert (it
->face_id
>= 0);
4521 p
->face_id
= it
->face_id
;
4522 p
->string
= it
->string
;
4523 p
->pos
= it
->current
;
4524 p
->end_charpos
= it
->end_charpos
;
4525 p
->string_nchars
= it
->string_nchars
;
4527 p
->multibyte_p
= it
->multibyte_p
;
4528 p
->slice
= it
->slice
;
4529 p
->space_width
= it
->space_width
;
4530 p
->font_height
= it
->font_height
;
4531 p
->voffset
= it
->voffset
;
4532 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4533 p
->display_ellipsis_p
= 0;
4538 /* Restore IT's settings from IT->stack. Called, for example, when no
4539 more overlay strings must be processed, and we return to delivering
4540 display elements from a buffer, or when the end of a string from a
4541 `display' property is reached and we return to delivering display
4542 elements from an overlay string, or from a buffer. */
4548 struct iterator_stack_entry
*p
;
4550 xassert (it
->sp
> 0);
4552 p
= it
->stack
+ it
->sp
;
4553 it
->stop_charpos
= p
->stop_charpos
;
4554 it
->face_id
= p
->face_id
;
4555 it
->string
= p
->string
;
4556 it
->current
= p
->pos
;
4557 it
->end_charpos
= p
->end_charpos
;
4558 it
->string_nchars
= p
->string_nchars
;
4560 it
->multibyte_p
= p
->multibyte_p
;
4561 it
->slice
= p
->slice
;
4562 it
->space_width
= p
->space_width
;
4563 it
->font_height
= p
->font_height
;
4564 it
->voffset
= p
->voffset
;
4565 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4570 /***********************************************************************
4572 ***********************************************************************/
4574 /* Set IT's current position to the previous line start. */
4577 back_to_previous_line_start (it
)
4580 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4581 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4585 /* Move IT to the next line start.
4587 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4588 we skipped over part of the text (as opposed to moving the iterator
4589 continuously over the text). Otherwise, don't change the value
4592 Newlines may come from buffer text, overlay strings, or strings
4593 displayed via the `display' property. That's the reason we can't
4594 simply use find_next_newline_no_quit.
4596 Note that this function may not skip over invisible text that is so
4597 because of text properties and immediately follows a newline. If
4598 it would, function reseat_at_next_visible_line_start, when called
4599 from set_iterator_to_next, would effectively make invisible
4600 characters following a newline part of the wrong glyph row, which
4601 leads to wrong cursor motion. */
4604 forward_to_next_line_start (it
, skipped_p
)
4608 int old_selective
, newline_found_p
, n
;
4609 const int MAX_NEWLINE_DISTANCE
= 500;
4611 /* If already on a newline, just consume it to avoid unintended
4612 skipping over invisible text below. */
4613 if (it
->what
== IT_CHARACTER
4615 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4617 set_iterator_to_next (it
, 0);
4622 /* Don't handle selective display in the following. It's (a)
4623 unnecessary because it's done by the caller, and (b) leads to an
4624 infinite recursion because next_element_from_ellipsis indirectly
4625 calls this function. */
4626 old_selective
= it
->selective
;
4629 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4630 from buffer text. */
4631 for (n
= newline_found_p
= 0;
4632 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4633 n
+= STRINGP (it
->string
) ? 0 : 1)
4635 if (!get_next_display_element (it
))
4637 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4638 set_iterator_to_next (it
, 0);
4641 /* If we didn't find a newline near enough, see if we can use a
4643 if (!newline_found_p
)
4645 int start
= IT_CHARPOS (*it
);
4646 int limit
= find_next_newline_no_quit (start
, 1);
4649 xassert (!STRINGP (it
->string
));
4651 /* If there isn't any `display' property in sight, and no
4652 overlays, we can just use the position of the newline in
4654 if (it
->stop_charpos
>= limit
4655 || ((pos
= Fnext_single_property_change (make_number (start
),
4657 Qnil
, make_number (limit
)),
4659 && next_overlay_change (start
) == ZV
))
4661 IT_CHARPOS (*it
) = limit
;
4662 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4663 *skipped_p
= newline_found_p
= 1;
4667 while (get_next_display_element (it
)
4668 && !newline_found_p
)
4670 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4671 set_iterator_to_next (it
, 0);
4676 it
->selective
= old_selective
;
4677 return newline_found_p
;
4681 /* Set IT's current position to the previous visible line start. Skip
4682 invisible text that is so either due to text properties or due to
4683 selective display. Caution: this does not change IT->current_x and
4687 back_to_previous_visible_line_start (it
)
4690 while (IT_CHARPOS (*it
) > BEGV
)
4692 back_to_previous_line_start (it
);
4693 if (IT_CHARPOS (*it
) <= BEGV
)
4696 /* If selective > 0, then lines indented more than that values
4698 if (it
->selective
> 0
4699 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4700 (double) it
->selective
)) /* iftc */
4703 /* Check the newline before point for invisibility. */
4706 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
4707 Qinvisible
, it
->window
);
4708 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4712 /* If newline has a display property that replaces the newline with something
4713 else (image or text), find start of overlay or interval and continue search
4715 if (IT_CHARPOS (*it
) > BEGV
)
4717 struct it it2
= *it
;
4720 Lisp_Object val
, overlay
;
4722 pos
= --IT_CHARPOS (it2
);
4725 if (handle_display_prop (&it2
) == HANDLED_RETURN
4726 && !NILP (val
= get_char_property_and_overlay
4727 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
4728 && (OVERLAYP (overlay
)
4729 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
4730 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
4734 IT_CHARPOS (*it
) = beg
;
4735 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
4743 xassert (IT_CHARPOS (*it
) >= BEGV
);
4744 xassert (IT_CHARPOS (*it
) == BEGV
4745 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4750 /* Reseat iterator IT at the previous visible line start. Skip
4751 invisible text that is so either due to text properties or due to
4752 selective display. At the end, update IT's overlay information,
4753 face information etc. */
4756 reseat_at_previous_visible_line_start (it
)
4759 back_to_previous_visible_line_start (it
);
4760 reseat (it
, it
->current
.pos
, 1);
4765 /* Reseat iterator IT on the next visible line start in the current
4766 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4767 preceding the line start. Skip over invisible text that is so
4768 because of selective display. Compute faces, overlays etc at the
4769 new position. Note that this function does not skip over text that
4770 is invisible because of text properties. */
4773 reseat_at_next_visible_line_start (it
, on_newline_p
)
4777 int newline_found_p
, skipped_p
= 0;
4779 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4781 /* Skip over lines that are invisible because they are indented
4782 more than the value of IT->selective. */
4783 if (it
->selective
> 0)
4784 while (IT_CHARPOS (*it
) < ZV
4785 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4786 (double) it
->selective
)) /* iftc */
4788 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4789 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4792 /* Position on the newline if that's what's requested. */
4793 if (on_newline_p
&& newline_found_p
)
4795 if (STRINGP (it
->string
))
4797 if (IT_STRING_CHARPOS (*it
) > 0)
4799 --IT_STRING_CHARPOS (*it
);
4800 --IT_STRING_BYTEPOS (*it
);
4803 else if (IT_CHARPOS (*it
) > BEGV
)
4807 reseat (it
, it
->current
.pos
, 0);
4811 reseat (it
, it
->current
.pos
, 0);
4818 /***********************************************************************
4819 Changing an iterator's position
4820 ***********************************************************************/
4822 /* Change IT's current position to POS in current_buffer. If FORCE_P
4823 is non-zero, always check for text properties at the new position.
4824 Otherwise, text properties are only looked up if POS >=
4825 IT->check_charpos of a property. */
4828 reseat (it
, pos
, force_p
)
4830 struct text_pos pos
;
4833 int original_pos
= IT_CHARPOS (*it
);
4835 reseat_1 (it
, pos
, 0);
4837 /* Determine where to check text properties. Avoid doing it
4838 where possible because text property lookup is very expensive. */
4840 || CHARPOS (pos
) > it
->stop_charpos
4841 || CHARPOS (pos
) < original_pos
)
4848 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4849 IT->stop_pos to POS, also. */
4852 reseat_1 (it
, pos
, set_stop_p
)
4854 struct text_pos pos
;
4857 /* Don't call this function when scanning a C string. */
4858 xassert (it
->s
== NULL
);
4860 /* POS must be a reasonable value. */
4861 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4863 it
->current
.pos
= it
->position
= pos
;
4864 XSETBUFFER (it
->object
, current_buffer
);
4865 it
->end_charpos
= ZV
;
4867 it
->current
.dpvec_index
= -1;
4868 it
->current
.overlay_string_index
= -1;
4869 IT_STRING_CHARPOS (*it
) = -1;
4870 IT_STRING_BYTEPOS (*it
) = -1;
4872 it
->method
= GET_FROM_BUFFER
;
4873 /* RMS: I added this to fix a bug in move_it_vertically_backward
4874 where it->area continued to relate to the starting point
4875 for the backward motion. Bug report from
4876 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
4877 However, I am not sure whether reseat still does the right thing
4878 in general after this change. */
4879 it
->area
= TEXT_AREA
;
4880 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4882 it
->face_before_selective_p
= 0;
4885 it
->stop_charpos
= CHARPOS (pos
);
4889 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4890 If S is non-null, it is a C string to iterate over. Otherwise,
4891 STRING gives a Lisp string to iterate over.
4893 If PRECISION > 0, don't return more then PRECISION number of
4894 characters from the string.
4896 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4897 characters have been returned. FIELD_WIDTH < 0 means an infinite
4900 MULTIBYTE = 0 means disable processing of multibyte characters,
4901 MULTIBYTE > 0 means enable it,
4902 MULTIBYTE < 0 means use IT->multibyte_p.
4904 IT must be initialized via a prior call to init_iterator before
4905 calling this function. */
4908 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4913 int precision
, field_width
, multibyte
;
4915 /* No region in strings. */
4916 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4918 /* No text property checks performed by default, but see below. */
4919 it
->stop_charpos
= -1;
4921 /* Set iterator position and end position. */
4922 bzero (&it
->current
, sizeof it
->current
);
4923 it
->current
.overlay_string_index
= -1;
4924 it
->current
.dpvec_index
= -1;
4925 xassert (charpos
>= 0);
4927 /* If STRING is specified, use its multibyteness, otherwise use the
4928 setting of MULTIBYTE, if specified. */
4930 it
->multibyte_p
= multibyte
> 0;
4934 xassert (STRINGP (string
));
4935 it
->string
= string
;
4937 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4938 it
->method
= GET_FROM_STRING
;
4939 it
->current
.string_pos
= string_pos (charpos
, string
);
4946 /* Note that we use IT->current.pos, not it->current.string_pos,
4947 for displaying C strings. */
4948 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4949 if (it
->multibyte_p
)
4951 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4952 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4956 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4957 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4960 it
->method
= GET_FROM_C_STRING
;
4963 /* PRECISION > 0 means don't return more than PRECISION characters
4965 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4966 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4968 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4969 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4970 FIELD_WIDTH < 0 means infinite field width. This is useful for
4971 padding with `-' at the end of a mode line. */
4972 if (field_width
< 0)
4973 field_width
= INFINITY
;
4974 if (field_width
> it
->end_charpos
- charpos
)
4975 it
->end_charpos
= charpos
+ field_width
;
4977 /* Use the standard display table for displaying strings. */
4978 if (DISP_TABLE_P (Vstandard_display_table
))
4979 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4981 it
->stop_charpos
= charpos
;
4987 /***********************************************************************
4989 ***********************************************************************/
4991 /* Map enum it_method value to corresponding next_element_from_* function. */
4993 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
4995 next_element_from_buffer
,
4996 next_element_from_display_vector
,
4997 next_element_from_composition
,
4998 next_element_from_string
,
4999 next_element_from_c_string
,
5000 next_element_from_image
,
5001 next_element_from_stretch
5005 /* Load IT's display element fields with information about the next
5006 display element from the current position of IT. Value is zero if
5007 end of buffer (or C string) is reached. */
5010 get_next_display_element (it
)
5013 /* Non-zero means that we found a display element. Zero means that
5014 we hit the end of what we iterate over. Performance note: the
5015 function pointer `method' used here turns out to be faster than
5016 using a sequence of if-statements. */
5020 success_p
= (*get_next_element
[it
->method
]) (it
);
5022 if (it
->what
== IT_CHARACTER
)
5024 /* Map via display table or translate control characters.
5025 IT->c, IT->len etc. have been set to the next character by
5026 the function call above. If we have a display table, and it
5027 contains an entry for IT->c, translate it. Don't do this if
5028 IT->c itself comes from a display table, otherwise we could
5029 end up in an infinite recursion. (An alternative could be to
5030 count the recursion depth of this function and signal an
5031 error when a certain maximum depth is reached.) Is it worth
5033 if (success_p
&& it
->dpvec
== NULL
)
5038 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5041 struct Lisp_Vector
*v
= XVECTOR (dv
);
5043 /* Return the first character from the display table
5044 entry, if not empty. If empty, don't display the
5045 current character. */
5048 it
->dpvec_char_len
= it
->len
;
5049 it
->dpvec
= v
->contents
;
5050 it
->dpend
= v
->contents
+ v
->size
;
5051 it
->current
.dpvec_index
= 0;
5052 it
->dpvec_face_id
= -1;
5053 it
->saved_face_id
= it
->face_id
;
5054 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5059 set_iterator_to_next (it
, 0);
5064 /* Translate control characters into `\003' or `^C' form.
5065 Control characters coming from a display table entry are
5066 currently not translated because we use IT->dpvec to hold
5067 the translation. This could easily be changed but I
5068 don't believe that it is worth doing.
5070 If it->multibyte_p is nonzero, eight-bit characters and
5071 non-printable multibyte characters are also translated to
5074 If it->multibyte_p is zero, eight-bit characters that
5075 don't have corresponding multibyte char code are also
5076 translated to octal form. */
5077 else if ((it
->c
< ' '
5078 && (it
->area
!= TEXT_AREA
5079 /* In mode line, treat \n like other crl chars. */
5081 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5082 || (it
->c
!= '\n' && it
->c
!= '\t')))
5086 || !CHAR_PRINTABLE_P (it
->c
)
5087 || (!NILP (Vnobreak_char_display
)
5088 && (it
->c
== 0x8a0 || it
->c
== 0x8ad
5089 || it
->c
== 0x920 || it
->c
== 0x92d
5090 || it
->c
== 0xe20 || it
->c
== 0xe2d
5091 || it
->c
== 0xf20 || it
->c
== 0xf2d)))
5093 && (!unibyte_display_via_language_environment
5094 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5096 /* IT->c is a control character which must be displayed
5097 either as '\003' or as `^C' where the '\\' and '^'
5098 can be defined in the display table. Fill
5099 IT->ctl_chars with glyphs for what we have to
5100 display. Then, set IT->dpvec to these glyphs. */
5103 int face_id
, lface_id
= 0 ;
5106 /* Handle control characters with ^. */
5108 if (it
->c
< 128 && it
->ctl_arrow_p
)
5110 g
= '^'; /* default glyph for Control */
5111 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5113 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5114 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5116 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5117 lface_id
= FAST_GLYPH_FACE (g
);
5121 g
= FAST_GLYPH_CHAR (g
);
5122 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5127 /* Merge the escape-glyph face into the current face. */
5128 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5132 XSETINT (it
->ctl_chars
[0], g
);
5134 XSETINT (it
->ctl_chars
[1], g
);
5136 goto display_control
;
5139 /* Handle non-break space in the mode where it only gets
5142 if (EQ (Vnobreak_char_display
, Qt
)
5143 && (it
->c
== 0x8a0 || it
->c
== 0x920
5144 || it
->c
== 0xe20 || it
->c
== 0xf20))
5146 /* Merge the no-break-space face into the current face. */
5147 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5151 XSETINT (it
->ctl_chars
[0], g
);
5153 goto display_control
;
5156 /* Handle sequences that start with the "escape glyph". */
5158 /* the default escape glyph is \. */
5159 escape_glyph
= '\\';
5162 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5163 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5165 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5166 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5170 /* The display table specified a face.
5171 Merge it into face_id and also into escape_glyph. */
5172 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5173 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5178 /* Merge the escape-glyph face into the current face. */
5179 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5183 /* Handle soft hyphens in the mode where they only get
5186 if (EQ (Vnobreak_char_display
, Qt
)
5187 && (it
->c
== 0x8ad || it
->c
== 0x92d
5188 || it
->c
== 0xe2d || it
->c
== 0xf2d))
5191 XSETINT (it
->ctl_chars
[0], g
);
5193 goto display_control
;
5196 /* Handle non-break space and soft hyphen
5197 with the escape glyph. */
5199 if (it
->c
== 0x8a0 || it
->c
== 0x8ad
5200 || it
->c
== 0x920 || it
->c
== 0x92d
5201 || it
->c
== 0xe20 || it
->c
== 0xe2d
5202 || it
->c
== 0xf20 || it
->c
== 0xf2d)
5204 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5205 g
= it
->c
= ((it
->c
& 0xf) == 0 ? ' ' : '-');
5206 XSETINT (it
->ctl_chars
[1], g
);
5208 goto display_control
;
5212 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5216 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5217 if (SINGLE_BYTE_CHAR_P (it
->c
))
5218 str
[0] = it
->c
, len
= 1;
5221 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5224 /* It's an invalid character, which shouldn't
5225 happen actually, but due to bugs it may
5226 happen. Let's print the char as is, there's
5227 not much meaningful we can do with it. */
5229 str
[1] = it
->c
>> 8;
5230 str
[2] = it
->c
>> 16;
5231 str
[3] = it
->c
>> 24;
5236 for (i
= 0; i
< len
; i
++)
5238 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5239 /* Insert three more glyphs into IT->ctl_chars for
5240 the octal display of the character. */
5241 g
= ((str
[i
] >> 6) & 7) + '0';
5242 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5243 g
= ((str
[i
] >> 3) & 7) + '0';
5244 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5245 g
= (str
[i
] & 7) + '0';
5246 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5252 /* Set up IT->dpvec and return first character from it. */
5253 it
->dpvec_char_len
= it
->len
;
5254 it
->dpvec
= it
->ctl_chars
;
5255 it
->dpend
= it
->dpvec
+ ctl_len
;
5256 it
->current
.dpvec_index
= 0;
5257 it
->dpvec_face_id
= face_id
;
5258 it
->saved_face_id
= it
->face_id
;
5259 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5265 /* Adjust face id for a multibyte character. There are no
5266 multibyte character in unibyte text. */
5269 && FRAME_WINDOW_P (it
->f
))
5271 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5272 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5276 /* Is this character the last one of a run of characters with
5277 box? If yes, set IT->end_of_box_run_p to 1. */
5284 it
->end_of_box_run_p
5285 = ((face_id
= face_after_it_pos (it
),
5286 face_id
!= it
->face_id
)
5287 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5288 face
->box
== FACE_NO_BOX
));
5291 /* Value is 0 if end of buffer or string reached. */
5296 /* Move IT to the next display element.
5298 RESEAT_P non-zero means if called on a newline in buffer text,
5299 skip to the next visible line start.
5301 Functions get_next_display_element and set_iterator_to_next are
5302 separate because I find this arrangement easier to handle than a
5303 get_next_display_element function that also increments IT's
5304 position. The way it is we can first look at an iterator's current
5305 display element, decide whether it fits on a line, and if it does,
5306 increment the iterator position. The other way around we probably
5307 would either need a flag indicating whether the iterator has to be
5308 incremented the next time, or we would have to implement a
5309 decrement position function which would not be easy to write. */
5312 set_iterator_to_next (it
, reseat_p
)
5316 /* Reset flags indicating start and end of a sequence of characters
5317 with box. Reset them at the start of this function because
5318 moving the iterator to a new position might set them. */
5319 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5323 case GET_FROM_BUFFER
:
5324 /* The current display element of IT is a character from
5325 current_buffer. Advance in the buffer, and maybe skip over
5326 invisible lines that are so because of selective display. */
5327 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5328 reseat_at_next_visible_line_start (it
, 0);
5331 xassert (it
->len
!= 0);
5332 IT_BYTEPOS (*it
) += it
->len
;
5333 IT_CHARPOS (*it
) += 1;
5334 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5338 case GET_FROM_COMPOSITION
:
5339 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5340 if (STRINGP (it
->string
))
5342 IT_STRING_BYTEPOS (*it
) += it
->len
;
5343 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5344 it
->method
= GET_FROM_STRING
;
5345 goto consider_string_end
;
5349 IT_BYTEPOS (*it
) += it
->len
;
5350 IT_CHARPOS (*it
) += it
->cmp_len
;
5351 it
->method
= GET_FROM_BUFFER
;
5355 case GET_FROM_C_STRING
:
5356 /* Current display element of IT is from a C string. */
5357 IT_BYTEPOS (*it
) += it
->len
;
5358 IT_CHARPOS (*it
) += 1;
5361 case GET_FROM_DISPLAY_VECTOR
:
5362 /* Current display element of IT is from a display table entry.
5363 Advance in the display table definition. Reset it to null if
5364 end reached, and continue with characters from buffers/
5366 ++it
->current
.dpvec_index
;
5368 /* Restore face of the iterator to what they were before the
5369 display vector entry (these entries may contain faces). */
5370 it
->face_id
= it
->saved_face_id
;
5372 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5375 it
->method
= GET_FROM_C_STRING
;
5376 else if (STRINGP (it
->string
))
5377 it
->method
= GET_FROM_STRING
;
5379 it
->method
= GET_FROM_BUFFER
;
5382 it
->current
.dpvec_index
= -1;
5384 /* Skip over characters which were displayed via IT->dpvec. */
5385 if (it
->dpvec_char_len
< 0)
5386 reseat_at_next_visible_line_start (it
, 1);
5387 else if (it
->dpvec_char_len
> 0)
5389 it
->len
= it
->dpvec_char_len
;
5390 set_iterator_to_next (it
, reseat_p
);
5393 /* Recheck faces after display vector */
5394 it
->stop_charpos
= IT_CHARPOS (*it
);
5398 case GET_FROM_STRING
:
5399 /* Current display element is a character from a Lisp string. */
5400 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5401 IT_STRING_BYTEPOS (*it
) += it
->len
;
5402 IT_STRING_CHARPOS (*it
) += 1;
5404 consider_string_end
:
5406 if (it
->current
.overlay_string_index
>= 0)
5408 /* IT->string is an overlay string. Advance to the
5409 next, if there is one. */
5410 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5411 next_overlay_string (it
);
5415 /* IT->string is not an overlay string. If we reached
5416 its end, and there is something on IT->stack, proceed
5417 with what is on the stack. This can be either another
5418 string, this time an overlay string, or a buffer. */
5419 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5423 if (STRINGP (it
->string
))
5424 goto consider_string_end
;
5425 it
->method
= GET_FROM_BUFFER
;
5430 case GET_FROM_IMAGE
:
5431 case GET_FROM_STRETCH
:
5432 /* The position etc with which we have to proceed are on
5433 the stack. The position may be at the end of a string,
5434 if the `display' property takes up the whole string. */
5435 xassert (it
->sp
> 0);
5438 if (STRINGP (it
->string
))
5440 it
->method
= GET_FROM_STRING
;
5441 goto consider_string_end
;
5443 it
->method
= GET_FROM_BUFFER
;
5447 /* There are no other methods defined, so this should be a bug. */
5451 xassert (it
->method
!= GET_FROM_STRING
5452 || (STRINGP (it
->string
)
5453 && IT_STRING_CHARPOS (*it
) >= 0));
5456 /* Load IT's display element fields with information about the next
5457 display element which comes from a display table entry or from the
5458 result of translating a control character to one of the forms `^C'
5461 IT->dpvec holds the glyphs to return as characters.
5462 IT->saved_face_id holds the face id before the display vector--
5463 it is restored into IT->face_idin set_iterator_to_next. */
5466 next_element_from_display_vector (it
)
5470 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5472 it
->face_id
= it
->saved_face_id
;
5474 if (INTEGERP (*it
->dpvec
)
5475 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5479 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5480 it
->c
= FAST_GLYPH_CHAR (g
);
5481 it
->len
= CHAR_BYTES (it
->c
);
5483 /* The entry may contain a face id to use. Such a face id is
5484 the id of a Lisp face, not a realized face. A face id of
5485 zero means no face is specified. */
5486 if (it
->dpvec_face_id
>= 0)
5487 it
->face_id
= it
->dpvec_face_id
;
5490 int lface_id
= FAST_GLYPH_FACE (g
);
5492 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5497 /* Display table entry is invalid. Return a space. */
5498 it
->c
= ' ', it
->len
= 1;
5500 /* Don't change position and object of the iterator here. They are
5501 still the values of the character that had this display table
5502 entry or was translated, and that's what we want. */
5503 it
->what
= IT_CHARACTER
;
5508 /* Load IT with the next display element from Lisp string IT->string.
5509 IT->current.string_pos is the current position within the string.
5510 If IT->current.overlay_string_index >= 0, the Lisp string is an
5514 next_element_from_string (it
)
5517 struct text_pos position
;
5519 xassert (STRINGP (it
->string
));
5520 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5521 position
= it
->current
.string_pos
;
5523 /* Time to check for invisible text? */
5524 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5525 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5529 /* Since a handler may have changed IT->method, we must
5531 return get_next_display_element (it
);
5534 if (it
->current
.overlay_string_index
>= 0)
5536 /* Get the next character from an overlay string. In overlay
5537 strings, There is no field width or padding with spaces to
5539 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5544 else if (STRING_MULTIBYTE (it
->string
))
5546 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5547 const unsigned char *s
= (SDATA (it
->string
)
5548 + IT_STRING_BYTEPOS (*it
));
5549 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5553 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5559 /* Get the next character from a Lisp string that is not an
5560 overlay string. Such strings come from the mode line, for
5561 example. We may have to pad with spaces, or truncate the
5562 string. See also next_element_from_c_string. */
5563 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5568 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5570 /* Pad with spaces. */
5571 it
->c
= ' ', it
->len
= 1;
5572 CHARPOS (position
) = BYTEPOS (position
) = -1;
5574 else if (STRING_MULTIBYTE (it
->string
))
5576 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5577 const unsigned char *s
= (SDATA (it
->string
)
5578 + IT_STRING_BYTEPOS (*it
));
5579 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5583 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5588 /* Record what we have and where it came from. Note that we store a
5589 buffer position in IT->position although it could arguably be a
5591 it
->what
= IT_CHARACTER
;
5592 it
->object
= it
->string
;
5593 it
->position
= position
;
5598 /* Load IT with next display element from C string IT->s.
5599 IT->string_nchars is the maximum number of characters to return
5600 from the string. IT->end_charpos may be greater than
5601 IT->string_nchars when this function is called, in which case we
5602 may have to return padding spaces. Value is zero if end of string
5603 reached, including padding spaces. */
5606 next_element_from_c_string (it
)
5612 it
->what
= IT_CHARACTER
;
5613 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5616 /* IT's position can be greater IT->string_nchars in case a field
5617 width or precision has been specified when the iterator was
5619 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5621 /* End of the game. */
5625 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5627 /* Pad with spaces. */
5628 it
->c
= ' ', it
->len
= 1;
5629 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5631 else if (it
->multibyte_p
)
5633 /* Implementation note: The calls to strlen apparently aren't a
5634 performance problem because there is no noticeable performance
5635 difference between Emacs running in unibyte or multibyte mode. */
5636 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5637 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5641 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5647 /* Set up IT to return characters from an ellipsis, if appropriate.
5648 The definition of the ellipsis glyphs may come from a display table
5649 entry. This function Fills IT with the first glyph from the
5650 ellipsis if an ellipsis is to be displayed. */
5653 next_element_from_ellipsis (it
)
5656 if (it
->selective_display_ellipsis_p
)
5657 setup_for_ellipsis (it
, it
->len
);
5660 /* The face at the current position may be different from the
5661 face we find after the invisible text. Remember what it
5662 was in IT->saved_face_id, and signal that it's there by
5663 setting face_before_selective_p. */
5664 it
->saved_face_id
= it
->face_id
;
5665 it
->method
= GET_FROM_BUFFER
;
5666 reseat_at_next_visible_line_start (it
, 1);
5667 it
->face_before_selective_p
= 1;
5670 return get_next_display_element (it
);
5674 /* Deliver an image display element. The iterator IT is already
5675 filled with image information (done in handle_display_prop). Value
5680 next_element_from_image (it
)
5683 it
->what
= IT_IMAGE
;
5688 /* Fill iterator IT with next display element from a stretch glyph
5689 property. IT->object is the value of the text property. Value is
5693 next_element_from_stretch (it
)
5696 it
->what
= IT_STRETCH
;
5701 /* Load IT with the next display element from current_buffer. Value
5702 is zero if end of buffer reached. IT->stop_charpos is the next
5703 position at which to stop and check for text properties or buffer
5707 next_element_from_buffer (it
)
5712 /* Check this assumption, otherwise, we would never enter the
5713 if-statement, below. */
5714 xassert (IT_CHARPOS (*it
) >= BEGV
5715 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
5717 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
5719 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5721 int overlay_strings_follow_p
;
5723 /* End of the game, except when overlay strings follow that
5724 haven't been returned yet. */
5725 if (it
->overlay_strings_at_end_processed_p
)
5726 overlay_strings_follow_p
= 0;
5729 it
->overlay_strings_at_end_processed_p
= 1;
5730 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
5733 if (overlay_strings_follow_p
)
5734 success_p
= get_next_display_element (it
);
5738 it
->position
= it
->current
.pos
;
5745 return get_next_display_element (it
);
5750 /* No face changes, overlays etc. in sight, so just return a
5751 character from current_buffer. */
5754 /* Maybe run the redisplay end trigger hook. Performance note:
5755 This doesn't seem to cost measurable time. */
5756 if (it
->redisplay_end_trigger_charpos
5758 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
5759 run_redisplay_end_trigger_hook (it
);
5761 /* Get the next character, maybe multibyte. */
5762 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
5763 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
5765 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
5766 - IT_BYTEPOS (*it
));
5767 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
5770 it
->c
= *p
, it
->len
= 1;
5772 /* Record what we have and where it came from. */
5773 it
->what
= IT_CHARACTER
;;
5774 it
->object
= it
->w
->buffer
;
5775 it
->position
= it
->current
.pos
;
5777 /* Normally we return the character found above, except when we
5778 really want to return an ellipsis for selective display. */
5783 /* A value of selective > 0 means hide lines indented more
5784 than that number of columns. */
5785 if (it
->selective
> 0
5786 && IT_CHARPOS (*it
) + 1 < ZV
5787 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
5788 IT_BYTEPOS (*it
) + 1,
5789 (double) it
->selective
)) /* iftc */
5791 success_p
= next_element_from_ellipsis (it
);
5792 it
->dpvec_char_len
= -1;
5795 else if (it
->c
== '\r' && it
->selective
== -1)
5797 /* A value of selective == -1 means that everything from the
5798 CR to the end of the line is invisible, with maybe an
5799 ellipsis displayed for it. */
5800 success_p
= next_element_from_ellipsis (it
);
5801 it
->dpvec_char_len
= -1;
5806 /* Value is zero if end of buffer reached. */
5807 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
5812 /* Run the redisplay end trigger hook for IT. */
5815 run_redisplay_end_trigger_hook (it
)
5818 Lisp_Object args
[3];
5820 /* IT->glyph_row should be non-null, i.e. we should be actually
5821 displaying something, or otherwise we should not run the hook. */
5822 xassert (it
->glyph_row
);
5824 /* Set up hook arguments. */
5825 args
[0] = Qredisplay_end_trigger_functions
;
5826 args
[1] = it
->window
;
5827 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
5828 it
->redisplay_end_trigger_charpos
= 0;
5830 /* Since we are *trying* to run these functions, don't try to run
5831 them again, even if they get an error. */
5832 it
->w
->redisplay_end_trigger
= Qnil
;
5833 Frun_hook_with_args (3, args
);
5835 /* Notice if it changed the face of the character we are on. */
5836 handle_face_prop (it
);
5840 /* Deliver a composition display element. The iterator IT is already
5841 filled with composition information (done in
5842 handle_composition_prop). Value is always 1. */
5845 next_element_from_composition (it
)
5848 it
->what
= IT_COMPOSITION
;
5849 it
->position
= (STRINGP (it
->string
)
5850 ? it
->current
.string_pos
5857 /***********************************************************************
5858 Moving an iterator without producing glyphs
5859 ***********************************************************************/
5861 /* Move iterator IT to a specified buffer or X position within one
5862 line on the display without producing glyphs.
5864 OP should be a bit mask including some or all of these bits:
5865 MOVE_TO_X: Stop on reaching x-position TO_X.
5866 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5867 Regardless of OP's value, stop in reaching the end of the display line.
5869 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5870 This means, in particular, that TO_X includes window's horizontal
5873 The return value has several possible values that
5874 say what condition caused the scan to stop:
5876 MOVE_POS_MATCH_OR_ZV
5877 - when TO_POS or ZV was reached.
5880 -when TO_X was reached before TO_POS or ZV were reached.
5883 - when we reached the end of the display area and the line must
5887 - when we reached the end of the display area and the line is
5891 - when we stopped at a line end, i.e. a newline or a CR and selective
5894 static enum move_it_result
5895 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5897 int to_charpos
, to_x
, op
;
5899 enum move_it_result result
= MOVE_UNDEFINED
;
5900 struct glyph_row
*saved_glyph_row
;
5902 /* Don't produce glyphs in produce_glyphs. */
5903 saved_glyph_row
= it
->glyph_row
;
5904 it
->glyph_row
= NULL
;
5906 #define BUFFER_POS_REACHED_P() \
5907 ((op & MOVE_TO_POS) != 0 \
5908 && BUFFERP (it->object) \
5909 && IT_CHARPOS (*it) >= to_charpos \
5910 && (it->method == GET_FROM_BUFFER \
5911 || (it->method == GET_FROM_DISPLAY_VECTOR \
5912 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
5917 int x
, i
, ascent
= 0, descent
= 0;
5919 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
5920 if ((op
& MOVE_TO_POS
) != 0
5921 && BUFFERP (it
->object
)
5922 && it
->method
== GET_FROM_BUFFER
5923 && IT_CHARPOS (*it
) > to_charpos
)
5925 result
= MOVE_POS_MATCH_OR_ZV
;
5929 /* Stop when ZV reached.
5930 We used to stop here when TO_CHARPOS reached as well, but that is
5931 too soon if this glyph does not fit on this line. So we handle it
5932 explicitly below. */
5933 if (!get_next_display_element (it
)
5934 || (it
->truncate_lines_p
5935 && BUFFER_POS_REACHED_P ()))
5937 result
= MOVE_POS_MATCH_OR_ZV
;
5941 /* The call to produce_glyphs will get the metrics of the
5942 display element IT is loaded with. We record in x the
5943 x-position before this display element in case it does not
5947 /* Remember the line height so far in case the next element doesn't
5949 if (!it
->truncate_lines_p
)
5951 ascent
= it
->max_ascent
;
5952 descent
= it
->max_descent
;
5955 PRODUCE_GLYPHS (it
);
5957 if (it
->area
!= TEXT_AREA
)
5959 set_iterator_to_next (it
, 1);
5963 /* The number of glyphs we get back in IT->nglyphs will normally
5964 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5965 character on a terminal frame, or (iii) a line end. For the
5966 second case, IT->nglyphs - 1 padding glyphs will be present
5967 (on X frames, there is only one glyph produced for a
5968 composite character.
5970 The behavior implemented below means, for continuation lines,
5971 that as many spaces of a TAB as fit on the current line are
5972 displayed there. For terminal frames, as many glyphs of a
5973 multi-glyph character are displayed in the current line, too.
5974 This is what the old redisplay code did, and we keep it that
5975 way. Under X, the whole shape of a complex character must
5976 fit on the line or it will be completely displayed in the
5979 Note that both for tabs and padding glyphs, all glyphs have
5983 /* More than one glyph or glyph doesn't fit on line. All
5984 glyphs have the same width. */
5985 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5988 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5990 new_x
= x
+ single_glyph_width
;
5992 /* We want to leave anything reaching TO_X to the caller. */
5993 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5995 if (BUFFER_POS_REACHED_P ())
5996 goto buffer_pos_reached
;
5998 result
= MOVE_X_REACHED
;
6001 else if (/* Lines are continued. */
6002 !it
->truncate_lines_p
6003 && (/* And glyph doesn't fit on the line. */
6004 new_x
> it
->last_visible_x
6005 /* Or it fits exactly and we're on a window
6007 || (new_x
== it
->last_visible_x
6008 && FRAME_WINDOW_P (it
->f
))))
6010 if (/* IT->hpos == 0 means the very first glyph
6011 doesn't fit on the line, e.g. a wide image. */
6013 || (new_x
== it
->last_visible_x
6014 && FRAME_WINDOW_P (it
->f
)))
6017 it
->current_x
= new_x
;
6018 if (i
== it
->nglyphs
- 1)
6020 set_iterator_to_next (it
, 1);
6021 #ifdef HAVE_WINDOW_SYSTEM
6022 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6024 if (!get_next_display_element (it
))
6026 result
= MOVE_POS_MATCH_OR_ZV
;
6029 if (BUFFER_POS_REACHED_P ())
6031 if (ITERATOR_AT_END_OF_LINE_P (it
))
6032 result
= MOVE_POS_MATCH_OR_ZV
;
6034 result
= MOVE_LINE_CONTINUED
;
6037 if (ITERATOR_AT_END_OF_LINE_P (it
))
6039 result
= MOVE_NEWLINE_OR_CR
;
6043 #endif /* HAVE_WINDOW_SYSTEM */
6049 it
->max_ascent
= ascent
;
6050 it
->max_descent
= descent
;
6053 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6055 result
= MOVE_LINE_CONTINUED
;
6058 else if (BUFFER_POS_REACHED_P ())
6059 goto buffer_pos_reached
;
6060 else if (new_x
> it
->first_visible_x
)
6062 /* Glyph is visible. Increment number of glyphs that
6063 would be displayed. */
6068 /* Glyph is completely off the left margin of the display
6069 area. Nothing to do. */
6073 if (result
!= MOVE_UNDEFINED
)
6076 else if (BUFFER_POS_REACHED_P ())
6080 it
->max_ascent
= ascent
;
6081 it
->max_descent
= descent
;
6082 result
= MOVE_POS_MATCH_OR_ZV
;
6085 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6087 /* Stop when TO_X specified and reached. This check is
6088 necessary here because of lines consisting of a line end,
6089 only. The line end will not produce any glyphs and we
6090 would never get MOVE_X_REACHED. */
6091 xassert (it
->nglyphs
== 0);
6092 result
= MOVE_X_REACHED
;
6096 /* Is this a line end? If yes, we're done. */
6097 if (ITERATOR_AT_END_OF_LINE_P (it
))
6099 result
= MOVE_NEWLINE_OR_CR
;
6103 /* The current display element has been consumed. Advance
6105 set_iterator_to_next (it
, 1);
6107 /* Stop if lines are truncated and IT's current x-position is
6108 past the right edge of the window now. */
6109 if (it
->truncate_lines_p
6110 && it
->current_x
>= it
->last_visible_x
)
6112 #ifdef HAVE_WINDOW_SYSTEM
6113 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6115 if (!get_next_display_element (it
)
6116 || BUFFER_POS_REACHED_P ())
6118 result
= MOVE_POS_MATCH_OR_ZV
;
6121 if (ITERATOR_AT_END_OF_LINE_P (it
))
6123 result
= MOVE_NEWLINE_OR_CR
;
6127 #endif /* HAVE_WINDOW_SYSTEM */
6128 result
= MOVE_LINE_TRUNCATED
;
6133 #undef BUFFER_POS_REACHED_P
6135 /* Restore the iterator settings altered at the beginning of this
6137 it
->glyph_row
= saved_glyph_row
;
6142 /* Move IT forward until it satisfies one or more of the criteria in
6143 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6145 OP is a bit-mask that specifies where to stop, and in particular,
6146 which of those four position arguments makes a difference. See the
6147 description of enum move_operation_enum.
6149 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6150 screen line, this function will set IT to the next position >
6154 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6156 int to_charpos
, to_x
, to_y
, to_vpos
;
6159 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6165 if (op
& MOVE_TO_VPOS
)
6167 /* If no TO_CHARPOS and no TO_X specified, stop at the
6168 start of the line TO_VPOS. */
6169 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6171 if (it
->vpos
== to_vpos
)
6177 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6181 /* TO_VPOS >= 0 means stop at TO_X in the line at
6182 TO_VPOS, or at TO_POS, whichever comes first. */
6183 if (it
->vpos
== to_vpos
)
6189 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6191 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6196 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6198 /* We have reached TO_X but not in the line we want. */
6199 skip
= move_it_in_display_line_to (it
, to_charpos
,
6201 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6209 else if (op
& MOVE_TO_Y
)
6211 struct it it_backup
;
6213 /* TO_Y specified means stop at TO_X in the line containing
6214 TO_Y---or at TO_CHARPOS if this is reached first. The
6215 problem is that we can't really tell whether the line
6216 contains TO_Y before we have completely scanned it, and
6217 this may skip past TO_X. What we do is to first scan to
6220 If TO_X is not specified, use a TO_X of zero. The reason
6221 is to make the outcome of this function more predictable.
6222 If we didn't use TO_X == 0, we would stop at the end of
6223 the line which is probably not what a caller would expect
6225 skip
= move_it_in_display_line_to (it
, to_charpos
,
6229 | (op
& MOVE_TO_POS
)));
6231 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6232 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6238 /* If TO_X was reached, we would like to know whether TO_Y
6239 is in the line. This can only be said if we know the
6240 total line height which requires us to scan the rest of
6242 if (skip
== MOVE_X_REACHED
)
6245 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6246 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6248 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6251 /* Now, decide whether TO_Y is in this line. */
6252 line_height
= it
->max_ascent
+ it
->max_descent
;
6253 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6255 if (to_y
>= it
->current_y
6256 && to_y
< it
->current_y
+ line_height
)
6258 if (skip
== MOVE_X_REACHED
)
6259 /* If TO_Y is in this line and TO_X was reached above,
6260 we scanned too far. We have to restore IT's settings
6261 to the ones before skipping. */
6265 else if (skip
== MOVE_X_REACHED
)
6268 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6276 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6280 case MOVE_POS_MATCH_OR_ZV
:
6284 case MOVE_NEWLINE_OR_CR
:
6285 set_iterator_to_next (it
, 1);
6286 it
->continuation_lines_width
= 0;
6289 case MOVE_LINE_TRUNCATED
:
6290 it
->continuation_lines_width
= 0;
6291 reseat_at_next_visible_line_start (it
, 0);
6292 if ((op
& MOVE_TO_POS
) != 0
6293 && IT_CHARPOS (*it
) > to_charpos
)
6300 case MOVE_LINE_CONTINUED
:
6301 it
->continuation_lines_width
+= it
->current_x
;
6308 /* Reset/increment for the next run. */
6309 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6310 it
->current_x
= it
->hpos
= 0;
6311 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6313 last_height
= it
->max_ascent
+ it
->max_descent
;
6314 last_max_ascent
= it
->max_ascent
;
6315 it
->max_ascent
= it
->max_descent
= 0;
6320 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6324 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6326 If DY > 0, move IT backward at least that many pixels. DY = 0
6327 means move IT backward to the preceding line start or BEGV. This
6328 function may move over more than DY pixels if IT->current_y - DY
6329 ends up in the middle of a line; in this case IT->current_y will be
6330 set to the top of the line moved to. */
6333 move_it_vertically_backward (it
, dy
)
6344 start_pos
= IT_CHARPOS (*it
);
6346 /* Estimate how many newlines we must move back. */
6347 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6349 /* Set the iterator's position that many lines back. */
6350 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6351 back_to_previous_visible_line_start (it
);
6353 /* Reseat the iterator here. When moving backward, we don't want
6354 reseat to skip forward over invisible text, set up the iterator
6355 to deliver from overlay strings at the new position etc. So,
6356 use reseat_1 here. */
6357 reseat_1 (it
, it
->current
.pos
, 1);
6359 /* We are now surely at a line start. */
6360 it
->current_x
= it
->hpos
= 0;
6361 it
->continuation_lines_width
= 0;
6363 /* Move forward and see what y-distance we moved. First move to the
6364 start of the next line so that we get its height. We need this
6365 height to be able to tell whether we reached the specified
6368 it2
.max_ascent
= it2
.max_descent
= 0;
6369 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6370 MOVE_TO_POS
| MOVE_TO_VPOS
);
6371 xassert (IT_CHARPOS (*it
) >= BEGV
);
6374 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6375 xassert (IT_CHARPOS (*it
) >= BEGV
);
6376 /* H is the actual vertical distance from the position in *IT
6377 and the starting position. */
6378 h
= it2
.current_y
- it
->current_y
;
6379 /* NLINES is the distance in number of lines. */
6380 nlines
= it2
.vpos
- it
->vpos
;
6382 /* Correct IT's y and vpos position
6383 so that they are relative to the starting point. */
6389 /* DY == 0 means move to the start of the screen line. The
6390 value of nlines is > 0 if continuation lines were involved. */
6392 move_it_by_lines (it
, nlines
, 1);
6394 /* I think this assert is bogus if buffer contains
6395 invisible text or images. KFS. */
6396 xassert (IT_CHARPOS (*it
) <= start_pos
);
6401 /* The y-position we try to reach, relative to *IT.
6402 Note that H has been subtracted in front of the if-statement. */
6403 int target_y
= it
->current_y
+ h
- dy
;
6404 int y0
= it3
.current_y
;
6405 int y1
= line_bottom_y (&it3
);
6406 int line_height
= y1
- y0
;
6408 /* If we did not reach target_y, try to move further backward if
6409 we can. If we moved too far backward, try to move forward. */
6410 if (target_y
< it
->current_y
6411 /* This is heuristic. In a window that's 3 lines high, with
6412 a line height of 13 pixels each, recentering with point
6413 on the bottom line will try to move -39/2 = 19 pixels
6414 backward. Try to avoid moving into the first line. */
6415 && (it
->current_y
- target_y
6416 > min (window_box_height (it
->w
), line_height
* 2 / 3))
6417 && IT_CHARPOS (*it
) > BEGV
)
6419 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6420 target_y
- it
->current_y
));
6421 dy
= it
->current_y
- target_y
;
6422 goto move_further_back
;
6424 else if (target_y
>= it
->current_y
+ line_height
6425 && IT_CHARPOS (*it
) < ZV
)
6427 /* Should move forward by at least one line, maybe more.
6429 Note: Calling move_it_by_lines can be expensive on
6430 terminal frames, where compute_motion is used (via
6431 vmotion) to do the job, when there are very long lines
6432 and truncate-lines is nil. That's the reason for
6433 treating terminal frames specially here. */
6435 if (!FRAME_WINDOW_P (it
->f
))
6436 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6441 move_it_by_lines (it
, 1, 1);
6443 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6447 /* I think this assert is bogus if buffer contains
6448 invisible text or images. KFS. */
6449 xassert (IT_CHARPOS (*it
) >= BEGV
);
6456 /* Move IT by a specified amount of pixel lines DY. DY negative means
6457 move backwards. DY = 0 means move to start of screen line. At the
6458 end, IT will be on the start of a screen line. */
6461 move_it_vertically (it
, dy
)
6466 move_it_vertically_backward (it
, -dy
);
6469 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6470 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6471 MOVE_TO_POS
| MOVE_TO_Y
);
6472 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6474 /* If buffer ends in ZV without a newline, move to the start of
6475 the line to satisfy the post-condition. */
6476 if (IT_CHARPOS (*it
) == ZV
6477 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6478 move_it_by_lines (it
, 0, 0);
6483 /* Move iterator IT past the end of the text line it is in. */
6486 move_it_past_eol (it
)
6489 enum move_it_result rc
;
6491 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6492 if (rc
== MOVE_NEWLINE_OR_CR
)
6493 set_iterator_to_next (it
, 0);
6497 #if 0 /* Currently not used. */
6499 /* Return non-zero if some text between buffer positions START_CHARPOS
6500 and END_CHARPOS is invisible. IT->window is the window for text
6504 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6506 int start_charpos
, end_charpos
;
6508 Lisp_Object prop
, limit
;
6509 int invisible_found_p
;
6511 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6513 /* Is text at START invisible? */
6514 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6516 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6517 invisible_found_p
= 1;
6520 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6522 make_number (end_charpos
));
6523 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6526 return invisible_found_p
;
6532 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6533 negative means move up. DVPOS == 0 means move to the start of the
6534 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6535 NEED_Y_P is zero, IT->current_y will be left unchanged.
6537 Further optimization ideas: If we would know that IT->f doesn't use
6538 a face with proportional font, we could be faster for
6539 truncate-lines nil. */
6542 move_it_by_lines (it
, dvpos
, need_y_p
)
6544 int dvpos
, need_y_p
;
6546 struct position pos
;
6548 if (!FRAME_WINDOW_P (it
->f
))
6550 struct text_pos textpos
;
6552 /* We can use vmotion on frames without proportional fonts. */
6553 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6554 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6555 reseat (it
, textpos
, 1);
6556 it
->vpos
+= pos
.vpos
;
6557 it
->current_y
+= pos
.vpos
;
6559 else if (dvpos
== 0)
6561 /* DVPOS == 0 means move to the start of the screen line. */
6562 move_it_vertically_backward (it
, 0);
6563 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6564 /* Let next call to line_bottom_y calculate real line height */
6568 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6572 int start_charpos
, i
;
6574 /* Start at the beginning of the screen line containing IT's
6576 move_it_vertically_backward (it
, 0);
6578 /* Go back -DVPOS visible lines and reseat the iterator there. */
6579 start_charpos
= IT_CHARPOS (*it
);
6580 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
6581 back_to_previous_visible_line_start (it
);
6582 reseat (it
, it
->current
.pos
, 1);
6583 it
->current_x
= it
->hpos
= 0;
6585 /* Above call may have moved too far if continuation lines
6586 are involved. Scan forward and see if it did. */
6588 it2
.vpos
= it2
.current_y
= 0;
6589 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6590 it
->vpos
-= it2
.vpos
;
6591 it
->current_y
-= it2
.current_y
;
6592 it
->current_x
= it
->hpos
= 0;
6594 /* If we moved too far back, move IT some lines forward. */
6595 if (it2
.vpos
> -dvpos
)
6597 int delta
= it2
.vpos
+ dvpos
;
6599 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6600 /* Move back again if we got too far ahead. */
6601 if (IT_CHARPOS (*it
) >= start_charpos
)
6607 /* Return 1 if IT points into the middle of a display vector. */
6610 in_display_vector_p (it
)
6613 return (it
->method
== GET_FROM_DISPLAY_VECTOR
6614 && it
->current
.dpvec_index
> 0
6615 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6619 /***********************************************************************
6621 ***********************************************************************/
6624 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6628 add_to_log (format
, arg1
, arg2
)
6630 Lisp_Object arg1
, arg2
;
6632 Lisp_Object args
[3];
6633 Lisp_Object msg
, fmt
;
6636 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6639 /* Do nothing if called asynchronously. Inserting text into
6640 a buffer may call after-change-functions and alike and
6641 that would means running Lisp asynchronously. */
6642 if (handling_signal
)
6646 GCPRO4 (fmt
, msg
, arg1
, arg2
);
6648 args
[0] = fmt
= build_string (format
);
6651 msg
= Fformat (3, args
);
6653 len
= SBYTES (msg
) + 1;
6654 SAFE_ALLOCA (buffer
, char *, len
);
6655 bcopy (SDATA (msg
), buffer
, len
);
6657 message_dolog (buffer
, len
- 1, 1, 0);
6664 /* Output a newline in the *Messages* buffer if "needs" one. */
6667 message_log_maybe_newline ()
6669 if (message_log_need_newline
)
6670 message_dolog ("", 0, 1, 0);
6674 /* Add a string M of length NBYTES to the message log, optionally
6675 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
6676 nonzero, means interpret the contents of M as multibyte. This
6677 function calls low-level routines in order to bypass text property
6678 hooks, etc. which might not be safe to run. */
6681 message_dolog (m
, nbytes
, nlflag
, multibyte
)
6683 int nbytes
, nlflag
, multibyte
;
6685 if (!NILP (Vmemory_full
))
6688 if (!NILP (Vmessage_log_max
))
6690 struct buffer
*oldbuf
;
6691 Lisp_Object oldpoint
, oldbegv
, oldzv
;
6692 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6693 int point_at_end
= 0;
6695 Lisp_Object old_deactivate_mark
, tem
;
6696 struct gcpro gcpro1
;
6698 old_deactivate_mark
= Vdeactivate_mark
;
6699 oldbuf
= current_buffer
;
6700 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
6701 current_buffer
->undo_list
= Qt
;
6703 oldpoint
= message_dolog_marker1
;
6704 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
6705 oldbegv
= message_dolog_marker2
;
6706 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
6707 oldzv
= message_dolog_marker3
;
6708 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
6709 GCPRO1 (old_deactivate_mark
);
6717 BEGV_BYTE
= BEG_BYTE
;
6720 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6722 /* Insert the string--maybe converting multibyte to single byte
6723 or vice versa, so that all the text fits the buffer. */
6725 && NILP (current_buffer
->enable_multibyte_characters
))
6727 int i
, c
, char_bytes
;
6728 unsigned char work
[1];
6730 /* Convert a multibyte string to single-byte
6731 for the *Message* buffer. */
6732 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
6734 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
6735 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6737 : multibyte_char_to_unibyte (c
, Qnil
));
6738 insert_1_both (work
, 1, 1, 1, 0, 0);
6741 else if (! multibyte
6742 && ! NILP (current_buffer
->enable_multibyte_characters
))
6744 int i
, c
, char_bytes
;
6745 unsigned char *msg
= (unsigned char *) m
;
6746 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6747 /* Convert a single-byte string to multibyte
6748 for the *Message* buffer. */
6749 for (i
= 0; i
< nbytes
; i
++)
6751 c
= unibyte_char_to_multibyte (msg
[i
]);
6752 char_bytes
= CHAR_STRING (c
, str
);
6753 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
6757 insert_1 (m
, nbytes
, 1, 0, 0);
6761 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
6762 insert_1 ("\n", 1, 1, 0, 0);
6764 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6766 this_bol_byte
= PT_BYTE
;
6768 /* See if this line duplicates the previous one.
6769 If so, combine duplicates. */
6772 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6774 prev_bol_byte
= PT_BYTE
;
6776 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
6777 this_bol
, this_bol_byte
);
6780 del_range_both (prev_bol
, prev_bol_byte
,
6781 this_bol
, this_bol_byte
, 0);
6787 /* If you change this format, don't forget to also
6788 change message_log_check_duplicate. */
6789 sprintf (dupstr
, " [%d times]", dup
);
6790 duplen
= strlen (dupstr
);
6791 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
6792 insert_1 (dupstr
, duplen
, 1, 0, 1);
6797 /* If we have more than the desired maximum number of lines
6798 in the *Messages* buffer now, delete the oldest ones.
6799 This is safe because we don't have undo in this buffer. */
6801 if (NATNUMP (Vmessage_log_max
))
6803 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
6804 -XFASTINT (Vmessage_log_max
) - 1, 0);
6805 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
6808 BEGV
= XMARKER (oldbegv
)->charpos
;
6809 BEGV_BYTE
= marker_byte_position (oldbegv
);
6818 ZV
= XMARKER (oldzv
)->charpos
;
6819 ZV_BYTE
= marker_byte_position (oldzv
);
6823 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6825 /* We can't do Fgoto_char (oldpoint) because it will run some
6827 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
6828 XMARKER (oldpoint
)->bytepos
);
6831 unchain_marker (XMARKER (oldpoint
));
6832 unchain_marker (XMARKER (oldbegv
));
6833 unchain_marker (XMARKER (oldzv
));
6835 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
6836 set_buffer_internal (oldbuf
);
6838 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6839 message_log_need_newline
= !nlflag
;
6840 Vdeactivate_mark
= old_deactivate_mark
;
6845 /* We are at the end of the buffer after just having inserted a newline.
6846 (Note: We depend on the fact we won't be crossing the gap.)
6847 Check to see if the most recent message looks a lot like the previous one.
6848 Return 0 if different, 1 if the new one should just replace it, or a
6849 value N > 1 if we should also append " [N times]". */
6852 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
6853 int prev_bol
, this_bol
;
6854 int prev_bol_byte
, this_bol_byte
;
6857 int len
= Z_BYTE
- 1 - this_bol_byte
;
6859 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
6860 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
6862 for (i
= 0; i
< len
; i
++)
6864 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
6872 if (*p1
++ == ' ' && *p1
++ == '[')
6875 while (*p1
>= '0' && *p1
<= '9')
6876 n
= n
* 10 + *p1
++ - '0';
6877 if (strncmp (p1
, " times]\n", 8) == 0)
6884 /* Display an echo area message M with a specified length of NBYTES
6885 bytes. The string may include null characters. If M is 0, clear
6886 out any existing message, and let the mini-buffer text show
6889 The buffer M must continue to exist until after the echo area gets
6890 cleared or some other message gets displayed there. This means do
6891 not pass text that is stored in a Lisp string; do not pass text in
6892 a buffer that was alloca'd. */
6895 message2 (m
, nbytes
, multibyte
)
6900 /* First flush out any partial line written with print. */
6901 message_log_maybe_newline ();
6903 message_dolog (m
, nbytes
, 1, multibyte
);
6904 message2_nolog (m
, nbytes
, multibyte
);
6908 /* The non-logging counterpart of message2. */
6911 message2_nolog (m
, nbytes
, multibyte
)
6913 int nbytes
, multibyte
;
6915 struct frame
*sf
= SELECTED_FRAME ();
6916 message_enable_multibyte
= multibyte
;
6920 if (noninteractive_need_newline
)
6921 putc ('\n', stderr
);
6922 noninteractive_need_newline
= 0;
6924 fwrite (m
, nbytes
, 1, stderr
);
6925 if (cursor_in_echo_area
== 0)
6926 fprintf (stderr
, "\n");
6929 /* A null message buffer means that the frame hasn't really been
6930 initialized yet. Error messages get reported properly by
6931 cmd_error, so this must be just an informative message; toss it. */
6932 else if (INTERACTIVE
6933 && sf
->glyphs_initialized_p
6934 && FRAME_MESSAGE_BUF (sf
))
6936 Lisp_Object mini_window
;
6939 /* Get the frame containing the mini-buffer
6940 that the selected frame is using. */
6941 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6942 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6944 FRAME_SAMPLE_VISIBILITY (f
);
6945 if (FRAME_VISIBLE_P (sf
)
6946 && ! FRAME_VISIBLE_P (f
))
6947 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
6951 set_message (m
, Qnil
, nbytes
, multibyte
);
6952 if (minibuffer_auto_raise
)
6953 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6956 clear_message (1, 1);
6958 do_pending_window_change (0);
6959 echo_area_display (1);
6960 do_pending_window_change (0);
6961 if (FRAME_DISPLAY (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6962 (*FRAME_DISPLAY (f
)->frame_up_to_date_hook
) (f
);
6967 /* Display an echo area message M with a specified length of NBYTES
6968 bytes. The string may include null characters. If M is not a
6969 string, clear out any existing message, and let the mini-buffer
6972 This function cancels echoing. */
6975 message3 (m
, nbytes
, multibyte
)
6980 struct gcpro gcpro1
;
6983 clear_message (1,1);
6986 /* First flush out any partial line written with print. */
6987 message_log_maybe_newline ();
6989 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
6990 message3_nolog (m
, nbytes
, multibyte
);
6996 /* The non-logging version of message3.
6997 This does not cancel echoing, because it is used for echoing.
6998 Perhaps we need to make a separate function for echoing
6999 and make this cancel echoing. */
7002 message3_nolog (m
, nbytes
, multibyte
)
7004 int nbytes
, multibyte
;
7006 struct frame
*sf
= SELECTED_FRAME ();
7007 message_enable_multibyte
= multibyte
;
7011 if (noninteractive_need_newline
)
7012 putc ('\n', stderr
);
7013 noninteractive_need_newline
= 0;
7015 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7016 if (cursor_in_echo_area
== 0)
7017 fprintf (stderr
, "\n");
7020 /* A null message buffer means that the frame hasn't really been
7021 initialized yet. Error messages get reported properly by
7022 cmd_error, so this must be just an informative message; toss it. */
7023 else if (INTERACTIVE
7024 && sf
->glyphs_initialized_p
7025 && FRAME_MESSAGE_BUF (sf
))
7027 Lisp_Object mini_window
;
7031 /* Get the frame containing the mini-buffer
7032 that the selected frame is using. */
7033 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7034 frame
= XWINDOW (mini_window
)->frame
;
7037 FRAME_SAMPLE_VISIBILITY (f
);
7038 if (FRAME_VISIBLE_P (sf
)
7039 && !FRAME_VISIBLE_P (f
))
7040 Fmake_frame_visible (frame
);
7042 if (STRINGP (m
) && SCHARS (m
) > 0)
7044 set_message (NULL
, m
, nbytes
, multibyte
);
7045 if (minibuffer_auto_raise
)
7046 Fraise_frame (frame
);
7049 clear_message (1, 1);
7051 do_pending_window_change (0);
7052 echo_area_display (1);
7053 do_pending_window_change (0);
7054 if (FRAME_DISPLAY (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7055 (*FRAME_DISPLAY (f
)->frame_up_to_date_hook
) (f
);
7060 /* Display a null-terminated echo area message M. If M is 0, clear
7061 out any existing message, and let the mini-buffer text show through.
7063 The buffer M must continue to exist until after the echo area gets
7064 cleared or some other message gets displayed there. Do not pass
7065 text that is stored in a Lisp string. Do not pass text in a buffer
7066 that was alloca'd. */
7072 message2 (m
, (m
? strlen (m
) : 0), 0);
7076 /* The non-logging counterpart of message1. */
7082 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7085 /* Display a message M which contains a single %s
7086 which gets replaced with STRING. */
7089 message_with_string (m
, string
, log
)
7094 CHECK_STRING (string
);
7100 if (noninteractive_need_newline
)
7101 putc ('\n', stderr
);
7102 noninteractive_need_newline
= 0;
7103 fprintf (stderr
, m
, SDATA (string
));
7104 if (cursor_in_echo_area
== 0)
7105 fprintf (stderr
, "\n");
7109 else if (INTERACTIVE
)
7111 /* The frame whose minibuffer we're going to display the message on.
7112 It may be larger than the selected frame, so we need
7113 to use its buffer, not the selected frame's buffer. */
7114 Lisp_Object mini_window
;
7115 struct frame
*f
, *sf
= SELECTED_FRAME ();
7117 /* Get the frame containing the minibuffer
7118 that the selected frame is using. */
7119 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7120 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7122 /* A null message buffer means that the frame hasn't really been
7123 initialized yet. Error messages get reported properly by
7124 cmd_error, so this must be just an informative message; toss it. */
7125 if (FRAME_MESSAGE_BUF (f
))
7127 Lisp_Object args
[2], message
;
7128 struct gcpro gcpro1
, gcpro2
;
7130 args
[0] = build_string (m
);
7131 args
[1] = message
= string
;
7132 GCPRO2 (args
[0], message
);
7135 message
= Fformat (2, args
);
7138 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7140 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7144 /* Print should start at the beginning of the message
7145 buffer next time. */
7146 message_buf_print
= 0;
7152 /* Dump an informative message to the minibuf. If M is 0, clear out
7153 any existing message, and let the mini-buffer text show through. */
7157 message (m
, a1
, a2
, a3
)
7159 EMACS_INT a1
, a2
, a3
;
7165 if (noninteractive_need_newline
)
7166 putc ('\n', stderr
);
7167 noninteractive_need_newline
= 0;
7168 fprintf (stderr
, m
, a1
, a2
, a3
);
7169 if (cursor_in_echo_area
== 0)
7170 fprintf (stderr
, "\n");
7174 else if (INTERACTIVE
)
7176 /* The frame whose mini-buffer we're going to display the message
7177 on. It may be larger than the selected frame, so we need to
7178 use its buffer, not the selected frame's buffer. */
7179 Lisp_Object mini_window
;
7180 struct frame
*f
, *sf
= SELECTED_FRAME ();
7182 /* Get the frame containing the mini-buffer
7183 that the selected frame is using. */
7184 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7185 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7187 /* A null message buffer means that the frame hasn't really been
7188 initialized yet. Error messages get reported properly by
7189 cmd_error, so this must be just an informative message; toss
7191 if (FRAME_MESSAGE_BUF (f
))
7202 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7203 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7205 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7206 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7208 #endif /* NO_ARG_ARRAY */
7210 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7215 /* Print should start at the beginning of the message
7216 buffer next time. */
7217 message_buf_print
= 0;
7223 /* The non-logging version of message. */
7226 message_nolog (m
, a1
, a2
, a3
)
7228 EMACS_INT a1
, a2
, a3
;
7230 Lisp_Object old_log_max
;
7231 old_log_max
= Vmessage_log_max
;
7232 Vmessage_log_max
= Qnil
;
7233 message (m
, a1
, a2
, a3
);
7234 Vmessage_log_max
= old_log_max
;
7238 /* Display the current message in the current mini-buffer. This is
7239 only called from error handlers in process.c, and is not time
7245 if (!NILP (echo_area_buffer
[0]))
7248 string
= Fcurrent_message ();
7249 message3 (string
, SBYTES (string
),
7250 !NILP (current_buffer
->enable_multibyte_characters
));
7255 /* Make sure echo area buffers in `echo_buffers' are live.
7256 If they aren't, make new ones. */
7259 ensure_echo_area_buffers ()
7263 for (i
= 0; i
< 2; ++i
)
7264 if (!BUFFERP (echo_buffer
[i
])
7265 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7268 Lisp_Object old_buffer
;
7271 old_buffer
= echo_buffer
[i
];
7272 sprintf (name
, " *Echo Area %d*", i
);
7273 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7274 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7276 for (j
= 0; j
< 2; ++j
)
7277 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7278 echo_area_buffer
[j
] = echo_buffer
[i
];
7283 /* Call FN with args A1..A4 with either the current or last displayed
7284 echo_area_buffer as current buffer.
7286 WHICH zero means use the current message buffer
7287 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7288 from echo_buffer[] and clear it.
7290 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7291 suitable buffer from echo_buffer[] and clear it.
7293 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
7294 that the current message becomes the last displayed one, make
7295 choose a suitable buffer for echo_area_buffer[0], and clear it.
7297 Value is what FN returns. */
7300 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7303 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7309 int this_one
, the_other
, clear_buffer_p
, rc
;
7310 int count
= SPECPDL_INDEX ();
7312 /* If buffers aren't live, make new ones. */
7313 ensure_echo_area_buffers ();
7318 this_one
= 0, the_other
= 1;
7320 this_one
= 1, the_other
= 0;
7323 this_one
= 0, the_other
= 1;
7326 /* We need a fresh one in case the current echo buffer equals
7327 the one containing the last displayed echo area message. */
7328 if (!NILP (echo_area_buffer
[this_one
])
7329 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
7330 echo_area_buffer
[this_one
] = Qnil
;
7333 /* Choose a suitable buffer from echo_buffer[] is we don't
7335 if (NILP (echo_area_buffer
[this_one
]))
7337 echo_area_buffer
[this_one
]
7338 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7339 ? echo_buffer
[the_other
]
7340 : echo_buffer
[this_one
]);
7344 buffer
= echo_area_buffer
[this_one
];
7346 /* Don't get confused by reusing the buffer used for echoing
7347 for a different purpose. */
7348 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7351 record_unwind_protect (unwind_with_echo_area_buffer
,
7352 with_echo_area_buffer_unwind_data (w
));
7354 /* Make the echo area buffer current. Note that for display
7355 purposes, it is not necessary that the displayed window's buffer
7356 == current_buffer, except for text property lookup. So, let's
7357 only set that buffer temporarily here without doing a full
7358 Fset_window_buffer. We must also change w->pointm, though,
7359 because otherwise an assertions in unshow_buffer fails, and Emacs
7361 set_buffer_internal_1 (XBUFFER (buffer
));
7365 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7368 current_buffer
->undo_list
= Qt
;
7369 current_buffer
->read_only
= Qnil
;
7370 specbind (Qinhibit_read_only
, Qt
);
7371 specbind (Qinhibit_modification_hooks
, Qt
);
7373 if (clear_buffer_p
&& Z
> BEG
)
7376 xassert (BEGV
>= BEG
);
7377 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7379 rc
= fn (a1
, a2
, a3
, a4
);
7381 xassert (BEGV
>= BEG
);
7382 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7384 unbind_to (count
, Qnil
);
7389 /* Save state that should be preserved around the call to the function
7390 FN called in with_echo_area_buffer. */
7393 with_echo_area_buffer_unwind_data (w
)
7399 /* Reduce consing by keeping one vector in
7400 Vwith_echo_area_save_vector. */
7401 vector
= Vwith_echo_area_save_vector
;
7402 Vwith_echo_area_save_vector
= Qnil
;
7405 vector
= Fmake_vector (make_number (7), Qnil
);
7407 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7408 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7409 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7413 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7414 AREF (vector
, i
) = w
->buffer
; ++i
;
7415 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7416 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7421 for (; i
< end
; ++i
)
7422 AREF (vector
, i
) = Qnil
;
7425 xassert (i
== ASIZE (vector
));
7430 /* Restore global state from VECTOR which was created by
7431 with_echo_area_buffer_unwind_data. */
7434 unwind_with_echo_area_buffer (vector
)
7437 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7438 Vdeactivate_mark
= AREF (vector
, 1);
7439 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7441 if (WINDOWP (AREF (vector
, 3)))
7444 Lisp_Object buffer
, charpos
, bytepos
;
7446 w
= XWINDOW (AREF (vector
, 3));
7447 buffer
= AREF (vector
, 4);
7448 charpos
= AREF (vector
, 5);
7449 bytepos
= AREF (vector
, 6);
7452 set_marker_both (w
->pointm
, buffer
,
7453 XFASTINT (charpos
), XFASTINT (bytepos
));
7456 Vwith_echo_area_save_vector
= vector
;
7461 /* Set up the echo area for use by print functions. MULTIBYTE_P
7462 non-zero means we will print multibyte. */
7465 setup_echo_area_for_printing (multibyte_p
)
7468 /* If we can't find an echo area any more, exit. */
7469 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7472 ensure_echo_area_buffers ();
7474 if (!message_buf_print
)
7476 /* A message has been output since the last time we printed.
7477 Choose a fresh echo area buffer. */
7478 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7479 echo_area_buffer
[0] = echo_buffer
[1];
7481 echo_area_buffer
[0] = echo_buffer
[0];
7483 /* Switch to that buffer and clear it. */
7484 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7485 current_buffer
->truncate_lines
= Qnil
;
7489 int count
= SPECPDL_INDEX ();
7490 specbind (Qinhibit_read_only
, Qt
);
7491 /* Note that undo recording is always disabled. */
7493 unbind_to (count
, Qnil
);
7495 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7497 /* Set up the buffer for the multibyteness we need. */
7499 != !NILP (current_buffer
->enable_multibyte_characters
))
7500 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7502 /* Raise the frame containing the echo area. */
7503 if (minibuffer_auto_raise
)
7505 struct frame
*sf
= SELECTED_FRAME ();
7506 Lisp_Object mini_window
;
7507 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7508 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7511 message_log_maybe_newline ();
7512 message_buf_print
= 1;
7516 if (NILP (echo_area_buffer
[0]))
7518 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7519 echo_area_buffer
[0] = echo_buffer
[1];
7521 echo_area_buffer
[0] = echo_buffer
[0];
7524 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7526 /* Someone switched buffers between print requests. */
7527 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7528 current_buffer
->truncate_lines
= Qnil
;
7534 /* Display an echo area message in window W. Value is non-zero if W's
7535 height is changed. If display_last_displayed_message_p is
7536 non-zero, display the message that was last displayed, otherwise
7537 display the current message. */
7540 display_echo_area (w
)
7543 int i
, no_message_p
, window_height_changed_p
, count
;
7545 /* Temporarily disable garbage collections while displaying the echo
7546 area. This is done because a GC can print a message itself.
7547 That message would modify the echo area buffer's contents while a
7548 redisplay of the buffer is going on, and seriously confuse
7550 count
= inhibit_garbage_collection ();
7552 /* If there is no message, we must call display_echo_area_1
7553 nevertheless because it resizes the window. But we will have to
7554 reset the echo_area_buffer in question to nil at the end because
7555 with_echo_area_buffer will sets it to an empty buffer. */
7556 i
= display_last_displayed_message_p
? 1 : 0;
7557 no_message_p
= NILP (echo_area_buffer
[i
]);
7559 window_height_changed_p
7560 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7561 display_echo_area_1
,
7562 (EMACS_INT
) w
, Qnil
, 0, 0);
7565 echo_area_buffer
[i
] = Qnil
;
7567 unbind_to (count
, Qnil
);
7568 return window_height_changed_p
;
7572 /* Helper for display_echo_area. Display the current buffer which
7573 contains the current echo area message in window W, a mini-window,
7574 a pointer to which is passed in A1. A2..A4 are currently not used.
7575 Change the height of W so that all of the message is displayed.
7576 Value is non-zero if height of W was changed. */
7579 display_echo_area_1 (a1
, a2
, a3
, a4
)
7584 struct window
*w
= (struct window
*) a1
;
7586 struct text_pos start
;
7587 int window_height_changed_p
= 0;
7589 /* Do this before displaying, so that we have a large enough glyph
7590 matrix for the display. */
7591 window_height_changed_p
= resize_mini_window (w
, 0);
7594 clear_glyph_matrix (w
->desired_matrix
);
7595 XSETWINDOW (window
, w
);
7596 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
7597 try_window (window
, start
, 0);
7599 return window_height_changed_p
;
7603 /* Resize the echo area window to exactly the size needed for the
7604 currently displayed message, if there is one. If a mini-buffer
7605 is active, don't shrink it. */
7608 resize_echo_area_exactly ()
7610 if (BUFFERP (echo_area_buffer
[0])
7611 && WINDOWP (echo_area_window
))
7613 struct window
*w
= XWINDOW (echo_area_window
);
7615 Lisp_Object resize_exactly
;
7617 if (minibuf_level
== 0)
7618 resize_exactly
= Qt
;
7620 resize_exactly
= Qnil
;
7622 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7623 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7626 ++windows_or_buffers_changed
;
7627 ++update_mode_lines
;
7628 redisplay_internal (0);
7634 /* Callback function for with_echo_area_buffer, when used from
7635 resize_echo_area_exactly. A1 contains a pointer to the window to
7636 resize, EXACTLY non-nil means resize the mini-window exactly to the
7637 size of the text displayed. A3 and A4 are not used. Value is what
7638 resize_mini_window returns. */
7641 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
7643 Lisp_Object exactly
;
7646 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
7650 /* Resize mini-window W to fit the size of its contents. EXACT:P
7651 means size the window exactly to the size needed. Otherwise, it's
7652 only enlarged until W's buffer is empty. Value is non-zero if
7653 the window height has been changed. */
7656 resize_mini_window (w
, exact_p
)
7660 struct frame
*f
= XFRAME (w
->frame
);
7661 int window_height_changed_p
= 0;
7663 xassert (MINI_WINDOW_P (w
));
7665 /* Don't resize windows while redisplaying a window; it would
7666 confuse redisplay functions when the size of the window they are
7667 displaying changes from under them. Such a resizing can happen,
7668 for instance, when which-func prints a long message while
7669 we are running fontification-functions. We're running these
7670 functions with safe_call which binds inhibit-redisplay to t. */
7671 if (!NILP (Vinhibit_redisplay
))
7674 /* Nil means don't try to resize. */
7675 if (NILP (Vresize_mini_windows
)
7676 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
7679 if (!FRAME_MINIBUF_ONLY_P (f
))
7682 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7683 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
7684 int height
, max_height
;
7685 int unit
= FRAME_LINE_HEIGHT (f
);
7686 struct text_pos start
;
7687 struct buffer
*old_current_buffer
= NULL
;
7689 if (current_buffer
!= XBUFFER (w
->buffer
))
7691 old_current_buffer
= current_buffer
;
7692 set_buffer_internal (XBUFFER (w
->buffer
));
7695 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
7697 /* Compute the max. number of lines specified by the user. */
7698 if (FLOATP (Vmax_mini_window_height
))
7699 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
7700 else if (INTEGERP (Vmax_mini_window_height
))
7701 max_height
= XINT (Vmax_mini_window_height
);
7703 max_height
= total_height
/ 4;
7705 /* Correct that max. height if it's bogus. */
7706 max_height
= max (1, max_height
);
7707 max_height
= min (total_height
, max_height
);
7709 /* Find out the height of the text in the window. */
7710 if (it
.truncate_lines_p
)
7715 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
7716 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
7717 height
= it
.current_y
+ last_height
;
7719 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
7720 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
7721 height
= (height
+ unit
- 1) / unit
;
7724 /* Compute a suitable window start. */
7725 if (height
> max_height
)
7727 height
= max_height
;
7728 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
7729 move_it_vertically_backward (&it
, (height
- 1) * unit
);
7730 start
= it
.current
.pos
;
7733 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
7734 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
7736 if (EQ (Vresize_mini_windows
, Qgrow_only
))
7738 /* Let it grow only, until we display an empty message, in which
7739 case the window shrinks again. */
7740 if (height
> WINDOW_TOTAL_LINES (w
))
7742 int old_height
= WINDOW_TOTAL_LINES (w
);
7743 freeze_window_starts (f
, 1);
7744 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7745 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7747 else if (height
< WINDOW_TOTAL_LINES (w
)
7748 && (exact_p
|| BEGV
== ZV
))
7750 int old_height
= WINDOW_TOTAL_LINES (w
);
7751 freeze_window_starts (f
, 0);
7752 shrink_mini_window (w
);
7753 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7758 /* Always resize to exact size needed. */
7759 if (height
> WINDOW_TOTAL_LINES (w
))
7761 int old_height
= WINDOW_TOTAL_LINES (w
);
7762 freeze_window_starts (f
, 1);
7763 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7764 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7766 else if (height
< WINDOW_TOTAL_LINES (w
))
7768 int old_height
= WINDOW_TOTAL_LINES (w
);
7769 freeze_window_starts (f
, 0);
7770 shrink_mini_window (w
);
7774 freeze_window_starts (f
, 1);
7775 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7778 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7782 if (old_current_buffer
)
7783 set_buffer_internal (old_current_buffer
);
7786 return window_height_changed_p
;
7790 /* Value is the current message, a string, or nil if there is no
7798 if (NILP (echo_area_buffer
[0]))
7802 with_echo_area_buffer (0, 0, current_message_1
,
7803 (EMACS_INT
) &msg
, Qnil
, 0, 0);
7805 echo_area_buffer
[0] = Qnil
;
7813 current_message_1 (a1
, a2
, a3
, a4
)
7818 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
7821 *msg
= make_buffer_string (BEG
, Z
, 1);
7828 /* Push the current message on Vmessage_stack for later restauration
7829 by restore_message. Value is non-zero if the current message isn't
7830 empty. This is a relatively infrequent operation, so it's not
7831 worth optimizing. */
7837 msg
= current_message ();
7838 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
7839 return STRINGP (msg
);
7843 /* Restore message display from the top of Vmessage_stack. */
7850 xassert (CONSP (Vmessage_stack
));
7851 msg
= XCAR (Vmessage_stack
);
7853 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
7855 message3_nolog (msg
, 0, 0);
7859 /* Handler for record_unwind_protect calling pop_message. */
7862 pop_message_unwind (dummy
)
7869 /* Pop the top-most entry off Vmessage_stack. */
7874 xassert (CONSP (Vmessage_stack
));
7875 Vmessage_stack
= XCDR (Vmessage_stack
);
7879 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
7880 exits. If the stack is not empty, we have a missing pop_message
7884 check_message_stack ()
7886 if (!NILP (Vmessage_stack
))
7891 /* Truncate to NCHARS what will be displayed in the echo area the next
7892 time we display it---but don't redisplay it now. */
7895 truncate_echo_area (nchars
)
7899 echo_area_buffer
[0] = Qnil
;
7900 /* A null message buffer means that the frame hasn't really been
7901 initialized yet. Error messages get reported properly by
7902 cmd_error, so this must be just an informative message; toss it. */
7903 else if (!noninteractive
7905 && !NILP (echo_area_buffer
[0]))
7907 struct frame
*sf
= SELECTED_FRAME ();
7908 if (FRAME_MESSAGE_BUF (sf
))
7909 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
7914 /* Helper function for truncate_echo_area. Truncate the current
7915 message to at most NCHARS characters. */
7918 truncate_message_1 (nchars
, a2
, a3
, a4
)
7923 if (BEG
+ nchars
< Z
)
7924 del_range (BEG
+ nchars
, Z
);
7926 echo_area_buffer
[0] = Qnil
;
7931 /* Set the current message to a substring of S or STRING.
7933 If STRING is a Lisp string, set the message to the first NBYTES
7934 bytes from STRING. NBYTES zero means use the whole string. If
7935 STRING is multibyte, the message will be displayed multibyte.
7937 If S is not null, set the message to the first LEN bytes of S. LEN
7938 zero means use the whole string. MULTIBYTE_P non-zero means S is
7939 multibyte. Display the message multibyte in that case. */
7942 set_message (s
, string
, nbytes
, multibyte_p
)
7945 int nbytes
, multibyte_p
;
7947 message_enable_multibyte
7948 = ((s
&& multibyte_p
)
7949 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
7951 with_echo_area_buffer (0, -1, set_message_1
,
7952 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
7953 message_buf_print
= 0;
7954 help_echo_showing_p
= 0;
7958 /* Helper function for set_message. Arguments have the same meaning
7959 as there, with A1 corresponding to S and A2 corresponding to STRING
7960 This function is called with the echo area buffer being
7964 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
7967 EMACS_INT nbytes
, multibyte_p
;
7969 const char *s
= (const char *) a1
;
7970 Lisp_Object string
= a2
;
7972 /* Change multibyteness of the echo buffer appropriately. */
7973 if (message_enable_multibyte
7974 != !NILP (current_buffer
->enable_multibyte_characters
))
7975 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
7977 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
7979 /* Insert new message at BEG. */
7980 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7982 if (STRINGP (string
))
7987 nbytes
= SBYTES (string
);
7988 nchars
= string_byte_to_char (string
, nbytes
);
7990 /* This function takes care of single/multibyte conversion. We
7991 just have to ensure that the echo area buffer has the right
7992 setting of enable_multibyte_characters. */
7993 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7998 nbytes
= strlen (s
);
8000 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8002 /* Convert from multi-byte to single-byte. */
8004 unsigned char work
[1];
8006 /* Convert a multibyte string to single-byte. */
8007 for (i
= 0; i
< nbytes
; i
+= n
)
8009 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8010 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
8012 : multibyte_char_to_unibyte (c
, Qnil
));
8013 insert_1_both (work
, 1, 1, 1, 0, 0);
8016 else if (!multibyte_p
8017 && !NILP (current_buffer
->enable_multibyte_characters
))
8019 /* Convert from single-byte to multi-byte. */
8021 const unsigned char *msg
= (const unsigned char *) s
;
8022 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8024 /* Convert a single-byte string to multibyte. */
8025 for (i
= 0; i
< nbytes
; i
++)
8027 c
= unibyte_char_to_multibyte (msg
[i
]);
8028 n
= CHAR_STRING (c
, str
);
8029 insert_1_both (str
, 1, n
, 1, 0, 0);
8033 insert_1 (s
, nbytes
, 1, 0, 0);
8040 /* Clear messages. CURRENT_P non-zero means clear the current
8041 message. LAST_DISPLAYED_P non-zero means clear the message
8045 clear_message (current_p
, last_displayed_p
)
8046 int current_p
, last_displayed_p
;
8050 echo_area_buffer
[0] = Qnil
;
8051 message_cleared_p
= 1;
8054 if (last_displayed_p
)
8055 echo_area_buffer
[1] = Qnil
;
8057 message_buf_print
= 0;
8060 /* Clear garbaged frames.
8062 This function is used where the old redisplay called
8063 redraw_garbaged_frames which in turn called redraw_frame which in
8064 turn called clear_frame. The call to clear_frame was a source of
8065 flickering. I believe a clear_frame is not necessary. It should
8066 suffice in the new redisplay to invalidate all current matrices,
8067 and ensure a complete redisplay of all windows. */
8070 clear_garbaged_frames ()
8074 Lisp_Object tail
, frame
;
8075 int changed_count
= 0;
8077 FOR_EACH_FRAME (tail
, frame
)
8079 struct frame
*f
= XFRAME (frame
);
8081 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8085 Fredraw_frame (frame
);
8086 f
->force_flush_display_p
= 1;
8088 clear_current_matrices (f
);
8097 ++windows_or_buffers_changed
;
8102 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8103 is non-zero update selected_frame. Value is non-zero if the
8104 mini-windows height has been changed. */
8107 echo_area_display (update_frame_p
)
8110 Lisp_Object mini_window
;
8113 int window_height_changed_p
= 0;
8114 struct frame
*sf
= SELECTED_FRAME ();
8116 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8117 w
= XWINDOW (mini_window
);
8118 f
= XFRAME (WINDOW_FRAME (w
));
8120 /* Don't display if frame is invisible or not yet initialized. */
8121 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8124 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8126 #ifdef HAVE_WINDOW_SYSTEM
8127 /* When Emacs starts, selected_frame may be the initial terminal
8128 frame. If we let this through, a message would be displayed on
8130 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
8132 #endif /* HAVE_WINDOW_SYSTEM */
8135 /* Redraw garbaged frames. */
8137 clear_garbaged_frames ();
8139 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8141 echo_area_window
= mini_window
;
8142 window_height_changed_p
= display_echo_area (w
);
8143 w
->must_be_updated_p
= 1;
8145 /* Update the display, unless called from redisplay_internal.
8146 Also don't update the screen during redisplay itself. The
8147 update will happen at the end of redisplay, and an update
8148 here could cause confusion. */
8149 if (update_frame_p
&& !redisplaying_p
)
8153 /* If the display update has been interrupted by pending
8154 input, update mode lines in the frame. Due to the
8155 pending input, it might have been that redisplay hasn't
8156 been called, so that mode lines above the echo area are
8157 garbaged. This looks odd, so we prevent it here. */
8158 if (!display_completed
)
8159 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8161 if (window_height_changed_p
8162 /* Don't do this if Emacs is shutting down. Redisplay
8163 needs to run hooks. */
8164 && !NILP (Vrun_hooks
))
8166 /* Must update other windows. Likewise as in other
8167 cases, don't let this update be interrupted by
8169 int count
= SPECPDL_INDEX ();
8170 specbind (Qredisplay_dont_pause
, Qt
);
8171 windows_or_buffers_changed
= 1;
8172 redisplay_internal (0);
8173 unbind_to (count
, Qnil
);
8175 else if (FRAME_WINDOW_P (f
) && n
== 0)
8177 /* Window configuration is the same as before.
8178 Can do with a display update of the echo area,
8179 unless we displayed some mode lines. */
8180 update_single_window (w
, 1);
8181 FRAME_RIF (f
)->flush_display (f
);
8184 update_frame (f
, 1, 1);
8186 /* If cursor is in the echo area, make sure that the next
8187 redisplay displays the minibuffer, so that the cursor will
8188 be replaced with what the minibuffer wants. */
8189 if (cursor_in_echo_area
)
8190 ++windows_or_buffers_changed
;
8193 else if (!EQ (mini_window
, selected_window
))
8194 windows_or_buffers_changed
++;
8196 /* Last displayed message is now the current message. */
8197 echo_area_buffer
[1] = echo_area_buffer
[0];
8198 /* Inform read_char that we're not echoing. */
8199 echo_message_buffer
= Qnil
;
8201 /* Prevent redisplay optimization in redisplay_internal by resetting
8202 this_line_start_pos. This is done because the mini-buffer now
8203 displays the message instead of its buffer text. */
8204 if (EQ (mini_window
, selected_window
))
8205 CHARPOS (this_line_start_pos
) = 0;
8207 return window_height_changed_p
;
8212 /***********************************************************************
8213 Mode Lines and Frame Titles
8214 ***********************************************************************/
8216 /* A buffer for constructing non-propertized mode-line strings and
8217 frame titles in it; allocated from the heap in init_xdisp and
8218 resized as needed in store_mode_line_noprop_char. */
8220 static char *mode_line_noprop_buf
;
8222 /* The buffer's end, and a current output position in it. */
8224 static char *mode_line_noprop_buf_end
;
8225 static char *mode_line_noprop_ptr
;
8227 #define MODE_LINE_NOPROP_LEN(start) \
8228 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8231 MODE_LINE_DISPLAY
= 0,
8237 /* Alist that caches the results of :propertize.
8238 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8239 static Lisp_Object mode_line_proptrans_alist
;
8241 /* List of strings making up the mode-line. */
8242 static Lisp_Object mode_line_string_list
;
8244 /* Base face property when building propertized mode line string. */
8245 static Lisp_Object mode_line_string_face
;
8246 static Lisp_Object mode_line_string_face_prop
;
8249 /* Unwind data for mode line strings */
8251 static Lisp_Object Vmode_line_unwind_vector
;
8254 format_mode_line_unwind_data (obuf
)
8255 struct buffer
*obuf
;
8259 /* Reduce consing by keeping one vector in
8260 Vwith_echo_area_save_vector. */
8261 vector
= Vmode_line_unwind_vector
;
8262 Vmode_line_unwind_vector
= Qnil
;
8265 vector
= Fmake_vector (make_number (7), Qnil
);
8267 AREF (vector
, 0) = make_number (mode_line_target
);
8268 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8269 AREF (vector
, 2) = mode_line_string_list
;
8270 AREF (vector
, 3) = mode_line_proptrans_alist
;
8271 AREF (vector
, 4) = mode_line_string_face
;
8272 AREF (vector
, 5) = mode_line_string_face_prop
;
8275 XSETBUFFER (AREF (vector
, 6), obuf
);
8277 AREF (vector
, 6) = Qnil
;
8283 unwind_format_mode_line (vector
)
8286 mode_line_target
= XINT (AREF (vector
, 0));
8287 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8288 mode_line_string_list
= AREF (vector
, 2);
8289 mode_line_proptrans_alist
= AREF (vector
, 3);
8290 mode_line_string_face
= AREF (vector
, 4);
8291 mode_line_string_face_prop
= AREF (vector
, 5);
8293 if (!NILP (AREF (vector
, 6)))
8295 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8296 AREF (vector
, 6) = Qnil
;
8299 Vmode_line_unwind_vector
= vector
;
8304 /* Store a single character C for the frame title in mode_line_noprop_buf.
8305 Re-allocate mode_line_noprop_buf if necessary. */
8309 store_mode_line_noprop_char (char c
)
8311 store_mode_line_noprop_char (c
)
8315 /* If output position has reached the end of the allocated buffer,
8316 double the buffer's size. */
8317 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8319 int len
= MODE_LINE_NOPROP_LEN (0);
8320 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8321 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8322 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8323 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8326 *mode_line_noprop_ptr
++ = c
;
8330 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8331 mode_line_noprop_ptr. STR is the string to store. Do not copy
8332 characters that yield more columns than PRECISION; PRECISION <= 0
8333 means copy the whole string. Pad with spaces until FIELD_WIDTH
8334 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8335 pad. Called from display_mode_element when it is used to build a
8339 store_mode_line_noprop (str
, field_width
, precision
)
8340 const unsigned char *str
;
8341 int field_width
, precision
;
8346 /* Copy at most PRECISION chars from STR. */
8347 nbytes
= strlen (str
);
8348 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8350 store_mode_line_noprop_char (*str
++);
8352 /* Fill up with spaces until FIELD_WIDTH reached. */
8353 while (field_width
> 0
8356 store_mode_line_noprop_char (' ');
8363 /***********************************************************************
8365 ***********************************************************************/
8367 #ifdef HAVE_WINDOW_SYSTEM
8369 /* Set the title of FRAME, if it has changed. The title format is
8370 Vicon_title_format if FRAME is iconified, otherwise it is
8371 frame_title_format. */
8374 x_consider_frame_title (frame
)
8377 struct frame
*f
= XFRAME (frame
);
8379 if (FRAME_WINDOW_P (f
)
8380 || FRAME_MINIBUF_ONLY_P (f
)
8381 || f
->explicit_name
)
8383 /* Do we have more than one visible frame on this X display? */
8390 int count
= SPECPDL_INDEX ();
8392 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8394 Lisp_Object other_frame
= XCAR (tail
);
8395 struct frame
*tf
= XFRAME (other_frame
);
8398 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8399 && !FRAME_MINIBUF_ONLY_P (tf
)
8400 && !EQ (other_frame
, tip_frame
)
8401 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8405 /* Set global variable indicating that multiple frames exist. */
8406 multiple_frames
= CONSP (tail
);
8408 /* Switch to the buffer of selected window of the frame. Set up
8409 mode_line_target so that display_mode_element will output into
8410 mode_line_noprop_buf; then display the title. */
8411 record_unwind_protect (unwind_format_mode_line
,
8412 format_mode_line_unwind_data (current_buffer
));
8414 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8415 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8417 mode_line_target
= MODE_LINE_TITLE
;
8418 title_start
= MODE_LINE_NOPROP_LEN (0);
8419 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8420 NULL
, DEFAULT_FACE_ID
);
8421 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8422 len
= MODE_LINE_NOPROP_LEN (title_start
);
8423 title
= mode_line_noprop_buf
+ title_start
;
8424 unbind_to (count
, Qnil
);
8426 /* Set the title only if it's changed. This avoids consing in
8427 the common case where it hasn't. (If it turns out that we've
8428 already wasted too much time by walking through the list with
8429 display_mode_element, then we might need to optimize at a
8430 higher level than this.) */
8431 if (! STRINGP (f
->name
)
8432 || SBYTES (f
->name
) != len
8433 || bcmp (title
, SDATA (f
->name
), len
) != 0)
8434 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
8438 #endif /* not HAVE_WINDOW_SYSTEM */
8443 /***********************************************************************
8445 ***********************************************************************/
8448 /* Prepare for redisplay by updating menu-bar item lists when
8449 appropriate. This can call eval. */
8452 prepare_menu_bars ()
8455 struct gcpro gcpro1
, gcpro2
;
8457 Lisp_Object tooltip_frame
;
8459 #ifdef HAVE_WINDOW_SYSTEM
8460 tooltip_frame
= tip_frame
;
8462 tooltip_frame
= Qnil
;
8465 /* Update all frame titles based on their buffer names, etc. We do
8466 this before the menu bars so that the buffer-menu will show the
8467 up-to-date frame titles. */
8468 #ifdef HAVE_WINDOW_SYSTEM
8469 if (windows_or_buffers_changed
|| update_mode_lines
)
8471 Lisp_Object tail
, frame
;
8473 FOR_EACH_FRAME (tail
, frame
)
8476 if (!EQ (frame
, tooltip_frame
)
8477 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8478 x_consider_frame_title (frame
);
8481 #endif /* HAVE_WINDOW_SYSTEM */
8483 /* Update the menu bar item lists, if appropriate. This has to be
8484 done before any actual redisplay or generation of display lines. */
8485 all_windows
= (update_mode_lines
8486 || buffer_shared
> 1
8487 || windows_or_buffers_changed
);
8490 Lisp_Object tail
, frame
;
8491 int count
= SPECPDL_INDEX ();
8493 record_unwind_save_match_data ();
8495 FOR_EACH_FRAME (tail
, frame
)
8499 /* Ignore tooltip frame. */
8500 if (EQ (frame
, tooltip_frame
))
8503 /* If a window on this frame changed size, report that to
8504 the user and clear the size-change flag. */
8505 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8507 Lisp_Object functions
;
8509 /* Clear flag first in case we get an error below. */
8510 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8511 functions
= Vwindow_size_change_functions
;
8512 GCPRO2 (tail
, functions
);
8514 while (CONSP (functions
))
8516 call1 (XCAR (functions
), frame
);
8517 functions
= XCDR (functions
);
8523 update_menu_bar (f
, 0);
8524 #ifdef HAVE_WINDOW_SYSTEM
8525 update_tool_bar (f
, 0);
8530 unbind_to (count
, Qnil
);
8534 struct frame
*sf
= SELECTED_FRAME ();
8535 update_menu_bar (sf
, 1);
8536 #ifdef HAVE_WINDOW_SYSTEM
8537 update_tool_bar (sf
, 1);
8541 /* Motif needs this. See comment in xmenu.c. Turn it off when
8542 pending_menu_activation is not defined. */
8543 #ifdef USE_X_TOOLKIT
8544 pending_menu_activation
= 0;
8549 /* Update the menu bar item list for frame F. This has to be done
8550 before we start to fill in any display lines, because it can call
8553 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8556 update_menu_bar (f
, save_match_data
)
8558 int save_match_data
;
8561 register struct window
*w
;
8563 /* If called recursively during a menu update, do nothing. This can
8564 happen when, for instance, an activate-menubar-hook causes a
8566 if (inhibit_menubar_update
)
8569 window
= FRAME_SELECTED_WINDOW (f
);
8570 w
= XWINDOW (window
);
8572 #if 0 /* The if statement below this if statement used to include the
8573 condition !NILP (w->update_mode_line), rather than using
8574 update_mode_lines directly, and this if statement may have
8575 been added to make that condition work. Now the if
8576 statement below matches its comment, this isn't needed. */
8577 if (update_mode_lines
)
8578 w
->update_mode_line
= Qt
;
8581 if (FRAME_WINDOW_P (f
)
8583 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8584 || defined (USE_GTK)
8585 FRAME_EXTERNAL_MENU_BAR (f
)
8587 FRAME_MENU_BAR_LINES (f
) > 0
8589 : FRAME_MENU_BAR_LINES (f
) > 0)
8591 /* If the user has switched buffers or windows, we need to
8592 recompute to reflect the new bindings. But we'll
8593 recompute when update_mode_lines is set too; that means
8594 that people can use force-mode-line-update to request
8595 that the menu bar be recomputed. The adverse effect on
8596 the rest of the redisplay algorithm is about the same as
8597 windows_or_buffers_changed anyway. */
8598 if (windows_or_buffers_changed
8599 /* This used to test w->update_mode_line, but we believe
8600 there is no need to recompute the menu in that case. */
8601 || update_mode_lines
8602 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8603 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8604 != !NILP (w
->last_had_star
))
8605 || ((!NILP (Vtransient_mark_mode
)
8606 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8607 != !NILP (w
->region_showing
)))
8609 struct buffer
*prev
= current_buffer
;
8610 int count
= SPECPDL_INDEX ();
8612 specbind (Qinhibit_menubar_update
, Qt
);
8614 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8615 if (save_match_data
)
8616 record_unwind_save_match_data ();
8617 if (NILP (Voverriding_local_map_menu_flag
))
8619 specbind (Qoverriding_terminal_local_map
, Qnil
);
8620 specbind (Qoverriding_local_map
, Qnil
);
8623 /* Run the Lucid hook. */
8624 safe_run_hooks (Qactivate_menubar_hook
);
8626 /* If it has changed current-menubar from previous value,
8627 really recompute the menu-bar from the value. */
8628 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8629 call0 (Qrecompute_lucid_menubar
);
8631 safe_run_hooks (Qmenu_bar_update_hook
);
8632 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
8634 /* Redisplay the menu bar in case we changed it. */
8635 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8636 || defined (USE_GTK)
8637 if (FRAME_WINDOW_P (f
)
8638 #if defined (MAC_OS)
8639 /* All frames on Mac OS share the same menubar. So only the
8640 selected frame should be allowed to set it. */
8641 && f
== SELECTED_FRAME ()
8644 set_frame_menubar (f
, 0, 0);
8646 /* On a terminal screen, the menu bar is an ordinary screen
8647 line, and this makes it get updated. */
8648 w
->update_mode_line
= Qt
;
8649 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8650 /* In the non-toolkit version, the menu bar is an ordinary screen
8651 line, and this makes it get updated. */
8652 w
->update_mode_line
= Qt
;
8653 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8655 unbind_to (count
, Qnil
);
8656 set_buffer_internal_1 (prev
);
8663 /***********************************************************************
8665 ***********************************************************************/
8667 #ifdef HAVE_WINDOW_SYSTEM
8670 Nominal cursor position -- where to draw output.
8671 HPOS and VPOS are window relative glyph matrix coordinates.
8672 X and Y are window relative pixel coordinates. */
8674 struct cursor_pos output_cursor
;
8678 Set the global variable output_cursor to CURSOR. All cursor
8679 positions are relative to updated_window. */
8682 set_output_cursor (cursor
)
8683 struct cursor_pos
*cursor
;
8685 output_cursor
.hpos
= cursor
->hpos
;
8686 output_cursor
.vpos
= cursor
->vpos
;
8687 output_cursor
.x
= cursor
->x
;
8688 output_cursor
.y
= cursor
->y
;
8693 Set a nominal cursor position.
8695 HPOS and VPOS are column/row positions in a window glyph matrix. X
8696 and Y are window text area relative pixel positions.
8698 If this is done during an update, updated_window will contain the
8699 window that is being updated and the position is the future output
8700 cursor position for that window. If updated_window is null, use
8701 selected_window and display the cursor at the given position. */
8704 x_cursor_to (vpos
, hpos
, y
, x
)
8705 int vpos
, hpos
, y
, x
;
8709 /* If updated_window is not set, work on selected_window. */
8713 w
= XWINDOW (selected_window
);
8715 /* Set the output cursor. */
8716 output_cursor
.hpos
= hpos
;
8717 output_cursor
.vpos
= vpos
;
8718 output_cursor
.x
= x
;
8719 output_cursor
.y
= y
;
8721 /* If not called as part of an update, really display the cursor.
8722 This will also set the cursor position of W. */
8723 if (updated_window
== NULL
)
8726 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8727 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
8728 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
8733 #endif /* HAVE_WINDOW_SYSTEM */
8736 /***********************************************************************
8738 ***********************************************************************/
8740 #ifdef HAVE_WINDOW_SYSTEM
8742 /* Where the mouse was last time we reported a mouse event. */
8744 FRAME_PTR last_mouse_frame
;
8746 /* Tool-bar item index of the item on which a mouse button was pressed
8749 int last_tool_bar_item
;
8752 /* Update the tool-bar item list for frame F. This has to be done
8753 before we start to fill in any display lines. Called from
8754 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8755 and restore it here. */
8758 update_tool_bar (f
, save_match_data
)
8760 int save_match_data
;
8763 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
8765 int do_update
= WINDOWP (f
->tool_bar_window
)
8766 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
8774 window
= FRAME_SELECTED_WINDOW (f
);
8775 w
= XWINDOW (window
);
8777 /* If the user has switched buffers or windows, we need to
8778 recompute to reflect the new bindings. But we'll
8779 recompute when update_mode_lines is set too; that means
8780 that people can use force-mode-line-update to request
8781 that the menu bar be recomputed. The adverse effect on
8782 the rest of the redisplay algorithm is about the same as
8783 windows_or_buffers_changed anyway. */
8784 if (windows_or_buffers_changed
8785 || !NILP (w
->update_mode_line
)
8786 || update_mode_lines
8787 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8788 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8789 != !NILP (w
->last_had_star
))
8790 || ((!NILP (Vtransient_mark_mode
)
8791 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8792 != !NILP (w
->region_showing
)))
8794 struct buffer
*prev
= current_buffer
;
8795 int count
= SPECPDL_INDEX ();
8796 Lisp_Object new_tool_bar
;
8798 struct gcpro gcpro1
;
8800 /* Set current_buffer to the buffer of the selected
8801 window of the frame, so that we get the right local
8803 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8805 /* Save match data, if we must. */
8806 if (save_match_data
)
8807 record_unwind_save_match_data ();
8809 /* Make sure that we don't accidentally use bogus keymaps. */
8810 if (NILP (Voverriding_local_map_menu_flag
))
8812 specbind (Qoverriding_terminal_local_map
, Qnil
);
8813 specbind (Qoverriding_local_map
, Qnil
);
8816 GCPRO1 (new_tool_bar
);
8818 /* Build desired tool-bar items from keymaps. */
8819 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
8822 /* Redisplay the tool-bar if we changed it. */
8823 if (NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
8825 /* Redisplay that happens asynchronously due to an expose event
8826 may access f->tool_bar_items. Make sure we update both
8827 variables within BLOCK_INPUT so no such event interrupts. */
8829 f
->tool_bar_items
= new_tool_bar
;
8830 f
->n_tool_bar_items
= new_n_tool_bar
;
8831 w
->update_mode_line
= Qt
;
8837 unbind_to (count
, Qnil
);
8838 set_buffer_internal_1 (prev
);
8844 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8845 F's desired tool-bar contents. F->tool_bar_items must have
8846 been set up previously by calling prepare_menu_bars. */
8849 build_desired_tool_bar_string (f
)
8852 int i
, size
, size_needed
;
8853 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8854 Lisp_Object image
, plist
, props
;
8856 image
= plist
= props
= Qnil
;
8857 GCPRO3 (image
, plist
, props
);
8859 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
8860 Otherwise, make a new string. */
8862 /* The size of the string we might be able to reuse. */
8863 size
= (STRINGP (f
->desired_tool_bar_string
)
8864 ? SCHARS (f
->desired_tool_bar_string
)
8867 /* We need one space in the string for each image. */
8868 size_needed
= f
->n_tool_bar_items
;
8870 /* Reuse f->desired_tool_bar_string, if possible. */
8871 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
8872 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
8876 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
8877 Fremove_text_properties (make_number (0), make_number (size
),
8878 props
, f
->desired_tool_bar_string
);
8881 /* Put a `display' property on the string for the images to display,
8882 put a `menu_item' property on tool-bar items with a value that
8883 is the index of the item in F's tool-bar item vector. */
8884 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
8886 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
8888 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8889 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8890 int hmargin
, vmargin
, relief
, idx
, end
;
8891 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
8893 /* If image is a vector, choose the image according to the
8895 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
8896 if (VECTORP (image
))
8900 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
8901 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
8904 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
8905 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
8907 xassert (ASIZE (image
) >= idx
);
8908 image
= AREF (image
, idx
);
8913 /* Ignore invalid image specifications. */
8914 if (!valid_image_p (image
))
8917 /* Display the tool-bar button pressed, or depressed. */
8918 plist
= Fcopy_sequence (XCDR (image
));
8920 /* Compute margin and relief to draw. */
8921 relief
= (tool_bar_button_relief
>= 0
8922 ? tool_bar_button_relief
8923 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
8924 hmargin
= vmargin
= relief
;
8926 if (INTEGERP (Vtool_bar_button_margin
)
8927 && XINT (Vtool_bar_button_margin
) > 0)
8929 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
8930 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
8932 else if (CONSP (Vtool_bar_button_margin
))
8934 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
8935 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
8936 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
8938 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
8939 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
8940 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
8943 if (auto_raise_tool_bar_buttons_p
)
8945 /* Add a `:relief' property to the image spec if the item is
8949 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
8956 /* If image is selected, display it pressed, i.e. with a
8957 negative relief. If it's not selected, display it with a
8959 plist
= Fplist_put (plist
, QCrelief
,
8961 ? make_number (-relief
)
8962 : make_number (relief
)));
8967 /* Put a margin around the image. */
8968 if (hmargin
|| vmargin
)
8970 if (hmargin
== vmargin
)
8971 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
8973 plist
= Fplist_put (plist
, QCmargin
,
8974 Fcons (make_number (hmargin
),
8975 make_number (vmargin
)));
8978 /* If button is not enabled, and we don't have special images
8979 for the disabled state, make the image appear disabled by
8980 applying an appropriate algorithm to it. */
8981 if (!enabled_p
&& idx
< 0)
8982 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
8984 /* Put a `display' text property on the string for the image to
8985 display. Put a `menu-item' property on the string that gives
8986 the start of this item's properties in the tool-bar items
8988 image
= Fcons (Qimage
, plist
);
8989 props
= list4 (Qdisplay
, image
,
8990 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
8992 /* Let the last image hide all remaining spaces in the tool bar
8993 string. The string can be longer than needed when we reuse a
8995 if (i
+ 1 == f
->n_tool_bar_items
)
8996 end
= SCHARS (f
->desired_tool_bar_string
);
8999 Fadd_text_properties (make_number (i
), make_number (end
),
9000 props
, f
->desired_tool_bar_string
);
9008 /* Display one line of the tool-bar of frame IT->f. */
9011 display_tool_bar_line (it
)
9014 struct glyph_row
*row
= it
->glyph_row
;
9015 int max_x
= it
->last_visible_x
;
9018 prepare_desired_row (row
);
9019 row
->y
= it
->current_y
;
9021 /* Note that this isn't made use of if the face hasn't a box,
9022 so there's no need to check the face here. */
9023 it
->start_of_box_run_p
= 1;
9025 while (it
->current_x
< max_x
)
9027 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
9029 /* Get the next display element. */
9030 if (!get_next_display_element (it
))
9033 /* Produce glyphs. */
9034 x_before
= it
->current_x
;
9035 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
9036 PRODUCE_GLYPHS (it
);
9038 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
9043 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9045 if (x
+ glyph
->pixel_width
> max_x
)
9047 /* Glyph doesn't fit on line. */
9048 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
9054 x
+= glyph
->pixel_width
;
9058 /* Stop at line ends. */
9059 if (ITERATOR_AT_END_OF_LINE_P (it
))
9062 set_iterator_to_next (it
, 1);
9067 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9068 extend_face_to_end_of_line (it
);
9069 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9070 last
->right_box_line_p
= 1;
9071 if (last
== row
->glyphs
[TEXT_AREA
])
9072 last
->left_box_line_p
= 1;
9073 compute_line_metrics (it
);
9075 /* If line is empty, make it occupy the rest of the tool-bar. */
9076 if (!row
->displays_text_p
)
9078 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9079 row
->ascent
= row
->phys_ascent
= 0;
9080 row
->extra_line_spacing
= 0;
9083 row
->full_width_p
= 1;
9084 row
->continued_p
= 0;
9085 row
->truncated_on_left_p
= 0;
9086 row
->truncated_on_right_p
= 0;
9088 it
->current_x
= it
->hpos
= 0;
9089 it
->current_y
+= row
->height
;
9095 /* Value is the number of screen lines needed to make all tool-bar
9096 items of frame F visible. */
9099 tool_bar_lines_needed (f
)
9102 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9105 /* Initialize an iterator for iteration over
9106 F->desired_tool_bar_string in the tool-bar window of frame F. */
9107 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9108 it
.first_visible_x
= 0;
9109 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9110 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9112 while (!ITERATOR_AT_END_P (&it
))
9114 it
.glyph_row
= w
->desired_matrix
->rows
;
9115 clear_glyph_row (it
.glyph_row
);
9116 display_tool_bar_line (&it
);
9119 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9123 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9125 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9134 frame
= selected_frame
;
9136 CHECK_FRAME (frame
);
9139 if (WINDOWP (f
->tool_bar_window
)
9140 || (w
= XWINDOW (f
->tool_bar_window
),
9141 WINDOW_TOTAL_LINES (w
) > 0))
9143 update_tool_bar (f
, 1);
9144 if (f
->n_tool_bar_items
)
9146 build_desired_tool_bar_string (f
);
9147 nlines
= tool_bar_lines_needed (f
);
9151 return make_number (nlines
);
9155 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9156 height should be changed. */
9159 redisplay_tool_bar (f
)
9164 struct glyph_row
*row
;
9165 int change_height_p
= 0;
9168 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9169 update_frame_tool_bar (f
);
9173 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9174 do anything. This means you must start with tool-bar-lines
9175 non-zero to get the auto-sizing effect. Or in other words, you
9176 can turn off tool-bars by specifying tool-bar-lines zero. */
9177 if (!WINDOWP (f
->tool_bar_window
)
9178 || (w
= XWINDOW (f
->tool_bar_window
),
9179 WINDOW_TOTAL_LINES (w
) == 0))
9182 /* Set up an iterator for the tool-bar window. */
9183 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9184 it
.first_visible_x
= 0;
9185 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9188 /* Build a string that represents the contents of the tool-bar. */
9189 build_desired_tool_bar_string (f
);
9190 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9192 /* Display as many lines as needed to display all tool-bar items. */
9193 while (it
.current_y
< it
.last_visible_y
)
9194 display_tool_bar_line (&it
);
9196 /* It doesn't make much sense to try scrolling in the tool-bar
9197 window, so don't do it. */
9198 w
->desired_matrix
->no_scrolling_p
= 1;
9199 w
->must_be_updated_p
= 1;
9201 if (auto_resize_tool_bars_p
)
9205 /* If we couldn't display everything, change the tool-bar's
9207 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
9208 change_height_p
= 1;
9210 /* If there are blank lines at the end, except for a partially
9211 visible blank line at the end that is smaller than
9212 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9213 row
= it
.glyph_row
- 1;
9214 if (!row
->displays_text_p
9215 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9216 change_height_p
= 1;
9218 /* If row displays tool-bar items, but is partially visible,
9219 change the tool-bar's height. */
9220 if (row
->displays_text_p
9221 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
9222 change_height_p
= 1;
9224 /* Resize windows as needed by changing the `tool-bar-lines'
9227 && (nlines
= tool_bar_lines_needed (f
),
9228 nlines
!= WINDOW_TOTAL_LINES (w
)))
9230 extern Lisp_Object Qtool_bar_lines
;
9232 int old_height
= WINDOW_TOTAL_LINES (w
);
9234 XSETFRAME (frame
, f
);
9235 clear_glyph_matrix (w
->desired_matrix
);
9236 Fmodify_frame_parameters (frame
,
9237 Fcons (Fcons (Qtool_bar_lines
,
9238 make_number (nlines
)),
9240 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9241 fonts_changed_p
= 1;
9245 return change_height_p
;
9249 /* Get information about the tool-bar item which is displayed in GLYPH
9250 on frame F. Return in *PROP_IDX the index where tool-bar item
9251 properties start in F->tool_bar_items. Value is zero if
9252 GLYPH doesn't display a tool-bar item. */
9255 tool_bar_item_info (f
, glyph
, prop_idx
)
9257 struct glyph
*glyph
;
9264 /* This function can be called asynchronously, which means we must
9265 exclude any possibility that Fget_text_property signals an
9267 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
9268 charpos
= max (0, charpos
);
9270 /* Get the text property `menu-item' at pos. The value of that
9271 property is the start index of this item's properties in
9272 F->tool_bar_items. */
9273 prop
= Fget_text_property (make_number (charpos
),
9274 Qmenu_item
, f
->current_tool_bar_string
);
9275 if (INTEGERP (prop
))
9277 *prop_idx
= XINT (prop
);
9287 /* Get information about the tool-bar item at position X/Y on frame F.
9288 Return in *GLYPH a pointer to the glyph of the tool-bar item in
9289 the current matrix of the tool-bar window of F, or NULL if not
9290 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
9291 item in F->tool_bar_items. Value is
9293 -1 if X/Y is not on a tool-bar item
9294 0 if X/Y is on the same item that was highlighted before.
9298 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
9301 struct glyph
**glyph
;
9302 int *hpos
, *vpos
, *prop_idx
;
9304 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9305 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9308 /* Find the glyph under X/Y. */
9309 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
9313 /* Get the start of this tool-bar item's properties in
9314 f->tool_bar_items. */
9315 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
9318 /* Is mouse on the highlighted item? */
9319 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
9320 && *vpos
>= dpyinfo
->mouse_face_beg_row
9321 && *vpos
<= dpyinfo
->mouse_face_end_row
9322 && (*vpos
> dpyinfo
->mouse_face_beg_row
9323 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
9324 && (*vpos
< dpyinfo
->mouse_face_end_row
9325 || *hpos
< dpyinfo
->mouse_face_end_col
9326 || dpyinfo
->mouse_face_past_end
))
9334 Handle mouse button event on the tool-bar of frame F, at
9335 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
9336 0 for button release. MODIFIERS is event modifiers for button
9340 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
9343 unsigned int modifiers
;
9345 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9346 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9347 int hpos
, vpos
, prop_idx
;
9348 struct glyph
*glyph
;
9349 Lisp_Object enabled_p
;
9351 /* If not on the highlighted tool-bar item, return. */
9352 frame_to_window_pixel_xy (w
, &x
, &y
);
9353 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
9356 /* If item is disabled, do nothing. */
9357 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9358 if (NILP (enabled_p
))
9363 /* Show item in pressed state. */
9364 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
9365 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
9366 last_tool_bar_item
= prop_idx
;
9370 Lisp_Object key
, frame
;
9371 struct input_event event
;
9374 /* Show item in released state. */
9375 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
9376 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
9378 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
9380 XSETFRAME (frame
, f
);
9381 event
.kind
= TOOL_BAR_EVENT
;
9382 event
.frame_or_window
= frame
;
9384 kbd_buffer_store_event (&event
);
9386 event
.kind
= TOOL_BAR_EVENT
;
9387 event
.frame_or_window
= frame
;
9389 event
.modifiers
= modifiers
;
9390 kbd_buffer_store_event (&event
);
9391 last_tool_bar_item
= -1;
9396 /* Possibly highlight a tool-bar item on frame F when mouse moves to
9397 tool-bar window-relative coordinates X/Y. Called from
9398 note_mouse_highlight. */
9401 note_tool_bar_highlight (f
, x
, y
)
9405 Lisp_Object window
= f
->tool_bar_window
;
9406 struct window
*w
= XWINDOW (window
);
9407 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9409 struct glyph
*glyph
;
9410 struct glyph_row
*row
;
9412 Lisp_Object enabled_p
;
9414 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9415 int mouse_down_p
, rc
;
9417 /* Function note_mouse_highlight is called with negative x(y
9418 values when mouse moves outside of the frame. */
9419 if (x
<= 0 || y
<= 0)
9421 clear_mouse_face (dpyinfo
);
9425 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9428 /* Not on tool-bar item. */
9429 clear_mouse_face (dpyinfo
);
9433 /* On same tool-bar item as before. */
9436 clear_mouse_face (dpyinfo
);
9438 /* Mouse is down, but on different tool-bar item? */
9439 mouse_down_p
= (dpyinfo
->grabbed
9440 && f
== last_mouse_frame
9441 && FRAME_LIVE_P (f
));
9443 && last_tool_bar_item
!= prop_idx
)
9446 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9447 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9449 /* If tool-bar item is not enabled, don't highlight it. */
9450 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9451 if (!NILP (enabled_p
))
9453 /* Compute the x-position of the glyph. In front and past the
9454 image is a space. We include this in the highlighted area. */
9455 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9456 for (i
= x
= 0; i
< hpos
; ++i
)
9457 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9459 /* Record this as the current active region. */
9460 dpyinfo
->mouse_face_beg_col
= hpos
;
9461 dpyinfo
->mouse_face_beg_row
= vpos
;
9462 dpyinfo
->mouse_face_beg_x
= x
;
9463 dpyinfo
->mouse_face_beg_y
= row
->y
;
9464 dpyinfo
->mouse_face_past_end
= 0;
9466 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9467 dpyinfo
->mouse_face_end_row
= vpos
;
9468 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9469 dpyinfo
->mouse_face_end_y
= row
->y
;
9470 dpyinfo
->mouse_face_window
= window
;
9471 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9473 /* Display it as active. */
9474 show_mouse_face (dpyinfo
, draw
);
9475 dpyinfo
->mouse_face_image_state
= draw
;
9480 /* Set help_echo_string to a help string to display for this tool-bar item.
9481 XTread_socket does the rest. */
9482 help_echo_object
= help_echo_window
= Qnil
;
9484 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9485 if (NILP (help_echo_string
))
9486 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9489 #endif /* HAVE_WINDOW_SYSTEM */
9493 /************************************************************************
9494 Horizontal scrolling
9495 ************************************************************************/
9497 static int hscroll_window_tree
P_ ((Lisp_Object
));
9498 static int hscroll_windows
P_ ((Lisp_Object
));
9500 /* For all leaf windows in the window tree rooted at WINDOW, set their
9501 hscroll value so that PT is (i) visible in the window, and (ii) so
9502 that it is not within a certain margin at the window's left and
9503 right border. Value is non-zero if any window's hscroll has been
9507 hscroll_window_tree (window
)
9510 int hscrolled_p
= 0;
9511 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9512 int hscroll_step_abs
= 0;
9513 double hscroll_step_rel
= 0;
9515 if (hscroll_relative_p
)
9517 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9518 if (hscroll_step_rel
< 0)
9520 hscroll_relative_p
= 0;
9521 hscroll_step_abs
= 0;
9524 else if (INTEGERP (Vhscroll_step
))
9526 hscroll_step_abs
= XINT (Vhscroll_step
);
9527 if (hscroll_step_abs
< 0)
9528 hscroll_step_abs
= 0;
9531 hscroll_step_abs
= 0;
9533 while (WINDOWP (window
))
9535 struct window
*w
= XWINDOW (window
);
9537 if (WINDOWP (w
->hchild
))
9538 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9539 else if (WINDOWP (w
->vchild
))
9540 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9541 else if (w
->cursor
.vpos
>= 0)
9544 int text_area_width
;
9545 struct glyph_row
*current_cursor_row
9546 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9547 struct glyph_row
*desired_cursor_row
9548 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9549 struct glyph_row
*cursor_row
9550 = (desired_cursor_row
->enabled_p
9551 ? desired_cursor_row
9552 : current_cursor_row
);
9554 text_area_width
= window_box_width (w
, TEXT_AREA
);
9556 /* Scroll when cursor is inside this scroll margin. */
9557 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9559 if ((XFASTINT (w
->hscroll
)
9560 && w
->cursor
.x
<= h_margin
)
9561 || (cursor_row
->enabled_p
9562 && cursor_row
->truncated_on_right_p
9563 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9567 struct buffer
*saved_current_buffer
;
9571 /* Find point in a display of infinite width. */
9572 saved_current_buffer
= current_buffer
;
9573 current_buffer
= XBUFFER (w
->buffer
);
9575 if (w
== XWINDOW (selected_window
))
9576 pt
= BUF_PT (current_buffer
);
9579 pt
= marker_position (w
->pointm
);
9580 pt
= max (BEGV
, pt
);
9584 /* Move iterator to pt starting at cursor_row->start in
9585 a line with infinite width. */
9586 init_to_row_start (&it
, w
, cursor_row
);
9587 it
.last_visible_x
= INFINITY
;
9588 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9589 current_buffer
= saved_current_buffer
;
9591 /* Position cursor in window. */
9592 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9593 hscroll
= max (0, (it
.current_x
9594 - (ITERATOR_AT_END_OF_LINE_P (&it
)
9595 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
9596 : (text_area_width
/ 2))))
9597 / FRAME_COLUMN_WIDTH (it
.f
);
9598 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9600 if (hscroll_relative_p
)
9601 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9604 wanted_x
= text_area_width
9605 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9608 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9612 if (hscroll_relative_p
)
9613 wanted_x
= text_area_width
* hscroll_step_rel
9616 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9619 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9621 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9623 /* Don't call Fset_window_hscroll if value hasn't
9624 changed because it will prevent redisplay
9626 if (XFASTINT (w
->hscroll
) != hscroll
)
9628 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9629 w
->hscroll
= make_number (hscroll
);
9638 /* Value is non-zero if hscroll of any leaf window has been changed. */
9643 /* Set hscroll so that cursor is visible and not inside horizontal
9644 scroll margins for all windows in the tree rooted at WINDOW. See
9645 also hscroll_window_tree above. Value is non-zero if any window's
9646 hscroll has been changed. If it has, desired matrices on the frame
9647 of WINDOW are cleared. */
9650 hscroll_windows (window
)
9655 if (automatic_hscrolling_p
)
9657 hscrolled_p
= hscroll_window_tree (window
);
9659 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9668 /************************************************************************
9670 ************************************************************************/
9672 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9673 to a non-zero value. This is sometimes handy to have in a debugger
9678 /* First and last unchanged row for try_window_id. */
9680 int debug_first_unchanged_at_end_vpos
;
9681 int debug_last_unchanged_at_beg_vpos
;
9683 /* Delta vpos and y. */
9685 int debug_dvpos
, debug_dy
;
9687 /* Delta in characters and bytes for try_window_id. */
9689 int debug_delta
, debug_delta_bytes
;
9691 /* Values of window_end_pos and window_end_vpos at the end of
9694 EMACS_INT debug_end_pos
, debug_end_vpos
;
9696 /* Append a string to W->desired_matrix->method. FMT is a printf
9697 format string. A1...A9 are a supplement for a variable-length
9698 argument list. If trace_redisplay_p is non-zero also printf the
9699 resulting string to stderr. */
9702 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9705 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9708 char *method
= w
->desired_matrix
->method
;
9709 int len
= strlen (method
);
9710 int size
= sizeof w
->desired_matrix
->method
;
9711 int remaining
= size
- len
- 1;
9713 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9714 if (len
&& remaining
)
9720 strncpy (method
+ len
, buffer
, remaining
);
9722 if (trace_redisplay_p
)
9723 fprintf (stderr
, "%p (%s): %s\n",
9725 ((BUFFERP (w
->buffer
)
9726 && STRINGP (XBUFFER (w
->buffer
)->name
))
9727 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9732 #endif /* GLYPH_DEBUG */
9735 /* Value is non-zero if all changes in window W, which displays
9736 current_buffer, are in the text between START and END. START is a
9737 buffer position, END is given as a distance from Z. Used in
9738 redisplay_internal for display optimization. */
9741 text_outside_line_unchanged_p (w
, start
, end
)
9745 int unchanged_p
= 1;
9747 /* If text or overlays have changed, see where. */
9748 if (XFASTINT (w
->last_modified
) < MODIFF
9749 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9751 /* Gap in the line? */
9752 if (GPT
< start
|| Z
- GPT
< end
)
9755 /* Changes start in front of the line, or end after it? */
9757 && (BEG_UNCHANGED
< start
- 1
9758 || END_UNCHANGED
< end
))
9761 /* If selective display, can't optimize if changes start at the
9762 beginning of the line. */
9764 && INTEGERP (current_buffer
->selective_display
)
9765 && XINT (current_buffer
->selective_display
) > 0
9766 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9769 /* If there are overlays at the start or end of the line, these
9770 may have overlay strings with newlines in them. A change at
9771 START, for instance, may actually concern the display of such
9772 overlay strings as well, and they are displayed on different
9773 lines. So, quickly rule out this case. (For the future, it
9774 might be desirable to implement something more telling than
9775 just BEG/END_UNCHANGED.) */
9778 if (BEG
+ BEG_UNCHANGED
== start
9779 && overlay_touches_p (start
))
9781 if (END_UNCHANGED
== end
9782 && overlay_touches_p (Z
- end
))
9791 /* Do a frame update, taking possible shortcuts into account. This is
9792 the main external entry point for redisplay.
9794 If the last redisplay displayed an echo area message and that message
9795 is no longer requested, we clear the echo area or bring back the
9796 mini-buffer if that is in use. */
9801 redisplay_internal (0);
9806 overlay_arrow_string_or_property (var
)
9811 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
9814 return Voverlay_arrow_string
;
9817 /* Return 1 if there are any overlay-arrows in current_buffer. */
9819 overlay_arrow_in_current_buffer_p ()
9823 for (vlist
= Voverlay_arrow_variable_list
;
9825 vlist
= XCDR (vlist
))
9827 Lisp_Object var
= XCAR (vlist
);
9832 val
= find_symbol_value (var
);
9834 && current_buffer
== XMARKER (val
)->buffer
)
9841 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
9845 overlay_arrows_changed_p ()
9849 for (vlist
= Voverlay_arrow_variable_list
;
9851 vlist
= XCDR (vlist
))
9853 Lisp_Object var
= XCAR (vlist
);
9854 Lisp_Object val
, pstr
;
9858 val
= find_symbol_value (var
);
9861 if (! EQ (COERCE_MARKER (val
),
9862 Fget (var
, Qlast_arrow_position
))
9863 || ! (pstr
= overlay_arrow_string_or_property (var
),
9864 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
9870 /* Mark overlay arrows to be updated on next redisplay. */
9873 update_overlay_arrows (up_to_date
)
9878 for (vlist
= Voverlay_arrow_variable_list
;
9880 vlist
= XCDR (vlist
))
9882 Lisp_Object var
= XCAR (vlist
);
9889 Lisp_Object val
= find_symbol_value (var
);
9890 Fput (var
, Qlast_arrow_position
,
9891 COERCE_MARKER (val
));
9892 Fput (var
, Qlast_arrow_string
,
9893 overlay_arrow_string_or_property (var
));
9895 else if (up_to_date
< 0
9896 || !NILP (Fget (var
, Qlast_arrow_position
)))
9898 Fput (var
, Qlast_arrow_position
, Qt
);
9899 Fput (var
, Qlast_arrow_string
, Qt
);
9905 /* Return overlay arrow string to display at row.
9906 Return integer (bitmap number) for arrow bitmap in left fringe.
9907 Return nil if no overlay arrow. */
9910 overlay_arrow_at_row (it
, row
)
9912 struct glyph_row
*row
;
9916 for (vlist
= Voverlay_arrow_variable_list
;
9918 vlist
= XCDR (vlist
))
9920 Lisp_Object var
= XCAR (vlist
);
9926 val
= find_symbol_value (var
);
9929 && current_buffer
== XMARKER (val
)->buffer
9930 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
9932 if (FRAME_WINDOW_P (it
->f
)
9933 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
9935 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
9938 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
9939 return make_number (fringe_bitmap
);
9941 return make_number (-1); /* Use default arrow bitmap */
9943 return overlay_arrow_string_or_property (var
);
9950 /* Return 1 if point moved out of or into a composition. Otherwise
9951 return 0. PREV_BUF and PREV_PT are the last point buffer and
9952 position. BUF and PT are the current point buffer and position. */
9955 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
9956 struct buffer
*prev_buf
, *buf
;
9963 XSETBUFFER (buffer
, buf
);
9964 /* Check a composition at the last point if point moved within the
9966 if (prev_buf
== buf
)
9969 /* Point didn't move. */
9972 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
9973 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
9974 && COMPOSITION_VALID_P (start
, end
, prop
)
9975 && start
< prev_pt
&& end
> prev_pt
)
9976 /* The last point was within the composition. Return 1 iff
9977 point moved out of the composition. */
9978 return (pt
<= start
|| pt
>= end
);
9981 /* Check a composition at the current point. */
9982 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
9983 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
9984 && COMPOSITION_VALID_P (start
, end
, prop
)
9985 && start
< pt
&& end
> pt
);
9989 /* Reconsider the setting of B->clip_changed which is displayed
9993 reconsider_clip_changes (w
, b
)
9998 && !NILP (w
->window_end_valid
)
9999 && w
->current_matrix
->buffer
== b
10000 && w
->current_matrix
->zv
== BUF_ZV (b
)
10001 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10002 b
->clip_changed
= 0;
10004 /* If display wasn't paused, and W is not a tool bar window, see if
10005 point has been moved into or out of a composition. In that case,
10006 we set b->clip_changed to 1 to force updating the screen. If
10007 b->clip_changed has already been set to 1, we can skip this
10009 if (!b
->clip_changed
10010 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10014 if (w
== XWINDOW (selected_window
))
10015 pt
= BUF_PT (current_buffer
);
10017 pt
= marker_position (w
->pointm
);
10019 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10020 || pt
!= XINT (w
->last_point
))
10021 && check_point_in_composition (w
->current_matrix
->buffer
,
10022 XINT (w
->last_point
),
10023 XBUFFER (w
->buffer
), pt
))
10024 b
->clip_changed
= 1;
10029 /* Select FRAME to forward the values of frame-local variables into C
10030 variables so that the redisplay routines can access those values
10034 select_frame_for_redisplay (frame
)
10037 Lisp_Object tail
, sym
, val
;
10038 Lisp_Object old
= selected_frame
;
10040 selected_frame
= frame
;
10042 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10043 if (CONSP (XCAR (tail
))
10044 && (sym
= XCAR (XCAR (tail
)),
10046 && (sym
= indirect_variable (sym
),
10047 val
= SYMBOL_VALUE (sym
),
10048 (BUFFER_LOCAL_VALUEP (val
)
10049 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10050 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10051 Fsymbol_value (sym
);
10053 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10054 if (CONSP (XCAR (tail
))
10055 && (sym
= XCAR (XCAR (tail
)),
10057 && (sym
= indirect_variable (sym
),
10058 val
= SYMBOL_VALUE (sym
),
10059 (BUFFER_LOCAL_VALUEP (val
)
10060 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10061 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10062 Fsymbol_value (sym
);
10066 #define STOP_POLLING \
10067 do { if (! polling_stopped_here) stop_polling (); \
10068 polling_stopped_here = 1; } while (0)
10070 #define RESUME_POLLING \
10071 do { if (polling_stopped_here) start_polling (); \
10072 polling_stopped_here = 0; } while (0)
10075 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10076 response to any user action; therefore, we should preserve the echo
10077 area. (Actually, our caller does that job.) Perhaps in the future
10078 avoid recentering windows if it is not necessary; currently that
10079 causes some problems. */
10082 redisplay_internal (preserve_echo_area
)
10083 int preserve_echo_area
;
10085 struct window
*w
= XWINDOW (selected_window
);
10086 struct frame
*f
= XFRAME (w
->frame
);
10088 int must_finish
= 0;
10089 struct text_pos tlbufpos
, tlendpos
;
10090 int number_of_visible_frames
;
10092 struct frame
*sf
= SELECTED_FRAME ();
10093 int polling_stopped_here
= 0;
10095 /* Non-zero means redisplay has to consider all windows on all
10096 frames. Zero means, only selected_window is considered. */
10097 int consider_all_windows_p
;
10099 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10101 /* No redisplay if running in batch mode or frame is not yet fully
10102 initialized, or redisplay is explicitly turned off by setting
10103 Vinhibit_redisplay. */
10105 || !NILP (Vinhibit_redisplay
)
10106 || !f
->glyphs_initialized_p
)
10109 /* The flag redisplay_performed_directly_p is set by
10110 direct_output_for_insert when it already did the whole screen
10111 update necessary. */
10112 if (redisplay_performed_directly_p
)
10114 redisplay_performed_directly_p
= 0;
10115 if (!hscroll_windows (selected_window
))
10119 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
10120 if (popup_activated ())
10124 /* I don't think this happens but let's be paranoid. */
10125 if (redisplaying_p
)
10128 /* Record a function that resets redisplaying_p to its old value
10129 when we leave this function. */
10130 count
= SPECPDL_INDEX ();
10131 record_unwind_protect (unwind_redisplay
,
10132 Fcons (make_number (redisplaying_p
), selected_frame
));
10134 specbind (Qinhibit_free_realized_faces
, Qnil
);
10138 reconsider_clip_changes (w
, current_buffer
);
10140 /* If new fonts have been loaded that make a glyph matrix adjustment
10141 necessary, do it. */
10142 if (fonts_changed_p
)
10144 adjust_glyphs (NULL
);
10145 ++windows_or_buffers_changed
;
10146 fonts_changed_p
= 0;
10149 /* If face_change_count is non-zero, init_iterator will free all
10150 realized faces, which includes the faces referenced from current
10151 matrices. So, we can't reuse current matrices in this case. */
10152 if (face_change_count
)
10153 ++windows_or_buffers_changed
;
10155 if (FRAME_TERMCAP_P (sf
)
10156 && FRAME_TTY (sf
)->previous_terminal_frame
!= sf
)
10158 /* Since frames on a single ASCII terminal share the same
10159 display area, displaying a different frame means redisplay
10160 the whole thing. */
10161 windows_or_buffers_changed
++;
10162 SET_FRAME_GARBAGED (sf
);
10163 FRAME_TTY (sf
)->previous_terminal_frame
= sf
;
10166 /* Set the visible flags for all frames. Do this before checking
10167 for resized or garbaged frames; they want to know if their frames
10168 are visible. See the comment in frame.h for
10169 FRAME_SAMPLE_VISIBILITY. */
10171 Lisp_Object tail
, frame
;
10173 number_of_visible_frames
= 0;
10175 FOR_EACH_FRAME (tail
, frame
)
10177 struct frame
*f
= XFRAME (frame
);
10179 FRAME_SAMPLE_VISIBILITY (f
);
10180 if (FRAME_VISIBLE_P (f
))
10181 ++number_of_visible_frames
;
10182 clear_desired_matrices (f
);
10187 /* Notice any pending interrupt request to change frame size. */
10188 do_pending_window_change (1);
10190 /* Clear frames marked as garbaged. */
10191 if (frame_garbaged
)
10192 clear_garbaged_frames ();
10194 /* Build menubar and tool-bar items. */
10195 prepare_menu_bars ();
10197 if (windows_or_buffers_changed
)
10198 update_mode_lines
++;
10200 /* Detect case that we need to write or remove a star in the mode line. */
10201 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10203 w
->update_mode_line
= Qt
;
10204 if (buffer_shared
> 1)
10205 update_mode_lines
++;
10208 /* If %c is in the mode line, update it if needed. */
10209 if (!NILP (w
->column_number_displayed
)
10210 /* This alternative quickly identifies a common case
10211 where no change is needed. */
10212 && !(PT
== XFASTINT (w
->last_point
)
10213 && XFASTINT (w
->last_modified
) >= MODIFF
10214 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10215 && (XFASTINT (w
->column_number_displayed
)
10216 != (int) current_column ())) /* iftc */
10217 w
->update_mode_line
= Qt
;
10219 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10221 /* The variable buffer_shared is set in redisplay_window and
10222 indicates that we redisplay a buffer in different windows. See
10224 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10225 || cursor_type_changed
);
10227 /* If specs for an arrow have changed, do thorough redisplay
10228 to ensure we remove any arrow that should no longer exist. */
10229 if (overlay_arrows_changed_p ())
10230 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10232 /* Normally the message* functions will have already displayed and
10233 updated the echo area, but the frame may have been trashed, or
10234 the update may have been preempted, so display the echo area
10235 again here. Checking message_cleared_p captures the case that
10236 the echo area should be cleared. */
10237 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10238 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10239 || (message_cleared_p
10240 && minibuf_level
== 0
10241 /* If the mini-window is currently selected, this means the
10242 echo-area doesn't show through. */
10243 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10245 int window_height_changed_p
= echo_area_display (0);
10248 /* If we don't display the current message, don't clear the
10249 message_cleared_p flag, because, if we did, we wouldn't clear
10250 the echo area in the next redisplay which doesn't preserve
10252 if (!display_last_displayed_message_p
)
10253 message_cleared_p
= 0;
10255 if (fonts_changed_p
)
10257 else if (window_height_changed_p
)
10259 consider_all_windows_p
= 1;
10260 ++update_mode_lines
;
10261 ++windows_or_buffers_changed
;
10263 /* If window configuration was changed, frames may have been
10264 marked garbaged. Clear them or we will experience
10265 surprises wrt scrolling. */
10266 if (frame_garbaged
)
10267 clear_garbaged_frames ();
10270 else if (EQ (selected_window
, minibuf_window
)
10271 && (current_buffer
->clip_changed
10272 || XFASTINT (w
->last_modified
) < MODIFF
10273 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10274 && resize_mini_window (w
, 0))
10276 /* Resized active mini-window to fit the size of what it is
10277 showing if its contents might have changed. */
10279 consider_all_windows_p
= 1;
10280 ++windows_or_buffers_changed
;
10281 ++update_mode_lines
;
10283 /* If window configuration was changed, frames may have been
10284 marked garbaged. Clear them or we will experience
10285 surprises wrt scrolling. */
10286 if (frame_garbaged
)
10287 clear_garbaged_frames ();
10291 /* If showing the region, and mark has changed, we must redisplay
10292 the whole window. The assignment to this_line_start_pos prevents
10293 the optimization directly below this if-statement. */
10294 if (((!NILP (Vtransient_mark_mode
)
10295 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10296 != !NILP (w
->region_showing
))
10297 || (!NILP (w
->region_showing
)
10298 && !EQ (w
->region_showing
,
10299 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
10300 CHARPOS (this_line_start_pos
) = 0;
10302 /* Optimize the case that only the line containing the cursor in the
10303 selected window has changed. Variables starting with this_ are
10304 set in display_line and record information about the line
10305 containing the cursor. */
10306 tlbufpos
= this_line_start_pos
;
10307 tlendpos
= this_line_end_pos
;
10308 if (!consider_all_windows_p
10309 && CHARPOS (tlbufpos
) > 0
10310 && NILP (w
->update_mode_line
)
10311 && !current_buffer
->clip_changed
10312 && !current_buffer
->prevent_redisplay_optimizations_p
10313 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
10314 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
10315 /* Make sure recorded data applies to current buffer, etc. */
10316 && this_line_buffer
== current_buffer
10317 && current_buffer
== XBUFFER (w
->buffer
)
10318 && NILP (w
->force_start
)
10319 && NILP (w
->optional_new_start
)
10320 /* Point must be on the line that we have info recorded about. */
10321 && PT
>= CHARPOS (tlbufpos
)
10322 && PT
<= Z
- CHARPOS (tlendpos
)
10323 /* All text outside that line, including its final newline,
10324 must be unchanged */
10325 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
10326 CHARPOS (tlendpos
)))
10328 if (CHARPOS (tlbufpos
) > BEGV
10329 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
10330 && (CHARPOS (tlbufpos
) == ZV
10331 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
10332 /* Former continuation line has disappeared by becoming empty */
10334 else if (XFASTINT (w
->last_modified
) < MODIFF
10335 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
10336 || MINI_WINDOW_P (w
))
10338 /* We have to handle the case of continuation around a
10339 wide-column character (See the comment in indent.c around
10342 For instance, in the following case:
10344 -------- Insert --------
10345 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
10346 J_I_ ==> J_I_ `^^' are cursors.
10350 As we have to redraw the line above, we should goto cancel. */
10353 int line_height_before
= this_line_pixel_height
;
10355 /* Note that start_display will handle the case that the
10356 line starting at tlbufpos is a continuation lines. */
10357 start_display (&it
, w
, tlbufpos
);
10359 /* Implementation note: It this still necessary? */
10360 if (it
.current_x
!= this_line_start_x
)
10363 TRACE ((stderr
, "trying display optimization 1\n"));
10364 w
->cursor
.vpos
= -1;
10365 overlay_arrow_seen
= 0;
10366 it
.vpos
= this_line_vpos
;
10367 it
.current_y
= this_line_y
;
10368 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10369 display_line (&it
);
10371 /* If line contains point, is not continued,
10372 and ends at same distance from eob as before, we win */
10373 if (w
->cursor
.vpos
>= 0
10374 /* Line is not continued, otherwise this_line_start_pos
10375 would have been set to 0 in display_line. */
10376 && CHARPOS (this_line_start_pos
)
10377 /* Line ends as before. */
10378 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10379 /* Line has same height as before. Otherwise other lines
10380 would have to be shifted up or down. */
10381 && this_line_pixel_height
== line_height_before
)
10383 /* If this is not the window's last line, we must adjust
10384 the charstarts of the lines below. */
10385 if (it
.current_y
< it
.last_visible_y
)
10387 struct glyph_row
*row
10388 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10389 int delta
, delta_bytes
;
10391 if (Z
- CHARPOS (tlendpos
) == ZV
)
10393 /* This line ends at end of (accessible part of)
10394 buffer. There is no newline to count. */
10396 - CHARPOS (tlendpos
)
10397 - MATRIX_ROW_START_CHARPOS (row
));
10398 delta_bytes
= (Z_BYTE
10399 - BYTEPOS (tlendpos
)
10400 - MATRIX_ROW_START_BYTEPOS (row
));
10404 /* This line ends in a newline. Must take
10405 account of the newline and the rest of the
10406 text that follows. */
10408 - CHARPOS (tlendpos
)
10409 - MATRIX_ROW_START_CHARPOS (row
));
10410 delta_bytes
= (Z_BYTE
10411 - BYTEPOS (tlendpos
)
10412 - MATRIX_ROW_START_BYTEPOS (row
));
10415 increment_matrix_positions (w
->current_matrix
,
10416 this_line_vpos
+ 1,
10417 w
->current_matrix
->nrows
,
10418 delta
, delta_bytes
);
10421 /* If this row displays text now but previously didn't,
10422 or vice versa, w->window_end_vpos may have to be
10424 if ((it
.glyph_row
- 1)->displays_text_p
)
10426 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10427 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10429 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10430 && this_line_vpos
> 0)
10431 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10432 w
->window_end_valid
= Qnil
;
10434 /* Update hint: No need to try to scroll in update_window. */
10435 w
->desired_matrix
->no_scrolling_p
= 1;
10438 *w
->desired_matrix
->method
= 0;
10439 debug_method_add (w
, "optimization 1");
10441 #ifdef HAVE_WINDOW_SYSTEM
10442 update_window_fringes (w
, 0);
10449 else if (/* Cursor position hasn't changed. */
10450 PT
== XFASTINT (w
->last_point
)
10451 /* Make sure the cursor was last displayed
10452 in this window. Otherwise we have to reposition it. */
10453 && 0 <= w
->cursor
.vpos
10454 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10458 do_pending_window_change (1);
10460 /* We used to always goto end_of_redisplay here, but this
10461 isn't enough if we have a blinking cursor. */
10462 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10463 goto end_of_redisplay
;
10467 /* If highlighting the region, or if the cursor is in the echo area,
10468 then we can't just move the cursor. */
10469 else if (! (!NILP (Vtransient_mark_mode
)
10470 && !NILP (current_buffer
->mark_active
))
10471 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10472 || highlight_nonselected_windows
)
10473 && NILP (w
->region_showing
)
10474 && NILP (Vshow_trailing_whitespace
)
10475 && !cursor_in_echo_area
)
10478 struct glyph_row
*row
;
10480 /* Skip from tlbufpos to PT and see where it is. Note that
10481 PT may be in invisible text. If so, we will end at the
10482 next visible position. */
10483 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10484 NULL
, DEFAULT_FACE_ID
);
10485 it
.current_x
= this_line_start_x
;
10486 it
.current_y
= this_line_y
;
10487 it
.vpos
= this_line_vpos
;
10489 /* The call to move_it_to stops in front of PT, but
10490 moves over before-strings. */
10491 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10493 if (it
.vpos
== this_line_vpos
10494 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10497 xassert (this_line_vpos
== it
.vpos
);
10498 xassert (this_line_y
== it
.current_y
);
10499 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10501 *w
->desired_matrix
->method
= 0;
10502 debug_method_add (w
, "optimization 3");
10511 /* Text changed drastically or point moved off of line. */
10512 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10515 CHARPOS (this_line_start_pos
) = 0;
10516 consider_all_windows_p
|= buffer_shared
> 1;
10517 ++clear_face_cache_count
;
10518 #ifdef HAVE_WINDOW_SYSTEM
10519 ++clear_image_cache_count
;
10522 /* Build desired matrices, and update the display. If
10523 consider_all_windows_p is non-zero, do it for all windows on all
10524 frames. Otherwise do it for selected_window, only. */
10526 if (consider_all_windows_p
)
10528 Lisp_Object tail
, frame
;
10529 int i
, n
= 0, size
= 50;
10530 struct frame
**updated
10531 = (struct frame
**) alloca (size
* sizeof *updated
);
10533 /* Recompute # windows showing selected buffer. This will be
10534 incremented each time such a window is displayed. */
10537 FOR_EACH_FRAME (tail
, frame
)
10539 struct frame
*f
= XFRAME (frame
);
10541 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
10543 if (! EQ (frame
, selected_frame
))
10544 /* Select the frame, for the sake of frame-local
10546 select_frame_for_redisplay (frame
);
10548 /* Mark all the scroll bars to be removed; we'll redeem
10549 the ones we want when we redisplay their windows. */
10550 if (FRAME_DISPLAY (f
)->condemn_scroll_bars_hook
)
10551 FRAME_DISPLAY (f
)->condemn_scroll_bars_hook (f
);
10553 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10554 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10556 /* Any scroll bars which redisplay_windows should have
10557 nuked should now go away. */
10558 if (FRAME_DISPLAY (f
)->judge_scroll_bars_hook
)
10559 FRAME_DISPLAY (f
)->judge_scroll_bars_hook (f
);
10561 /* If fonts changed, display again. */
10562 /* ??? rms: I suspect it is a mistake to jump all the way
10563 back to retry here. It should just retry this frame. */
10564 if (fonts_changed_p
)
10567 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10569 /* See if we have to hscroll. */
10570 if (hscroll_windows (f
->root_window
))
10573 /* Prevent various kinds of signals during display
10574 update. stdio is not robust about handling
10575 signals, which can cause an apparent I/O
10577 if (interrupt_input
)
10578 unrequest_sigio ();
10581 /* Update the display. */
10582 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10583 pause
|= update_frame (f
, 0, 0);
10584 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10591 int nbytes
= size
* sizeof *updated
;
10592 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
10593 bcopy (updated
, p
, nbytes
);
10604 /* Do the mark_window_display_accurate after all windows have
10605 been redisplayed because this call resets flags in buffers
10606 which are needed for proper redisplay. */
10607 for (i
= 0; i
< n
; ++i
)
10609 struct frame
*f
= updated
[i
];
10610 mark_window_display_accurate (f
->root_window
, 1);
10611 if (FRAME_DISPLAY (f
)->frame_up_to_date_hook
)
10612 FRAME_DISPLAY (f
)->frame_up_to_date_hook (f
);
10616 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10618 Lisp_Object mini_window
;
10619 struct frame
*mini_frame
;
10621 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10622 /* Use list_of_error, not Qerror, so that
10623 we catch only errors and don't run the debugger. */
10624 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10626 redisplay_window_error
);
10628 /* Compare desired and current matrices, perform output. */
10631 /* If fonts changed, display again. */
10632 if (fonts_changed_p
)
10635 /* Prevent various kinds of signals during display update.
10636 stdio is not robust about handling signals,
10637 which can cause an apparent I/O error. */
10638 if (interrupt_input
)
10639 unrequest_sigio ();
10642 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10644 if (hscroll_windows (selected_window
))
10647 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10648 pause
= update_frame (sf
, 0, 0);
10651 /* We may have called echo_area_display at the top of this
10652 function. If the echo area is on another frame, that may
10653 have put text on a frame other than the selected one, so the
10654 above call to update_frame would not have caught it. Catch
10656 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10657 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10659 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10661 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10662 pause
|= update_frame (mini_frame
, 0, 0);
10663 if (!pause
&& hscroll_windows (mini_window
))
10668 /* If display was paused because of pending input, make sure we do a
10669 thorough update the next time. */
10672 /* Prevent the optimization at the beginning of
10673 redisplay_internal that tries a single-line update of the
10674 line containing the cursor in the selected window. */
10675 CHARPOS (this_line_start_pos
) = 0;
10677 /* Let the overlay arrow be updated the next time. */
10678 update_overlay_arrows (0);
10680 /* If we pause after scrolling, some rows in the current
10681 matrices of some windows are not valid. */
10682 if (!WINDOW_FULL_WIDTH_P (w
)
10683 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10684 update_mode_lines
= 1;
10688 if (!consider_all_windows_p
)
10690 /* This has already been done above if
10691 consider_all_windows_p is set. */
10692 mark_window_display_accurate_1 (w
, 1);
10694 /* Say overlay arrows are up to date. */
10695 update_overlay_arrows (1);
10697 if (FRAME_DISPLAY (sf
)->frame_up_to_date_hook
!= 0)
10698 FRAME_DISPLAY (sf
)->frame_up_to_date_hook (sf
);
10701 update_mode_lines
= 0;
10702 windows_or_buffers_changed
= 0;
10703 cursor_type_changed
= 0;
10706 /* Start SIGIO interrupts coming again. Having them off during the
10707 code above makes it less likely one will discard output, but not
10708 impossible, since there might be stuff in the system buffer here.
10709 But it is much hairier to try to do anything about that. */
10710 if (interrupt_input
)
10714 /* If a frame has become visible which was not before, redisplay
10715 again, so that we display it. Expose events for such a frame
10716 (which it gets when becoming visible) don't call the parts of
10717 redisplay constructing glyphs, so simply exposing a frame won't
10718 display anything in this case. So, we have to display these
10719 frames here explicitly. */
10722 Lisp_Object tail
, frame
;
10725 FOR_EACH_FRAME (tail
, frame
)
10727 int this_is_visible
= 0;
10729 if (XFRAME (frame
)->visible
)
10730 this_is_visible
= 1;
10731 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10732 if (XFRAME (frame
)->visible
)
10733 this_is_visible
= 1;
10735 if (this_is_visible
)
10739 if (new_count
!= number_of_visible_frames
)
10740 windows_or_buffers_changed
++;
10743 /* Change frame size now if a change is pending. */
10744 do_pending_window_change (1);
10746 /* If we just did a pending size change, or have additional
10747 visible frames, redisplay again. */
10748 if (windows_or_buffers_changed
&& !pause
)
10751 /* Clear the face cache eventually. */
10752 if (consider_all_windows_p
)
10754 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
10756 clear_face_cache (0);
10757 clear_face_cache_count
= 0;
10759 #ifdef HAVE_WINDOW_SYSTEM
10760 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
10762 Lisp_Object tail
, frame
;
10763 FOR_EACH_FRAME (tail
, frame
)
10765 struct frame
*f
= XFRAME (frame
);
10766 if (FRAME_WINDOW_P (f
))
10767 clear_image_cache (f
, 0);
10769 clear_image_cache_count
= 0;
10771 #endif /* HAVE_WINDOW_SYSTEM */
10775 unbind_to (count
, Qnil
);
10780 /* Redisplay, but leave alone any recent echo area message unless
10781 another message has been requested in its place.
10783 This is useful in situations where you need to redisplay but no
10784 user action has occurred, making it inappropriate for the message
10785 area to be cleared. See tracking_off and
10786 wait_reading_process_output for examples of these situations.
10788 FROM_WHERE is an integer saying from where this function was
10789 called. This is useful for debugging. */
10792 redisplay_preserve_echo_area (from_where
)
10795 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10797 if (!NILP (echo_area_buffer
[1]))
10799 /* We have a previously displayed message, but no current
10800 message. Redisplay the previous message. */
10801 display_last_displayed_message_p
= 1;
10802 redisplay_internal (1);
10803 display_last_displayed_message_p
= 0;
10806 redisplay_internal (1);
10808 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
10809 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
10810 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
10814 /* Function registered with record_unwind_protect in
10815 redisplay_internal. Reset redisplaying_p to the value it had
10816 before redisplay_internal was called, and clear
10817 prevent_freeing_realized_faces_p. It also selects the previously
10821 unwind_redisplay (val
)
10824 Lisp_Object old_redisplaying_p
, old_frame
;
10826 old_redisplaying_p
= XCAR (val
);
10827 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10828 old_frame
= XCDR (val
);
10829 if (! EQ (old_frame
, selected_frame
))
10830 select_frame_for_redisplay (old_frame
);
10835 /* Mark the display of window W as accurate or inaccurate. If
10836 ACCURATE_P is non-zero mark display of W as accurate. If
10837 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10838 redisplay_internal is called. */
10841 mark_window_display_accurate_1 (w
, accurate_p
)
10845 if (BUFFERP (w
->buffer
))
10847 struct buffer
*b
= XBUFFER (w
->buffer
);
10850 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
10851 w
->last_overlay_modified
10852 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
10854 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
10858 b
->clip_changed
= 0;
10859 b
->prevent_redisplay_optimizations_p
= 0;
10861 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
10862 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
10863 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
10864 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
10866 w
->current_matrix
->buffer
= b
;
10867 w
->current_matrix
->begv
= BUF_BEGV (b
);
10868 w
->current_matrix
->zv
= BUF_ZV (b
);
10870 w
->last_cursor
= w
->cursor
;
10871 w
->last_cursor_off_p
= w
->cursor_off_p
;
10873 if (w
== XWINDOW (selected_window
))
10874 w
->last_point
= make_number (BUF_PT (b
));
10876 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
10882 w
->window_end_valid
= w
->buffer
;
10883 #if 0 /* This is incorrect with variable-height lines. */
10884 xassert (XINT (w
->window_end_vpos
)
10885 < (WINDOW_TOTAL_LINES (w
)
10886 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
10888 w
->update_mode_line
= Qnil
;
10893 /* Mark the display of windows in the window tree rooted at WINDOW as
10894 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
10895 windows as accurate. If ACCURATE_P is zero, arrange for windows to
10896 be redisplayed the next time redisplay_internal is called. */
10899 mark_window_display_accurate (window
, accurate_p
)
10900 Lisp_Object window
;
10905 for (; !NILP (window
); window
= w
->next
)
10907 w
= XWINDOW (window
);
10908 mark_window_display_accurate_1 (w
, accurate_p
);
10910 if (!NILP (w
->vchild
))
10911 mark_window_display_accurate (w
->vchild
, accurate_p
);
10912 if (!NILP (w
->hchild
))
10913 mark_window_display_accurate (w
->hchild
, accurate_p
);
10918 update_overlay_arrows (1);
10922 /* Force a thorough redisplay the next time by setting
10923 last_arrow_position and last_arrow_string to t, which is
10924 unequal to any useful value of Voverlay_arrow_... */
10925 update_overlay_arrows (-1);
10930 /* Return value in display table DP (Lisp_Char_Table *) for character
10931 C. Since a display table doesn't have any parent, we don't have to
10932 follow parent. Do not call this function directly but use the
10933 macro DISP_CHAR_VECTOR. */
10936 disp_char_vector (dp
, c
)
10937 struct Lisp_Char_Table
*dp
;
10943 if (SINGLE_BYTE_CHAR_P (c
))
10944 return (dp
->contents
[c
]);
10946 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
10949 else if (code
[2] < 32)
10952 /* Here, the possible range of code[0] (== charset ID) is
10953 128..max_charset. Since the top level char table contains data
10954 for multibyte characters after 256th element, we must increment
10955 code[0] by 128 to get a correct index. */
10957 code
[3] = -1; /* anchor */
10959 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
10961 val
= dp
->contents
[code
[i
]];
10962 if (!SUB_CHAR_TABLE_P (val
))
10963 return (NILP (val
) ? dp
->defalt
: val
);
10966 /* Here, val is a sub char table. We return the default value of
10968 return (dp
->defalt
);
10973 /***********************************************************************
10975 ***********************************************************************/
10977 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
10980 redisplay_windows (window
)
10981 Lisp_Object window
;
10983 while (!NILP (window
))
10985 struct window
*w
= XWINDOW (window
);
10987 if (!NILP (w
->hchild
))
10988 redisplay_windows (w
->hchild
);
10989 else if (!NILP (w
->vchild
))
10990 redisplay_windows (w
->vchild
);
10993 displayed_buffer
= XBUFFER (w
->buffer
);
10994 /* Use list_of_error, not Qerror, so that
10995 we catch only errors and don't run the debugger. */
10996 internal_condition_case_1 (redisplay_window_0
, window
,
10998 redisplay_window_error
);
11006 redisplay_window_error ()
11008 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11013 redisplay_window_0 (window
)
11014 Lisp_Object window
;
11016 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11017 redisplay_window (window
, 0);
11022 redisplay_window_1 (window
)
11023 Lisp_Object window
;
11025 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11026 redisplay_window (window
, 1);
11031 /* Increment GLYPH until it reaches END or CONDITION fails while
11032 adding (GLYPH)->pixel_width to X. */
11034 #define SKIP_GLYPHS(glyph, end, x, condition) \
11037 (x) += (glyph)->pixel_width; \
11040 while ((glyph) < (end) && (condition))
11043 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11044 DELTA is the number of bytes by which positions recorded in ROW
11045 differ from current buffer positions. */
11048 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11050 struct glyph_row
*row
;
11051 struct glyph_matrix
*matrix
;
11052 int delta
, delta_bytes
, dy
, dvpos
;
11054 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11055 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11056 struct glyph
*cursor
= NULL
;
11057 /* The first glyph that starts a sequence of glyphs from string. */
11058 struct glyph
*string_start
;
11059 /* The X coordinate of string_start. */
11060 int string_start_x
;
11061 /* The last known character position. */
11062 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11063 /* The last known character position before string_start. */
11064 int string_before_pos
;
11067 int cursor_from_overlay_pos
= 0;
11068 int pt_old
= PT
- delta
;
11070 /* Skip over glyphs not having an object at the start of the row.
11071 These are special glyphs like truncation marks on terminal
11073 if (row
->displays_text_p
)
11075 && INTEGERP (glyph
->object
)
11076 && glyph
->charpos
< 0)
11078 x
+= glyph
->pixel_width
;
11082 string_start
= NULL
;
11084 && !INTEGERP (glyph
->object
)
11085 && (!BUFFERP (glyph
->object
)
11086 || (last_pos
= glyph
->charpos
) < pt_old
))
11088 if (! STRINGP (glyph
->object
))
11090 string_start
= NULL
;
11091 x
+= glyph
->pixel_width
;
11093 if (cursor_from_overlay_pos
11094 && last_pos
> cursor_from_overlay_pos
)
11096 cursor_from_overlay_pos
= 0;
11102 string_before_pos
= last_pos
;
11103 string_start
= glyph
;
11104 string_start_x
= x
;
11105 /* Skip all glyphs from string. */
11109 if ((cursor
== NULL
|| glyph
> cursor
)
11110 && !NILP (Fget_char_property (make_number ((glyph
)->charpos
),
11111 Qcursor
, (glyph
)->object
))
11112 && (pos
= string_buffer_position (w
, glyph
->object
,
11113 string_before_pos
),
11114 (pos
== 0 /* From overlay */
11115 || pos
== pt_old
)))
11117 /* Estimate overlay buffer position from the buffer
11118 positions of the glyphs before and after the overlay.
11119 Add 1 to last_pos so that if point corresponds to the
11120 glyph right after the overlay, we still use a 'cursor'
11121 property found in that overlay. */
11122 cursor_from_overlay_pos
= pos
== 0 ? last_pos
+1 : 0;
11126 x
+= glyph
->pixel_width
;
11129 while (glyph
< end
&& STRINGP (glyph
->object
));
11133 if (cursor
!= NULL
)
11138 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
11140 /* Scan back over the ellipsis glyphs, decrementing positions. */
11141 while (glyph
> row
->glyphs
[TEXT_AREA
]
11142 && (glyph
- 1)->charpos
== last_pos
)
11143 glyph
--, x
-= glyph
->pixel_width
;
11144 /* That loop always goes one position too far,
11145 including the glyph before the ellipsis.
11146 So scan forward over that one. */
11147 x
+= glyph
->pixel_width
;
11150 else if (string_start
11151 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11153 /* We may have skipped over point because the previous glyphs
11154 are from string. As there's no easy way to know the
11155 character position of the current glyph, find the correct
11156 glyph on point by scanning from string_start again. */
11158 Lisp_Object string
;
11161 limit
= make_number (pt_old
+ 1);
11163 glyph
= string_start
;
11164 x
= string_start_x
;
11165 string
= glyph
->object
;
11166 pos
= string_buffer_position (w
, string
, string_before_pos
);
11167 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11168 because we always put cursor after overlay strings. */
11169 while (pos
== 0 && glyph
< end
)
11171 string
= glyph
->object
;
11172 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11174 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11177 while (glyph
< end
)
11179 pos
= XINT (Fnext_single_char_property_change
11180 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11183 /* Skip glyphs from the same string. */
11184 string
= glyph
->object
;
11185 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11186 /* Skip glyphs from an overlay. */
11188 && ! string_buffer_position (w
, glyph
->object
, pos
))
11190 string
= glyph
->object
;
11191 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11196 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11198 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11199 w
->cursor
.y
= row
->y
+ dy
;
11201 if (w
== XWINDOW (selected_window
))
11203 if (!row
->continued_p
11204 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11207 this_line_buffer
= XBUFFER (w
->buffer
);
11209 CHARPOS (this_line_start_pos
)
11210 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11211 BYTEPOS (this_line_start_pos
)
11212 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
11214 CHARPOS (this_line_end_pos
)
11215 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
11216 BYTEPOS (this_line_end_pos
)
11217 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
11219 this_line_y
= w
->cursor
.y
;
11220 this_line_pixel_height
= row
->height
;
11221 this_line_vpos
= w
->cursor
.vpos
;
11222 this_line_start_x
= row
->x
;
11225 CHARPOS (this_line_start_pos
) = 0;
11230 /* Run window scroll functions, if any, for WINDOW with new window
11231 start STARTP. Sets the window start of WINDOW to that position.
11233 We assume that the window's buffer is really current. */
11235 static INLINE
struct text_pos
11236 run_window_scroll_functions (window
, startp
)
11237 Lisp_Object window
;
11238 struct text_pos startp
;
11240 struct window
*w
= XWINDOW (window
);
11241 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
11243 if (current_buffer
!= XBUFFER (w
->buffer
))
11246 if (!NILP (Vwindow_scroll_functions
))
11248 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
11249 make_number (CHARPOS (startp
)));
11250 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11251 /* In case the hook functions switch buffers. */
11252 if (current_buffer
!= XBUFFER (w
->buffer
))
11253 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11260 /* Make sure the line containing the cursor is fully visible.
11261 A value of 1 means there is nothing to be done.
11262 (Either the line is fully visible, or it cannot be made so,
11263 or we cannot tell.)
11265 If FORCE_P is non-zero, return 0 even if partial visible cursor row
11266 is higher than window.
11268 A value of 0 means the caller should do scrolling
11269 as if point had gone off the screen. */
11272 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
11276 struct glyph_matrix
*matrix
;
11277 struct glyph_row
*row
;
11280 if (!make_cursor_line_fully_visible_p
)
11283 /* It's not always possible to find the cursor, e.g, when a window
11284 is full of overlay strings. Don't do anything in that case. */
11285 if (w
->cursor
.vpos
< 0)
11288 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
11289 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
11291 /* If the cursor row is not partially visible, there's nothing to do. */
11292 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
11295 /* If the row the cursor is in is taller than the window's height,
11296 it's not clear what to do, so do nothing. */
11297 window_height
= window_box_height (w
);
11298 if (row
->height
>= window_height
)
11300 if (!force_p
|| w
->vscroll
)
11306 /* This code used to try to scroll the window just enough to make
11307 the line visible. It returned 0 to say that the caller should
11308 allocate larger glyph matrices. */
11310 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
11312 int dy
= row
->height
- row
->visible_height
;
11315 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11317 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
11319 int dy
= - (row
->height
- row
->visible_height
);
11322 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11325 /* When we change the cursor y-position of the selected window,
11326 change this_line_y as well so that the display optimization for
11327 the cursor line of the selected window in redisplay_internal uses
11328 the correct y-position. */
11329 if (w
== XWINDOW (selected_window
))
11330 this_line_y
= w
->cursor
.y
;
11332 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
11333 redisplay with larger matrices. */
11334 if (matrix
->nrows
< required_matrix_height (w
))
11336 fonts_changed_p
= 1;
11345 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
11346 non-zero means only WINDOW is redisplayed in redisplay_internal.
11347 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
11348 in redisplay_window to bring a partially visible line into view in
11349 the case that only the cursor has moved.
11351 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
11352 last screen line's vertical height extends past the end of the screen.
11356 1 if scrolling succeeded
11358 0 if scrolling didn't find point.
11360 -1 if new fonts have been loaded so that we must interrupt
11361 redisplay, adjust glyph matrices, and try again. */
11367 SCROLLING_NEED_LARGER_MATRICES
11371 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
11372 scroll_step
, temp_scroll_step
, last_line_misfit
)
11373 Lisp_Object window
;
11374 int just_this_one_p
;
11375 EMACS_INT scroll_conservatively
, scroll_step
;
11376 int temp_scroll_step
;
11377 int last_line_misfit
;
11379 struct window
*w
= XWINDOW (window
);
11380 struct frame
*f
= XFRAME (w
->frame
);
11381 struct text_pos scroll_margin_pos
;
11382 struct text_pos pos
;
11383 struct text_pos startp
;
11385 Lisp_Object window_end
;
11386 int this_scroll_margin
;
11390 int amount_to_scroll
= 0;
11391 Lisp_Object aggressive
;
11393 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
11396 debug_method_add (w
, "try_scrolling");
11399 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11401 /* Compute scroll margin height in pixels. We scroll when point is
11402 within this distance from the top or bottom of the window. */
11403 if (scroll_margin
> 0)
11405 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11406 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11409 this_scroll_margin
= 0;
11411 /* Force scroll_conservatively to have a reasonable value so it doesn't
11412 cause an overflow while computing how much to scroll. */
11413 if (scroll_conservatively
)
11414 scroll_conservatively
= min (scroll_conservatively
,
11415 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
11417 /* Compute how much we should try to scroll maximally to bring point
11419 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11420 scroll_max
= max (scroll_step
,
11421 max (scroll_conservatively
, temp_scroll_step
));
11422 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11423 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11424 /* We're trying to scroll because of aggressive scrolling
11425 but no scroll_step is set. Choose an arbitrary one. Maybe
11426 there should be a variable for this. */
11430 scroll_max
*= FRAME_LINE_HEIGHT (f
);
11432 /* Decide whether we have to scroll down. Start at the window end
11433 and move this_scroll_margin up to find the position of the scroll
11435 window_end
= Fwindow_end (window
, Qt
);
11439 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
11440 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
11442 if (this_scroll_margin
|| extra_scroll_margin_lines
)
11444 start_display (&it
, w
, scroll_margin_pos
);
11445 if (this_scroll_margin
)
11446 move_it_vertically_backward (&it
, this_scroll_margin
);
11447 if (extra_scroll_margin_lines
)
11448 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
11449 scroll_margin_pos
= it
.current
.pos
;
11452 if (PT
>= CHARPOS (scroll_margin_pos
))
11456 /* Point is in the scroll margin at the bottom of the window, or
11457 below. Compute a new window start that makes point visible. */
11459 /* Compute the distance from the scroll margin to PT.
11460 Give up if the distance is greater than scroll_max. */
11461 start_display (&it
, w
, scroll_margin_pos
);
11463 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11464 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11466 /* To make point visible, we have to move the window start
11467 down so that the line the cursor is in is visible, which
11468 means we have to add in the height of the cursor line. */
11469 dy
= line_bottom_y (&it
) - y0
;
11471 if (dy
> scroll_max
)
11472 return SCROLLING_FAILED
;
11474 /* Move the window start down. If scrolling conservatively,
11475 move it just enough down to make point visible. If
11476 scroll_step is set, move it down by scroll_step. */
11477 start_display (&it
, w
, startp
);
11479 if (scroll_conservatively
)
11480 /* Set AMOUNT_TO_SCROLL to at least one line,
11481 and at most scroll_conservatively lines. */
11483 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11484 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11485 else if (scroll_step
|| temp_scroll_step
)
11486 amount_to_scroll
= scroll_max
;
11489 aggressive
= current_buffer
->scroll_up_aggressively
;
11490 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11491 if (NUMBERP (aggressive
))
11493 double float_amount
= XFLOATINT (aggressive
) * height
;
11494 amount_to_scroll
= float_amount
;
11495 if (amount_to_scroll
== 0 && float_amount
> 0)
11496 amount_to_scroll
= 1;
11500 if (amount_to_scroll
<= 0)
11501 return SCROLLING_FAILED
;
11503 /* If moving by amount_to_scroll leaves STARTP unchanged,
11504 move it down one screen line. */
11506 move_it_vertically (&it
, amount_to_scroll
);
11507 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
11508 move_it_by_lines (&it
, 1, 1);
11509 startp
= it
.current
.pos
;
11513 /* See if point is inside the scroll margin at the top of the
11515 scroll_margin_pos
= startp
;
11516 if (this_scroll_margin
)
11518 start_display (&it
, w
, startp
);
11519 move_it_vertically (&it
, this_scroll_margin
);
11520 scroll_margin_pos
= it
.current
.pos
;
11523 if (PT
< CHARPOS (scroll_margin_pos
))
11525 /* Point is in the scroll margin at the top of the window or
11526 above what is displayed in the window. */
11529 /* Compute the vertical distance from PT to the scroll
11530 margin position. Give up if distance is greater than
11532 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
11533 start_display (&it
, w
, pos
);
11535 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11536 it
.last_visible_y
, -1,
11537 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11538 dy
= it
.current_y
- y0
;
11539 if (dy
> scroll_max
)
11540 return SCROLLING_FAILED
;
11542 /* Compute new window start. */
11543 start_display (&it
, w
, startp
);
11545 if (scroll_conservatively
)
11547 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11548 else if (scroll_step
|| temp_scroll_step
)
11549 amount_to_scroll
= scroll_max
;
11552 aggressive
= current_buffer
->scroll_down_aggressively
;
11553 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11554 if (NUMBERP (aggressive
))
11556 double float_amount
= XFLOATINT (aggressive
) * height
;
11557 amount_to_scroll
= float_amount
;
11558 if (amount_to_scroll
== 0 && float_amount
> 0)
11559 amount_to_scroll
= 1;
11563 if (amount_to_scroll
<= 0)
11564 return SCROLLING_FAILED
;
11566 move_it_vertically_backward (&it
, amount_to_scroll
);
11567 startp
= it
.current
.pos
;
11571 /* Run window scroll functions. */
11572 startp
= run_window_scroll_functions (window
, startp
);
11574 /* Display the window. Give up if new fonts are loaded, or if point
11576 if (!try_window (window
, startp
, 0))
11577 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11578 else if (w
->cursor
.vpos
< 0)
11580 clear_glyph_matrix (w
->desired_matrix
);
11581 rc
= SCROLLING_FAILED
;
11585 /* Maybe forget recorded base line for line number display. */
11586 if (!just_this_one_p
11587 || current_buffer
->clip_changed
11588 || BEG_UNCHANGED
< CHARPOS (startp
))
11589 w
->base_line_number
= Qnil
;
11591 /* If cursor ends up on a partially visible line,
11592 treat that as being off the bottom of the screen. */
11593 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
11595 clear_glyph_matrix (w
->desired_matrix
);
11596 ++extra_scroll_margin_lines
;
11599 rc
= SCROLLING_SUCCESS
;
11606 /* Compute a suitable window start for window W if display of W starts
11607 on a continuation line. Value is non-zero if a new window start
11610 The new window start will be computed, based on W's width, starting
11611 from the start of the continued line. It is the start of the
11612 screen line with the minimum distance from the old start W->start. */
11615 compute_window_start_on_continuation_line (w
)
11618 struct text_pos pos
, start_pos
;
11619 int window_start_changed_p
= 0;
11621 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
11623 /* If window start is on a continuation line... Window start may be
11624 < BEGV in case there's invisible text at the start of the
11625 buffer (M-x rmail, for example). */
11626 if (CHARPOS (start_pos
) > BEGV
11627 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
11630 struct glyph_row
*row
;
11632 /* Handle the case that the window start is out of range. */
11633 if (CHARPOS (start_pos
) < BEGV
)
11634 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
11635 else if (CHARPOS (start_pos
) > ZV
)
11636 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
11638 /* Find the start of the continued line. This should be fast
11639 because scan_buffer is fast (newline cache). */
11640 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
11641 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
11642 row
, DEFAULT_FACE_ID
);
11643 reseat_at_previous_visible_line_start (&it
);
11645 /* If the line start is "too far" away from the window start,
11646 say it takes too much time to compute a new window start. */
11647 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
11648 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
11650 int min_distance
, distance
;
11652 /* Move forward by display lines to find the new window
11653 start. If window width was enlarged, the new start can
11654 be expected to be > the old start. If window width was
11655 decreased, the new window start will be < the old start.
11656 So, we're looking for the display line start with the
11657 minimum distance from the old window start. */
11658 pos
= it
.current
.pos
;
11659 min_distance
= INFINITY
;
11660 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
11661 distance
< min_distance
)
11663 min_distance
= distance
;
11664 pos
= it
.current
.pos
;
11665 move_it_by_lines (&it
, 1, 0);
11668 /* Set the window start there. */
11669 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
11670 window_start_changed_p
= 1;
11674 return window_start_changed_p
;
11678 /* Try cursor movement in case text has not changed in window WINDOW,
11679 with window start STARTP. Value is
11681 CURSOR_MOVEMENT_SUCCESS if successful
11683 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
11685 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
11686 display. *SCROLL_STEP is set to 1, under certain circumstances, if
11687 we want to scroll as if scroll-step were set to 1. See the code.
11689 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
11690 which case we have to abort this redisplay, and adjust matrices
11695 CURSOR_MOVEMENT_SUCCESS
,
11696 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11697 CURSOR_MOVEMENT_MUST_SCROLL
,
11698 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11702 try_cursor_movement (window
, startp
, scroll_step
)
11703 Lisp_Object window
;
11704 struct text_pos startp
;
11707 struct window
*w
= XWINDOW (window
);
11708 struct frame
*f
= XFRAME (w
->frame
);
11709 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11712 if (inhibit_try_cursor_movement
)
11716 /* Handle case where text has not changed, only point, and it has
11717 not moved off the frame. */
11718 if (/* Point may be in this window. */
11719 PT
>= CHARPOS (startp
)
11720 /* Selective display hasn't changed. */
11721 && !current_buffer
->clip_changed
11722 /* Function force-mode-line-update is used to force a thorough
11723 redisplay. It sets either windows_or_buffers_changed or
11724 update_mode_lines. So don't take a shortcut here for these
11726 && !update_mode_lines
11727 && !windows_or_buffers_changed
11728 && !cursor_type_changed
11729 /* Can't use this case if highlighting a region. When a
11730 region exists, cursor movement has to do more than just
11732 && !(!NILP (Vtransient_mark_mode
)
11733 && !NILP (current_buffer
->mark_active
))
11734 && NILP (w
->region_showing
)
11735 && NILP (Vshow_trailing_whitespace
)
11736 /* Right after splitting windows, last_point may be nil. */
11737 && INTEGERP (w
->last_point
)
11738 /* This code is not used for mini-buffer for the sake of the case
11739 of redisplaying to replace an echo area message; since in
11740 that case the mini-buffer contents per se are usually
11741 unchanged. This code is of no real use in the mini-buffer
11742 since the handling of this_line_start_pos, etc., in redisplay
11743 handles the same cases. */
11744 && !EQ (window
, minibuf_window
)
11745 /* When splitting windows or for new windows, it happens that
11746 redisplay is called with a nil window_end_vpos or one being
11747 larger than the window. This should really be fixed in
11748 window.c. I don't have this on my list, now, so we do
11749 approximately the same as the old redisplay code. --gerd. */
11750 && INTEGERP (w
->window_end_vpos
)
11751 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11752 && (FRAME_WINDOW_P (f
)
11753 || !overlay_arrow_in_current_buffer_p ()))
11755 int this_scroll_margin
, top_scroll_margin
;
11756 struct glyph_row
*row
= NULL
;
11759 debug_method_add (w
, "cursor movement");
11762 /* Scroll if point within this distance from the top or bottom
11763 of the window. This is a pixel value. */
11764 this_scroll_margin
= max (0, scroll_margin
);
11765 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11766 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11768 top_scroll_margin
= this_scroll_margin
;
11769 if (WINDOW_WANTS_HEADER_LINE_P (w
))
11770 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
11772 /* Start with the row the cursor was displayed during the last
11773 not paused redisplay. Give up if that row is not valid. */
11774 if (w
->last_cursor
.vpos
< 0
11775 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11776 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11779 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11780 if (row
->mode_line_p
)
11782 if (!row
->enabled_p
)
11783 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11786 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11789 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11791 if (PT
> XFASTINT (w
->last_point
))
11793 /* Point has moved forward. */
11794 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11795 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11797 xassert (row
->enabled_p
);
11801 /* The end position of a row equals the start position
11802 of the next row. If PT is there, we would rather
11803 display it in the next line. */
11804 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11805 && MATRIX_ROW_END_CHARPOS (row
) == PT
11806 && !cursor_row_p (w
, row
))
11809 /* If within the scroll margin, scroll. Note that
11810 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11811 the next line would be drawn, and that
11812 this_scroll_margin can be zero. */
11813 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11814 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11815 /* Line is completely visible last line in window
11816 and PT is to be set in the next line. */
11817 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11818 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11819 && !row
->ends_at_zv_p
11820 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11823 else if (PT
< XFASTINT (w
->last_point
))
11825 /* Cursor has to be moved backward. Note that PT >=
11826 CHARPOS (startp) because of the outer if-statement. */
11827 while (!row
->mode_line_p
11828 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11829 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11830 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
11831 && (row
->y
> top_scroll_margin
11832 || CHARPOS (startp
) == BEGV
))
11834 xassert (row
->enabled_p
);
11838 /* Consider the following case: Window starts at BEGV,
11839 there is invisible, intangible text at BEGV, so that
11840 display starts at some point START > BEGV. It can
11841 happen that we are called with PT somewhere between
11842 BEGV and START. Try to handle that case. */
11843 if (row
< w
->current_matrix
->rows
11844 || row
->mode_line_p
)
11846 row
= w
->current_matrix
->rows
;
11847 if (row
->mode_line_p
)
11851 /* Due to newlines in overlay strings, we may have to
11852 skip forward over overlay strings. */
11853 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11854 && MATRIX_ROW_END_CHARPOS (row
) == PT
11855 && !cursor_row_p (w
, row
))
11858 /* If within the scroll margin, scroll. */
11859 if (row
->y
< top_scroll_margin
11860 && CHARPOS (startp
) != BEGV
)
11865 /* Cursor did not move. So don't scroll even if cursor line
11866 is partially visible, as it was so before. */
11867 rc
= CURSOR_MOVEMENT_SUCCESS
;
11870 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
11871 || PT
> MATRIX_ROW_END_CHARPOS (row
))
11873 /* if PT is not in the glyph row, give up. */
11874 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11876 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
11877 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
11878 && make_cursor_line_fully_visible_p
)
11880 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
11881 && !row
->ends_at_zv_p
11882 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11883 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11884 else if (row
->height
> window_box_height (w
))
11886 /* If we end up in a partially visible line, let's
11887 make it fully visible, except when it's taller
11888 than the window, in which case we can't do much
11891 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11895 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11896 if (!cursor_row_fully_visible_p (w
, 0, 1))
11897 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11899 rc
= CURSOR_MOVEMENT_SUCCESS
;
11903 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11906 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11907 rc
= CURSOR_MOVEMENT_SUCCESS
;
11916 set_vertical_scroll_bar (w
)
11919 int start
, end
, whole
;
11921 /* Calculate the start and end positions for the current window.
11922 At some point, it would be nice to choose between scrollbars
11923 which reflect the whole buffer size, with special markers
11924 indicating narrowing, and scrollbars which reflect only the
11927 Note that mini-buffers sometimes aren't displaying any text. */
11928 if (!MINI_WINDOW_P (w
)
11929 || (w
== XWINDOW (minibuf_window
)
11930 && NILP (echo_area_buffer
[0])))
11932 struct buffer
*buf
= XBUFFER (w
->buffer
);
11933 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
11934 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
11935 /* I don't think this is guaranteed to be right. For the
11936 moment, we'll pretend it is. */
11937 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
11941 if (whole
< (end
- start
))
11942 whole
= end
- start
;
11945 start
= end
= whole
= 0;
11947 /* Indicate what this scroll bar ought to be displaying now. */
11948 if (FRAME_DISPLAY (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
11949 (*FRAME_DISPLAY (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
11950 (w
, end
- start
, whole
, start
);
11954 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
11955 selected_window is redisplayed.
11957 We can return without actually redisplaying the window if
11958 fonts_changed_p is nonzero. In that case, redisplay_internal will
11962 redisplay_window (window
, just_this_one_p
)
11963 Lisp_Object window
;
11964 int just_this_one_p
;
11966 struct window
*w
= XWINDOW (window
);
11967 struct frame
*f
= XFRAME (w
->frame
);
11968 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11969 struct buffer
*old
= current_buffer
;
11970 struct text_pos lpoint
, opoint
, startp
;
11971 int update_mode_line
;
11974 /* Record it now because it's overwritten. */
11975 int current_matrix_up_to_date_p
= 0;
11976 int used_current_matrix_p
= 0;
11977 /* This is less strict than current_matrix_up_to_date_p.
11978 It indictes that the buffer contents and narrowing are unchanged. */
11979 int buffer_unchanged_p
= 0;
11980 int temp_scroll_step
= 0;
11981 int count
= SPECPDL_INDEX ();
11983 int centering_position
= -1;
11984 int last_line_misfit
= 0;
11986 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11989 /* W must be a leaf window here. */
11990 xassert (!NILP (w
->buffer
));
11992 *w
->desired_matrix
->method
= 0;
11995 specbind (Qinhibit_point_motion_hooks
, Qt
);
11997 reconsider_clip_changes (w
, buffer
);
11999 /* Has the mode line to be updated? */
12000 update_mode_line
= (!NILP (w
->update_mode_line
)
12001 || update_mode_lines
12002 || buffer
->clip_changed
12003 || buffer
->prevent_redisplay_optimizations_p
);
12005 if (MINI_WINDOW_P (w
))
12007 if (w
== XWINDOW (echo_area_window
)
12008 && !NILP (echo_area_buffer
[0]))
12010 if (update_mode_line
)
12011 /* We may have to update a tty frame's menu bar or a
12012 tool-bar. Example `M-x C-h C-h C-g'. */
12013 goto finish_menu_bars
;
12015 /* We've already displayed the echo area glyphs in this window. */
12016 goto finish_scroll_bars
;
12018 else if ((w
!= XWINDOW (minibuf_window
)
12019 || minibuf_level
== 0)
12020 /* When buffer is nonempty, redisplay window normally. */
12021 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12022 /* Quail displays non-mini buffers in minibuffer window.
12023 In that case, redisplay the window normally. */
12024 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12026 /* W is a mini-buffer window, but it's not active, so clear
12028 int yb
= window_text_bottom_y (w
);
12029 struct glyph_row
*row
;
12032 for (y
= 0, row
= w
->desired_matrix
->rows
;
12034 y
+= row
->height
, ++row
)
12035 blank_row (w
, row
, y
);
12036 goto finish_scroll_bars
;
12039 clear_glyph_matrix (w
->desired_matrix
);
12042 /* Otherwise set up data on this window; select its buffer and point
12044 /* Really select the buffer, for the sake of buffer-local
12046 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12047 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12049 current_matrix_up_to_date_p
12050 = (!NILP (w
->window_end_valid
)
12051 && !current_buffer
->clip_changed
12052 && !current_buffer
->prevent_redisplay_optimizations_p
12053 && XFASTINT (w
->last_modified
) >= MODIFF
12054 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12057 = (!NILP (w
->window_end_valid
)
12058 && !current_buffer
->clip_changed
12059 && XFASTINT (w
->last_modified
) >= MODIFF
12060 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12062 /* When windows_or_buffers_changed is non-zero, we can't rely on
12063 the window end being valid, so set it to nil there. */
12064 if (windows_or_buffers_changed
)
12066 /* If window starts on a continuation line, maybe adjust the
12067 window start in case the window's width changed. */
12068 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12069 compute_window_start_on_continuation_line (w
);
12071 w
->window_end_valid
= Qnil
;
12074 /* Some sanity checks. */
12075 CHECK_WINDOW_END (w
);
12076 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12078 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12081 /* If %c is in mode line, update it if needed. */
12082 if (!NILP (w
->column_number_displayed
)
12083 /* This alternative quickly identifies a common case
12084 where no change is needed. */
12085 && !(PT
== XFASTINT (w
->last_point
)
12086 && XFASTINT (w
->last_modified
) >= MODIFF
12087 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12088 && (XFASTINT (w
->column_number_displayed
)
12089 != (int) current_column ())) /* iftc */
12090 update_mode_line
= 1;
12092 /* Count number of windows showing the selected buffer. An indirect
12093 buffer counts as its base buffer. */
12094 if (!just_this_one_p
)
12096 struct buffer
*current_base
, *window_base
;
12097 current_base
= current_buffer
;
12098 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12099 if (current_base
->base_buffer
)
12100 current_base
= current_base
->base_buffer
;
12101 if (window_base
->base_buffer
)
12102 window_base
= window_base
->base_buffer
;
12103 if (current_base
== window_base
)
12107 /* Point refers normally to the selected window. For any other
12108 window, set up appropriate value. */
12109 if (!EQ (window
, selected_window
))
12111 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12112 int new_pt_byte
= marker_byte_position (w
->pointm
);
12116 new_pt_byte
= BEGV_BYTE
;
12117 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
12119 else if (new_pt
> (ZV
- 1))
12122 new_pt_byte
= ZV_BYTE
;
12123 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
12126 /* We don't use SET_PT so that the point-motion hooks don't run. */
12127 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
12130 /* If any of the character widths specified in the display table
12131 have changed, invalidate the width run cache. It's true that
12132 this may be a bit late to catch such changes, but the rest of
12133 redisplay goes (non-fatally) haywire when the display table is
12134 changed, so why should we worry about doing any better? */
12135 if (current_buffer
->width_run_cache
)
12137 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
12139 if (! disptab_matches_widthtab (disptab
,
12140 XVECTOR (current_buffer
->width_table
)))
12142 invalidate_region_cache (current_buffer
,
12143 current_buffer
->width_run_cache
,
12145 recompute_width_table (current_buffer
, disptab
);
12149 /* If window-start is screwed up, choose a new one. */
12150 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12153 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12155 /* If someone specified a new starting point but did not insist,
12156 check whether it can be used. */
12157 if (!NILP (w
->optional_new_start
)
12158 && CHARPOS (startp
) >= BEGV
12159 && CHARPOS (startp
) <= ZV
)
12161 w
->optional_new_start
= Qnil
;
12162 start_display (&it
, w
, startp
);
12163 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12164 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12165 if (IT_CHARPOS (it
) == PT
)
12166 w
->force_start
= Qt
;
12167 /* IT may overshoot PT if text at PT is invisible. */
12168 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12169 w
->force_start
= Qt
;
12174 /* Handle case where place to start displaying has been specified,
12175 unless the specified location is outside the accessible range. */
12176 if (!NILP (w
->force_start
)
12177 || w
->frozen_window_start_p
)
12179 /* We set this later on if we have to adjust point. */
12183 w
->force_start
= Qnil
;
12185 w
->window_end_valid
= Qnil
;
12187 /* Forget any recorded base line for line number display. */
12188 if (!buffer_unchanged_p
)
12189 w
->base_line_number
= Qnil
;
12191 /* Redisplay the mode line. Select the buffer properly for that.
12192 Also, run the hook window-scroll-functions
12193 because we have scrolled. */
12194 /* Note, we do this after clearing force_start because
12195 if there's an error, it is better to forget about force_start
12196 than to get into an infinite loop calling the hook functions
12197 and having them get more errors. */
12198 if (!update_mode_line
12199 || ! NILP (Vwindow_scroll_functions
))
12201 update_mode_line
= 1;
12202 w
->update_mode_line
= Qt
;
12203 startp
= run_window_scroll_functions (window
, startp
);
12206 w
->last_modified
= make_number (0);
12207 w
->last_overlay_modified
= make_number (0);
12208 if (CHARPOS (startp
) < BEGV
)
12209 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
12210 else if (CHARPOS (startp
) > ZV
)
12211 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12213 /* Redisplay, then check if cursor has been set during the
12214 redisplay. Give up if new fonts were loaded. */
12215 val
= try_window (window
, startp
, 1);
12218 w
->force_start
= Qt
;
12219 clear_glyph_matrix (w
->desired_matrix
);
12220 goto need_larger_matrices
;
12222 /* Point was outside the scroll margins. */
12224 new_vpos
= window_box_height (w
) / 2;
12226 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12228 /* If point does not appear, try to move point so it does
12229 appear. The desired matrix has been built above, so we
12230 can use it here. */
12231 new_vpos
= window_box_height (w
) / 2;
12234 if (!cursor_row_fully_visible_p (w
, 0, 0))
12236 /* Point does appear, but on a line partly visible at end of window.
12237 Move it back to a fully-visible line. */
12238 new_vpos
= window_box_height (w
);
12241 /* If we need to move point for either of the above reasons,
12242 now actually do it. */
12245 struct glyph_row
*row
;
12247 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
12248 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
12251 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
12252 MATRIX_ROW_START_BYTEPOS (row
));
12254 if (w
!= XWINDOW (selected_window
))
12255 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
12256 else if (current_buffer
== old
)
12257 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12259 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
12261 /* If we are highlighting the region, then we just changed
12262 the region, so redisplay to show it. */
12263 if (!NILP (Vtransient_mark_mode
)
12264 && !NILP (current_buffer
->mark_active
))
12266 clear_glyph_matrix (w
->desired_matrix
);
12267 if (!try_window (window
, startp
, 0))
12268 goto need_larger_matrices
;
12273 debug_method_add (w
, "forced window start");
12278 /* Handle case where text has not changed, only point, and it has
12279 not moved off the frame, and we are not retrying after hscroll.
12280 (current_matrix_up_to_date_p is nonzero when retrying.) */
12281 if (current_matrix_up_to_date_p
12282 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
12283 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
12287 case CURSOR_MOVEMENT_SUCCESS
:
12288 used_current_matrix_p
= 1;
12291 #if 0 /* try_cursor_movement never returns this value. */
12292 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
12293 goto need_larger_matrices
;
12296 case CURSOR_MOVEMENT_MUST_SCROLL
:
12297 goto try_to_scroll
;
12303 /* If current starting point was originally the beginning of a line
12304 but no longer is, find a new starting point. */
12305 else if (!NILP (w
->start_at_line_beg
)
12306 && !(CHARPOS (startp
) <= BEGV
12307 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
12310 debug_method_add (w
, "recenter 1");
12315 /* Try scrolling with try_window_id. Value is > 0 if update has
12316 been done, it is -1 if we know that the same window start will
12317 not work. It is 0 if unsuccessful for some other reason. */
12318 else if ((tem
= try_window_id (w
)) != 0)
12321 debug_method_add (w
, "try_window_id %d", tem
);
12324 if (fonts_changed_p
)
12325 goto need_larger_matrices
;
12329 /* Otherwise try_window_id has returned -1 which means that we
12330 don't want the alternative below this comment to execute. */
12332 else if (CHARPOS (startp
) >= BEGV
12333 && CHARPOS (startp
) <= ZV
12334 && PT
>= CHARPOS (startp
)
12335 && (CHARPOS (startp
) < ZV
12336 /* Avoid starting at end of buffer. */
12337 || CHARPOS (startp
) == BEGV
12338 || (XFASTINT (w
->last_modified
) >= MODIFF
12339 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
12342 debug_method_add (w
, "same window start");
12345 /* Try to redisplay starting at same place as before.
12346 If point has not moved off frame, accept the results. */
12347 if (!current_matrix_up_to_date_p
12348 /* Don't use try_window_reusing_current_matrix in this case
12349 because a window scroll function can have changed the
12351 || !NILP (Vwindow_scroll_functions
)
12352 || MINI_WINDOW_P (w
)
12353 || !(used_current_matrix_p
12354 = try_window_reusing_current_matrix (w
)))
12356 IF_DEBUG (debug_method_add (w
, "1"));
12357 if (try_window (window
, startp
, 1) < 0)
12358 /* -1 means we need to scroll.
12359 0 means we need new matrices, but fonts_changed_p
12360 is set in that case, so we will detect it below. */
12361 goto try_to_scroll
;
12364 if (fonts_changed_p
)
12365 goto need_larger_matrices
;
12367 if (w
->cursor
.vpos
>= 0)
12369 if (!just_this_one_p
12370 || current_buffer
->clip_changed
12371 || BEG_UNCHANGED
< CHARPOS (startp
))
12372 /* Forget any recorded base line for line number display. */
12373 w
->base_line_number
= Qnil
;
12375 if (!cursor_row_fully_visible_p (w
, 1, 0))
12377 clear_glyph_matrix (w
->desired_matrix
);
12378 last_line_misfit
= 1;
12380 /* Drop through and scroll. */
12385 clear_glyph_matrix (w
->desired_matrix
);
12390 w
->last_modified
= make_number (0);
12391 w
->last_overlay_modified
= make_number (0);
12393 /* Redisplay the mode line. Select the buffer properly for that. */
12394 if (!update_mode_line
)
12396 update_mode_line
= 1;
12397 w
->update_mode_line
= Qt
;
12400 /* Try to scroll by specified few lines. */
12401 if ((scroll_conservatively
12403 || temp_scroll_step
12404 || NUMBERP (current_buffer
->scroll_up_aggressively
)
12405 || NUMBERP (current_buffer
->scroll_down_aggressively
))
12406 && !current_buffer
->clip_changed
12407 && CHARPOS (startp
) >= BEGV
12408 && CHARPOS (startp
) <= ZV
)
12410 /* The function returns -1 if new fonts were loaded, 1 if
12411 successful, 0 if not successful. */
12412 int rc
= try_scrolling (window
, just_this_one_p
,
12413 scroll_conservatively
,
12415 temp_scroll_step
, last_line_misfit
);
12418 case SCROLLING_SUCCESS
:
12421 case SCROLLING_NEED_LARGER_MATRICES
:
12422 goto need_larger_matrices
;
12424 case SCROLLING_FAILED
:
12432 /* Finally, just choose place to start which centers point */
12435 if (centering_position
< 0)
12436 centering_position
= window_box_height (w
) / 2;
12439 debug_method_add (w
, "recenter");
12442 /* w->vscroll = 0; */
12444 /* Forget any previously recorded base line for line number display. */
12445 if (!buffer_unchanged_p
)
12446 w
->base_line_number
= Qnil
;
12448 /* Move backward half the height of the window. */
12449 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12450 it
.current_y
= it
.last_visible_y
;
12451 move_it_vertically_backward (&it
, centering_position
);
12452 xassert (IT_CHARPOS (it
) >= BEGV
);
12454 /* The function move_it_vertically_backward may move over more
12455 than the specified y-distance. If it->w is small, e.g. a
12456 mini-buffer window, we may end up in front of the window's
12457 display area. Start displaying at the start of the line
12458 containing PT in this case. */
12459 if (it
.current_y
<= 0)
12461 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12462 move_it_vertically_backward (&it
, 0);
12464 /* I think this assert is bogus if buffer contains
12465 invisible text or images. KFS. */
12466 xassert (IT_CHARPOS (it
) <= PT
);
12471 it
.current_x
= it
.hpos
= 0;
12473 /* Set startp here explicitly in case that helps avoid an infinite loop
12474 in case the window-scroll-functions functions get errors. */
12475 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
12477 /* Run scroll hooks. */
12478 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
12480 /* Redisplay the window. */
12481 if (!current_matrix_up_to_date_p
12482 || windows_or_buffers_changed
12483 || cursor_type_changed
12484 /* Don't use try_window_reusing_current_matrix in this case
12485 because it can have changed the buffer. */
12486 || !NILP (Vwindow_scroll_functions
)
12487 || !just_this_one_p
12488 || MINI_WINDOW_P (w
)
12489 || !(used_current_matrix_p
12490 = try_window_reusing_current_matrix (w
)))
12491 try_window (window
, startp
, 0);
12493 /* If new fonts have been loaded (due to fontsets), give up. We
12494 have to start a new redisplay since we need to re-adjust glyph
12496 if (fonts_changed_p
)
12497 goto need_larger_matrices
;
12499 /* If cursor did not appear assume that the middle of the window is
12500 in the first line of the window. Do it again with the next line.
12501 (Imagine a window of height 100, displaying two lines of height
12502 60. Moving back 50 from it->last_visible_y will end in the first
12504 if (w
->cursor
.vpos
< 0)
12506 if (!NILP (w
->window_end_valid
)
12507 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
12509 clear_glyph_matrix (w
->desired_matrix
);
12510 move_it_by_lines (&it
, 1, 0);
12511 try_window (window
, it
.current
.pos
, 0);
12513 else if (PT
< IT_CHARPOS (it
))
12515 clear_glyph_matrix (w
->desired_matrix
);
12516 move_it_by_lines (&it
, -1, 0);
12517 try_window (window
, it
.current
.pos
, 0);
12521 /* Not much we can do about it. */
12525 /* Consider the following case: Window starts at BEGV, there is
12526 invisible, intangible text at BEGV, so that display starts at
12527 some point START > BEGV. It can happen that we are called with
12528 PT somewhere between BEGV and START. Try to handle that case. */
12529 if (w
->cursor
.vpos
< 0)
12531 struct glyph_row
*row
= w
->current_matrix
->rows
;
12532 if (row
->mode_line_p
)
12534 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12537 if (!cursor_row_fully_visible_p (w
, 0, 0))
12539 /* If vscroll is enabled, disable it and try again. */
12543 clear_glyph_matrix (w
->desired_matrix
);
12547 /* If centering point failed to make the whole line visible,
12548 put point at the top instead. That has to make the whole line
12549 visible, if it can be done. */
12550 if (centering_position
== 0)
12553 clear_glyph_matrix (w
->desired_matrix
);
12554 centering_position
= 0;
12560 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12561 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
12562 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
12565 /* Display the mode line, if we must. */
12566 if ((update_mode_line
12567 /* If window not full width, must redo its mode line
12568 if (a) the window to its side is being redone and
12569 (b) we do a frame-based redisplay. This is a consequence
12570 of how inverted lines are drawn in frame-based redisplay. */
12571 || (!just_this_one_p
12572 && !FRAME_WINDOW_P (f
)
12573 && !WINDOW_FULL_WIDTH_P (w
))
12574 /* Line number to display. */
12575 || INTEGERP (w
->base_line_pos
)
12576 /* Column number is displayed and different from the one displayed. */
12577 || (!NILP (w
->column_number_displayed
)
12578 && (XFASTINT (w
->column_number_displayed
)
12579 != (int) current_column ()))) /* iftc */
12580 /* This means that the window has a mode line. */
12581 && (WINDOW_WANTS_MODELINE_P (w
)
12582 || WINDOW_WANTS_HEADER_LINE_P (w
)))
12584 display_mode_lines (w
);
12586 /* If mode line height has changed, arrange for a thorough
12587 immediate redisplay using the correct mode line height. */
12588 if (WINDOW_WANTS_MODELINE_P (w
)
12589 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12591 fonts_changed_p
= 1;
12592 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12593 = DESIRED_MODE_LINE_HEIGHT (w
);
12596 /* If top line height has changed, arrange for a thorough
12597 immediate redisplay using the correct mode line height. */
12598 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12599 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
12601 fonts_changed_p
= 1;
12602 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
12603 = DESIRED_HEADER_LINE_HEIGHT (w
);
12606 if (fonts_changed_p
)
12607 goto need_larger_matrices
;
12610 if (!line_number_displayed
12611 && !BUFFERP (w
->base_line_pos
))
12613 w
->base_line_pos
= Qnil
;
12614 w
->base_line_number
= Qnil
;
12619 /* When we reach a frame's selected window, redo the frame's menu bar. */
12620 if (update_mode_line
12621 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
12623 int redisplay_menu_p
= 0;
12624 int redisplay_tool_bar_p
= 0;
12626 if (FRAME_WINDOW_P (f
))
12628 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
12629 || defined (USE_GTK)
12630 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
12632 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12636 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12638 if (redisplay_menu_p
)
12639 display_menu_bar (w
);
12641 #ifdef HAVE_WINDOW_SYSTEM
12642 if (FRAME_WINDOW_P (f
))
12645 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
12647 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
12648 && (FRAME_TOOL_BAR_LINES (f
) > 0
12649 || auto_resize_tool_bars_p
);
12652 if (redisplay_tool_bar_p
)
12653 redisplay_tool_bar (f
);
12658 #ifdef HAVE_WINDOW_SYSTEM
12659 if (FRAME_WINDOW_P (f
)
12660 && update_window_fringes (w
, 0)
12661 && !just_this_one_p
12662 && (used_current_matrix_p
|| overlay_arrow_seen
)
12663 && !w
->pseudo_window_p
)
12667 if (draw_window_fringes (w
, 1))
12668 x_draw_vertical_border (w
);
12672 #endif /* HAVE_WINDOW_SYSTEM */
12674 /* We go to this label, with fonts_changed_p nonzero,
12675 if it is necessary to try again using larger glyph matrices.
12676 We have to redeem the scroll bar even in this case,
12677 because the loop in redisplay_internal expects that. */
12678 need_larger_matrices
:
12680 finish_scroll_bars
:
12682 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
12684 /* Set the thumb's position and size. */
12685 set_vertical_scroll_bar (w
);
12687 /* Note that we actually used the scroll bar attached to this
12688 window, so it shouldn't be deleted at the end of redisplay. */
12689 if (FRAME_DISPLAY (f
)->redeem_scroll_bar_hook
)
12690 (*FRAME_DISPLAY (f
)->redeem_scroll_bar_hook
) (w
);
12693 /* Restore current_buffer and value of point in it. */
12694 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
12695 set_buffer_internal_1 (old
);
12696 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12698 unbind_to (count
, Qnil
);
12702 /* Build the complete desired matrix of WINDOW with a window start
12703 buffer position POS.
12705 Value is 1 if successful. It is zero if fonts were loaded during
12706 redisplay which makes re-adjusting glyph matrices necessary, and -1
12707 if point would appear in the scroll margins.
12708 (We check that only if CHECK_MARGINS is nonzero. */
12711 try_window (window
, pos
, check_margins
)
12712 Lisp_Object window
;
12713 struct text_pos pos
;
12716 struct window
*w
= XWINDOW (window
);
12718 struct glyph_row
*last_text_row
= NULL
;
12720 /* Make POS the new window start. */
12721 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
12723 /* Mark cursor position as unknown. No overlay arrow seen. */
12724 w
->cursor
.vpos
= -1;
12725 overlay_arrow_seen
= 0;
12727 /* Initialize iterator and info to start at POS. */
12728 start_display (&it
, w
, pos
);
12730 /* Display all lines of W. */
12731 while (it
.current_y
< it
.last_visible_y
)
12733 if (display_line (&it
))
12734 last_text_row
= it
.glyph_row
- 1;
12735 if (fonts_changed_p
)
12739 /* Don't let the cursor end in the scroll margins. */
12742 int this_scroll_margin
, cursor_height
;
12744 this_scroll_margin
= max (0, scroll_margin
);
12745 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12746 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
12747 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
12749 if ((w
->cursor
.y
< this_scroll_margin
12750 && CHARPOS (pos
) > BEGV
)
12751 /* rms: considering make_cursor_line_fully_visible_p here
12752 seems to give wrong results. We don't want to recenter
12753 when the last line is partly visible, we want to allow
12754 that case to be handled in the usual way. */
12755 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
12757 w
->cursor
.vpos
= -1;
12758 clear_glyph_matrix (w
->desired_matrix
);
12763 /* If bottom moved off end of frame, change mode line percentage. */
12764 if (XFASTINT (w
->window_end_pos
) <= 0
12765 && Z
!= IT_CHARPOS (it
))
12766 w
->update_mode_line
= Qt
;
12768 /* Set window_end_pos to the offset of the last character displayed
12769 on the window from the end of current_buffer. Set
12770 window_end_vpos to its row number. */
12773 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
12774 w
->window_end_bytepos
12775 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12777 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12779 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12780 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12781 ->displays_text_p
);
12785 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12786 w
->window_end_pos
= make_number (Z
- ZV
);
12787 w
->window_end_vpos
= make_number (0);
12790 /* But that is not valid info until redisplay finishes. */
12791 w
->window_end_valid
= Qnil
;
12797 /************************************************************************
12798 Window redisplay reusing current matrix when buffer has not changed
12799 ************************************************************************/
12801 /* Try redisplay of window W showing an unchanged buffer with a
12802 different window start than the last time it was displayed by
12803 reusing its current matrix. Value is non-zero if successful.
12804 W->start is the new window start. */
12807 try_window_reusing_current_matrix (w
)
12810 struct frame
*f
= XFRAME (w
->frame
);
12811 struct glyph_row
*row
, *bottom_row
;
12814 struct text_pos start
, new_start
;
12815 int nrows_scrolled
, i
;
12816 struct glyph_row
*last_text_row
;
12817 struct glyph_row
*last_reused_text_row
;
12818 struct glyph_row
*start_row
;
12819 int start_vpos
, min_y
, max_y
;
12822 if (inhibit_try_window_reusing
)
12826 if (/* This function doesn't handle terminal frames. */
12827 !FRAME_WINDOW_P (f
)
12828 /* Don't try to reuse the display if windows have been split
12830 || windows_or_buffers_changed
12831 || cursor_type_changed
)
12834 /* Can't do this if region may have changed. */
12835 if ((!NILP (Vtransient_mark_mode
)
12836 && !NILP (current_buffer
->mark_active
))
12837 || !NILP (w
->region_showing
)
12838 || !NILP (Vshow_trailing_whitespace
))
12841 /* If top-line visibility has changed, give up. */
12842 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12843 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12846 /* Give up if old or new display is scrolled vertically. We could
12847 make this function handle this, but right now it doesn't. */
12848 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12849 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
12852 /* The variable new_start now holds the new window start. The old
12853 start `start' can be determined from the current matrix. */
12854 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
12855 start
= start_row
->start
.pos
;
12856 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12858 /* Clear the desired matrix for the display below. */
12859 clear_glyph_matrix (w
->desired_matrix
);
12861 if (CHARPOS (new_start
) <= CHARPOS (start
))
12865 /* Don't use this method if the display starts with an ellipsis
12866 displayed for invisible text. It's not easy to handle that case
12867 below, and it's certainly not worth the effort since this is
12868 not a frequent case. */
12869 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
12872 IF_DEBUG (debug_method_add (w
, "twu1"));
12874 /* Display up to a row that can be reused. The variable
12875 last_text_row is set to the last row displayed that displays
12876 text. Note that it.vpos == 0 if or if not there is a
12877 header-line; it's not the same as the MATRIX_ROW_VPOS! */
12878 start_display (&it
, w
, new_start
);
12879 first_row_y
= it
.current_y
;
12880 w
->cursor
.vpos
= -1;
12881 last_text_row
= last_reused_text_row
= NULL
;
12883 while (it
.current_y
< it
.last_visible_y
12884 && !fonts_changed_p
)
12886 /* If we have reached into the characters in the START row,
12887 that means the line boundaries have changed. So we
12888 can't start copying with the row START. Maybe it will
12889 work to start copying with the following row. */
12890 while (IT_CHARPOS (it
) > CHARPOS (start
))
12892 /* Advance to the next row as the "start". */
12894 start
= start_row
->start
.pos
;
12895 /* If there are no more rows to try, or just one, give up. */
12896 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
12897 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
12898 || CHARPOS (start
) == ZV
)
12900 clear_glyph_matrix (w
->desired_matrix
);
12904 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12906 /* If we have reached alignment,
12907 we can copy the rest of the rows. */
12908 if (IT_CHARPOS (it
) == CHARPOS (start
))
12911 if (display_line (&it
))
12912 last_text_row
= it
.glyph_row
- 1;
12915 /* A value of current_y < last_visible_y means that we stopped
12916 at the previous window start, which in turn means that we
12917 have at least one reusable row. */
12918 if (it
.current_y
< it
.last_visible_y
)
12920 /* IT.vpos always starts from 0; it counts text lines. */
12921 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
12923 /* Find PT if not already found in the lines displayed. */
12924 if (w
->cursor
.vpos
< 0)
12926 int dy
= it
.current_y
- start_row
->y
;
12928 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12929 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
12931 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
12932 dy
, nrows_scrolled
);
12935 clear_glyph_matrix (w
->desired_matrix
);
12940 /* Scroll the display. Do it before the current matrix is
12941 changed. The problem here is that update has not yet
12942 run, i.e. part of the current matrix is not up to date.
12943 scroll_run_hook will clear the cursor, and use the
12944 current matrix to get the height of the row the cursor is
12946 run
.current_y
= start_row
->y
;
12947 run
.desired_y
= it
.current_y
;
12948 run
.height
= it
.last_visible_y
- it
.current_y
;
12950 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
12953 FRAME_RIF (f
)->update_window_begin_hook (w
);
12954 FRAME_RIF (f
)->clear_window_mouse_face (w
);
12955 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
12956 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
12960 /* Shift current matrix down by nrows_scrolled lines. */
12961 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12962 rotate_matrix (w
->current_matrix
,
12964 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12967 /* Disable lines that must be updated. */
12968 for (i
= 0; i
< it
.vpos
; ++i
)
12969 (start_row
+ i
)->enabled_p
= 0;
12971 /* Re-compute Y positions. */
12972 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12973 max_y
= it
.last_visible_y
;
12974 for (row
= start_row
+ nrows_scrolled
;
12978 row
->y
= it
.current_y
;
12979 row
->visible_height
= row
->height
;
12981 if (row
->y
< min_y
)
12982 row
->visible_height
-= min_y
- row
->y
;
12983 if (row
->y
+ row
->height
> max_y
)
12984 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12985 row
->redraw_fringe_bitmaps_p
= 1;
12987 it
.current_y
+= row
->height
;
12989 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12990 last_reused_text_row
= row
;
12991 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
12995 /* Disable lines in the current matrix which are now
12996 below the window. */
12997 for (++row
; row
< bottom_row
; ++row
)
12998 row
->enabled_p
= 0;
13001 /* Update window_end_pos etc.; last_reused_text_row is the last
13002 reused row from the current matrix containing text, if any.
13003 The value of last_text_row is the last displayed line
13004 containing text. */
13005 if (last_reused_text_row
)
13007 w
->window_end_bytepos
13008 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13010 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13012 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13013 w
->current_matrix
));
13015 else if (last_text_row
)
13017 w
->window_end_bytepos
13018 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13020 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13022 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13026 /* This window must be completely empty. */
13027 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13028 w
->window_end_pos
= make_number (Z
- ZV
);
13029 w
->window_end_vpos
= make_number (0);
13031 w
->window_end_valid
= Qnil
;
13033 /* Update hint: don't try scrolling again in update_window. */
13034 w
->desired_matrix
->no_scrolling_p
= 1;
13037 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13041 else if (CHARPOS (new_start
) > CHARPOS (start
))
13043 struct glyph_row
*pt_row
, *row
;
13044 struct glyph_row
*first_reusable_row
;
13045 struct glyph_row
*first_row_to_display
;
13047 int yb
= window_text_bottom_y (w
);
13049 /* Find the row starting at new_start, if there is one. Don't
13050 reuse a partially visible line at the end. */
13051 first_reusable_row
= start_row
;
13052 while (first_reusable_row
->enabled_p
13053 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13054 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13055 < CHARPOS (new_start
)))
13056 ++first_reusable_row
;
13058 /* Give up if there is no row to reuse. */
13059 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13060 || !first_reusable_row
->enabled_p
13061 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13062 != CHARPOS (new_start
)))
13065 /* We can reuse fully visible rows beginning with
13066 first_reusable_row to the end of the window. Set
13067 first_row_to_display to the first row that cannot be reused.
13068 Set pt_row to the row containing point, if there is any. */
13070 for (first_row_to_display
= first_reusable_row
;
13071 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13072 ++first_row_to_display
)
13074 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13075 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13076 pt_row
= first_row_to_display
;
13079 /* Start displaying at the start of first_row_to_display. */
13080 xassert (first_row_to_display
->y
< yb
);
13081 init_to_row_start (&it
, w
, first_row_to_display
);
13083 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
13085 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
13087 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
13088 + WINDOW_HEADER_LINE_HEIGHT (w
));
13090 /* Display lines beginning with first_row_to_display in the
13091 desired matrix. Set last_text_row to the last row displayed
13092 that displays text. */
13093 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
13094 if (pt_row
== NULL
)
13095 w
->cursor
.vpos
= -1;
13096 last_text_row
= NULL
;
13097 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
13098 if (display_line (&it
))
13099 last_text_row
= it
.glyph_row
- 1;
13101 /* Give up If point isn't in a row displayed or reused. */
13102 if (w
->cursor
.vpos
< 0)
13104 clear_glyph_matrix (w
->desired_matrix
);
13108 /* If point is in a reused row, adjust y and vpos of the cursor
13112 w
->cursor
.vpos
-= nrows_scrolled
;
13113 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
13116 /* Scroll the display. */
13117 run
.current_y
= first_reusable_row
->y
;
13118 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13119 run
.height
= it
.last_visible_y
- run
.current_y
;
13120 dy
= run
.current_y
- run
.desired_y
;
13125 FRAME_RIF (f
)->update_window_begin_hook (w
);
13126 FRAME_RIF (f
)->clear_window_mouse_face (w
);
13127 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
13128 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
13132 /* Adjust Y positions of reused rows. */
13133 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13134 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13135 max_y
= it
.last_visible_y
;
13136 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
13139 row
->visible_height
= row
->height
;
13140 if (row
->y
< min_y
)
13141 row
->visible_height
-= min_y
- row
->y
;
13142 if (row
->y
+ row
->height
> max_y
)
13143 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13144 row
->redraw_fringe_bitmaps_p
= 1;
13147 /* Scroll the current matrix. */
13148 xassert (nrows_scrolled
> 0);
13149 rotate_matrix (w
->current_matrix
,
13151 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13154 /* Disable rows not reused. */
13155 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
13156 row
->enabled_p
= 0;
13158 /* Point may have moved to a different line, so we cannot assume that
13159 the previous cursor position is valid; locate the correct row. */
13162 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
13163 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
13167 w
->cursor
.y
= row
->y
;
13169 if (row
< bottom_row
)
13171 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
13172 while (glyph
->charpos
< PT
)
13175 w
->cursor
.x
+= glyph
->pixel_width
;
13181 /* Adjust window end. A null value of last_text_row means that
13182 the window end is in reused rows which in turn means that
13183 only its vpos can have changed. */
13186 w
->window_end_bytepos
13187 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13189 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13191 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13196 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
13199 w
->window_end_valid
= Qnil
;
13200 w
->desired_matrix
->no_scrolling_p
= 1;
13203 debug_method_add (w
, "try_window_reusing_current_matrix 2");
13213 /************************************************************************
13214 Window redisplay reusing current matrix when buffer has changed
13215 ************************************************************************/
13217 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
13218 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
13220 static struct glyph_row
*
13221 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
13222 struct glyph_row
*));
13225 /* Return the last row in MATRIX displaying text. If row START is
13226 non-null, start searching with that row. IT gives the dimensions
13227 of the display. Value is null if matrix is empty; otherwise it is
13228 a pointer to the row found. */
13230 static struct glyph_row
*
13231 find_last_row_displaying_text (matrix
, it
, start
)
13232 struct glyph_matrix
*matrix
;
13234 struct glyph_row
*start
;
13236 struct glyph_row
*row
, *row_found
;
13238 /* Set row_found to the last row in IT->w's current matrix
13239 displaying text. The loop looks funny but think of partially
13242 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
13243 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13245 xassert (row
->enabled_p
);
13247 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
13256 /* Return the last row in the current matrix of W that is not affected
13257 by changes at the start of current_buffer that occurred since W's
13258 current matrix was built. Value is null if no such row exists.
13260 BEG_UNCHANGED us the number of characters unchanged at the start of
13261 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
13262 first changed character in current_buffer. Characters at positions <
13263 BEG + BEG_UNCHANGED are at the same buffer positions as they were
13264 when the current matrix was built. */
13266 static struct glyph_row
*
13267 find_last_unchanged_at_beg_row (w
)
13270 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
13271 struct glyph_row
*row
;
13272 struct glyph_row
*row_found
= NULL
;
13273 int yb
= window_text_bottom_y (w
);
13275 /* Find the last row displaying unchanged text. */
13276 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13277 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13278 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
13280 if (/* If row ends before first_changed_pos, it is unchanged,
13281 except in some case. */
13282 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
13283 /* When row ends in ZV and we write at ZV it is not
13285 && !row
->ends_at_zv_p
13286 /* When first_changed_pos is the end of a continued line,
13287 row is not unchanged because it may be no longer
13289 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
13290 && (row
->continued_p
13291 || row
->exact_window_width_line_p
)))
13294 /* Stop if last visible row. */
13295 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
13305 /* Find the first glyph row in the current matrix of W that is not
13306 affected by changes at the end of current_buffer since the
13307 time W's current matrix was built.
13309 Return in *DELTA the number of chars by which buffer positions in
13310 unchanged text at the end of current_buffer must be adjusted.
13312 Return in *DELTA_BYTES the corresponding number of bytes.
13314 Value is null if no such row exists, i.e. all rows are affected by
13317 static struct glyph_row
*
13318 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
13320 int *delta
, *delta_bytes
;
13322 struct glyph_row
*row
;
13323 struct glyph_row
*row_found
= NULL
;
13325 *delta
= *delta_bytes
= 0;
13327 /* Display must not have been paused, otherwise the current matrix
13328 is not up to date. */
13329 if (NILP (w
->window_end_valid
))
13332 /* A value of window_end_pos >= END_UNCHANGED means that the window
13333 end is in the range of changed text. If so, there is no
13334 unchanged row at the end of W's current matrix. */
13335 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
13338 /* Set row to the last row in W's current matrix displaying text. */
13339 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13341 /* If matrix is entirely empty, no unchanged row exists. */
13342 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13344 /* The value of row is the last glyph row in the matrix having a
13345 meaningful buffer position in it. The end position of row
13346 corresponds to window_end_pos. This allows us to translate
13347 buffer positions in the current matrix to current buffer
13348 positions for characters not in changed text. */
13349 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13350 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13351 int last_unchanged_pos
, last_unchanged_pos_old
;
13352 struct glyph_row
*first_text_row
13353 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13355 *delta
= Z
- Z_old
;
13356 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13358 /* Set last_unchanged_pos to the buffer position of the last
13359 character in the buffer that has not been changed. Z is the
13360 index + 1 of the last character in current_buffer, i.e. by
13361 subtracting END_UNCHANGED we get the index of the last
13362 unchanged character, and we have to add BEG to get its buffer
13364 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
13365 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
13367 /* Search backward from ROW for a row displaying a line that
13368 starts at a minimum position >= last_unchanged_pos_old. */
13369 for (; row
> first_text_row
; --row
)
13371 /* This used to abort, but it can happen.
13372 It is ok to just stop the search instead here. KFS. */
13373 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13376 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
13381 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
13388 /* Make sure that glyph rows in the current matrix of window W
13389 reference the same glyph memory as corresponding rows in the
13390 frame's frame matrix. This function is called after scrolling W's
13391 current matrix on a terminal frame in try_window_id and
13392 try_window_reusing_current_matrix. */
13395 sync_frame_with_window_matrix_rows (w
)
13398 struct frame
*f
= XFRAME (w
->frame
);
13399 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
13401 /* Preconditions: W must be a leaf window and full-width. Its frame
13402 must have a frame matrix. */
13403 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
13404 xassert (WINDOW_FULL_WIDTH_P (w
));
13405 xassert (!FRAME_WINDOW_P (f
));
13407 /* If W is a full-width window, glyph pointers in W's current matrix
13408 have, by definition, to be the same as glyph pointers in the
13409 corresponding frame matrix. Note that frame matrices have no
13410 marginal areas (see build_frame_matrix). */
13411 window_row
= w
->current_matrix
->rows
;
13412 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
13413 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
13414 while (window_row
< window_row_end
)
13416 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
13417 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
13419 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
13420 frame_row
->glyphs
[TEXT_AREA
] = start
;
13421 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
13422 frame_row
->glyphs
[LAST_AREA
] = end
;
13424 /* Disable frame rows whose corresponding window rows have
13425 been disabled in try_window_id. */
13426 if (!window_row
->enabled_p
)
13427 frame_row
->enabled_p
= 0;
13429 ++window_row
, ++frame_row
;
13434 /* Find the glyph row in window W containing CHARPOS. Consider all
13435 rows between START and END (not inclusive). END null means search
13436 all rows to the end of the display area of W. Value is the row
13437 containing CHARPOS or null. */
13440 row_containing_pos (w
, charpos
, start
, end
, dy
)
13443 struct glyph_row
*start
, *end
;
13446 struct glyph_row
*row
= start
;
13449 /* If we happen to start on a header-line, skip that. */
13450 if (row
->mode_line_p
)
13453 if ((end
&& row
>= end
) || !row
->enabled_p
)
13456 last_y
= window_text_bottom_y (w
) - dy
;
13460 /* Give up if we have gone too far. */
13461 if (end
&& row
>= end
)
13463 /* This formerly returned if they were equal.
13464 I think that both quantities are of a "last plus one" type;
13465 if so, when they are equal, the row is within the screen. -- rms. */
13466 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
13469 /* If it is in this row, return this row. */
13470 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
13471 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
13472 /* The end position of a row equals the start
13473 position of the next row. If CHARPOS is there, we
13474 would rather display it in the next line, except
13475 when this line ends in ZV. */
13476 && !row
->ends_at_zv_p
13477 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13478 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
13485 /* Try to redisplay window W by reusing its existing display. W's
13486 current matrix must be up to date when this function is called,
13487 i.e. window_end_valid must not be nil.
13491 1 if display has been updated
13492 0 if otherwise unsuccessful
13493 -1 if redisplay with same window start is known not to succeed
13495 The following steps are performed:
13497 1. Find the last row in the current matrix of W that is not
13498 affected by changes at the start of current_buffer. If no such row
13501 2. Find the first row in W's current matrix that is not affected by
13502 changes at the end of current_buffer. Maybe there is no such row.
13504 3. Display lines beginning with the row + 1 found in step 1 to the
13505 row found in step 2 or, if step 2 didn't find a row, to the end of
13508 4. If cursor is not known to appear on the window, give up.
13510 5. If display stopped at the row found in step 2, scroll the
13511 display and current matrix as needed.
13513 6. Maybe display some lines at the end of W, if we must. This can
13514 happen under various circumstances, like a partially visible line
13515 becoming fully visible, or because newly displayed lines are displayed
13516 in smaller font sizes.
13518 7. Update W's window end information. */
13524 struct frame
*f
= XFRAME (w
->frame
);
13525 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
13526 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
13527 struct glyph_row
*last_unchanged_at_beg_row
;
13528 struct glyph_row
*first_unchanged_at_end_row
;
13529 struct glyph_row
*row
;
13530 struct glyph_row
*bottom_row
;
13533 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
13534 struct text_pos start_pos
;
13536 int first_unchanged_at_end_vpos
= 0;
13537 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
13538 struct text_pos start
;
13539 int first_changed_charpos
, last_changed_charpos
;
13542 if (inhibit_try_window_id
)
13546 /* This is handy for debugging. */
13548 #define GIVE_UP(X) \
13550 fprintf (stderr, "try_window_id give up %d\n", (X)); \
13554 #define GIVE_UP(X) return 0
13557 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
13559 /* Don't use this for mini-windows because these can show
13560 messages and mini-buffers, and we don't handle that here. */
13561 if (MINI_WINDOW_P (w
))
13564 /* This flag is used to prevent redisplay optimizations. */
13565 if (windows_or_buffers_changed
|| cursor_type_changed
)
13568 /* Verify that narrowing has not changed.
13569 Also verify that we were not told to prevent redisplay optimizations.
13570 It would be nice to further
13571 reduce the number of cases where this prevents try_window_id. */
13572 if (current_buffer
->clip_changed
13573 || current_buffer
->prevent_redisplay_optimizations_p
)
13576 /* Window must either use window-based redisplay or be full width. */
13577 if (!FRAME_WINDOW_P (f
)
13578 && (!FRAME_LINE_INS_DEL_OK (f
)
13579 || !WINDOW_FULL_WIDTH_P (w
)))
13582 /* Give up if point is not known NOT to appear in W. */
13583 if (PT
< CHARPOS (start
))
13586 /* Another way to prevent redisplay optimizations. */
13587 if (XFASTINT (w
->last_modified
) == 0)
13590 /* Verify that window is not hscrolled. */
13591 if (XFASTINT (w
->hscroll
) != 0)
13594 /* Verify that display wasn't paused. */
13595 if (NILP (w
->window_end_valid
))
13598 /* Can't use this if highlighting a region because a cursor movement
13599 will do more than just set the cursor. */
13600 if (!NILP (Vtransient_mark_mode
)
13601 && !NILP (current_buffer
->mark_active
))
13604 /* Likewise if highlighting trailing whitespace. */
13605 if (!NILP (Vshow_trailing_whitespace
))
13608 /* Likewise if showing a region. */
13609 if (!NILP (w
->region_showing
))
13612 /* Can use this if overlay arrow position and or string have changed. */
13613 if (overlay_arrows_changed_p ())
13617 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
13618 only if buffer has really changed. The reason is that the gap is
13619 initially at Z for freshly visited files. The code below would
13620 set end_unchanged to 0 in that case. */
13621 if (MODIFF
> SAVE_MODIFF
13622 /* This seems to happen sometimes after saving a buffer. */
13623 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
13625 if (GPT
- BEG
< BEG_UNCHANGED
)
13626 BEG_UNCHANGED
= GPT
- BEG
;
13627 if (Z
- GPT
< END_UNCHANGED
)
13628 END_UNCHANGED
= Z
- GPT
;
13631 /* The position of the first and last character that has been changed. */
13632 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
13633 last_changed_charpos
= Z
- END_UNCHANGED
;
13635 /* If window starts after a line end, and the last change is in
13636 front of that newline, then changes don't affect the display.
13637 This case happens with stealth-fontification. Note that although
13638 the display is unchanged, glyph positions in the matrix have to
13639 be adjusted, of course. */
13640 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13641 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13642 && ((last_changed_charpos
< CHARPOS (start
)
13643 && CHARPOS (start
) == BEGV
)
13644 || (last_changed_charpos
< CHARPOS (start
) - 1
13645 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
13647 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
13648 struct glyph_row
*r0
;
13650 /* Compute how many chars/bytes have been added to or removed
13651 from the buffer. */
13652 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13653 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13655 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13657 /* Give up if PT is not in the window. Note that it already has
13658 been checked at the start of try_window_id that PT is not in
13659 front of the window start. */
13660 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
13663 /* If window start is unchanged, we can reuse the whole matrix
13664 as is, after adjusting glyph positions. No need to compute
13665 the window end again, since its offset from Z hasn't changed. */
13666 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13667 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
13668 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
13669 /* PT must not be in a partially visible line. */
13670 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
13671 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13673 /* Adjust positions in the glyph matrix. */
13674 if (delta
|| delta_bytes
)
13676 struct glyph_row
*r1
13677 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13678 increment_matrix_positions (w
->current_matrix
,
13679 MATRIX_ROW_VPOS (r0
, current_matrix
),
13680 MATRIX_ROW_VPOS (r1
, current_matrix
),
13681 delta
, delta_bytes
);
13684 /* Set the cursor. */
13685 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13687 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13694 /* Handle the case that changes are all below what is displayed in
13695 the window, and that PT is in the window. This shortcut cannot
13696 be taken if ZV is visible in the window, and text has been added
13697 there that is visible in the window. */
13698 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
13699 /* ZV is not visible in the window, or there are no
13700 changes at ZV, actually. */
13701 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
13702 || first_changed_charpos
== last_changed_charpos
))
13704 struct glyph_row
*r0
;
13706 /* Give up if PT is not in the window. Note that it already has
13707 been checked at the start of try_window_id that PT is not in
13708 front of the window start. */
13709 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
13712 /* If window start is unchanged, we can reuse the whole matrix
13713 as is, without changing glyph positions since no text has
13714 been added/removed in front of the window end. */
13715 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13716 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
13717 /* PT must not be in a partially visible line. */
13718 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
13719 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13721 /* We have to compute the window end anew since text
13722 can have been added/removed after it. */
13724 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13725 w
->window_end_bytepos
13726 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13728 /* Set the cursor. */
13729 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13731 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13738 /* Give up if window start is in the changed area.
13740 The condition used to read
13742 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
13744 but why that was tested escapes me at the moment. */
13745 if (CHARPOS (start
) >= first_changed_charpos
13746 && CHARPOS (start
) <= last_changed_charpos
)
13749 /* Check that window start agrees with the start of the first glyph
13750 row in its current matrix. Check this after we know the window
13751 start is not in changed text, otherwise positions would not be
13753 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13754 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
13757 /* Give up if the window ends in strings. Overlay strings
13758 at the end are difficult to handle, so don't try. */
13759 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
13760 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
13763 /* Compute the position at which we have to start displaying new
13764 lines. Some of the lines at the top of the window might be
13765 reusable because they are not displaying changed text. Find the
13766 last row in W's current matrix not affected by changes at the
13767 start of current_buffer. Value is null if changes start in the
13768 first line of window. */
13769 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
13770 if (last_unchanged_at_beg_row
)
13772 /* Avoid starting to display in the moddle of a character, a TAB
13773 for instance. This is easier than to set up the iterator
13774 exactly, and it's not a frequent case, so the additional
13775 effort wouldn't really pay off. */
13776 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
13777 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
13778 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
13779 --last_unchanged_at_beg_row
;
13781 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
13784 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
13786 start_pos
= it
.current
.pos
;
13788 /* Start displaying new lines in the desired matrix at the same
13789 vpos we would use in the current matrix, i.e. below
13790 last_unchanged_at_beg_row. */
13791 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
13793 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13794 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
13796 xassert (it
.hpos
== 0 && it
.current_x
== 0);
13800 /* There are no reusable lines at the start of the window.
13801 Start displaying in the first text line. */
13802 start_display (&it
, w
, start
);
13803 it
.vpos
= it
.first_vpos
;
13804 start_pos
= it
.current
.pos
;
13807 /* Find the first row that is not affected by changes at the end of
13808 the buffer. Value will be null if there is no unchanged row, in
13809 which case we must redisplay to the end of the window. delta
13810 will be set to the value by which buffer positions beginning with
13811 first_unchanged_at_end_row have to be adjusted due to text
13813 first_unchanged_at_end_row
13814 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
13815 IF_DEBUG (debug_delta
= delta
);
13816 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
13818 /* Set stop_pos to the buffer position up to which we will have to
13819 display new lines. If first_unchanged_at_end_row != NULL, this
13820 is the buffer position of the start of the line displayed in that
13821 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
13822 that we don't stop at a buffer position. */
13824 if (first_unchanged_at_end_row
)
13826 xassert (last_unchanged_at_beg_row
== NULL
13827 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
13829 /* If this is a continuation line, move forward to the next one
13830 that isn't. Changes in lines above affect this line.
13831 Caution: this may move first_unchanged_at_end_row to a row
13832 not displaying text. */
13833 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
13834 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13835 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13836 < it
.last_visible_y
))
13837 ++first_unchanged_at_end_row
;
13839 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13840 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13841 >= it
.last_visible_y
))
13842 first_unchanged_at_end_row
= NULL
;
13845 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13847 first_unchanged_at_end_vpos
13848 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13849 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13852 else if (last_unchanged_at_beg_row
== NULL
)
13858 /* Either there is no unchanged row at the end, or the one we have
13859 now displays text. This is a necessary condition for the window
13860 end pos calculation at the end of this function. */
13861 xassert (first_unchanged_at_end_row
== NULL
13862 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
13864 debug_last_unchanged_at_beg_vpos
13865 = (last_unchanged_at_beg_row
13866 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
13868 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
13870 #endif /* GLYPH_DEBUG != 0 */
13873 /* Display new lines. Set last_text_row to the last new line
13874 displayed which has text on it, i.e. might end up as being the
13875 line where the window_end_vpos is. */
13876 w
->cursor
.vpos
= -1;
13877 last_text_row
= NULL
;
13878 overlay_arrow_seen
= 0;
13879 while (it
.current_y
< it
.last_visible_y
13880 && !fonts_changed_p
13881 && (first_unchanged_at_end_row
== NULL
13882 || IT_CHARPOS (it
) < stop_pos
))
13884 if (display_line (&it
))
13885 last_text_row
= it
.glyph_row
- 1;
13888 if (fonts_changed_p
)
13892 /* Compute differences in buffer positions, y-positions etc. for
13893 lines reused at the bottom of the window. Compute what we can
13895 if (first_unchanged_at_end_row
13896 /* No lines reused because we displayed everything up to the
13897 bottom of the window. */
13898 && it
.current_y
< it
.last_visible_y
)
13901 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
13903 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
13904 run
.current_y
= first_unchanged_at_end_row
->y
;
13905 run
.desired_y
= run
.current_y
+ dy
;
13906 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
13910 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
13911 first_unchanged_at_end_row
= NULL
;
13913 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
13916 /* Find the cursor if not already found. We have to decide whether
13917 PT will appear on this window (it sometimes doesn't, but this is
13918 not a very frequent case.) This decision has to be made before
13919 the current matrix is altered. A value of cursor.vpos < 0 means
13920 that PT is either in one of the lines beginning at
13921 first_unchanged_at_end_row or below the window. Don't care for
13922 lines that might be displayed later at the window end; as
13923 mentioned, this is not a frequent case. */
13924 if (w
->cursor
.vpos
< 0)
13926 /* Cursor in unchanged rows at the top? */
13927 if (PT
< CHARPOS (start_pos
)
13928 && last_unchanged_at_beg_row
)
13930 row
= row_containing_pos (w
, PT
,
13931 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
13932 last_unchanged_at_beg_row
+ 1, 0);
13934 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13937 /* Start from first_unchanged_at_end_row looking for PT. */
13938 else if (first_unchanged_at_end_row
)
13940 row
= row_containing_pos (w
, PT
- delta
,
13941 first_unchanged_at_end_row
, NULL
, 0);
13943 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
13944 delta_bytes
, dy
, dvpos
);
13947 /* Give up if cursor was not found. */
13948 if (w
->cursor
.vpos
< 0)
13950 clear_glyph_matrix (w
->desired_matrix
);
13955 /* Don't let the cursor end in the scroll margins. */
13957 int this_scroll_margin
, cursor_height
;
13959 this_scroll_margin
= max (0, scroll_margin
);
13960 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13961 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13962 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
13964 if ((w
->cursor
.y
< this_scroll_margin
13965 && CHARPOS (start
) > BEGV
)
13966 /* Old redisplay didn't take scroll margin into account at the bottom,
13967 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
13968 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
13969 ? cursor_height
+ this_scroll_margin
13970 : 1)) > it
.last_visible_y
)
13972 w
->cursor
.vpos
= -1;
13973 clear_glyph_matrix (w
->desired_matrix
);
13978 /* Scroll the display. Do it before changing the current matrix so
13979 that xterm.c doesn't get confused about where the cursor glyph is
13981 if (dy
&& run
.height
)
13985 if (FRAME_WINDOW_P (f
))
13987 FRAME_RIF (f
)->update_window_begin_hook (w
);
13988 FRAME_RIF (f
)->clear_window_mouse_face (w
);
13989 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
13990 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
13994 /* Terminal frame. In this case, dvpos gives the number of
13995 lines to scroll by; dvpos < 0 means scroll up. */
13996 int first_unchanged_at_end_vpos
13997 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
13998 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
13999 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14000 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14001 + window_internal_height (w
));
14003 /* Perform the operation on the screen. */
14006 /* Scroll last_unchanged_at_beg_row to the end of the
14007 window down dvpos lines. */
14008 set_terminal_window (f
, end
);
14010 /* On dumb terminals delete dvpos lines at the end
14011 before inserting dvpos empty lines. */
14012 if (!FRAME_SCROLL_REGION_OK (f
))
14013 ins_del_lines (f
, end
- dvpos
, -dvpos
);
14015 /* Insert dvpos empty lines in front of
14016 last_unchanged_at_beg_row. */
14017 ins_del_lines (f
, from
, dvpos
);
14019 else if (dvpos
< 0)
14021 /* Scroll up last_unchanged_at_beg_vpos to the end of
14022 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14023 set_terminal_window (f
, end
);
14025 /* Delete dvpos lines in front of
14026 last_unchanged_at_beg_vpos. ins_del_lines will set
14027 the cursor to the given vpos and emit |dvpos| delete
14029 ins_del_lines (f
, from
+ dvpos
, dvpos
);
14031 /* On a dumb terminal insert dvpos empty lines at the
14033 if (!FRAME_SCROLL_REGION_OK (f
))
14034 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
14037 set_terminal_window (f
, 0);
14043 /* Shift reused rows of the current matrix to the right position.
14044 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14046 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14047 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14050 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14051 bottom_vpos
, dvpos
);
14052 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14055 else if (dvpos
> 0)
14057 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14058 bottom_vpos
, dvpos
);
14059 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14060 first_unchanged_at_end_vpos
+ dvpos
, 0);
14063 /* For frame-based redisplay, make sure that current frame and window
14064 matrix are in sync with respect to glyph memory. */
14065 if (!FRAME_WINDOW_P (f
))
14066 sync_frame_with_window_matrix_rows (w
);
14068 /* Adjust buffer positions in reused rows. */
14070 increment_matrix_positions (current_matrix
,
14071 first_unchanged_at_end_vpos
+ dvpos
,
14072 bottom_vpos
, delta
, delta_bytes
);
14074 /* Adjust Y positions. */
14076 shift_glyph_matrix (w
, current_matrix
,
14077 first_unchanged_at_end_vpos
+ dvpos
,
14080 if (first_unchanged_at_end_row
)
14082 first_unchanged_at_end_row
+= dvpos
;
14083 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14084 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
14085 first_unchanged_at_end_row
= NULL
;
14088 /* If scrolling up, there may be some lines to display at the end of
14090 last_text_row_at_end
= NULL
;
14093 /* Scrolling up can leave for example a partially visible line
14094 at the end of the window to be redisplayed. */
14095 /* Set last_row to the glyph row in the current matrix where the
14096 window end line is found. It has been moved up or down in
14097 the matrix by dvpos. */
14098 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
14099 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
14101 /* If last_row is the window end line, it should display text. */
14102 xassert (last_row
->displays_text_p
);
14104 /* If window end line was partially visible before, begin
14105 displaying at that line. Otherwise begin displaying with the
14106 line following it. */
14107 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
14109 init_to_row_start (&it
, w
, last_row
);
14110 it
.vpos
= last_vpos
;
14111 it
.current_y
= last_row
->y
;
14115 init_to_row_end (&it
, w
, last_row
);
14116 it
.vpos
= 1 + last_vpos
;
14117 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
14121 /* We may start in a continuation line. If so, we have to
14122 get the right continuation_lines_width and current_x. */
14123 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
14124 it
.hpos
= it
.current_x
= 0;
14126 /* Display the rest of the lines at the window end. */
14127 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14128 while (it
.current_y
< it
.last_visible_y
14129 && !fonts_changed_p
)
14131 /* Is it always sure that the display agrees with lines in
14132 the current matrix? I don't think so, so we mark rows
14133 displayed invalid in the current matrix by setting their
14134 enabled_p flag to zero. */
14135 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
14136 if (display_line (&it
))
14137 last_text_row_at_end
= it
.glyph_row
- 1;
14141 /* Update window_end_pos and window_end_vpos. */
14142 if (first_unchanged_at_end_row
14143 && !last_text_row_at_end
)
14145 /* Window end line if one of the preserved rows from the current
14146 matrix. Set row to the last row displaying text in current
14147 matrix starting at first_unchanged_at_end_row, after
14149 xassert (first_unchanged_at_end_row
->displays_text_p
);
14150 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
14151 first_unchanged_at_end_row
);
14152 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
14154 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14155 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14157 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
14158 xassert (w
->window_end_bytepos
>= 0);
14159 IF_DEBUG (debug_method_add (w
, "A"));
14161 else if (last_text_row_at_end
)
14164 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
14165 w
->window_end_bytepos
14166 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
14168 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
14169 xassert (w
->window_end_bytepos
>= 0);
14170 IF_DEBUG (debug_method_add (w
, "B"));
14172 else if (last_text_row
)
14174 /* We have displayed either to the end of the window or at the
14175 end of the window, i.e. the last row with text is to be found
14176 in the desired matrix. */
14178 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14179 w
->window_end_bytepos
14180 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14182 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
14183 xassert (w
->window_end_bytepos
>= 0);
14185 else if (first_unchanged_at_end_row
== NULL
14186 && last_text_row
== NULL
14187 && last_text_row_at_end
== NULL
)
14189 /* Displayed to end of window, but no line containing text was
14190 displayed. Lines were deleted at the end of the window. */
14191 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
14192 int vpos
= XFASTINT (w
->window_end_vpos
);
14193 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
14194 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
14197 row
== NULL
&& vpos
>= first_vpos
;
14198 --vpos
, --current_row
, --desired_row
)
14200 if (desired_row
->enabled_p
)
14202 if (desired_row
->displays_text_p
)
14205 else if (current_row
->displays_text_p
)
14209 xassert (row
!= NULL
);
14210 w
->window_end_vpos
= make_number (vpos
+ 1);
14211 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14212 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14213 xassert (w
->window_end_bytepos
>= 0);
14214 IF_DEBUG (debug_method_add (w
, "C"));
14219 #if 0 /* This leads to problems, for instance when the cursor is
14220 at ZV, and the cursor line displays no text. */
14221 /* Disable rows below what's displayed in the window. This makes
14222 debugging easier. */
14223 enable_glyph_matrix_rows (current_matrix
,
14224 XFASTINT (w
->window_end_vpos
) + 1,
14228 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
14229 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
14231 /* Record that display has not been completed. */
14232 w
->window_end_valid
= Qnil
;
14233 w
->desired_matrix
->no_scrolling_p
= 1;
14241 /***********************************************************************
14242 More debugging support
14243 ***********************************************************************/
14247 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
14248 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
14249 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
14252 /* Dump the contents of glyph matrix MATRIX on stderr.
14254 GLYPHS 0 means don't show glyph contents.
14255 GLYPHS 1 means show glyphs in short form
14256 GLYPHS > 1 means show glyphs in long form. */
14259 dump_glyph_matrix (matrix
, glyphs
)
14260 struct glyph_matrix
*matrix
;
14264 for (i
= 0; i
< matrix
->nrows
; ++i
)
14265 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
14269 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
14270 the glyph row and area where the glyph comes from. */
14273 dump_glyph (row
, glyph
, area
)
14274 struct glyph_row
*row
;
14275 struct glyph
*glyph
;
14278 if (glyph
->type
== CHAR_GLYPH
)
14281 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14282 glyph
- row
->glyphs
[TEXT_AREA
],
14285 (BUFFERP (glyph
->object
)
14287 : (STRINGP (glyph
->object
)
14290 glyph
->pixel_width
,
14292 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
14296 glyph
->left_box_line_p
,
14297 glyph
->right_box_line_p
);
14299 else if (glyph
->type
== STRETCH_GLYPH
)
14302 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14303 glyph
- row
->glyphs
[TEXT_AREA
],
14306 (BUFFERP (glyph
->object
)
14308 : (STRINGP (glyph
->object
)
14311 glyph
->pixel_width
,
14315 glyph
->left_box_line_p
,
14316 glyph
->right_box_line_p
);
14318 else if (glyph
->type
== IMAGE_GLYPH
)
14321 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14322 glyph
- row
->glyphs
[TEXT_AREA
],
14325 (BUFFERP (glyph
->object
)
14327 : (STRINGP (glyph
->object
)
14330 glyph
->pixel_width
,
14334 glyph
->left_box_line_p
,
14335 glyph
->right_box_line_p
);
14340 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
14341 GLYPHS 0 means don't show glyph contents.
14342 GLYPHS 1 means show glyphs in short form
14343 GLYPHS > 1 means show glyphs in long form. */
14346 dump_glyph_row (row
, vpos
, glyphs
)
14347 struct glyph_row
*row
;
14352 fprintf (stderr
, "Row Start End Used oEI><\\CTZFesm X Y W H V A P\n");
14353 fprintf (stderr
, "======================================================================\n");
14355 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
14356 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
14358 MATRIX_ROW_START_CHARPOS (row
),
14359 MATRIX_ROW_END_CHARPOS (row
),
14360 row
->used
[TEXT_AREA
],
14361 row
->contains_overlapping_glyphs_p
,
14363 row
->truncated_on_left_p
,
14364 row
->truncated_on_right_p
,
14366 MATRIX_ROW_CONTINUATION_LINE_P (row
),
14367 row
->displays_text_p
,
14370 row
->ends_in_middle_of_char_p
,
14371 row
->starts_in_middle_of_char_p
,
14377 row
->visible_height
,
14380 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
14381 row
->end
.overlay_string_index
,
14382 row
->continuation_lines_width
);
14383 fprintf (stderr
, "%9d %5d\n",
14384 CHARPOS (row
->start
.string_pos
),
14385 CHARPOS (row
->end
.string_pos
));
14386 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
14387 row
->end
.dpvec_index
);
14394 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14396 struct glyph
*glyph
= row
->glyphs
[area
];
14397 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
14399 /* Glyph for a line end in text. */
14400 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
14403 if (glyph
< glyph_end
)
14404 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
14406 for (; glyph
< glyph_end
; ++glyph
)
14407 dump_glyph (row
, glyph
, area
);
14410 else if (glyphs
== 1)
14414 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14416 char *s
= (char *) alloca (row
->used
[area
] + 1);
14419 for (i
= 0; i
< row
->used
[area
]; ++i
)
14421 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
14422 if (glyph
->type
== CHAR_GLYPH
14423 && glyph
->u
.ch
< 0x80
14424 && glyph
->u
.ch
>= ' ')
14425 s
[i
] = glyph
->u
.ch
;
14431 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
14437 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
14438 Sdump_glyph_matrix
, 0, 1, "p",
14439 doc
: /* Dump the current matrix of the selected window to stderr.
14440 Shows contents of glyph row structures. With non-nil
14441 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
14442 glyphs in short form, otherwise show glyphs in long form. */)
14444 Lisp_Object glyphs
;
14446 struct window
*w
= XWINDOW (selected_window
);
14447 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14449 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
14450 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
14451 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
14452 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
14453 fprintf (stderr
, "=============================================\n");
14454 dump_glyph_matrix (w
->current_matrix
,
14455 NILP (glyphs
) ? 0 : XINT (glyphs
));
14460 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
14461 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
14464 struct frame
*f
= XFRAME (selected_frame
);
14465 dump_glyph_matrix (f
->current_matrix
, 1);
14470 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
14471 doc
: /* Dump glyph row ROW to stderr.
14472 GLYPH 0 means don't dump glyphs.
14473 GLYPH 1 means dump glyphs in short form.
14474 GLYPH > 1 or omitted means dump glyphs in long form. */)
14476 Lisp_Object row
, glyphs
;
14478 struct glyph_matrix
*matrix
;
14481 CHECK_NUMBER (row
);
14482 matrix
= XWINDOW (selected_window
)->current_matrix
;
14484 if (vpos
>= 0 && vpos
< matrix
->nrows
)
14485 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
14487 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14492 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
14493 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
14494 GLYPH 0 means don't dump glyphs.
14495 GLYPH 1 means dump glyphs in short form.
14496 GLYPH > 1 or omitted means dump glyphs in long form. */)
14498 Lisp_Object row
, glyphs
;
14500 struct frame
*sf
= SELECTED_FRAME ();
14501 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
14504 CHECK_NUMBER (row
);
14506 if (vpos
>= 0 && vpos
< m
->nrows
)
14507 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
14508 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14513 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
14514 doc
: /* Toggle tracing of redisplay.
14515 With ARG, turn tracing on if and only if ARG is positive. */)
14520 trace_redisplay_p
= !trace_redisplay_p
;
14523 arg
= Fprefix_numeric_value (arg
);
14524 trace_redisplay_p
= XINT (arg
) > 0;
14531 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
14532 doc
: /* Like `format', but print result to stderr.
14533 usage: (trace-to-stderr STRING &rest OBJECTS) */)
14538 Lisp_Object s
= Fformat (nargs
, args
);
14539 fprintf (stderr
, "%s", SDATA (s
));
14543 #endif /* GLYPH_DEBUG */
14547 /***********************************************************************
14548 Building Desired Matrix Rows
14549 ***********************************************************************/
14551 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
14552 Used for non-window-redisplay windows, and for windows w/o left fringe. */
14554 static struct glyph_row
*
14555 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
14557 Lisp_Object overlay_arrow_string
;
14559 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14560 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14561 struct buffer
*old
= current_buffer
;
14562 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
14563 int arrow_len
= SCHARS (overlay_arrow_string
);
14564 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
14565 const unsigned char *p
;
14568 int n_glyphs_before
;
14570 set_buffer_temp (buffer
);
14571 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
14572 it
.glyph_row
->used
[TEXT_AREA
] = 0;
14573 SET_TEXT_POS (it
.position
, 0, 0);
14575 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
14577 while (p
< arrow_end
)
14579 Lisp_Object face
, ilisp
;
14581 /* Get the next character. */
14583 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
14585 it
.c
= *p
, it
.len
= 1;
14588 /* Get its face. */
14589 ilisp
= make_number (p
- arrow_string
);
14590 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
14591 it
.face_id
= compute_char_face (f
, it
.c
, face
);
14593 /* Compute its width, get its glyphs. */
14594 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
14595 SET_TEXT_POS (it
.position
, -1, -1);
14596 PRODUCE_GLYPHS (&it
);
14598 /* If this character doesn't fit any more in the line, we have
14599 to remove some glyphs. */
14600 if (it
.current_x
> it
.last_visible_x
)
14602 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14607 set_buffer_temp (old
);
14608 return it
.glyph_row
;
14612 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
14613 glyphs are only inserted for terminal frames since we can't really
14614 win with truncation glyphs when partially visible glyphs are
14615 involved. Which glyphs to insert is determined by
14616 produce_special_glyphs. */
14619 insert_left_trunc_glyphs (it
)
14622 struct it truncate_it
;
14623 struct glyph
*from
, *end
, *to
, *toend
;
14625 xassert (!FRAME_WINDOW_P (it
->f
));
14627 /* Get the truncation glyphs. */
14629 truncate_it
.current_x
= 0;
14630 truncate_it
.face_id
= DEFAULT_FACE_ID
;
14631 truncate_it
.glyph_row
= &scratch_glyph_row
;
14632 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
14633 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
14634 truncate_it
.object
= make_number (0);
14635 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
14637 /* Overwrite glyphs from IT with truncation glyphs. */
14638 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14639 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
14640 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
14641 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
14646 /* There may be padding glyphs left over. Overwrite them too. */
14647 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
14649 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14655 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
14659 /* Compute the pixel height and width of IT->glyph_row.
14661 Most of the time, ascent and height of a display line will be equal
14662 to the max_ascent and max_height values of the display iterator
14663 structure. This is not the case if
14665 1. We hit ZV without displaying anything. In this case, max_ascent
14666 and max_height will be zero.
14668 2. We have some glyphs that don't contribute to the line height.
14669 (The glyph row flag contributes_to_line_height_p is for future
14670 pixmap extensions).
14672 The first case is easily covered by using default values because in
14673 these cases, the line height does not really matter, except that it
14674 must not be zero. */
14677 compute_line_metrics (it
)
14680 struct glyph_row
*row
= it
->glyph_row
;
14683 if (FRAME_WINDOW_P (it
->f
))
14685 int i
, min_y
, max_y
;
14687 /* The line may consist of one space only, that was added to
14688 place the cursor on it. If so, the row's height hasn't been
14690 if (row
->height
== 0)
14692 if (it
->max_ascent
+ it
->max_descent
== 0)
14693 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
14694 row
->ascent
= it
->max_ascent
;
14695 row
->height
= it
->max_ascent
+ it
->max_descent
;
14696 row
->phys_ascent
= it
->max_phys_ascent
;
14697 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14698 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
14701 /* Compute the width of this line. */
14702 row
->pixel_width
= row
->x
;
14703 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
14704 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
14706 xassert (row
->pixel_width
>= 0);
14707 xassert (row
->ascent
>= 0 && row
->height
> 0);
14709 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
14710 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
14712 /* If first line's physical ascent is larger than its logical
14713 ascent, use the physical ascent, and make the row taller.
14714 This makes accented characters fully visible. */
14715 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
14716 && row
->phys_ascent
> row
->ascent
)
14718 row
->height
+= row
->phys_ascent
- row
->ascent
;
14719 row
->ascent
= row
->phys_ascent
;
14722 /* Compute how much of the line is visible. */
14723 row
->visible_height
= row
->height
;
14725 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
14726 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
14728 if (row
->y
< min_y
)
14729 row
->visible_height
-= min_y
- row
->y
;
14730 if (row
->y
+ row
->height
> max_y
)
14731 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14735 row
->pixel_width
= row
->used
[TEXT_AREA
];
14736 if (row
->continued_p
)
14737 row
->pixel_width
-= it
->continuation_pixel_width
;
14738 else if (row
->truncated_on_right_p
)
14739 row
->pixel_width
-= it
->truncation_pixel_width
;
14740 row
->ascent
= row
->phys_ascent
= 0;
14741 row
->height
= row
->phys_height
= row
->visible_height
= 1;
14742 row
->extra_line_spacing
= 0;
14745 /* Compute a hash code for this row. */
14747 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14748 for (i
= 0; i
< row
->used
[area
]; ++i
)
14749 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
14750 + row
->glyphs
[area
][i
].u
.val
14751 + row
->glyphs
[area
][i
].face_id
14752 + row
->glyphs
[area
][i
].padding_p
14753 + (row
->glyphs
[area
][i
].type
<< 2));
14755 it
->max_ascent
= it
->max_descent
= 0;
14756 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
14760 /* Append one space to the glyph row of iterator IT if doing a
14761 window-based redisplay. The space has the same face as
14762 IT->face_id. Value is non-zero if a space was added.
14764 This function is called to make sure that there is always one glyph
14765 at the end of a glyph row that the cursor can be set on under
14766 window-systems. (If there weren't such a glyph we would not know
14767 how wide and tall a box cursor should be displayed).
14769 At the same time this space let's a nicely handle clearing to the
14770 end of the line if the row ends in italic text. */
14773 append_space_for_newline (it
, default_face_p
)
14775 int default_face_p
;
14777 if (FRAME_WINDOW_P (it
->f
))
14779 int n
= it
->glyph_row
->used
[TEXT_AREA
];
14781 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
14782 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
14784 /* Save some values that must not be changed.
14785 Must save IT->c and IT->len because otherwise
14786 ITERATOR_AT_END_P wouldn't work anymore after
14787 append_space_for_newline has been called. */
14788 enum display_element_type saved_what
= it
->what
;
14789 int saved_c
= it
->c
, saved_len
= it
->len
;
14790 int saved_x
= it
->current_x
;
14791 int saved_face_id
= it
->face_id
;
14792 struct text_pos saved_pos
;
14793 Lisp_Object saved_object
;
14796 saved_object
= it
->object
;
14797 saved_pos
= it
->position
;
14799 it
->what
= IT_CHARACTER
;
14800 bzero (&it
->position
, sizeof it
->position
);
14801 it
->object
= make_number (0);
14805 if (default_face_p
)
14806 it
->face_id
= DEFAULT_FACE_ID
;
14807 else if (it
->face_before_selective_p
)
14808 it
->face_id
= it
->saved_face_id
;
14809 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14810 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
14812 PRODUCE_GLYPHS (it
);
14814 it
->override_ascent
= -1;
14815 it
->constrain_row_ascent_descent_p
= 0;
14816 it
->current_x
= saved_x
;
14817 it
->object
= saved_object
;
14818 it
->position
= saved_pos
;
14819 it
->what
= saved_what
;
14820 it
->face_id
= saved_face_id
;
14821 it
->len
= saved_len
;
14831 /* Extend the face of the last glyph in the text area of IT->glyph_row
14832 to the end of the display line. Called from display_line.
14833 If the glyph row is empty, add a space glyph to it so that we
14834 know the face to draw. Set the glyph row flag fill_line_p. */
14837 extend_face_to_end_of_line (it
)
14841 struct frame
*f
= it
->f
;
14843 /* If line is already filled, do nothing. */
14844 if (it
->current_x
>= it
->last_visible_x
)
14847 /* Face extension extends the background and box of IT->face_id
14848 to the end of the line. If the background equals the background
14849 of the frame, we don't have to do anything. */
14850 if (it
->face_before_selective_p
)
14851 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14853 face
= FACE_FROM_ID (f
, it
->face_id
);
14855 if (FRAME_WINDOW_P (f
)
14856 && face
->box
== FACE_NO_BOX
14857 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
14861 /* Set the glyph row flag indicating that the face of the last glyph
14862 in the text area has to be drawn to the end of the text area. */
14863 it
->glyph_row
->fill_line_p
= 1;
14865 /* If current character of IT is not ASCII, make sure we have the
14866 ASCII face. This will be automatically undone the next time
14867 get_next_display_element returns a multibyte character. Note
14868 that the character will always be single byte in unibyte text. */
14869 if (!SINGLE_BYTE_CHAR_P (it
->c
))
14871 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
14874 if (FRAME_WINDOW_P (f
))
14876 /* If the row is empty, add a space with the current face of IT,
14877 so that we know which face to draw. */
14878 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
14880 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
14881 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
14882 it
->glyph_row
->used
[TEXT_AREA
] = 1;
14887 /* Save some values that must not be changed. */
14888 int saved_x
= it
->current_x
;
14889 struct text_pos saved_pos
;
14890 Lisp_Object saved_object
;
14891 enum display_element_type saved_what
= it
->what
;
14892 int saved_face_id
= it
->face_id
;
14894 saved_object
= it
->object
;
14895 saved_pos
= it
->position
;
14897 it
->what
= IT_CHARACTER
;
14898 bzero (&it
->position
, sizeof it
->position
);
14899 it
->object
= make_number (0);
14902 it
->face_id
= face
->id
;
14904 PRODUCE_GLYPHS (it
);
14906 while (it
->current_x
<= it
->last_visible_x
)
14907 PRODUCE_GLYPHS (it
);
14909 /* Don't count these blanks really. It would let us insert a left
14910 truncation glyph below and make us set the cursor on them, maybe. */
14911 it
->current_x
= saved_x
;
14912 it
->object
= saved_object
;
14913 it
->position
= saved_pos
;
14914 it
->what
= saved_what
;
14915 it
->face_id
= saved_face_id
;
14920 /* Value is non-zero if text starting at CHARPOS in current_buffer is
14921 trailing whitespace. */
14924 trailing_whitespace_p (charpos
)
14927 int bytepos
= CHAR_TO_BYTE (charpos
);
14930 while (bytepos
< ZV_BYTE
14931 && (c
= FETCH_CHAR (bytepos
),
14932 c
== ' ' || c
== '\t'))
14935 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
14937 if (bytepos
!= PT_BYTE
)
14944 /* Highlight trailing whitespace, if any, in ROW. */
14947 highlight_trailing_whitespace (f
, row
)
14949 struct glyph_row
*row
;
14951 int used
= row
->used
[TEXT_AREA
];
14955 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
14956 struct glyph
*glyph
= start
+ used
- 1;
14958 /* Skip over glyphs inserted to display the cursor at the
14959 end of a line, for extending the face of the last glyph
14960 to the end of the line on terminals, and for truncation
14961 and continuation glyphs. */
14962 while (glyph
>= start
14963 && glyph
->type
== CHAR_GLYPH
14964 && INTEGERP (glyph
->object
))
14967 /* If last glyph is a space or stretch, and it's trailing
14968 whitespace, set the face of all trailing whitespace glyphs in
14969 IT->glyph_row to `trailing-whitespace'. */
14971 && BUFFERP (glyph
->object
)
14972 && (glyph
->type
== STRETCH_GLYPH
14973 || (glyph
->type
== CHAR_GLYPH
14974 && glyph
->u
.ch
== ' '))
14975 && trailing_whitespace_p (glyph
->charpos
))
14977 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
14981 while (glyph
>= start
14982 && BUFFERP (glyph
->object
)
14983 && (glyph
->type
== STRETCH_GLYPH
14984 || (glyph
->type
== CHAR_GLYPH
14985 && glyph
->u
.ch
== ' ')))
14986 (glyph
--)->face_id
= face_id
;
14992 /* Value is non-zero if glyph row ROW in window W should be
14993 used to hold the cursor. */
14996 cursor_row_p (w
, row
)
14998 struct glyph_row
*row
;
15000 int cursor_row_p
= 1;
15002 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15004 /* If the row ends with a newline from a string, we don't want
15005 the cursor there (if the row is continued it doesn't end in a
15007 if (CHARPOS (row
->end
.string_pos
) >= 0)
15008 cursor_row_p
= row
->continued_p
;
15009 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15011 /* If the row ends in middle of a real character,
15012 and the line is continued, we want the cursor here.
15013 That's because MATRIX_ROW_END_CHARPOS would equal
15014 PT if PT is before the character. */
15015 if (!row
->ends_in_ellipsis_p
)
15016 cursor_row_p
= row
->continued_p
;
15018 /* If the row ends in an ellipsis, then
15019 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15020 We want that position to be displayed after the ellipsis. */
15023 /* If the row ends at ZV, display the cursor at the end of that
15024 row instead of at the start of the row below. */
15025 else if (row
->ends_at_zv_p
)
15031 return cursor_row_p
;
15035 /* Construct the glyph row IT->glyph_row in the desired matrix of
15036 IT->w from text at the current position of IT. See dispextern.h
15037 for an overview of struct it. Value is non-zero if
15038 IT->glyph_row displays text, as opposed to a line displaying ZV
15045 struct glyph_row
*row
= it
->glyph_row
;
15046 Lisp_Object overlay_arrow_string
;
15048 /* We always start displaying at hpos zero even if hscrolled. */
15049 xassert (it
->hpos
== 0 && it
->current_x
== 0);
15051 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
15052 >= it
->w
->desired_matrix
->nrows
)
15054 it
->w
->nrows_scale_factor
++;
15055 fonts_changed_p
= 1;
15059 /* Is IT->w showing the region? */
15060 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
15062 /* Clear the result glyph row and enable it. */
15063 prepare_desired_row (row
);
15065 row
->y
= it
->current_y
;
15066 row
->start
= it
->start
;
15067 row
->continuation_lines_width
= it
->continuation_lines_width
;
15068 row
->displays_text_p
= 1;
15069 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
15070 it
->starts_in_middle_of_char_p
= 0;
15072 /* Arrange the overlays nicely for our purposes. Usually, we call
15073 display_line on only one line at a time, in which case this
15074 can't really hurt too much, or we call it on lines which appear
15075 one after another in the buffer, in which case all calls to
15076 recenter_overlay_lists but the first will be pretty cheap. */
15077 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
15079 /* Move over display elements that are not visible because we are
15080 hscrolled. This may stop at an x-position < IT->first_visible_x
15081 if the first glyph is partially visible or if we hit a line end. */
15082 if (it
->current_x
< it
->first_visible_x
)
15084 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
15085 MOVE_TO_POS
| MOVE_TO_X
);
15088 /* Get the initial row height. This is either the height of the
15089 text hscrolled, if there is any, or zero. */
15090 row
->ascent
= it
->max_ascent
;
15091 row
->height
= it
->max_ascent
+ it
->max_descent
;
15092 row
->phys_ascent
= it
->max_phys_ascent
;
15093 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15094 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15096 /* Loop generating characters. The loop is left with IT on the next
15097 character to display. */
15100 int n_glyphs_before
, hpos_before
, x_before
;
15102 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
15104 /* Retrieve the next thing to display. Value is zero if end of
15106 if (!get_next_display_element (it
))
15108 /* Maybe add a space at the end of this line that is used to
15109 display the cursor there under X. Set the charpos of the
15110 first glyph of blank lines not corresponding to any text
15112 #ifdef HAVE_WINDOW_SYSTEM
15113 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15114 row
->exact_window_width_line_p
= 1;
15116 #endif /* HAVE_WINDOW_SYSTEM */
15117 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
15118 || row
->used
[TEXT_AREA
] == 0)
15120 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
15121 row
->displays_text_p
= 0;
15123 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
15124 && (!MINI_WINDOW_P (it
->w
)
15125 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
15126 row
->indicate_empty_line_p
= 1;
15129 it
->continuation_lines_width
= 0;
15130 row
->ends_at_zv_p
= 1;
15134 /* Now, get the metrics of what we want to display. This also
15135 generates glyphs in `row' (which is IT->glyph_row). */
15136 n_glyphs_before
= row
->used
[TEXT_AREA
];
15139 /* Remember the line height so far in case the next element doesn't
15140 fit on the line. */
15141 if (!it
->truncate_lines_p
)
15143 ascent
= it
->max_ascent
;
15144 descent
= it
->max_descent
;
15145 phys_ascent
= it
->max_phys_ascent
;
15146 phys_descent
= it
->max_phys_descent
;
15149 PRODUCE_GLYPHS (it
);
15151 /* If this display element was in marginal areas, continue with
15153 if (it
->area
!= TEXT_AREA
)
15155 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15156 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15157 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15158 row
->phys_height
= max (row
->phys_height
,
15159 it
->max_phys_ascent
+ it
->max_phys_descent
);
15160 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15161 it
->max_extra_line_spacing
);
15162 set_iterator_to_next (it
, 1);
15166 /* Does the display element fit on the line? If we truncate
15167 lines, we should draw past the right edge of the window. If
15168 we don't truncate, we want to stop so that we can display the
15169 continuation glyph before the right margin. If lines are
15170 continued, there are two possible strategies for characters
15171 resulting in more than 1 glyph (e.g. tabs): Display as many
15172 glyphs as possible in this line and leave the rest for the
15173 continuation line, or display the whole element in the next
15174 line. Original redisplay did the former, so we do it also. */
15175 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
15176 hpos_before
= it
->hpos
;
15179 if (/* Not a newline. */
15181 /* Glyphs produced fit entirely in the line. */
15182 && it
->current_x
< it
->last_visible_x
)
15184 it
->hpos
+= nglyphs
;
15185 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15186 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15187 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15188 row
->phys_height
= max (row
->phys_height
,
15189 it
->max_phys_ascent
+ it
->max_phys_descent
);
15190 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15191 it
->max_extra_line_spacing
);
15192 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
15193 row
->x
= x
- it
->first_visible_x
;
15198 struct glyph
*glyph
;
15200 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
15202 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15203 new_x
= x
+ glyph
->pixel_width
;
15205 if (/* Lines are continued. */
15206 !it
->truncate_lines_p
15207 && (/* Glyph doesn't fit on the line. */
15208 new_x
> it
->last_visible_x
15209 /* Or it fits exactly on a window system frame. */
15210 || (new_x
== it
->last_visible_x
15211 && FRAME_WINDOW_P (it
->f
))))
15213 /* End of a continued line. */
15216 || (new_x
== it
->last_visible_x
15217 && FRAME_WINDOW_P (it
->f
)))
15219 /* Current glyph is the only one on the line or
15220 fits exactly on the line. We must continue
15221 the line because we can't draw the cursor
15222 after the glyph. */
15223 row
->continued_p
= 1;
15224 it
->current_x
= new_x
;
15225 it
->continuation_lines_width
+= new_x
;
15227 if (i
== nglyphs
- 1)
15229 set_iterator_to_next (it
, 1);
15230 #ifdef HAVE_WINDOW_SYSTEM
15231 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15233 if (!get_next_display_element (it
))
15235 row
->exact_window_width_line_p
= 1;
15236 it
->continuation_lines_width
= 0;
15237 row
->continued_p
= 0;
15238 row
->ends_at_zv_p
= 1;
15240 else if (ITERATOR_AT_END_OF_LINE_P (it
))
15242 row
->continued_p
= 0;
15243 row
->exact_window_width_line_p
= 1;
15246 #endif /* HAVE_WINDOW_SYSTEM */
15249 else if (CHAR_GLYPH_PADDING_P (*glyph
)
15250 && !FRAME_WINDOW_P (it
->f
))
15252 /* A padding glyph that doesn't fit on this line.
15253 This means the whole character doesn't fit
15255 row
->used
[TEXT_AREA
] = n_glyphs_before
;
15257 /* Fill the rest of the row with continuation
15258 glyphs like in 20.x. */
15259 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
15260 < row
->glyphs
[1 + TEXT_AREA
])
15261 produce_special_glyphs (it
, IT_CONTINUATION
);
15263 row
->continued_p
= 1;
15264 it
->current_x
= x_before
;
15265 it
->continuation_lines_width
+= x_before
;
15267 /* Restore the height to what it was before the
15268 element not fitting on the line. */
15269 it
->max_ascent
= ascent
;
15270 it
->max_descent
= descent
;
15271 it
->max_phys_ascent
= phys_ascent
;
15272 it
->max_phys_descent
= phys_descent
;
15274 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
15276 /* A TAB that extends past the right edge of the
15277 window. This produces a single glyph on
15278 window system frames. We leave the glyph in
15279 this row and let it fill the row, but don't
15280 consume the TAB. */
15281 it
->continuation_lines_width
+= it
->last_visible_x
;
15282 row
->ends_in_middle_of_char_p
= 1;
15283 row
->continued_p
= 1;
15284 glyph
->pixel_width
= it
->last_visible_x
- x
;
15285 it
->starts_in_middle_of_char_p
= 1;
15289 /* Something other than a TAB that draws past
15290 the right edge of the window. Restore
15291 positions to values before the element. */
15292 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15294 /* Display continuation glyphs. */
15295 if (!FRAME_WINDOW_P (it
->f
))
15296 produce_special_glyphs (it
, IT_CONTINUATION
);
15297 row
->continued_p
= 1;
15299 it
->continuation_lines_width
+= x
;
15301 if (nglyphs
> 1 && i
> 0)
15303 row
->ends_in_middle_of_char_p
= 1;
15304 it
->starts_in_middle_of_char_p
= 1;
15307 /* Restore the height to what it was before the
15308 element not fitting on the line. */
15309 it
->max_ascent
= ascent
;
15310 it
->max_descent
= descent
;
15311 it
->max_phys_ascent
= phys_ascent
;
15312 it
->max_phys_descent
= phys_descent
;
15317 else if (new_x
> it
->first_visible_x
)
15319 /* Increment number of glyphs actually displayed. */
15322 if (x
< it
->first_visible_x
)
15323 /* Glyph is partially visible, i.e. row starts at
15324 negative X position. */
15325 row
->x
= x
- it
->first_visible_x
;
15329 /* Glyph is completely off the left margin of the
15330 window. This should not happen because of the
15331 move_it_in_display_line at the start of this
15332 function, unless the text display area of the
15333 window is empty. */
15334 xassert (it
->first_visible_x
<= it
->last_visible_x
);
15338 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15339 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15340 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15341 row
->phys_height
= max (row
->phys_height
,
15342 it
->max_phys_ascent
+ it
->max_phys_descent
);
15343 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15344 it
->max_extra_line_spacing
);
15346 /* End of this display line if row is continued. */
15347 if (row
->continued_p
|| row
->ends_at_zv_p
)
15352 /* Is this a line end? If yes, we're also done, after making
15353 sure that a non-default face is extended up to the right
15354 margin of the window. */
15355 if (ITERATOR_AT_END_OF_LINE_P (it
))
15357 int used_before
= row
->used
[TEXT_AREA
];
15359 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
15361 #ifdef HAVE_WINDOW_SYSTEM
15362 /* Add a space at the end of the line that is used to
15363 display the cursor there. */
15364 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15365 append_space_for_newline (it
, 0);
15366 #endif /* HAVE_WINDOW_SYSTEM */
15368 /* Extend the face to the end of the line. */
15369 extend_face_to_end_of_line (it
);
15371 /* Make sure we have the position. */
15372 if (used_before
== 0)
15373 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
15375 /* Consume the line end. This skips over invisible lines. */
15376 set_iterator_to_next (it
, 1);
15377 it
->continuation_lines_width
= 0;
15381 /* Proceed with next display element. Note that this skips
15382 over lines invisible because of selective display. */
15383 set_iterator_to_next (it
, 1);
15385 /* If we truncate lines, we are done when the last displayed
15386 glyphs reach past the right margin of the window. */
15387 if (it
->truncate_lines_p
15388 && (FRAME_WINDOW_P (it
->f
)
15389 ? (it
->current_x
>= it
->last_visible_x
)
15390 : (it
->current_x
> it
->last_visible_x
)))
15392 /* Maybe add truncation glyphs. */
15393 if (!FRAME_WINDOW_P (it
->f
))
15397 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15398 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15401 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15403 row
->used
[TEXT_AREA
] = i
;
15404 produce_special_glyphs (it
, IT_TRUNCATION
);
15407 #ifdef HAVE_WINDOW_SYSTEM
15410 /* Don't truncate if we can overflow newline into fringe. */
15411 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15413 if (!get_next_display_element (it
))
15415 it
->continuation_lines_width
= 0;
15416 row
->ends_at_zv_p
= 1;
15417 row
->exact_window_width_line_p
= 1;
15420 if (ITERATOR_AT_END_OF_LINE_P (it
))
15422 row
->exact_window_width_line_p
= 1;
15423 goto at_end_of_line
;
15427 #endif /* HAVE_WINDOW_SYSTEM */
15429 row
->truncated_on_right_p
= 1;
15430 it
->continuation_lines_width
= 0;
15431 reseat_at_next_visible_line_start (it
, 0);
15432 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
15433 it
->hpos
= hpos_before
;
15434 it
->current_x
= x_before
;
15439 /* If line is not empty and hscrolled, maybe insert truncation glyphs
15440 at the left window margin. */
15441 if (it
->first_visible_x
15442 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
15444 if (!FRAME_WINDOW_P (it
->f
))
15445 insert_left_trunc_glyphs (it
);
15446 row
->truncated_on_left_p
= 1;
15449 /* If the start of this line is the overlay arrow-position, then
15450 mark this glyph row as the one containing the overlay arrow.
15451 This is clearly a mess with variable size fonts. It would be
15452 better to let it be displayed like cursors under X. */
15453 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
15454 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
15455 !NILP (overlay_arrow_string
)))
15457 /* Overlay arrow in window redisplay is a fringe bitmap. */
15458 if (STRINGP (overlay_arrow_string
))
15460 struct glyph_row
*arrow_row
15461 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
15462 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
15463 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
15464 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
15465 struct glyph
*p2
, *end
;
15467 /* Copy the arrow glyphs. */
15468 while (glyph
< arrow_end
)
15471 /* Throw away padding glyphs. */
15473 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15474 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
15480 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
15485 xassert (INTEGERP (overlay_arrow_string
));
15486 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
15488 overlay_arrow_seen
= 1;
15491 /* Compute pixel dimensions of this line. */
15492 compute_line_metrics (it
);
15494 /* Remember the position at which this line ends. */
15495 row
->end
= it
->current
;
15497 /* Record whether this row ends inside an ellipsis. */
15498 row
->ends_in_ellipsis_p
15499 = (it
->method
== GET_FROM_DISPLAY_VECTOR
15500 && it
->ellipsis_p
);
15502 /* Save fringe bitmaps in this row. */
15503 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
15504 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
15505 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
15506 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
15508 it
->left_user_fringe_bitmap
= 0;
15509 it
->left_user_fringe_face_id
= 0;
15510 it
->right_user_fringe_bitmap
= 0;
15511 it
->right_user_fringe_face_id
= 0;
15513 /* Maybe set the cursor. */
15514 if (it
->w
->cursor
.vpos
< 0
15515 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
15516 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15517 && cursor_row_p (it
->w
, row
))
15518 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
15520 /* Highlight trailing whitespace. */
15521 if (!NILP (Vshow_trailing_whitespace
))
15522 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
15524 /* Prepare for the next line. This line starts horizontally at (X
15525 HPOS) = (0 0). Vertical positions are incremented. As a
15526 convenience for the caller, IT->glyph_row is set to the next
15528 it
->current_x
= it
->hpos
= 0;
15529 it
->current_y
+= row
->height
;
15532 it
->start
= it
->current
;
15533 return row
->displays_text_p
;
15538 /***********************************************************************
15540 ***********************************************************************/
15542 /* Redisplay the menu bar in the frame for window W.
15544 The menu bar of X frames that don't have X toolkit support is
15545 displayed in a special window W->frame->menu_bar_window.
15547 The menu bar of terminal frames is treated specially as far as
15548 glyph matrices are concerned. Menu bar lines are not part of
15549 windows, so the update is done directly on the frame matrix rows
15550 for the menu bar. */
15553 display_menu_bar (w
)
15556 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15561 /* Don't do all this for graphical frames. */
15563 if (!NILP (Vwindow_system
))
15566 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
15571 if (FRAME_MAC_P (f
))
15575 #ifdef USE_X_TOOLKIT
15576 xassert (!FRAME_WINDOW_P (f
));
15577 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
15578 it
.first_visible_x
= 0;
15579 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15580 #else /* not USE_X_TOOLKIT */
15581 if (FRAME_WINDOW_P (f
))
15583 /* Menu bar lines are displayed in the desired matrix of the
15584 dummy window menu_bar_window. */
15585 struct window
*menu_w
;
15586 xassert (WINDOWP (f
->menu_bar_window
));
15587 menu_w
= XWINDOW (f
->menu_bar_window
);
15588 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
15590 it
.first_visible_x
= 0;
15591 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15595 /* This is a TTY frame, i.e. character hpos/vpos are used as
15597 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
15599 it
.first_visible_x
= 0;
15600 it
.last_visible_x
= FRAME_COLS (f
);
15602 #endif /* not USE_X_TOOLKIT */
15604 if (! mode_line_inverse_video
)
15605 /* Force the menu-bar to be displayed in the default face. */
15606 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15608 /* Clear all rows of the menu bar. */
15609 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
15611 struct glyph_row
*row
= it
.glyph_row
+ i
;
15612 clear_glyph_row (row
);
15613 row
->enabled_p
= 1;
15614 row
->full_width_p
= 1;
15617 /* Display all items of the menu bar. */
15618 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
15619 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
15621 Lisp_Object string
;
15623 /* Stop at nil string. */
15624 string
= AREF (items
, i
+ 1);
15628 /* Remember where item was displayed. */
15629 AREF (items
, i
+ 3) = make_number (it
.hpos
);
15631 /* Display the item, pad with one space. */
15632 if (it
.current_x
< it
.last_visible_x
)
15633 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
15634 SCHARS (string
) + 1, 0, 0, -1);
15637 /* Fill out the line with spaces. */
15638 if (it
.current_x
< it
.last_visible_x
)
15639 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
15641 /* Compute the total height of the lines. */
15642 compute_line_metrics (&it
);
15647 /***********************************************************************
15649 ***********************************************************************/
15651 /* Redisplay mode lines in the window tree whose root is WINDOW. If
15652 FORCE is non-zero, redisplay mode lines unconditionally.
15653 Otherwise, redisplay only mode lines that are garbaged. Value is
15654 the number of windows whose mode lines were redisplayed. */
15657 redisplay_mode_lines (window
, force
)
15658 Lisp_Object window
;
15663 while (!NILP (window
))
15665 struct window
*w
= XWINDOW (window
);
15667 if (WINDOWP (w
->hchild
))
15668 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
15669 else if (WINDOWP (w
->vchild
))
15670 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
15672 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
15673 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
15675 struct text_pos lpoint
;
15676 struct buffer
*old
= current_buffer
;
15678 /* Set the window's buffer for the mode line display. */
15679 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15680 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15682 /* Point refers normally to the selected window. For any
15683 other window, set up appropriate value. */
15684 if (!EQ (window
, selected_window
))
15686 struct text_pos pt
;
15688 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
15689 if (CHARPOS (pt
) < BEGV
)
15690 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15691 else if (CHARPOS (pt
) > (ZV
- 1))
15692 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
15694 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
15697 /* Display mode lines. */
15698 clear_glyph_matrix (w
->desired_matrix
);
15699 if (display_mode_lines (w
))
15702 w
->must_be_updated_p
= 1;
15705 /* Restore old settings. */
15706 set_buffer_internal_1 (old
);
15707 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15717 /* Display the mode and/or top line of window W. Value is the number
15718 of mode lines displayed. */
15721 display_mode_lines (w
)
15724 Lisp_Object old_selected_window
, old_selected_frame
;
15727 old_selected_frame
= selected_frame
;
15728 selected_frame
= w
->frame
;
15729 old_selected_window
= selected_window
;
15730 XSETWINDOW (selected_window
, w
);
15732 /* These will be set while the mode line specs are processed. */
15733 line_number_displayed
= 0;
15734 w
->column_number_displayed
= Qnil
;
15736 if (WINDOW_WANTS_MODELINE_P (w
))
15738 struct window
*sel_w
= XWINDOW (old_selected_window
);
15740 /* Select mode line face based on the real selected window. */
15741 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
15742 current_buffer
->mode_line_format
);
15746 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15748 display_mode_line (w
, HEADER_LINE_FACE_ID
,
15749 current_buffer
->header_line_format
);
15753 selected_frame
= old_selected_frame
;
15754 selected_window
= old_selected_window
;
15759 /* Display mode or top line of window W. FACE_ID specifies which line
15760 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
15761 FORMAT is the mode line format to display. Value is the pixel
15762 height of the mode line displayed. */
15765 display_mode_line (w
, face_id
, format
)
15767 enum face_id face_id
;
15768 Lisp_Object format
;
15772 int count
= SPECPDL_INDEX ();
15774 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15775 prepare_desired_row (it
.glyph_row
);
15777 it
.glyph_row
->mode_line_p
= 1;
15779 if (! mode_line_inverse_video
)
15780 /* Force the mode-line to be displayed in the default face. */
15781 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15783 record_unwind_protect (unwind_format_mode_line
,
15784 format_mode_line_unwind_data (NULL
));
15786 mode_line_target
= MODE_LINE_DISPLAY
;
15788 /* Temporarily make frame's keyboard the current kboard so that
15789 kboard-local variables in the mode_line_format will get the right
15791 push_frame_kboard (it
.f
);
15792 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15793 pop_frame_kboard ();
15795 unbind_to (count
, Qnil
);
15797 /* Fill up with spaces. */
15798 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
15800 compute_line_metrics (&it
);
15801 it
.glyph_row
->full_width_p
= 1;
15802 it
.glyph_row
->continued_p
= 0;
15803 it
.glyph_row
->truncated_on_left_p
= 0;
15804 it
.glyph_row
->truncated_on_right_p
= 0;
15806 /* Make a 3D mode-line have a shadow at its right end. */
15807 face
= FACE_FROM_ID (it
.f
, face_id
);
15808 extend_face_to_end_of_line (&it
);
15809 if (face
->box
!= FACE_NO_BOX
)
15811 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
15812 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
15813 last
->right_box_line_p
= 1;
15816 return it
.glyph_row
->height
;
15819 /* Contribute ELT to the mode line for window IT->w. How it
15820 translates into text depends on its data type.
15822 IT describes the display environment in which we display, as usual.
15824 DEPTH is the depth in recursion. It is used to prevent
15825 infinite recursion here.
15827 FIELD_WIDTH is the number of characters the display of ELT should
15828 occupy in the mode line, and PRECISION is the maximum number of
15829 characters to display from ELT's representation. See
15830 display_string for details.
15832 Returns the hpos of the end of the text generated by ELT.
15834 PROPS is a property list to add to any string we encounter.
15836 If RISKY is nonzero, remove (disregard) any properties in any string
15837 we encounter, and ignore :eval and :propertize.
15839 The global variable `mode_line_target' determines whether the
15840 output is passed to `store_mode_line_noprop',
15841 `store_mode_line_string', or `display_string'. */
15844 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
15847 int field_width
, precision
;
15848 Lisp_Object elt
, props
;
15851 int n
= 0, field
, prec
;
15856 elt
= build_string ("*too-deep*");
15860 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
15864 /* A string: output it and check for %-constructs within it. */
15866 const unsigned char *this, *lisp_string
;
15868 if (!NILP (props
) || risky
)
15870 Lisp_Object oprops
, aelt
;
15871 oprops
= Ftext_properties_at (make_number (0), elt
);
15873 /* If the starting string's properties are not what
15874 we want, translate the string. Also, if the string
15875 is risky, do that anyway. */
15877 if (NILP (Fequal (props
, oprops
)) || risky
)
15879 /* If the starting string has properties,
15880 merge the specified ones onto the existing ones. */
15881 if (! NILP (oprops
) && !risky
)
15885 oprops
= Fcopy_sequence (oprops
);
15887 while (CONSP (tem
))
15889 oprops
= Fplist_put (oprops
, XCAR (tem
),
15890 XCAR (XCDR (tem
)));
15891 tem
= XCDR (XCDR (tem
));
15896 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
15897 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
15899 mode_line_proptrans_alist
15900 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
15907 elt
= Fcopy_sequence (elt
);
15908 Fset_text_properties (make_number (0), Flength (elt
),
15910 /* Add this item to mode_line_proptrans_alist. */
15911 mode_line_proptrans_alist
15912 = Fcons (Fcons (elt
, props
),
15913 mode_line_proptrans_alist
);
15914 /* Truncate mode_line_proptrans_alist
15915 to at most 50 elements. */
15916 tem
= Fnthcdr (make_number (50),
15917 mode_line_proptrans_alist
);
15919 XSETCDR (tem
, Qnil
);
15924 this = SDATA (elt
);
15925 lisp_string
= this;
15929 prec
= precision
- n
;
15930 switch (mode_line_target
)
15932 case MODE_LINE_NOPROP
:
15933 case MODE_LINE_TITLE
:
15934 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
15936 case MODE_LINE_STRING
:
15937 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
15939 case MODE_LINE_DISPLAY
:
15940 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
15941 0, prec
, 0, STRING_MULTIBYTE (elt
));
15948 while ((precision
<= 0 || n
< precision
)
15950 && (mode_line_target
!= MODE_LINE_DISPLAY
15951 || it
->current_x
< it
->last_visible_x
))
15953 const unsigned char *last
= this;
15955 /* Advance to end of string or next format specifier. */
15956 while ((c
= *this++) != '\0' && c
!= '%')
15959 if (this - 1 != last
)
15961 int nchars
, nbytes
;
15963 /* Output to end of string or up to '%'. Field width
15964 is length of string. Don't output more than
15965 PRECISION allows us. */
15968 prec
= c_string_width (last
, this - last
, precision
- n
,
15971 switch (mode_line_target
)
15973 case MODE_LINE_NOPROP
:
15974 case MODE_LINE_TITLE
:
15975 n
+= store_mode_line_noprop (last
, 0, prec
);
15977 case MODE_LINE_STRING
:
15979 int bytepos
= last
- lisp_string
;
15980 int charpos
= string_byte_to_char (elt
, bytepos
);
15981 int endpos
= (precision
<= 0
15982 ? string_byte_to_char (elt
,
15983 this - lisp_string
)
15984 : charpos
+ nchars
);
15986 n
+= store_mode_line_string (NULL
,
15987 Fsubstring (elt
, make_number (charpos
),
15988 make_number (endpos
)),
15992 case MODE_LINE_DISPLAY
:
15994 int bytepos
= last
- lisp_string
;
15995 int charpos
= string_byte_to_char (elt
, bytepos
);
15996 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
15998 STRING_MULTIBYTE (elt
));
16003 else /* c == '%' */
16005 const unsigned char *percent_position
= this;
16007 /* Get the specified minimum width. Zero means
16010 while ((c
= *this++) >= '0' && c
<= '9')
16011 field
= field
* 10 + c
- '0';
16013 /* Don't pad beyond the total padding allowed. */
16014 if (field_width
- n
> 0 && field
> field_width
- n
)
16015 field
= field_width
- n
;
16017 /* Note that either PRECISION <= 0 or N < PRECISION. */
16018 prec
= precision
- n
;
16021 n
+= display_mode_element (it
, depth
, field
, prec
,
16022 Vglobal_mode_string
, props
,
16027 int bytepos
, charpos
;
16028 unsigned char *spec
;
16030 bytepos
= percent_position
- lisp_string
;
16031 charpos
= (STRING_MULTIBYTE (elt
)
16032 ? string_byte_to_char (elt
, bytepos
)
16036 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
16038 switch (mode_line_target
)
16040 case MODE_LINE_NOPROP
:
16041 case MODE_LINE_TITLE
:
16042 n
+= store_mode_line_noprop (spec
, field
, prec
);
16044 case MODE_LINE_STRING
:
16046 int len
= strlen (spec
);
16047 Lisp_Object tem
= make_string (spec
, len
);
16048 props
= Ftext_properties_at (make_number (charpos
), elt
);
16049 /* Should only keep face property in props */
16050 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
16053 case MODE_LINE_DISPLAY
:
16055 int nglyphs_before
, nwritten
;
16057 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16058 nwritten
= display_string (spec
, Qnil
, elt
,
16063 /* Assign to the glyphs written above the
16064 string where the `%x' came from, position
16068 struct glyph
*glyph
16069 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
16073 for (i
= 0; i
< nwritten
; ++i
)
16075 glyph
[i
].object
= elt
;
16076 glyph
[i
].charpos
= charpos
;
16093 /* A symbol: process the value of the symbol recursively
16094 as if it appeared here directly. Avoid error if symbol void.
16095 Special case: if value of symbol is a string, output the string
16098 register Lisp_Object tem
;
16100 /* If the variable is not marked as risky to set
16101 then its contents are risky to use. */
16102 if (NILP (Fget (elt
, Qrisky_local_variable
)))
16105 tem
= Fboundp (elt
);
16108 tem
= Fsymbol_value (elt
);
16109 /* If value is a string, output that string literally:
16110 don't check for % within it. */
16114 if (!EQ (tem
, elt
))
16116 /* Give up right away for nil or t. */
16126 register Lisp_Object car
, tem
;
16128 /* A cons cell: five distinct cases.
16129 If first element is :eval or :propertize, do something special.
16130 If first element is a string or a cons, process all the elements
16131 and effectively concatenate them.
16132 If first element is a negative number, truncate displaying cdr to
16133 at most that many characters. If positive, pad (with spaces)
16134 to at least that many characters.
16135 If first element is a symbol, process the cadr or caddr recursively
16136 according to whether the symbol's value is non-nil or nil. */
16138 if (EQ (car
, QCeval
))
16140 /* An element of the form (:eval FORM) means evaluate FORM
16141 and use the result as mode line elements. */
16146 if (CONSP (XCDR (elt
)))
16149 spec
= safe_eval (XCAR (XCDR (elt
)));
16150 n
+= display_mode_element (it
, depth
, field_width
- n
,
16151 precision
- n
, spec
, props
,
16155 else if (EQ (car
, QCpropertize
))
16157 /* An element of the form (:propertize ELT PROPS...)
16158 means display ELT but applying properties PROPS. */
16163 if (CONSP (XCDR (elt
)))
16164 n
+= display_mode_element (it
, depth
, field_width
- n
,
16165 precision
- n
, XCAR (XCDR (elt
)),
16166 XCDR (XCDR (elt
)), risky
);
16168 else if (SYMBOLP (car
))
16170 tem
= Fboundp (car
);
16174 /* elt is now the cdr, and we know it is a cons cell.
16175 Use its car if CAR has a non-nil value. */
16178 tem
= Fsymbol_value (car
);
16185 /* Symbol's value is nil (or symbol is unbound)
16186 Get the cddr of the original list
16187 and if possible find the caddr and use that. */
16191 else if (!CONSP (elt
))
16196 else if (INTEGERP (car
))
16198 register int lim
= XINT (car
);
16202 /* Negative int means reduce maximum width. */
16203 if (precision
<= 0)
16206 precision
= min (precision
, -lim
);
16210 /* Padding specified. Don't let it be more than
16211 current maximum. */
16213 lim
= min (precision
, lim
);
16215 /* If that's more padding than already wanted, queue it.
16216 But don't reduce padding already specified even if
16217 that is beyond the current truncation point. */
16218 field_width
= max (lim
, field_width
);
16222 else if (STRINGP (car
) || CONSP (car
))
16224 register int limit
= 50;
16225 /* Limit is to protect against circular lists. */
16228 && (precision
<= 0 || n
< precision
))
16230 n
+= display_mode_element (it
, depth
,
16231 /* Do padding only after the last
16232 element in the list. */
16233 (! CONSP (XCDR (elt
))
16236 precision
- n
, XCAR (elt
),
16246 elt
= build_string ("*invalid*");
16250 /* Pad to FIELD_WIDTH. */
16251 if (field_width
> 0 && n
< field_width
)
16253 switch (mode_line_target
)
16255 case MODE_LINE_NOPROP
:
16256 case MODE_LINE_TITLE
:
16257 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
16259 case MODE_LINE_STRING
:
16260 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
16262 case MODE_LINE_DISPLAY
:
16263 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
16272 /* Store a mode-line string element in mode_line_string_list.
16274 If STRING is non-null, display that C string. Otherwise, the Lisp
16275 string LISP_STRING is displayed.
16277 FIELD_WIDTH is the minimum number of output glyphs to produce.
16278 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16279 with spaces. FIELD_WIDTH <= 0 means don't pad.
16281 PRECISION is the maximum number of characters to output from
16282 STRING. PRECISION <= 0 means don't truncate the string.
16284 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
16285 properties to the string.
16287 PROPS are the properties to add to the string.
16288 The mode_line_string_face face property is always added to the string.
16292 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
16294 Lisp_Object lisp_string
;
16303 if (string
!= NULL
)
16305 len
= strlen (string
);
16306 if (precision
> 0 && len
> precision
)
16308 lisp_string
= make_string (string
, len
);
16310 props
= mode_line_string_face_prop
;
16311 else if (!NILP (mode_line_string_face
))
16313 Lisp_Object face
= Fplist_get (props
, Qface
);
16314 props
= Fcopy_sequence (props
);
16316 face
= mode_line_string_face
;
16318 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16319 props
= Fplist_put (props
, Qface
, face
);
16321 Fadd_text_properties (make_number (0), make_number (len
),
16322 props
, lisp_string
);
16326 len
= XFASTINT (Flength (lisp_string
));
16327 if (precision
> 0 && len
> precision
)
16330 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
16333 if (!NILP (mode_line_string_face
))
16337 props
= Ftext_properties_at (make_number (0), lisp_string
);
16338 face
= Fplist_get (props
, Qface
);
16340 face
= mode_line_string_face
;
16342 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16343 props
= Fcons (Qface
, Fcons (face
, Qnil
));
16345 lisp_string
= Fcopy_sequence (lisp_string
);
16348 Fadd_text_properties (make_number (0), make_number (len
),
16349 props
, lisp_string
);
16354 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16358 if (field_width
> len
)
16360 field_width
-= len
;
16361 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
16363 Fadd_text_properties (make_number (0), make_number (field_width
),
16364 props
, lisp_string
);
16365 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16373 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
16375 doc
: /* Format a string out of a mode line format specification.
16376 First arg FORMAT specifies the mode line format (see `mode-line-format'
16377 for details) to use.
16379 Optional second arg FACE specifies the face property to put
16380 on all characters for which no face is specified.
16381 t means whatever face the window's mode line currently uses
16382 \(either `mode-line' or `mode-line-inactive', depending).
16383 nil means the default is no face property.
16384 If FACE is an integer, the value string has no text properties.
16386 Optional third and fourth args WINDOW and BUFFER specify the window
16387 and buffer to use as the context for the formatting (defaults
16388 are the selected window and the window's buffer). */)
16389 (format
, face
, window
, buffer
)
16390 Lisp_Object format
, face
, window
, buffer
;
16395 struct buffer
*old_buffer
= NULL
;
16397 int no_props
= INTEGERP (face
);
16398 int count
= SPECPDL_INDEX ();
16400 int string_start
= 0;
16403 window
= selected_window
;
16404 CHECK_WINDOW (window
);
16405 w
= XWINDOW (window
);
16408 buffer
= w
->buffer
;
16409 CHECK_BUFFER (buffer
);
16412 return build_string ("");
16420 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
16421 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
16425 face_id
= DEFAULT_FACE_ID
;
16427 if (XBUFFER (buffer
) != current_buffer
)
16428 old_buffer
= current_buffer
;
16430 record_unwind_protect (unwind_format_mode_line
,
16431 format_mode_line_unwind_data (old_buffer
));
16434 set_buffer_internal_1 (XBUFFER (buffer
));
16436 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16440 mode_line_target
= MODE_LINE_NOPROP
;
16441 mode_line_string_face_prop
= Qnil
;
16442 mode_line_string_list
= Qnil
;
16443 string_start
= MODE_LINE_NOPROP_LEN (0);
16447 mode_line_target
= MODE_LINE_STRING
;
16448 mode_line_string_list
= Qnil
;
16449 mode_line_string_face
= face
;
16450 mode_line_string_face_prop
16451 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
16454 push_frame_kboard (it
.f
);
16455 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16456 pop_frame_kboard ();
16460 len
= MODE_LINE_NOPROP_LEN (string_start
);
16461 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
16465 mode_line_string_list
= Fnreverse (mode_line_string_list
);
16466 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
16467 make_string ("", 0));
16470 unbind_to (count
, Qnil
);
16474 /* Write a null-terminated, right justified decimal representation of
16475 the positive integer D to BUF using a minimal field width WIDTH. */
16478 pint2str (buf
, width
, d
)
16479 register char *buf
;
16480 register int width
;
16483 register char *p
= buf
;
16491 *p
++ = d
% 10 + '0';
16496 for (width
-= (int) (p
- buf
); width
> 0; --width
)
16507 /* Write a null-terminated, right justified decimal and "human
16508 readable" representation of the nonnegative integer D to BUF using
16509 a minimal field width WIDTH. D should be smaller than 999.5e24. */
16511 static const char power_letter
[] =
16525 pint2hrstr (buf
, width
, d
)
16530 /* We aim to represent the nonnegative integer D as
16531 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
16534 /* -1 means: do not use TENTHS. */
16538 /* Length of QUOTIENT.TENTHS as a string. */
16544 if (1000 <= quotient
)
16546 /* Scale to the appropriate EXPONENT. */
16549 remainder
= quotient
% 1000;
16553 while (1000 <= quotient
);
16555 /* Round to nearest and decide whether to use TENTHS or not. */
16558 tenths
= remainder
/ 100;
16559 if (50 <= remainder
% 100)
16566 if (quotient
== 10)
16574 if (500 <= remainder
)
16576 if (quotient
< 999)
16587 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
16588 if (tenths
== -1 && quotient
<= 99)
16595 p
= psuffix
= buf
+ max (width
, length
);
16597 /* Print EXPONENT. */
16599 *psuffix
++ = power_letter
[exponent
];
16602 /* Print TENTHS. */
16605 *--p
= '0' + tenths
;
16609 /* Print QUOTIENT. */
16612 int digit
= quotient
% 10;
16613 *--p
= '0' + digit
;
16615 while ((quotient
/= 10) != 0);
16617 /* Print leading spaces. */
16622 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
16623 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
16624 type of CODING_SYSTEM. Return updated pointer into BUF. */
16626 static unsigned char invalid_eol_type
[] = "(*invalid*)";
16629 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
16630 Lisp_Object coding_system
;
16631 register char *buf
;
16635 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
16636 const unsigned char *eol_str
;
16638 /* The EOL conversion we are using. */
16639 Lisp_Object eoltype
;
16641 val
= Fget (coding_system
, Qcoding_system
);
16644 if (!VECTORP (val
)) /* Not yet decided. */
16649 eoltype
= eol_mnemonic_undecided
;
16650 /* Don't mention EOL conversion if it isn't decided. */
16654 Lisp_Object eolvalue
;
16656 eolvalue
= Fget (coding_system
, Qeol_type
);
16659 *buf
++ = XFASTINT (AREF (val
, 1));
16663 /* The EOL conversion that is normal on this system. */
16665 if (NILP (eolvalue
)) /* Not yet decided. */
16666 eoltype
= eol_mnemonic_undecided
;
16667 else if (VECTORP (eolvalue
)) /* Not yet decided. */
16668 eoltype
= eol_mnemonic_undecided
;
16669 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
16670 eoltype
= (XFASTINT (eolvalue
) == 0
16671 ? eol_mnemonic_unix
16672 : (XFASTINT (eolvalue
) == 1
16673 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
16679 /* Mention the EOL conversion if it is not the usual one. */
16680 if (STRINGP (eoltype
))
16682 eol_str
= SDATA (eoltype
);
16683 eol_str_len
= SBYTES (eoltype
);
16685 else if (INTEGERP (eoltype
)
16686 && CHAR_VALID_P (XINT (eoltype
), 0))
16688 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
16689 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
16694 eol_str
= invalid_eol_type
;
16695 eol_str_len
= sizeof (invalid_eol_type
) - 1;
16697 bcopy (eol_str
, buf
, eol_str_len
);
16698 buf
+= eol_str_len
;
16704 /* Return a string for the output of a mode line %-spec for window W,
16705 generated by character C. PRECISION >= 0 means don't return a
16706 string longer than that value. FIELD_WIDTH > 0 means pad the
16707 string returned with spaces to that value. Return 1 in *MULTIBYTE
16708 if the result is multibyte text.
16710 Note we operate on the current buffer for most purposes,
16711 the exception being w->base_line_pos. */
16713 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
16716 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
16719 int field_width
, precision
;
16723 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16724 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
16725 struct buffer
*b
= current_buffer
;
16733 if (!NILP (b
->read_only
))
16735 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16740 /* This differs from %* only for a modified read-only buffer. */
16741 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16743 if (!NILP (b
->read_only
))
16748 /* This differs from %* in ignoring read-only-ness. */
16749 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16761 if (command_loop_level
> 5)
16763 p
= decode_mode_spec_buf
;
16764 for (i
= 0; i
< command_loop_level
; i
++)
16767 return decode_mode_spec_buf
;
16775 if (command_loop_level
> 5)
16777 p
= decode_mode_spec_buf
;
16778 for (i
= 0; i
< command_loop_level
; i
++)
16781 return decode_mode_spec_buf
;
16788 /* Let lots_of_dashes be a string of infinite length. */
16789 if (mode_line_target
== MODE_LINE_NOPROP
||
16790 mode_line_target
== MODE_LINE_STRING
)
16792 if (field_width
<= 0
16793 || field_width
> sizeof (lots_of_dashes
))
16795 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
16796 decode_mode_spec_buf
[i
] = '-';
16797 decode_mode_spec_buf
[i
] = '\0';
16798 return decode_mode_spec_buf
;
16801 return lots_of_dashes
;
16810 int col
= (int) current_column (); /* iftc */
16811 w
->column_number_displayed
= make_number (col
);
16812 pint2str (decode_mode_spec_buf
, field_width
, col
);
16813 return decode_mode_spec_buf
;
16817 /* %F displays the frame name. */
16818 if (!NILP (f
->title
))
16819 return (char *) SDATA (f
->title
);
16820 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
16821 return (char *) SDATA (f
->name
);
16830 int size
= ZV
- BEGV
;
16831 pint2str (decode_mode_spec_buf
, field_width
, size
);
16832 return decode_mode_spec_buf
;
16837 int size
= ZV
- BEGV
;
16838 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
16839 return decode_mode_spec_buf
;
16844 int startpos
= XMARKER (w
->start
)->charpos
;
16845 int startpos_byte
= marker_byte_position (w
->start
);
16846 int line
, linepos
, linepos_byte
, topline
;
16848 int height
= WINDOW_TOTAL_LINES (w
);
16850 /* If we decided that this buffer isn't suitable for line numbers,
16851 don't forget that too fast. */
16852 if (EQ (w
->base_line_pos
, w
->buffer
))
16854 /* But do forget it, if the window shows a different buffer now. */
16855 else if (BUFFERP (w
->base_line_pos
))
16856 w
->base_line_pos
= Qnil
;
16858 /* If the buffer is very big, don't waste time. */
16859 if (INTEGERP (Vline_number_display_limit
)
16860 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
16862 w
->base_line_pos
= Qnil
;
16863 w
->base_line_number
= Qnil
;
16867 if (!NILP (w
->base_line_number
)
16868 && !NILP (w
->base_line_pos
)
16869 && XFASTINT (w
->base_line_pos
) <= startpos
)
16871 line
= XFASTINT (w
->base_line_number
);
16872 linepos
= XFASTINT (w
->base_line_pos
);
16873 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
16878 linepos
= BUF_BEGV (b
);
16879 linepos_byte
= BUF_BEGV_BYTE (b
);
16882 /* Count lines from base line to window start position. */
16883 nlines
= display_count_lines (linepos
, linepos_byte
,
16887 topline
= nlines
+ line
;
16889 /* Determine a new base line, if the old one is too close
16890 or too far away, or if we did not have one.
16891 "Too close" means it's plausible a scroll-down would
16892 go back past it. */
16893 if (startpos
== BUF_BEGV (b
))
16895 w
->base_line_number
= make_number (topline
);
16896 w
->base_line_pos
= make_number (BUF_BEGV (b
));
16898 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
16899 || linepos
== BUF_BEGV (b
))
16901 int limit
= BUF_BEGV (b
);
16902 int limit_byte
= BUF_BEGV_BYTE (b
);
16904 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
16906 if (startpos
- distance
> limit
)
16908 limit
= startpos
- distance
;
16909 limit_byte
= CHAR_TO_BYTE (limit
);
16912 nlines
= display_count_lines (startpos
, startpos_byte
,
16914 - (height
* 2 + 30),
16916 /* If we couldn't find the lines we wanted within
16917 line_number_display_limit_width chars per line,
16918 give up on line numbers for this window. */
16919 if (position
== limit_byte
&& limit
== startpos
- distance
)
16921 w
->base_line_pos
= w
->buffer
;
16922 w
->base_line_number
= Qnil
;
16926 w
->base_line_number
= make_number (topline
- nlines
);
16927 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
16930 /* Now count lines from the start pos to point. */
16931 nlines
= display_count_lines (startpos
, startpos_byte
,
16932 PT_BYTE
, PT
, &junk
);
16934 /* Record that we did display the line number. */
16935 line_number_displayed
= 1;
16937 /* Make the string to show. */
16938 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
16939 return decode_mode_spec_buf
;
16942 char* p
= decode_mode_spec_buf
;
16943 int pad
= field_width
- 2;
16949 return decode_mode_spec_buf
;
16955 obj
= b
->mode_name
;
16959 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
16965 int pos
= marker_position (w
->start
);
16966 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16968 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
16970 if (pos
<= BUF_BEGV (b
))
16975 else if (pos
<= BUF_BEGV (b
))
16979 if (total
> 1000000)
16980 /* Do it differently for a large value, to avoid overflow. */
16981 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16983 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16984 /* We can't normally display a 3-digit number,
16985 so get us a 2-digit number that is close. */
16988 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16989 return decode_mode_spec_buf
;
16993 /* Display percentage of size above the bottom of the screen. */
16996 int toppos
= marker_position (w
->start
);
16997 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
16998 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17000 if (botpos
>= BUF_ZV (b
))
17002 if (toppos
<= BUF_BEGV (b
))
17009 if (total
> 1000000)
17010 /* Do it differently for a large value, to avoid overflow. */
17011 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17013 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17014 /* We can't normally display a 3-digit number,
17015 so get us a 2-digit number that is close. */
17018 if (toppos
<= BUF_BEGV (b
))
17019 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
17021 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17022 return decode_mode_spec_buf
;
17027 /* status of process */
17028 obj
= Fget_buffer_process (Fcurrent_buffer ());
17030 return "no process";
17031 #ifdef subprocesses
17032 obj
= Fsymbol_name (Fprocess_status (obj
));
17036 case 't': /* indicate TEXT or BINARY */
17037 #ifdef MODE_LINE_BINARY_TEXT
17038 return MODE_LINE_BINARY_TEXT (b
);
17044 /* coding-system (not including end-of-line format) */
17046 /* coding-system (including end-of-line type) */
17048 int eol_flag
= (c
== 'Z');
17049 char *p
= decode_mode_spec_buf
;
17051 if (! FRAME_WINDOW_P (f
))
17053 /* No need to mention EOL here--the terminal never needs
17054 to do EOL conversion. */
17055 p
= decode_mode_spec_coding (FRAME_KEYBOARD_CODING (f
)->symbol
, p
, 0);
17056 p
= decode_mode_spec_coding (FRAME_TERMINAL_CODING (f
)->symbol
, p
, 0);
17058 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
17061 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
17062 #ifdef subprocesses
17063 obj
= Fget_buffer_process (Fcurrent_buffer ());
17064 if (PROCESSP (obj
))
17066 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
17068 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
17071 #endif /* subprocesses */
17074 return decode_mode_spec_buf
;
17080 *multibyte
= STRING_MULTIBYTE (obj
);
17081 return (char *) SDATA (obj
);
17088 /* Count up to COUNT lines starting from START / START_BYTE.
17089 But don't go beyond LIMIT_BYTE.
17090 Return the number of lines thus found (always nonnegative).
17092 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
17095 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
17096 int start
, start_byte
, limit_byte
, count
;
17099 register unsigned char *cursor
;
17100 unsigned char *base
;
17102 register int ceiling
;
17103 register unsigned char *ceiling_addr
;
17104 int orig_count
= count
;
17106 /* If we are not in selective display mode,
17107 check only for newlines. */
17108 int selective_display
= (!NILP (current_buffer
->selective_display
)
17109 && !INTEGERP (current_buffer
->selective_display
));
17113 while (start_byte
< limit_byte
)
17115 ceiling
= BUFFER_CEILING_OF (start_byte
);
17116 ceiling
= min (limit_byte
- 1, ceiling
);
17117 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
17118 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
17121 if (selective_display
)
17122 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
17125 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
17128 if (cursor
!= ceiling_addr
)
17132 start_byte
+= cursor
- base
+ 1;
17133 *byte_pos_ptr
= start_byte
;
17137 if (++cursor
== ceiling_addr
)
17143 start_byte
+= cursor
- base
;
17148 while (start_byte
> limit_byte
)
17150 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
17151 ceiling
= max (limit_byte
, ceiling
);
17152 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
17153 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
17156 if (selective_display
)
17157 while (--cursor
!= ceiling_addr
17158 && *cursor
!= '\n' && *cursor
!= 015)
17161 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
17164 if (cursor
!= ceiling_addr
)
17168 start_byte
+= cursor
- base
+ 1;
17169 *byte_pos_ptr
= start_byte
;
17170 /* When scanning backwards, we should
17171 not count the newline posterior to which we stop. */
17172 return - orig_count
- 1;
17178 /* Here we add 1 to compensate for the last decrement
17179 of CURSOR, which took it past the valid range. */
17180 start_byte
+= cursor
- base
+ 1;
17184 *byte_pos_ptr
= limit_byte
;
17187 return - orig_count
+ count
;
17188 return orig_count
- count
;
17194 /***********************************************************************
17196 ***********************************************************************/
17198 /* Display a NUL-terminated string, starting with index START.
17200 If STRING is non-null, display that C string. Otherwise, the Lisp
17201 string LISP_STRING is displayed.
17203 If FACE_STRING is not nil, FACE_STRING_POS is a position in
17204 FACE_STRING. Display STRING or LISP_STRING with the face at
17205 FACE_STRING_POS in FACE_STRING:
17207 Display the string in the environment given by IT, but use the
17208 standard display table, temporarily.
17210 FIELD_WIDTH is the minimum number of output glyphs to produce.
17211 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17212 with spaces. If STRING has more characters, more than FIELD_WIDTH
17213 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
17215 PRECISION is the maximum number of characters to output from
17216 STRING. PRECISION < 0 means don't truncate the string.
17218 This is roughly equivalent to printf format specifiers:
17220 FIELD_WIDTH PRECISION PRINTF
17221 ----------------------------------------
17227 MULTIBYTE zero means do not display multibyte chars, > 0 means do
17228 display them, and < 0 means obey the current buffer's value of
17229 enable_multibyte_characters.
17231 Value is the number of glyphs produced. */
17234 display_string (string
, lisp_string
, face_string
, face_string_pos
,
17235 start
, it
, field_width
, precision
, max_x
, multibyte
)
17236 unsigned char *string
;
17237 Lisp_Object lisp_string
;
17238 Lisp_Object face_string
;
17239 int face_string_pos
;
17242 int field_width
, precision
, max_x
;
17245 int hpos_at_start
= it
->hpos
;
17246 int saved_face_id
= it
->face_id
;
17247 struct glyph_row
*row
= it
->glyph_row
;
17249 /* Initialize the iterator IT for iteration over STRING beginning
17250 with index START. */
17251 reseat_to_string (it
, string
, lisp_string
, start
,
17252 precision
, field_width
, multibyte
);
17254 /* If displaying STRING, set up the face of the iterator
17255 from LISP_STRING, if that's given. */
17256 if (STRINGP (face_string
))
17262 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
17263 0, it
->region_beg_charpos
,
17264 it
->region_end_charpos
,
17265 &endptr
, it
->base_face_id
, 0);
17266 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17267 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
17270 /* Set max_x to the maximum allowed X position. Don't let it go
17271 beyond the right edge of the window. */
17273 max_x
= it
->last_visible_x
;
17275 max_x
= min (max_x
, it
->last_visible_x
);
17277 /* Skip over display elements that are not visible. because IT->w is
17279 if (it
->current_x
< it
->first_visible_x
)
17280 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
17281 MOVE_TO_POS
| MOVE_TO_X
);
17283 row
->ascent
= it
->max_ascent
;
17284 row
->height
= it
->max_ascent
+ it
->max_descent
;
17285 row
->phys_ascent
= it
->max_phys_ascent
;
17286 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17287 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17289 /* This condition is for the case that we are called with current_x
17290 past last_visible_x. */
17291 while (it
->current_x
< max_x
)
17293 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
17295 /* Get the next display element. */
17296 if (!get_next_display_element (it
))
17299 /* Produce glyphs. */
17300 x_before
= it
->current_x
;
17301 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17302 PRODUCE_GLYPHS (it
);
17304 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
17307 while (i
< nglyphs
)
17309 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17311 if (!it
->truncate_lines_p
17312 && x
+ glyph
->pixel_width
> max_x
)
17314 /* End of continued line or max_x reached. */
17315 if (CHAR_GLYPH_PADDING_P (*glyph
))
17317 /* A wide character is unbreakable. */
17318 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17319 it
->current_x
= x_before
;
17323 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17328 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
17330 /* Glyph is at least partially visible. */
17332 if (x
< it
->first_visible_x
)
17333 it
->glyph_row
->x
= x
- it
->first_visible_x
;
17337 /* Glyph is off the left margin of the display area.
17338 Should not happen. */
17342 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17343 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17344 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17345 row
->phys_height
= max (row
->phys_height
,
17346 it
->max_phys_ascent
+ it
->max_phys_descent
);
17347 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17348 it
->max_extra_line_spacing
);
17349 x
+= glyph
->pixel_width
;
17353 /* Stop if max_x reached. */
17357 /* Stop at line ends. */
17358 if (ITERATOR_AT_END_OF_LINE_P (it
))
17360 it
->continuation_lines_width
= 0;
17364 set_iterator_to_next (it
, 1);
17366 /* Stop if truncating at the right edge. */
17367 if (it
->truncate_lines_p
17368 && it
->current_x
>= it
->last_visible_x
)
17370 /* Add truncation mark, but don't do it if the line is
17371 truncated at a padding space. */
17372 if (IT_CHARPOS (*it
) < it
->string_nchars
)
17374 if (!FRAME_WINDOW_P (it
->f
))
17378 if (it
->current_x
> it
->last_visible_x
)
17380 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17381 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17383 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17385 row
->used
[TEXT_AREA
] = i
;
17386 produce_special_glyphs (it
, IT_TRUNCATION
);
17389 produce_special_glyphs (it
, IT_TRUNCATION
);
17391 it
->glyph_row
->truncated_on_right_p
= 1;
17397 /* Maybe insert a truncation at the left. */
17398 if (it
->first_visible_x
17399 && IT_CHARPOS (*it
) > 0)
17401 if (!FRAME_WINDOW_P (it
->f
))
17402 insert_left_trunc_glyphs (it
);
17403 it
->glyph_row
->truncated_on_left_p
= 1;
17406 it
->face_id
= saved_face_id
;
17408 /* Value is number of columns displayed. */
17409 return it
->hpos
- hpos_at_start
;
17414 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
17415 appears as an element of LIST or as the car of an element of LIST.
17416 If PROPVAL is a list, compare each element against LIST in that
17417 way, and return 1/2 if any element of PROPVAL is found in LIST.
17418 Otherwise return 0. This function cannot quit.
17419 The return value is 2 if the text is invisible but with an ellipsis
17420 and 1 if it's invisible and without an ellipsis. */
17423 invisible_p (propval
, list
)
17424 register Lisp_Object propval
;
17427 register Lisp_Object tail
, proptail
;
17429 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17431 register Lisp_Object tem
;
17433 if (EQ (propval
, tem
))
17435 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
17436 return NILP (XCDR (tem
)) ? 1 : 2;
17439 if (CONSP (propval
))
17441 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
17443 Lisp_Object propelt
;
17444 propelt
= XCAR (proptail
);
17445 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17447 register Lisp_Object tem
;
17449 if (EQ (propelt
, tem
))
17451 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
17452 return NILP (XCDR (tem
)) ? 1 : 2;
17460 /* Calculate a width or height in pixels from a specification using
17461 the following elements:
17464 NUM - a (fractional) multiple of the default font width/height
17465 (NUM) - specifies exactly NUM pixels
17466 UNIT - a fixed number of pixels, see below.
17467 ELEMENT - size of a display element in pixels, see below.
17468 (NUM . SPEC) - equals NUM * SPEC
17469 (+ SPEC SPEC ...) - add pixel values
17470 (- SPEC SPEC ...) - subtract pixel values
17471 (- SPEC) - negate pixel value
17474 INT or FLOAT - a number constant
17475 SYMBOL - use symbol's (buffer local) variable binding.
17478 in - pixels per inch *)
17479 mm - pixels per 1/1000 meter *)
17480 cm - pixels per 1/100 meter *)
17481 width - width of current font in pixels.
17482 height - height of current font in pixels.
17484 *) using the ratio(s) defined in display-pixels-per-inch.
17488 left-fringe - left fringe width in pixels
17489 right-fringe - right fringe width in pixels
17491 left-margin - left margin width in pixels
17492 right-margin - right margin width in pixels
17494 scroll-bar - scroll-bar area width in pixels
17498 Pixels corresponding to 5 inches:
17501 Total width of non-text areas on left side of window (if scroll-bar is on left):
17502 '(space :width (+ left-fringe left-margin scroll-bar))
17504 Align to first text column (in header line):
17505 '(space :align-to 0)
17507 Align to middle of text area minus half the width of variable `my-image'
17508 containing a loaded image:
17509 '(space :align-to (0.5 . (- text my-image)))
17511 Width of left margin minus width of 1 character in the default font:
17512 '(space :width (- left-margin 1))
17514 Width of left margin minus width of 2 characters in the current font:
17515 '(space :width (- left-margin (2 . width)))
17517 Center 1 character over left-margin (in header line):
17518 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
17520 Different ways to express width of left fringe plus left margin minus one pixel:
17521 '(space :width (- (+ left-fringe left-margin) (1)))
17522 '(space :width (+ left-fringe left-margin (- (1))))
17523 '(space :width (+ left-fringe left-margin (-1)))
17527 #define NUMVAL(X) \
17528 ((INTEGERP (X) || FLOATP (X)) \
17533 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
17538 int width_p
, *align_to
;
17542 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
17543 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
17546 return OK_PIXELS (0);
17548 if (SYMBOLP (prop
))
17550 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
17552 char *unit
= SDATA (SYMBOL_NAME (prop
));
17554 if (unit
[0] == 'i' && unit
[1] == 'n')
17556 else if (unit
[0] == 'm' && unit
[1] == 'm')
17558 else if (unit
[0] == 'c' && unit
[1] == 'm')
17565 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
17566 || (CONSP (Vdisplay_pixels_per_inch
)
17568 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
17569 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
17571 return OK_PIXELS (ppi
/ pixels
);
17577 #ifdef HAVE_WINDOW_SYSTEM
17578 if (EQ (prop
, Qheight
))
17579 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
17580 if (EQ (prop
, Qwidth
))
17581 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
17583 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
17584 return OK_PIXELS (1);
17587 if (EQ (prop
, Qtext
))
17588 return OK_PIXELS (width_p
17589 ? window_box_width (it
->w
, TEXT_AREA
)
17590 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
17592 if (align_to
&& *align_to
< 0)
17595 if (EQ (prop
, Qleft
))
17596 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
17597 if (EQ (prop
, Qright
))
17598 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
17599 if (EQ (prop
, Qcenter
))
17600 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
17601 + window_box_width (it
->w
, TEXT_AREA
) / 2);
17602 if (EQ (prop
, Qleft_fringe
))
17603 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17604 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
17605 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
17606 if (EQ (prop
, Qright_fringe
))
17607 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17608 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17609 : window_box_right_offset (it
->w
, TEXT_AREA
));
17610 if (EQ (prop
, Qleft_margin
))
17611 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
17612 if (EQ (prop
, Qright_margin
))
17613 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
17614 if (EQ (prop
, Qscroll_bar
))
17615 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
17617 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17618 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17619 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
17624 if (EQ (prop
, Qleft_fringe
))
17625 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
17626 if (EQ (prop
, Qright_fringe
))
17627 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
17628 if (EQ (prop
, Qleft_margin
))
17629 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
17630 if (EQ (prop
, Qright_margin
))
17631 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
17632 if (EQ (prop
, Qscroll_bar
))
17633 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
17636 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
17639 if (INTEGERP (prop
) || FLOATP (prop
))
17641 int base_unit
= (width_p
17642 ? FRAME_COLUMN_WIDTH (it
->f
)
17643 : FRAME_LINE_HEIGHT (it
->f
));
17644 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
17649 Lisp_Object car
= XCAR (prop
);
17650 Lisp_Object cdr
= XCDR (prop
);
17654 #ifdef HAVE_WINDOW_SYSTEM
17655 if (valid_image_p (prop
))
17657 int id
= lookup_image (it
->f
, prop
);
17658 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
17660 return OK_PIXELS (width_p
? img
->width
: img
->height
);
17663 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
17669 while (CONSP (cdr
))
17671 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
17672 font
, width_p
, align_to
))
17675 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
17680 if (EQ (car
, Qminus
))
17682 return OK_PIXELS (pixels
);
17685 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
17688 if (INTEGERP (car
) || FLOATP (car
))
17691 pixels
= XFLOATINT (car
);
17693 return OK_PIXELS (pixels
);
17694 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
17695 font
, width_p
, align_to
))
17696 return OK_PIXELS (pixels
* fact
);
17707 /***********************************************************************
17709 ***********************************************************************/
17711 #ifdef HAVE_WINDOW_SYSTEM
17716 dump_glyph_string (s
)
17717 struct glyph_string
*s
;
17719 fprintf (stderr
, "glyph string\n");
17720 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
17721 s
->x
, s
->y
, s
->width
, s
->height
);
17722 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
17723 fprintf (stderr
, " hl = %d\n", s
->hl
);
17724 fprintf (stderr
, " left overhang = %d, right = %d\n",
17725 s
->left_overhang
, s
->right_overhang
);
17726 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
17727 fprintf (stderr
, " extends to end of line = %d\n",
17728 s
->extends_to_end_of_line_p
);
17729 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
17730 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
17733 #endif /* GLYPH_DEBUG */
17735 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
17736 of XChar2b structures for S; it can't be allocated in
17737 init_glyph_string because it must be allocated via `alloca'. W
17738 is the window on which S is drawn. ROW and AREA are the glyph row
17739 and area within the row from which S is constructed. START is the
17740 index of the first glyph structure covered by S. HL is a
17741 face-override for drawing S. */
17744 #define OPTIONAL_HDC(hdc) hdc,
17745 #define DECLARE_HDC(hdc) HDC hdc;
17746 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
17747 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
17750 #ifndef OPTIONAL_HDC
17751 #define OPTIONAL_HDC(hdc)
17752 #define DECLARE_HDC(hdc)
17753 #define ALLOCATE_HDC(hdc, f)
17754 #define RELEASE_HDC(hdc, f)
17758 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
17759 struct glyph_string
*s
;
17763 struct glyph_row
*row
;
17764 enum glyph_row_area area
;
17766 enum draw_glyphs_face hl
;
17768 bzero (s
, sizeof *s
);
17770 s
->f
= XFRAME (w
->frame
);
17774 s
->display
= FRAME_X_DISPLAY (s
->f
);
17775 s
->window
= FRAME_X_WINDOW (s
->f
);
17776 s
->char2b
= char2b
;
17780 s
->first_glyph
= row
->glyphs
[area
] + start
;
17781 s
->height
= row
->height
;
17782 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
17784 /* Display the internal border below the tool-bar window. */
17785 if (WINDOWP (s
->f
->tool_bar_window
)
17786 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
17787 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
17789 s
->ybase
= s
->y
+ row
->ascent
;
17793 /* Append the list of glyph strings with head H and tail T to the list
17794 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
17797 append_glyph_string_lists (head
, tail
, h
, t
)
17798 struct glyph_string
**head
, **tail
;
17799 struct glyph_string
*h
, *t
;
17813 /* Prepend the list of glyph strings with head H and tail T to the
17814 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
17818 prepend_glyph_string_lists (head
, tail
, h
, t
)
17819 struct glyph_string
**head
, **tail
;
17820 struct glyph_string
*h
, *t
;
17834 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
17835 Set *HEAD and *TAIL to the resulting list. */
17838 append_glyph_string (head
, tail
, s
)
17839 struct glyph_string
**head
, **tail
;
17840 struct glyph_string
*s
;
17842 s
->next
= s
->prev
= NULL
;
17843 append_glyph_string_lists (head
, tail
, s
, s
);
17847 /* Get face and two-byte form of character glyph GLYPH on frame F.
17848 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
17849 a pointer to a realized face that is ready for display. */
17851 static INLINE
struct face
*
17852 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
17854 struct glyph
*glyph
;
17860 xassert (glyph
->type
== CHAR_GLYPH
);
17861 face
= FACE_FROM_ID (f
, glyph
->face_id
);
17866 if (!glyph
->multibyte_p
)
17868 /* Unibyte case. We don't have to encode, but we have to make
17869 sure to use a face suitable for unibyte. */
17870 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17872 else if (glyph
->u
.ch
< 128
17873 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
17875 /* Case of ASCII in a face known to fit ASCII. */
17876 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17880 int c1
, c2
, charset
;
17882 /* Split characters into bytes. If c2 is -1 afterwards, C is
17883 really a one-byte character so that byte1 is zero. */
17884 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
17886 STORE_XCHAR2B (char2b
, c1
, c2
);
17888 STORE_XCHAR2B (char2b
, 0, c1
);
17890 /* Maybe encode the character in *CHAR2B. */
17891 if (charset
!= CHARSET_ASCII
)
17893 struct font_info
*font_info
17894 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17897 = FRAME_RIF (f
)->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
17901 /* Make sure X resources of the face are allocated. */
17902 xassert (face
!= NULL
);
17903 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17908 /* Fill glyph string S with composition components specified by S->cmp.
17910 FACES is an array of faces for all components of this composition.
17911 S->gidx is the index of the first component for S.
17912 OVERLAPS_P non-zero means S should draw the foreground only, and
17913 use its physical height for clipping.
17915 Value is the index of a component not in S. */
17918 fill_composite_glyph_string (s
, faces
, overlaps_p
)
17919 struct glyph_string
*s
;
17920 struct face
**faces
;
17927 s
->for_overlaps_p
= overlaps_p
;
17929 s
->face
= faces
[s
->gidx
];
17930 s
->font
= s
->face
->font
;
17931 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17933 /* For all glyphs of this composition, starting at the offset
17934 S->gidx, until we reach the end of the definition or encounter a
17935 glyph that requires the different face, add it to S. */
17937 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
17940 /* All glyph strings for the same composition has the same width,
17941 i.e. the width set for the first component of the composition. */
17943 s
->width
= s
->first_glyph
->pixel_width
;
17945 /* If the specified font could not be loaded, use the frame's
17946 default font, but record the fact that we couldn't load it in
17947 the glyph string so that we can draw rectangles for the
17948 characters of the glyph string. */
17949 if (s
->font
== NULL
)
17951 s
->font_not_found_p
= 1;
17952 s
->font
= FRAME_FONT (s
->f
);
17955 /* Adjust base line for subscript/superscript text. */
17956 s
->ybase
+= s
->first_glyph
->voffset
;
17958 xassert (s
->face
&& s
->face
->gc
);
17960 /* This glyph string must always be drawn with 16-bit functions. */
17963 return s
->gidx
+ s
->nchars
;
17967 /* Fill glyph string S from a sequence of character glyphs.
17969 FACE_ID is the face id of the string. START is the index of the
17970 first glyph to consider, END is the index of the last + 1.
17971 OVERLAPS_P non-zero means S should draw the foreground only, and
17972 use its physical height for clipping.
17974 Value is the index of the first glyph not in S. */
17977 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
17978 struct glyph_string
*s
;
17980 int start
, end
, overlaps_p
;
17982 struct glyph
*glyph
, *last
;
17984 int glyph_not_available_p
;
17986 xassert (s
->f
== XFRAME (s
->w
->frame
));
17987 xassert (s
->nchars
== 0);
17988 xassert (start
>= 0 && end
> start
);
17990 s
->for_overlaps_p
= overlaps_p
,
17991 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17992 last
= s
->row
->glyphs
[s
->area
] + end
;
17993 voffset
= glyph
->voffset
;
17995 glyph_not_available_p
= glyph
->glyph_not_available_p
;
17997 while (glyph
< last
17998 && glyph
->type
== CHAR_GLYPH
17999 && glyph
->voffset
== voffset
18000 /* Same face id implies same font, nowadays. */
18001 && glyph
->face_id
== face_id
18002 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
18006 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
18007 s
->char2b
+ s
->nchars
,
18009 s
->two_byte_p
= two_byte_p
;
18011 xassert (s
->nchars
<= end
- start
);
18012 s
->width
+= glyph
->pixel_width
;
18016 s
->font
= s
->face
->font
;
18017 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18019 /* If the specified font could not be loaded, use the frame's font,
18020 but record the fact that we couldn't load it in
18021 S->font_not_found_p so that we can draw rectangles for the
18022 characters of the glyph string. */
18023 if (s
->font
== NULL
|| glyph_not_available_p
)
18025 s
->font_not_found_p
= 1;
18026 s
->font
= FRAME_FONT (s
->f
);
18029 /* Adjust base line for subscript/superscript text. */
18030 s
->ybase
+= voffset
;
18032 xassert (s
->face
&& s
->face
->gc
);
18033 return glyph
- s
->row
->glyphs
[s
->area
];
18037 /* Fill glyph string S from image glyph S->first_glyph. */
18040 fill_image_glyph_string (s
)
18041 struct glyph_string
*s
;
18043 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
18044 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
18046 s
->slice
= s
->first_glyph
->slice
;
18047 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
18048 s
->font
= s
->face
->font
;
18049 s
->width
= s
->first_glyph
->pixel_width
;
18051 /* Adjust base line for subscript/superscript text. */
18052 s
->ybase
+= s
->first_glyph
->voffset
;
18056 /* Fill glyph string S from a sequence of stretch glyphs.
18058 ROW is the glyph row in which the glyphs are found, AREA is the
18059 area within the row. START is the index of the first glyph to
18060 consider, END is the index of the last + 1.
18062 Value is the index of the first glyph not in S. */
18065 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
18066 struct glyph_string
*s
;
18067 struct glyph_row
*row
;
18068 enum glyph_row_area area
;
18071 struct glyph
*glyph
, *last
;
18072 int voffset
, face_id
;
18074 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
18076 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18077 last
= s
->row
->glyphs
[s
->area
] + end
;
18078 face_id
= glyph
->face_id
;
18079 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
18080 s
->font
= s
->face
->font
;
18081 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18082 s
->width
= glyph
->pixel_width
;
18083 voffset
= glyph
->voffset
;
18087 && glyph
->type
== STRETCH_GLYPH
18088 && glyph
->voffset
== voffset
18089 && glyph
->face_id
== face_id
);
18091 s
->width
+= glyph
->pixel_width
;
18093 /* Adjust base line for subscript/superscript text. */
18094 s
->ybase
+= voffset
;
18096 /* The case that face->gc == 0 is handled when drawing the glyph
18097 string by calling PREPARE_FACE_FOR_DISPLAY. */
18099 return glyph
- s
->row
->glyphs
[s
->area
];
18104 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
18105 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
18106 assumed to be zero. */
18109 x_get_glyph_overhangs (glyph
, f
, left
, right
)
18110 struct glyph
*glyph
;
18114 *left
= *right
= 0;
18116 if (glyph
->type
== CHAR_GLYPH
)
18120 struct font_info
*font_info
;
18124 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
18126 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18127 if (font
/* ++KFS: Should this be font_info ? */
18128 && (pcm
= FRAME_RIF (f
)->per_char_metric (font
, &char2b
, glyph
->font_type
)))
18130 if (pcm
->rbearing
> pcm
->width
)
18131 *right
= pcm
->rbearing
- pcm
->width
;
18132 if (pcm
->lbearing
< 0)
18133 *left
= -pcm
->lbearing
;
18139 /* Return the index of the first glyph preceding glyph string S that
18140 is overwritten by S because of S's left overhang. Value is -1
18141 if no glyphs are overwritten. */
18144 left_overwritten (s
)
18145 struct glyph_string
*s
;
18149 if (s
->left_overhang
)
18152 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18153 int first
= s
->first_glyph
- glyphs
;
18155 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
18156 x
-= glyphs
[i
].pixel_width
;
18167 /* Return the index of the first glyph preceding glyph string S that
18168 is overwriting S because of its right overhang. Value is -1 if no
18169 glyph in front of S overwrites S. */
18172 left_overwriting (s
)
18173 struct glyph_string
*s
;
18176 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18177 int first
= s
->first_glyph
- glyphs
;
18181 for (i
= first
- 1; i
>= 0; --i
)
18184 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18187 x
-= glyphs
[i
].pixel_width
;
18194 /* Return the index of the last glyph following glyph string S that is
18195 not overwritten by S because of S's right overhang. Value is -1 if
18196 no such glyph is found. */
18199 right_overwritten (s
)
18200 struct glyph_string
*s
;
18204 if (s
->right_overhang
)
18207 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18208 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18209 int end
= s
->row
->used
[s
->area
];
18211 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
18212 x
+= glyphs
[i
].pixel_width
;
18221 /* Return the index of the last glyph following glyph string S that
18222 overwrites S because of its left overhang. Value is negative
18223 if no such glyph is found. */
18226 right_overwriting (s
)
18227 struct glyph_string
*s
;
18230 int end
= s
->row
->used
[s
->area
];
18231 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18232 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18236 for (i
= first
; i
< end
; ++i
)
18239 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18242 x
+= glyphs
[i
].pixel_width
;
18249 /* Get face and two-byte form of character C in face FACE_ID on frame
18250 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
18251 means we want to display multibyte text. DISPLAY_P non-zero means
18252 make sure that X resources for the face returned are allocated.
18253 Value is a pointer to a realized face that is ready for display if
18254 DISPLAY_P is non-zero. */
18256 static INLINE
struct face
*
18257 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
18261 int multibyte_p
, display_p
;
18263 struct face
*face
= FACE_FROM_ID (f
, face_id
);
18267 /* Unibyte case. We don't have to encode, but we have to make
18268 sure to use a face suitable for unibyte. */
18269 STORE_XCHAR2B (char2b
, 0, c
);
18270 face_id
= FACE_FOR_CHAR (f
, face
, c
);
18271 face
= FACE_FROM_ID (f
, face_id
);
18273 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
18275 /* Case of ASCII in a face known to fit ASCII. */
18276 STORE_XCHAR2B (char2b
, 0, c
);
18280 int c1
, c2
, charset
;
18282 /* Split characters into bytes. If c2 is -1 afterwards, C is
18283 really a one-byte character so that byte1 is zero. */
18284 SPLIT_CHAR (c
, charset
, c1
, c2
);
18286 STORE_XCHAR2B (char2b
, c1
, c2
);
18288 STORE_XCHAR2B (char2b
, 0, c1
);
18290 /* Maybe encode the character in *CHAR2B. */
18291 if (face
->font
!= NULL
)
18293 struct font_info
*font_info
18294 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18296 FRAME_RIF (f
)->encode_char (c
, char2b
, font_info
, 0);
18300 /* Make sure X resources of the face are allocated. */
18301 #ifdef HAVE_X_WINDOWS
18305 xassert (face
!= NULL
);
18306 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18313 /* Set background width of glyph string S. START is the index of the
18314 first glyph following S. LAST_X is the right-most x-position + 1
18315 in the drawing area. */
18318 set_glyph_string_background_width (s
, start
, last_x
)
18319 struct glyph_string
*s
;
18323 /* If the face of this glyph string has to be drawn to the end of
18324 the drawing area, set S->extends_to_end_of_line_p. */
18325 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
18327 if (start
== s
->row
->used
[s
->area
]
18328 && s
->area
== TEXT_AREA
18329 && ((s
->hl
== DRAW_NORMAL_TEXT
18330 && (s
->row
->fill_line_p
18331 || s
->face
->background
!= default_face
->background
18332 || s
->face
->stipple
!= default_face
->stipple
18333 || s
->row
->mouse_face_p
))
18334 || s
->hl
== DRAW_MOUSE_FACE
18335 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
18336 && s
->row
->fill_line_p
)))
18337 s
->extends_to_end_of_line_p
= 1;
18339 /* If S extends its face to the end of the line, set its
18340 background_width to the distance to the right edge of the drawing
18342 if (s
->extends_to_end_of_line_p
)
18343 s
->background_width
= last_x
- s
->x
+ 1;
18345 s
->background_width
= s
->width
;
18349 /* Compute overhangs and x-positions for glyph string S and its
18350 predecessors, or successors. X is the starting x-position for S.
18351 BACKWARD_P non-zero means process predecessors. */
18354 compute_overhangs_and_x (s
, x
, backward_p
)
18355 struct glyph_string
*s
;
18363 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
18364 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
18374 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
18375 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
18385 /* The following macros are only called from draw_glyphs below.
18386 They reference the following parameters of that function directly:
18387 `w', `row', `area', and `overlap_p'
18388 as well as the following local variables:
18389 `s', `f', and `hdc' (in W32) */
18392 /* On W32, silently add local `hdc' variable to argument list of
18393 init_glyph_string. */
18394 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18395 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
18397 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18398 init_glyph_string (s, char2b, w, row, area, start, hl)
18401 /* Add a glyph string for a stretch glyph to the list of strings
18402 between HEAD and TAIL. START is the index of the stretch glyph in
18403 row area AREA of glyph row ROW. END is the index of the last glyph
18404 in that glyph row area. X is the current output position assigned
18405 to the new glyph string constructed. HL overrides that face of the
18406 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18407 is the right-most x-position of the drawing area. */
18409 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
18410 and below -- keep them on one line. */
18411 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18414 s = (struct glyph_string *) alloca (sizeof *s); \
18415 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18416 START = fill_stretch_glyph_string (s, row, area, START, END); \
18417 append_glyph_string (&HEAD, &TAIL, s); \
18423 /* Add a glyph string for an image glyph to the list of strings
18424 between HEAD and TAIL. START is the index of the image glyph in
18425 row area AREA of glyph row ROW. END is the index of the last glyph
18426 in that glyph row area. X is the current output position assigned
18427 to the new glyph string constructed. HL overrides that face of the
18428 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18429 is the right-most x-position of the drawing area. */
18431 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18434 s = (struct glyph_string *) alloca (sizeof *s); \
18435 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18436 fill_image_glyph_string (s); \
18437 append_glyph_string (&HEAD, &TAIL, s); \
18444 /* Add a glyph string for a sequence of character glyphs to the list
18445 of strings between HEAD and TAIL. START is the index of the first
18446 glyph in row area AREA of glyph row ROW that is part of the new
18447 glyph string. END is the index of the last glyph in that glyph row
18448 area. X is the current output position assigned to the new glyph
18449 string constructed. HL overrides that face of the glyph; e.g. it
18450 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
18451 right-most x-position of the drawing area. */
18453 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18459 c = (row)->glyphs[area][START].u.ch; \
18460 face_id = (row)->glyphs[area][START].face_id; \
18462 s = (struct glyph_string *) alloca (sizeof *s); \
18463 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
18464 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
18465 append_glyph_string (&HEAD, &TAIL, s); \
18467 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
18472 /* Add a glyph string for a composite sequence to the list of strings
18473 between HEAD and TAIL. START is the index of the first glyph in
18474 row area AREA of glyph row ROW that is part of the new glyph
18475 string. END is the index of the last glyph in that glyph row area.
18476 X is the current output position assigned to the new glyph string
18477 constructed. HL overrides that face of the glyph; e.g. it is
18478 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
18479 x-position of the drawing area. */
18481 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18483 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
18484 int face_id = (row)->glyphs[area][START].face_id; \
18485 struct face *base_face = FACE_FROM_ID (f, face_id); \
18486 struct composition *cmp = composition_table[cmp_id]; \
18487 int glyph_len = cmp->glyph_len; \
18489 struct face **faces; \
18490 struct glyph_string *first_s = NULL; \
18493 base_face = base_face->ascii_face; \
18494 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
18495 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
18496 /* At first, fill in `char2b' and `faces'. */ \
18497 for (n = 0; n < glyph_len; n++) \
18499 int c = COMPOSITION_GLYPH (cmp, n); \
18500 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
18501 faces[n] = FACE_FROM_ID (f, this_face_id); \
18502 get_char_face_and_encoding (f, c, this_face_id, \
18503 char2b + n, 1, 1); \
18506 /* Make glyph_strings for each glyph sequence that is drawable by \
18507 the same face, and append them to HEAD/TAIL. */ \
18508 for (n = 0; n < cmp->glyph_len;) \
18510 s = (struct glyph_string *) alloca (sizeof *s); \
18511 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
18512 append_glyph_string (&(HEAD), &(TAIL), s); \
18520 n = fill_composite_glyph_string (s, faces, overlaps_p); \
18528 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
18529 of AREA of glyph row ROW on window W between indices START and END.
18530 HL overrides the face for drawing glyph strings, e.g. it is
18531 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
18532 x-positions of the drawing area.
18534 This is an ugly monster macro construct because we must use alloca
18535 to allocate glyph strings (because draw_glyphs can be called
18536 asynchronously). */
18538 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18541 HEAD = TAIL = NULL; \
18542 while (START < END) \
18544 struct glyph *first_glyph = (row)->glyphs[area] + START; \
18545 switch (first_glyph->type) \
18548 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
18552 case COMPOSITE_GLYPH: \
18553 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
18557 case STRETCH_GLYPH: \
18558 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
18562 case IMAGE_GLYPH: \
18563 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
18571 set_glyph_string_background_width (s, START, LAST_X); \
18578 /* Draw glyphs between START and END in AREA of ROW on window W,
18579 starting at x-position X. X is relative to AREA in W. HL is a
18580 face-override with the following meaning:
18582 DRAW_NORMAL_TEXT draw normally
18583 DRAW_CURSOR draw in cursor face
18584 DRAW_MOUSE_FACE draw in mouse face.
18585 DRAW_INVERSE_VIDEO draw in mode line face
18586 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
18587 DRAW_IMAGE_RAISED draw an image with a raised relief around it
18589 If OVERLAPS_P is non-zero, draw only the foreground of characters
18590 and clip to the physical height of ROW.
18592 Value is the x-position reached, relative to AREA of W. */
18595 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
18598 struct glyph_row
*row
;
18599 enum glyph_row_area area
;
18601 enum draw_glyphs_face hl
;
18604 struct glyph_string
*head
, *tail
;
18605 struct glyph_string
*s
;
18606 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
18607 int last_x
, area_width
;
18610 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18613 ALLOCATE_HDC (hdc
, f
);
18615 /* Let's rather be paranoid than getting a SEGV. */
18616 end
= min (end
, row
->used
[area
]);
18617 start
= max (0, start
);
18618 start
= min (end
, start
);
18620 /* Translate X to frame coordinates. Set last_x to the right
18621 end of the drawing area. */
18622 if (row
->full_width_p
)
18624 /* X is relative to the left edge of W, without scroll bars
18626 x
+= WINDOW_LEFT_EDGE_X (w
);
18627 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
18631 int area_left
= window_box_left (w
, area
);
18633 area_width
= window_box_width (w
, area
);
18634 last_x
= area_left
+ area_width
;
18637 /* Build a doubly-linked list of glyph_string structures between
18638 head and tail from what we have to draw. Note that the macro
18639 BUILD_GLYPH_STRINGS will modify its start parameter. That's
18640 the reason we use a separate variable `i'. */
18642 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
18644 x_reached
= tail
->x
+ tail
->background_width
;
18648 /* If there are any glyphs with lbearing < 0 or rbearing > width in
18649 the row, redraw some glyphs in front or following the glyph
18650 strings built above. */
18651 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
18654 struct glyph_string
*h
, *t
;
18656 /* Compute overhangs for all glyph strings. */
18657 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
18658 for (s
= head
; s
; s
= s
->next
)
18659 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
18661 /* Prepend glyph strings for glyphs in front of the first glyph
18662 string that are overwritten because of the first glyph
18663 string's left overhang. The background of all strings
18664 prepended must be drawn because the first glyph string
18666 i
= left_overwritten (head
);
18670 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
18671 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18673 compute_overhangs_and_x (t
, head
->x
, 1);
18674 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18678 /* Prepend glyph strings for glyphs in front of the first glyph
18679 string that overwrite that glyph string because of their
18680 right overhang. For these strings, only the foreground must
18681 be drawn, because it draws over the glyph string at `head'.
18682 The background must not be drawn because this would overwrite
18683 right overhangs of preceding glyphs for which no glyph
18685 i
= left_overwriting (head
);
18689 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
18690 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18691 for (s
= h
; s
; s
= s
->next
)
18692 s
->background_filled_p
= 1;
18693 compute_overhangs_and_x (t
, head
->x
, 1);
18694 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18697 /* Append glyphs strings for glyphs following the last glyph
18698 string tail that are overwritten by tail. The background of
18699 these strings has to be drawn because tail's foreground draws
18701 i
= right_overwritten (tail
);
18704 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18705 DRAW_NORMAL_TEXT
, x
, last_x
);
18706 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18707 append_glyph_string_lists (&head
, &tail
, h
, t
);
18711 /* Append glyph strings for glyphs following the last glyph
18712 string tail that overwrite tail. The foreground of such
18713 glyphs has to be drawn because it writes into the background
18714 of tail. The background must not be drawn because it could
18715 paint over the foreground of following glyphs. */
18716 i
= right_overwriting (tail
);
18720 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18721 DRAW_NORMAL_TEXT
, x
, last_x
);
18722 for (s
= h
; s
; s
= s
->next
)
18723 s
->background_filled_p
= 1;
18724 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18725 append_glyph_string_lists (&head
, &tail
, h
, t
);
18727 if (clip_head
|| clip_tail
)
18728 for (s
= head
; s
; s
= s
->next
)
18730 s
->clip_head
= clip_head
;
18731 s
->clip_tail
= clip_tail
;
18735 /* Draw all strings. */
18736 for (s
= head
; s
; s
= s
->next
)
18737 FRAME_RIF (f
)->draw_glyph_string (s
);
18739 if (area
== TEXT_AREA
18740 && !row
->full_width_p
18741 /* When drawing overlapping rows, only the glyph strings'
18742 foreground is drawn, which doesn't erase a cursor
18746 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
18747 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
18748 : (tail
? tail
->x
+ tail
->background_width
: x
));
18750 int text_left
= window_box_left (w
, TEXT_AREA
);
18754 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
18755 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
18758 /* Value is the x-position up to which drawn, relative to AREA of W.
18759 This doesn't include parts drawn because of overhangs. */
18760 if (row
->full_width_p
)
18761 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
18763 x_reached
-= window_box_left (w
, area
);
18765 RELEASE_HDC (hdc
, f
);
18770 /* Expand row matrix if too narrow. Don't expand if area
18773 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
18775 if (!fonts_changed_p \
18776 && (it->glyph_row->glyphs[area] \
18777 < it->glyph_row->glyphs[area + 1])) \
18779 it->w->ncols_scale_factor++; \
18780 fonts_changed_p = 1; \
18784 /* Store one glyph for IT->char_to_display in IT->glyph_row.
18785 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18791 struct glyph
*glyph
;
18792 enum glyph_row_area area
= it
->area
;
18794 xassert (it
->glyph_row
);
18795 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
18797 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18798 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18800 glyph
->charpos
= CHARPOS (it
->position
);
18801 glyph
->object
= it
->object
;
18802 glyph
->pixel_width
= it
->pixel_width
;
18803 glyph
->ascent
= it
->ascent
;
18804 glyph
->descent
= it
->descent
;
18805 glyph
->voffset
= it
->voffset
;
18806 glyph
->type
= CHAR_GLYPH
;
18807 glyph
->multibyte_p
= it
->multibyte_p
;
18808 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18809 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18810 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18811 || it
->phys_descent
> it
->descent
);
18812 glyph
->padding_p
= 0;
18813 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
18814 glyph
->face_id
= it
->face_id
;
18815 glyph
->u
.ch
= it
->char_to_display
;
18816 glyph
->slice
= null_glyph_slice
;
18817 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18818 ++it
->glyph_row
->used
[area
];
18821 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18824 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
18825 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18828 append_composite_glyph (it
)
18831 struct glyph
*glyph
;
18832 enum glyph_row_area area
= it
->area
;
18834 xassert (it
->glyph_row
);
18836 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18837 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18839 glyph
->charpos
= CHARPOS (it
->position
);
18840 glyph
->object
= it
->object
;
18841 glyph
->pixel_width
= it
->pixel_width
;
18842 glyph
->ascent
= it
->ascent
;
18843 glyph
->descent
= it
->descent
;
18844 glyph
->voffset
= it
->voffset
;
18845 glyph
->type
= COMPOSITE_GLYPH
;
18846 glyph
->multibyte_p
= it
->multibyte_p
;
18847 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18848 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18849 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18850 || it
->phys_descent
> it
->descent
);
18851 glyph
->padding_p
= 0;
18852 glyph
->glyph_not_available_p
= 0;
18853 glyph
->face_id
= it
->face_id
;
18854 glyph
->u
.cmp_id
= it
->cmp_id
;
18855 glyph
->slice
= null_glyph_slice
;
18856 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18857 ++it
->glyph_row
->used
[area
];
18860 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18864 /* Change IT->ascent and IT->height according to the setting of
18868 take_vertical_position_into_account (it
)
18873 if (it
->voffset
< 0)
18874 /* Increase the ascent so that we can display the text higher
18876 it
->ascent
-= it
->voffset
;
18878 /* Increase the descent so that we can display the text lower
18880 it
->descent
+= it
->voffset
;
18885 /* Produce glyphs/get display metrics for the image IT is loaded with.
18886 See the description of struct display_iterator in dispextern.h for
18887 an overview of struct display_iterator. */
18890 produce_image_glyph (it
)
18896 struct glyph_slice slice
;
18898 xassert (it
->what
== IT_IMAGE
);
18900 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18902 /* Make sure X resources of the face is loaded. */
18903 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18905 if (it
->image_id
< 0)
18907 /* Fringe bitmap. */
18908 it
->ascent
= it
->phys_ascent
= 0;
18909 it
->descent
= it
->phys_descent
= 0;
18910 it
->pixel_width
= 0;
18915 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
18917 /* Make sure X resources of the image is loaded. */
18918 prepare_image_for_display (it
->f
, img
);
18920 slice
.x
= slice
.y
= 0;
18921 slice
.width
= img
->width
;
18922 slice
.height
= img
->height
;
18924 if (INTEGERP (it
->slice
.x
))
18925 slice
.x
= XINT (it
->slice
.x
);
18926 else if (FLOATP (it
->slice
.x
))
18927 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
18929 if (INTEGERP (it
->slice
.y
))
18930 slice
.y
= XINT (it
->slice
.y
);
18931 else if (FLOATP (it
->slice
.y
))
18932 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
18934 if (INTEGERP (it
->slice
.width
))
18935 slice
.width
= XINT (it
->slice
.width
);
18936 else if (FLOATP (it
->slice
.width
))
18937 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
18939 if (INTEGERP (it
->slice
.height
))
18940 slice
.height
= XINT (it
->slice
.height
);
18941 else if (FLOATP (it
->slice
.height
))
18942 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
18944 if (slice
.x
>= img
->width
)
18945 slice
.x
= img
->width
;
18946 if (slice
.y
>= img
->height
)
18947 slice
.y
= img
->height
;
18948 if (slice
.x
+ slice
.width
>= img
->width
)
18949 slice
.width
= img
->width
- slice
.x
;
18950 if (slice
.y
+ slice
.height
> img
->height
)
18951 slice
.height
= img
->height
- slice
.y
;
18953 if (slice
.width
== 0 || slice
.height
== 0)
18956 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
18958 it
->descent
= slice
.height
- glyph_ascent
;
18960 it
->descent
+= img
->vmargin
;
18961 if (slice
.y
+ slice
.height
== img
->height
)
18962 it
->descent
+= img
->vmargin
;
18963 it
->phys_descent
= it
->descent
;
18965 it
->pixel_width
= slice
.width
;
18967 it
->pixel_width
+= img
->hmargin
;
18968 if (slice
.x
+ slice
.width
== img
->width
)
18969 it
->pixel_width
+= img
->hmargin
;
18971 /* It's quite possible for images to have an ascent greater than
18972 their height, so don't get confused in that case. */
18973 if (it
->descent
< 0)
18976 #if 0 /* this breaks image tiling */
18977 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
18978 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
18979 if (face_ascent
> it
->ascent
)
18980 it
->ascent
= it
->phys_ascent
= face_ascent
;
18985 if (face
->box
!= FACE_NO_BOX
)
18987 if (face
->box_line_width
> 0)
18990 it
->ascent
+= face
->box_line_width
;
18991 if (slice
.y
+ slice
.height
== img
->height
)
18992 it
->descent
+= face
->box_line_width
;
18995 if (it
->start_of_box_run_p
&& slice
.x
== 0)
18996 it
->pixel_width
+= abs (face
->box_line_width
);
18997 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
18998 it
->pixel_width
+= abs (face
->box_line_width
);
19001 take_vertical_position_into_account (it
);
19005 struct glyph
*glyph
;
19006 enum glyph_row_area area
= it
->area
;
19008 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19009 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19011 glyph
->charpos
= CHARPOS (it
->position
);
19012 glyph
->object
= it
->object
;
19013 glyph
->pixel_width
= it
->pixel_width
;
19014 glyph
->ascent
= glyph_ascent
;
19015 glyph
->descent
= it
->descent
;
19016 glyph
->voffset
= it
->voffset
;
19017 glyph
->type
= IMAGE_GLYPH
;
19018 glyph
->multibyte_p
= it
->multibyte_p
;
19019 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19020 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19021 glyph
->overlaps_vertically_p
= 0;
19022 glyph
->padding_p
= 0;
19023 glyph
->glyph_not_available_p
= 0;
19024 glyph
->face_id
= it
->face_id
;
19025 glyph
->u
.img_id
= img
->id
;
19026 glyph
->slice
= slice
;
19027 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19028 ++it
->glyph_row
->used
[area
];
19031 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19036 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
19037 of the glyph, WIDTH and HEIGHT are the width and height of the
19038 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
19041 append_stretch_glyph (it
, object
, width
, height
, ascent
)
19043 Lisp_Object object
;
19047 struct glyph
*glyph
;
19048 enum glyph_row_area area
= it
->area
;
19050 xassert (ascent
>= 0 && ascent
<= height
);
19052 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19053 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19055 glyph
->charpos
= CHARPOS (it
->position
);
19056 glyph
->object
= object
;
19057 glyph
->pixel_width
= width
;
19058 glyph
->ascent
= ascent
;
19059 glyph
->descent
= height
- ascent
;
19060 glyph
->voffset
= it
->voffset
;
19061 glyph
->type
= STRETCH_GLYPH
;
19062 glyph
->multibyte_p
= it
->multibyte_p
;
19063 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19064 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19065 glyph
->overlaps_vertically_p
= 0;
19066 glyph
->padding_p
= 0;
19067 glyph
->glyph_not_available_p
= 0;
19068 glyph
->face_id
= it
->face_id
;
19069 glyph
->u
.stretch
.ascent
= ascent
;
19070 glyph
->u
.stretch
.height
= height
;
19071 glyph
->slice
= null_glyph_slice
;
19072 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19073 ++it
->glyph_row
->used
[area
];
19076 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19080 /* Produce a stretch glyph for iterator IT. IT->object is the value
19081 of the glyph property displayed. The value must be a list
19082 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
19085 1. `:width WIDTH' specifies that the space should be WIDTH *
19086 canonical char width wide. WIDTH may be an integer or floating
19089 2. `:relative-width FACTOR' specifies that the width of the stretch
19090 should be computed from the width of the first character having the
19091 `glyph' property, and should be FACTOR times that width.
19093 3. `:align-to HPOS' specifies that the space should be wide enough
19094 to reach HPOS, a value in canonical character units.
19096 Exactly one of the above pairs must be present.
19098 4. `:height HEIGHT' specifies that the height of the stretch produced
19099 should be HEIGHT, measured in canonical character units.
19101 5. `:relative-height FACTOR' specifies that the height of the
19102 stretch should be FACTOR times the height of the characters having
19103 the glyph property.
19105 Either none or exactly one of 4 or 5 must be present.
19107 6. `:ascent ASCENT' specifies that ASCENT percent of the height
19108 of the stretch should be used for the ascent of the stretch.
19109 ASCENT must be in the range 0 <= ASCENT <= 100. */
19112 produce_stretch_glyph (it
)
19115 /* (space :width WIDTH :height HEIGHT ...) */
19116 Lisp_Object prop
, plist
;
19117 int width
= 0, height
= 0, align_to
= -1;
19118 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
19121 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19122 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
19124 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19126 /* List should start with `space'. */
19127 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
19128 plist
= XCDR (it
->object
);
19130 /* Compute the width of the stretch. */
19131 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
19132 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
19134 /* Absolute width `:width WIDTH' specified and valid. */
19135 zero_width_ok_p
= 1;
19138 else if (prop
= Fplist_get (plist
, QCrelative_width
),
19141 /* Relative width `:relative-width FACTOR' specified and valid.
19142 Compute the width of the characters having the `glyph'
19145 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
19148 if (it
->multibyte_p
)
19150 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
19151 - IT_BYTEPOS (*it
));
19152 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
19155 it2
.c
= *p
, it2
.len
= 1;
19157 it2
.glyph_row
= NULL
;
19158 it2
.what
= IT_CHARACTER
;
19159 x_produce_glyphs (&it2
);
19160 width
= NUMVAL (prop
) * it2
.pixel_width
;
19162 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
19163 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
19165 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
19166 align_to
= (align_to
< 0
19168 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
19169 else if (align_to
< 0)
19170 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
19171 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
19172 zero_width_ok_p
= 1;
19175 /* Nothing specified -> width defaults to canonical char width. */
19176 width
= FRAME_COLUMN_WIDTH (it
->f
);
19178 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
19181 /* Compute height. */
19182 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
19183 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19186 zero_height_ok_p
= 1;
19188 else if (prop
= Fplist_get (plist
, QCrelative_height
),
19190 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
19192 height
= FONT_HEIGHT (font
);
19194 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
19197 /* Compute percentage of height used for ascent. If
19198 `:ascent ASCENT' is present and valid, use that. Otherwise,
19199 derive the ascent from the font in use. */
19200 if (prop
= Fplist_get (plist
, QCascent
),
19201 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
19202 ascent
= height
* NUMVAL (prop
) / 100.0;
19203 else if (!NILP (prop
)
19204 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19205 ascent
= min (max (0, (int)tem
), height
);
19207 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
19209 if (width
> 0 && height
> 0 && it
->glyph_row
)
19211 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
19212 if (!STRINGP (object
))
19213 object
= it
->w
->buffer
;
19214 append_stretch_glyph (it
, object
, width
, height
, ascent
);
19217 it
->pixel_width
= width
;
19218 it
->ascent
= it
->phys_ascent
= ascent
;
19219 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
19220 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
19222 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
19224 if (face
->box_line_width
> 0)
19226 it
->ascent
+= face
->box_line_width
;
19227 it
->descent
+= face
->box_line_width
;
19230 if (it
->start_of_box_run_p
)
19231 it
->pixel_width
+= abs (face
->box_line_width
);
19232 if (it
->end_of_box_run_p
)
19233 it
->pixel_width
+= abs (face
->box_line_width
);
19236 take_vertical_position_into_account (it
);
19239 /* Get line-height and line-spacing property at point.
19240 If line-height has format (HEIGHT TOTAL), return TOTAL
19241 in TOTAL_HEIGHT. */
19244 get_line_height_property (it
, prop
)
19248 Lisp_Object position
;
19250 if (STRINGP (it
->object
))
19251 position
= make_number (IT_STRING_CHARPOS (*it
));
19252 else if (BUFFERP (it
->object
))
19253 position
= make_number (IT_CHARPOS (*it
));
19257 return Fget_char_property (position
, prop
, it
->object
);
19260 /* Calculate line-height and line-spacing properties.
19261 An integer value specifies explicit pixel value.
19262 A float value specifies relative value to current face height.
19263 A cons (float . face-name) specifies relative value to
19264 height of specified face font.
19266 Returns height in pixels, or nil. */
19270 calc_line_height_property (it
, val
, font
, boff
, override
)
19274 int boff
, override
;
19276 Lisp_Object face_name
= Qnil
;
19277 int ascent
, descent
, height
;
19279 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
19284 face_name
= XCAR (val
);
19286 if (!NUMBERP (val
))
19287 val
= make_number (1);
19288 if (NILP (face_name
))
19290 height
= it
->ascent
+ it
->descent
;
19295 if (NILP (face_name
))
19297 font
= FRAME_FONT (it
->f
);
19298 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19300 else if (EQ (face_name
, Qt
))
19308 struct font_info
*font_info
;
19310 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
19312 return make_number (-1);
19314 face
= FACE_FROM_ID (it
->f
, face_id
);
19317 return make_number (-1);
19319 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19320 boff
= font_info
->baseline_offset
;
19321 if (font_info
->vertical_centering
)
19322 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19325 ascent
= FONT_BASE (font
) + boff
;
19326 descent
= FONT_DESCENT (font
) - boff
;
19330 it
->override_ascent
= ascent
;
19331 it
->override_descent
= descent
;
19332 it
->override_boff
= boff
;
19335 height
= ascent
+ descent
;
19339 height
= (int)(XFLOAT_DATA (val
) * height
);
19340 else if (INTEGERP (val
))
19341 height
*= XINT (val
);
19343 return make_number (height
);
19348 Produce glyphs/get display metrics for the display element IT is
19349 loaded with. See the description of struct display_iterator in
19350 dispextern.h for an overview of struct display_iterator. */
19353 x_produce_glyphs (it
)
19356 int extra_line_spacing
= it
->extra_line_spacing
;
19358 it
->glyph_not_available_p
= 0;
19360 if (it
->what
== IT_CHARACTER
)
19364 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19366 int font_not_found_p
;
19367 struct font_info
*font_info
;
19368 int boff
; /* baseline offset */
19369 /* We may change it->multibyte_p upon unibyte<->multibyte
19370 conversion. So, save the current value now and restore it
19373 Note: It seems that we don't have to record multibyte_p in
19374 struct glyph because the character code itself tells if or
19375 not the character is multibyte. Thus, in the future, we must
19376 consider eliminating the field `multibyte_p' in the struct
19378 int saved_multibyte_p
= it
->multibyte_p
;
19380 /* Maybe translate single-byte characters to multibyte, or the
19382 it
->char_to_display
= it
->c
;
19383 if (!ASCII_BYTE_P (it
->c
))
19385 if (unibyte_display_via_language_environment
19386 && SINGLE_BYTE_CHAR_P (it
->c
)
19388 || !NILP (Vnonascii_translation_table
)))
19390 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19391 it
->multibyte_p
= 1;
19392 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19393 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19395 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
19396 && !it
->multibyte_p
)
19398 it
->multibyte_p
= 1;
19399 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19400 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19404 /* Get font to use. Encode IT->char_to_display. */
19405 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19406 &char2b
, it
->multibyte_p
, 0);
19409 /* When no suitable font found, use the default font. */
19410 font_not_found_p
= font
== NULL
;
19411 if (font_not_found_p
)
19413 font
= FRAME_FONT (it
->f
);
19414 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19419 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19420 boff
= font_info
->baseline_offset
;
19421 if (font_info
->vertical_centering
)
19422 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19425 if (it
->char_to_display
>= ' '
19426 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
19428 /* Either unibyte or ASCII. */
19433 pcm
= FRAME_RIF (it
->f
)->per_char_metric
19434 (font
, &char2b
, FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
19436 if (it
->override_ascent
>= 0)
19438 it
->ascent
= it
->override_ascent
;
19439 it
->descent
= it
->override_descent
;
19440 boff
= it
->override_boff
;
19444 it
->ascent
= FONT_BASE (font
) + boff
;
19445 it
->descent
= FONT_DESCENT (font
) - boff
;
19450 it
->phys_ascent
= pcm
->ascent
+ boff
;
19451 it
->phys_descent
= pcm
->descent
- boff
;
19452 it
->pixel_width
= pcm
->width
;
19456 it
->glyph_not_available_p
= 1;
19457 it
->phys_ascent
= it
->ascent
;
19458 it
->phys_descent
= it
->descent
;
19459 it
->pixel_width
= FONT_WIDTH (font
);
19462 if (it
->constrain_row_ascent_descent_p
)
19464 if (it
->descent
> it
->max_descent
)
19466 it
->ascent
+= it
->descent
- it
->max_descent
;
19467 it
->descent
= it
->max_descent
;
19469 if (it
->ascent
> it
->max_ascent
)
19471 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19472 it
->ascent
= it
->max_ascent
;
19474 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19475 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19476 extra_line_spacing
= 0;
19479 /* If this is a space inside a region of text with
19480 `space-width' property, change its width. */
19481 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
19483 it
->pixel_width
*= XFLOATINT (it
->space_width
);
19485 /* If face has a box, add the box thickness to the character
19486 height. If character has a box line to the left and/or
19487 right, add the box line width to the character's width. */
19488 if (face
->box
!= FACE_NO_BOX
)
19490 int thick
= face
->box_line_width
;
19494 it
->ascent
+= thick
;
19495 it
->descent
+= thick
;
19500 if (it
->start_of_box_run_p
)
19501 it
->pixel_width
+= thick
;
19502 if (it
->end_of_box_run_p
)
19503 it
->pixel_width
+= thick
;
19506 /* If face has an overline, add the height of the overline
19507 (1 pixel) and a 1 pixel margin to the character height. */
19508 if (face
->overline_p
)
19511 if (it
->constrain_row_ascent_descent_p
)
19513 if (it
->ascent
> it
->max_ascent
)
19514 it
->ascent
= it
->max_ascent
;
19515 if (it
->descent
> it
->max_descent
)
19516 it
->descent
= it
->max_descent
;
19519 take_vertical_position_into_account (it
);
19521 /* If we have to actually produce glyphs, do it. */
19526 /* Translate a space with a `space-width' property
19527 into a stretch glyph. */
19528 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
19529 / FONT_HEIGHT (font
));
19530 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19531 it
->ascent
+ it
->descent
, ascent
);
19536 /* If characters with lbearing or rbearing are displayed
19537 in this line, record that fact in a flag of the
19538 glyph row. This is used to optimize X output code. */
19539 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
19540 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19543 else if (it
->char_to_display
== '\n')
19545 /* A newline has no width but we need the height of the line.
19546 But if previous part of the line set a height, don't
19547 increase that height */
19549 Lisp_Object height
;
19550 Lisp_Object total_height
= Qnil
;
19552 it
->override_ascent
= -1;
19553 it
->pixel_width
= 0;
19556 height
= get_line_height_property(it
, Qline_height
);
19557 /* Split (line-height total-height) list */
19559 && CONSP (XCDR (height
))
19560 && NILP (XCDR (XCDR (height
))))
19562 total_height
= XCAR (XCDR (height
));
19563 height
= XCAR (height
);
19565 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
19567 if (it
->override_ascent
>= 0)
19569 it
->ascent
= it
->override_ascent
;
19570 it
->descent
= it
->override_descent
;
19571 boff
= it
->override_boff
;
19575 it
->ascent
= FONT_BASE (font
) + boff
;
19576 it
->descent
= FONT_DESCENT (font
) - boff
;
19579 if (EQ (height
, Qt
))
19581 if (it
->descent
> it
->max_descent
)
19583 it
->ascent
+= it
->descent
- it
->max_descent
;
19584 it
->descent
= it
->max_descent
;
19586 if (it
->ascent
> it
->max_ascent
)
19588 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19589 it
->ascent
= it
->max_ascent
;
19591 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19592 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19593 it
->constrain_row_ascent_descent_p
= 1;
19594 extra_line_spacing
= 0;
19598 Lisp_Object spacing
;
19600 it
->phys_ascent
= it
->ascent
;
19601 it
->phys_descent
= it
->descent
;
19603 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
19604 && face
->box
!= FACE_NO_BOX
19605 && face
->box_line_width
> 0)
19607 it
->ascent
+= face
->box_line_width
;
19608 it
->descent
+= face
->box_line_width
;
19611 && XINT (height
) > it
->ascent
+ it
->descent
)
19612 it
->ascent
= XINT (height
) - it
->descent
;
19614 if (!NILP (total_height
))
19615 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
19618 spacing
= get_line_height_property(it
, Qline_spacing
);
19619 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
19621 if (INTEGERP (spacing
))
19623 extra_line_spacing
= XINT (spacing
);
19624 if (!NILP (total_height
))
19625 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
19629 else if (it
->char_to_display
== '\t')
19631 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
19632 int x
= it
->current_x
+ it
->continuation_lines_width
;
19633 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
19635 /* If the distance from the current position to the next tab
19636 stop is less than a space character width, use the
19637 tab stop after that. */
19638 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
19639 next_tab_x
+= tab_width
;
19641 it
->pixel_width
= next_tab_x
- x
;
19643 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
19644 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19648 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19649 it
->ascent
+ it
->descent
, it
->ascent
);
19654 /* A multi-byte character. Assume that the display width of the
19655 character is the width of the character multiplied by the
19656 width of the font. */
19658 /* If we found a font, this font should give us the right
19659 metrics. If we didn't find a font, use the frame's
19660 default font and calculate the width of the character
19661 from the charset width; this is what old redisplay code
19664 pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
19665 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
19667 if (font_not_found_p
|| !pcm
)
19669 int charset
= CHAR_CHARSET (it
->char_to_display
);
19671 it
->glyph_not_available_p
= 1;
19672 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
19673 * CHARSET_WIDTH (charset
));
19674 it
->phys_ascent
= FONT_BASE (font
) + boff
;
19675 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19679 it
->pixel_width
= pcm
->width
;
19680 it
->phys_ascent
= pcm
->ascent
+ boff
;
19681 it
->phys_descent
= pcm
->descent
- boff
;
19683 && (pcm
->lbearing
< 0
19684 || pcm
->rbearing
> pcm
->width
))
19685 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19688 it
->ascent
= FONT_BASE (font
) + boff
;
19689 it
->descent
= FONT_DESCENT (font
) - boff
;
19690 if (face
->box
!= FACE_NO_BOX
)
19692 int thick
= face
->box_line_width
;
19696 it
->ascent
+= thick
;
19697 it
->descent
+= thick
;
19702 if (it
->start_of_box_run_p
)
19703 it
->pixel_width
+= thick
;
19704 if (it
->end_of_box_run_p
)
19705 it
->pixel_width
+= thick
;
19708 /* If face has an overline, add the height of the overline
19709 (1 pixel) and a 1 pixel margin to the character height. */
19710 if (face
->overline_p
)
19713 take_vertical_position_into_account (it
);
19718 it
->multibyte_p
= saved_multibyte_p
;
19720 else if (it
->what
== IT_COMPOSITION
)
19722 /* Note: A composition is represented as one glyph in the
19723 glyph matrix. There are no padding glyphs. */
19726 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19728 int font_not_found_p
;
19729 struct font_info
*font_info
;
19730 int boff
; /* baseline offset */
19731 struct composition
*cmp
= composition_table
[it
->cmp_id
];
19733 /* Maybe translate single-byte characters to multibyte. */
19734 it
->char_to_display
= it
->c
;
19735 if (unibyte_display_via_language_environment
19736 && SINGLE_BYTE_CHAR_P (it
->c
)
19739 && !NILP (Vnonascii_translation_table
))))
19741 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19744 /* Get face and font to use. Encode IT->char_to_display. */
19745 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19746 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19747 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19748 &char2b
, it
->multibyte_p
, 0);
19751 /* When no suitable font found, use the default font. */
19752 font_not_found_p
= font
== NULL
;
19753 if (font_not_found_p
)
19755 font
= FRAME_FONT (it
->f
);
19756 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19761 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19762 boff
= font_info
->baseline_offset
;
19763 if (font_info
->vertical_centering
)
19764 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19767 /* There are no padding glyphs, so there is only one glyph to
19768 produce for the composition. Important is that pixel_width,
19769 ascent and descent are the values of what is drawn by
19770 draw_glyphs (i.e. the values of the overall glyphs composed). */
19773 /* If we have not yet calculated pixel size data of glyphs of
19774 the composition for the current face font, calculate them
19775 now. Theoretically, we have to check all fonts for the
19776 glyphs, but that requires much time and memory space. So,
19777 here we check only the font of the first glyph. This leads
19778 to incorrect display very rarely, and C-l (recenter) can
19779 correct the display anyway. */
19780 if (cmp
->font
!= (void *) font
)
19782 /* Ascent and descent of the font of the first character of
19783 this composition (adjusted by baseline offset). Ascent
19784 and descent of overall glyphs should not be less than
19785 them respectively. */
19786 int font_ascent
= FONT_BASE (font
) + boff
;
19787 int font_descent
= FONT_DESCENT (font
) - boff
;
19788 /* Bounding box of the overall glyphs. */
19789 int leftmost
, rightmost
, lowest
, highest
;
19790 int i
, width
, ascent
, descent
;
19792 cmp
->font
= (void *) font
;
19794 /* Initialize the bounding box. */
19796 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
19797 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
19799 width
= pcm
->width
;
19800 ascent
= pcm
->ascent
;
19801 descent
= pcm
->descent
;
19805 width
= FONT_WIDTH (font
);
19806 ascent
= FONT_BASE (font
);
19807 descent
= FONT_DESCENT (font
);
19811 lowest
= - descent
+ boff
;
19812 highest
= ascent
+ boff
;
19816 && font_info
->default_ascent
19817 && CHAR_TABLE_P (Vuse_default_ascent
)
19818 && !NILP (Faref (Vuse_default_ascent
,
19819 make_number (it
->char_to_display
))))
19820 highest
= font_info
->default_ascent
+ boff
;
19822 /* Draw the first glyph at the normal position. It may be
19823 shifted to right later if some other glyphs are drawn at
19825 cmp
->offsets
[0] = 0;
19826 cmp
->offsets
[1] = boff
;
19828 /* Set cmp->offsets for the remaining glyphs. */
19829 for (i
= 1; i
< cmp
->glyph_len
; i
++)
19831 int left
, right
, btm
, top
;
19832 int ch
= COMPOSITION_GLYPH (cmp
, i
);
19833 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
19835 face
= FACE_FROM_ID (it
->f
, face_id
);
19836 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
19837 &char2b
, it
->multibyte_p
, 0);
19841 font
= FRAME_FONT (it
->f
);
19842 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19848 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19849 boff
= font_info
->baseline_offset
;
19850 if (font_info
->vertical_centering
)
19851 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19855 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
19856 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
19858 width
= pcm
->width
;
19859 ascent
= pcm
->ascent
;
19860 descent
= pcm
->descent
;
19864 width
= FONT_WIDTH (font
);
19869 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
19871 /* Relative composition with or without
19872 alternate chars. */
19873 left
= (leftmost
+ rightmost
- width
) / 2;
19874 btm
= - descent
+ boff
;
19875 if (font_info
&& font_info
->relative_compose
19876 && (! CHAR_TABLE_P (Vignore_relative_composition
)
19877 || NILP (Faref (Vignore_relative_composition
,
19878 make_number (ch
)))))
19881 if (- descent
>= font_info
->relative_compose
)
19882 /* One extra pixel between two glyphs. */
19884 else if (ascent
<= 0)
19885 /* One extra pixel between two glyphs. */
19886 btm
= lowest
- 1 - ascent
- descent
;
19891 /* A composition rule is specified by an integer
19892 value that encodes global and new reference
19893 points (GREF and NREF). GREF and NREF are
19894 specified by numbers as below:
19896 0---1---2 -- ascent
19900 9--10--11 -- center
19902 ---3---4---5--- baseline
19904 6---7---8 -- descent
19906 int rule
= COMPOSITION_RULE (cmp
, i
);
19907 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
19909 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
19910 grefx
= gref
% 3, nrefx
= nref
% 3;
19911 grefy
= gref
/ 3, nrefy
= nref
/ 3;
19914 + grefx
* (rightmost
- leftmost
) / 2
19915 - nrefx
* width
/ 2);
19916 btm
= ((grefy
== 0 ? highest
19918 : grefy
== 2 ? lowest
19919 : (highest
+ lowest
) / 2)
19920 - (nrefy
== 0 ? ascent
+ descent
19921 : nrefy
== 1 ? descent
- boff
19923 : (ascent
+ descent
) / 2));
19926 cmp
->offsets
[i
* 2] = left
;
19927 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
19929 /* Update the bounding box of the overall glyphs. */
19930 right
= left
+ width
;
19931 top
= btm
+ descent
+ ascent
;
19932 if (left
< leftmost
)
19934 if (right
> rightmost
)
19942 /* If there are glyphs whose x-offsets are negative,
19943 shift all glyphs to the right and make all x-offsets
19947 for (i
= 0; i
< cmp
->glyph_len
; i
++)
19948 cmp
->offsets
[i
* 2] -= leftmost
;
19949 rightmost
-= leftmost
;
19952 cmp
->pixel_width
= rightmost
;
19953 cmp
->ascent
= highest
;
19954 cmp
->descent
= - lowest
;
19955 if (cmp
->ascent
< font_ascent
)
19956 cmp
->ascent
= font_ascent
;
19957 if (cmp
->descent
< font_descent
)
19958 cmp
->descent
= font_descent
;
19961 it
->pixel_width
= cmp
->pixel_width
;
19962 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
19963 it
->descent
= it
->phys_descent
= cmp
->descent
;
19965 if (face
->box
!= FACE_NO_BOX
)
19967 int thick
= face
->box_line_width
;
19971 it
->ascent
+= thick
;
19972 it
->descent
+= thick
;
19977 if (it
->start_of_box_run_p
)
19978 it
->pixel_width
+= thick
;
19979 if (it
->end_of_box_run_p
)
19980 it
->pixel_width
+= thick
;
19983 /* If face has an overline, add the height of the overline
19984 (1 pixel) and a 1 pixel margin to the character height. */
19985 if (face
->overline_p
)
19988 take_vertical_position_into_account (it
);
19991 append_composite_glyph (it
);
19993 else if (it
->what
== IT_IMAGE
)
19994 produce_image_glyph (it
);
19995 else if (it
->what
== IT_STRETCH
)
19996 produce_stretch_glyph (it
);
19998 /* Accumulate dimensions. Note: can't assume that it->descent > 0
19999 because this isn't true for images with `:ascent 100'. */
20000 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
20001 if (it
->area
== TEXT_AREA
)
20002 it
->current_x
+= it
->pixel_width
;
20004 if (extra_line_spacing
> 0)
20006 it
->descent
+= extra_line_spacing
;
20007 if (extra_line_spacing
> it
->max_extra_line_spacing
)
20008 it
->max_extra_line_spacing
= extra_line_spacing
;
20011 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
20012 it
->max_descent
= max (it
->max_descent
, it
->descent
);
20013 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
20014 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
20018 Output LEN glyphs starting at START at the nominal cursor position.
20019 Advance the nominal cursor over the text. The global variable
20020 updated_window contains the window being updated, updated_row is
20021 the glyph row being updated, and updated_area is the area of that
20022 row being updated. */
20025 x_write_glyphs (start
, len
)
20026 struct glyph
*start
;
20031 xassert (updated_window
&& updated_row
);
20034 /* Write glyphs. */
20036 hpos
= start
- updated_row
->glyphs
[updated_area
];
20037 x
= draw_glyphs (updated_window
, output_cursor
.x
,
20038 updated_row
, updated_area
,
20040 DRAW_NORMAL_TEXT
, 0);
20042 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
20043 if (updated_area
== TEXT_AREA
20044 && updated_window
->phys_cursor_on_p
20045 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
20046 && updated_window
->phys_cursor
.hpos
>= hpos
20047 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
20048 updated_window
->phys_cursor_on_p
= 0;
20052 /* Advance the output cursor. */
20053 output_cursor
.hpos
+= len
;
20054 output_cursor
.x
= x
;
20059 Insert LEN glyphs from START at the nominal cursor position. */
20062 x_insert_glyphs (start
, len
)
20063 struct glyph
*start
;
20068 int line_height
, shift_by_width
, shifted_region_width
;
20069 struct glyph_row
*row
;
20070 struct glyph
*glyph
;
20071 int frame_x
, frame_y
, hpos
;
20073 xassert (updated_window
&& updated_row
);
20075 w
= updated_window
;
20076 f
= XFRAME (WINDOW_FRAME (w
));
20078 /* Get the height of the line we are in. */
20080 line_height
= row
->height
;
20082 /* Get the width of the glyphs to insert. */
20083 shift_by_width
= 0;
20084 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
20085 shift_by_width
+= glyph
->pixel_width
;
20087 /* Get the width of the region to shift right. */
20088 shifted_region_width
= (window_box_width (w
, updated_area
)
20093 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
20094 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
20096 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
20097 line_height
, shift_by_width
);
20099 /* Write the glyphs. */
20100 hpos
= start
- row
->glyphs
[updated_area
];
20101 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
20103 DRAW_NORMAL_TEXT
, 0);
20105 /* Advance the output cursor. */
20106 output_cursor
.hpos
+= len
;
20107 output_cursor
.x
+= shift_by_width
;
20113 Erase the current text line from the nominal cursor position
20114 (inclusive) to pixel column TO_X (exclusive). The idea is that
20115 everything from TO_X onward is already erased.
20117 TO_X is a pixel position relative to updated_area of
20118 updated_window. TO_X == -1 means clear to the end of this area. */
20121 x_clear_end_of_line (to_x
)
20125 struct window
*w
= updated_window
;
20126 int max_x
, min_y
, max_y
;
20127 int from_x
, from_y
, to_y
;
20129 xassert (updated_window
&& updated_row
);
20130 f
= XFRAME (w
->frame
);
20132 if (updated_row
->full_width_p
)
20133 max_x
= WINDOW_TOTAL_WIDTH (w
);
20135 max_x
= window_box_width (w
, updated_area
);
20136 max_y
= window_text_bottom_y (w
);
20138 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
20139 of window. For TO_X > 0, truncate to end of drawing area. */
20145 to_x
= min (to_x
, max_x
);
20147 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
20149 /* Notice if the cursor will be cleared by this operation. */
20150 if (!updated_row
->full_width_p
)
20151 notice_overwritten_cursor (w
, updated_area
,
20152 output_cursor
.x
, -1,
20154 MATRIX_ROW_BOTTOM_Y (updated_row
));
20156 from_x
= output_cursor
.x
;
20158 /* Translate to frame coordinates. */
20159 if (updated_row
->full_width_p
)
20161 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
20162 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
20166 int area_left
= window_box_left (w
, updated_area
);
20167 from_x
+= area_left
;
20171 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
20172 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
20173 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
20175 /* Prevent inadvertently clearing to end of the X window. */
20176 if (to_x
> from_x
&& to_y
> from_y
)
20179 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
20180 to_x
- from_x
, to_y
- from_y
);
20185 #endif /* HAVE_WINDOW_SYSTEM */
20189 /***********************************************************************
20191 ***********************************************************************/
20193 /* Value is the internal representation of the specified cursor type
20194 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
20195 of the bar cursor. */
20197 static enum text_cursor_kinds
20198 get_specified_cursor_type (arg
, width
)
20202 enum text_cursor_kinds type
;
20207 if (EQ (arg
, Qbox
))
20208 return FILLED_BOX_CURSOR
;
20210 if (EQ (arg
, Qhollow
))
20211 return HOLLOW_BOX_CURSOR
;
20213 if (EQ (arg
, Qbar
))
20220 && EQ (XCAR (arg
), Qbar
)
20221 && INTEGERP (XCDR (arg
))
20222 && XINT (XCDR (arg
)) >= 0)
20224 *width
= XINT (XCDR (arg
));
20228 if (EQ (arg
, Qhbar
))
20231 return HBAR_CURSOR
;
20235 && EQ (XCAR (arg
), Qhbar
)
20236 && INTEGERP (XCDR (arg
))
20237 && XINT (XCDR (arg
)) >= 0)
20239 *width
= XINT (XCDR (arg
));
20240 return HBAR_CURSOR
;
20243 /* Treat anything unknown as "hollow box cursor".
20244 It was bad to signal an error; people have trouble fixing
20245 .Xdefaults with Emacs, when it has something bad in it. */
20246 type
= HOLLOW_BOX_CURSOR
;
20251 /* Set the default cursor types for specified frame. */
20253 set_frame_cursor_types (f
, arg
)
20260 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
20261 FRAME_CURSOR_WIDTH (f
) = width
;
20263 /* By default, set up the blink-off state depending on the on-state. */
20265 tem
= Fassoc (arg
, Vblink_cursor_alist
);
20268 FRAME_BLINK_OFF_CURSOR (f
)
20269 = get_specified_cursor_type (XCDR (tem
), &width
);
20270 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
20273 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
20277 /* Return the cursor we want to be displayed in window W. Return
20278 width of bar/hbar cursor through WIDTH arg. Return with
20279 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
20280 (i.e. if the `system caret' should track this cursor).
20282 In a mini-buffer window, we want the cursor only to appear if we
20283 are reading input from this window. For the selected window, we
20284 want the cursor type given by the frame parameter or buffer local
20285 setting of cursor-type. If explicitly marked off, draw no cursor.
20286 In all other cases, we want a hollow box cursor. */
20288 static enum text_cursor_kinds
20289 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
20291 struct glyph
*glyph
;
20293 int *active_cursor
;
20295 struct frame
*f
= XFRAME (w
->frame
);
20296 struct buffer
*b
= XBUFFER (w
->buffer
);
20297 int cursor_type
= DEFAULT_CURSOR
;
20298 Lisp_Object alt_cursor
;
20299 int non_selected
= 0;
20301 *active_cursor
= 1;
20304 if (cursor_in_echo_area
20305 && FRAME_HAS_MINIBUF_P (f
)
20306 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
20308 if (w
== XWINDOW (echo_area_window
))
20310 *width
= FRAME_CURSOR_WIDTH (f
);
20311 return FRAME_DESIRED_CURSOR (f
);
20314 *active_cursor
= 0;
20318 /* Nonselected window or nonselected frame. */
20319 else if (w
!= XWINDOW (f
->selected_window
)
20320 #ifdef HAVE_WINDOW_SYSTEM
20321 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
20325 *active_cursor
= 0;
20327 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
20333 /* Never display a cursor in a window in which cursor-type is nil. */
20334 if (NILP (b
->cursor_type
))
20337 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
20340 alt_cursor
= XBUFFER (w
->buffer
)->cursor_in_non_selected_windows
;
20341 return get_specified_cursor_type (alt_cursor
, width
);
20344 /* Get the normal cursor type for this window. */
20345 if (EQ (b
->cursor_type
, Qt
))
20347 cursor_type
= FRAME_DESIRED_CURSOR (f
);
20348 *width
= FRAME_CURSOR_WIDTH (f
);
20351 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
20353 /* Use normal cursor if not blinked off. */
20354 if (!w
->cursor_off_p
)
20356 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
20357 if (cursor_type
== FILLED_BOX_CURSOR
)
20358 cursor_type
= HOLLOW_BOX_CURSOR
;
20360 return cursor_type
;
20363 /* Cursor is blinked off, so determine how to "toggle" it. */
20365 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
20366 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
20367 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
20369 /* Then see if frame has specified a specific blink off cursor type. */
20370 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
20372 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
20373 return FRAME_BLINK_OFF_CURSOR (f
);
20377 /* Some people liked having a permanently visible blinking cursor,
20378 while others had very strong opinions against it. So it was
20379 decided to remove it. KFS 2003-09-03 */
20381 /* Finally perform built-in cursor blinking:
20382 filled box <-> hollow box
20383 wide [h]bar <-> narrow [h]bar
20384 narrow [h]bar <-> no cursor
20385 other type <-> no cursor */
20387 if (cursor_type
== FILLED_BOX_CURSOR
)
20388 return HOLLOW_BOX_CURSOR
;
20390 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
20393 return cursor_type
;
20401 #ifdef HAVE_WINDOW_SYSTEM
20403 /* Notice when the text cursor of window W has been completely
20404 overwritten by a drawing operation that outputs glyphs in AREA
20405 starting at X0 and ending at X1 in the line starting at Y0 and
20406 ending at Y1. X coordinates are area-relative. X1 < 0 means all
20407 the rest of the line after X0 has been written. Y coordinates
20408 are window-relative. */
20411 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
20413 enum glyph_row_area area
;
20414 int x0
, y0
, x1
, y1
;
20416 int cx0
, cx1
, cy0
, cy1
;
20417 struct glyph_row
*row
;
20419 if (!w
->phys_cursor_on_p
)
20421 if (area
!= TEXT_AREA
)
20424 if (w
->phys_cursor
.vpos
< 0
20425 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
20426 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
20427 !(row
->enabled_p
&& row
->displays_text_p
)))
20430 if (row
->cursor_in_fringe_p
)
20432 row
->cursor_in_fringe_p
= 0;
20433 draw_fringe_bitmap (w
, row
, 0);
20434 w
->phys_cursor_on_p
= 0;
20438 cx0
= w
->phys_cursor
.x
;
20439 cx1
= cx0
+ w
->phys_cursor_width
;
20440 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
20443 /* The cursor image will be completely removed from the
20444 screen if the output area intersects the cursor area in
20445 y-direction. When we draw in [y0 y1[, and some part of
20446 the cursor is at y < y0, that part must have been drawn
20447 before. When scrolling, the cursor is erased before
20448 actually scrolling, so we don't come here. When not
20449 scrolling, the rows above the old cursor row must have
20450 changed, and in this case these rows must have written
20451 over the cursor image.
20453 Likewise if part of the cursor is below y1, with the
20454 exception of the cursor being in the first blank row at
20455 the buffer and window end because update_text_area
20456 doesn't draw that row. (Except when it does, but
20457 that's handled in update_text_area.) */
20459 cy0
= w
->phys_cursor
.y
;
20460 cy1
= cy0
+ w
->phys_cursor_height
;
20461 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
20464 w
->phys_cursor_on_p
= 0;
20467 #endif /* HAVE_WINDOW_SYSTEM */
20470 /************************************************************************
20472 ************************************************************************/
20474 #ifdef HAVE_WINDOW_SYSTEM
20477 Fix the display of area AREA of overlapping row ROW in window W. */
20480 x_fix_overlapping_area (w
, row
, area
)
20482 struct glyph_row
*row
;
20483 enum glyph_row_area area
;
20490 for (i
= 0; i
< row
->used
[area
];)
20492 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
20494 int start
= i
, start_x
= x
;
20498 x
+= row
->glyphs
[area
][i
].pixel_width
;
20501 while (i
< row
->used
[area
]
20502 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
20504 draw_glyphs (w
, start_x
, row
, area
,
20506 DRAW_NORMAL_TEXT
, 1);
20510 x
+= row
->glyphs
[area
][i
].pixel_width
;
20520 Draw the cursor glyph of window W in glyph row ROW. See the
20521 comment of draw_glyphs for the meaning of HL. */
20524 draw_phys_cursor_glyph (w
, row
, hl
)
20526 struct glyph_row
*row
;
20527 enum draw_glyphs_face hl
;
20529 /* If cursor hpos is out of bounds, don't draw garbage. This can
20530 happen in mini-buffer windows when switching between echo area
20531 glyphs and mini-buffer. */
20532 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
20534 int on_p
= w
->phys_cursor_on_p
;
20536 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
20537 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
20539 w
->phys_cursor_on_p
= on_p
;
20541 if (hl
== DRAW_CURSOR
)
20542 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
20543 /* When we erase the cursor, and ROW is overlapped by other
20544 rows, make sure that these overlapping parts of other rows
20546 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
20548 if (row
> w
->current_matrix
->rows
20549 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
20550 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
20552 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
20553 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
20554 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
20561 Erase the image of a cursor of window W from the screen. */
20564 erase_phys_cursor (w
)
20567 struct frame
*f
= XFRAME (w
->frame
);
20568 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20569 int hpos
= w
->phys_cursor
.hpos
;
20570 int vpos
= w
->phys_cursor
.vpos
;
20571 int mouse_face_here_p
= 0;
20572 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
20573 struct glyph_row
*cursor_row
;
20574 struct glyph
*cursor_glyph
;
20575 enum draw_glyphs_face hl
;
20577 /* No cursor displayed or row invalidated => nothing to do on the
20579 if (w
->phys_cursor_type
== NO_CURSOR
)
20580 goto mark_cursor_off
;
20582 /* VPOS >= active_glyphs->nrows means that window has been resized.
20583 Don't bother to erase the cursor. */
20584 if (vpos
>= active_glyphs
->nrows
)
20585 goto mark_cursor_off
;
20587 /* If row containing cursor is marked invalid, there is nothing we
20589 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
20590 if (!cursor_row
->enabled_p
)
20591 goto mark_cursor_off
;
20593 /* If line spacing is > 0, old cursor may only be partially visible in
20594 window after split-window. So adjust visible height. */
20595 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
20596 window_text_bottom_y (w
) - cursor_row
->y
);
20598 /* If row is completely invisible, don't attempt to delete a cursor which
20599 isn't there. This can happen if cursor is at top of a window, and
20600 we switch to a buffer with a header line in that window. */
20601 if (cursor_row
->visible_height
<= 0)
20602 goto mark_cursor_off
;
20604 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
20605 if (cursor_row
->cursor_in_fringe_p
)
20607 cursor_row
->cursor_in_fringe_p
= 0;
20608 draw_fringe_bitmap (w
, cursor_row
, 0);
20609 goto mark_cursor_off
;
20612 /* This can happen when the new row is shorter than the old one.
20613 In this case, either draw_glyphs or clear_end_of_line
20614 should have cleared the cursor. Note that we wouldn't be
20615 able to erase the cursor in this case because we don't have a
20616 cursor glyph at hand. */
20617 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
20618 goto mark_cursor_off
;
20620 /* If the cursor is in the mouse face area, redisplay that when
20621 we clear the cursor. */
20622 if (! NILP (dpyinfo
->mouse_face_window
)
20623 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
20624 && (vpos
> dpyinfo
->mouse_face_beg_row
20625 || (vpos
== dpyinfo
->mouse_face_beg_row
20626 && hpos
>= dpyinfo
->mouse_face_beg_col
))
20627 && (vpos
< dpyinfo
->mouse_face_end_row
20628 || (vpos
== dpyinfo
->mouse_face_end_row
20629 && hpos
< dpyinfo
->mouse_face_end_col
))
20630 /* Don't redraw the cursor's spot in mouse face if it is at the
20631 end of a line (on a newline). The cursor appears there, but
20632 mouse highlighting does not. */
20633 && cursor_row
->used
[TEXT_AREA
] > hpos
)
20634 mouse_face_here_p
= 1;
20636 /* Maybe clear the display under the cursor. */
20637 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
20640 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
20643 cursor_glyph
= get_phys_cursor_glyph (w
);
20644 if (cursor_glyph
== NULL
)
20645 goto mark_cursor_off
;
20647 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
20648 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
20649 width
= min (cursor_glyph
->pixel_width
,
20650 window_box_width (w
, TEXT_AREA
) - w
->phys_cursor
.x
);
20652 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
20655 /* Erase the cursor by redrawing the character underneath it. */
20656 if (mouse_face_here_p
)
20657 hl
= DRAW_MOUSE_FACE
;
20659 hl
= DRAW_NORMAL_TEXT
;
20660 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
20663 w
->phys_cursor_on_p
= 0;
20664 w
->phys_cursor_type
= NO_CURSOR
;
20669 Display or clear cursor of window W. If ON is zero, clear the
20670 cursor. If it is non-zero, display the cursor. If ON is nonzero,
20671 where to put the cursor is specified by HPOS, VPOS, X and Y. */
20674 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
20676 int on
, hpos
, vpos
, x
, y
;
20678 struct frame
*f
= XFRAME (w
->frame
);
20679 int new_cursor_type
;
20680 int new_cursor_width
;
20682 struct glyph_row
*glyph_row
;
20683 struct glyph
*glyph
;
20685 /* This is pointless on invisible frames, and dangerous on garbaged
20686 windows and frames; in the latter case, the frame or window may
20687 be in the midst of changing its size, and x and y may be off the
20689 if (! FRAME_VISIBLE_P (f
)
20690 || FRAME_GARBAGED_P (f
)
20691 || vpos
>= w
->current_matrix
->nrows
20692 || hpos
>= w
->current_matrix
->matrix_w
)
20695 /* If cursor is off and we want it off, return quickly. */
20696 if (!on
&& !w
->phys_cursor_on_p
)
20699 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
20700 /* If cursor row is not enabled, we don't really know where to
20701 display the cursor. */
20702 if (!glyph_row
->enabled_p
)
20704 w
->phys_cursor_on_p
= 0;
20709 if (!glyph_row
->exact_window_width_line_p
20710 || hpos
< glyph_row
->used
[TEXT_AREA
])
20711 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
20713 xassert (interrupt_input_blocked
);
20715 /* Set new_cursor_type to the cursor we want to be displayed. */
20716 new_cursor_type
= get_window_cursor_type (w
, glyph
,
20717 &new_cursor_width
, &active_cursor
);
20719 /* If cursor is currently being shown and we don't want it to be or
20720 it is in the wrong place, or the cursor type is not what we want,
20722 if (w
->phys_cursor_on_p
20724 || w
->phys_cursor
.x
!= x
20725 || w
->phys_cursor
.y
!= y
20726 || new_cursor_type
!= w
->phys_cursor_type
20727 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
20728 && new_cursor_width
!= w
->phys_cursor_width
)))
20729 erase_phys_cursor (w
);
20731 /* Don't check phys_cursor_on_p here because that flag is only set
20732 to zero in some cases where we know that the cursor has been
20733 completely erased, to avoid the extra work of erasing the cursor
20734 twice. In other words, phys_cursor_on_p can be 1 and the cursor
20735 still not be visible, or it has only been partly erased. */
20738 w
->phys_cursor_ascent
= glyph_row
->ascent
;
20739 w
->phys_cursor_height
= glyph_row
->height
;
20741 /* Set phys_cursor_.* before x_draw_.* is called because some
20742 of them may need the information. */
20743 w
->phys_cursor
.x
= x
;
20744 w
->phys_cursor
.y
= glyph_row
->y
;
20745 w
->phys_cursor
.hpos
= hpos
;
20746 w
->phys_cursor
.vpos
= vpos
;
20749 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
20750 new_cursor_type
, new_cursor_width
,
20751 on
, active_cursor
);
20755 /* Switch the display of W's cursor on or off, according to the value
20759 update_window_cursor (w
, on
)
20763 /* Don't update cursor in windows whose frame is in the process
20764 of being deleted. */
20765 if (w
->current_matrix
)
20768 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20769 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20775 /* Call update_window_cursor with parameter ON_P on all leaf windows
20776 in the window tree rooted at W. */
20779 update_cursor_in_window_tree (w
, on_p
)
20785 if (!NILP (w
->hchild
))
20786 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
20787 else if (!NILP (w
->vchild
))
20788 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
20790 update_window_cursor (w
, on_p
);
20792 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
20798 Display the cursor on window W, or clear it, according to ON_P.
20799 Don't change the cursor's position. */
20802 x_update_cursor (f
, on_p
)
20806 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
20811 Clear the cursor of window W to background color, and mark the
20812 cursor as not shown. This is used when the text where the cursor
20813 is is about to be rewritten. */
20819 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
20820 update_window_cursor (w
, 0);
20825 Display the active region described by mouse_face_* according to DRAW. */
20828 show_mouse_face (dpyinfo
, draw
)
20829 Display_Info
*dpyinfo
;
20830 enum draw_glyphs_face draw
;
20832 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
20833 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20835 if (/* If window is in the process of being destroyed, don't bother
20837 w
->current_matrix
!= NULL
20838 /* Don't update mouse highlight if hidden */
20839 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
20840 /* Recognize when we are called to operate on rows that don't exist
20841 anymore. This can happen when a window is split. */
20842 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
20844 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
20845 struct glyph_row
*row
, *first
, *last
;
20847 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20848 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20850 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
20852 int start_hpos
, end_hpos
, start_x
;
20854 /* For all but the first row, the highlight starts at column 0. */
20857 start_hpos
= dpyinfo
->mouse_face_beg_col
;
20858 start_x
= dpyinfo
->mouse_face_beg_x
;
20867 end_hpos
= dpyinfo
->mouse_face_end_col
;
20869 end_hpos
= row
->used
[TEXT_AREA
];
20871 if (end_hpos
> start_hpos
)
20873 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
20874 start_hpos
, end_hpos
,
20878 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
20882 /* When we've written over the cursor, arrange for it to
20883 be displayed again. */
20884 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
20887 display_and_set_cursor (w
, 1,
20888 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20889 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20894 /* Change the mouse cursor. */
20895 if (draw
== DRAW_NORMAL_TEXT
)
20896 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
20897 else if (draw
== DRAW_MOUSE_FACE
)
20898 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
20900 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
20904 Clear out the mouse-highlighted active region.
20905 Redraw it un-highlighted first. Value is non-zero if mouse
20906 face was actually drawn unhighlighted. */
20909 clear_mouse_face (dpyinfo
)
20910 Display_Info
*dpyinfo
;
20914 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
20916 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
20920 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
20921 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
20922 dpyinfo
->mouse_face_window
= Qnil
;
20923 dpyinfo
->mouse_face_overlay
= Qnil
;
20929 Non-zero if physical cursor of window W is within mouse face. */
20932 cursor_in_mouse_face_p (w
)
20935 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
20936 int in_mouse_face
= 0;
20938 if (WINDOWP (dpyinfo
->mouse_face_window
)
20939 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
20941 int hpos
= w
->phys_cursor
.hpos
;
20942 int vpos
= w
->phys_cursor
.vpos
;
20944 if (vpos
>= dpyinfo
->mouse_face_beg_row
20945 && vpos
<= dpyinfo
->mouse_face_end_row
20946 && (vpos
> dpyinfo
->mouse_face_beg_row
20947 || hpos
>= dpyinfo
->mouse_face_beg_col
)
20948 && (vpos
< dpyinfo
->mouse_face_end_row
20949 || hpos
< dpyinfo
->mouse_face_end_col
20950 || dpyinfo
->mouse_face_past_end
))
20954 return in_mouse_face
;
20960 /* Find the glyph matrix position of buffer position CHARPOS in window
20961 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
20962 current glyphs must be up to date. If CHARPOS is above window
20963 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
20964 of last line in W. In the row containing CHARPOS, stop before glyphs
20965 having STOP as object. */
20967 #if 1 /* This is a version of fast_find_position that's more correct
20968 in the presence of hscrolling, for example. I didn't install
20969 it right away because the problem fixed is minor, it failed
20970 in 20.x as well, and I think it's too risky to install
20971 so near the release of 21.1. 2001-09-25 gerd. */
20974 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
20977 int *hpos
, *vpos
, *x
, *y
;
20980 struct glyph_row
*row
, *first
;
20981 struct glyph
*glyph
, *end
;
20984 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20985 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
20990 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
20994 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
20997 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
21001 /* If whole rows or last part of a row came from a display overlay,
21002 row_containing_pos will skip over such rows because their end pos
21003 equals the start pos of the overlay or interval.
21005 Move back if we have a STOP object and previous row's
21006 end glyph came from STOP. */
21009 struct glyph_row
*prev
;
21010 while ((prev
= row
- 1, prev
>= first
)
21011 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
21012 && prev
->used
[TEXT_AREA
] > 0)
21014 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
21015 glyph
= beg
+ prev
->used
[TEXT_AREA
];
21016 while (--glyph
>= beg
21017 && INTEGERP (glyph
->object
));
21019 || !EQ (stop
, glyph
->object
))
21027 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21029 glyph
= row
->glyphs
[TEXT_AREA
];
21030 end
= glyph
+ row
->used
[TEXT_AREA
];
21032 /* Skip over glyphs not having an object at the start of the row.
21033 These are special glyphs like truncation marks on terminal
21035 if (row
->displays_text_p
)
21037 && INTEGERP (glyph
->object
)
21038 && !EQ (stop
, glyph
->object
)
21039 && glyph
->charpos
< 0)
21041 *x
+= glyph
->pixel_width
;
21046 && !INTEGERP (glyph
->object
)
21047 && !EQ (stop
, glyph
->object
)
21048 && (!BUFFERP (glyph
->object
)
21049 || glyph
->charpos
< charpos
))
21051 *x
+= glyph
->pixel_width
;
21055 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
21062 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
21065 int *hpos
, *vpos
, *x
, *y
;
21070 int maybe_next_line_p
= 0;
21071 int line_start_position
;
21072 int yb
= window_text_bottom_y (w
);
21073 struct glyph_row
*row
, *best_row
;
21074 int row_vpos
, best_row_vpos
;
21077 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21078 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21080 while (row
->y
< yb
)
21082 if (row
->used
[TEXT_AREA
])
21083 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
21085 line_start_position
= 0;
21087 if (line_start_position
> pos
)
21089 /* If the position sought is the end of the buffer,
21090 don't include the blank lines at the bottom of the window. */
21091 else if (line_start_position
== pos
21092 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
21094 maybe_next_line_p
= 1;
21097 else if (line_start_position
> 0)
21100 best_row_vpos
= row_vpos
;
21103 if (row
->y
+ row
->height
>= yb
)
21110 /* Find the right column within BEST_ROW. */
21112 current_x
= best_row
->x
;
21113 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
21115 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
21116 int charpos
= glyph
->charpos
;
21118 if (BUFFERP (glyph
->object
))
21120 if (charpos
== pos
)
21123 *vpos
= best_row_vpos
;
21128 else if (charpos
> pos
)
21131 else if (EQ (glyph
->object
, stop
))
21136 current_x
+= glyph
->pixel_width
;
21139 /* If we're looking for the end of the buffer,
21140 and we didn't find it in the line we scanned,
21141 use the start of the following line. */
21142 if (maybe_next_line_p
)
21147 current_x
= best_row
->x
;
21150 *vpos
= best_row_vpos
;
21151 *hpos
= lastcol
+ 1;
21160 /* Find the position of the glyph for position POS in OBJECT in
21161 window W's current matrix, and return in *X, *Y the pixel
21162 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
21164 RIGHT_P non-zero means return the position of the right edge of the
21165 glyph, RIGHT_P zero means return the left edge position.
21167 If no glyph for POS exists in the matrix, return the position of
21168 the glyph with the next smaller position that is in the matrix, if
21169 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
21170 exists in the matrix, return the position of the glyph with the
21171 next larger position in OBJECT.
21173 Value is non-zero if a glyph was found. */
21176 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
21179 Lisp_Object object
;
21180 int *hpos
, *vpos
, *x
, *y
;
21183 int yb
= window_text_bottom_y (w
);
21184 struct glyph_row
*r
;
21185 struct glyph
*best_glyph
= NULL
;
21186 struct glyph_row
*best_row
= NULL
;
21189 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21190 r
->enabled_p
&& r
->y
< yb
;
21193 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
21194 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
21197 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
21198 if (EQ (g
->object
, object
))
21200 if (g
->charpos
== pos
)
21207 else if (best_glyph
== NULL
21208 || ((abs (g
->charpos
- pos
)
21209 < abs (best_glyph
->charpos
- pos
))
21212 : g
->charpos
> pos
)))
21226 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
21230 *x
+= best_glyph
->pixel_width
;
21235 *vpos
= best_row
- w
->current_matrix
->rows
;
21238 return best_glyph
!= NULL
;
21242 /* See if position X, Y is within a hot-spot of an image. */
21245 on_hot_spot_p (hot_spot
, x
, y
)
21246 Lisp_Object hot_spot
;
21249 if (!CONSP (hot_spot
))
21252 if (EQ (XCAR (hot_spot
), Qrect
))
21254 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
21255 Lisp_Object rect
= XCDR (hot_spot
);
21259 if (!CONSP (XCAR (rect
)))
21261 if (!CONSP (XCDR (rect
)))
21263 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
21265 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
21267 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
21269 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
21273 else if (EQ (XCAR (hot_spot
), Qcircle
))
21275 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
21276 Lisp_Object circ
= XCDR (hot_spot
);
21277 Lisp_Object lr
, lx0
, ly0
;
21279 && CONSP (XCAR (circ
))
21280 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
21281 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
21282 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
21284 double r
= XFLOATINT (lr
);
21285 double dx
= XINT (lx0
) - x
;
21286 double dy
= XINT (ly0
) - y
;
21287 return (dx
* dx
+ dy
* dy
<= r
* r
);
21290 else if (EQ (XCAR (hot_spot
), Qpoly
))
21292 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
21293 if (VECTORP (XCDR (hot_spot
)))
21295 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
21296 Lisp_Object
*poly
= v
->contents
;
21300 Lisp_Object lx
, ly
;
21303 /* Need an even number of coordinates, and at least 3 edges. */
21304 if (n
< 6 || n
& 1)
21307 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
21308 If count is odd, we are inside polygon. Pixels on edges
21309 may or may not be included depending on actual geometry of the
21311 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
21312 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
21314 x0
= XINT (lx
), y0
= XINT (ly
);
21315 for (i
= 0; i
< n
; i
+= 2)
21317 int x1
= x0
, y1
= y0
;
21318 if ((lx
= poly
[i
], !INTEGERP (lx
))
21319 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
21321 x0
= XINT (lx
), y0
= XINT (ly
);
21323 /* Does this segment cross the X line? */
21331 if (y
> y0
&& y
> y1
)
21333 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
21343 find_hot_spot (map
, x
, y
)
21347 while (CONSP (map
))
21349 if (CONSP (XCAR (map
))
21350 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
21358 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
21360 doc
: /* Lookup in image map MAP coordinates X and Y.
21361 An image map is an alist where each element has the format (AREA ID PLIST).
21362 An AREA is specified as either a rectangle, a circle, or a polygon:
21363 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
21364 pixel coordinates of the upper left and bottom right corners.
21365 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
21366 and the radius of the circle; r may be a float or integer.
21367 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
21368 vector describes one corner in the polygon.
21369 Returns the alist element for the first matching AREA in MAP. */)
21380 return find_hot_spot (map
, XINT (x
), XINT (y
));
21384 /* Display frame CURSOR, optionally using shape defined by POINTER. */
21386 define_frame_cursor1 (f
, cursor
, pointer
)
21389 Lisp_Object pointer
;
21391 /* Do not change cursor shape while dragging mouse. */
21392 if (!NILP (do_mouse_tracking
))
21395 if (!NILP (pointer
))
21397 if (EQ (pointer
, Qarrow
))
21398 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21399 else if (EQ (pointer
, Qhand
))
21400 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
21401 else if (EQ (pointer
, Qtext
))
21402 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21403 else if (EQ (pointer
, intern ("hdrag")))
21404 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21405 #ifdef HAVE_X_WINDOWS
21406 else if (EQ (pointer
, intern ("vdrag")))
21407 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
21409 else if (EQ (pointer
, intern ("hourglass")))
21410 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
21411 else if (EQ (pointer
, Qmodeline
))
21412 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
21414 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21417 if (cursor
!= No_Cursor
)
21418 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
21421 /* Take proper action when mouse has moved to the mode or header line
21422 or marginal area AREA of window W, x-position X and y-position Y.
21423 X is relative to the start of the text display area of W, so the
21424 width of bitmap areas and scroll bars must be subtracted to get a
21425 position relative to the start of the mode line. */
21428 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
21429 Lisp_Object window
;
21431 enum window_part area
;
21433 struct window
*w
= XWINDOW (window
);
21434 struct frame
*f
= XFRAME (w
->frame
);
21435 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21436 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21437 Lisp_Object pointer
= Qnil
;
21438 int charpos
, dx
, dy
, width
, height
;
21439 Lisp_Object string
, object
= Qnil
;
21440 Lisp_Object pos
, help
;
21442 Lisp_Object mouse_face
;
21443 int original_x_pixel
= x
;
21444 struct glyph
* glyph
= NULL
;
21445 struct glyph_row
*row
;
21447 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
21452 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
21453 &object
, &dx
, &dy
, &width
, &height
);
21455 row
= (area
== ON_MODE_LINE
21456 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
21457 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
21460 if (row
->mode_line_p
&& row
->enabled_p
)
21462 glyph
= row
->glyphs
[TEXT_AREA
];
21463 end
= glyph
+ row
->used
[TEXT_AREA
];
21465 for (x0
= original_x_pixel
;
21466 glyph
< end
&& x0
>= glyph
->pixel_width
;
21468 x0
-= glyph
->pixel_width
;
21476 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
21477 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
21478 &object
, &dx
, &dy
, &width
, &height
);
21483 if (IMAGEP (object
))
21485 Lisp_Object image_map
, hotspot
;
21486 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
21488 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
21490 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21492 Lisp_Object area_id
, plist
;
21494 area_id
= XCAR (hotspot
);
21495 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21496 If so, we could look for mouse-enter, mouse-leave
21497 properties in PLIST (and do something...). */
21498 hotspot
= XCDR (hotspot
);
21499 if (CONSP (hotspot
)
21500 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21502 pointer
= Fplist_get (plist
, Qpointer
);
21503 if (NILP (pointer
))
21505 help
= Fplist_get (plist
, Qhelp_echo
);
21508 help_echo_string
= help
;
21509 /* Is this correct? ++kfs */
21510 XSETWINDOW (help_echo_window
, w
);
21511 help_echo_object
= w
->buffer
;
21512 help_echo_pos
= charpos
;
21516 if (NILP (pointer
))
21517 pointer
= Fplist_get (XCDR (object
), QCpointer
);
21520 if (STRINGP (string
))
21522 pos
= make_number (charpos
);
21523 /* If we're on a string with `help-echo' text property, arrange
21524 for the help to be displayed. This is done by setting the
21525 global variable help_echo_string to the help string. */
21528 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
21531 help_echo_string
= help
;
21532 XSETWINDOW (help_echo_window
, w
);
21533 help_echo_object
= string
;
21534 help_echo_pos
= charpos
;
21538 if (NILP (pointer
))
21539 pointer
= Fget_text_property (pos
, Qpointer
, string
);
21541 /* Change the mouse pointer according to what is under X/Y. */
21542 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
21545 map
= Fget_text_property (pos
, Qlocal_map
, string
);
21546 if (!KEYMAPP (map
))
21547 map
= Fget_text_property (pos
, Qkeymap
, string
);
21548 if (!KEYMAPP (map
))
21549 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
21552 /* Change the mouse face according to what is under X/Y. */
21553 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
21554 if (!NILP (mouse_face
)
21555 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
21560 struct glyph
* tmp_glyph
;
21564 int total_pixel_width
;
21569 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
21570 Qmouse_face
, string
, Qnil
);
21572 b
= make_number (0);
21574 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
21576 e
= make_number (SCHARS (string
));
21578 /* Calculate the position(glyph position: GPOS) of GLYPH in
21579 displayed string. GPOS is different from CHARPOS.
21581 CHARPOS is the position of glyph in internal string
21582 object. A mode line string format has structures which
21583 is converted to a flatten by emacs lisp interpreter.
21584 The internal string is an element of the structures.
21585 The displayed string is the flatten string. */
21586 for (tmp_glyph
= glyph
- 1, gpos
= 0;
21587 tmp_glyph
->charpos
>= XINT (b
);
21588 tmp_glyph
--, gpos
++)
21590 if (!EQ (tmp_glyph
->object
, glyph
->object
))
21594 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
21595 displayed string holding GLYPH.
21597 GSEQ_LENGTH is different from SCHARS (STRING).
21598 SCHARS (STRING) returns the length of the internal string. */
21599 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
21600 tmp_glyph
->charpos
< XINT (e
);
21601 tmp_glyph
++, gseq_length
++)
21603 if (!EQ (tmp_glyph
->object
, glyph
->object
))
21607 total_pixel_width
= 0;
21608 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
21609 total_pixel_width
+= tmp_glyph
->pixel_width
;
21611 /* Pre calculation of re-rendering position */
21613 hpos
= (area
== ON_MODE_LINE
21614 ? (w
->current_matrix
)->nrows
- 1
21617 /* If the re-rendering position is included in the last
21618 re-rendering area, we should do nothing. */
21619 if ( EQ (window
, dpyinfo
->mouse_face_window
)
21620 && dpyinfo
->mouse_face_beg_col
<= vpos
21621 && vpos
< dpyinfo
->mouse_face_end_col
21622 && dpyinfo
->mouse_face_beg_row
== hpos
)
21625 if (clear_mouse_face (dpyinfo
))
21626 cursor
= No_Cursor
;
21628 dpyinfo
->mouse_face_beg_col
= vpos
;
21629 dpyinfo
->mouse_face_beg_row
= hpos
;
21631 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
21632 dpyinfo
->mouse_face_beg_y
= 0;
21634 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
21635 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
21637 dpyinfo
->mouse_face_end_x
= 0;
21638 dpyinfo
->mouse_face_end_y
= 0;
21640 dpyinfo
->mouse_face_past_end
= 0;
21641 dpyinfo
->mouse_face_window
= window
;
21643 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
21646 glyph
->face_id
, 1);
21647 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21649 if (NILP (pointer
))
21652 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
21653 clear_mouse_face (dpyinfo
);
21655 define_frame_cursor1 (f
, cursor
, pointer
);
21660 Take proper action when the mouse has moved to position X, Y on
21661 frame F as regards highlighting characters that have mouse-face
21662 properties. Also de-highlighting chars where the mouse was before.
21663 X and Y can be negative or out of range. */
21666 note_mouse_highlight (f
, x
, y
)
21670 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21671 enum window_part part
;
21672 Lisp_Object window
;
21674 Cursor cursor
= No_Cursor
;
21675 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
21678 /* When a menu is active, don't highlight because this looks odd. */
21679 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
21680 if (popup_activated ())
21684 if (NILP (Vmouse_highlight
)
21685 || !f
->glyphs_initialized_p
)
21688 dpyinfo
->mouse_face_mouse_x
= x
;
21689 dpyinfo
->mouse_face_mouse_y
= y
;
21690 dpyinfo
->mouse_face_mouse_frame
= f
;
21692 if (dpyinfo
->mouse_face_defer
)
21695 if (gc_in_progress
)
21697 dpyinfo
->mouse_face_deferred_gc
= 1;
21701 /* Which window is that in? */
21702 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
21704 /* If we were displaying active text in another window, clear that.
21705 Also clear if we move out of text area in same window. */
21706 if (! EQ (window
, dpyinfo
->mouse_face_window
)
21707 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
21708 && !NILP (dpyinfo
->mouse_face_window
)))
21709 clear_mouse_face (dpyinfo
);
21711 /* Not on a window -> return. */
21712 if (!WINDOWP (window
))
21715 /* Reset help_echo_string. It will get recomputed below. */
21716 help_echo_string
= Qnil
;
21718 /* Convert to window-relative pixel coordinates. */
21719 w
= XWINDOW (window
);
21720 frame_to_window_pixel_xy (w
, &x
, &y
);
21722 /* Handle tool-bar window differently since it doesn't display a
21724 if (EQ (window
, f
->tool_bar_window
))
21726 note_tool_bar_highlight (f
, x
, y
);
21730 /* Mouse is on the mode, header line or margin? */
21731 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
21732 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
21734 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
21738 if (part
== ON_VERTICAL_BORDER
)
21739 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21740 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
21741 || part
== ON_SCROLL_BAR
)
21742 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21744 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21746 /* Are we in a window whose display is up to date?
21747 And verify the buffer's text has not changed. */
21748 b
= XBUFFER (w
->buffer
);
21749 if (part
== ON_TEXT
21750 && EQ (w
->window_end_valid
, w
->buffer
)
21751 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
21752 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
21754 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
21755 struct glyph
*glyph
;
21756 Lisp_Object object
;
21757 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
21758 Lisp_Object
*overlay_vec
= NULL
;
21760 struct buffer
*obuf
;
21761 int obegv
, ozv
, same_region
;
21763 /* Find the glyph under X/Y. */
21764 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
21766 /* Look for :pointer property on image. */
21767 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21769 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21770 if (img
!= NULL
&& IMAGEP (img
->spec
))
21772 Lisp_Object image_map
, hotspot
;
21773 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
21775 && (hotspot
= find_hot_spot (image_map
,
21776 glyph
->slice
.x
+ dx
,
21777 glyph
->slice
.y
+ dy
),
21779 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21781 Lisp_Object area_id
, plist
;
21783 area_id
= XCAR (hotspot
);
21784 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21785 If so, we could look for mouse-enter, mouse-leave
21786 properties in PLIST (and do something...). */
21787 hotspot
= XCDR (hotspot
);
21788 if (CONSP (hotspot
)
21789 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21791 pointer
= Fplist_get (plist
, Qpointer
);
21792 if (NILP (pointer
))
21794 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
21795 if (!NILP (help_echo_string
))
21797 help_echo_window
= window
;
21798 help_echo_object
= glyph
->object
;
21799 help_echo_pos
= glyph
->charpos
;
21803 if (NILP (pointer
))
21804 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
21808 /* Clear mouse face if X/Y not over text. */
21810 || area
!= TEXT_AREA
21811 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
21813 if (clear_mouse_face (dpyinfo
))
21814 cursor
= No_Cursor
;
21815 if (NILP (pointer
))
21817 if (area
!= TEXT_AREA
)
21818 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21820 pointer
= Vvoid_text_area_pointer
;
21825 pos
= glyph
->charpos
;
21826 object
= glyph
->object
;
21827 if (!STRINGP (object
) && !BUFFERP (object
))
21830 /* If we get an out-of-range value, return now; avoid an error. */
21831 if (BUFFERP (object
) && pos
> BUF_Z (b
))
21834 /* Make the window's buffer temporarily current for
21835 overlays_at and compute_char_face. */
21836 obuf
= current_buffer
;
21837 current_buffer
= b
;
21843 /* Is this char mouse-active or does it have help-echo? */
21844 position
= make_number (pos
);
21846 if (BUFFERP (object
))
21848 /* Put all the overlays we want in a vector in overlay_vec. */
21849 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
21850 /* Sort overlays into increasing priority order. */
21851 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
21856 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
21857 && vpos
>= dpyinfo
->mouse_face_beg_row
21858 && vpos
<= dpyinfo
->mouse_face_end_row
21859 && (vpos
> dpyinfo
->mouse_face_beg_row
21860 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21861 && (vpos
< dpyinfo
->mouse_face_end_row
21862 || hpos
< dpyinfo
->mouse_face_end_col
21863 || dpyinfo
->mouse_face_past_end
));
21866 cursor
= No_Cursor
;
21868 /* Check mouse-face highlighting. */
21870 /* If there exists an overlay with mouse-face overlapping
21871 the one we are currently highlighting, we have to
21872 check if we enter the overlapping overlay, and then
21873 highlight only that. */
21874 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
21875 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
21877 /* Find the highest priority overlay that has a mouse-face
21880 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
21882 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
21883 if (!NILP (mouse_face
))
21884 overlay
= overlay_vec
[i
];
21887 /* If we're actually highlighting the same overlay as
21888 before, there's no need to do that again. */
21889 if (!NILP (overlay
)
21890 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
21891 goto check_help_echo
;
21893 dpyinfo
->mouse_face_overlay
= overlay
;
21895 /* Clear the display of the old active region, if any. */
21896 if (clear_mouse_face (dpyinfo
))
21897 cursor
= No_Cursor
;
21899 /* If no overlay applies, get a text property. */
21900 if (NILP (overlay
))
21901 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
21903 /* Handle the overlay case. */
21904 if (!NILP (overlay
))
21906 /* Find the range of text around this char that
21907 should be active. */
21908 Lisp_Object before
, after
;
21911 before
= Foverlay_start (overlay
);
21912 after
= Foverlay_end (overlay
);
21913 /* Record this as the current active region. */
21914 fast_find_position (w
, XFASTINT (before
),
21915 &dpyinfo
->mouse_face_beg_col
,
21916 &dpyinfo
->mouse_face_beg_row
,
21917 &dpyinfo
->mouse_face_beg_x
,
21918 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21920 dpyinfo
->mouse_face_past_end
21921 = !fast_find_position (w
, XFASTINT (after
),
21922 &dpyinfo
->mouse_face_end_col
,
21923 &dpyinfo
->mouse_face_end_row
,
21924 &dpyinfo
->mouse_face_end_x
,
21925 &dpyinfo
->mouse_face_end_y
, Qnil
);
21926 dpyinfo
->mouse_face_window
= window
;
21928 dpyinfo
->mouse_face_face_id
21929 = face_at_buffer_position (w
, pos
, 0, 0,
21931 !dpyinfo
->mouse_face_hidden
);
21933 /* Display it as active. */
21934 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21935 cursor
= No_Cursor
;
21937 /* Handle the text property case. */
21938 else if (!NILP (mouse_face
) && BUFFERP (object
))
21940 /* Find the range of text around this char that
21941 should be active. */
21942 Lisp_Object before
, after
, beginning
, end
;
21945 beginning
= Fmarker_position (w
->start
);
21946 end
= make_number (BUF_Z (XBUFFER (object
))
21947 - XFASTINT (w
->window_end_pos
));
21949 = Fprevious_single_property_change (make_number (pos
+ 1),
21951 object
, beginning
);
21953 = Fnext_single_property_change (position
, Qmouse_face
,
21956 /* Record this as the current active region. */
21957 fast_find_position (w
, XFASTINT (before
),
21958 &dpyinfo
->mouse_face_beg_col
,
21959 &dpyinfo
->mouse_face_beg_row
,
21960 &dpyinfo
->mouse_face_beg_x
,
21961 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21962 dpyinfo
->mouse_face_past_end
21963 = !fast_find_position (w
, XFASTINT (after
),
21964 &dpyinfo
->mouse_face_end_col
,
21965 &dpyinfo
->mouse_face_end_row
,
21966 &dpyinfo
->mouse_face_end_x
,
21967 &dpyinfo
->mouse_face_end_y
, Qnil
);
21968 dpyinfo
->mouse_face_window
= window
;
21970 if (BUFFERP (object
))
21971 dpyinfo
->mouse_face_face_id
21972 = face_at_buffer_position (w
, pos
, 0, 0,
21974 !dpyinfo
->mouse_face_hidden
);
21976 /* Display it as active. */
21977 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21978 cursor
= No_Cursor
;
21980 else if (!NILP (mouse_face
) && STRINGP (object
))
21985 b
= Fprevious_single_property_change (make_number (pos
+ 1),
21988 e
= Fnext_single_property_change (position
, Qmouse_face
,
21991 b
= make_number (0);
21993 e
= make_number (SCHARS (object
) - 1);
21995 fast_find_string_pos (w
, XINT (b
), object
,
21996 &dpyinfo
->mouse_face_beg_col
,
21997 &dpyinfo
->mouse_face_beg_row
,
21998 &dpyinfo
->mouse_face_beg_x
,
21999 &dpyinfo
->mouse_face_beg_y
, 0);
22000 fast_find_string_pos (w
, XINT (e
), object
,
22001 &dpyinfo
->mouse_face_end_col
,
22002 &dpyinfo
->mouse_face_end_row
,
22003 &dpyinfo
->mouse_face_end_x
,
22004 &dpyinfo
->mouse_face_end_y
, 1);
22005 dpyinfo
->mouse_face_past_end
= 0;
22006 dpyinfo
->mouse_face_window
= window
;
22007 dpyinfo
->mouse_face_face_id
22008 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
22009 glyph
->face_id
, 1);
22010 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22011 cursor
= No_Cursor
;
22013 else if (STRINGP (object
) && NILP (mouse_face
))
22015 /* A string which doesn't have mouse-face, but
22016 the text ``under'' it might have. */
22017 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
22018 int start
= MATRIX_ROW_START_CHARPOS (r
);
22020 pos
= string_buffer_position (w
, object
, start
);
22022 mouse_face
= get_char_property_and_overlay (make_number (pos
),
22026 if (!NILP (mouse_face
) && !NILP (overlay
))
22028 Lisp_Object before
= Foverlay_start (overlay
);
22029 Lisp_Object after
= Foverlay_end (overlay
);
22032 /* Note that we might not be able to find position
22033 BEFORE in the glyph matrix if the overlay is
22034 entirely covered by a `display' property. In
22035 this case, we overshoot. So let's stop in
22036 the glyph matrix before glyphs for OBJECT. */
22037 fast_find_position (w
, XFASTINT (before
),
22038 &dpyinfo
->mouse_face_beg_col
,
22039 &dpyinfo
->mouse_face_beg_row
,
22040 &dpyinfo
->mouse_face_beg_x
,
22041 &dpyinfo
->mouse_face_beg_y
,
22044 dpyinfo
->mouse_face_past_end
22045 = !fast_find_position (w
, XFASTINT (after
),
22046 &dpyinfo
->mouse_face_end_col
,
22047 &dpyinfo
->mouse_face_end_row
,
22048 &dpyinfo
->mouse_face_end_x
,
22049 &dpyinfo
->mouse_face_end_y
,
22051 dpyinfo
->mouse_face_window
= window
;
22052 dpyinfo
->mouse_face_face_id
22053 = face_at_buffer_position (w
, pos
, 0, 0,
22055 !dpyinfo
->mouse_face_hidden
);
22057 /* Display it as active. */
22058 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22059 cursor
= No_Cursor
;
22066 /* Look for a `help-echo' property. */
22067 if (NILP (help_echo_string
)) {
22068 Lisp_Object help
, overlay
;
22070 /* Check overlays first. */
22071 help
= overlay
= Qnil
;
22072 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
22074 overlay
= overlay_vec
[i
];
22075 help
= Foverlay_get (overlay
, Qhelp_echo
);
22080 help_echo_string
= help
;
22081 help_echo_window
= window
;
22082 help_echo_object
= overlay
;
22083 help_echo_pos
= pos
;
22087 Lisp_Object object
= glyph
->object
;
22088 int charpos
= glyph
->charpos
;
22090 /* Try text properties. */
22091 if (STRINGP (object
)
22093 && charpos
< SCHARS (object
))
22095 help
= Fget_text_property (make_number (charpos
),
22096 Qhelp_echo
, object
);
22099 /* If the string itself doesn't specify a help-echo,
22100 see if the buffer text ``under'' it does. */
22101 struct glyph_row
*r
22102 = MATRIX_ROW (w
->current_matrix
, vpos
);
22103 int start
= MATRIX_ROW_START_CHARPOS (r
);
22104 int pos
= string_buffer_position (w
, object
, start
);
22107 help
= Fget_char_property (make_number (pos
),
22108 Qhelp_echo
, w
->buffer
);
22112 object
= w
->buffer
;
22117 else if (BUFFERP (object
)
22120 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
22125 help_echo_string
= help
;
22126 help_echo_window
= window
;
22127 help_echo_object
= object
;
22128 help_echo_pos
= charpos
;
22133 /* Look for a `pointer' property. */
22134 if (NILP (pointer
))
22136 /* Check overlays first. */
22137 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
22138 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
22140 if (NILP (pointer
))
22142 Lisp_Object object
= glyph
->object
;
22143 int charpos
= glyph
->charpos
;
22145 /* Try text properties. */
22146 if (STRINGP (object
)
22148 && charpos
< SCHARS (object
))
22150 pointer
= Fget_text_property (make_number (charpos
),
22152 if (NILP (pointer
))
22154 /* If the string itself doesn't specify a pointer,
22155 see if the buffer text ``under'' it does. */
22156 struct glyph_row
*r
22157 = MATRIX_ROW (w
->current_matrix
, vpos
);
22158 int start
= MATRIX_ROW_START_CHARPOS (r
);
22159 int pos
= string_buffer_position (w
, object
, start
);
22161 pointer
= Fget_char_property (make_number (pos
),
22162 Qpointer
, w
->buffer
);
22165 else if (BUFFERP (object
)
22168 pointer
= Fget_text_property (make_number (charpos
),
22175 current_buffer
= obuf
;
22180 define_frame_cursor1 (f
, cursor
, pointer
);
22185 Clear any mouse-face on window W. This function is part of the
22186 redisplay interface, and is called from try_window_id and similar
22187 functions to ensure the mouse-highlight is off. */
22190 x_clear_window_mouse_face (w
)
22193 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22194 Lisp_Object window
;
22197 XSETWINDOW (window
, w
);
22198 if (EQ (window
, dpyinfo
->mouse_face_window
))
22199 clear_mouse_face (dpyinfo
);
22205 Just discard the mouse face information for frame F, if any.
22206 This is used when the size of F is changed. */
22209 cancel_mouse_face (f
)
22212 Lisp_Object window
;
22213 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22215 window
= dpyinfo
->mouse_face_window
;
22216 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
22218 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22219 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22220 dpyinfo
->mouse_face_window
= Qnil
;
22225 #endif /* HAVE_WINDOW_SYSTEM */
22228 /***********************************************************************
22230 ***********************************************************************/
22232 #ifdef HAVE_WINDOW_SYSTEM
22234 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
22235 which intersects rectangle R. R is in window-relative coordinates. */
22238 expose_area (w
, row
, r
, area
)
22240 struct glyph_row
*row
;
22242 enum glyph_row_area area
;
22244 struct glyph
*first
= row
->glyphs
[area
];
22245 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
22246 struct glyph
*last
;
22247 int first_x
, start_x
, x
;
22249 if (area
== TEXT_AREA
&& row
->fill_line_p
)
22250 /* If row extends face to end of line write the whole line. */
22251 draw_glyphs (w
, 0, row
, area
,
22252 0, row
->used
[area
],
22253 DRAW_NORMAL_TEXT
, 0);
22256 /* Set START_X to the window-relative start position for drawing glyphs of
22257 AREA. The first glyph of the text area can be partially visible.
22258 The first glyphs of other areas cannot. */
22259 start_x
= window_box_left_offset (w
, area
);
22261 if (area
== TEXT_AREA
)
22264 /* Find the first glyph that must be redrawn. */
22266 && x
+ first
->pixel_width
< r
->x
)
22268 x
+= first
->pixel_width
;
22272 /* Find the last one. */
22276 && x
< r
->x
+ r
->width
)
22278 x
+= last
->pixel_width
;
22284 draw_glyphs (w
, first_x
- start_x
, row
, area
,
22285 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
22286 DRAW_NORMAL_TEXT
, 0);
22291 /* Redraw the parts of the glyph row ROW on window W intersecting
22292 rectangle R. R is in window-relative coordinates. Value is
22293 non-zero if mouse-face was overwritten. */
22296 expose_line (w
, row
, r
)
22298 struct glyph_row
*row
;
22301 xassert (row
->enabled_p
);
22303 if (row
->mode_line_p
|| w
->pseudo_window_p
)
22304 draw_glyphs (w
, 0, row
, TEXT_AREA
,
22305 0, row
->used
[TEXT_AREA
],
22306 DRAW_NORMAL_TEXT
, 0);
22309 if (row
->used
[LEFT_MARGIN_AREA
])
22310 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
22311 if (row
->used
[TEXT_AREA
])
22312 expose_area (w
, row
, r
, TEXT_AREA
);
22313 if (row
->used
[RIGHT_MARGIN_AREA
])
22314 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
22315 draw_row_fringe_bitmaps (w
, row
);
22318 return row
->mouse_face_p
;
22322 /* Redraw those parts of glyphs rows during expose event handling that
22323 overlap other rows. Redrawing of an exposed line writes over parts
22324 of lines overlapping that exposed line; this function fixes that.
22326 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
22327 row in W's current matrix that is exposed and overlaps other rows.
22328 LAST_OVERLAPPING_ROW is the last such row. */
22331 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
22333 struct glyph_row
*first_overlapping_row
;
22334 struct glyph_row
*last_overlapping_row
;
22336 struct glyph_row
*row
;
22338 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
22339 if (row
->overlapping_p
)
22341 xassert (row
->enabled_p
&& !row
->mode_line_p
);
22343 if (row
->used
[LEFT_MARGIN_AREA
])
22344 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
22346 if (row
->used
[TEXT_AREA
])
22347 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
22349 if (row
->used
[RIGHT_MARGIN_AREA
])
22350 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
22355 /* Return non-zero if W's cursor intersects rectangle R. */
22358 phys_cursor_in_rect_p (w
, r
)
22362 XRectangle cr
, result
;
22363 struct glyph
*cursor_glyph
;
22365 cursor_glyph
= get_phys_cursor_glyph (w
);
22368 /* r is relative to W's box, but w->phys_cursor.x is relative
22369 to left edge of W's TEXT area. Adjust it. */
22370 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
22371 cr
.y
= w
->phys_cursor
.y
;
22372 cr
.width
= cursor_glyph
->pixel_width
;
22373 cr
.height
= w
->phys_cursor_height
;
22374 /* ++KFS: W32 version used W32-specific IntersectRect here, but
22375 I assume the effect is the same -- and this is portable. */
22376 return x_intersect_rectangles (&cr
, r
, &result
);
22378 /* If we don't understand the format, pretend we're not in the hot-spot. */
22384 Draw a vertical window border to the right of window W if W doesn't
22385 have vertical scroll bars. */
22388 x_draw_vertical_border (w
)
22391 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22393 /* We could do better, if we knew what type of scroll-bar the adjacent
22394 windows (on either side) have... But we don't :-(
22395 However, I think this works ok. ++KFS 2003-04-25 */
22397 /* Redraw borders between horizontally adjacent windows. Don't
22398 do it for frames with vertical scroll bars because either the
22399 right scroll bar of a window, or the left scroll bar of its
22400 neighbor will suffice as a border. */
22401 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
22404 if (!WINDOW_RIGHTMOST_P (w
)
22405 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
22407 int x0
, x1
, y0
, y1
;
22409 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22412 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22415 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
22417 else if (!WINDOW_LEFTMOST_P (w
)
22418 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
22420 int x0
, x1
, y0
, y1
;
22422 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22425 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22428 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
22433 /* Redraw the part of window W intersection rectangle FR. Pixel
22434 coordinates in FR are frame-relative. Call this function with
22435 input blocked. Value is non-zero if the exposure overwrites
22439 expose_window (w
, fr
)
22443 struct frame
*f
= XFRAME (w
->frame
);
22445 int mouse_face_overwritten_p
= 0;
22447 /* If window is not yet fully initialized, do nothing. This can
22448 happen when toolkit scroll bars are used and a window is split.
22449 Reconfiguring the scroll bar will generate an expose for a newly
22451 if (w
->current_matrix
== NULL
)
22454 /* When we're currently updating the window, display and current
22455 matrix usually don't agree. Arrange for a thorough display
22457 if (w
== updated_window
)
22459 SET_FRAME_GARBAGED (f
);
22463 /* Frame-relative pixel rectangle of W. */
22464 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
22465 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
22466 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
22467 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
22469 if (x_intersect_rectangles (fr
, &wr
, &r
))
22471 int yb
= window_text_bottom_y (w
);
22472 struct glyph_row
*row
;
22473 int cursor_cleared_p
;
22474 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
22476 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
22477 r
.x
, r
.y
, r
.width
, r
.height
));
22479 /* Convert to window coordinates. */
22480 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
22481 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
22483 /* Turn off the cursor. */
22484 if (!w
->pseudo_window_p
22485 && phys_cursor_in_rect_p (w
, &r
))
22487 x_clear_cursor (w
);
22488 cursor_cleared_p
= 1;
22491 cursor_cleared_p
= 0;
22493 /* Update lines intersecting rectangle R. */
22494 first_overlapping_row
= last_overlapping_row
= NULL
;
22495 for (row
= w
->current_matrix
->rows
;
22500 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
22502 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
22503 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
22504 || (r
.y
>= y0
&& r
.y
< y1
)
22505 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
22507 /* A header line may be overlapping, but there is no need
22508 to fix overlapping areas for them. KFS 2005-02-12 */
22509 if (row
->overlapping_p
&& !row
->mode_line_p
)
22511 if (first_overlapping_row
== NULL
)
22512 first_overlapping_row
= row
;
22513 last_overlapping_row
= row
;
22516 if (expose_line (w
, row
, &r
))
22517 mouse_face_overwritten_p
= 1;
22524 /* Display the mode line if there is one. */
22525 if (WINDOW_WANTS_MODELINE_P (w
)
22526 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
22528 && row
->y
< r
.y
+ r
.height
)
22530 if (expose_line (w
, row
, &r
))
22531 mouse_face_overwritten_p
= 1;
22534 if (!w
->pseudo_window_p
)
22536 /* Fix the display of overlapping rows. */
22537 if (first_overlapping_row
)
22538 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
22540 /* Draw border between windows. */
22541 x_draw_vertical_border (w
);
22543 /* Turn the cursor on again. */
22544 if (cursor_cleared_p
)
22545 update_window_cursor (w
, 1);
22549 return mouse_face_overwritten_p
;
22554 /* Redraw (parts) of all windows in the window tree rooted at W that
22555 intersect R. R contains frame pixel coordinates. Value is
22556 non-zero if the exposure overwrites mouse-face. */
22559 expose_window_tree (w
, r
)
22563 struct frame
*f
= XFRAME (w
->frame
);
22564 int mouse_face_overwritten_p
= 0;
22566 while (w
&& !FRAME_GARBAGED_P (f
))
22568 if (!NILP (w
->hchild
))
22569 mouse_face_overwritten_p
22570 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
22571 else if (!NILP (w
->vchild
))
22572 mouse_face_overwritten_p
22573 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
22575 mouse_face_overwritten_p
|= expose_window (w
, r
);
22577 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
22580 return mouse_face_overwritten_p
;
22585 Redisplay an exposed area of frame F. X and Y are the upper-left
22586 corner of the exposed rectangle. W and H are width and height of
22587 the exposed area. All are pixel values. W or H zero means redraw
22588 the entire frame. */
22591 expose_frame (f
, x
, y
, w
, h
)
22596 int mouse_face_overwritten_p
= 0;
22598 TRACE ((stderr
, "expose_frame "));
22600 /* No need to redraw if frame will be redrawn soon. */
22601 if (FRAME_GARBAGED_P (f
))
22603 TRACE ((stderr
, " garbaged\n"));
22607 /* If basic faces haven't been realized yet, there is no point in
22608 trying to redraw anything. This can happen when we get an expose
22609 event while Emacs is starting, e.g. by moving another window. */
22610 if (FRAME_FACE_CACHE (f
) == NULL
22611 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
22613 TRACE ((stderr
, " no faces\n"));
22617 if (w
== 0 || h
== 0)
22620 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
22621 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
22631 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
22632 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
22634 if (WINDOWP (f
->tool_bar_window
))
22635 mouse_face_overwritten_p
22636 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
22638 #ifdef HAVE_X_WINDOWS
22640 #ifndef USE_X_TOOLKIT
22641 if (WINDOWP (f
->menu_bar_window
))
22642 mouse_face_overwritten_p
22643 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
22644 #endif /* not USE_X_TOOLKIT */
22648 /* Some window managers support a focus-follows-mouse style with
22649 delayed raising of frames. Imagine a partially obscured frame,
22650 and moving the mouse into partially obscured mouse-face on that
22651 frame. The visible part of the mouse-face will be highlighted,
22652 then the WM raises the obscured frame. With at least one WM, KDE
22653 2.1, Emacs is not getting any event for the raising of the frame
22654 (even tried with SubstructureRedirectMask), only Expose events.
22655 These expose events will draw text normally, i.e. not
22656 highlighted. Which means we must redo the highlight here.
22657 Subsume it under ``we love X''. --gerd 2001-08-15 */
22658 /* Included in Windows version because Windows most likely does not
22659 do the right thing if any third party tool offers
22660 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
22661 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
22663 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22664 if (f
== dpyinfo
->mouse_face_mouse_frame
)
22666 int x
= dpyinfo
->mouse_face_mouse_x
;
22667 int y
= dpyinfo
->mouse_face_mouse_y
;
22668 clear_mouse_face (dpyinfo
);
22669 note_mouse_highlight (f
, x
, y
);
22676 Determine the intersection of two rectangles R1 and R2. Return
22677 the intersection in *RESULT. Value is non-zero if RESULT is not
22681 x_intersect_rectangles (r1
, r2
, result
)
22682 XRectangle
*r1
, *r2
, *result
;
22684 XRectangle
*left
, *right
;
22685 XRectangle
*upper
, *lower
;
22686 int intersection_p
= 0;
22688 /* Rearrange so that R1 is the left-most rectangle. */
22690 left
= r1
, right
= r2
;
22692 left
= r2
, right
= r1
;
22694 /* X0 of the intersection is right.x0, if this is inside R1,
22695 otherwise there is no intersection. */
22696 if (right
->x
<= left
->x
+ left
->width
)
22698 result
->x
= right
->x
;
22700 /* The right end of the intersection is the minimum of the
22701 the right ends of left and right. */
22702 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
22705 /* Same game for Y. */
22707 upper
= r1
, lower
= r2
;
22709 upper
= r2
, lower
= r1
;
22711 /* The upper end of the intersection is lower.y0, if this is inside
22712 of upper. Otherwise, there is no intersection. */
22713 if (lower
->y
<= upper
->y
+ upper
->height
)
22715 result
->y
= lower
->y
;
22717 /* The lower end of the intersection is the minimum of the lower
22718 ends of upper and lower. */
22719 result
->height
= (min (lower
->y
+ lower
->height
,
22720 upper
->y
+ upper
->height
)
22722 intersection_p
= 1;
22726 return intersection_p
;
22729 #endif /* HAVE_WINDOW_SYSTEM */
22732 /***********************************************************************
22734 ***********************************************************************/
22739 Vwith_echo_area_save_vector
= Qnil
;
22740 staticpro (&Vwith_echo_area_save_vector
);
22742 Vmessage_stack
= Qnil
;
22743 staticpro (&Vmessage_stack
);
22745 Qinhibit_redisplay
= intern ("inhibit-redisplay");
22746 staticpro (&Qinhibit_redisplay
);
22748 message_dolog_marker1
= Fmake_marker ();
22749 staticpro (&message_dolog_marker1
);
22750 message_dolog_marker2
= Fmake_marker ();
22751 staticpro (&message_dolog_marker2
);
22752 message_dolog_marker3
= Fmake_marker ();
22753 staticpro (&message_dolog_marker3
);
22756 defsubr (&Sdump_frame_glyph_matrix
);
22757 defsubr (&Sdump_glyph_matrix
);
22758 defsubr (&Sdump_glyph_row
);
22759 defsubr (&Sdump_tool_bar_row
);
22760 defsubr (&Strace_redisplay
);
22761 defsubr (&Strace_to_stderr
);
22763 #ifdef HAVE_WINDOW_SYSTEM
22764 defsubr (&Stool_bar_lines_needed
);
22765 defsubr (&Slookup_image_map
);
22767 defsubr (&Sformat_mode_line
);
22769 staticpro (&Qmenu_bar_update_hook
);
22770 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
22772 staticpro (&Qoverriding_terminal_local_map
);
22773 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
22775 staticpro (&Qoverriding_local_map
);
22776 Qoverriding_local_map
= intern ("overriding-local-map");
22778 staticpro (&Qwindow_scroll_functions
);
22779 Qwindow_scroll_functions
= intern ("window-scroll-functions");
22781 staticpro (&Qredisplay_end_trigger_functions
);
22782 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
22784 staticpro (&Qinhibit_point_motion_hooks
);
22785 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
22787 QCdata
= intern (":data");
22788 staticpro (&QCdata
);
22789 Qdisplay
= intern ("display");
22790 staticpro (&Qdisplay
);
22791 Qspace_width
= intern ("space-width");
22792 staticpro (&Qspace_width
);
22793 Qraise
= intern ("raise");
22794 staticpro (&Qraise
);
22795 Qslice
= intern ("slice");
22796 staticpro (&Qslice
);
22797 Qspace
= intern ("space");
22798 staticpro (&Qspace
);
22799 Qmargin
= intern ("margin");
22800 staticpro (&Qmargin
);
22801 Qpointer
= intern ("pointer");
22802 staticpro (&Qpointer
);
22803 Qleft_margin
= intern ("left-margin");
22804 staticpro (&Qleft_margin
);
22805 Qright_margin
= intern ("right-margin");
22806 staticpro (&Qright_margin
);
22807 Qcenter
= intern ("center");
22808 staticpro (&Qcenter
);
22809 Qline_height
= intern ("line-height");
22810 staticpro (&Qline_height
);
22811 QCalign_to
= intern (":align-to");
22812 staticpro (&QCalign_to
);
22813 QCrelative_width
= intern (":relative-width");
22814 staticpro (&QCrelative_width
);
22815 QCrelative_height
= intern (":relative-height");
22816 staticpro (&QCrelative_height
);
22817 QCeval
= intern (":eval");
22818 staticpro (&QCeval
);
22819 QCpropertize
= intern (":propertize");
22820 staticpro (&QCpropertize
);
22821 QCfile
= intern (":file");
22822 staticpro (&QCfile
);
22823 Qfontified
= intern ("fontified");
22824 staticpro (&Qfontified
);
22825 Qfontification_functions
= intern ("fontification-functions");
22826 staticpro (&Qfontification_functions
);
22827 Qtrailing_whitespace
= intern ("trailing-whitespace");
22828 staticpro (&Qtrailing_whitespace
);
22829 Qescape_glyph
= intern ("escape-glyph");
22830 staticpro (&Qescape_glyph
);
22831 Qnobreak_space
= intern ("nobreak-space");
22832 staticpro (&Qnobreak_space
);
22833 Qimage
= intern ("image");
22834 staticpro (&Qimage
);
22835 QCmap
= intern (":map");
22836 staticpro (&QCmap
);
22837 QCpointer
= intern (":pointer");
22838 staticpro (&QCpointer
);
22839 Qrect
= intern ("rect");
22840 staticpro (&Qrect
);
22841 Qcircle
= intern ("circle");
22842 staticpro (&Qcircle
);
22843 Qpoly
= intern ("poly");
22844 staticpro (&Qpoly
);
22845 Qmessage_truncate_lines
= intern ("message-truncate-lines");
22846 staticpro (&Qmessage_truncate_lines
);
22847 Qgrow_only
= intern ("grow-only");
22848 staticpro (&Qgrow_only
);
22849 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
22850 staticpro (&Qinhibit_menubar_update
);
22851 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
22852 staticpro (&Qinhibit_eval_during_redisplay
);
22853 Qposition
= intern ("position");
22854 staticpro (&Qposition
);
22855 Qbuffer_position
= intern ("buffer-position");
22856 staticpro (&Qbuffer_position
);
22857 Qobject
= intern ("object");
22858 staticpro (&Qobject
);
22859 Qbar
= intern ("bar");
22861 Qhbar
= intern ("hbar");
22862 staticpro (&Qhbar
);
22863 Qbox
= intern ("box");
22865 Qhollow
= intern ("hollow");
22866 staticpro (&Qhollow
);
22867 Qhand
= intern ("hand");
22868 staticpro (&Qhand
);
22869 Qarrow
= intern ("arrow");
22870 staticpro (&Qarrow
);
22871 Qtext
= intern ("text");
22872 staticpro (&Qtext
);
22873 Qrisky_local_variable
= intern ("risky-local-variable");
22874 staticpro (&Qrisky_local_variable
);
22875 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
22876 staticpro (&Qinhibit_free_realized_faces
);
22878 list_of_error
= Fcons (Fcons (intern ("error"),
22879 Fcons (intern ("void-variable"), Qnil
)),
22881 staticpro (&list_of_error
);
22883 Qlast_arrow_position
= intern ("last-arrow-position");
22884 staticpro (&Qlast_arrow_position
);
22885 Qlast_arrow_string
= intern ("last-arrow-string");
22886 staticpro (&Qlast_arrow_string
);
22888 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
22889 staticpro (&Qoverlay_arrow_string
);
22890 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
22891 staticpro (&Qoverlay_arrow_bitmap
);
22893 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
22894 staticpro (&echo_buffer
[0]);
22895 staticpro (&echo_buffer
[1]);
22897 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
22898 staticpro (&echo_area_buffer
[0]);
22899 staticpro (&echo_area_buffer
[1]);
22901 Vmessages_buffer_name
= build_string ("*Messages*");
22902 staticpro (&Vmessages_buffer_name
);
22904 mode_line_proptrans_alist
= Qnil
;
22905 staticpro (&mode_line_proptrans_alist
);
22906 mode_line_string_list
= Qnil
;
22907 staticpro (&mode_line_string_list
);
22908 mode_line_string_face
= Qnil
;
22909 staticpro (&mode_line_string_face
);
22910 mode_line_string_face_prop
= Qnil
;
22911 staticpro (&mode_line_string_face_prop
);
22912 Vmode_line_unwind_vector
= Qnil
;
22913 staticpro (&Vmode_line_unwind_vector
);
22915 help_echo_string
= Qnil
;
22916 staticpro (&help_echo_string
);
22917 help_echo_object
= Qnil
;
22918 staticpro (&help_echo_object
);
22919 help_echo_window
= Qnil
;
22920 staticpro (&help_echo_window
);
22921 previous_help_echo_string
= Qnil
;
22922 staticpro (&previous_help_echo_string
);
22923 help_echo_pos
= -1;
22925 #ifdef HAVE_WINDOW_SYSTEM
22926 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
22927 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
22928 For example, if a block cursor is over a tab, it will be drawn as
22929 wide as that tab on the display. */);
22930 x_stretch_cursor_p
= 0;
22933 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
22934 doc
: /* *Non-nil means highlight trailing whitespace.
22935 The face used for trailing whitespace is `trailing-whitespace'. */);
22936 Vshow_trailing_whitespace
= Qnil
;
22938 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
22939 doc
: /* *Control highlighting of nobreak space and soft hyphen.
22940 A value of t means highlight the character itself (for nobreak space,
22941 use face `nobreak-space').
22942 A value of nil means no highlighting.
22943 Other values mean display the escape glyph followed by an ordinary
22944 space or ordinary hyphen. */);
22945 Vnobreak_char_display
= Qt
;
22947 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
22948 doc
: /* *The pointer shape to show in void text areas.
22949 A value of nil means to show the text pointer. Other options are `arrow',
22950 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
22951 Vvoid_text_area_pointer
= Qarrow
;
22953 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
22954 doc
: /* Non-nil means don't actually do any redisplay.
22955 This is used for internal purposes. */);
22956 Vinhibit_redisplay
= Qnil
;
22958 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
22959 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
22960 Vglobal_mode_string
= Qnil
;
22962 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
22963 doc
: /* Marker for where to display an arrow on top of the buffer text.
22964 This must be the beginning of a line in order to work.
22965 See also `overlay-arrow-string'. */);
22966 Voverlay_arrow_position
= Qnil
;
22968 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
22969 doc
: /* String to display as an arrow in non-window frames.
22970 See also `overlay-arrow-position'. */);
22971 Voverlay_arrow_string
= build_string ("=>");
22973 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
22974 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
22975 The symbols on this list are examined during redisplay to determine
22976 where to display overlay arrows. */);
22977 Voverlay_arrow_variable_list
22978 = Fcons (intern ("overlay-arrow-position"), Qnil
);
22980 DEFVAR_INT ("scroll-step", &scroll_step
,
22981 doc
: /* *The number of lines to try scrolling a window by when point moves out.
22982 If that fails to bring point back on frame, point is centered instead.
22983 If this is zero, point is always centered after it moves off frame.
22984 If you want scrolling to always be a line at a time, you should set
22985 `scroll-conservatively' to a large value rather than set this to 1. */);
22987 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
22988 doc
: /* *Scroll up to this many lines, to bring point back on screen.
22989 A value of zero means to scroll the text to center point vertically
22990 in the window. */);
22991 scroll_conservatively
= 0;
22993 DEFVAR_INT ("scroll-margin", &scroll_margin
,
22994 doc
: /* *Number of lines of margin at the top and bottom of a window.
22995 Recenter the window whenever point gets within this many lines
22996 of the top or bottom of the window. */);
22999 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
23000 doc
: /* Pixels per inch on current display.
23001 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
23002 Vdisplay_pixels_per_inch
= make_float (72.0);
23005 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
23008 DEFVAR_BOOL ("truncate-partial-width-windows",
23009 &truncate_partial_width_windows
,
23010 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
23011 truncate_partial_width_windows
= 1;
23013 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
23014 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
23015 Any other value means to use the appropriate face, `mode-line',
23016 `header-line', or `menu' respectively. */);
23017 mode_line_inverse_video
= 1;
23019 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
23020 doc
: /* *Maximum buffer size for which line number should be displayed.
23021 If the buffer is bigger than this, the line number does not appear
23022 in the mode line. A value of nil means no limit. */);
23023 Vline_number_display_limit
= Qnil
;
23025 DEFVAR_INT ("line-number-display-limit-width",
23026 &line_number_display_limit_width
,
23027 doc
: /* *Maximum line width (in characters) for line number display.
23028 If the average length of the lines near point is bigger than this, then the
23029 line number may be omitted from the mode line. */);
23030 line_number_display_limit_width
= 200;
23032 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
23033 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
23034 highlight_nonselected_windows
= 0;
23036 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
23037 doc
: /* Non-nil if more than one frame is visible on this display.
23038 Minibuffer-only frames don't count, but iconified frames do.
23039 This variable is not guaranteed to be accurate except while processing
23040 `frame-title-format' and `icon-title-format'. */);
23042 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
23043 doc
: /* Template for displaying the title bar of visible frames.
23044 \(Assuming the window manager supports this feature.)
23045 This variable has the same structure as `mode-line-format' (which see),
23046 and is used only on frames for which no explicit name has been set
23047 \(see `modify-frame-parameters'). */);
23049 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
23050 doc
: /* Template for displaying the title bar of an iconified frame.
23051 \(Assuming the window manager supports this feature.)
23052 This variable has the same structure as `mode-line-format' (which see),
23053 and is used only on frames for which no explicit name has been set
23054 \(see `modify-frame-parameters'). */);
23056 = Vframe_title_format
23057 = Fcons (intern ("multiple-frames"),
23058 Fcons (build_string ("%b"),
23059 Fcons (Fcons (empty_string
,
23060 Fcons (intern ("invocation-name"),
23061 Fcons (build_string ("@"),
23062 Fcons (intern ("system-name"),
23066 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
23067 doc
: /* Maximum number of lines to keep in the message log buffer.
23068 If nil, disable message logging. If t, log messages but don't truncate
23069 the buffer when it becomes large. */);
23070 Vmessage_log_max
= make_number (50);
23072 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
23073 doc
: /* Functions called before redisplay, if window sizes have changed.
23074 The value should be a list of functions that take one argument.
23075 Just before redisplay, for each frame, if any of its windows have changed
23076 size since the last redisplay, or have been split or deleted,
23077 all the functions in the list are called, with the frame as argument. */);
23078 Vwindow_size_change_functions
= Qnil
;
23080 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
23081 doc
: /* List of functions to call before redisplaying a window with scrolling.
23082 Each function is called with two arguments, the window
23083 and its new display-start position. Note that the value of `window-end'
23084 is not valid when these functions are called. */);
23085 Vwindow_scroll_functions
= Qnil
;
23087 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
23088 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
23089 mouse_autoselect_window
= 0;
23091 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
23092 doc
: /* *Non-nil means automatically resize tool-bars.
23093 This increases a tool-bar's height if not all tool-bar items are visible.
23094 It decreases a tool-bar's height when it would display blank lines
23096 auto_resize_tool_bars_p
= 1;
23098 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
23099 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
23100 auto_raise_tool_bar_buttons_p
= 1;
23102 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
23103 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
23104 make_cursor_line_fully_visible_p
= 1;
23106 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
23107 doc
: /* *Margin around tool-bar buttons in pixels.
23108 If an integer, use that for both horizontal and vertical margins.
23109 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
23110 HORZ specifying the horizontal margin, and VERT specifying the
23111 vertical margin. */);
23112 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
23114 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
23115 doc
: /* *Relief thickness of tool-bar buttons. */);
23116 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
23118 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
23119 doc
: /* List of functions to call to fontify regions of text.
23120 Each function is called with one argument POS. Functions must
23121 fontify a region starting at POS in the current buffer, and give
23122 fontified regions the property `fontified'. */);
23123 Vfontification_functions
= Qnil
;
23124 Fmake_variable_buffer_local (Qfontification_functions
);
23126 DEFVAR_BOOL ("unibyte-display-via-language-environment",
23127 &unibyte_display_via_language_environment
,
23128 doc
: /* *Non-nil means display unibyte text according to language environment.
23129 Specifically this means that unibyte non-ASCII characters
23130 are displayed by converting them to the equivalent multibyte characters
23131 according to the current language environment. As a result, they are
23132 displayed according to the current fontset. */);
23133 unibyte_display_via_language_environment
= 0;
23135 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
23136 doc
: /* *Maximum height for resizing mini-windows.
23137 If a float, it specifies a fraction of the mini-window frame's height.
23138 If an integer, it specifies a number of lines. */);
23139 Vmax_mini_window_height
= make_float (0.25);
23141 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
23142 doc
: /* *How to resize mini-windows.
23143 A value of nil means don't automatically resize mini-windows.
23144 A value of t means resize them to fit the text displayed in them.
23145 A value of `grow-only', the default, means let mini-windows grow
23146 only, until their display becomes empty, at which point the windows
23147 go back to their normal size. */);
23148 Vresize_mini_windows
= Qgrow_only
;
23150 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
23151 doc
: /* Alist specifying how to blink the cursor off.
23152 Each element has the form (ON-STATE . OFF-STATE). Whenever the
23153 `cursor-type' frame-parameter or variable equals ON-STATE,
23154 comparing using `equal', Emacs uses OFF-STATE to specify
23155 how to blink it off. */);
23156 Vblink_cursor_alist
= Qnil
;
23158 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
23159 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
23160 automatic_hscrolling_p
= 1;
23162 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
23163 doc
: /* *How many columns away from the window edge point is allowed to get
23164 before automatic hscrolling will horizontally scroll the window. */);
23165 hscroll_margin
= 5;
23167 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
23168 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
23169 When point is less than `automatic-hscroll-margin' columns from the window
23170 edge, automatic hscrolling will scroll the window by the amount of columns
23171 determined by this variable. If its value is a positive integer, scroll that
23172 many columns. If it's a positive floating-point number, it specifies the
23173 fraction of the window's width to scroll. If it's nil or zero, point will be
23174 centered horizontally after the scroll. Any other value, including negative
23175 numbers, are treated as if the value were zero.
23177 Automatic hscrolling always moves point outside the scroll margin, so if
23178 point was more than scroll step columns inside the margin, the window will
23179 scroll more than the value given by the scroll step.
23181 Note that the lower bound for automatic hscrolling specified by `scroll-left'
23182 and `scroll-right' overrides this variable's effect. */);
23183 Vhscroll_step
= make_number (0);
23185 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
23186 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
23187 Bind this around calls to `message' to let it take effect. */);
23188 message_truncate_lines
= 0;
23190 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
23191 doc
: /* Normal hook run to update the menu bar definitions.
23192 Redisplay runs this hook before it redisplays the menu bar.
23193 This is used to update submenus such as Buffers,
23194 whose contents depend on various data. */);
23195 Vmenu_bar_update_hook
= Qnil
;
23197 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
23198 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
23199 inhibit_menubar_update
= 0;
23201 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
23202 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
23203 inhibit_eval_during_redisplay
= 0;
23205 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
23206 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
23207 inhibit_free_realized_faces
= 0;
23210 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
23211 doc
: /* Inhibit try_window_id display optimization. */);
23212 inhibit_try_window_id
= 0;
23214 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
23215 doc
: /* Inhibit try_window_reusing display optimization. */);
23216 inhibit_try_window_reusing
= 0;
23218 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
23219 doc
: /* Inhibit try_cursor_movement display optimization. */);
23220 inhibit_try_cursor_movement
= 0;
23221 #endif /* GLYPH_DEBUG */
23225 /* Initialize this module when Emacs starts. */
23230 Lisp_Object root_window
;
23231 struct window
*mini_w
;
23233 current_header_line_height
= current_mode_line_height
= -1;
23235 CHARPOS (this_line_start_pos
) = 0;
23237 mini_w
= XWINDOW (minibuf_window
);
23238 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
23240 if (!noninteractive
)
23242 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
23245 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
23246 set_window_height (root_window
,
23247 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
23249 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
23250 set_window_height (minibuf_window
, 1, 0);
23252 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
23253 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
23255 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
23256 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
23257 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
23259 /* The default ellipsis glyphs `...'. */
23260 for (i
= 0; i
< 3; ++i
)
23261 default_invis_vector
[i
] = make_number ('.');
23265 /* Allocate the buffer for frame titles.
23266 Also used for `format-mode-line'. */
23268 mode_line_noprop_buf
= (char *) xmalloc (size
);
23269 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
23270 mode_line_noprop_ptr
= mode_line_noprop_buf
;
23271 mode_line_target
= MODE_LINE_DISPLAY
;
23274 help_echo_showing_p
= 0;
23278 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
23279 (do not change this comment) */