1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985,86,87,88,93,94,95,97,98,99,2000,01,02,03,04
3 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., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, 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 int minibuffer_auto_raise
;
219 extern Lisp_Object Vminibuffer_list
;
221 extern Lisp_Object Qface
;
222 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
224 extern Lisp_Object Voverriding_local_map
;
225 extern Lisp_Object Voverriding_local_map_menu_flag
;
226 extern Lisp_Object Qmenu_item
;
227 extern Lisp_Object Qwhen
;
228 extern Lisp_Object Qhelp_echo
;
230 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
231 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
232 Lisp_Object Qredisplay_end_trigger_functions
;
233 Lisp_Object Qinhibit_point_motion_hooks
;
234 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
235 Lisp_Object Qfontified
;
236 Lisp_Object Qgrow_only
;
237 Lisp_Object Qinhibit_eval_during_redisplay
;
238 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
241 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
244 Lisp_Object Qarrow
, Qhand
, Qtext
;
246 Lisp_Object Qrisky_local_variable
;
248 /* Holds the list (error). */
249 Lisp_Object list_of_error
;
251 /* Functions called to fontify regions of text. */
253 Lisp_Object Vfontification_functions
;
254 Lisp_Object Qfontification_functions
;
256 /* Non-zero means automatically select any window when the mouse
257 cursor moves into it. */
258 int mouse_autoselect_window
;
260 /* Non-zero means draw tool bar buttons raised when the mouse moves
263 int auto_raise_tool_bar_buttons_p
;
265 /* Margin around tool bar buttons in pixels. */
267 Lisp_Object Vtool_bar_button_margin
;
269 /* Thickness of shadow to draw around tool bar buttons. */
271 EMACS_INT tool_bar_button_relief
;
273 /* Non-zero means automatically resize tool-bars so that all tool-bar
274 items are visible, and no blank lines remain. */
276 int auto_resize_tool_bars_p
;
278 /* Non-zero means draw block and hollow cursor as wide as the glyph
279 under it. For example, if a block cursor is over a tab, it will be
280 drawn as wide as that tab on the display. */
282 int x_stretch_cursor_p
;
284 /* Non-nil means don't actually do any redisplay. */
286 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
288 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
290 int inhibit_eval_during_redisplay
;
292 /* Names of text properties relevant for redisplay. */
294 Lisp_Object Qdisplay
;
295 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
297 /* Symbols used in text property values. */
299 Lisp_Object Vdisplay_pixels_per_inch
;
300 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
301 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
304 Lisp_Object Qmargin
, Qpointer
;
305 Lisp_Object Qline_height
, Qtotal
;
306 extern Lisp_Object Qheight
;
307 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
308 extern Lisp_Object Qscroll_bar
;
310 /* Non-nil means highlight trailing whitespace. */
312 Lisp_Object Vshow_trailing_whitespace
;
314 #ifdef HAVE_WINDOW_SYSTEM
315 extern Lisp_Object Voverflow_newline_into_fringe
;
317 /* Test if overflow newline into fringe. Called with iterator IT
318 at or past right window margin, and with IT->current_x set. */
320 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
321 (!NILP (Voverflow_newline_into_fringe) \
322 && FRAME_WINDOW_P (it->f) \
323 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
324 && it->current_x == it->last_visible_x)
326 #endif /* HAVE_WINDOW_SYSTEM */
328 /* Non-nil means show the text cursor in void text areas
329 i.e. in blank areas after eol and eob. This used to be
330 the default in 21.3. */
332 Lisp_Object Vvoid_text_area_pointer
;
334 /* Name of the face used to highlight trailing whitespace. */
336 Lisp_Object Qtrailing_whitespace
;
338 /* The symbol `image' which is the car of the lists used to represent
343 /* The image map types. */
344 Lisp_Object QCmap
, QCpointer
;
345 Lisp_Object Qrect
, Qcircle
, Qpoly
;
347 /* Non-zero means print newline to stdout before next mini-buffer
350 int noninteractive_need_newline
;
352 /* Non-zero means print newline to message log before next message. */
354 static int message_log_need_newline
;
356 /* Three markers that message_dolog uses.
357 It could allocate them itself, but that causes trouble
358 in handling memory-full errors. */
359 static Lisp_Object message_dolog_marker1
;
360 static Lisp_Object message_dolog_marker2
;
361 static Lisp_Object message_dolog_marker3
;
363 /* The buffer position of the first character appearing entirely or
364 partially on the line of the selected window which contains the
365 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
366 redisplay optimization in redisplay_internal. */
368 static struct text_pos this_line_start_pos
;
370 /* Number of characters past the end of the line above, including the
371 terminating newline. */
373 static struct text_pos this_line_end_pos
;
375 /* The vertical positions and the height of this line. */
377 static int this_line_vpos
;
378 static int this_line_y
;
379 static int this_line_pixel_height
;
381 /* X position at which this display line starts. Usually zero;
382 negative if first character is partially visible. */
384 static int this_line_start_x
;
386 /* Buffer that this_line_.* variables are referring to. */
388 static struct buffer
*this_line_buffer
;
390 /* Nonzero means truncate lines in all windows less wide than the
393 int truncate_partial_width_windows
;
395 /* A flag to control how to display unibyte 8-bit character. */
397 int unibyte_display_via_language_environment
;
399 /* Nonzero means we have more than one non-mini-buffer-only frame.
400 Not guaranteed to be accurate except while parsing
401 frame-title-format. */
405 Lisp_Object Vglobal_mode_string
;
408 /* List of variables (symbols) which hold markers for overlay arrows.
409 The symbols on this list are examined during redisplay to determine
410 where to display overlay arrows. */
412 Lisp_Object Voverlay_arrow_variable_list
;
414 /* Marker for where to display an arrow on top of the buffer text. */
416 Lisp_Object Voverlay_arrow_position
;
418 /* String to display for the arrow. Only used on terminal frames. */
420 Lisp_Object Voverlay_arrow_string
;
422 /* Values of those variables at last redisplay are stored as
423 properties on `overlay-arrow-position' symbol. However, if
424 Voverlay_arrow_position is a marker, last-arrow-position is its
425 numerical position. */
427 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
429 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
430 properties on a symbol in overlay-arrow-variable-list. */
432 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
434 /* Like mode-line-format, but for the title bar on a visible frame. */
436 Lisp_Object Vframe_title_format
;
438 /* Like mode-line-format, but for the title bar on an iconified frame. */
440 Lisp_Object Vicon_title_format
;
442 /* List of functions to call when a window's size changes. These
443 functions get one arg, a frame on which one or more windows' sizes
446 static Lisp_Object Vwindow_size_change_functions
;
448 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
450 /* Nonzero if overlay arrow has been displayed once in this window. */
452 static int overlay_arrow_seen
;
454 /* Nonzero means highlight the region even in nonselected windows. */
456 int highlight_nonselected_windows
;
458 /* If cursor motion alone moves point off frame, try scrolling this
459 many lines up or down if that will bring it back. */
461 static EMACS_INT scroll_step
;
463 /* Nonzero means scroll just far enough to bring point back on the
464 screen, when appropriate. */
466 static EMACS_INT scroll_conservatively
;
468 /* Recenter the window whenever point gets within this many lines of
469 the top or bottom of the window. This value is translated into a
470 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
471 that there is really a fixed pixel height scroll margin. */
473 EMACS_INT scroll_margin
;
475 /* Number of windows showing the buffer of the selected window (or
476 another buffer with the same base buffer). keyboard.c refers to
481 /* Vector containing glyphs for an ellipsis `...'. */
483 static Lisp_Object default_invis_vector
[3];
485 /* Zero means display the mode-line/header-line/menu-bar in the default face
486 (this slightly odd definition is for compatibility with previous versions
487 of emacs), non-zero means display them using their respective faces.
489 This variable is deprecated. */
491 int mode_line_inverse_video
;
493 /* Prompt to display in front of the mini-buffer contents. */
495 Lisp_Object minibuf_prompt
;
497 /* Width of current mini-buffer prompt. Only set after display_line
498 of the line that contains the prompt. */
500 int minibuf_prompt_width
;
502 /* This is the window where the echo area message was displayed. It
503 is always a mini-buffer window, but it may not be the same window
504 currently active as a mini-buffer. */
506 Lisp_Object echo_area_window
;
508 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
509 pushes the current message and the value of
510 message_enable_multibyte on the stack, the function restore_message
511 pops the stack and displays MESSAGE again. */
513 Lisp_Object Vmessage_stack
;
515 /* Nonzero means multibyte characters were enabled when the echo area
516 message was specified. */
518 int message_enable_multibyte
;
520 /* Nonzero if we should redraw the mode lines on the next redisplay. */
522 int update_mode_lines
;
524 /* Nonzero if window sizes or contents have changed since last
525 redisplay that finished. */
527 int windows_or_buffers_changed
;
529 /* Nonzero means a frame's cursor type has been changed. */
531 int cursor_type_changed
;
533 /* Nonzero after display_mode_line if %l was used and it displayed a
536 int line_number_displayed
;
538 /* Maximum buffer size for which to display line numbers. */
540 Lisp_Object Vline_number_display_limit
;
542 /* Line width to consider when repositioning for line number display. */
544 static EMACS_INT line_number_display_limit_width
;
546 /* Number of lines to keep in the message log buffer. t means
547 infinite. nil means don't log at all. */
549 Lisp_Object Vmessage_log_max
;
551 /* The name of the *Messages* buffer, a string. */
553 static Lisp_Object Vmessages_buffer_name
;
555 /* Current, index 0, and last displayed echo area message. Either
556 buffers from echo_buffers, or nil to indicate no message. */
558 Lisp_Object echo_area_buffer
[2];
560 /* The buffers referenced from echo_area_buffer. */
562 static Lisp_Object echo_buffer
[2];
564 /* A vector saved used in with_area_buffer to reduce consing. */
566 static Lisp_Object Vwith_echo_area_save_vector
;
568 /* Non-zero means display_echo_area should display the last echo area
569 message again. Set by redisplay_preserve_echo_area. */
571 static int display_last_displayed_message_p
;
573 /* Nonzero if echo area is being used by print; zero if being used by
576 int message_buf_print
;
578 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
580 Lisp_Object Qinhibit_menubar_update
;
581 int inhibit_menubar_update
;
583 /* Maximum height for resizing mini-windows. Either a float
584 specifying a fraction of the available height, or an integer
585 specifying a number of lines. */
587 Lisp_Object Vmax_mini_window_height
;
589 /* Non-zero means messages should be displayed with truncated
590 lines instead of being continued. */
592 int message_truncate_lines
;
593 Lisp_Object Qmessage_truncate_lines
;
595 /* Set to 1 in clear_message to make redisplay_internal aware
596 of an emptied echo area. */
598 static int message_cleared_p
;
600 /* Non-zero means we want a hollow cursor in windows that are not
601 selected. Zero means there's no cursor in such windows. */
603 Lisp_Object Vcursor_in_non_selected_windows
;
604 Lisp_Object Qcursor_in_non_selected_windows
;
606 /* How to blink the default frame cursor off. */
607 Lisp_Object Vblink_cursor_alist
;
609 /* A scratch glyph row with contents used for generating truncation
610 glyphs. Also used in direct_output_for_insert. */
612 #define MAX_SCRATCH_GLYPHS 100
613 struct glyph_row scratch_glyph_row
;
614 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
616 /* Ascent and height of the last line processed by move_it_to. */
618 static int last_max_ascent
, last_height
;
620 /* Non-zero if there's a help-echo in the echo area. */
622 int help_echo_showing_p
;
624 /* If >= 0, computed, exact values of mode-line and header-line height
625 to use in the macros CURRENT_MODE_LINE_HEIGHT and
626 CURRENT_HEADER_LINE_HEIGHT. */
628 int current_mode_line_height
, current_header_line_height
;
630 /* The maximum distance to look ahead for text properties. Values
631 that are too small let us call compute_char_face and similar
632 functions too often which is expensive. Values that are too large
633 let us call compute_char_face and alike too often because we
634 might not be interested in text properties that far away. */
636 #define TEXT_PROP_DISTANCE_LIMIT 100
640 /* Variables to turn off display optimizations from Lisp. */
642 int inhibit_try_window_id
, inhibit_try_window_reusing
;
643 int inhibit_try_cursor_movement
;
645 /* Non-zero means print traces of redisplay if compiled with
648 int trace_redisplay_p
;
650 #endif /* GLYPH_DEBUG */
652 #ifdef DEBUG_TRACE_MOVE
653 /* Non-zero means trace with TRACE_MOVE to stderr. */
656 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
658 #define TRACE_MOVE(x) (void) 0
661 /* Non-zero means automatically scroll windows horizontally to make
664 int automatic_hscrolling_p
;
666 /* How close to the margin can point get before the window is scrolled
668 EMACS_INT hscroll_margin
;
670 /* How much to scroll horizontally when point is inside the above margin. */
671 Lisp_Object Vhscroll_step
;
673 /* A list of symbols, one for each supported image type. */
675 Lisp_Object Vimage_types
;
677 /* The variable `resize-mini-windows'. If nil, don't resize
678 mini-windows. If t, always resize them to fit the text they
679 display. If `grow-only', let mini-windows grow only until they
682 Lisp_Object Vresize_mini_windows
;
684 /* Buffer being redisplayed -- for redisplay_window_error. */
686 struct buffer
*displayed_buffer
;
688 /* Value returned from text property handlers (see below). */
693 HANDLED_RECOMPUTE_PROPS
,
694 HANDLED_OVERLAY_STRING_CONSUMED
,
698 /* A description of text properties that redisplay is interested
703 /* The name of the property. */
706 /* A unique index for the property. */
709 /* A handler function called to set up iterator IT from the property
710 at IT's current position. Value is used to steer handle_stop. */
711 enum prop_handled (*handler
) P_ ((struct it
*it
));
714 static enum prop_handled handle_face_prop
P_ ((struct it
*));
715 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
716 static enum prop_handled handle_display_prop
P_ ((struct it
*));
717 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
718 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
719 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
721 /* Properties handled by iterators. */
723 static struct props it_props
[] =
725 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
726 /* Handle `face' before `display' because some sub-properties of
727 `display' need to know the face. */
728 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
729 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
730 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
731 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
735 /* Value is the position described by X. If X is a marker, value is
736 the marker_position of X. Otherwise, value is X. */
738 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
740 /* Enumeration returned by some move_it_.* functions internally. */
744 /* Not used. Undefined value. */
747 /* Move ended at the requested buffer position or ZV. */
748 MOVE_POS_MATCH_OR_ZV
,
750 /* Move ended at the requested X pixel position. */
753 /* Move within a line ended at the end of a line that must be
757 /* Move within a line ended at the end of a line that would
758 be displayed truncated. */
761 /* Move within a line ended at a line end. */
765 /* This counter is used to clear the face cache every once in a while
766 in redisplay_internal. It is incremented for each redisplay.
767 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
770 #define CLEAR_FACE_CACHE_COUNT 500
771 static int clear_face_cache_count
;
773 /* Record the previous terminal frame we displayed. */
775 static struct frame
*previous_terminal_frame
;
777 /* Non-zero while redisplay_internal is in progress. */
781 /* Non-zero means don't free realized faces. Bound while freeing
782 realized faces is dangerous because glyph matrices might still
785 int inhibit_free_realized_faces
;
786 Lisp_Object Qinhibit_free_realized_faces
;
788 /* If a string, XTread_socket generates an event to display that string.
789 (The display is done in read_char.) */
791 Lisp_Object help_echo_string
;
792 Lisp_Object help_echo_window
;
793 Lisp_Object help_echo_object
;
796 /* Temporary variable for XTread_socket. */
798 Lisp_Object previous_help_echo_string
;
800 /* Null glyph slice */
802 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
805 /* Function prototypes. */
807 static void setup_for_ellipsis
P_ ((struct it
*));
808 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
809 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
810 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
811 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
812 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
813 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
816 static int invisible_text_between_p
P_ ((struct it
*, int, int));
819 static int next_element_from_ellipsis
P_ ((struct it
*));
820 static void pint2str
P_ ((char *, int, int));
821 static void pint2hrstr
P_ ((char *, int, int));
822 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
824 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
825 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
826 static void store_frame_title_char
P_ ((char));
827 static int store_frame_title
P_ ((const unsigned char *, int, int));
828 static void x_consider_frame_title
P_ ((Lisp_Object
));
829 static void handle_stop
P_ ((struct it
*));
830 static int tool_bar_lines_needed
P_ ((struct frame
*));
831 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
832 static void ensure_echo_area_buffers
P_ ((void));
833 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
834 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
835 static int with_echo_area_buffer
P_ ((struct window
*, int,
836 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
837 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
838 static void clear_garbaged_frames
P_ ((void));
839 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
840 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
841 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
842 static int display_echo_area
P_ ((struct window
*));
843 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
844 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
845 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
846 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
847 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
849 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
850 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
851 static void insert_left_trunc_glyphs
P_ ((struct it
*));
852 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
854 static void extend_face_to_end_of_line
P_ ((struct it
*));
855 static int append_space_for_newline
P_ ((struct it
*, int));
856 static int make_cursor_line_fully_visible
P_ ((struct window
*, int));
857 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
858 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
859 static int trailing_whitespace_p
P_ ((int));
860 static int message_log_check_duplicate
P_ ((int, int, int, int));
861 static void push_it
P_ ((struct it
*));
862 static void pop_it
P_ ((struct it
*));
863 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
864 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
865 static void redisplay_internal
P_ ((int));
866 static int echo_area_display
P_ ((int));
867 static void redisplay_windows
P_ ((Lisp_Object
));
868 static void redisplay_window
P_ ((Lisp_Object
, int));
869 static Lisp_Object
redisplay_window_error ();
870 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
871 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
872 static void update_menu_bar
P_ ((struct frame
*, int));
873 static int try_window_reusing_current_matrix
P_ ((struct window
*));
874 static int try_window_id
P_ ((struct window
*));
875 static int display_line
P_ ((struct it
*));
876 static int display_mode_lines
P_ ((struct window
*));
877 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
878 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
879 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
880 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
881 static void display_menu_bar
P_ ((struct window
*));
882 static int display_count_lines
P_ ((int, int, int, int, int *));
883 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
884 int, int, struct it
*, int, int, int, int));
885 static void compute_line_metrics
P_ ((struct it
*));
886 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
887 static int get_overlay_strings
P_ ((struct it
*, int));
888 static void next_overlay_string
P_ ((struct it
*));
889 static void reseat
P_ ((struct it
*, struct text_pos
, int));
890 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
891 static void back_to_previous_visible_line_start
P_ ((struct it
*));
892 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
893 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
894 static int next_element_from_display_vector
P_ ((struct it
*));
895 static int next_element_from_string
P_ ((struct it
*));
896 static int next_element_from_c_string
P_ ((struct it
*));
897 static int next_element_from_buffer
P_ ((struct it
*));
898 static int next_element_from_composition
P_ ((struct it
*));
899 static int next_element_from_image
P_ ((struct it
*));
900 static int next_element_from_stretch
P_ ((struct it
*));
901 static void load_overlay_strings
P_ ((struct it
*, int));
902 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
903 struct display_pos
*));
904 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
905 Lisp_Object
, int, int, int, int));
906 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
908 void move_it_vertically_backward
P_ ((struct it
*, int));
909 static void init_to_row_start
P_ ((struct it
*, struct window
*,
910 struct glyph_row
*));
911 static int init_to_row_end
P_ ((struct it
*, struct window
*,
912 struct glyph_row
*));
913 static void back_to_previous_line_start
P_ ((struct it
*));
914 static int forward_to_next_line_start
P_ ((struct it
*, int *));
915 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
917 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
918 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
919 static int number_of_chars
P_ ((unsigned char *, int));
920 static void compute_stop_pos
P_ ((struct it
*));
921 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
923 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
924 static int next_overlay_change
P_ ((int));
925 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
926 Lisp_Object
, struct text_pos
*,
928 static int underlying_face_id
P_ ((struct it
*));
929 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
932 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
933 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
935 #ifdef HAVE_WINDOW_SYSTEM
937 static void update_tool_bar
P_ ((struct frame
*, int));
938 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
939 static int redisplay_tool_bar
P_ ((struct frame
*));
940 static void display_tool_bar_line
P_ ((struct it
*));
941 static void notice_overwritten_cursor
P_ ((struct window
*,
943 int, int, int, int));
947 #endif /* HAVE_WINDOW_SYSTEM */
950 /***********************************************************************
951 Window display dimensions
952 ***********************************************************************/
954 /* Return the bottom boundary y-position for text lines in window W.
955 This is the first y position at which a line cannot start.
956 It is relative to the top of the window.
958 This is the height of W minus the height of a mode line, if any. */
961 window_text_bottom_y (w
)
964 int height
= WINDOW_TOTAL_HEIGHT (w
);
966 if (WINDOW_WANTS_MODELINE_P (w
))
967 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
971 /* Return the pixel width of display area AREA of window W. AREA < 0
972 means return the total width of W, not including fringes to
973 the left and right of the window. */
976 window_box_width (w
, area
)
980 int cols
= XFASTINT (w
->total_cols
);
983 if (!w
->pseudo_window_p
)
985 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
987 if (area
== TEXT_AREA
)
989 if (INTEGERP (w
->left_margin_cols
))
990 cols
-= XFASTINT (w
->left_margin_cols
);
991 if (INTEGERP (w
->right_margin_cols
))
992 cols
-= XFASTINT (w
->right_margin_cols
);
993 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
995 else if (area
== LEFT_MARGIN_AREA
)
997 cols
= (INTEGERP (w
->left_margin_cols
)
998 ? XFASTINT (w
->left_margin_cols
) : 0);
1001 else if (area
== RIGHT_MARGIN_AREA
)
1003 cols
= (INTEGERP (w
->right_margin_cols
)
1004 ? XFASTINT (w
->right_margin_cols
) : 0);
1009 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1013 /* Return the pixel height of the display area of window W, not
1014 including mode lines of W, if any. */
1017 window_box_height (w
)
1020 struct frame
*f
= XFRAME (w
->frame
);
1021 int height
= WINDOW_TOTAL_HEIGHT (w
);
1023 xassert (height
>= 0);
1025 /* Note: the code below that determines the mode-line/header-line
1026 height is essentially the same as that contained in the macro
1027 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1028 the appropriate glyph row has its `mode_line_p' flag set,
1029 and if it doesn't, uses estimate_mode_line_height instead. */
1031 if (WINDOW_WANTS_MODELINE_P (w
))
1033 struct glyph_row
*ml_row
1034 = (w
->current_matrix
&& w
->current_matrix
->rows
1035 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1037 if (ml_row
&& ml_row
->mode_line_p
)
1038 height
-= ml_row
->height
;
1040 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1043 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1045 struct glyph_row
*hl_row
1046 = (w
->current_matrix
&& w
->current_matrix
->rows
1047 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1049 if (hl_row
&& hl_row
->mode_line_p
)
1050 height
-= hl_row
->height
;
1052 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1055 /* With a very small font and a mode-line that's taller than
1056 default, we might end up with a negative height. */
1057 return max (0, height
);
1060 /* Return the window-relative coordinate of the left edge of display
1061 area AREA of window W. AREA < 0 means return the left edge of the
1062 whole window, to the right of the left fringe of W. */
1065 window_box_left_offset (w
, area
)
1071 if (w
->pseudo_window_p
)
1074 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1076 if (area
== TEXT_AREA
)
1077 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1078 + window_box_width (w
, LEFT_MARGIN_AREA
));
1079 else if (area
== RIGHT_MARGIN_AREA
)
1080 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1081 + window_box_width (w
, LEFT_MARGIN_AREA
)
1082 + window_box_width (w
, TEXT_AREA
)
1083 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1085 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1086 else if (area
== LEFT_MARGIN_AREA
1087 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1088 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1094 /* Return the window-relative coordinate of the right edge of display
1095 area AREA of window W. AREA < 0 means return the left edge of the
1096 whole window, to the left of the right fringe of W. */
1099 window_box_right_offset (w
, area
)
1103 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1106 /* Return the frame-relative coordinate of the left edge of display
1107 area AREA of window W. AREA < 0 means return the left edge of the
1108 whole window, to the right of the left fringe of W. */
1111 window_box_left (w
, area
)
1115 struct frame
*f
= XFRAME (w
->frame
);
1118 if (w
->pseudo_window_p
)
1119 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1121 x
= (WINDOW_LEFT_EDGE_X (w
)
1122 + window_box_left_offset (w
, area
));
1128 /* Return the frame-relative coordinate of the right edge of display
1129 area AREA of window W. AREA < 0 means return the left edge of the
1130 whole window, to the left of the right fringe of W. */
1133 window_box_right (w
, area
)
1137 return window_box_left (w
, area
) + window_box_width (w
, area
);
1140 /* Get the bounding box of the display area AREA of window W, without
1141 mode lines, in frame-relative coordinates. AREA < 0 means the
1142 whole window, not including the left and right fringes of
1143 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1144 coordinates of the upper-left corner of the box. Return in
1145 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1148 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1151 int *box_x
, *box_y
, *box_width
, *box_height
;
1154 *box_width
= window_box_width (w
, area
);
1156 *box_height
= window_box_height (w
);
1158 *box_x
= window_box_left (w
, area
);
1161 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1162 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1163 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1168 /* Get the bounding box of the display area AREA of window W, without
1169 mode lines. AREA < 0 means the whole window, not including the
1170 left and right fringe of the window. Return in *TOP_LEFT_X
1171 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1172 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1173 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1177 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1178 bottom_right_x
, bottom_right_y
)
1181 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1183 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1185 *bottom_right_x
+= *top_left_x
;
1186 *bottom_right_y
+= *top_left_y
;
1191 /***********************************************************************
1193 ***********************************************************************/
1195 /* Return the bottom y-position of the line the iterator IT is in.
1196 This can modify IT's settings. */
1202 int line_height
= it
->max_ascent
+ it
->max_descent
;
1203 int line_top_y
= it
->current_y
;
1205 if (line_height
== 0)
1208 line_height
= last_height
;
1209 else if (IT_CHARPOS (*it
) < ZV
)
1211 move_it_by_lines (it
, 1, 1);
1212 line_height
= (it
->max_ascent
|| it
->max_descent
1213 ? it
->max_ascent
+ it
->max_descent
1218 struct glyph_row
*row
= it
->glyph_row
;
1220 /* Use the default character height. */
1221 it
->glyph_row
= NULL
;
1222 it
->what
= IT_CHARACTER
;
1225 PRODUCE_GLYPHS (it
);
1226 line_height
= it
->ascent
+ it
->descent
;
1227 it
->glyph_row
= row
;
1231 return line_top_y
+ line_height
;
1235 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1236 1 if POS is visible and the line containing POS is fully visible.
1237 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1238 and header-lines heights. */
1241 pos_visible_p (w
, charpos
, fully
, x
, y
, exact_mode_line_heights_p
)
1243 int charpos
, *fully
, *x
, *y
, exact_mode_line_heights_p
;
1246 struct text_pos top
;
1248 struct buffer
*old_buffer
= NULL
;
1250 if (XBUFFER (w
->buffer
) != current_buffer
)
1252 old_buffer
= current_buffer
;
1253 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1256 *fully
= visible_p
= 0;
1257 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1259 /* Compute exact mode line heights, if requested. */
1260 if (exact_mode_line_heights_p
)
1262 if (WINDOW_WANTS_MODELINE_P (w
))
1263 current_mode_line_height
1264 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1265 current_buffer
->mode_line_format
);
1267 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1268 current_header_line_height
1269 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1270 current_buffer
->header_line_format
);
1273 start_display (&it
, w
, top
);
1274 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1275 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1277 /* Note that we may overshoot because of invisible text. */
1278 if (IT_CHARPOS (it
) >= charpos
)
1280 int top_y
= it
.current_y
;
1281 int bottom_y
= line_bottom_y (&it
);
1282 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1284 if (top_y
< window_top_y
)
1285 visible_p
= bottom_y
> window_top_y
;
1286 else if (top_y
< it
.last_visible_y
)
1289 *fully
= bottom_y
<= it
.last_visible_y
;
1294 *y
= max (top_y
+ it
.max_ascent
- it
.ascent
, window_top_y
);
1297 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1302 move_it_by_lines (&it
, 1, 0);
1303 if (charpos
< IT_CHARPOS (it
))
1308 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1310 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1316 set_buffer_internal_1 (old_buffer
);
1318 current_header_line_height
= current_mode_line_height
= -1;
1324 /* Return the next character from STR which is MAXLEN bytes long.
1325 Return in *LEN the length of the character. This is like
1326 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1327 we find one, we return a `?', but with the length of the invalid
1331 string_char_and_length (str
, maxlen
, len
)
1332 const unsigned char *str
;
1337 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1338 if (!CHAR_VALID_P (c
, 1))
1339 /* We may not change the length here because other places in Emacs
1340 don't use this function, i.e. they silently accept invalid
1349 /* Given a position POS containing a valid character and byte position
1350 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1352 static struct text_pos
1353 string_pos_nchars_ahead (pos
, string
, nchars
)
1354 struct text_pos pos
;
1358 xassert (STRINGP (string
) && nchars
>= 0);
1360 if (STRING_MULTIBYTE (string
))
1362 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1363 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1368 string_char_and_length (p
, rest
, &len
);
1369 p
+= len
, rest
-= len
;
1370 xassert (rest
>= 0);
1372 BYTEPOS (pos
) += len
;
1376 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1382 /* Value is the text position, i.e. character and byte position,
1383 for character position CHARPOS in STRING. */
1385 static INLINE
struct text_pos
1386 string_pos (charpos
, string
)
1390 struct text_pos pos
;
1391 xassert (STRINGP (string
));
1392 xassert (charpos
>= 0);
1393 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1398 /* Value is a text position, i.e. character and byte position, for
1399 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1400 means recognize multibyte characters. */
1402 static struct text_pos
1403 c_string_pos (charpos
, s
, multibyte_p
)
1408 struct text_pos pos
;
1410 xassert (s
!= NULL
);
1411 xassert (charpos
>= 0);
1415 int rest
= strlen (s
), len
;
1417 SET_TEXT_POS (pos
, 0, 0);
1420 string_char_and_length (s
, rest
, &len
);
1421 s
+= len
, rest
-= len
;
1422 xassert (rest
>= 0);
1424 BYTEPOS (pos
) += len
;
1428 SET_TEXT_POS (pos
, charpos
, charpos
);
1434 /* Value is the number of characters in C string S. MULTIBYTE_P
1435 non-zero means recognize multibyte characters. */
1438 number_of_chars (s
, multibyte_p
)
1446 int rest
= strlen (s
), len
;
1447 unsigned char *p
= (unsigned char *) s
;
1449 for (nchars
= 0; rest
> 0; ++nchars
)
1451 string_char_and_length (p
, rest
, &len
);
1452 rest
-= len
, p
+= len
;
1456 nchars
= strlen (s
);
1462 /* Compute byte position NEWPOS->bytepos corresponding to
1463 NEWPOS->charpos. POS is a known position in string STRING.
1464 NEWPOS->charpos must be >= POS.charpos. */
1467 compute_string_pos (newpos
, pos
, string
)
1468 struct text_pos
*newpos
, pos
;
1471 xassert (STRINGP (string
));
1472 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1474 if (STRING_MULTIBYTE (string
))
1475 *newpos
= string_pos_nchars_ahead (pos
, string
,
1476 CHARPOS (*newpos
) - CHARPOS (pos
));
1478 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1482 Return an estimation of the pixel height of mode or top lines on
1483 frame F. FACE_ID specifies what line's height to estimate. */
1486 estimate_mode_line_height (f
, face_id
)
1488 enum face_id face_id
;
1490 #ifdef HAVE_WINDOW_SYSTEM
1491 if (FRAME_WINDOW_P (f
))
1493 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1495 /* This function is called so early when Emacs starts that the face
1496 cache and mode line face are not yet initialized. */
1497 if (FRAME_FACE_CACHE (f
))
1499 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1503 height
= FONT_HEIGHT (face
->font
);
1504 if (face
->box_line_width
> 0)
1505 height
+= 2 * face
->box_line_width
;
1516 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1517 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1518 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1519 not force the value into range. */
1522 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1524 register int pix_x
, pix_y
;
1526 NativeRectangle
*bounds
;
1530 #ifdef HAVE_WINDOW_SYSTEM
1531 if (FRAME_WINDOW_P (f
))
1533 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1534 even for negative values. */
1536 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1538 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1540 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1541 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1544 STORE_NATIVE_RECT (*bounds
,
1545 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1546 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1547 FRAME_COLUMN_WIDTH (f
) - 1,
1548 FRAME_LINE_HEIGHT (f
) - 1);
1554 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1555 pix_x
= FRAME_TOTAL_COLS (f
);
1559 else if (pix_y
> FRAME_LINES (f
))
1560 pix_y
= FRAME_LINES (f
);
1570 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1571 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1572 can't tell the positions because W's display is not up to date,
1576 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1579 int *frame_x
, *frame_y
;
1581 #ifdef HAVE_WINDOW_SYSTEM
1582 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1586 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1587 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1589 if (display_completed
)
1591 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1592 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1593 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1599 hpos
+= glyph
->pixel_width
;
1603 /* If first glyph is partially visible, its first visible position is still 0. */
1615 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1616 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1627 #ifdef HAVE_WINDOW_SYSTEM
1629 /* Find the glyph under window-relative coordinates X/Y in window W.
1630 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1631 strings. Return in *HPOS and *VPOS the row and column number of
1632 the glyph found. Return in *AREA the glyph area containing X.
1633 Value is a pointer to the glyph found or null if X/Y is not on
1634 text, or we can't tell because W's current matrix is not up to
1637 static struct glyph
*
1638 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1641 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1643 struct glyph
*glyph
, *end
;
1644 struct glyph_row
*row
= NULL
;
1647 /* Find row containing Y. Give up if some row is not enabled. */
1648 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1650 row
= MATRIX_ROW (w
->current_matrix
, i
);
1651 if (!row
->enabled_p
)
1653 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1660 /* Give up if Y is not in the window. */
1661 if (i
== w
->current_matrix
->nrows
)
1664 /* Get the glyph area containing X. */
1665 if (w
->pseudo_window_p
)
1672 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1674 *area
= LEFT_MARGIN_AREA
;
1675 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1677 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1680 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1684 *area
= RIGHT_MARGIN_AREA
;
1685 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1689 /* Find glyph containing X. */
1690 glyph
= row
->glyphs
[*area
];
1691 end
= glyph
+ row
->used
[*area
];
1693 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1695 x
-= glyph
->pixel_width
;
1705 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1708 *hpos
= glyph
- row
->glyphs
[*area
];
1714 Convert frame-relative x/y to coordinates relative to window W.
1715 Takes pseudo-windows into account. */
1718 frame_to_window_pixel_xy (w
, x
, y
)
1722 if (w
->pseudo_window_p
)
1724 /* A pseudo-window is always full-width, and starts at the
1725 left edge of the frame, plus a frame border. */
1726 struct frame
*f
= XFRAME (w
->frame
);
1727 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1728 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1732 *x
-= WINDOW_LEFT_EDGE_X (w
);
1733 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1738 Return in *R the clipping rectangle for glyph string S. */
1741 get_glyph_string_clip_rect (s
, nr
)
1742 struct glyph_string
*s
;
1743 NativeRectangle
*nr
;
1747 if (s
->row
->full_width_p
)
1749 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1750 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1751 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1753 /* Unless displaying a mode or menu bar line, which are always
1754 fully visible, clip to the visible part of the row. */
1755 if (s
->w
->pseudo_window_p
)
1756 r
.height
= s
->row
->visible_height
;
1758 r
.height
= s
->height
;
1762 /* This is a text line that may be partially visible. */
1763 r
.x
= window_box_left (s
->w
, s
->area
);
1764 r
.width
= window_box_width (s
->w
, s
->area
);
1765 r
.height
= s
->row
->visible_height
;
1768 /* If S draws overlapping rows, it's sufficient to use the top and
1769 bottom of the window for clipping because this glyph string
1770 intentionally draws over other lines. */
1771 if (s
->for_overlaps_p
)
1773 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1774 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1778 /* Don't use S->y for clipping because it doesn't take partially
1779 visible lines into account. For example, it can be negative for
1780 partially visible lines at the top of a window. */
1781 if (!s
->row
->full_width_p
1782 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1783 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1785 r
.y
= max (0, s
->row
->y
);
1787 /* If drawing a tool-bar window, draw it over the internal border
1788 at the top of the window. */
1789 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1790 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1793 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1795 /* If drawing the cursor, don't let glyph draw outside its
1796 advertised boundaries. Cleartype does this under some circumstances. */
1797 if (s
->hl
== DRAW_CURSOR
)
1799 struct glyph
*glyph
= s
->first_glyph
;
1804 r
.width
-= s
->x
- r
.x
;
1807 r
.width
= min (r
.width
, glyph
->pixel_width
);
1809 /* Don't draw cursor glyph taller than our actual glyph. */
1810 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1811 if (height
< r
.height
)
1813 int max_y
= r
.y
+ r
.height
;
1814 r
.y
= min (max_y
, s
->ybase
+ glyph
->descent
- height
);
1815 r
.height
= min (max_y
- r
.y
, height
);
1819 #ifdef CONVERT_FROM_XRECT
1820 CONVERT_FROM_XRECT (r
, *nr
);
1826 #endif /* HAVE_WINDOW_SYSTEM */
1829 /***********************************************************************
1830 Lisp form evaluation
1831 ***********************************************************************/
1833 /* Error handler for safe_eval and safe_call. */
1836 safe_eval_handler (arg
)
1839 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1844 /* Evaluate SEXPR and return the result, or nil if something went
1845 wrong. Prevent redisplay during the evaluation. */
1853 if (inhibit_eval_during_redisplay
)
1857 int count
= SPECPDL_INDEX ();
1858 struct gcpro gcpro1
;
1861 specbind (Qinhibit_redisplay
, Qt
);
1862 /* Use Qt to ensure debugger does not run,
1863 so there is no possibility of wanting to redisplay. */
1864 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1867 val
= unbind_to (count
, val
);
1874 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1875 Return the result, or nil if something went wrong. Prevent
1876 redisplay during the evaluation. */
1879 safe_call (nargs
, args
)
1885 if (inhibit_eval_during_redisplay
)
1889 int count
= SPECPDL_INDEX ();
1890 struct gcpro gcpro1
;
1893 gcpro1
.nvars
= nargs
;
1894 specbind (Qinhibit_redisplay
, Qt
);
1895 /* Use Qt to ensure debugger does not run,
1896 so there is no possibility of wanting to redisplay. */
1897 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
1900 val
= unbind_to (count
, val
);
1907 /* Call function FN with one argument ARG.
1908 Return the result, or nil if something went wrong. */
1911 safe_call1 (fn
, arg
)
1912 Lisp_Object fn
, arg
;
1914 Lisp_Object args
[2];
1917 return safe_call (2, args
);
1922 /***********************************************************************
1924 ***********************************************************************/
1928 /* Define CHECK_IT to perform sanity checks on iterators.
1929 This is for debugging. It is too slow to do unconditionally. */
1935 if (it
->method
== next_element_from_string
)
1937 xassert (STRINGP (it
->string
));
1938 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1942 xassert (IT_STRING_CHARPOS (*it
) < 0);
1943 if (it
->method
== next_element_from_buffer
)
1945 /* Check that character and byte positions agree. */
1946 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1951 xassert (it
->current
.dpvec_index
>= 0);
1953 xassert (it
->current
.dpvec_index
< 0);
1956 #define CHECK_IT(IT) check_it ((IT))
1960 #define CHECK_IT(IT) (void) 0
1967 /* Check that the window end of window W is what we expect it
1968 to be---the last row in the current matrix displaying text. */
1971 check_window_end (w
)
1974 if (!MINI_WINDOW_P (w
)
1975 && !NILP (w
->window_end_valid
))
1977 struct glyph_row
*row
;
1978 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1979 XFASTINT (w
->window_end_vpos
)),
1981 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1982 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1986 #define CHECK_WINDOW_END(W) check_window_end ((W))
1988 #else /* not GLYPH_DEBUG */
1990 #define CHECK_WINDOW_END(W) (void) 0
1992 #endif /* not GLYPH_DEBUG */
1996 /***********************************************************************
1997 Iterator initialization
1998 ***********************************************************************/
2000 /* Initialize IT for displaying current_buffer in window W, starting
2001 at character position CHARPOS. CHARPOS < 0 means that no buffer
2002 position is specified which is useful when the iterator is assigned
2003 a position later. BYTEPOS is the byte position corresponding to
2004 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2006 If ROW is not null, calls to produce_glyphs with IT as parameter
2007 will produce glyphs in that row.
2009 BASE_FACE_ID is the id of a base face to use. It must be one of
2010 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2011 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2012 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2014 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2015 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2016 will be initialized to use the corresponding mode line glyph row of
2017 the desired matrix of W. */
2020 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2023 int charpos
, bytepos
;
2024 struct glyph_row
*row
;
2025 enum face_id base_face_id
;
2027 int highlight_region_p
;
2029 /* Some precondition checks. */
2030 xassert (w
!= NULL
&& it
!= NULL
);
2031 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2034 /* If face attributes have been changed since the last redisplay,
2035 free realized faces now because they depend on face definitions
2036 that might have changed. Don't free faces while there might be
2037 desired matrices pending which reference these faces. */
2038 if (face_change_count
&& !inhibit_free_realized_faces
)
2040 face_change_count
= 0;
2041 free_all_realized_faces (Qnil
);
2044 /* Use one of the mode line rows of W's desired matrix if
2048 if (base_face_id
== MODE_LINE_FACE_ID
2049 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2050 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2051 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2052 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2056 bzero (it
, sizeof *it
);
2057 it
->current
.overlay_string_index
= -1;
2058 it
->current
.dpvec_index
= -1;
2059 it
->base_face_id
= base_face_id
;
2061 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2063 /* The window in which we iterate over current_buffer: */
2064 XSETWINDOW (it
->window
, w
);
2066 it
->f
= XFRAME (w
->frame
);
2068 /* Extra space between lines (on window systems only). */
2069 if (base_face_id
== DEFAULT_FACE_ID
2070 && FRAME_WINDOW_P (it
->f
))
2072 if (NATNUMP (current_buffer
->extra_line_spacing
))
2073 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2074 else if (FLOATP (current_buffer
->extra_line_spacing
))
2075 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2076 * FRAME_LINE_HEIGHT (it
->f
));
2077 else if (it
->f
->extra_line_spacing
> 0)
2078 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2081 /* If realized faces have been removed, e.g. because of face
2082 attribute changes of named faces, recompute them. When running
2083 in batch mode, the face cache of Vterminal_frame is null. If
2084 we happen to get called, make a dummy face cache. */
2085 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2086 init_frame_faces (it
->f
);
2087 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2088 recompute_basic_faces (it
->f
);
2090 /* Current value of the `slice', `space-width', and 'height' properties. */
2091 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2092 it
->space_width
= Qnil
;
2093 it
->font_height
= Qnil
;
2094 it
->override_ascent
= -1;
2096 /* Are control characters displayed as `^C'? */
2097 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2099 /* -1 means everything between a CR and the following line end
2100 is invisible. >0 means lines indented more than this value are
2102 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2103 ? XFASTINT (current_buffer
->selective_display
)
2104 : (!NILP (current_buffer
->selective_display
)
2106 it
->selective_display_ellipsis_p
2107 = !NILP (current_buffer
->selective_display_ellipses
);
2109 /* Display table to use. */
2110 it
->dp
= window_display_table (w
);
2112 /* Are multibyte characters enabled in current_buffer? */
2113 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2115 /* Non-zero if we should highlight the region. */
2117 = (!NILP (Vtransient_mark_mode
)
2118 && !NILP (current_buffer
->mark_active
)
2119 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2121 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2122 start and end of a visible region in window IT->w. Set both to
2123 -1 to indicate no region. */
2124 if (highlight_region_p
2125 /* Maybe highlight only in selected window. */
2126 && (/* Either show region everywhere. */
2127 highlight_nonselected_windows
2128 /* Or show region in the selected window. */
2129 || w
== XWINDOW (selected_window
)
2130 /* Or show the region if we are in the mini-buffer and W is
2131 the window the mini-buffer refers to. */
2132 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2133 && WINDOWP (minibuf_selected_window
)
2134 && w
== XWINDOW (minibuf_selected_window
))))
2136 int charpos
= marker_position (current_buffer
->mark
);
2137 it
->region_beg_charpos
= min (PT
, charpos
);
2138 it
->region_end_charpos
= max (PT
, charpos
);
2141 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2143 /* Get the position at which the redisplay_end_trigger hook should
2144 be run, if it is to be run at all. */
2145 if (MARKERP (w
->redisplay_end_trigger
)
2146 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2147 it
->redisplay_end_trigger_charpos
2148 = marker_position (w
->redisplay_end_trigger
);
2149 else if (INTEGERP (w
->redisplay_end_trigger
))
2150 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2152 /* Correct bogus values of tab_width. */
2153 it
->tab_width
= XINT (current_buffer
->tab_width
);
2154 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2157 /* Are lines in the display truncated? */
2158 it
->truncate_lines_p
2159 = (base_face_id
!= DEFAULT_FACE_ID
2160 || XINT (it
->w
->hscroll
)
2161 || (truncate_partial_width_windows
2162 && !WINDOW_FULL_WIDTH_P (it
->w
))
2163 || !NILP (current_buffer
->truncate_lines
));
2165 /* Get dimensions of truncation and continuation glyphs. These are
2166 displayed as fringe bitmaps under X, so we don't need them for such
2168 if (!FRAME_WINDOW_P (it
->f
))
2170 if (it
->truncate_lines_p
)
2172 /* We will need the truncation glyph. */
2173 xassert (it
->glyph_row
== NULL
);
2174 produce_special_glyphs (it
, IT_TRUNCATION
);
2175 it
->truncation_pixel_width
= it
->pixel_width
;
2179 /* We will need the continuation glyph. */
2180 xassert (it
->glyph_row
== NULL
);
2181 produce_special_glyphs (it
, IT_CONTINUATION
);
2182 it
->continuation_pixel_width
= it
->pixel_width
;
2185 /* Reset these values to zero because the produce_special_glyphs
2186 above has changed them. */
2187 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2188 it
->phys_ascent
= it
->phys_descent
= 0;
2191 /* Set this after getting the dimensions of truncation and
2192 continuation glyphs, so that we don't produce glyphs when calling
2193 produce_special_glyphs, above. */
2194 it
->glyph_row
= row
;
2195 it
->area
= TEXT_AREA
;
2197 /* Get the dimensions of the display area. The display area
2198 consists of the visible window area plus a horizontally scrolled
2199 part to the left of the window. All x-values are relative to the
2200 start of this total display area. */
2201 if (base_face_id
!= DEFAULT_FACE_ID
)
2203 /* Mode lines, menu bar in terminal frames. */
2204 it
->first_visible_x
= 0;
2205 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2210 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2211 it
->last_visible_x
= (it
->first_visible_x
2212 + window_box_width (w
, TEXT_AREA
));
2214 /* If we truncate lines, leave room for the truncator glyph(s) at
2215 the right margin. Otherwise, leave room for the continuation
2216 glyph(s). Truncation and continuation glyphs are not inserted
2217 for window-based redisplay. */
2218 if (!FRAME_WINDOW_P (it
->f
))
2220 if (it
->truncate_lines_p
)
2221 it
->last_visible_x
-= it
->truncation_pixel_width
;
2223 it
->last_visible_x
-= it
->continuation_pixel_width
;
2226 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2227 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2230 /* Leave room for a border glyph. */
2231 if (!FRAME_WINDOW_P (it
->f
)
2232 && !WINDOW_RIGHTMOST_P (it
->w
))
2233 it
->last_visible_x
-= 1;
2235 it
->last_visible_y
= window_text_bottom_y (w
);
2237 /* For mode lines and alike, arrange for the first glyph having a
2238 left box line if the face specifies a box. */
2239 if (base_face_id
!= DEFAULT_FACE_ID
)
2243 it
->face_id
= base_face_id
;
2245 /* If we have a boxed mode line, make the first character appear
2246 with a left box line. */
2247 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2248 if (face
->box
!= FACE_NO_BOX
)
2249 it
->start_of_box_run_p
= 1;
2252 /* If a buffer position was specified, set the iterator there,
2253 getting overlays and face properties from that position. */
2254 if (charpos
>= BUF_BEG (current_buffer
))
2256 it
->end_charpos
= ZV
;
2258 IT_CHARPOS (*it
) = charpos
;
2260 /* Compute byte position if not specified. */
2261 if (bytepos
< charpos
)
2262 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2264 IT_BYTEPOS (*it
) = bytepos
;
2266 it
->start
= it
->current
;
2268 /* Compute faces etc. */
2269 reseat (it
, it
->current
.pos
, 1);
2276 /* Initialize IT for the display of window W with window start POS. */
2279 start_display (it
, w
, pos
)
2282 struct text_pos pos
;
2284 struct glyph_row
*row
;
2285 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2287 row
= w
->desired_matrix
->rows
+ first_vpos
;
2288 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2289 it
->first_vpos
= first_vpos
;
2291 if (!it
->truncate_lines_p
)
2293 int start_at_line_beg_p
;
2294 int first_y
= it
->current_y
;
2296 /* If window start is not at a line start, skip forward to POS to
2297 get the correct continuation lines width. */
2298 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2299 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2300 if (!start_at_line_beg_p
)
2304 reseat_at_previous_visible_line_start (it
);
2305 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2307 new_x
= it
->current_x
+ it
->pixel_width
;
2309 /* If lines are continued, this line may end in the middle
2310 of a multi-glyph character (e.g. a control character
2311 displayed as \003, or in the middle of an overlay
2312 string). In this case move_it_to above will not have
2313 taken us to the start of the continuation line but to the
2314 end of the continued line. */
2315 if (it
->current_x
> 0
2316 && !it
->truncate_lines_p
/* Lines are continued. */
2317 && (/* And glyph doesn't fit on the line. */
2318 new_x
> it
->last_visible_x
2319 /* Or it fits exactly and we're on a window
2321 || (new_x
== it
->last_visible_x
2322 && FRAME_WINDOW_P (it
->f
))))
2324 if (it
->current
.dpvec_index
>= 0
2325 || it
->current
.overlay_string_index
>= 0)
2327 set_iterator_to_next (it
, 1);
2328 move_it_in_display_line_to (it
, -1, -1, 0);
2331 it
->continuation_lines_width
+= it
->current_x
;
2334 /* We're starting a new display line, not affected by the
2335 height of the continued line, so clear the appropriate
2336 fields in the iterator structure. */
2337 it
->max_ascent
= it
->max_descent
= 0;
2338 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2340 it
->current_y
= first_y
;
2342 it
->current_x
= it
->hpos
= 0;
2346 #if 0 /* Don't assert the following because start_display is sometimes
2347 called intentionally with a window start that is not at a
2348 line start. Please leave this code in as a comment. */
2350 /* Window start should be on a line start, now. */
2351 xassert (it
->continuation_lines_width
2352 || IT_CHARPOS (it
) == BEGV
2353 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2358 /* Return 1 if POS is a position in ellipses displayed for invisible
2359 text. W is the window we display, for text property lookup. */
2362 in_ellipses_for_invisible_text_p (pos
, w
)
2363 struct display_pos
*pos
;
2366 Lisp_Object prop
, window
;
2368 int charpos
= CHARPOS (pos
->pos
);
2370 /* If POS specifies a position in a display vector, this might
2371 be for an ellipsis displayed for invisible text. We won't
2372 get the iterator set up for delivering that ellipsis unless
2373 we make sure that it gets aware of the invisible text. */
2374 if (pos
->dpvec_index
>= 0
2375 && pos
->overlay_string_index
< 0
2376 && CHARPOS (pos
->string_pos
) < 0
2378 && (XSETWINDOW (window
, w
),
2379 prop
= Fget_char_property (make_number (charpos
),
2380 Qinvisible
, window
),
2381 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2383 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2385 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2392 /* Initialize IT for stepping through current_buffer in window W,
2393 starting at position POS that includes overlay string and display
2394 vector/ control character translation position information. Value
2395 is zero if there are overlay strings with newlines at POS. */
2398 init_from_display_pos (it
, w
, pos
)
2401 struct display_pos
*pos
;
2403 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2404 int i
, overlay_strings_with_newlines
= 0;
2406 /* If POS specifies a position in a display vector, this might
2407 be for an ellipsis displayed for invisible text. We won't
2408 get the iterator set up for delivering that ellipsis unless
2409 we make sure that it gets aware of the invisible text. */
2410 if (in_ellipses_for_invisible_text_p (pos
, w
))
2416 /* Keep in mind: the call to reseat in init_iterator skips invisible
2417 text, so we might end up at a position different from POS. This
2418 is only a problem when POS is a row start after a newline and an
2419 overlay starts there with an after-string, and the overlay has an
2420 invisible property. Since we don't skip invisible text in
2421 display_line and elsewhere immediately after consuming the
2422 newline before the row start, such a POS will not be in a string,
2423 but the call to init_iterator below will move us to the
2425 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2427 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
2429 const char *s
= SDATA (it
->overlay_strings
[i
]);
2430 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2432 while (s
< e
&& *s
!= '\n')
2437 overlay_strings_with_newlines
= 1;
2442 /* If position is within an overlay string, set up IT to the right
2444 if (pos
->overlay_string_index
>= 0)
2448 /* If the first overlay string happens to have a `display'
2449 property for an image, the iterator will be set up for that
2450 image, and we have to undo that setup first before we can
2451 correct the overlay string index. */
2452 if (it
->method
== next_element_from_image
)
2455 /* We already have the first chunk of overlay strings in
2456 IT->overlay_strings. Load more until the one for
2457 pos->overlay_string_index is in IT->overlay_strings. */
2458 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2460 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2461 it
->current
.overlay_string_index
= 0;
2464 load_overlay_strings (it
, 0);
2465 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2469 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2470 relative_index
= (it
->current
.overlay_string_index
2471 % OVERLAY_STRING_CHUNK_SIZE
);
2472 it
->string
= it
->overlay_strings
[relative_index
];
2473 xassert (STRINGP (it
->string
));
2474 it
->current
.string_pos
= pos
->string_pos
;
2475 it
->method
= next_element_from_string
;
2478 #if 0 /* This is bogus because POS not having an overlay string
2479 position does not mean it's after the string. Example: A
2480 line starting with a before-string and initialization of IT
2481 to the previous row's end position. */
2482 else if (it
->current
.overlay_string_index
>= 0)
2484 /* If POS says we're already after an overlay string ending at
2485 POS, make sure to pop the iterator because it will be in
2486 front of that overlay string. When POS is ZV, we've thereby
2487 also ``processed'' overlay strings at ZV. */
2490 it
->current
.overlay_string_index
= -1;
2491 it
->method
= next_element_from_buffer
;
2492 if (CHARPOS (pos
->pos
) == ZV
)
2493 it
->overlay_strings_at_end_processed_p
= 1;
2497 if (CHARPOS (pos
->string_pos
) >= 0)
2499 /* Recorded position is not in an overlay string, but in another
2500 string. This can only be a string from a `display' property.
2501 IT should already be filled with that string. */
2502 it
->current
.string_pos
= pos
->string_pos
;
2503 xassert (STRINGP (it
->string
));
2506 /* Restore position in display vector translations, control
2507 character translations or ellipses. */
2508 if (pos
->dpvec_index
>= 0)
2510 if (it
->dpvec
== NULL
)
2511 get_next_display_element (it
);
2512 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2513 it
->current
.dpvec_index
= pos
->dpvec_index
;
2517 return !overlay_strings_with_newlines
;
2521 /* Initialize IT for stepping through current_buffer in window W
2522 starting at ROW->start. */
2525 init_to_row_start (it
, w
, row
)
2528 struct glyph_row
*row
;
2530 init_from_display_pos (it
, w
, &row
->start
);
2531 it
->start
= row
->start
;
2532 it
->continuation_lines_width
= row
->continuation_lines_width
;
2537 /* Initialize IT for stepping through current_buffer in window W
2538 starting in the line following ROW, i.e. starting at ROW->end.
2539 Value is zero if there are overlay strings with newlines at ROW's
2543 init_to_row_end (it
, w
, row
)
2546 struct glyph_row
*row
;
2550 if (init_from_display_pos (it
, w
, &row
->end
))
2552 if (row
->continued_p
)
2553 it
->continuation_lines_width
2554 = row
->continuation_lines_width
+ row
->pixel_width
;
2565 /***********************************************************************
2567 ***********************************************************************/
2569 /* Called when IT reaches IT->stop_charpos. Handle text property and
2570 overlay changes. Set IT->stop_charpos to the next position where
2577 enum prop_handled handled
;
2578 int handle_overlay_change_p
= 1;
2582 it
->current
.dpvec_index
= -1;
2586 handled
= HANDLED_NORMALLY
;
2588 /* Call text property handlers. */
2589 for (p
= it_props
; p
->handler
; ++p
)
2591 handled
= p
->handler (it
);
2593 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2595 else if (handled
== HANDLED_RETURN
)
2597 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2598 handle_overlay_change_p
= 0;
2601 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2603 /* Don't check for overlay strings below when set to deliver
2604 characters from a display vector. */
2605 if (it
->method
== next_element_from_display_vector
)
2606 handle_overlay_change_p
= 0;
2608 /* Handle overlay changes. */
2609 if (handle_overlay_change_p
)
2610 handled
= handle_overlay_change (it
);
2612 /* Determine where to stop next. */
2613 if (handled
== HANDLED_NORMALLY
)
2614 compute_stop_pos (it
);
2617 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2621 /* Compute IT->stop_charpos from text property and overlay change
2622 information for IT's current position. */
2625 compute_stop_pos (it
)
2628 register INTERVAL iv
, next_iv
;
2629 Lisp_Object object
, limit
, position
;
2631 /* If nowhere else, stop at the end. */
2632 it
->stop_charpos
= it
->end_charpos
;
2634 if (STRINGP (it
->string
))
2636 /* Strings are usually short, so don't limit the search for
2638 object
= it
->string
;
2640 position
= make_number (IT_STRING_CHARPOS (*it
));
2646 /* If next overlay change is in front of the current stop pos
2647 (which is IT->end_charpos), stop there. Note: value of
2648 next_overlay_change is point-max if no overlay change
2650 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2651 if (charpos
< it
->stop_charpos
)
2652 it
->stop_charpos
= charpos
;
2654 /* If showing the region, we have to stop at the region
2655 start or end because the face might change there. */
2656 if (it
->region_beg_charpos
> 0)
2658 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2659 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2660 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2661 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2664 /* Set up variables for computing the stop position from text
2665 property changes. */
2666 XSETBUFFER (object
, current_buffer
);
2667 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2668 position
= make_number (IT_CHARPOS (*it
));
2672 /* Get the interval containing IT's position. Value is a null
2673 interval if there isn't such an interval. */
2674 iv
= validate_interval_range (object
, &position
, &position
, 0);
2675 if (!NULL_INTERVAL_P (iv
))
2677 Lisp_Object values_here
[LAST_PROP_IDX
];
2680 /* Get properties here. */
2681 for (p
= it_props
; p
->handler
; ++p
)
2682 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2684 /* Look for an interval following iv that has different
2686 for (next_iv
= next_interval (iv
);
2687 (!NULL_INTERVAL_P (next_iv
)
2689 || XFASTINT (limit
) > next_iv
->position
));
2690 next_iv
= next_interval (next_iv
))
2692 for (p
= it_props
; p
->handler
; ++p
)
2694 Lisp_Object new_value
;
2696 new_value
= textget (next_iv
->plist
, *p
->name
);
2697 if (!EQ (values_here
[p
->idx
], new_value
))
2705 if (!NULL_INTERVAL_P (next_iv
))
2707 if (INTEGERP (limit
)
2708 && next_iv
->position
>= XFASTINT (limit
))
2709 /* No text property change up to limit. */
2710 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2712 /* Text properties change in next_iv. */
2713 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2717 xassert (STRINGP (it
->string
)
2718 || (it
->stop_charpos
>= BEGV
2719 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2723 /* Return the position of the next overlay change after POS in
2724 current_buffer. Value is point-max if no overlay change
2725 follows. This is like `next-overlay-change' but doesn't use
2729 next_overlay_change (pos
)
2734 Lisp_Object
*overlays
;
2737 /* Get all overlays at the given position. */
2738 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
2740 /* If any of these overlays ends before endpos,
2741 use its ending point instead. */
2742 for (i
= 0; i
< noverlays
; ++i
)
2747 oend
= OVERLAY_END (overlays
[i
]);
2748 oendpos
= OVERLAY_POSITION (oend
);
2749 endpos
= min (endpos
, oendpos
);
2757 /***********************************************************************
2759 ***********************************************************************/
2761 /* Handle changes in the `fontified' property of the current buffer by
2762 calling hook functions from Qfontification_functions to fontify
2765 static enum prop_handled
2766 handle_fontified_prop (it
)
2769 Lisp_Object prop
, pos
;
2770 enum prop_handled handled
= HANDLED_NORMALLY
;
2772 /* Get the value of the `fontified' property at IT's current buffer
2773 position. (The `fontified' property doesn't have a special
2774 meaning in strings.) If the value is nil, call functions from
2775 Qfontification_functions. */
2776 if (!STRINGP (it
->string
)
2778 && !NILP (Vfontification_functions
)
2779 && !NILP (Vrun_hooks
)
2780 && (pos
= make_number (IT_CHARPOS (*it
)),
2781 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2784 int count
= SPECPDL_INDEX ();
2787 val
= Vfontification_functions
;
2788 specbind (Qfontification_functions
, Qnil
);
2790 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2791 safe_call1 (val
, pos
);
2794 Lisp_Object globals
, fn
;
2795 struct gcpro gcpro1
, gcpro2
;
2798 GCPRO2 (val
, globals
);
2800 for (; CONSP (val
); val
= XCDR (val
))
2806 /* A value of t indicates this hook has a local
2807 binding; it means to run the global binding too.
2808 In a global value, t should not occur. If it
2809 does, we must ignore it to avoid an endless
2811 for (globals
= Fdefault_value (Qfontification_functions
);
2813 globals
= XCDR (globals
))
2815 fn
= XCAR (globals
);
2817 safe_call1 (fn
, pos
);
2821 safe_call1 (fn
, pos
);
2827 unbind_to (count
, Qnil
);
2829 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2830 something. This avoids an endless loop if they failed to
2831 fontify the text for which reason ever. */
2832 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2833 handled
= HANDLED_RECOMPUTE_PROPS
;
2841 /***********************************************************************
2843 ***********************************************************************/
2845 /* Set up iterator IT from face properties at its current position.
2846 Called from handle_stop. */
2848 static enum prop_handled
2849 handle_face_prop (it
)
2852 int new_face_id
, next_stop
;
2854 if (!STRINGP (it
->string
))
2857 = face_at_buffer_position (it
->w
,
2859 it
->region_beg_charpos
,
2860 it
->region_end_charpos
,
2863 + TEXT_PROP_DISTANCE_LIMIT
),
2866 /* Is this a start of a run of characters with box face?
2867 Caveat: this can be called for a freshly initialized
2868 iterator; face_id is -1 in this case. We know that the new
2869 face will not change until limit, i.e. if the new face has a
2870 box, all characters up to limit will have one. But, as
2871 usual, we don't know whether limit is really the end. */
2872 if (new_face_id
!= it
->face_id
)
2874 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2876 /* If new face has a box but old face has not, this is
2877 the start of a run of characters with box, i.e. it has
2878 a shadow on the left side. The value of face_id of the
2879 iterator will be -1 if this is the initial call that gets
2880 the face. In this case, we have to look in front of IT's
2881 position and see whether there is a face != new_face_id. */
2882 it
->start_of_box_run_p
2883 = (new_face
->box
!= FACE_NO_BOX
2884 && (it
->face_id
>= 0
2885 || IT_CHARPOS (*it
) == BEG
2886 || new_face_id
!= face_before_it_pos (it
)));
2887 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2892 int base_face_id
, bufpos
;
2894 if (it
->current
.overlay_string_index
>= 0)
2895 bufpos
= IT_CHARPOS (*it
);
2899 /* For strings from a buffer, i.e. overlay strings or strings
2900 from a `display' property, use the face at IT's current
2901 buffer position as the base face to merge with, so that
2902 overlay strings appear in the same face as surrounding
2903 text, unless they specify their own faces. */
2904 base_face_id
= underlying_face_id (it
);
2906 new_face_id
= face_at_string_position (it
->w
,
2908 IT_STRING_CHARPOS (*it
),
2910 it
->region_beg_charpos
,
2911 it
->region_end_charpos
,
2915 #if 0 /* This shouldn't be neccessary. Let's check it. */
2916 /* If IT is used to display a mode line we would really like to
2917 use the mode line face instead of the frame's default face. */
2918 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2919 && new_face_id
== DEFAULT_FACE_ID
)
2920 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
2923 /* Is this a start of a run of characters with box? Caveat:
2924 this can be called for a freshly allocated iterator; face_id
2925 is -1 is this case. We know that the new face will not
2926 change until the next check pos, i.e. if the new face has a
2927 box, all characters up to that position will have a
2928 box. But, as usual, we don't know whether that position
2929 is really the end. */
2930 if (new_face_id
!= it
->face_id
)
2932 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2933 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2935 /* If new face has a box but old face hasn't, this is the
2936 start of a run of characters with box, i.e. it has a
2937 shadow on the left side. */
2938 it
->start_of_box_run_p
2939 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2940 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2944 it
->face_id
= new_face_id
;
2945 return HANDLED_NORMALLY
;
2949 /* Return the ID of the face ``underlying'' IT's current position,
2950 which is in a string. If the iterator is associated with a
2951 buffer, return the face at IT's current buffer position.
2952 Otherwise, use the iterator's base_face_id. */
2955 underlying_face_id (it
)
2958 int face_id
= it
->base_face_id
, i
;
2960 xassert (STRINGP (it
->string
));
2962 for (i
= it
->sp
- 1; i
>= 0; --i
)
2963 if (NILP (it
->stack
[i
].string
))
2964 face_id
= it
->stack
[i
].face_id
;
2970 /* Compute the face one character before or after the current position
2971 of IT. BEFORE_P non-zero means get the face in front of IT's
2972 position. Value is the id of the face. */
2975 face_before_or_after_it_pos (it
, before_p
)
2980 int next_check_charpos
;
2981 struct text_pos pos
;
2983 xassert (it
->s
== NULL
);
2985 if (STRINGP (it
->string
))
2987 int bufpos
, base_face_id
;
2989 /* No face change past the end of the string (for the case
2990 we are padding with spaces). No face change before the
2992 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
2993 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2996 /* Set pos to the position before or after IT's current position. */
2998 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3000 /* For composition, we must check the character after the
3002 pos
= (it
->what
== IT_COMPOSITION
3003 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3004 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3006 if (it
->current
.overlay_string_index
>= 0)
3007 bufpos
= IT_CHARPOS (*it
);
3011 base_face_id
= underlying_face_id (it
);
3013 /* Get the face for ASCII, or unibyte. */
3014 face_id
= face_at_string_position (it
->w
,
3018 it
->region_beg_charpos
,
3019 it
->region_end_charpos
,
3020 &next_check_charpos
,
3023 /* Correct the face for charsets different from ASCII. Do it
3024 for the multibyte case only. The face returned above is
3025 suitable for unibyte text if IT->string is unibyte. */
3026 if (STRING_MULTIBYTE (it
->string
))
3028 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3029 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3031 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3033 c
= string_char_and_length (p
, rest
, &len
);
3034 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3039 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3040 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3043 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3044 pos
= it
->current
.pos
;
3047 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3050 if (it
->what
== IT_COMPOSITION
)
3051 /* For composition, we must check the position after the
3053 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3055 INC_TEXT_POS (pos
, it
->multibyte_p
);
3058 /* Determine face for CHARSET_ASCII, or unibyte. */
3059 face_id
= face_at_buffer_position (it
->w
,
3061 it
->region_beg_charpos
,
3062 it
->region_end_charpos
,
3063 &next_check_charpos
,
3066 /* Correct the face for charsets different from ASCII. Do it
3067 for the multibyte case only. The face returned above is
3068 suitable for unibyte text if current_buffer is unibyte. */
3069 if (it
->multibyte_p
)
3071 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3072 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3073 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3082 /***********************************************************************
3084 ***********************************************************************/
3086 /* Set up iterator IT from invisible properties at its current
3087 position. Called from handle_stop. */
3089 static enum prop_handled
3090 handle_invisible_prop (it
)
3093 enum prop_handled handled
= HANDLED_NORMALLY
;
3095 if (STRINGP (it
->string
))
3097 extern Lisp_Object Qinvisible
;
3098 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3100 /* Get the value of the invisible text property at the
3101 current position. Value will be nil if there is no such
3103 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3104 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3107 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3109 handled
= HANDLED_RECOMPUTE_PROPS
;
3111 /* Get the position at which the next change of the
3112 invisible text property can be found in IT->string.
3113 Value will be nil if the property value is the same for
3114 all the rest of IT->string. */
3115 XSETINT (limit
, SCHARS (it
->string
));
3116 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3119 /* Text at current position is invisible. The next
3120 change in the property is at position end_charpos.
3121 Move IT's current position to that position. */
3122 if (INTEGERP (end_charpos
)
3123 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3125 struct text_pos old
;
3126 old
= it
->current
.string_pos
;
3127 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3128 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3132 /* The rest of the string is invisible. If this is an
3133 overlay string, proceed with the next overlay string
3134 or whatever comes and return a character from there. */
3135 if (it
->current
.overlay_string_index
>= 0)
3137 next_overlay_string (it
);
3138 /* Don't check for overlay strings when we just
3139 finished processing them. */
3140 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3144 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3145 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3152 int invis_p
, newpos
, next_stop
, start_charpos
;
3153 Lisp_Object pos
, prop
, overlay
;
3155 /* First of all, is there invisible text at this position? */
3156 start_charpos
= IT_CHARPOS (*it
);
3157 pos
= make_number (IT_CHARPOS (*it
));
3158 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3160 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3162 /* If we are on invisible text, skip over it. */
3163 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3165 /* Record whether we have to display an ellipsis for the
3167 int display_ellipsis_p
= invis_p
== 2;
3169 handled
= HANDLED_RECOMPUTE_PROPS
;
3171 /* Loop skipping over invisible text. The loop is left at
3172 ZV or with IT on the first char being visible again. */
3175 /* Try to skip some invisible text. Return value is the
3176 position reached which can be equal to IT's position
3177 if there is nothing invisible here. This skips both
3178 over invisible text properties and overlays with
3179 invisible property. */
3180 newpos
= skip_invisible (IT_CHARPOS (*it
),
3181 &next_stop
, ZV
, it
->window
);
3183 /* If we skipped nothing at all we weren't at invisible
3184 text in the first place. If everything to the end of
3185 the buffer was skipped, end the loop. */
3186 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3190 /* We skipped some characters but not necessarily
3191 all there are. Check if we ended up on visible
3192 text. Fget_char_property returns the property of
3193 the char before the given position, i.e. if we
3194 get invis_p = 0, this means that the char at
3195 newpos is visible. */
3196 pos
= make_number (newpos
);
3197 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3198 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3201 /* If we ended up on invisible text, proceed to
3202 skip starting with next_stop. */
3204 IT_CHARPOS (*it
) = next_stop
;
3208 /* The position newpos is now either ZV or on visible text. */
3209 IT_CHARPOS (*it
) = newpos
;
3210 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3212 /* If there are before-strings at the start of invisible
3213 text, and the text is invisible because of a text
3214 property, arrange to show before-strings because 20.x did
3215 it that way. (If the text is invisible because of an
3216 overlay property instead of a text property, this is
3217 already handled in the overlay code.) */
3219 && get_overlay_strings (it
, start_charpos
))
3221 handled
= HANDLED_RECOMPUTE_PROPS
;
3222 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3224 else if (display_ellipsis_p
)
3225 setup_for_ellipsis (it
);
3233 /* Make iterator IT return `...' next. */
3236 setup_for_ellipsis (it
)
3240 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3242 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3243 it
->dpvec
= v
->contents
;
3244 it
->dpend
= v
->contents
+ v
->size
;
3248 /* Default `...'. */
3249 it
->dpvec
= default_invis_vector
;
3250 it
->dpend
= default_invis_vector
+ 3;
3253 /* The ellipsis display does not replace the display of the
3254 character at the new position. Indicate this by setting
3255 IT->dpvec_char_len to zero. */
3256 it
->dpvec_char_len
= 0;
3258 it
->current
.dpvec_index
= 0;
3259 it
->method
= next_element_from_display_vector
;
3264 /***********************************************************************
3266 ***********************************************************************/
3268 /* Set up iterator IT from `display' property at its current position.
3269 Called from handle_stop. */
3271 static enum prop_handled
3272 handle_display_prop (it
)
3275 Lisp_Object prop
, object
;
3276 struct text_pos
*position
;
3277 int display_replaced_p
= 0;
3279 if (STRINGP (it
->string
))
3281 object
= it
->string
;
3282 position
= &it
->current
.string_pos
;
3286 object
= it
->w
->buffer
;
3287 position
= &it
->current
.pos
;
3290 /* Reset those iterator values set from display property values. */
3291 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3292 it
->space_width
= Qnil
;
3293 it
->font_height
= Qnil
;
3296 /* We don't support recursive `display' properties, i.e. string
3297 values that have a string `display' property, that have a string
3298 `display' property etc. */
3299 if (!it
->string_from_display_prop_p
)
3300 it
->area
= TEXT_AREA
;
3302 prop
= Fget_char_property (make_number (position
->charpos
),
3305 return HANDLED_NORMALLY
;
3308 /* Simple properties. */
3309 && !EQ (XCAR (prop
), Qimage
)
3310 && !EQ (XCAR (prop
), Qspace
)
3311 && !EQ (XCAR (prop
), Qwhen
)
3312 && !EQ (XCAR (prop
), Qslice
)
3313 && !EQ (XCAR (prop
), Qspace_width
)
3314 && !EQ (XCAR (prop
), Qheight
)
3315 && !EQ (XCAR (prop
), Qraise
)
3316 /* Marginal area specifications. */
3317 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3318 && !EQ (XCAR (prop
), Qleft_fringe
)
3319 && !EQ (XCAR (prop
), Qright_fringe
)
3320 && !NILP (XCAR (prop
)))
3322 for (; CONSP (prop
); prop
= XCDR (prop
))
3324 if (handle_single_display_prop (it
, XCAR (prop
), object
,
3325 position
, display_replaced_p
))
3326 display_replaced_p
= 1;
3329 else if (VECTORP (prop
))
3332 for (i
= 0; i
< ASIZE (prop
); ++i
)
3333 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
3334 position
, display_replaced_p
))
3335 display_replaced_p
= 1;
3339 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
3340 display_replaced_p
= 1;
3343 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3347 /* Value is the position of the end of the `display' property starting
3348 at START_POS in OBJECT. */
3350 static struct text_pos
3351 display_prop_end (it
, object
, start_pos
)
3354 struct text_pos start_pos
;
3357 struct text_pos end_pos
;
3359 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3360 Qdisplay
, object
, Qnil
);
3361 CHARPOS (end_pos
) = XFASTINT (end
);
3362 if (STRINGP (object
))
3363 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3365 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3371 /* Set up IT from a single `display' sub-property value PROP. OBJECT
3372 is the object in which the `display' property was found. *POSITION
3373 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3374 means that we previously saw a display sub-property which already
3375 replaced text display with something else, for example an image;
3376 ignore such properties after the first one has been processed.
3378 If PROP is a `space' or `image' sub-property, set *POSITION to the
3379 end position of the `display' property.
3381 Value is non-zero if something was found which replaces the display
3382 of buffer or string text. */
3385 handle_single_display_prop (it
, prop
, object
, position
,
3386 display_replaced_before_p
)
3390 struct text_pos
*position
;
3391 int display_replaced_before_p
;
3394 int replaces_text_display_p
= 0;
3397 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
3398 evaluated. If the result is nil, VALUE is ignored. */
3400 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3409 if (!NILP (form
) && !EQ (form
, Qt
))
3411 int count
= SPECPDL_INDEX ();
3412 struct gcpro gcpro1
;
3414 /* Bind `object' to the object having the `display' property, a
3415 buffer or string. Bind `position' to the position in the
3416 object where the property was found, and `buffer-position'
3417 to the current position in the buffer. */
3418 specbind (Qobject
, object
);
3419 specbind (Qposition
, make_number (CHARPOS (*position
)));
3420 specbind (Qbuffer_position
,
3421 make_number (STRINGP (object
)
3422 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3424 form
= safe_eval (form
);
3426 unbind_to (count
, Qnil
);
3433 && EQ (XCAR (prop
), Qheight
)
3434 && CONSP (XCDR (prop
)))
3436 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3439 /* `(height HEIGHT)'. */
3440 it
->font_height
= XCAR (XCDR (prop
));
3441 if (!NILP (it
->font_height
))
3443 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3444 int new_height
= -1;
3446 if (CONSP (it
->font_height
)
3447 && (EQ (XCAR (it
->font_height
), Qplus
)
3448 || EQ (XCAR (it
->font_height
), Qminus
))
3449 && CONSP (XCDR (it
->font_height
))
3450 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3452 /* `(+ N)' or `(- N)' where N is an integer. */
3453 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3454 if (EQ (XCAR (it
->font_height
), Qplus
))
3456 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3458 else if (FUNCTIONP (it
->font_height
))
3460 /* Call function with current height as argument.
3461 Value is the new height. */
3463 height
= safe_call1 (it
->font_height
,
3464 face
->lface
[LFACE_HEIGHT_INDEX
]);
3465 if (NUMBERP (height
))
3466 new_height
= XFLOATINT (height
);
3468 else if (NUMBERP (it
->font_height
))
3470 /* Value is a multiple of the canonical char height. */
3473 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3474 new_height
= (XFLOATINT (it
->font_height
)
3475 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3479 /* Evaluate IT->font_height with `height' bound to the
3480 current specified height to get the new height. */
3482 int count
= SPECPDL_INDEX ();
3484 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3485 value
= safe_eval (it
->font_height
);
3486 unbind_to (count
, Qnil
);
3488 if (NUMBERP (value
))
3489 new_height
= XFLOATINT (value
);
3493 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3496 else if (CONSP (prop
)
3497 && EQ (XCAR (prop
), Qspace_width
)
3498 && CONSP (XCDR (prop
)))
3500 /* `(space_width WIDTH)'. */
3501 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3504 value
= XCAR (XCDR (prop
));
3505 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3506 it
->space_width
= value
;
3508 else if (CONSP (prop
)
3509 && EQ (XCAR (prop
), Qslice
))
3511 /* `(slice X Y WIDTH HEIGHT)'. */
3514 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3517 if (tem
= XCDR (prop
), CONSP (tem
))
3519 it
->slice
.x
= XCAR (tem
);
3520 if (tem
= XCDR (tem
), CONSP (tem
))
3522 it
->slice
.y
= XCAR (tem
);
3523 if (tem
= XCDR (tem
), CONSP (tem
))
3525 it
->slice
.width
= XCAR (tem
);
3526 if (tem
= XCDR (tem
), CONSP (tem
))
3527 it
->slice
.height
= XCAR (tem
);
3532 else if (CONSP (prop
)
3533 && EQ (XCAR (prop
), Qraise
)
3534 && CONSP (XCDR (prop
)))
3536 /* `(raise FACTOR)'. */
3537 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3540 #ifdef HAVE_WINDOW_SYSTEM
3541 value
= XCAR (XCDR (prop
));
3542 if (NUMBERP (value
))
3544 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3545 it
->voffset
= - (XFLOATINT (value
)
3546 * (FONT_HEIGHT (face
->font
)));
3548 #endif /* HAVE_WINDOW_SYSTEM */
3550 else if (!it
->string_from_display_prop_p
)
3552 /* `((margin left-margin) VALUE)' or `((margin right-margin)
3553 VALUE) or `((margin nil) VALUE)' or VALUE. */
3554 Lisp_Object location
, value
;
3555 struct text_pos start_pos
;
3558 /* Characters having this form of property are not displayed, so
3559 we have to find the end of the property. */
3560 start_pos
= *position
;
3561 *position
= display_prop_end (it
, object
, start_pos
);
3564 /* Let's stop at the new position and assume that all
3565 text properties change there. */
3566 it
->stop_charpos
= position
->charpos
;
3569 && (EQ (XCAR (prop
), Qleft_fringe
)
3570 || EQ (XCAR (prop
), Qright_fringe
))
3571 && CONSP (XCDR (prop
)))
3573 unsigned face_id
= DEFAULT_FACE_ID
;
3575 /* Save current settings of IT so that we can restore them
3576 when we are finished with the glyph property value. */
3578 /* `(left-fringe BITMAP FACE)'. */
3579 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3582 #ifdef HAVE_WINDOW_SYSTEM
3583 value
= XCAR (XCDR (prop
));
3584 if (!NUMBERP (value
)
3585 || !valid_fringe_bitmap_id_p (XINT (value
)))
3588 if (CONSP (XCDR (XCDR (prop
))))
3590 Lisp_Object face_name
= XCAR (XCDR (XCDR (prop
)));
3592 face_id
= lookup_named_face (it
->f
, face_name
, 'A');
3599 it
->area
= TEXT_AREA
;
3600 it
->what
= IT_IMAGE
;
3601 it
->image_id
= -1; /* no image */
3602 it
->position
= start_pos
;
3603 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3604 it
->method
= next_element_from_image
;
3605 it
->face_id
= face_id
;
3607 /* Say that we haven't consumed the characters with
3608 `display' property yet. The call to pop_it in
3609 set_iterator_to_next will clean this up. */
3610 *position
= start_pos
;
3612 if (EQ (XCAR (prop
), Qleft_fringe
))
3614 it
->left_user_fringe_bitmap
= XINT (value
);
3615 it
->left_user_fringe_face_id
= face_id
;
3619 it
->right_user_fringe_bitmap
= XINT (value
);
3620 it
->right_user_fringe_face_id
= face_id
;
3622 #endif /* HAVE_WINDOW_SYSTEM */
3626 location
= Qunbound
;
3627 if (CONSP (prop
) && CONSP (XCAR (prop
)))
3631 value
= XCDR (prop
);
3633 value
= XCAR (value
);
3636 if (EQ (XCAR (tem
), Qmargin
)
3637 && (tem
= XCDR (tem
),
3638 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3640 || EQ (tem
, Qleft_margin
)
3641 || EQ (tem
, Qright_margin
))))
3645 if (EQ (location
, Qunbound
))
3651 valid_p
= (STRINGP (value
)
3652 #ifdef HAVE_WINDOW_SYSTEM
3653 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
3654 #endif /* not HAVE_WINDOW_SYSTEM */
3655 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
3657 if ((EQ (location
, Qleft_margin
)
3658 || EQ (location
, Qright_margin
)
3661 && !display_replaced_before_p
)
3663 replaces_text_display_p
= 1;
3665 /* Save current settings of IT so that we can restore them
3666 when we are finished with the glyph property value. */
3669 if (NILP (location
))
3670 it
->area
= TEXT_AREA
;
3671 else if (EQ (location
, Qleft_margin
))
3672 it
->area
= LEFT_MARGIN_AREA
;
3674 it
->area
= RIGHT_MARGIN_AREA
;
3676 if (STRINGP (value
))
3679 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3680 it
->current
.overlay_string_index
= -1;
3681 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3682 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3683 it
->method
= next_element_from_string
;
3684 it
->stop_charpos
= 0;
3685 it
->string_from_display_prop_p
= 1;
3686 /* Say that we haven't consumed the characters with
3687 `display' property yet. The call to pop_it in
3688 set_iterator_to_next will clean this up. */
3689 *position
= start_pos
;
3691 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3693 it
->method
= next_element_from_stretch
;
3695 it
->current
.pos
= it
->position
= start_pos
;
3697 #ifdef HAVE_WINDOW_SYSTEM
3700 it
->what
= IT_IMAGE
;
3701 it
->image_id
= lookup_image (it
->f
, value
);
3702 it
->position
= start_pos
;
3703 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3704 it
->method
= next_element_from_image
;
3706 /* Say that we haven't consumed the characters with
3707 `display' property yet. The call to pop_it in
3708 set_iterator_to_next will clean this up. */
3709 *position
= start_pos
;
3711 #endif /* HAVE_WINDOW_SYSTEM */
3714 /* Invalid property or property not supported. Restore
3715 the position to what it was before. */
3716 *position
= start_pos
;
3719 return replaces_text_display_p
;
3723 /* Check if PROP is a display sub-property value whose text should be
3724 treated as intangible. */
3727 single_display_prop_intangible_p (prop
)
3730 /* Skip over `when FORM'. */
3731 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3745 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3746 we don't need to treat text as intangible. */
3747 if (EQ (XCAR (prop
), Qmargin
))
3755 || EQ (XCAR (prop
), Qleft_margin
)
3756 || EQ (XCAR (prop
), Qright_margin
))
3760 return (CONSP (prop
)
3761 && (EQ (XCAR (prop
), Qimage
)
3762 || EQ (XCAR (prop
), Qspace
)));
3766 /* Check if PROP is a display property value whose text should be
3767 treated as intangible. */
3770 display_prop_intangible_p (prop
)
3774 && CONSP (XCAR (prop
))
3775 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3777 /* A list of sub-properties. */
3778 while (CONSP (prop
))
3780 if (single_display_prop_intangible_p (XCAR (prop
)))
3785 else if (VECTORP (prop
))
3787 /* A vector of sub-properties. */
3789 for (i
= 0; i
< ASIZE (prop
); ++i
)
3790 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3794 return single_display_prop_intangible_p (prop
);
3800 /* Return 1 if PROP is a display sub-property value containing STRING. */
3803 single_display_prop_string_p (prop
, string
)
3804 Lisp_Object prop
, string
;
3806 if (EQ (string
, prop
))
3809 /* Skip over `when FORM'. */
3810 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3819 /* Skip over `margin LOCATION'. */
3820 if (EQ (XCAR (prop
), Qmargin
))
3831 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3835 /* Return 1 if STRING appears in the `display' property PROP. */
3838 display_prop_string_p (prop
, string
)
3839 Lisp_Object prop
, string
;
3842 && CONSP (XCAR (prop
))
3843 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3845 /* A list of sub-properties. */
3846 while (CONSP (prop
))
3848 if (single_display_prop_string_p (XCAR (prop
), string
))
3853 else if (VECTORP (prop
))
3855 /* A vector of sub-properties. */
3857 for (i
= 0; i
< ASIZE (prop
); ++i
)
3858 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3862 return single_display_prop_string_p (prop
, string
);
3868 /* Determine from which buffer position in W's buffer STRING comes
3869 from. AROUND_CHARPOS is an approximate position where it could
3870 be from. Value is the buffer position or 0 if it couldn't be
3873 W's buffer must be current.
3875 This function is necessary because we don't record buffer positions
3876 in glyphs generated from strings (to keep struct glyph small).
3877 This function may only use code that doesn't eval because it is
3878 called asynchronously from note_mouse_highlight. */
3881 string_buffer_position (w
, string
, around_charpos
)
3886 Lisp_Object limit
, prop
, pos
;
3887 const int MAX_DISTANCE
= 1000;
3890 pos
= make_number (around_charpos
);
3891 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3892 while (!found
&& !EQ (pos
, limit
))
3894 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3895 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3898 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3903 pos
= make_number (around_charpos
);
3904 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3905 while (!found
&& !EQ (pos
, limit
))
3907 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3908 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3911 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3916 return found
? XINT (pos
) : 0;
3921 /***********************************************************************
3922 `composition' property
3923 ***********************************************************************/
3925 /* Set up iterator IT from `composition' property at its current
3926 position. Called from handle_stop. */
3928 static enum prop_handled
3929 handle_composition_prop (it
)
3932 Lisp_Object prop
, string
;
3933 int pos
, pos_byte
, end
;
3934 enum prop_handled handled
= HANDLED_NORMALLY
;
3936 if (STRINGP (it
->string
))
3938 pos
= IT_STRING_CHARPOS (*it
);
3939 pos_byte
= IT_STRING_BYTEPOS (*it
);
3940 string
= it
->string
;
3944 pos
= IT_CHARPOS (*it
);
3945 pos_byte
= IT_BYTEPOS (*it
);
3949 /* If there's a valid composition and point is not inside of the
3950 composition (in the case that the composition is from the current
3951 buffer), draw a glyph composed from the composition components. */
3952 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3953 && COMPOSITION_VALID_P (pos
, end
, prop
)
3954 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3956 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3960 it
->method
= next_element_from_composition
;
3962 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3963 /* For a terminal, draw only the first character of the
3965 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3966 it
->len
= (STRINGP (it
->string
)
3967 ? string_char_to_byte (it
->string
, end
)
3968 : CHAR_TO_BYTE (end
)) - pos_byte
;
3969 it
->stop_charpos
= end
;
3970 handled
= HANDLED_RETURN
;
3979 /***********************************************************************
3981 ***********************************************************************/
3983 /* The following structure is used to record overlay strings for
3984 later sorting in load_overlay_strings. */
3986 struct overlay_entry
3988 Lisp_Object overlay
;
3995 /* Set up iterator IT from overlay strings at its current position.
3996 Called from handle_stop. */
3998 static enum prop_handled
3999 handle_overlay_change (it
)
4002 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4003 return HANDLED_RECOMPUTE_PROPS
;
4005 return HANDLED_NORMALLY
;
4009 /* Set up the next overlay string for delivery by IT, if there is an
4010 overlay string to deliver. Called by set_iterator_to_next when the
4011 end of the current overlay string is reached. If there are more
4012 overlay strings to display, IT->string and
4013 IT->current.overlay_string_index are set appropriately here.
4014 Otherwise IT->string is set to nil. */
4017 next_overlay_string (it
)
4020 ++it
->current
.overlay_string_index
;
4021 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4023 /* No more overlay strings. Restore IT's settings to what
4024 they were before overlay strings were processed, and
4025 continue to deliver from current_buffer. */
4026 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4029 xassert (it
->stop_charpos
>= BEGV
4030 && it
->stop_charpos
<= it
->end_charpos
);
4032 it
->current
.overlay_string_index
= -1;
4033 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4034 it
->n_overlay_strings
= 0;
4035 it
->method
= next_element_from_buffer
;
4037 /* If we're at the end of the buffer, record that we have
4038 processed the overlay strings there already, so that
4039 next_element_from_buffer doesn't try it again. */
4040 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4041 it
->overlay_strings_at_end_processed_p
= 1;
4043 /* If we have to display `...' for invisible text, set
4044 the iterator up for that. */
4045 if (display_ellipsis_p
)
4046 setup_for_ellipsis (it
);
4050 /* There are more overlay strings to process. If
4051 IT->current.overlay_string_index has advanced to a position
4052 where we must load IT->overlay_strings with more strings, do
4054 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4056 if (it
->current
.overlay_string_index
&& i
== 0)
4057 load_overlay_strings (it
, 0);
4059 /* Initialize IT to deliver display elements from the overlay
4061 it
->string
= it
->overlay_strings
[i
];
4062 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4063 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4064 it
->method
= next_element_from_string
;
4065 it
->stop_charpos
= 0;
4072 /* Compare two overlay_entry structures E1 and E2. Used as a
4073 comparison function for qsort in load_overlay_strings. Overlay
4074 strings for the same position are sorted so that
4076 1. All after-strings come in front of before-strings, except
4077 when they come from the same overlay.
4079 2. Within after-strings, strings are sorted so that overlay strings
4080 from overlays with higher priorities come first.
4082 2. Within before-strings, strings are sorted so that overlay
4083 strings from overlays with higher priorities come last.
4085 Value is analogous to strcmp. */
4089 compare_overlay_entries (e1
, e2
)
4092 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4093 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4096 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4098 /* Let after-strings appear in front of before-strings if
4099 they come from different overlays. */
4100 if (EQ (entry1
->overlay
, entry2
->overlay
))
4101 result
= entry1
->after_string_p
? 1 : -1;
4103 result
= entry1
->after_string_p
? -1 : 1;
4105 else if (entry1
->after_string_p
)
4106 /* After-strings sorted in order of decreasing priority. */
4107 result
= entry2
->priority
- entry1
->priority
;
4109 /* Before-strings sorted in order of increasing priority. */
4110 result
= entry1
->priority
- entry2
->priority
;
4116 /* Load the vector IT->overlay_strings with overlay strings from IT's
4117 current buffer position, or from CHARPOS if that is > 0. Set
4118 IT->n_overlays to the total number of overlay strings found.
4120 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4121 a time. On entry into load_overlay_strings,
4122 IT->current.overlay_string_index gives the number of overlay
4123 strings that have already been loaded by previous calls to this
4126 IT->add_overlay_start contains an additional overlay start
4127 position to consider for taking overlay strings from, if non-zero.
4128 This position comes into play when the overlay has an `invisible'
4129 property, and both before and after-strings. When we've skipped to
4130 the end of the overlay, because of its `invisible' property, we
4131 nevertheless want its before-string to appear.
4132 IT->add_overlay_start will contain the overlay start position
4135 Overlay strings are sorted so that after-string strings come in
4136 front of before-string strings. Within before and after-strings,
4137 strings are sorted by overlay priority. See also function
4138 compare_overlay_entries. */
4141 load_overlay_strings (it
, charpos
)
4145 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4146 Lisp_Object overlay
, window
, str
, invisible
;
4147 struct Lisp_Overlay
*ov
;
4150 int n
= 0, i
, j
, invis_p
;
4151 struct overlay_entry
*entries
4152 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4155 charpos
= IT_CHARPOS (*it
);
4157 /* Append the overlay string STRING of overlay OVERLAY to vector
4158 `entries' which has size `size' and currently contains `n'
4159 elements. AFTER_P non-zero means STRING is an after-string of
4161 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4164 Lisp_Object priority; \
4168 int new_size = 2 * size; \
4169 struct overlay_entry *old = entries; \
4171 (struct overlay_entry *) alloca (new_size \
4172 * sizeof *entries); \
4173 bcopy (old, entries, size * sizeof *entries); \
4177 entries[n].string = (STRING); \
4178 entries[n].overlay = (OVERLAY); \
4179 priority = Foverlay_get ((OVERLAY), Qpriority); \
4180 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4181 entries[n].after_string_p = (AFTER_P); \
4186 /* Process overlay before the overlay center. */
4187 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4189 XSETMISC (overlay
, ov
);
4190 xassert (OVERLAYP (overlay
));
4191 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4192 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4197 /* Skip this overlay if it doesn't start or end at IT's current
4199 if (end
!= charpos
&& start
!= charpos
)
4202 /* Skip this overlay if it doesn't apply to IT->w. */
4203 window
= Foverlay_get (overlay
, Qwindow
);
4204 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4207 /* If the text ``under'' the overlay is invisible, both before-
4208 and after-strings from this overlay are visible; start and
4209 end position are indistinguishable. */
4210 invisible
= Foverlay_get (overlay
, Qinvisible
);
4211 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4213 /* If overlay has a non-empty before-string, record it. */
4214 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4215 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4217 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4219 /* If overlay has a non-empty after-string, record it. */
4220 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4221 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4223 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4226 /* Process overlays after the overlay center. */
4227 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4229 XSETMISC (overlay
, ov
);
4230 xassert (OVERLAYP (overlay
));
4231 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4232 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4234 if (start
> charpos
)
4237 /* Skip this overlay if it doesn't start or end at IT's current
4239 if (end
!= charpos
&& start
!= charpos
)
4242 /* Skip this overlay if it doesn't apply to IT->w. */
4243 window
= Foverlay_get (overlay
, Qwindow
);
4244 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4247 /* If the text ``under'' the overlay is invisible, it has a zero
4248 dimension, and both before- and after-strings apply. */
4249 invisible
= Foverlay_get (overlay
, Qinvisible
);
4250 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4252 /* If overlay has a non-empty before-string, record it. */
4253 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4254 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4256 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4258 /* If overlay has a non-empty after-string, record it. */
4259 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4260 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4262 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4265 #undef RECORD_OVERLAY_STRING
4269 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4271 /* Record the total number of strings to process. */
4272 it
->n_overlay_strings
= n
;
4274 /* IT->current.overlay_string_index is the number of overlay strings
4275 that have already been consumed by IT. Copy some of the
4276 remaining overlay strings to IT->overlay_strings. */
4278 j
= it
->current
.overlay_string_index
;
4279 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4280 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4286 /* Get the first chunk of overlay strings at IT's current buffer
4287 position, or at CHARPOS if that is > 0. Value is non-zero if at
4288 least one overlay string was found. */
4291 get_overlay_strings (it
, charpos
)
4295 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4296 process. This fills IT->overlay_strings with strings, and sets
4297 IT->n_overlay_strings to the total number of strings to process.
4298 IT->pos.overlay_string_index has to be set temporarily to zero
4299 because load_overlay_strings needs this; it must be set to -1
4300 when no overlay strings are found because a zero value would
4301 indicate a position in the first overlay string. */
4302 it
->current
.overlay_string_index
= 0;
4303 load_overlay_strings (it
, charpos
);
4305 /* If we found overlay strings, set up IT to deliver display
4306 elements from the first one. Otherwise set up IT to deliver
4307 from current_buffer. */
4308 if (it
->n_overlay_strings
)
4310 /* Make sure we know settings in current_buffer, so that we can
4311 restore meaningful values when we're done with the overlay
4313 compute_stop_pos (it
);
4314 xassert (it
->face_id
>= 0);
4316 /* Save IT's settings. They are restored after all overlay
4317 strings have been processed. */
4318 xassert (it
->sp
== 0);
4321 /* Set up IT to deliver display elements from the first overlay
4323 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4324 it
->string
= it
->overlay_strings
[0];
4325 it
->stop_charpos
= 0;
4326 xassert (STRINGP (it
->string
));
4327 it
->end_charpos
= SCHARS (it
->string
);
4328 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4329 it
->method
= next_element_from_string
;
4334 it
->current
.overlay_string_index
= -1;
4335 it
->method
= next_element_from_buffer
;
4340 /* Value is non-zero if we found at least one overlay string. */
4341 return STRINGP (it
->string
);
4346 /***********************************************************************
4347 Saving and restoring state
4348 ***********************************************************************/
4350 /* Save current settings of IT on IT->stack. Called, for example,
4351 before setting up IT for an overlay string, to be able to restore
4352 IT's settings to what they were after the overlay string has been
4359 struct iterator_stack_entry
*p
;
4361 xassert (it
->sp
< 2);
4362 p
= it
->stack
+ it
->sp
;
4364 p
->stop_charpos
= it
->stop_charpos
;
4365 xassert (it
->face_id
>= 0);
4366 p
->face_id
= it
->face_id
;
4367 p
->string
= it
->string
;
4368 p
->pos
= it
->current
;
4369 p
->end_charpos
= it
->end_charpos
;
4370 p
->string_nchars
= it
->string_nchars
;
4372 p
->multibyte_p
= it
->multibyte_p
;
4373 p
->slice
= it
->slice
;
4374 p
->space_width
= it
->space_width
;
4375 p
->font_height
= it
->font_height
;
4376 p
->voffset
= it
->voffset
;
4377 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4378 p
->display_ellipsis_p
= 0;
4383 /* Restore IT's settings from IT->stack. Called, for example, when no
4384 more overlay strings must be processed, and we return to delivering
4385 display elements from a buffer, or when the end of a string from a
4386 `display' property is reached and we return to delivering display
4387 elements from an overlay string, or from a buffer. */
4393 struct iterator_stack_entry
*p
;
4395 xassert (it
->sp
> 0);
4397 p
= it
->stack
+ it
->sp
;
4398 it
->stop_charpos
= p
->stop_charpos
;
4399 it
->face_id
= p
->face_id
;
4400 it
->string
= p
->string
;
4401 it
->current
= p
->pos
;
4402 it
->end_charpos
= p
->end_charpos
;
4403 it
->string_nchars
= p
->string_nchars
;
4405 it
->multibyte_p
= p
->multibyte_p
;
4406 it
->slice
= p
->slice
;
4407 it
->space_width
= p
->space_width
;
4408 it
->font_height
= p
->font_height
;
4409 it
->voffset
= p
->voffset
;
4410 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4415 /***********************************************************************
4417 ***********************************************************************/
4419 /* Set IT's current position to the previous line start. */
4422 back_to_previous_line_start (it
)
4425 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4426 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4430 /* Move IT to the next line start.
4432 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4433 we skipped over part of the text (as opposed to moving the iterator
4434 continuously over the text). Otherwise, don't change the value
4437 Newlines may come from buffer text, overlay strings, or strings
4438 displayed via the `display' property. That's the reason we can't
4439 simply use find_next_newline_no_quit.
4441 Note that this function may not skip over invisible text that is so
4442 because of text properties and immediately follows a newline. If
4443 it would, function reseat_at_next_visible_line_start, when called
4444 from set_iterator_to_next, would effectively make invisible
4445 characters following a newline part of the wrong glyph row, which
4446 leads to wrong cursor motion. */
4449 forward_to_next_line_start (it
, skipped_p
)
4453 int old_selective
, newline_found_p
, n
;
4454 const int MAX_NEWLINE_DISTANCE
= 500;
4456 /* If already on a newline, just consume it to avoid unintended
4457 skipping over invisible text below. */
4458 if (it
->what
== IT_CHARACTER
4460 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4462 set_iterator_to_next (it
, 0);
4467 /* Don't handle selective display in the following. It's (a)
4468 unnecessary because it's done by the caller, and (b) leads to an
4469 infinite recursion because next_element_from_ellipsis indirectly
4470 calls this function. */
4471 old_selective
= it
->selective
;
4474 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4475 from buffer text. */
4476 for (n
= newline_found_p
= 0;
4477 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4478 n
+= STRINGP (it
->string
) ? 0 : 1)
4480 if (!get_next_display_element (it
))
4482 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4483 set_iterator_to_next (it
, 0);
4486 /* If we didn't find a newline near enough, see if we can use a
4488 if (!newline_found_p
)
4490 int start
= IT_CHARPOS (*it
);
4491 int limit
= find_next_newline_no_quit (start
, 1);
4494 xassert (!STRINGP (it
->string
));
4496 /* If there isn't any `display' property in sight, and no
4497 overlays, we can just use the position of the newline in
4499 if (it
->stop_charpos
>= limit
4500 || ((pos
= Fnext_single_property_change (make_number (start
),
4502 Qnil
, make_number (limit
)),
4504 && next_overlay_change (start
) == ZV
))
4506 IT_CHARPOS (*it
) = limit
;
4507 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4508 *skipped_p
= newline_found_p
= 1;
4512 while (get_next_display_element (it
)
4513 && !newline_found_p
)
4515 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4516 set_iterator_to_next (it
, 0);
4521 it
->selective
= old_selective
;
4522 return newline_found_p
;
4526 /* Set IT's current position to the previous visible line start. Skip
4527 invisible text that is so either due to text properties or due to
4528 selective display. Caution: this does not change IT->current_x and
4532 back_to_previous_visible_line_start (it
)
4537 /* Go back one newline if not on BEGV already. */
4538 if (IT_CHARPOS (*it
) > BEGV
)
4539 back_to_previous_line_start (it
);
4541 /* Move over lines that are invisible because of selective display
4542 or text properties. */
4543 while (IT_CHARPOS (*it
) > BEGV
4548 /* If selective > 0, then lines indented more than that values
4550 if (it
->selective
> 0
4551 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4552 (double) it
->selective
)) /* iftc */
4558 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
4559 Qinvisible
, it
->window
);
4560 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4566 struct it it2
= *it
;
4568 if (handle_display_prop (&it2
) == HANDLED_RETURN
)
4572 /* Back one more newline if the current one is invisible. */
4574 back_to_previous_line_start (it
);
4577 xassert (IT_CHARPOS (*it
) >= BEGV
);
4578 xassert (IT_CHARPOS (*it
) == BEGV
4579 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4584 /* Reseat iterator IT at the previous visible line start. Skip
4585 invisible text that is so either due to text properties or due to
4586 selective display. At the end, update IT's overlay information,
4587 face information etc. */
4590 reseat_at_previous_visible_line_start (it
)
4593 back_to_previous_visible_line_start (it
);
4594 reseat (it
, it
->current
.pos
, 1);
4599 /* Reseat iterator IT on the next visible line start in the current
4600 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4601 preceding the line start. Skip over invisible text that is so
4602 because of selective display. Compute faces, overlays etc at the
4603 new position. Note that this function does not skip over text that
4604 is invisible because of text properties. */
4607 reseat_at_next_visible_line_start (it
, on_newline_p
)
4611 int newline_found_p
, skipped_p
= 0;
4613 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4615 /* Skip over lines that are invisible because they are indented
4616 more than the value of IT->selective. */
4617 if (it
->selective
> 0)
4618 while (IT_CHARPOS (*it
) < ZV
4619 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4620 (double) it
->selective
)) /* iftc */
4622 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4623 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4626 /* Position on the newline if that's what's requested. */
4627 if (on_newline_p
&& newline_found_p
)
4629 if (STRINGP (it
->string
))
4631 if (IT_STRING_CHARPOS (*it
) > 0)
4633 --IT_STRING_CHARPOS (*it
);
4634 --IT_STRING_BYTEPOS (*it
);
4637 else if (IT_CHARPOS (*it
) > BEGV
)
4641 reseat (it
, it
->current
.pos
, 0);
4645 reseat (it
, it
->current
.pos
, 0);
4652 /***********************************************************************
4653 Changing an iterator's position
4654 ***********************************************************************/
4656 /* Change IT's current position to POS in current_buffer. If FORCE_P
4657 is non-zero, always check for text properties at the new position.
4658 Otherwise, text properties are only looked up if POS >=
4659 IT->check_charpos of a property. */
4662 reseat (it
, pos
, force_p
)
4664 struct text_pos pos
;
4667 int original_pos
= IT_CHARPOS (*it
);
4669 reseat_1 (it
, pos
, 0);
4671 /* Determine where to check text properties. Avoid doing it
4672 where possible because text property lookup is very expensive. */
4674 || CHARPOS (pos
) > it
->stop_charpos
4675 || CHARPOS (pos
) < original_pos
)
4682 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4683 IT->stop_pos to POS, also. */
4686 reseat_1 (it
, pos
, set_stop_p
)
4688 struct text_pos pos
;
4691 /* Don't call this function when scanning a C string. */
4692 xassert (it
->s
== NULL
);
4694 /* POS must be a reasonable value. */
4695 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4697 it
->current
.pos
= it
->position
= pos
;
4698 XSETBUFFER (it
->object
, current_buffer
);
4699 it
->end_charpos
= ZV
;
4701 it
->current
.dpvec_index
= -1;
4702 it
->current
.overlay_string_index
= -1;
4703 IT_STRING_CHARPOS (*it
) = -1;
4704 IT_STRING_BYTEPOS (*it
) = -1;
4706 it
->method
= next_element_from_buffer
;
4707 /* RMS: I added this to fix a bug in move_it_vertically_backward
4708 where it->area continued to relate to the starting point
4709 for the backward motion. Bug report from
4710 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
4711 However, I am not sure whether reseat still does the right thing
4712 in general after this change. */
4713 it
->area
= TEXT_AREA
;
4714 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4716 it
->face_before_selective_p
= 0;
4719 it
->stop_charpos
= CHARPOS (pos
);
4723 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4724 If S is non-null, it is a C string to iterate over. Otherwise,
4725 STRING gives a Lisp string to iterate over.
4727 If PRECISION > 0, don't return more then PRECISION number of
4728 characters from the string.
4730 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4731 characters have been returned. FIELD_WIDTH < 0 means an infinite
4734 MULTIBYTE = 0 means disable processing of multibyte characters,
4735 MULTIBYTE > 0 means enable it,
4736 MULTIBYTE < 0 means use IT->multibyte_p.
4738 IT must be initialized via a prior call to init_iterator before
4739 calling this function. */
4742 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4747 int precision
, field_width
, multibyte
;
4749 /* No region in strings. */
4750 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4752 /* No text property checks performed by default, but see below. */
4753 it
->stop_charpos
= -1;
4755 /* Set iterator position and end position. */
4756 bzero (&it
->current
, sizeof it
->current
);
4757 it
->current
.overlay_string_index
= -1;
4758 it
->current
.dpvec_index
= -1;
4759 xassert (charpos
>= 0);
4761 /* If STRING is specified, use its multibyteness, otherwise use the
4762 setting of MULTIBYTE, if specified. */
4764 it
->multibyte_p
= multibyte
> 0;
4768 xassert (STRINGP (string
));
4769 it
->string
= string
;
4771 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4772 it
->method
= next_element_from_string
;
4773 it
->current
.string_pos
= string_pos (charpos
, string
);
4780 /* Note that we use IT->current.pos, not it->current.string_pos,
4781 for displaying C strings. */
4782 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4783 if (it
->multibyte_p
)
4785 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4786 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4790 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4791 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4794 it
->method
= next_element_from_c_string
;
4797 /* PRECISION > 0 means don't return more than PRECISION characters
4799 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4800 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4802 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4803 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4804 FIELD_WIDTH < 0 means infinite field width. This is useful for
4805 padding with `-' at the end of a mode line. */
4806 if (field_width
< 0)
4807 field_width
= INFINITY
;
4808 if (field_width
> it
->end_charpos
- charpos
)
4809 it
->end_charpos
= charpos
+ field_width
;
4811 /* Use the standard display table for displaying strings. */
4812 if (DISP_TABLE_P (Vstandard_display_table
))
4813 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4815 it
->stop_charpos
= charpos
;
4821 /***********************************************************************
4823 ***********************************************************************/
4825 /* Load IT's display element fields with information about the next
4826 display element from the current position of IT. Value is zero if
4827 end of buffer (or C string) is reached. */
4830 get_next_display_element (it
)
4833 /* Non-zero means that we found a display element. Zero means that
4834 we hit the end of what we iterate over. Performance note: the
4835 function pointer `method' used here turns out to be faster than
4836 using a sequence of if-statements. */
4837 int success_p
= (*it
->method
) (it
);
4839 if (it
->what
== IT_CHARACTER
)
4841 /* Map via display table or translate control characters.
4842 IT->c, IT->len etc. have been set to the next character by
4843 the function call above. If we have a display table, and it
4844 contains an entry for IT->c, translate it. Don't do this if
4845 IT->c itself comes from a display table, otherwise we could
4846 end up in an infinite recursion. (An alternative could be to
4847 count the recursion depth of this function and signal an
4848 error when a certain maximum depth is reached.) Is it worth
4850 if (success_p
&& it
->dpvec
== NULL
)
4855 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4858 struct Lisp_Vector
*v
= XVECTOR (dv
);
4860 /* Return the first character from the display table
4861 entry, if not empty. If empty, don't display the
4862 current character. */
4865 it
->dpvec_char_len
= it
->len
;
4866 it
->dpvec
= v
->contents
;
4867 it
->dpend
= v
->contents
+ v
->size
;
4868 it
->current
.dpvec_index
= 0;
4869 it
->method
= next_element_from_display_vector
;
4870 success_p
= get_next_display_element (it
);
4874 set_iterator_to_next (it
, 0);
4875 success_p
= get_next_display_element (it
);
4879 /* Translate control characters into `\003' or `^C' form.
4880 Control characters coming from a display table entry are
4881 currently not translated because we use IT->dpvec to hold
4882 the translation. This could easily be changed but I
4883 don't believe that it is worth doing.
4885 If it->multibyte_p is nonzero, eight-bit characters and
4886 non-printable multibyte characters are also translated to
4889 If it->multibyte_p is zero, eight-bit characters that
4890 don't have corresponding multibyte char code are also
4891 translated to octal form. */
4892 else if ((it
->c
< ' '
4893 && (it
->area
!= TEXT_AREA
4894 || (it
->c
!= '\n' && it
->c
!= '\t')))
4898 || !CHAR_PRINTABLE_P (it
->c
))
4900 && it
->c
== unibyte_char_to_multibyte (it
->c
))))
4902 /* IT->c is a control character which must be displayed
4903 either as '\003' or as `^C' where the '\\' and '^'
4904 can be defined in the display table. Fill
4905 IT->ctl_chars with glyphs for what we have to
4906 display. Then, set IT->dpvec to these glyphs. */
4909 if (it
->c
< 128 && it
->ctl_arrow_p
)
4911 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4913 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4914 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4915 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4917 g
= FAST_MAKE_GLYPH ('^', 0);
4918 XSETINT (it
->ctl_chars
[0], g
);
4920 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4921 XSETINT (it
->ctl_chars
[1], g
);
4923 /* Set up IT->dpvec and return first character from it. */
4924 it
->dpvec_char_len
= it
->len
;
4925 it
->dpvec
= it
->ctl_chars
;
4926 it
->dpend
= it
->dpvec
+ 2;
4927 it
->current
.dpvec_index
= 0;
4928 it
->method
= next_element_from_display_vector
;
4929 get_next_display_element (it
);
4933 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4938 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4940 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4941 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4942 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4944 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4946 if (SINGLE_BYTE_CHAR_P (it
->c
))
4947 str
[0] = it
->c
, len
= 1;
4950 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4953 /* It's an invalid character, which
4954 shouldn't happen actually, but due to
4955 bugs it may happen. Let's print the char
4956 as is, there's not much meaningful we can
4959 str
[1] = it
->c
>> 8;
4960 str
[2] = it
->c
>> 16;
4961 str
[3] = it
->c
>> 24;
4966 for (i
= 0; i
< len
; i
++)
4968 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4969 /* Insert three more glyphs into IT->ctl_chars for
4970 the octal display of the character. */
4971 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4972 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4973 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4974 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4975 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4976 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4979 /* Set up IT->dpvec and return the first character
4981 it
->dpvec_char_len
= it
->len
;
4982 it
->dpvec
= it
->ctl_chars
;
4983 it
->dpend
= it
->dpvec
+ len
* 4;
4984 it
->current
.dpvec_index
= 0;
4985 it
->method
= next_element_from_display_vector
;
4986 get_next_display_element (it
);
4991 /* Adjust face id for a multibyte character. There are no
4992 multibyte character in unibyte text. */
4995 && FRAME_WINDOW_P (it
->f
))
4997 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4998 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5002 /* Is this character the last one of a run of characters with
5003 box? If yes, set IT->end_of_box_run_p to 1. */
5010 it
->end_of_box_run_p
5011 = ((face_id
= face_after_it_pos (it
),
5012 face_id
!= it
->face_id
)
5013 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5014 face
->box
== FACE_NO_BOX
));
5017 /* Value is 0 if end of buffer or string reached. */
5022 /* Move IT to the next display element.
5024 RESEAT_P non-zero means if called on a newline in buffer text,
5025 skip to the next visible line start.
5027 Functions get_next_display_element and set_iterator_to_next are
5028 separate because I find this arrangement easier to handle than a
5029 get_next_display_element function that also increments IT's
5030 position. The way it is we can first look at an iterator's current
5031 display element, decide whether it fits on a line, and if it does,
5032 increment the iterator position. The other way around we probably
5033 would either need a flag indicating whether the iterator has to be
5034 incremented the next time, or we would have to implement a
5035 decrement position function which would not be easy to write. */
5038 set_iterator_to_next (it
, reseat_p
)
5042 /* Reset flags indicating start and end of a sequence of characters
5043 with box. Reset them at the start of this function because
5044 moving the iterator to a new position might set them. */
5045 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5047 if (it
->method
== next_element_from_buffer
)
5049 /* The current display element of IT is a character from
5050 current_buffer. Advance in the buffer, and maybe skip over
5051 invisible lines that are so because of selective display. */
5052 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5053 reseat_at_next_visible_line_start (it
, 0);
5056 xassert (it
->len
!= 0);
5057 IT_BYTEPOS (*it
) += it
->len
;
5058 IT_CHARPOS (*it
) += 1;
5059 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5062 else if (it
->method
== next_element_from_composition
)
5064 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5065 if (STRINGP (it
->string
))
5067 IT_STRING_BYTEPOS (*it
) += it
->len
;
5068 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5069 it
->method
= next_element_from_string
;
5070 goto consider_string_end
;
5074 IT_BYTEPOS (*it
) += it
->len
;
5075 IT_CHARPOS (*it
) += it
->cmp_len
;
5076 it
->method
= next_element_from_buffer
;
5079 else if (it
->method
== next_element_from_c_string
)
5081 /* Current display element of IT is from a C string. */
5082 IT_BYTEPOS (*it
) += it
->len
;
5083 IT_CHARPOS (*it
) += 1;
5085 else if (it
->method
== next_element_from_display_vector
)
5087 /* Current display element of IT is from a display table entry.
5088 Advance in the display table definition. Reset it to null if
5089 end reached, and continue with characters from buffers/
5091 ++it
->current
.dpvec_index
;
5093 /* Restore face of the iterator to what they were before the
5094 display vector entry (these entries may contain faces). */
5095 it
->face_id
= it
->saved_face_id
;
5097 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5100 it
->method
= next_element_from_c_string
;
5101 else if (STRINGP (it
->string
))
5102 it
->method
= next_element_from_string
;
5104 it
->method
= next_element_from_buffer
;
5107 it
->current
.dpvec_index
= -1;
5109 /* Skip over characters which were displayed via IT->dpvec. */
5110 if (it
->dpvec_char_len
< 0)
5111 reseat_at_next_visible_line_start (it
, 1);
5112 else if (it
->dpvec_char_len
> 0)
5114 it
->len
= it
->dpvec_char_len
;
5115 set_iterator_to_next (it
, reseat_p
);
5119 else if (it
->method
== next_element_from_string
)
5121 /* Current display element is a character from a Lisp string. */
5122 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5123 IT_STRING_BYTEPOS (*it
) += it
->len
;
5124 IT_STRING_CHARPOS (*it
) += 1;
5126 consider_string_end
:
5128 if (it
->current
.overlay_string_index
>= 0)
5130 /* IT->string is an overlay string. Advance to the
5131 next, if there is one. */
5132 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5133 next_overlay_string (it
);
5137 /* IT->string is not an overlay string. If we reached
5138 its end, and there is something on IT->stack, proceed
5139 with what is on the stack. This can be either another
5140 string, this time an overlay string, or a buffer. */
5141 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5145 if (!STRINGP (it
->string
))
5146 it
->method
= next_element_from_buffer
;
5148 goto consider_string_end
;
5152 else if (it
->method
== next_element_from_image
5153 || it
->method
== next_element_from_stretch
)
5155 /* The position etc with which we have to proceed are on
5156 the stack. The position may be at the end of a string,
5157 if the `display' property takes up the whole string. */
5160 if (STRINGP (it
->string
))
5162 it
->method
= next_element_from_string
;
5163 goto consider_string_end
;
5166 it
->method
= next_element_from_buffer
;
5169 /* There are no other methods defined, so this should be a bug. */
5172 xassert (it
->method
!= next_element_from_string
5173 || (STRINGP (it
->string
)
5174 && IT_STRING_CHARPOS (*it
) >= 0));
5178 /* Load IT's display element fields with information about the next
5179 display element which comes from a display table entry or from the
5180 result of translating a control character to one of the forms `^C'
5181 or `\003'. IT->dpvec holds the glyphs to return as characters. */
5184 next_element_from_display_vector (it
)
5188 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5190 /* Remember the current face id in case glyphs specify faces.
5191 IT's face is restored in set_iterator_to_next. */
5192 it
->saved_face_id
= it
->face_id
;
5194 if (INTEGERP (*it
->dpvec
)
5195 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5200 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5201 it
->c
= FAST_GLYPH_CHAR (g
);
5202 it
->len
= CHAR_BYTES (it
->c
);
5204 /* The entry may contain a face id to use. Such a face id is
5205 the id of a Lisp face, not a realized face. A face id of
5206 zero means no face is specified. */
5207 lface_id
= FAST_GLYPH_FACE (g
);
5210 /* The function returns -1 if lface_id is invalid. */
5211 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
5213 it
->face_id
= face_id
;
5217 /* Display table entry is invalid. Return a space. */
5218 it
->c
= ' ', it
->len
= 1;
5220 /* Don't change position and object of the iterator here. They are
5221 still the values of the character that had this display table
5222 entry or was translated, and that's what we want. */
5223 it
->what
= IT_CHARACTER
;
5228 /* Load IT with the next display element from Lisp string IT->string.
5229 IT->current.string_pos is the current position within the string.
5230 If IT->current.overlay_string_index >= 0, the Lisp string is an
5234 next_element_from_string (it
)
5237 struct text_pos position
;
5239 xassert (STRINGP (it
->string
));
5240 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5241 position
= it
->current
.string_pos
;
5243 /* Time to check for invisible text? */
5244 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5245 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5249 /* Since a handler may have changed IT->method, we must
5251 return get_next_display_element (it
);
5254 if (it
->current
.overlay_string_index
>= 0)
5256 /* Get the next character from an overlay string. In overlay
5257 strings, There is no field width or padding with spaces to
5259 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5264 else if (STRING_MULTIBYTE (it
->string
))
5266 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5267 const unsigned char *s
= (SDATA (it
->string
)
5268 + IT_STRING_BYTEPOS (*it
));
5269 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5273 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5279 /* Get the next character from a Lisp string that is not an
5280 overlay string. Such strings come from the mode line, for
5281 example. We may have to pad with spaces, or truncate the
5282 string. See also next_element_from_c_string. */
5283 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5288 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5290 /* Pad with spaces. */
5291 it
->c
= ' ', it
->len
= 1;
5292 CHARPOS (position
) = BYTEPOS (position
) = -1;
5294 else if (STRING_MULTIBYTE (it
->string
))
5296 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5297 const unsigned char *s
= (SDATA (it
->string
)
5298 + IT_STRING_BYTEPOS (*it
));
5299 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5303 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5308 /* Record what we have and where it came from. Note that we store a
5309 buffer position in IT->position although it could arguably be a
5311 it
->what
= IT_CHARACTER
;
5312 it
->object
= it
->string
;
5313 it
->position
= position
;
5318 /* Load IT with next display element from C string IT->s.
5319 IT->string_nchars is the maximum number of characters to return
5320 from the string. IT->end_charpos may be greater than
5321 IT->string_nchars when this function is called, in which case we
5322 may have to return padding spaces. Value is zero if end of string
5323 reached, including padding spaces. */
5326 next_element_from_c_string (it
)
5332 it
->what
= IT_CHARACTER
;
5333 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5336 /* IT's position can be greater IT->string_nchars in case a field
5337 width or precision has been specified when the iterator was
5339 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5341 /* End of the game. */
5345 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5347 /* Pad with spaces. */
5348 it
->c
= ' ', it
->len
= 1;
5349 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5351 else if (it
->multibyte_p
)
5353 /* Implementation note: The calls to strlen apparently aren't a
5354 performance problem because there is no noticeable performance
5355 difference between Emacs running in unibyte or multibyte mode. */
5356 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5357 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5361 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5367 /* Set up IT to return characters from an ellipsis, if appropriate.
5368 The definition of the ellipsis glyphs may come from a display table
5369 entry. This function Fills IT with the first glyph from the
5370 ellipsis if an ellipsis is to be displayed. */
5373 next_element_from_ellipsis (it
)
5376 if (it
->selective_display_ellipsis_p
)
5378 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
5380 /* Use the display table definition for `...'. Invalid glyphs
5381 will be handled by the method returning elements from dpvec. */
5382 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
5383 it
->dpvec_char_len
= it
->len
;
5384 it
->dpvec
= v
->contents
;
5385 it
->dpend
= v
->contents
+ v
->size
;
5386 it
->current
.dpvec_index
= 0;
5387 it
->method
= next_element_from_display_vector
;
5391 /* Use default `...' which is stored in default_invis_vector. */
5392 it
->dpvec_char_len
= it
->len
;
5393 it
->dpvec
= default_invis_vector
;
5394 it
->dpend
= default_invis_vector
+ 3;
5395 it
->current
.dpvec_index
= 0;
5396 it
->method
= next_element_from_display_vector
;
5401 /* The face at the current position may be different from the
5402 face we find after the invisible text. Remember what it
5403 was in IT->saved_face_id, and signal that it's there by
5404 setting face_before_selective_p. */
5405 it
->saved_face_id
= it
->face_id
;
5406 it
->method
= next_element_from_buffer
;
5407 reseat_at_next_visible_line_start (it
, 1);
5408 it
->face_before_selective_p
= 1;
5411 return get_next_display_element (it
);
5415 /* Deliver an image display element. The iterator IT is already
5416 filled with image information (done in handle_display_prop). Value
5421 next_element_from_image (it
)
5424 it
->what
= IT_IMAGE
;
5429 /* Fill iterator IT with next display element from a stretch glyph
5430 property. IT->object is the value of the text property. Value is
5434 next_element_from_stretch (it
)
5437 it
->what
= IT_STRETCH
;
5442 /* Load IT with the next display element from current_buffer. Value
5443 is zero if end of buffer reached. IT->stop_charpos is the next
5444 position at which to stop and check for text properties or buffer
5448 next_element_from_buffer (it
)
5453 /* Check this assumption, otherwise, we would never enter the
5454 if-statement, below. */
5455 xassert (IT_CHARPOS (*it
) >= BEGV
5456 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
5458 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
5460 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5462 int overlay_strings_follow_p
;
5464 /* End of the game, except when overlay strings follow that
5465 haven't been returned yet. */
5466 if (it
->overlay_strings_at_end_processed_p
)
5467 overlay_strings_follow_p
= 0;
5470 it
->overlay_strings_at_end_processed_p
= 1;
5471 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
5474 if (overlay_strings_follow_p
)
5475 success_p
= get_next_display_element (it
);
5479 it
->position
= it
->current
.pos
;
5486 return get_next_display_element (it
);
5491 /* No face changes, overlays etc. in sight, so just return a
5492 character from current_buffer. */
5495 /* Maybe run the redisplay end trigger hook. Performance note:
5496 This doesn't seem to cost measurable time. */
5497 if (it
->redisplay_end_trigger_charpos
5499 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
5500 run_redisplay_end_trigger_hook (it
);
5502 /* Get the next character, maybe multibyte. */
5503 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
5504 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
5506 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
5507 - IT_BYTEPOS (*it
));
5508 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
5511 it
->c
= *p
, it
->len
= 1;
5513 /* Record what we have and where it came from. */
5514 it
->what
= IT_CHARACTER
;;
5515 it
->object
= it
->w
->buffer
;
5516 it
->position
= it
->current
.pos
;
5518 /* Normally we return the character found above, except when we
5519 really want to return an ellipsis for selective display. */
5524 /* A value of selective > 0 means hide lines indented more
5525 than that number of columns. */
5526 if (it
->selective
> 0
5527 && IT_CHARPOS (*it
) + 1 < ZV
5528 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
5529 IT_BYTEPOS (*it
) + 1,
5530 (double) it
->selective
)) /* iftc */
5532 success_p
= next_element_from_ellipsis (it
);
5533 it
->dpvec_char_len
= -1;
5536 else if (it
->c
== '\r' && it
->selective
== -1)
5538 /* A value of selective == -1 means that everything from the
5539 CR to the end of the line is invisible, with maybe an
5540 ellipsis displayed for it. */
5541 success_p
= next_element_from_ellipsis (it
);
5542 it
->dpvec_char_len
= -1;
5547 /* Value is zero if end of buffer reached. */
5548 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
5553 /* Run the redisplay end trigger hook for IT. */
5556 run_redisplay_end_trigger_hook (it
)
5559 Lisp_Object args
[3];
5561 /* IT->glyph_row should be non-null, i.e. we should be actually
5562 displaying something, or otherwise we should not run the hook. */
5563 xassert (it
->glyph_row
);
5565 /* Set up hook arguments. */
5566 args
[0] = Qredisplay_end_trigger_functions
;
5567 args
[1] = it
->window
;
5568 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
5569 it
->redisplay_end_trigger_charpos
= 0;
5571 /* Since we are *trying* to run these functions, don't try to run
5572 them again, even if they get an error. */
5573 it
->w
->redisplay_end_trigger
= Qnil
;
5574 Frun_hook_with_args (3, args
);
5576 /* Notice if it changed the face of the character we are on. */
5577 handle_face_prop (it
);
5581 /* Deliver a composition display element. The iterator IT is already
5582 filled with composition information (done in
5583 handle_composition_prop). Value is always 1. */
5586 next_element_from_composition (it
)
5589 it
->what
= IT_COMPOSITION
;
5590 it
->position
= (STRINGP (it
->string
)
5591 ? it
->current
.string_pos
5598 /***********************************************************************
5599 Moving an iterator without producing glyphs
5600 ***********************************************************************/
5602 /* Move iterator IT to a specified buffer or X position within one
5603 line on the display without producing glyphs.
5605 OP should be a bit mask including some or all of these bits:
5606 MOVE_TO_X: Stop on reaching x-position TO_X.
5607 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5608 Regardless of OP's value, stop in reaching the end of the display line.
5610 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5611 This means, in particular, that TO_X includes window's horizontal
5614 The return value has several possible values that
5615 say what condition caused the scan to stop:
5617 MOVE_POS_MATCH_OR_ZV
5618 - when TO_POS or ZV was reached.
5621 -when TO_X was reached before TO_POS or ZV were reached.
5624 - when we reached the end of the display area and the line must
5628 - when we reached the end of the display area and the line is
5632 - when we stopped at a line end, i.e. a newline or a CR and selective
5635 static enum move_it_result
5636 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5638 int to_charpos
, to_x
, op
;
5640 enum move_it_result result
= MOVE_UNDEFINED
;
5641 struct glyph_row
*saved_glyph_row
;
5643 /* Don't produce glyphs in produce_glyphs. */
5644 saved_glyph_row
= it
->glyph_row
;
5645 it
->glyph_row
= NULL
;
5647 #define BUFFER_POS_REACHED_P() \
5648 ((op & MOVE_TO_POS) != 0 \
5649 && BUFFERP (it->object) \
5650 && IT_CHARPOS (*it) >= to_charpos)
5654 int x
, i
, ascent
= 0, descent
= 0;
5656 /* Stop when ZV or TO_CHARPOS reached. */
5657 if (!get_next_display_element (it
)
5658 || BUFFER_POS_REACHED_P ())
5660 result
= MOVE_POS_MATCH_OR_ZV
;
5664 /* The call to produce_glyphs will get the metrics of the
5665 display element IT is loaded with. We record in x the
5666 x-position before this display element in case it does not
5670 /* Remember the line height so far in case the next element doesn't
5672 if (!it
->truncate_lines_p
)
5674 ascent
= it
->max_ascent
;
5675 descent
= it
->max_descent
;
5678 PRODUCE_GLYPHS (it
);
5680 if (it
->area
!= TEXT_AREA
)
5682 set_iterator_to_next (it
, 1);
5686 /* The number of glyphs we get back in IT->nglyphs will normally
5687 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5688 character on a terminal frame, or (iii) a line end. For the
5689 second case, IT->nglyphs - 1 padding glyphs will be present
5690 (on X frames, there is only one glyph produced for a
5691 composite character.
5693 The behavior implemented below means, for continuation lines,
5694 that as many spaces of a TAB as fit on the current line are
5695 displayed there. For terminal frames, as many glyphs of a
5696 multi-glyph character are displayed in the current line, too.
5697 This is what the old redisplay code did, and we keep it that
5698 way. Under X, the whole shape of a complex character must
5699 fit on the line or it will be completely displayed in the
5702 Note that both for tabs and padding glyphs, all glyphs have
5706 /* More than one glyph or glyph doesn't fit on line. All
5707 glyphs have the same width. */
5708 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5711 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5713 new_x
= x
+ single_glyph_width
;
5715 /* We want to leave anything reaching TO_X to the caller. */
5716 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5719 result
= MOVE_X_REACHED
;
5722 else if (/* Lines are continued. */
5723 !it
->truncate_lines_p
5724 && (/* And glyph doesn't fit on the line. */
5725 new_x
> it
->last_visible_x
5726 /* Or it fits exactly and we're on a window
5728 || (new_x
== it
->last_visible_x
5729 && FRAME_WINDOW_P (it
->f
))))
5731 if (/* IT->hpos == 0 means the very first glyph
5732 doesn't fit on the line, e.g. a wide image. */
5734 || (new_x
== it
->last_visible_x
5735 && FRAME_WINDOW_P (it
->f
)))
5738 it
->current_x
= new_x
;
5739 if (i
== it
->nglyphs
- 1)
5741 set_iterator_to_next (it
, 1);
5742 #ifdef HAVE_WINDOW_SYSTEM
5743 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
5745 if (!get_next_display_element (it
)
5746 || BUFFER_POS_REACHED_P ())
5748 result
= MOVE_POS_MATCH_OR_ZV
;
5751 if (ITERATOR_AT_END_OF_LINE_P (it
))
5753 result
= MOVE_NEWLINE_OR_CR
;
5757 #endif /* HAVE_WINDOW_SYSTEM */
5763 it
->max_ascent
= ascent
;
5764 it
->max_descent
= descent
;
5767 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5769 result
= MOVE_LINE_CONTINUED
;
5772 else if (new_x
> it
->first_visible_x
)
5774 /* Glyph is visible. Increment number of glyphs that
5775 would be displayed. */
5780 /* Glyph is completely off the left margin of the display
5781 area. Nothing to do. */
5785 if (result
!= MOVE_UNDEFINED
)
5788 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5790 /* Stop when TO_X specified and reached. This check is
5791 necessary here because of lines consisting of a line end,
5792 only. The line end will not produce any glyphs and we
5793 would never get MOVE_X_REACHED. */
5794 xassert (it
->nglyphs
== 0);
5795 result
= MOVE_X_REACHED
;
5799 /* Is this a line end? If yes, we're done. */
5800 if (ITERATOR_AT_END_OF_LINE_P (it
))
5802 result
= MOVE_NEWLINE_OR_CR
;
5806 /* The current display element has been consumed. Advance
5808 set_iterator_to_next (it
, 1);
5810 /* Stop if lines are truncated and IT's current x-position is
5811 past the right edge of the window now. */
5812 if (it
->truncate_lines_p
5813 && it
->current_x
>= it
->last_visible_x
)
5815 #ifdef HAVE_WINDOW_SYSTEM
5816 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
5818 if (!get_next_display_element (it
)
5819 || BUFFER_POS_REACHED_P ())
5821 result
= MOVE_POS_MATCH_OR_ZV
;
5824 if (ITERATOR_AT_END_OF_LINE_P (it
))
5826 result
= MOVE_NEWLINE_OR_CR
;
5830 #endif /* HAVE_WINDOW_SYSTEM */
5831 result
= MOVE_LINE_TRUNCATED
;
5836 #undef BUFFER_POS_REACHED_P
5838 /* Restore the iterator settings altered at the beginning of this
5840 it
->glyph_row
= saved_glyph_row
;
5845 /* Move IT forward until it satisfies one or more of the criteria in
5846 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
5848 OP is a bit-mask that specifies where to stop, and in particular,
5849 which of those four position arguments makes a difference. See the
5850 description of enum move_operation_enum.
5852 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5853 screen line, this function will set IT to the next position >
5857 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5859 int to_charpos
, to_x
, to_y
, to_vpos
;
5862 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5868 if (op
& MOVE_TO_VPOS
)
5870 /* If no TO_CHARPOS and no TO_X specified, stop at the
5871 start of the line TO_VPOS. */
5872 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5874 if (it
->vpos
== to_vpos
)
5880 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5884 /* TO_VPOS >= 0 means stop at TO_X in the line at
5885 TO_VPOS, or at TO_POS, whichever comes first. */
5886 if (it
->vpos
== to_vpos
)
5892 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5894 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5899 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5901 /* We have reached TO_X but not in the line we want. */
5902 skip
= move_it_in_display_line_to (it
, to_charpos
,
5904 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5912 else if (op
& MOVE_TO_Y
)
5914 struct it it_backup
;
5916 /* TO_Y specified means stop at TO_X in the line containing
5917 TO_Y---or at TO_CHARPOS if this is reached first. The
5918 problem is that we can't really tell whether the line
5919 contains TO_Y before we have completely scanned it, and
5920 this may skip past TO_X. What we do is to first scan to
5923 If TO_X is not specified, use a TO_X of zero. The reason
5924 is to make the outcome of this function more predictable.
5925 If we didn't use TO_X == 0, we would stop at the end of
5926 the line which is probably not what a caller would expect
5928 skip
= move_it_in_display_line_to (it
, to_charpos
,
5932 | (op
& MOVE_TO_POS
)));
5934 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5935 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5941 /* If TO_X was reached, we would like to know whether TO_Y
5942 is in the line. This can only be said if we know the
5943 total line height which requires us to scan the rest of
5945 if (skip
== MOVE_X_REACHED
)
5948 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5949 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5951 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5954 /* Now, decide whether TO_Y is in this line. */
5955 line_height
= it
->max_ascent
+ it
->max_descent
;
5956 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5958 if (to_y
>= it
->current_y
5959 && to_y
< it
->current_y
+ line_height
)
5961 if (skip
== MOVE_X_REACHED
)
5962 /* If TO_Y is in this line and TO_X was reached above,
5963 we scanned too far. We have to restore IT's settings
5964 to the ones before skipping. */
5968 else if (skip
== MOVE_X_REACHED
)
5971 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5979 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5983 case MOVE_POS_MATCH_OR_ZV
:
5987 case MOVE_NEWLINE_OR_CR
:
5988 set_iterator_to_next (it
, 1);
5989 it
->continuation_lines_width
= 0;
5992 case MOVE_LINE_TRUNCATED
:
5993 it
->continuation_lines_width
= 0;
5994 reseat_at_next_visible_line_start (it
, 0);
5995 if ((op
& MOVE_TO_POS
) != 0
5996 && IT_CHARPOS (*it
) > to_charpos
)
6003 case MOVE_LINE_CONTINUED
:
6004 it
->continuation_lines_width
+= it
->current_x
;
6011 /* Reset/increment for the next run. */
6012 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6013 it
->current_x
= it
->hpos
= 0;
6014 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6016 last_height
= it
->max_ascent
+ it
->max_descent
;
6017 last_max_ascent
= it
->max_ascent
;
6018 it
->max_ascent
= it
->max_descent
= 0;
6023 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6027 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6029 If DY > 0, move IT backward at least that many pixels. DY = 0
6030 means move IT backward to the preceding line start or BEGV. This
6031 function may move over more than DY pixels if IT->current_y - DY
6032 ends up in the middle of a line; in this case IT->current_y will be
6033 set to the top of the line moved to. */
6036 move_it_vertically_backward (it
, dy
)
6042 int start_pos
= IT_CHARPOS (*it
);
6046 /* Estimate how many newlines we must move back. */
6047 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6049 /* Set the iterator's position that many lines back. */
6050 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6051 back_to_previous_visible_line_start (it
);
6053 /* Reseat the iterator here. When moving backward, we don't want
6054 reseat to skip forward over invisible text, set up the iterator
6055 to deliver from overlay strings at the new position etc. So,
6056 use reseat_1 here. */
6057 reseat_1 (it
, it
->current
.pos
, 1);
6059 /* We are now surely at a line start. */
6060 it
->current_x
= it
->hpos
= 0;
6061 it
->continuation_lines_width
= 0;
6063 /* Move forward and see what y-distance we moved. First move to the
6064 start of the next line so that we get its height. We need this
6065 height to be able to tell whether we reached the specified
6068 it2
.max_ascent
= it2
.max_descent
= 0;
6069 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6070 MOVE_TO_POS
| MOVE_TO_VPOS
);
6071 xassert (IT_CHARPOS (*it
) >= BEGV
);
6074 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6075 xassert (IT_CHARPOS (*it
) >= BEGV
);
6076 /* H is the actual vertical distance from the position in *IT
6077 and the starting position. */
6078 h
= it2
.current_y
- it
->current_y
;
6079 /* NLINES is the distance in number of lines. */
6080 nlines
= it2
.vpos
- it
->vpos
;
6082 /* Correct IT's y and vpos position
6083 so that they are relative to the starting point. */
6089 /* DY == 0 means move to the start of the screen line. The
6090 value of nlines is > 0 if continuation lines were involved. */
6092 move_it_by_lines (it
, nlines
, 1);
6093 xassert (IT_CHARPOS (*it
) <= start_pos
);
6097 /* The y-position we try to reach, relative to *IT.
6098 Note that H has been subtracted in front of the if-statement. */
6099 int target_y
= it
->current_y
+ h
- dy
;
6100 int y0
= it3
.current_y
;
6101 int y1
= line_bottom_y (&it3
);
6102 int line_height
= y1
- y0
;
6104 /* If we did not reach target_y, try to move further backward if
6105 we can. If we moved too far backward, try to move forward. */
6106 if (target_y
< it
->current_y
6107 /* This is heuristic. In a window that's 3 lines high, with
6108 a line height of 13 pixels each, recentering with point
6109 on the bottom line will try to move -39/2 = 19 pixels
6110 backward. Try to avoid moving into the first line. */
6111 && it
->current_y
- target_y
> line_height
/ 3 * 2
6112 && IT_CHARPOS (*it
) > BEGV
)
6114 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6115 target_y
- it
->current_y
));
6116 move_it_vertically (it
, target_y
- it
->current_y
);
6117 xassert (IT_CHARPOS (*it
) >= BEGV
);
6119 else if (target_y
>= it
->current_y
+ line_height
6120 && IT_CHARPOS (*it
) < ZV
)
6122 /* Should move forward by at least one line, maybe more.
6124 Note: Calling move_it_by_lines can be expensive on
6125 terminal frames, where compute_motion is used (via
6126 vmotion) to do the job, when there are very long lines
6127 and truncate-lines is nil. That's the reason for
6128 treating terminal frames specially here. */
6130 if (!FRAME_WINDOW_P (it
->f
))
6131 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6136 move_it_by_lines (it
, 1, 1);
6138 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6141 xassert (IT_CHARPOS (*it
) >= BEGV
);
6147 /* Move IT by a specified amount of pixel lines DY. DY negative means
6148 move backwards. DY = 0 means move to start of screen line. At the
6149 end, IT will be on the start of a screen line. */
6152 move_it_vertically (it
, dy
)
6157 move_it_vertically_backward (it
, -dy
);
6160 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6161 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6162 MOVE_TO_POS
| MOVE_TO_Y
);
6163 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6165 /* If buffer ends in ZV without a newline, move to the start of
6166 the line to satisfy the post-condition. */
6167 if (IT_CHARPOS (*it
) == ZV
6168 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6169 move_it_by_lines (it
, 0, 0);
6174 /* Move iterator IT past the end of the text line it is in. */
6177 move_it_past_eol (it
)
6180 enum move_it_result rc
;
6182 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6183 if (rc
== MOVE_NEWLINE_OR_CR
)
6184 set_iterator_to_next (it
, 0);
6188 #if 0 /* Currently not used. */
6190 /* Return non-zero if some text between buffer positions START_CHARPOS
6191 and END_CHARPOS is invisible. IT->window is the window for text
6195 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6197 int start_charpos
, end_charpos
;
6199 Lisp_Object prop
, limit
;
6200 int invisible_found_p
;
6202 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6204 /* Is text at START invisible? */
6205 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6207 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6208 invisible_found_p
= 1;
6211 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6213 make_number (end_charpos
));
6214 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6217 return invisible_found_p
;
6223 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6224 negative means move up. DVPOS == 0 means move to the start of the
6225 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6226 NEED_Y_P is zero, IT->current_y will be left unchanged.
6228 Further optimization ideas: If we would know that IT->f doesn't use
6229 a face with proportional font, we could be faster for
6230 truncate-lines nil. */
6233 move_it_by_lines (it
, dvpos
, need_y_p
)
6235 int dvpos
, need_y_p
;
6237 struct position pos
;
6239 if (!FRAME_WINDOW_P (it
->f
))
6241 struct text_pos textpos
;
6243 /* We can use vmotion on frames without proportional fonts. */
6244 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6245 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6246 reseat (it
, textpos
, 1);
6247 it
->vpos
+= pos
.vpos
;
6248 it
->current_y
+= pos
.vpos
;
6250 else if (dvpos
== 0)
6252 /* DVPOS == 0 means move to the start of the screen line. */
6253 move_it_vertically_backward (it
, 0);
6254 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6257 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6261 int start_charpos
, i
;
6263 /* Start at the beginning of the screen line containing IT's
6265 move_it_vertically_backward (it
, 0);
6267 /* Go back -DVPOS visible lines and reseat the iterator there. */
6268 start_charpos
= IT_CHARPOS (*it
);
6269 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
6270 back_to_previous_visible_line_start (it
);
6271 reseat (it
, it
->current
.pos
, 1);
6272 it
->current_x
= it
->hpos
= 0;
6274 /* Above call may have moved too far if continuation lines
6275 are involved. Scan forward and see if it did. */
6277 it2
.vpos
= it2
.current_y
= 0;
6278 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6279 it
->vpos
-= it2
.vpos
;
6280 it
->current_y
-= it2
.current_y
;
6281 it
->current_x
= it
->hpos
= 0;
6283 /* If we moved too far, move IT some lines forward. */
6284 if (it2
.vpos
> -dvpos
)
6286 int delta
= it2
.vpos
+ dvpos
;
6287 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6292 /* Return 1 if IT points into the middle of a display vector. */
6295 in_display_vector_p (it
)
6298 return (it
->method
== next_element_from_display_vector
6299 && it
->current
.dpvec_index
> 0
6300 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6304 /***********************************************************************
6306 ***********************************************************************/
6309 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6313 add_to_log (format
, arg1
, arg2
)
6315 Lisp_Object arg1
, arg2
;
6317 Lisp_Object args
[3];
6318 Lisp_Object msg
, fmt
;
6321 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6323 /* Do nothing if called asynchronously. Inserting text into
6324 a buffer may call after-change-functions and alike and
6325 that would means running Lisp asynchronously. */
6326 if (handling_signal
)
6330 GCPRO4 (fmt
, msg
, arg1
, arg2
);
6332 args
[0] = fmt
= build_string (format
);
6335 msg
= Fformat (3, args
);
6337 len
= SBYTES (msg
) + 1;
6338 buffer
= (char *) alloca (len
);
6339 bcopy (SDATA (msg
), buffer
, len
);
6341 message_dolog (buffer
, len
- 1, 1, 0);
6346 /* Output a newline in the *Messages* buffer if "needs" one. */
6349 message_log_maybe_newline ()
6351 if (message_log_need_newline
)
6352 message_dolog ("", 0, 1, 0);
6356 /* Add a string M of length NBYTES to the message log, optionally
6357 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
6358 nonzero, means interpret the contents of M as multibyte. This
6359 function calls low-level routines in order to bypass text property
6360 hooks, etc. which might not be safe to run. */
6363 message_dolog (m
, nbytes
, nlflag
, multibyte
)
6365 int nbytes
, nlflag
, multibyte
;
6367 if (!NILP (Vmemory_full
))
6370 if (!NILP (Vmessage_log_max
))
6372 struct buffer
*oldbuf
;
6373 Lisp_Object oldpoint
, oldbegv
, oldzv
;
6374 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6375 int point_at_end
= 0;
6377 Lisp_Object old_deactivate_mark
, tem
;
6378 struct gcpro gcpro1
;
6380 old_deactivate_mark
= Vdeactivate_mark
;
6381 oldbuf
= current_buffer
;
6382 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
6383 current_buffer
->undo_list
= Qt
;
6385 oldpoint
= message_dolog_marker1
;
6386 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
6387 oldbegv
= message_dolog_marker2
;
6388 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
6389 oldzv
= message_dolog_marker3
;
6390 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
6391 GCPRO1 (old_deactivate_mark
);
6399 BEGV_BYTE
= BEG_BYTE
;
6402 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6404 /* Insert the string--maybe converting multibyte to single byte
6405 or vice versa, so that all the text fits the buffer. */
6407 && NILP (current_buffer
->enable_multibyte_characters
))
6409 int i
, c
, char_bytes
;
6410 unsigned char work
[1];
6412 /* Convert a multibyte string to single-byte
6413 for the *Message* buffer. */
6414 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
6416 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
6417 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6419 : multibyte_char_to_unibyte (c
, Qnil
));
6420 insert_1_both (work
, 1, 1, 1, 0, 0);
6423 else if (! multibyte
6424 && ! NILP (current_buffer
->enable_multibyte_characters
))
6426 int i
, c
, char_bytes
;
6427 unsigned char *msg
= (unsigned char *) m
;
6428 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6429 /* Convert a single-byte string to multibyte
6430 for the *Message* buffer. */
6431 for (i
= 0; i
< nbytes
; i
++)
6433 c
= unibyte_char_to_multibyte (msg
[i
]);
6434 char_bytes
= CHAR_STRING (c
, str
);
6435 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
6439 insert_1 (m
, nbytes
, 1, 0, 0);
6443 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
6444 insert_1 ("\n", 1, 1, 0, 0);
6446 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6448 this_bol_byte
= PT_BYTE
;
6450 /* See if this line duplicates the previous one.
6451 If so, combine duplicates. */
6454 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6456 prev_bol_byte
= PT_BYTE
;
6458 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
6459 this_bol
, this_bol_byte
);
6462 del_range_both (prev_bol
, prev_bol_byte
,
6463 this_bol
, this_bol_byte
, 0);
6469 /* If you change this format, don't forget to also
6470 change message_log_check_duplicate. */
6471 sprintf (dupstr
, " [%d times]", dup
);
6472 duplen
= strlen (dupstr
);
6473 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
6474 insert_1 (dupstr
, duplen
, 1, 0, 1);
6479 /* If we have more than the desired maximum number of lines
6480 in the *Messages* buffer now, delete the oldest ones.
6481 This is safe because we don't have undo in this buffer. */
6483 if (NATNUMP (Vmessage_log_max
))
6485 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
6486 -XFASTINT (Vmessage_log_max
) - 1, 0);
6487 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
6490 BEGV
= XMARKER (oldbegv
)->charpos
;
6491 BEGV_BYTE
= marker_byte_position (oldbegv
);
6500 ZV
= XMARKER (oldzv
)->charpos
;
6501 ZV_BYTE
= marker_byte_position (oldzv
);
6505 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6507 /* We can't do Fgoto_char (oldpoint) because it will run some
6509 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
6510 XMARKER (oldpoint
)->bytepos
);
6513 unchain_marker (XMARKER (oldpoint
));
6514 unchain_marker (XMARKER (oldbegv
));
6515 unchain_marker (XMARKER (oldzv
));
6517 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
6518 set_buffer_internal (oldbuf
);
6520 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6521 message_log_need_newline
= !nlflag
;
6522 Vdeactivate_mark
= old_deactivate_mark
;
6527 /* We are at the end of the buffer after just having inserted a newline.
6528 (Note: We depend on the fact we won't be crossing the gap.)
6529 Check to see if the most recent message looks a lot like the previous one.
6530 Return 0 if different, 1 if the new one should just replace it, or a
6531 value N > 1 if we should also append " [N times]". */
6534 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
6535 int prev_bol
, this_bol
;
6536 int prev_bol_byte
, this_bol_byte
;
6539 int len
= Z_BYTE
- 1 - this_bol_byte
;
6541 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
6542 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
6544 for (i
= 0; i
< len
; i
++)
6546 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
6554 if (*p1
++ == ' ' && *p1
++ == '[')
6557 while (*p1
>= '0' && *p1
<= '9')
6558 n
= n
* 10 + *p1
++ - '0';
6559 if (strncmp (p1
, " times]\n", 8) == 0)
6566 /* Display an echo area message M with a specified length of NBYTES
6567 bytes. The string may include null characters. If M is 0, clear
6568 out any existing message, and let the mini-buffer text show
6571 The buffer M must continue to exist until after the echo area gets
6572 cleared or some other message gets displayed there. This means do
6573 not pass text that is stored in a Lisp string; do not pass text in
6574 a buffer that was alloca'd. */
6577 message2 (m
, nbytes
, multibyte
)
6582 /* First flush out any partial line written with print. */
6583 message_log_maybe_newline ();
6585 message_dolog (m
, nbytes
, 1, multibyte
);
6586 message2_nolog (m
, nbytes
, multibyte
);
6590 /* The non-logging counterpart of message2. */
6593 message2_nolog (m
, nbytes
, multibyte
)
6595 int nbytes
, multibyte
;
6597 struct frame
*sf
= SELECTED_FRAME ();
6598 message_enable_multibyte
= multibyte
;
6602 if (noninteractive_need_newline
)
6603 putc ('\n', stderr
);
6604 noninteractive_need_newline
= 0;
6606 fwrite (m
, nbytes
, 1, stderr
);
6607 if (cursor_in_echo_area
== 0)
6608 fprintf (stderr
, "\n");
6611 /* A null message buffer means that the frame hasn't really been
6612 initialized yet. Error messages get reported properly by
6613 cmd_error, so this must be just an informative message; toss it. */
6614 else if (INTERACTIVE
6615 && sf
->glyphs_initialized_p
6616 && FRAME_MESSAGE_BUF (sf
))
6618 Lisp_Object mini_window
;
6621 /* Get the frame containing the mini-buffer
6622 that the selected frame is using. */
6623 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6624 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6626 FRAME_SAMPLE_VISIBILITY (f
);
6627 if (FRAME_VISIBLE_P (sf
)
6628 && ! FRAME_VISIBLE_P (f
))
6629 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
6633 set_message (m
, Qnil
, nbytes
, multibyte
);
6634 if (minibuffer_auto_raise
)
6635 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6638 clear_message (1, 1);
6640 do_pending_window_change (0);
6641 echo_area_display (1);
6642 do_pending_window_change (0);
6643 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6644 (*frame_up_to_date_hook
) (f
);
6649 /* Display an echo area message M with a specified length of NBYTES
6650 bytes. The string may include null characters. If M is not a
6651 string, clear out any existing message, and let the mini-buffer
6652 text show through. */
6655 message3 (m
, nbytes
, multibyte
)
6660 struct gcpro gcpro1
;
6664 /* First flush out any partial line written with print. */
6665 message_log_maybe_newline ();
6667 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
6668 message3_nolog (m
, nbytes
, multibyte
);
6674 /* The non-logging version of message3. */
6677 message3_nolog (m
, nbytes
, multibyte
)
6679 int nbytes
, multibyte
;
6681 struct frame
*sf
= SELECTED_FRAME ();
6682 message_enable_multibyte
= multibyte
;
6686 if (noninteractive_need_newline
)
6687 putc ('\n', stderr
);
6688 noninteractive_need_newline
= 0;
6690 fwrite (SDATA (m
), nbytes
, 1, stderr
);
6691 if (cursor_in_echo_area
== 0)
6692 fprintf (stderr
, "\n");
6695 /* A null message buffer means that the frame hasn't really been
6696 initialized yet. Error messages get reported properly by
6697 cmd_error, so this must be just an informative message; toss it. */
6698 else if (INTERACTIVE
6699 && sf
->glyphs_initialized_p
6700 && FRAME_MESSAGE_BUF (sf
))
6702 Lisp_Object mini_window
;
6706 /* Get the frame containing the mini-buffer
6707 that the selected frame is using. */
6708 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6709 frame
= XWINDOW (mini_window
)->frame
;
6712 FRAME_SAMPLE_VISIBILITY (f
);
6713 if (FRAME_VISIBLE_P (sf
)
6714 && !FRAME_VISIBLE_P (f
))
6715 Fmake_frame_visible (frame
);
6717 if (STRINGP (m
) && SCHARS (m
) > 0)
6719 set_message (NULL
, m
, nbytes
, multibyte
);
6720 if (minibuffer_auto_raise
)
6721 Fraise_frame (frame
);
6724 clear_message (1, 1);
6726 do_pending_window_change (0);
6727 echo_area_display (1);
6728 do_pending_window_change (0);
6729 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6730 (*frame_up_to_date_hook
) (f
);
6735 /* Display a null-terminated echo area message M. If M is 0, clear
6736 out any existing message, and let the mini-buffer text show through.
6738 The buffer M must continue to exist until after the echo area gets
6739 cleared or some other message gets displayed there. Do not pass
6740 text that is stored in a Lisp string. Do not pass text in a buffer
6741 that was alloca'd. */
6747 message2 (m
, (m
? strlen (m
) : 0), 0);
6751 /* The non-logging counterpart of message1. */
6757 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6760 /* Display a message M which contains a single %s
6761 which gets replaced with STRING. */
6764 message_with_string (m
, string
, log
)
6769 CHECK_STRING (string
);
6775 if (noninteractive_need_newline
)
6776 putc ('\n', stderr
);
6777 noninteractive_need_newline
= 0;
6778 fprintf (stderr
, m
, SDATA (string
));
6779 if (cursor_in_echo_area
== 0)
6780 fprintf (stderr
, "\n");
6784 else if (INTERACTIVE
)
6786 /* The frame whose minibuffer we're going to display the message on.
6787 It may be larger than the selected frame, so we need
6788 to use its buffer, not the selected frame's buffer. */
6789 Lisp_Object mini_window
;
6790 struct frame
*f
, *sf
= SELECTED_FRAME ();
6792 /* Get the frame containing the minibuffer
6793 that the selected frame is using. */
6794 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6795 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6797 /* A null message buffer means that the frame hasn't really been
6798 initialized yet. Error messages get reported properly by
6799 cmd_error, so this must be just an informative message; toss it. */
6800 if (FRAME_MESSAGE_BUF (f
))
6802 Lisp_Object args
[2], message
;
6803 struct gcpro gcpro1
, gcpro2
;
6805 args
[0] = build_string (m
);
6806 args
[1] = message
= string
;
6807 GCPRO2 (args
[0], message
);
6810 message
= Fformat (2, args
);
6813 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6815 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6819 /* Print should start at the beginning of the message
6820 buffer next time. */
6821 message_buf_print
= 0;
6827 /* Dump an informative message to the minibuf. If M is 0, clear out
6828 any existing message, and let the mini-buffer text show through. */
6832 message (m
, a1
, a2
, a3
)
6834 EMACS_INT a1
, a2
, a3
;
6840 if (noninteractive_need_newline
)
6841 putc ('\n', stderr
);
6842 noninteractive_need_newline
= 0;
6843 fprintf (stderr
, m
, a1
, a2
, a3
);
6844 if (cursor_in_echo_area
== 0)
6845 fprintf (stderr
, "\n");
6849 else if (INTERACTIVE
)
6851 /* The frame whose mini-buffer we're going to display the message
6852 on. It may be larger than the selected frame, so we need to
6853 use its buffer, not the selected frame's buffer. */
6854 Lisp_Object mini_window
;
6855 struct frame
*f
, *sf
= SELECTED_FRAME ();
6857 /* Get the frame containing the mini-buffer
6858 that the selected frame is using. */
6859 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6860 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6862 /* A null message buffer means that the frame hasn't really been
6863 initialized yet. Error messages get reported properly by
6864 cmd_error, so this must be just an informative message; toss
6866 if (FRAME_MESSAGE_BUF (f
))
6877 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6878 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6880 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6881 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6883 #endif /* NO_ARG_ARRAY */
6885 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6890 /* Print should start at the beginning of the message
6891 buffer next time. */
6892 message_buf_print
= 0;
6898 /* The non-logging version of message. */
6901 message_nolog (m
, a1
, a2
, a3
)
6903 EMACS_INT a1
, a2
, a3
;
6905 Lisp_Object old_log_max
;
6906 old_log_max
= Vmessage_log_max
;
6907 Vmessage_log_max
= Qnil
;
6908 message (m
, a1
, a2
, a3
);
6909 Vmessage_log_max
= old_log_max
;
6913 /* Display the current message in the current mini-buffer. This is
6914 only called from error handlers in process.c, and is not time
6920 if (!NILP (echo_area_buffer
[0]))
6923 string
= Fcurrent_message ();
6924 message3 (string
, SBYTES (string
),
6925 !NILP (current_buffer
->enable_multibyte_characters
));
6930 /* Make sure echo area buffers in `echo_buffers' are live.
6931 If they aren't, make new ones. */
6934 ensure_echo_area_buffers ()
6938 for (i
= 0; i
< 2; ++i
)
6939 if (!BUFFERP (echo_buffer
[i
])
6940 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6943 Lisp_Object old_buffer
;
6946 old_buffer
= echo_buffer
[i
];
6947 sprintf (name
, " *Echo Area %d*", i
);
6948 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6949 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6951 for (j
= 0; j
< 2; ++j
)
6952 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6953 echo_area_buffer
[j
] = echo_buffer
[i
];
6958 /* Call FN with args A1..A4 with either the current or last displayed
6959 echo_area_buffer as current buffer.
6961 WHICH zero means use the current message buffer
6962 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6963 from echo_buffer[] and clear it.
6965 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6966 suitable buffer from echo_buffer[] and clear it.
6968 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6969 that the current message becomes the last displayed one, make
6970 choose a suitable buffer for echo_area_buffer[0], and clear it.
6972 Value is what FN returns. */
6975 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6978 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6984 int this_one
, the_other
, clear_buffer_p
, rc
;
6985 int count
= SPECPDL_INDEX ();
6987 /* If buffers aren't live, make new ones. */
6988 ensure_echo_area_buffers ();
6993 this_one
= 0, the_other
= 1;
6995 this_one
= 1, the_other
= 0;
6998 this_one
= 0, the_other
= 1;
7001 /* We need a fresh one in case the current echo buffer equals
7002 the one containing the last displayed echo area message. */
7003 if (!NILP (echo_area_buffer
[this_one
])
7004 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
7005 echo_area_buffer
[this_one
] = Qnil
;
7008 /* Choose a suitable buffer from echo_buffer[] is we don't
7010 if (NILP (echo_area_buffer
[this_one
]))
7012 echo_area_buffer
[this_one
]
7013 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7014 ? echo_buffer
[the_other
]
7015 : echo_buffer
[this_one
]);
7019 buffer
= echo_area_buffer
[this_one
];
7021 /* Don't get confused by reusing the buffer used for echoing
7022 for a different purpose. */
7023 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7026 record_unwind_protect (unwind_with_echo_area_buffer
,
7027 with_echo_area_buffer_unwind_data (w
));
7029 /* Make the echo area buffer current. Note that for display
7030 purposes, it is not necessary that the displayed window's buffer
7031 == current_buffer, except for text property lookup. So, let's
7032 only set that buffer temporarily here without doing a full
7033 Fset_window_buffer. We must also change w->pointm, though,
7034 because otherwise an assertions in unshow_buffer fails, and Emacs
7036 set_buffer_internal_1 (XBUFFER (buffer
));
7040 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7043 current_buffer
->undo_list
= Qt
;
7044 current_buffer
->read_only
= Qnil
;
7045 specbind (Qinhibit_read_only
, Qt
);
7046 specbind (Qinhibit_modification_hooks
, Qt
);
7048 if (clear_buffer_p
&& Z
> BEG
)
7051 xassert (BEGV
>= BEG
);
7052 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7054 rc
= fn (a1
, a2
, a3
, a4
);
7056 xassert (BEGV
>= BEG
);
7057 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7059 unbind_to (count
, Qnil
);
7064 /* Save state that should be preserved around the call to the function
7065 FN called in with_echo_area_buffer. */
7068 with_echo_area_buffer_unwind_data (w
)
7074 /* Reduce consing by keeping one vector in
7075 Vwith_echo_area_save_vector. */
7076 vector
= Vwith_echo_area_save_vector
;
7077 Vwith_echo_area_save_vector
= Qnil
;
7080 vector
= Fmake_vector (make_number (7), Qnil
);
7082 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7083 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7084 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7088 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7089 AREF (vector
, i
) = w
->buffer
; ++i
;
7090 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7091 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7096 for (; i
< end
; ++i
)
7097 AREF (vector
, i
) = Qnil
;
7100 xassert (i
== ASIZE (vector
));
7105 /* Restore global state from VECTOR which was created by
7106 with_echo_area_buffer_unwind_data. */
7109 unwind_with_echo_area_buffer (vector
)
7112 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7113 Vdeactivate_mark
= AREF (vector
, 1);
7114 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7116 if (WINDOWP (AREF (vector
, 3)))
7119 Lisp_Object buffer
, charpos
, bytepos
;
7121 w
= XWINDOW (AREF (vector
, 3));
7122 buffer
= AREF (vector
, 4);
7123 charpos
= AREF (vector
, 5);
7124 bytepos
= AREF (vector
, 6);
7127 set_marker_both (w
->pointm
, buffer
,
7128 XFASTINT (charpos
), XFASTINT (bytepos
));
7131 Vwith_echo_area_save_vector
= vector
;
7136 /* Set up the echo area for use by print functions. MULTIBYTE_P
7137 non-zero means we will print multibyte. */
7140 setup_echo_area_for_printing (multibyte_p
)
7143 /* If we can't find an echo area any more, exit. */
7144 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7147 ensure_echo_area_buffers ();
7149 if (!message_buf_print
)
7151 /* A message has been output since the last time we printed.
7152 Choose a fresh echo area buffer. */
7153 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7154 echo_area_buffer
[0] = echo_buffer
[1];
7156 echo_area_buffer
[0] = echo_buffer
[0];
7158 /* Switch to that buffer and clear it. */
7159 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7160 current_buffer
->truncate_lines
= Qnil
;
7164 int count
= SPECPDL_INDEX ();
7165 specbind (Qinhibit_read_only
, Qt
);
7166 /* Note that undo recording is always disabled. */
7168 unbind_to (count
, Qnil
);
7170 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7172 /* Set up the buffer for the multibyteness we need. */
7174 != !NILP (current_buffer
->enable_multibyte_characters
))
7175 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7177 /* Raise the frame containing the echo area. */
7178 if (minibuffer_auto_raise
)
7180 struct frame
*sf
= SELECTED_FRAME ();
7181 Lisp_Object mini_window
;
7182 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7183 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7186 message_log_maybe_newline ();
7187 message_buf_print
= 1;
7191 if (NILP (echo_area_buffer
[0]))
7193 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7194 echo_area_buffer
[0] = echo_buffer
[1];
7196 echo_area_buffer
[0] = echo_buffer
[0];
7199 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7201 /* Someone switched buffers between print requests. */
7202 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7203 current_buffer
->truncate_lines
= Qnil
;
7209 /* Display an echo area message in window W. Value is non-zero if W's
7210 height is changed. If display_last_displayed_message_p is
7211 non-zero, display the message that was last displayed, otherwise
7212 display the current message. */
7215 display_echo_area (w
)
7218 int i
, no_message_p
, window_height_changed_p
, count
;
7220 /* Temporarily disable garbage collections while displaying the echo
7221 area. This is done because a GC can print a message itself.
7222 That message would modify the echo area buffer's contents while a
7223 redisplay of the buffer is going on, and seriously confuse
7225 count
= inhibit_garbage_collection ();
7227 /* If there is no message, we must call display_echo_area_1
7228 nevertheless because it resizes the window. But we will have to
7229 reset the echo_area_buffer in question to nil at the end because
7230 with_echo_area_buffer will sets it to an empty buffer. */
7231 i
= display_last_displayed_message_p
? 1 : 0;
7232 no_message_p
= NILP (echo_area_buffer
[i
]);
7234 window_height_changed_p
7235 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7236 display_echo_area_1
,
7237 (EMACS_INT
) w
, Qnil
, 0, 0);
7240 echo_area_buffer
[i
] = Qnil
;
7242 unbind_to (count
, Qnil
);
7243 return window_height_changed_p
;
7247 /* Helper for display_echo_area. Display the current buffer which
7248 contains the current echo area message in window W, a mini-window,
7249 a pointer to which is passed in A1. A2..A4 are currently not used.
7250 Change the height of W so that all of the message is displayed.
7251 Value is non-zero if height of W was changed. */
7254 display_echo_area_1 (a1
, a2
, a3
, a4
)
7259 struct window
*w
= (struct window
*) a1
;
7261 struct text_pos start
;
7262 int window_height_changed_p
= 0;
7264 /* Do this before displaying, so that we have a large enough glyph
7265 matrix for the display. */
7266 window_height_changed_p
= resize_mini_window (w
, 0);
7269 clear_glyph_matrix (w
->desired_matrix
);
7270 XSETWINDOW (window
, w
);
7271 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
7272 try_window (window
, start
);
7274 return window_height_changed_p
;
7278 /* Resize the echo area window to exactly the size needed for the
7279 currently displayed message, if there is one. If a mini-buffer
7280 is active, don't shrink it. */
7283 resize_echo_area_exactly ()
7285 if (BUFFERP (echo_area_buffer
[0])
7286 && WINDOWP (echo_area_window
))
7288 struct window
*w
= XWINDOW (echo_area_window
);
7290 Lisp_Object resize_exactly
;
7292 if (minibuf_level
== 0)
7293 resize_exactly
= Qt
;
7295 resize_exactly
= Qnil
;
7297 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7298 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7301 ++windows_or_buffers_changed
;
7302 ++update_mode_lines
;
7303 redisplay_internal (0);
7309 /* Callback function for with_echo_area_buffer, when used from
7310 resize_echo_area_exactly. A1 contains a pointer to the window to
7311 resize, EXACTLY non-nil means resize the mini-window exactly to the
7312 size of the text displayed. A3 and A4 are not used. Value is what
7313 resize_mini_window returns. */
7316 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
7318 Lisp_Object exactly
;
7321 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
7325 /* Resize mini-window W to fit the size of its contents. EXACT:P
7326 means size the window exactly to the size needed. Otherwise, it's
7327 only enlarged until W's buffer is empty. Value is non-zero if
7328 the window height has been changed. */
7331 resize_mini_window (w
, exact_p
)
7335 struct frame
*f
= XFRAME (w
->frame
);
7336 int window_height_changed_p
= 0;
7338 xassert (MINI_WINDOW_P (w
));
7340 /* Don't resize windows while redisplaying a window; it would
7341 confuse redisplay functions when the size of the window they are
7342 displaying changes from under them. Such a resizing can happen,
7343 for instance, when which-func prints a long message while
7344 we are running fontification-functions. We're running these
7345 functions with safe_call which binds inhibit-redisplay to t. */
7346 if (!NILP (Vinhibit_redisplay
))
7349 /* Nil means don't try to resize. */
7350 if (NILP (Vresize_mini_windows
)
7351 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
7354 if (!FRAME_MINIBUF_ONLY_P (f
))
7357 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7358 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
7359 int height
, max_height
;
7360 int unit
= FRAME_LINE_HEIGHT (f
);
7361 struct text_pos start
;
7362 struct buffer
*old_current_buffer
= NULL
;
7364 if (current_buffer
!= XBUFFER (w
->buffer
))
7366 old_current_buffer
= current_buffer
;
7367 set_buffer_internal (XBUFFER (w
->buffer
));
7370 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
7372 /* Compute the max. number of lines specified by the user. */
7373 if (FLOATP (Vmax_mini_window_height
))
7374 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
7375 else if (INTEGERP (Vmax_mini_window_height
))
7376 max_height
= XINT (Vmax_mini_window_height
);
7378 max_height
= total_height
/ 4;
7380 /* Correct that max. height if it's bogus. */
7381 max_height
= max (1, max_height
);
7382 max_height
= min (total_height
, max_height
);
7384 /* Find out the height of the text in the window. */
7385 if (it
.truncate_lines_p
)
7390 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
7391 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
7392 height
= it
.current_y
+ last_height
;
7394 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
7395 height
-= it
.extra_line_spacing
;
7396 height
= (height
+ unit
- 1) / unit
;
7399 /* Compute a suitable window start. */
7400 if (height
> max_height
)
7402 height
= max_height
;
7403 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
7404 move_it_vertically_backward (&it
, (height
- 1) * unit
);
7405 start
= it
.current
.pos
;
7408 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
7409 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
7411 if (EQ (Vresize_mini_windows
, Qgrow_only
))
7413 /* Let it grow only, until we display an empty message, in which
7414 case the window shrinks again. */
7415 if (height
> WINDOW_TOTAL_LINES (w
))
7417 int old_height
= WINDOW_TOTAL_LINES (w
);
7418 freeze_window_starts (f
, 1);
7419 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7420 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7422 else if (height
< WINDOW_TOTAL_LINES (w
)
7423 && (exact_p
|| BEGV
== ZV
))
7425 int old_height
= WINDOW_TOTAL_LINES (w
);
7426 freeze_window_starts (f
, 0);
7427 shrink_mini_window (w
);
7428 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7433 /* Always resize to exact size needed. */
7434 if (height
> WINDOW_TOTAL_LINES (w
))
7436 int old_height
= WINDOW_TOTAL_LINES (w
);
7437 freeze_window_starts (f
, 1);
7438 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7439 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7441 else if (height
< WINDOW_TOTAL_LINES (w
))
7443 int old_height
= WINDOW_TOTAL_LINES (w
);
7444 freeze_window_starts (f
, 0);
7445 shrink_mini_window (w
);
7449 freeze_window_starts (f
, 1);
7450 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7453 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7457 if (old_current_buffer
)
7458 set_buffer_internal (old_current_buffer
);
7461 return window_height_changed_p
;
7465 /* Value is the current message, a string, or nil if there is no
7473 if (NILP (echo_area_buffer
[0]))
7477 with_echo_area_buffer (0, 0, current_message_1
,
7478 (EMACS_INT
) &msg
, Qnil
, 0, 0);
7480 echo_area_buffer
[0] = Qnil
;
7488 current_message_1 (a1
, a2
, a3
, a4
)
7493 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
7496 *msg
= make_buffer_string (BEG
, Z
, 1);
7503 /* Push the current message on Vmessage_stack for later restauration
7504 by restore_message. Value is non-zero if the current message isn't
7505 empty. This is a relatively infrequent operation, so it's not
7506 worth optimizing. */
7512 msg
= current_message ();
7513 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
7514 return STRINGP (msg
);
7518 /* Restore message display from the top of Vmessage_stack. */
7525 xassert (CONSP (Vmessage_stack
));
7526 msg
= XCAR (Vmessage_stack
);
7528 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
7530 message3_nolog (msg
, 0, 0);
7534 /* Handler for record_unwind_protect calling pop_message. */
7537 pop_message_unwind (dummy
)
7544 /* Pop the top-most entry off Vmessage_stack. */
7549 xassert (CONSP (Vmessage_stack
));
7550 Vmessage_stack
= XCDR (Vmessage_stack
);
7554 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
7555 exits. If the stack is not empty, we have a missing pop_message
7559 check_message_stack ()
7561 if (!NILP (Vmessage_stack
))
7566 /* Truncate to NCHARS what will be displayed in the echo area the next
7567 time we display it---but don't redisplay it now. */
7570 truncate_echo_area (nchars
)
7574 echo_area_buffer
[0] = Qnil
;
7575 /* A null message buffer means that the frame hasn't really been
7576 initialized yet. Error messages get reported properly by
7577 cmd_error, so this must be just an informative message; toss it. */
7578 else if (!noninteractive
7580 && !NILP (echo_area_buffer
[0]))
7582 struct frame
*sf
= SELECTED_FRAME ();
7583 if (FRAME_MESSAGE_BUF (sf
))
7584 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
7589 /* Helper function for truncate_echo_area. Truncate the current
7590 message to at most NCHARS characters. */
7593 truncate_message_1 (nchars
, a2
, a3
, a4
)
7598 if (BEG
+ nchars
< Z
)
7599 del_range (BEG
+ nchars
, Z
);
7601 echo_area_buffer
[0] = Qnil
;
7606 /* Set the current message to a substring of S or STRING.
7608 If STRING is a Lisp string, set the message to the first NBYTES
7609 bytes from STRING. NBYTES zero means use the whole string. If
7610 STRING is multibyte, the message will be displayed multibyte.
7612 If S is not null, set the message to the first LEN bytes of S. LEN
7613 zero means use the whole string. MULTIBYTE_P non-zero means S is
7614 multibyte. Display the message multibyte in that case. */
7617 set_message (s
, string
, nbytes
, multibyte_p
)
7620 int nbytes
, multibyte_p
;
7622 message_enable_multibyte
7623 = ((s
&& multibyte_p
)
7624 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
7626 with_echo_area_buffer (0, -1, set_message_1
,
7627 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
7628 message_buf_print
= 0;
7629 help_echo_showing_p
= 0;
7633 /* Helper function for set_message. Arguments have the same meaning
7634 as there, with A1 corresponding to S and A2 corresponding to STRING
7635 This function is called with the echo area buffer being
7639 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
7642 EMACS_INT nbytes
, multibyte_p
;
7644 const char *s
= (const char *) a1
;
7645 Lisp_Object string
= a2
;
7649 /* Change multibyteness of the echo buffer appropriately. */
7650 if (message_enable_multibyte
7651 != !NILP (current_buffer
->enable_multibyte_characters
))
7652 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
7654 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
7656 /* Insert new message at BEG. */
7657 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7659 if (STRINGP (string
))
7664 nbytes
= SBYTES (string
);
7665 nchars
= string_byte_to_char (string
, nbytes
);
7667 /* This function takes care of single/multibyte conversion. We
7668 just have to ensure that the echo area buffer has the right
7669 setting of enable_multibyte_characters. */
7670 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7675 nbytes
= strlen (s
);
7677 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
7679 /* Convert from multi-byte to single-byte. */
7681 unsigned char work
[1];
7683 /* Convert a multibyte string to single-byte. */
7684 for (i
= 0; i
< nbytes
; i
+= n
)
7686 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
7687 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7689 : multibyte_char_to_unibyte (c
, Qnil
));
7690 insert_1_both (work
, 1, 1, 1, 0, 0);
7693 else if (!multibyte_p
7694 && !NILP (current_buffer
->enable_multibyte_characters
))
7696 /* Convert from single-byte to multi-byte. */
7698 const unsigned char *msg
= (const unsigned char *) s
;
7699 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7701 /* Convert a single-byte string to multibyte. */
7702 for (i
= 0; i
< nbytes
; i
++)
7704 c
= unibyte_char_to_multibyte (msg
[i
]);
7705 n
= CHAR_STRING (c
, str
);
7706 insert_1_both (str
, 1, n
, 1, 0, 0);
7710 insert_1 (s
, nbytes
, 1, 0, 0);
7717 /* Clear messages. CURRENT_P non-zero means clear the current
7718 message. LAST_DISPLAYED_P non-zero means clear the message
7722 clear_message (current_p
, last_displayed_p
)
7723 int current_p
, last_displayed_p
;
7727 echo_area_buffer
[0] = Qnil
;
7728 message_cleared_p
= 1;
7731 if (last_displayed_p
)
7732 echo_area_buffer
[1] = Qnil
;
7734 message_buf_print
= 0;
7737 /* Clear garbaged frames.
7739 This function is used where the old redisplay called
7740 redraw_garbaged_frames which in turn called redraw_frame which in
7741 turn called clear_frame. The call to clear_frame was a source of
7742 flickering. I believe a clear_frame is not necessary. It should
7743 suffice in the new redisplay to invalidate all current matrices,
7744 and ensure a complete redisplay of all windows. */
7747 clear_garbaged_frames ()
7751 Lisp_Object tail
, frame
;
7752 int changed_count
= 0;
7754 FOR_EACH_FRAME (tail
, frame
)
7756 struct frame
*f
= XFRAME (frame
);
7758 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7762 Fredraw_frame (frame
);
7763 f
->force_flush_display_p
= 1;
7765 clear_current_matrices (f
);
7774 ++windows_or_buffers_changed
;
7779 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7780 is non-zero update selected_frame. Value is non-zero if the
7781 mini-windows height has been changed. */
7784 echo_area_display (update_frame_p
)
7787 Lisp_Object mini_window
;
7790 int window_height_changed_p
= 0;
7791 struct frame
*sf
= SELECTED_FRAME ();
7793 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7794 w
= XWINDOW (mini_window
);
7795 f
= XFRAME (WINDOW_FRAME (w
));
7797 /* Don't display if frame is invisible or not yet initialized. */
7798 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7801 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7803 #ifdef HAVE_WINDOW_SYSTEM
7804 /* When Emacs starts, selected_frame may be a visible terminal
7805 frame, even if we run under a window system. If we let this
7806 through, a message would be displayed on the terminal. */
7807 if (EQ (selected_frame
, Vterminal_frame
)
7808 && !NILP (Vwindow_system
))
7810 #endif /* HAVE_WINDOW_SYSTEM */
7813 /* Redraw garbaged frames. */
7815 clear_garbaged_frames ();
7817 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7819 echo_area_window
= mini_window
;
7820 window_height_changed_p
= display_echo_area (w
);
7821 w
->must_be_updated_p
= 1;
7823 /* Update the display, unless called from redisplay_internal.
7824 Also don't update the screen during redisplay itself. The
7825 update will happen at the end of redisplay, and an update
7826 here could cause confusion. */
7827 if (update_frame_p
&& !redisplaying_p
)
7831 /* If the display update has been interrupted by pending
7832 input, update mode lines in the frame. Due to the
7833 pending input, it might have been that redisplay hasn't
7834 been called, so that mode lines above the echo area are
7835 garbaged. This looks odd, so we prevent it here. */
7836 if (!display_completed
)
7837 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7839 if (window_height_changed_p
7840 /* Don't do this if Emacs is shutting down. Redisplay
7841 needs to run hooks. */
7842 && !NILP (Vrun_hooks
))
7844 /* Must update other windows. Likewise as in other
7845 cases, don't let this update be interrupted by
7847 int count
= SPECPDL_INDEX ();
7848 specbind (Qredisplay_dont_pause
, Qt
);
7849 windows_or_buffers_changed
= 1;
7850 redisplay_internal (0);
7851 unbind_to (count
, Qnil
);
7853 else if (FRAME_WINDOW_P (f
) && n
== 0)
7855 /* Window configuration is the same as before.
7856 Can do with a display update of the echo area,
7857 unless we displayed some mode lines. */
7858 update_single_window (w
, 1);
7859 rif
->flush_display (f
);
7862 update_frame (f
, 1, 1);
7864 /* If cursor is in the echo area, make sure that the next
7865 redisplay displays the minibuffer, so that the cursor will
7866 be replaced with what the minibuffer wants. */
7867 if (cursor_in_echo_area
)
7868 ++windows_or_buffers_changed
;
7871 else if (!EQ (mini_window
, selected_window
))
7872 windows_or_buffers_changed
++;
7874 /* Last displayed message is now the current message. */
7875 echo_area_buffer
[1] = echo_area_buffer
[0];
7877 /* Prevent redisplay optimization in redisplay_internal by resetting
7878 this_line_start_pos. This is done because the mini-buffer now
7879 displays the message instead of its buffer text. */
7880 if (EQ (mini_window
, selected_window
))
7881 CHARPOS (this_line_start_pos
) = 0;
7883 return window_height_changed_p
;
7888 /***********************************************************************
7890 ***********************************************************************/
7893 /* The frame title buffering code is also used by Fformat_mode_line.
7894 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
7896 /* A buffer for constructing frame titles in it; allocated from the
7897 heap in init_xdisp and resized as needed in store_frame_title_char. */
7899 static char *frame_title_buf
;
7901 /* The buffer's end, and a current output position in it. */
7903 static char *frame_title_buf_end
;
7904 static char *frame_title_ptr
;
7907 /* Store a single character C for the frame title in frame_title_buf.
7908 Re-allocate frame_title_buf if necessary. */
7912 store_frame_title_char (char c
)
7914 store_frame_title_char (c
)
7918 /* If output position has reached the end of the allocated buffer,
7919 double the buffer's size. */
7920 if (frame_title_ptr
== frame_title_buf_end
)
7922 int len
= frame_title_ptr
- frame_title_buf
;
7923 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7924 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7925 frame_title_buf_end
= frame_title_buf
+ new_size
;
7926 frame_title_ptr
= frame_title_buf
+ len
;
7929 *frame_title_ptr
++ = c
;
7933 /* Store part of a frame title in frame_title_buf, beginning at
7934 frame_title_ptr. STR is the string to store. Do not copy
7935 characters that yield more columns than PRECISION; PRECISION <= 0
7936 means copy the whole string. Pad with spaces until FIELD_WIDTH
7937 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7938 pad. Called from display_mode_element when it is used to build a
7942 store_frame_title (str
, field_width
, precision
)
7943 const unsigned char *str
;
7944 int field_width
, precision
;
7949 /* Copy at most PRECISION chars from STR. */
7950 nbytes
= strlen (str
);
7951 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7953 store_frame_title_char (*str
++);
7955 /* Fill up with spaces until FIELD_WIDTH reached. */
7956 while (field_width
> 0
7959 store_frame_title_char (' ');
7966 #ifdef HAVE_WINDOW_SYSTEM
7968 /* Set the title of FRAME, if it has changed. The title format is
7969 Vicon_title_format if FRAME is iconified, otherwise it is
7970 frame_title_format. */
7973 x_consider_frame_title (frame
)
7976 struct frame
*f
= XFRAME (frame
);
7978 if (FRAME_WINDOW_P (f
)
7979 || FRAME_MINIBUF_ONLY_P (f
)
7980 || f
->explicit_name
)
7982 /* Do we have more than one visible frame on this X display? */
7985 struct buffer
*obuf
;
7989 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7991 Lisp_Object other_frame
= XCAR (tail
);
7992 struct frame
*tf
= XFRAME (other_frame
);
7995 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7996 && !FRAME_MINIBUF_ONLY_P (tf
)
7997 && !EQ (other_frame
, tip_frame
)
7998 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8002 /* Set global variable indicating that multiple frames exist. */
8003 multiple_frames
= CONSP (tail
);
8005 /* Switch to the buffer of selected window of the frame. Set up
8006 frame_title_ptr so that display_mode_element will output into it;
8007 then display the title. */
8008 obuf
= current_buffer
;
8009 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8010 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8011 frame_title_ptr
= frame_title_buf
;
8012 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8013 NULL
, DEFAULT_FACE_ID
);
8014 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8015 len
= frame_title_ptr
- frame_title_buf
;
8016 frame_title_ptr
= NULL
;
8017 set_buffer_internal_1 (obuf
);
8019 /* Set the title only if it's changed. This avoids consing in
8020 the common case where it hasn't. (If it turns out that we've
8021 already wasted too much time by walking through the list with
8022 display_mode_element, then we might need to optimize at a
8023 higher level than this.) */
8024 if (! STRINGP (f
->name
)
8025 || SBYTES (f
->name
) != len
8026 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
8027 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
8031 #endif /* not HAVE_WINDOW_SYSTEM */
8036 /***********************************************************************
8038 ***********************************************************************/
8041 /* Prepare for redisplay by updating menu-bar item lists when
8042 appropriate. This can call eval. */
8045 prepare_menu_bars ()
8048 struct gcpro gcpro1
, gcpro2
;
8050 Lisp_Object tooltip_frame
;
8052 #ifdef HAVE_WINDOW_SYSTEM
8053 tooltip_frame
= tip_frame
;
8055 tooltip_frame
= Qnil
;
8058 /* Update all frame titles based on their buffer names, etc. We do
8059 this before the menu bars so that the buffer-menu will show the
8060 up-to-date frame titles. */
8061 #ifdef HAVE_WINDOW_SYSTEM
8062 if (windows_or_buffers_changed
|| update_mode_lines
)
8064 Lisp_Object tail
, frame
;
8066 FOR_EACH_FRAME (tail
, frame
)
8069 if (!EQ (frame
, tooltip_frame
)
8070 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8071 x_consider_frame_title (frame
);
8074 #endif /* HAVE_WINDOW_SYSTEM */
8076 /* Update the menu bar item lists, if appropriate. This has to be
8077 done before any actual redisplay or generation of display lines. */
8078 all_windows
= (update_mode_lines
8079 || buffer_shared
> 1
8080 || windows_or_buffers_changed
);
8083 Lisp_Object tail
, frame
;
8084 int count
= SPECPDL_INDEX ();
8086 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8088 FOR_EACH_FRAME (tail
, frame
)
8092 /* Ignore tooltip frame. */
8093 if (EQ (frame
, tooltip_frame
))
8096 /* If a window on this frame changed size, report that to
8097 the user and clear the size-change flag. */
8098 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8100 Lisp_Object functions
;
8102 /* Clear flag first in case we get an error below. */
8103 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8104 functions
= Vwindow_size_change_functions
;
8105 GCPRO2 (tail
, functions
);
8107 while (CONSP (functions
))
8109 call1 (XCAR (functions
), frame
);
8110 functions
= XCDR (functions
);
8116 update_menu_bar (f
, 0);
8117 #ifdef HAVE_WINDOW_SYSTEM
8118 update_tool_bar (f
, 0);
8123 unbind_to (count
, Qnil
);
8127 struct frame
*sf
= SELECTED_FRAME ();
8128 update_menu_bar (sf
, 1);
8129 #ifdef HAVE_WINDOW_SYSTEM
8130 update_tool_bar (sf
, 1);
8134 /* Motif needs this. See comment in xmenu.c. Turn it off when
8135 pending_menu_activation is not defined. */
8136 #ifdef USE_X_TOOLKIT
8137 pending_menu_activation
= 0;
8142 /* Update the menu bar item list for frame F. This has to be done
8143 before we start to fill in any display lines, because it can call
8146 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8149 update_menu_bar (f
, save_match_data
)
8151 int save_match_data
;
8154 register struct window
*w
;
8156 /* If called recursively during a menu update, do nothing. This can
8157 happen when, for instance, an activate-menubar-hook causes a
8159 if (inhibit_menubar_update
)
8162 window
= FRAME_SELECTED_WINDOW (f
);
8163 w
= XWINDOW (window
);
8165 #if 0 /* The if statement below this if statement used to include the
8166 condition !NILP (w->update_mode_line), rather than using
8167 update_mode_lines directly, and this if statement may have
8168 been added to make that condition work. Now the if
8169 statement below matches its comment, this isn't needed. */
8170 if (update_mode_lines
)
8171 w
->update_mode_line
= Qt
;
8174 if (FRAME_WINDOW_P (f
)
8176 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8177 || defined (USE_GTK)
8178 FRAME_EXTERNAL_MENU_BAR (f
)
8180 FRAME_MENU_BAR_LINES (f
) > 0
8182 : FRAME_MENU_BAR_LINES (f
) > 0)
8184 /* If the user has switched buffers or windows, we need to
8185 recompute to reflect the new bindings. But we'll
8186 recompute when update_mode_lines is set too; that means
8187 that people can use force-mode-line-update to request
8188 that the menu bar be recomputed. The adverse effect on
8189 the rest of the redisplay algorithm is about the same as
8190 windows_or_buffers_changed anyway. */
8191 if (windows_or_buffers_changed
8192 /* This used to test w->update_mode_line, but we believe
8193 there is no need to recompute the menu in that case. */
8194 || update_mode_lines
8195 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8196 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8197 != !NILP (w
->last_had_star
))
8198 || ((!NILP (Vtransient_mark_mode
)
8199 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8200 != !NILP (w
->region_showing
)))
8202 struct buffer
*prev
= current_buffer
;
8203 int count
= SPECPDL_INDEX ();
8205 specbind (Qinhibit_menubar_update
, Qt
);
8207 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8208 if (save_match_data
)
8209 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8210 if (NILP (Voverriding_local_map_menu_flag
))
8212 specbind (Qoverriding_terminal_local_map
, Qnil
);
8213 specbind (Qoverriding_local_map
, Qnil
);
8216 /* Run the Lucid hook. */
8217 safe_run_hooks (Qactivate_menubar_hook
);
8219 /* If it has changed current-menubar from previous value,
8220 really recompute the menu-bar from the value. */
8221 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8222 call0 (Qrecompute_lucid_menubar
);
8224 safe_run_hooks (Qmenu_bar_update_hook
);
8225 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
8227 /* Redisplay the menu bar in case we changed it. */
8228 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8229 || defined (USE_GTK)
8230 if (FRAME_WINDOW_P (f
)
8231 #if defined (MAC_OS)
8232 /* All frames on Mac OS share the same menubar. So only the
8233 selected frame should be allowed to set it. */
8234 && f
== SELECTED_FRAME ()
8237 set_frame_menubar (f
, 0, 0);
8239 /* On a terminal screen, the menu bar is an ordinary screen
8240 line, and this makes it get updated. */
8241 w
->update_mode_line
= Qt
;
8242 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8243 /* In the non-toolkit version, the menu bar is an ordinary screen
8244 line, and this makes it get updated. */
8245 w
->update_mode_line
= Qt
;
8246 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8248 unbind_to (count
, Qnil
);
8249 set_buffer_internal_1 (prev
);
8256 /***********************************************************************
8258 ***********************************************************************/
8260 #ifdef HAVE_WINDOW_SYSTEM
8263 Nominal cursor position -- where to draw output.
8264 HPOS and VPOS are window relative glyph matrix coordinates.
8265 X and Y are window relative pixel coordinates. */
8267 struct cursor_pos output_cursor
;
8271 Set the global variable output_cursor to CURSOR. All cursor
8272 positions are relative to updated_window. */
8275 set_output_cursor (cursor
)
8276 struct cursor_pos
*cursor
;
8278 output_cursor
.hpos
= cursor
->hpos
;
8279 output_cursor
.vpos
= cursor
->vpos
;
8280 output_cursor
.x
= cursor
->x
;
8281 output_cursor
.y
= cursor
->y
;
8286 Set a nominal cursor position.
8288 HPOS and VPOS are column/row positions in a window glyph matrix. X
8289 and Y are window text area relative pixel positions.
8291 If this is done during an update, updated_window will contain the
8292 window that is being updated and the position is the future output
8293 cursor position for that window. If updated_window is null, use
8294 selected_window and display the cursor at the given position. */
8297 x_cursor_to (vpos
, hpos
, y
, x
)
8298 int vpos
, hpos
, y
, x
;
8302 /* If updated_window is not set, work on selected_window. */
8306 w
= XWINDOW (selected_window
);
8308 /* Set the output cursor. */
8309 output_cursor
.hpos
= hpos
;
8310 output_cursor
.vpos
= vpos
;
8311 output_cursor
.x
= x
;
8312 output_cursor
.y
= y
;
8314 /* If not called as part of an update, really display the cursor.
8315 This will also set the cursor position of W. */
8316 if (updated_window
== NULL
)
8319 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8320 if (rif
->flush_display_optional
)
8321 rif
->flush_display_optional (SELECTED_FRAME ());
8326 #endif /* HAVE_WINDOW_SYSTEM */
8329 /***********************************************************************
8331 ***********************************************************************/
8333 #ifdef HAVE_WINDOW_SYSTEM
8335 /* Where the mouse was last time we reported a mouse event. */
8337 FRAME_PTR last_mouse_frame
;
8339 /* Tool-bar item index of the item on which a mouse button was pressed
8342 int last_tool_bar_item
;
8345 /* Update the tool-bar item list for frame F. This has to be done
8346 before we start to fill in any display lines. Called from
8347 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8348 and restore it here. */
8351 update_tool_bar (f
, save_match_data
)
8353 int save_match_data
;
8356 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
8358 int do_update
= WINDOWP (f
->tool_bar_window
)
8359 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
8367 window
= FRAME_SELECTED_WINDOW (f
);
8368 w
= XWINDOW (window
);
8370 /* If the user has switched buffers or windows, we need to
8371 recompute to reflect the new bindings. But we'll
8372 recompute when update_mode_lines is set too; that means
8373 that people can use force-mode-line-update to request
8374 that the menu bar be recomputed. The adverse effect on
8375 the rest of the redisplay algorithm is about the same as
8376 windows_or_buffers_changed anyway. */
8377 if (windows_or_buffers_changed
8378 || !NILP (w
->update_mode_line
)
8379 || update_mode_lines
8380 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8381 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8382 != !NILP (w
->last_had_star
))
8383 || ((!NILP (Vtransient_mark_mode
)
8384 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8385 != !NILP (w
->region_showing
)))
8387 struct buffer
*prev
= current_buffer
;
8388 int count
= SPECPDL_INDEX ();
8389 Lisp_Object old_tool_bar
;
8390 struct gcpro gcpro1
;
8392 /* Set current_buffer to the buffer of the selected
8393 window of the frame, so that we get the right local
8395 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8397 /* Save match data, if we must. */
8398 if (save_match_data
)
8399 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8401 /* Make sure that we don't accidentally use bogus keymaps. */
8402 if (NILP (Voverriding_local_map_menu_flag
))
8404 specbind (Qoverriding_terminal_local_map
, Qnil
);
8405 specbind (Qoverriding_local_map
, Qnil
);
8408 old_tool_bar
= f
->tool_bar_items
;
8409 GCPRO1 (old_tool_bar
);
8411 /* Build desired tool-bar items from keymaps. */
8414 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
8417 /* Redisplay the tool-bar if we changed it. */
8418 if (! NILP (Fequal (old_tool_bar
, f
->tool_bar_items
)))
8419 w
->update_mode_line
= Qt
;
8423 unbind_to (count
, Qnil
);
8424 set_buffer_internal_1 (prev
);
8430 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8431 F's desired tool-bar contents. F->tool_bar_items must have
8432 been set up previously by calling prepare_menu_bars. */
8435 build_desired_tool_bar_string (f
)
8438 int i
, size
, size_needed
;
8439 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8440 Lisp_Object image
, plist
, props
;
8442 image
= plist
= props
= Qnil
;
8443 GCPRO3 (image
, plist
, props
);
8445 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
8446 Otherwise, make a new string. */
8448 /* The size of the string we might be able to reuse. */
8449 size
= (STRINGP (f
->desired_tool_bar_string
)
8450 ? SCHARS (f
->desired_tool_bar_string
)
8453 /* We need one space in the string for each image. */
8454 size_needed
= f
->n_tool_bar_items
;
8456 /* Reuse f->desired_tool_bar_string, if possible. */
8457 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
8458 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
8462 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
8463 Fremove_text_properties (make_number (0), make_number (size
),
8464 props
, f
->desired_tool_bar_string
);
8467 /* Put a `display' property on the string for the images to display,
8468 put a `menu_item' property on tool-bar items with a value that
8469 is the index of the item in F's tool-bar item vector. */
8470 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
8472 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
8474 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8475 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8476 int hmargin
, vmargin
, relief
, idx
, end
;
8477 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
8479 /* If image is a vector, choose the image according to the
8481 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
8482 if (VECTORP (image
))
8486 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
8487 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
8490 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
8491 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
8493 xassert (ASIZE (image
) >= idx
);
8494 image
= AREF (image
, idx
);
8499 /* Ignore invalid image specifications. */
8500 if (!valid_image_p (image
))
8503 /* Display the tool-bar button pressed, or depressed. */
8504 plist
= Fcopy_sequence (XCDR (image
));
8506 /* Compute margin and relief to draw. */
8507 relief
= (tool_bar_button_relief
>= 0
8508 ? tool_bar_button_relief
8509 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
8510 hmargin
= vmargin
= relief
;
8512 if (INTEGERP (Vtool_bar_button_margin
)
8513 && XINT (Vtool_bar_button_margin
) > 0)
8515 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
8516 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
8518 else if (CONSP (Vtool_bar_button_margin
))
8520 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
8521 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
8522 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
8524 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
8525 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
8526 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
8529 if (auto_raise_tool_bar_buttons_p
)
8531 /* Add a `:relief' property to the image spec if the item is
8535 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
8542 /* If image is selected, display it pressed, i.e. with a
8543 negative relief. If it's not selected, display it with a
8545 plist
= Fplist_put (plist
, QCrelief
,
8547 ? make_number (-relief
)
8548 : make_number (relief
)));
8553 /* Put a margin around the image. */
8554 if (hmargin
|| vmargin
)
8556 if (hmargin
== vmargin
)
8557 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
8559 plist
= Fplist_put (plist
, QCmargin
,
8560 Fcons (make_number (hmargin
),
8561 make_number (vmargin
)));
8564 /* If button is not enabled, and we don't have special images
8565 for the disabled state, make the image appear disabled by
8566 applying an appropriate algorithm to it. */
8567 if (!enabled_p
&& idx
< 0)
8568 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
8570 /* Put a `display' text property on the string for the image to
8571 display. Put a `menu-item' property on the string that gives
8572 the start of this item's properties in the tool-bar items
8574 image
= Fcons (Qimage
, plist
);
8575 props
= list4 (Qdisplay
, image
,
8576 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
8578 /* Let the last image hide all remaining spaces in the tool bar
8579 string. The string can be longer than needed when we reuse a
8581 if (i
+ 1 == f
->n_tool_bar_items
)
8582 end
= SCHARS (f
->desired_tool_bar_string
);
8585 Fadd_text_properties (make_number (i
), make_number (end
),
8586 props
, f
->desired_tool_bar_string
);
8594 /* Display one line of the tool-bar of frame IT->f. */
8597 display_tool_bar_line (it
)
8600 struct glyph_row
*row
= it
->glyph_row
;
8601 int max_x
= it
->last_visible_x
;
8604 prepare_desired_row (row
);
8605 row
->y
= it
->current_y
;
8607 /* Note that this isn't made use of if the face hasn't a box,
8608 so there's no need to check the face here. */
8609 it
->start_of_box_run_p
= 1;
8611 while (it
->current_x
< max_x
)
8613 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
8615 /* Get the next display element. */
8616 if (!get_next_display_element (it
))
8619 /* Produce glyphs. */
8620 x_before
= it
->current_x
;
8621 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
8622 PRODUCE_GLYPHS (it
);
8624 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
8629 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
8631 if (x
+ glyph
->pixel_width
> max_x
)
8633 /* Glyph doesn't fit on line. */
8634 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
8640 x
+= glyph
->pixel_width
;
8644 /* Stop at line ends. */
8645 if (ITERATOR_AT_END_OF_LINE_P (it
))
8648 set_iterator_to_next (it
, 1);
8653 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
8654 extend_face_to_end_of_line (it
);
8655 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
8656 last
->right_box_line_p
= 1;
8657 if (last
== row
->glyphs
[TEXT_AREA
])
8658 last
->left_box_line_p
= 1;
8659 compute_line_metrics (it
);
8661 /* If line is empty, make it occupy the rest of the tool-bar. */
8662 if (!row
->displays_text_p
)
8664 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
8665 row
->ascent
= row
->phys_ascent
= 0;
8668 row
->full_width_p
= 1;
8669 row
->continued_p
= 0;
8670 row
->truncated_on_left_p
= 0;
8671 row
->truncated_on_right_p
= 0;
8673 it
->current_x
= it
->hpos
= 0;
8674 it
->current_y
+= row
->height
;
8680 /* Value is the number of screen lines needed to make all tool-bar
8681 items of frame F visible. */
8684 tool_bar_lines_needed (f
)
8687 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8690 /* Initialize an iterator for iteration over
8691 F->desired_tool_bar_string in the tool-bar window of frame F. */
8692 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8693 it
.first_visible_x
= 0;
8694 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8695 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8697 while (!ITERATOR_AT_END_P (&it
))
8699 it
.glyph_row
= w
->desired_matrix
->rows
;
8700 clear_glyph_row (it
.glyph_row
);
8701 display_tool_bar_line (&it
);
8704 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
8708 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
8710 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
8719 frame
= selected_frame
;
8721 CHECK_FRAME (frame
);
8724 if (WINDOWP (f
->tool_bar_window
)
8725 || (w
= XWINDOW (f
->tool_bar_window
),
8726 WINDOW_TOTAL_LINES (w
) > 0))
8728 update_tool_bar (f
, 1);
8729 if (f
->n_tool_bar_items
)
8731 build_desired_tool_bar_string (f
);
8732 nlines
= tool_bar_lines_needed (f
);
8736 return make_number (nlines
);
8740 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
8741 height should be changed. */
8744 redisplay_tool_bar (f
)
8749 struct glyph_row
*row
;
8750 int change_height_p
= 0;
8753 if (FRAME_EXTERNAL_TOOL_BAR (f
))
8754 update_frame_tool_bar (f
);
8758 /* If frame hasn't a tool-bar window or if it is zero-height, don't
8759 do anything. This means you must start with tool-bar-lines
8760 non-zero to get the auto-sizing effect. Or in other words, you
8761 can turn off tool-bars by specifying tool-bar-lines zero. */
8762 if (!WINDOWP (f
->tool_bar_window
)
8763 || (w
= XWINDOW (f
->tool_bar_window
),
8764 WINDOW_TOTAL_LINES (w
) == 0))
8767 /* Set up an iterator for the tool-bar window. */
8768 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8769 it
.first_visible_x
= 0;
8770 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8773 /* Build a string that represents the contents of the tool-bar. */
8774 build_desired_tool_bar_string (f
);
8775 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8777 /* Display as many lines as needed to display all tool-bar items. */
8778 while (it
.current_y
< it
.last_visible_y
)
8779 display_tool_bar_line (&it
);
8781 /* It doesn't make much sense to try scrolling in the tool-bar
8782 window, so don't do it. */
8783 w
->desired_matrix
->no_scrolling_p
= 1;
8784 w
->must_be_updated_p
= 1;
8786 if (auto_resize_tool_bars_p
)
8790 /* If we couldn't display everything, change the tool-bar's
8792 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
8793 change_height_p
= 1;
8795 /* If there are blank lines at the end, except for a partially
8796 visible blank line at the end that is smaller than
8797 FRAME_LINE_HEIGHT, change the tool-bar's height. */
8798 row
= it
.glyph_row
- 1;
8799 if (!row
->displays_text_p
8800 && row
->height
>= FRAME_LINE_HEIGHT (f
))
8801 change_height_p
= 1;
8803 /* If row displays tool-bar items, but is partially visible,
8804 change the tool-bar's height. */
8805 if (row
->displays_text_p
8806 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
8807 change_height_p
= 1;
8809 /* Resize windows as needed by changing the `tool-bar-lines'
8812 && (nlines
= tool_bar_lines_needed (f
),
8813 nlines
!= WINDOW_TOTAL_LINES (w
)))
8815 extern Lisp_Object Qtool_bar_lines
;
8817 int old_height
= WINDOW_TOTAL_LINES (w
);
8819 XSETFRAME (frame
, f
);
8820 clear_glyph_matrix (w
->desired_matrix
);
8821 Fmodify_frame_parameters (frame
,
8822 Fcons (Fcons (Qtool_bar_lines
,
8823 make_number (nlines
)),
8825 if (WINDOW_TOTAL_LINES (w
) != old_height
)
8826 fonts_changed_p
= 1;
8830 return change_height_p
;
8834 /* Get information about the tool-bar item which is displayed in GLYPH
8835 on frame F. Return in *PROP_IDX the index where tool-bar item
8836 properties start in F->tool_bar_items. Value is zero if
8837 GLYPH doesn't display a tool-bar item. */
8840 tool_bar_item_info (f
, glyph
, prop_idx
)
8842 struct glyph
*glyph
;
8849 /* This function can be called asynchronously, which means we must
8850 exclude any possibility that Fget_text_property signals an
8852 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
8853 charpos
= max (0, charpos
);
8855 /* Get the text property `menu-item' at pos. The value of that
8856 property is the start index of this item's properties in
8857 F->tool_bar_items. */
8858 prop
= Fget_text_property (make_number (charpos
),
8859 Qmenu_item
, f
->current_tool_bar_string
);
8860 if (INTEGERP (prop
))
8862 *prop_idx
= XINT (prop
);
8872 /* Get information about the tool-bar item at position X/Y on frame F.
8873 Return in *GLYPH a pointer to the glyph of the tool-bar item in
8874 the current matrix of the tool-bar window of F, or NULL if not
8875 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
8876 item in F->tool_bar_items. Value is
8878 -1 if X/Y is not on a tool-bar item
8879 0 if X/Y is on the same item that was highlighted before.
8883 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
8886 struct glyph
**glyph
;
8887 int *hpos
, *vpos
, *prop_idx
;
8889 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8890 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8893 /* Find the glyph under X/Y. */
8894 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
8898 /* Get the start of this tool-bar item's properties in
8899 f->tool_bar_items. */
8900 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
8903 /* Is mouse on the highlighted item? */
8904 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
8905 && *vpos
>= dpyinfo
->mouse_face_beg_row
8906 && *vpos
<= dpyinfo
->mouse_face_end_row
8907 && (*vpos
> dpyinfo
->mouse_face_beg_row
8908 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
8909 && (*vpos
< dpyinfo
->mouse_face_end_row
8910 || *hpos
< dpyinfo
->mouse_face_end_col
8911 || dpyinfo
->mouse_face_past_end
))
8919 Handle mouse button event on the tool-bar of frame F, at
8920 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
8921 0 for button release. MODIFIERS is event modifiers for button
8925 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
8928 unsigned int modifiers
;
8930 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8931 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8932 int hpos
, vpos
, prop_idx
;
8933 struct glyph
*glyph
;
8934 Lisp_Object enabled_p
;
8936 /* If not on the highlighted tool-bar item, return. */
8937 frame_to_window_pixel_xy (w
, &x
, &y
);
8938 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
8941 /* If item is disabled, do nothing. */
8942 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
8943 if (NILP (enabled_p
))
8948 /* Show item in pressed state. */
8949 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
8950 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
8951 last_tool_bar_item
= prop_idx
;
8955 Lisp_Object key
, frame
;
8956 struct input_event event
;
8959 /* Show item in released state. */
8960 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
8961 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
8963 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
8965 XSETFRAME (frame
, f
);
8966 event
.kind
= TOOL_BAR_EVENT
;
8967 event
.frame_or_window
= frame
;
8969 kbd_buffer_store_event (&event
);
8971 event
.kind
= TOOL_BAR_EVENT
;
8972 event
.frame_or_window
= frame
;
8974 event
.modifiers
= modifiers
;
8975 kbd_buffer_store_event (&event
);
8976 last_tool_bar_item
= -1;
8981 /* Possibly highlight a tool-bar item on frame F when mouse moves to
8982 tool-bar window-relative coordinates X/Y. Called from
8983 note_mouse_highlight. */
8986 note_tool_bar_highlight (f
, x
, y
)
8990 Lisp_Object window
= f
->tool_bar_window
;
8991 struct window
*w
= XWINDOW (window
);
8992 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8994 struct glyph
*glyph
;
8995 struct glyph_row
*row
;
8997 Lisp_Object enabled_p
;
8999 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9000 int mouse_down_p
, rc
;
9002 /* Function note_mouse_highlight is called with negative x(y
9003 values when mouse moves outside of the frame. */
9004 if (x
<= 0 || y
<= 0)
9006 clear_mouse_face (dpyinfo
);
9010 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9013 /* Not on tool-bar item. */
9014 clear_mouse_face (dpyinfo
);
9018 /* On same tool-bar item as before. */
9021 clear_mouse_face (dpyinfo
);
9023 /* Mouse is down, but on different tool-bar item? */
9024 mouse_down_p
= (dpyinfo
->grabbed
9025 && f
== last_mouse_frame
9026 && FRAME_LIVE_P (f
));
9028 && last_tool_bar_item
!= prop_idx
)
9031 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9032 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9034 /* If tool-bar item is not enabled, don't highlight it. */
9035 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9036 if (!NILP (enabled_p
))
9038 /* Compute the x-position of the glyph. In front and past the
9039 image is a space. We include this in the highlighted area. */
9040 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9041 for (i
= x
= 0; i
< hpos
; ++i
)
9042 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9044 /* Record this as the current active region. */
9045 dpyinfo
->mouse_face_beg_col
= hpos
;
9046 dpyinfo
->mouse_face_beg_row
= vpos
;
9047 dpyinfo
->mouse_face_beg_x
= x
;
9048 dpyinfo
->mouse_face_beg_y
= row
->y
;
9049 dpyinfo
->mouse_face_past_end
= 0;
9051 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9052 dpyinfo
->mouse_face_end_row
= vpos
;
9053 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9054 dpyinfo
->mouse_face_end_y
= row
->y
;
9055 dpyinfo
->mouse_face_window
= window
;
9056 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9058 /* Display it as active. */
9059 show_mouse_face (dpyinfo
, draw
);
9060 dpyinfo
->mouse_face_image_state
= draw
;
9065 /* Set help_echo_string to a help string to display for this tool-bar item.
9066 XTread_socket does the rest. */
9067 help_echo_object
= help_echo_window
= Qnil
;
9069 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9070 if (NILP (help_echo_string
))
9071 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9074 #endif /* HAVE_WINDOW_SYSTEM */
9078 /************************************************************************
9079 Horizontal scrolling
9080 ************************************************************************/
9082 static int hscroll_window_tree
P_ ((Lisp_Object
));
9083 static int hscroll_windows
P_ ((Lisp_Object
));
9085 /* For all leaf windows in the window tree rooted at WINDOW, set their
9086 hscroll value so that PT is (i) visible in the window, and (ii) so
9087 that it is not within a certain margin at the window's left and
9088 right border. Value is non-zero if any window's hscroll has been
9092 hscroll_window_tree (window
)
9095 int hscrolled_p
= 0;
9096 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9097 int hscroll_step_abs
= 0;
9098 double hscroll_step_rel
= 0;
9100 if (hscroll_relative_p
)
9102 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9103 if (hscroll_step_rel
< 0)
9105 hscroll_relative_p
= 0;
9106 hscroll_step_abs
= 0;
9109 else if (INTEGERP (Vhscroll_step
))
9111 hscroll_step_abs
= XINT (Vhscroll_step
);
9112 if (hscroll_step_abs
< 0)
9113 hscroll_step_abs
= 0;
9116 hscroll_step_abs
= 0;
9118 while (WINDOWP (window
))
9120 struct window
*w
= XWINDOW (window
);
9122 if (WINDOWP (w
->hchild
))
9123 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9124 else if (WINDOWP (w
->vchild
))
9125 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9126 else if (w
->cursor
.vpos
>= 0)
9129 int text_area_width
;
9130 struct glyph_row
*current_cursor_row
9131 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9132 struct glyph_row
*desired_cursor_row
9133 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9134 struct glyph_row
*cursor_row
9135 = (desired_cursor_row
->enabled_p
9136 ? desired_cursor_row
9137 : current_cursor_row
);
9139 text_area_width
= window_box_width (w
, TEXT_AREA
);
9141 /* Scroll when cursor is inside this scroll margin. */
9142 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9144 if ((XFASTINT (w
->hscroll
)
9145 && w
->cursor
.x
<= h_margin
)
9146 || (cursor_row
->enabled_p
9147 && cursor_row
->truncated_on_right_p
9148 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9152 struct buffer
*saved_current_buffer
;
9156 /* Find point in a display of infinite width. */
9157 saved_current_buffer
= current_buffer
;
9158 current_buffer
= XBUFFER (w
->buffer
);
9160 if (w
== XWINDOW (selected_window
))
9161 pt
= BUF_PT (current_buffer
);
9164 pt
= marker_position (w
->pointm
);
9165 pt
= max (BEGV
, pt
);
9169 /* Move iterator to pt starting at cursor_row->start in
9170 a line with infinite width. */
9171 init_to_row_start (&it
, w
, cursor_row
);
9172 it
.last_visible_x
= INFINITY
;
9173 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9174 current_buffer
= saved_current_buffer
;
9176 /* Position cursor in window. */
9177 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9178 hscroll
= max (0, (it
.current_x
9179 - (ITERATOR_AT_END_OF_LINE_P (&it
)
9180 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
9181 : (text_area_width
/ 2))))
9182 / FRAME_COLUMN_WIDTH (it
.f
);
9183 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9185 if (hscroll_relative_p
)
9186 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9189 wanted_x
= text_area_width
9190 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9193 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9197 if (hscroll_relative_p
)
9198 wanted_x
= text_area_width
* hscroll_step_rel
9201 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9204 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9206 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9208 /* Don't call Fset_window_hscroll if value hasn't
9209 changed because it will prevent redisplay
9211 if (XFASTINT (w
->hscroll
) != hscroll
)
9213 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9214 w
->hscroll
= make_number (hscroll
);
9223 /* Value is non-zero if hscroll of any leaf window has been changed. */
9228 /* Set hscroll so that cursor is visible and not inside horizontal
9229 scroll margins for all windows in the tree rooted at WINDOW. See
9230 also hscroll_window_tree above. Value is non-zero if any window's
9231 hscroll has been changed. If it has, desired matrices on the frame
9232 of WINDOW are cleared. */
9235 hscroll_windows (window
)
9240 if (automatic_hscrolling_p
)
9242 hscrolled_p
= hscroll_window_tree (window
);
9244 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9253 /************************************************************************
9255 ************************************************************************/
9257 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9258 to a non-zero value. This is sometimes handy to have in a debugger
9263 /* First and last unchanged row for try_window_id. */
9265 int debug_first_unchanged_at_end_vpos
;
9266 int debug_last_unchanged_at_beg_vpos
;
9268 /* Delta vpos and y. */
9270 int debug_dvpos
, debug_dy
;
9272 /* Delta in characters and bytes for try_window_id. */
9274 int debug_delta
, debug_delta_bytes
;
9276 /* Values of window_end_pos and window_end_vpos at the end of
9279 EMACS_INT debug_end_pos
, debug_end_vpos
;
9281 /* Append a string to W->desired_matrix->method. FMT is a printf
9282 format string. A1...A9 are a supplement for a variable-length
9283 argument list. If trace_redisplay_p is non-zero also printf the
9284 resulting string to stderr. */
9287 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9290 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9293 char *method
= w
->desired_matrix
->method
;
9294 int len
= strlen (method
);
9295 int size
= sizeof w
->desired_matrix
->method
;
9296 int remaining
= size
- len
- 1;
9298 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9299 if (len
&& remaining
)
9305 strncpy (method
+ len
, buffer
, remaining
);
9307 if (trace_redisplay_p
)
9308 fprintf (stderr
, "%p (%s): %s\n",
9310 ((BUFFERP (w
->buffer
)
9311 && STRINGP (XBUFFER (w
->buffer
)->name
))
9312 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9317 #endif /* GLYPH_DEBUG */
9320 /* Value is non-zero if all changes in window W, which displays
9321 current_buffer, are in the text between START and END. START is a
9322 buffer position, END is given as a distance from Z. Used in
9323 redisplay_internal for display optimization. */
9326 text_outside_line_unchanged_p (w
, start
, end
)
9330 int unchanged_p
= 1;
9332 /* If text or overlays have changed, see where. */
9333 if (XFASTINT (w
->last_modified
) < MODIFF
9334 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9336 /* Gap in the line? */
9337 if (GPT
< start
|| Z
- GPT
< end
)
9340 /* Changes start in front of the line, or end after it? */
9342 && (BEG_UNCHANGED
< start
- 1
9343 || END_UNCHANGED
< end
))
9346 /* If selective display, can't optimize if changes start at the
9347 beginning of the line. */
9349 && INTEGERP (current_buffer
->selective_display
)
9350 && XINT (current_buffer
->selective_display
) > 0
9351 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9354 /* If there are overlays at the start or end of the line, these
9355 may have overlay strings with newlines in them. A change at
9356 START, for instance, may actually concern the display of such
9357 overlay strings as well, and they are displayed on different
9358 lines. So, quickly rule out this case. (For the future, it
9359 might be desirable to implement something more telling than
9360 just BEG/END_UNCHANGED.) */
9363 if (BEG
+ BEG_UNCHANGED
== start
9364 && overlay_touches_p (start
))
9366 if (END_UNCHANGED
== end
9367 && overlay_touches_p (Z
- end
))
9376 /* Do a frame update, taking possible shortcuts into account. This is
9377 the main external entry point for redisplay.
9379 If the last redisplay displayed an echo area message and that message
9380 is no longer requested, we clear the echo area or bring back the
9381 mini-buffer if that is in use. */
9386 redisplay_internal (0);
9391 overlay_arrow_string_or_property (var
, pbitmap
)
9395 Lisp_Object pstr
= Fget (var
, Qoverlay_arrow_string
);
9401 if (bitmap
= Fget (var
, Qoverlay_arrow_bitmap
), INTEGERP (bitmap
))
9402 *pbitmap
= XINT (bitmap
);
9407 return Voverlay_arrow_string
;
9410 /* Return 1 if there are any overlay-arrows in current_buffer. */
9412 overlay_arrow_in_current_buffer_p ()
9416 for (vlist
= Voverlay_arrow_variable_list
;
9418 vlist
= XCDR (vlist
))
9420 Lisp_Object var
= XCAR (vlist
);
9425 val
= find_symbol_value (var
);
9427 && current_buffer
== XMARKER (val
)->buffer
)
9434 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
9438 overlay_arrows_changed_p ()
9442 for (vlist
= Voverlay_arrow_variable_list
;
9444 vlist
= XCDR (vlist
))
9446 Lisp_Object var
= XCAR (vlist
);
9447 Lisp_Object val
, pstr
;
9451 val
= find_symbol_value (var
);
9454 if (! EQ (COERCE_MARKER (val
),
9455 Fget (var
, Qlast_arrow_position
))
9456 || ! (pstr
= overlay_arrow_string_or_property (var
, 0),
9457 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
9463 /* Mark overlay arrows to be updated on next redisplay. */
9466 update_overlay_arrows (up_to_date
)
9471 for (vlist
= Voverlay_arrow_variable_list
;
9473 vlist
= XCDR (vlist
))
9475 Lisp_Object var
= XCAR (vlist
);
9482 Lisp_Object val
= find_symbol_value (var
);
9483 Fput (var
, Qlast_arrow_position
,
9484 COERCE_MARKER (val
));
9485 Fput (var
, Qlast_arrow_string
,
9486 overlay_arrow_string_or_property (var
, 0));
9488 else if (up_to_date
< 0
9489 || !NILP (Fget (var
, Qlast_arrow_position
)))
9491 Fput (var
, Qlast_arrow_position
, Qt
);
9492 Fput (var
, Qlast_arrow_string
, Qt
);
9498 /* Return overlay arrow string at row, or nil. */
9501 overlay_arrow_at_row (f
, row
, pbitmap
)
9503 struct glyph_row
*row
;
9508 for (vlist
= Voverlay_arrow_variable_list
;
9510 vlist
= XCDR (vlist
))
9512 Lisp_Object var
= XCAR (vlist
);
9518 val
= find_symbol_value (var
);
9521 && current_buffer
== XMARKER (val
)->buffer
9522 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
9524 val
= overlay_arrow_string_or_property (var
, pbitmap
);
9525 if (FRAME_WINDOW_P (f
))
9527 else if (STRINGP (val
))
9537 /* Return 1 if point moved out of or into a composition. Otherwise
9538 return 0. PREV_BUF and PREV_PT are the last point buffer and
9539 position. BUF and PT are the current point buffer and position. */
9542 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
9543 struct buffer
*prev_buf
, *buf
;
9550 XSETBUFFER (buffer
, buf
);
9551 /* Check a composition at the last point if point moved within the
9553 if (prev_buf
== buf
)
9556 /* Point didn't move. */
9559 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
9560 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
9561 && COMPOSITION_VALID_P (start
, end
, prop
)
9562 && start
< prev_pt
&& end
> prev_pt
)
9563 /* The last point was within the composition. Return 1 iff
9564 point moved out of the composition. */
9565 return (pt
<= start
|| pt
>= end
);
9568 /* Check a composition at the current point. */
9569 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
9570 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
9571 && COMPOSITION_VALID_P (start
, end
, prop
)
9572 && start
< pt
&& end
> pt
);
9576 /* Reconsider the setting of B->clip_changed which is displayed
9580 reconsider_clip_changes (w
, b
)
9585 && !NILP (w
->window_end_valid
)
9586 && w
->current_matrix
->buffer
== b
9587 && w
->current_matrix
->zv
== BUF_ZV (b
)
9588 && w
->current_matrix
->begv
== BUF_BEGV (b
))
9589 b
->clip_changed
= 0;
9591 /* If display wasn't paused, and W is not a tool bar window, see if
9592 point has been moved into or out of a composition. In that case,
9593 we set b->clip_changed to 1 to force updating the screen. If
9594 b->clip_changed has already been set to 1, we can skip this
9596 if (!b
->clip_changed
9597 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
9601 if (w
== XWINDOW (selected_window
))
9602 pt
= BUF_PT (current_buffer
);
9604 pt
= marker_position (w
->pointm
);
9606 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
9607 || pt
!= XINT (w
->last_point
))
9608 && check_point_in_composition (w
->current_matrix
->buffer
,
9609 XINT (w
->last_point
),
9610 XBUFFER (w
->buffer
), pt
))
9611 b
->clip_changed
= 1;
9616 /* Select FRAME to forward the values of frame-local variables into C
9617 variables so that the redisplay routines can access those values
9621 select_frame_for_redisplay (frame
)
9624 Lisp_Object tail
, sym
, val
;
9625 Lisp_Object old
= selected_frame
;
9627 selected_frame
= frame
;
9629 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9630 if (CONSP (XCAR (tail
))
9631 && (sym
= XCAR (XCAR (tail
)),
9633 && (sym
= indirect_variable (sym
),
9634 val
= SYMBOL_VALUE (sym
),
9635 (BUFFER_LOCAL_VALUEP (val
)
9636 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9637 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9638 Fsymbol_value (sym
);
9640 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9641 if (CONSP (XCAR (tail
))
9642 && (sym
= XCAR (XCAR (tail
)),
9644 && (sym
= indirect_variable (sym
),
9645 val
= SYMBOL_VALUE (sym
),
9646 (BUFFER_LOCAL_VALUEP (val
)
9647 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9648 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9649 Fsymbol_value (sym
);
9653 #define STOP_POLLING \
9654 do { if (! polling_stopped_here) stop_polling (); \
9655 polling_stopped_here = 1; } while (0)
9657 #define RESUME_POLLING \
9658 do { if (polling_stopped_here) start_polling (); \
9659 polling_stopped_here = 0; } while (0)
9662 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
9663 response to any user action; therefore, we should preserve the echo
9664 area. (Actually, our caller does that job.) Perhaps in the future
9665 avoid recentering windows if it is not necessary; currently that
9666 causes some problems. */
9669 redisplay_internal (preserve_echo_area
)
9670 int preserve_echo_area
;
9672 struct window
*w
= XWINDOW (selected_window
);
9673 struct frame
*f
= XFRAME (w
->frame
);
9675 int must_finish
= 0;
9676 struct text_pos tlbufpos
, tlendpos
;
9677 int number_of_visible_frames
;
9679 struct frame
*sf
= SELECTED_FRAME ();
9680 int polling_stopped_here
= 0;
9682 /* Non-zero means redisplay has to consider all windows on all
9683 frames. Zero means, only selected_window is considered. */
9684 int consider_all_windows_p
;
9686 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
9688 /* No redisplay if running in batch mode or frame is not yet fully
9689 initialized, or redisplay is explicitly turned off by setting
9690 Vinhibit_redisplay. */
9692 || !NILP (Vinhibit_redisplay
)
9693 || !f
->glyphs_initialized_p
)
9696 /* The flag redisplay_performed_directly_p is set by
9697 direct_output_for_insert when it already did the whole screen
9698 update necessary. */
9699 if (redisplay_performed_directly_p
)
9701 redisplay_performed_directly_p
= 0;
9702 if (!hscroll_windows (selected_window
))
9706 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
9707 if (popup_activated ())
9711 /* I don't think this happens but let's be paranoid. */
9715 /* Record a function that resets redisplaying_p to its old value
9716 when we leave this function. */
9717 count
= SPECPDL_INDEX ();
9718 record_unwind_protect (unwind_redisplay
,
9719 Fcons (make_number (redisplaying_p
), selected_frame
));
9721 specbind (Qinhibit_free_realized_faces
, Qnil
);
9725 reconsider_clip_changes (w
, current_buffer
);
9727 /* If new fonts have been loaded that make a glyph matrix adjustment
9728 necessary, do it. */
9729 if (fonts_changed_p
)
9731 adjust_glyphs (NULL
);
9732 ++windows_or_buffers_changed
;
9733 fonts_changed_p
= 0;
9736 /* If face_change_count is non-zero, init_iterator will free all
9737 realized faces, which includes the faces referenced from current
9738 matrices. So, we can't reuse current matrices in this case. */
9739 if (face_change_count
)
9740 ++windows_or_buffers_changed
;
9742 if (! FRAME_WINDOW_P (sf
)
9743 && previous_terminal_frame
!= sf
)
9745 /* Since frames on an ASCII terminal share the same display
9746 area, displaying a different frame means redisplay the whole
9748 windows_or_buffers_changed
++;
9749 SET_FRAME_GARBAGED (sf
);
9750 XSETFRAME (Vterminal_frame
, sf
);
9752 previous_terminal_frame
= sf
;
9754 /* Set the visible flags for all frames. Do this before checking
9755 for resized or garbaged frames; they want to know if their frames
9756 are visible. See the comment in frame.h for
9757 FRAME_SAMPLE_VISIBILITY. */
9759 Lisp_Object tail
, frame
;
9761 number_of_visible_frames
= 0;
9763 FOR_EACH_FRAME (tail
, frame
)
9765 struct frame
*f
= XFRAME (frame
);
9767 FRAME_SAMPLE_VISIBILITY (f
);
9768 if (FRAME_VISIBLE_P (f
))
9769 ++number_of_visible_frames
;
9770 clear_desired_matrices (f
);
9774 /* Notice any pending interrupt request to change frame size. */
9775 do_pending_window_change (1);
9777 /* Clear frames marked as garbaged. */
9779 clear_garbaged_frames ();
9781 /* Build menubar and tool-bar items. */
9782 prepare_menu_bars ();
9784 if (windows_or_buffers_changed
)
9785 update_mode_lines
++;
9787 /* Detect case that we need to write or remove a star in the mode line. */
9788 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
9790 w
->update_mode_line
= Qt
;
9791 if (buffer_shared
> 1)
9792 update_mode_lines
++;
9795 /* If %c is in the mode line, update it if needed. */
9796 if (!NILP (w
->column_number_displayed
)
9797 /* This alternative quickly identifies a common case
9798 where no change is needed. */
9799 && !(PT
== XFASTINT (w
->last_point
)
9800 && XFASTINT (w
->last_modified
) >= MODIFF
9801 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9802 && (XFASTINT (w
->column_number_displayed
)
9803 != (int) current_column ())) /* iftc */
9804 w
->update_mode_line
= Qt
;
9806 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
9808 /* The variable buffer_shared is set in redisplay_window and
9809 indicates that we redisplay a buffer in different windows. See
9811 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
9812 || cursor_type_changed
);
9814 /* If specs for an arrow have changed, do thorough redisplay
9815 to ensure we remove any arrow that should no longer exist. */
9816 if (overlay_arrows_changed_p ())
9817 consider_all_windows_p
= windows_or_buffers_changed
= 1;
9819 /* Normally the message* functions will have already displayed and
9820 updated the echo area, but the frame may have been trashed, or
9821 the update may have been preempted, so display the echo area
9822 again here. Checking message_cleared_p captures the case that
9823 the echo area should be cleared. */
9824 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
9825 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
9826 || (message_cleared_p
9827 && minibuf_level
== 0
9828 /* If the mini-window is currently selected, this means the
9829 echo-area doesn't show through. */
9830 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
9832 int window_height_changed_p
= echo_area_display (0);
9835 /* If we don't display the current message, don't clear the
9836 message_cleared_p flag, because, if we did, we wouldn't clear
9837 the echo area in the next redisplay which doesn't preserve
9839 if (!display_last_displayed_message_p
)
9840 message_cleared_p
= 0;
9842 if (fonts_changed_p
)
9844 else if (window_height_changed_p
)
9846 consider_all_windows_p
= 1;
9847 ++update_mode_lines
;
9848 ++windows_or_buffers_changed
;
9850 /* If window configuration was changed, frames may have been
9851 marked garbaged. Clear them or we will experience
9852 surprises wrt scrolling. */
9854 clear_garbaged_frames ();
9857 else if (EQ (selected_window
, minibuf_window
)
9858 && (current_buffer
->clip_changed
9859 || XFASTINT (w
->last_modified
) < MODIFF
9860 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9861 && resize_mini_window (w
, 0))
9863 /* Resized active mini-window to fit the size of what it is
9864 showing if its contents might have changed. */
9866 consider_all_windows_p
= 1;
9867 ++windows_or_buffers_changed
;
9868 ++update_mode_lines
;
9870 /* If window configuration was changed, frames may have been
9871 marked garbaged. Clear them or we will experience
9872 surprises wrt scrolling. */
9874 clear_garbaged_frames ();
9878 /* If showing the region, and mark has changed, we must redisplay
9879 the whole window. The assignment to this_line_start_pos prevents
9880 the optimization directly below this if-statement. */
9881 if (((!NILP (Vtransient_mark_mode
)
9882 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9883 != !NILP (w
->region_showing
))
9884 || (!NILP (w
->region_showing
)
9885 && !EQ (w
->region_showing
,
9886 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
9887 CHARPOS (this_line_start_pos
) = 0;
9889 /* Optimize the case that only the line containing the cursor in the
9890 selected window has changed. Variables starting with this_ are
9891 set in display_line and record information about the line
9892 containing the cursor. */
9893 tlbufpos
= this_line_start_pos
;
9894 tlendpos
= this_line_end_pos
;
9895 if (!consider_all_windows_p
9896 && CHARPOS (tlbufpos
) > 0
9897 && NILP (w
->update_mode_line
)
9898 && !current_buffer
->clip_changed
9899 && !current_buffer
->prevent_redisplay_optimizations_p
9900 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
9901 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
9902 /* Make sure recorded data applies to current buffer, etc. */
9903 && this_line_buffer
== current_buffer
9904 && current_buffer
== XBUFFER (w
->buffer
)
9905 && NILP (w
->force_start
)
9906 && NILP (w
->optional_new_start
)
9907 /* Point must be on the line that we have info recorded about. */
9908 && PT
>= CHARPOS (tlbufpos
)
9909 && PT
<= Z
- CHARPOS (tlendpos
)
9910 /* All text outside that line, including its final newline,
9911 must be unchanged */
9912 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
9913 CHARPOS (tlendpos
)))
9915 if (CHARPOS (tlbufpos
) > BEGV
9916 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
9917 && (CHARPOS (tlbufpos
) == ZV
9918 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
9919 /* Former continuation line has disappeared by becoming empty */
9921 else if (XFASTINT (w
->last_modified
) < MODIFF
9922 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
9923 || MINI_WINDOW_P (w
))
9925 /* We have to handle the case of continuation around a
9926 wide-column character (See the comment in indent.c around
9929 For instance, in the following case:
9931 -------- Insert --------
9932 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
9933 J_I_ ==> J_I_ `^^' are cursors.
9937 As we have to redraw the line above, we should goto cancel. */
9940 int line_height_before
= this_line_pixel_height
;
9942 /* Note that start_display will handle the case that the
9943 line starting at tlbufpos is a continuation lines. */
9944 start_display (&it
, w
, tlbufpos
);
9946 /* Implementation note: It this still necessary? */
9947 if (it
.current_x
!= this_line_start_x
)
9950 TRACE ((stderr
, "trying display optimization 1\n"));
9951 w
->cursor
.vpos
= -1;
9952 overlay_arrow_seen
= 0;
9953 it
.vpos
= this_line_vpos
;
9954 it
.current_y
= this_line_y
;
9955 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
9958 /* If line contains point, is not continued,
9959 and ends at same distance from eob as before, we win */
9960 if (w
->cursor
.vpos
>= 0
9961 /* Line is not continued, otherwise this_line_start_pos
9962 would have been set to 0 in display_line. */
9963 && CHARPOS (this_line_start_pos
)
9964 /* Line ends as before. */
9965 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
9966 /* Line has same height as before. Otherwise other lines
9967 would have to be shifted up or down. */
9968 && this_line_pixel_height
== line_height_before
)
9970 /* If this is not the window's last line, we must adjust
9971 the charstarts of the lines below. */
9972 if (it
.current_y
< it
.last_visible_y
)
9974 struct glyph_row
*row
9975 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
9976 int delta
, delta_bytes
;
9978 if (Z
- CHARPOS (tlendpos
) == ZV
)
9980 /* This line ends at end of (accessible part of)
9981 buffer. There is no newline to count. */
9983 - CHARPOS (tlendpos
)
9984 - MATRIX_ROW_START_CHARPOS (row
));
9985 delta_bytes
= (Z_BYTE
9986 - BYTEPOS (tlendpos
)
9987 - MATRIX_ROW_START_BYTEPOS (row
));
9991 /* This line ends in a newline. Must take
9992 account of the newline and the rest of the
9993 text that follows. */
9995 - CHARPOS (tlendpos
)
9996 - MATRIX_ROW_START_CHARPOS (row
));
9997 delta_bytes
= (Z_BYTE
9998 - BYTEPOS (tlendpos
)
9999 - MATRIX_ROW_START_BYTEPOS (row
));
10002 increment_matrix_positions (w
->current_matrix
,
10003 this_line_vpos
+ 1,
10004 w
->current_matrix
->nrows
,
10005 delta
, delta_bytes
);
10008 /* If this row displays text now but previously didn't,
10009 or vice versa, w->window_end_vpos may have to be
10011 if ((it
.glyph_row
- 1)->displays_text_p
)
10013 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10014 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10016 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10017 && this_line_vpos
> 0)
10018 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10019 w
->window_end_valid
= Qnil
;
10021 /* Update hint: No need to try to scroll in update_window. */
10022 w
->desired_matrix
->no_scrolling_p
= 1;
10025 *w
->desired_matrix
->method
= 0;
10026 debug_method_add (w
, "optimization 1");
10028 #ifdef HAVE_WINDOW_SYSTEM
10029 update_window_fringes (w
, 0);
10036 else if (/* Cursor position hasn't changed. */
10037 PT
== XFASTINT (w
->last_point
)
10038 /* Make sure the cursor was last displayed
10039 in this window. Otherwise we have to reposition it. */
10040 && 0 <= w
->cursor
.vpos
10041 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10045 do_pending_window_change (1);
10047 /* We used to always goto end_of_redisplay here, but this
10048 isn't enough if we have a blinking cursor. */
10049 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10050 goto end_of_redisplay
;
10054 /* If highlighting the region, or if the cursor is in the echo area,
10055 then we can't just move the cursor. */
10056 else if (! (!NILP (Vtransient_mark_mode
)
10057 && !NILP (current_buffer
->mark_active
))
10058 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10059 || highlight_nonselected_windows
)
10060 && NILP (w
->region_showing
)
10061 && NILP (Vshow_trailing_whitespace
)
10062 && !cursor_in_echo_area
)
10065 struct glyph_row
*row
;
10067 /* Skip from tlbufpos to PT and see where it is. Note that
10068 PT may be in invisible text. If so, we will end at the
10069 next visible position. */
10070 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10071 NULL
, DEFAULT_FACE_ID
);
10072 it
.current_x
= this_line_start_x
;
10073 it
.current_y
= this_line_y
;
10074 it
.vpos
= this_line_vpos
;
10076 /* The call to move_it_to stops in front of PT, but
10077 moves over before-strings. */
10078 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10080 if (it
.vpos
== this_line_vpos
10081 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10084 xassert (this_line_vpos
== it
.vpos
);
10085 xassert (this_line_y
== it
.current_y
);
10086 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10088 *w
->desired_matrix
->method
= 0;
10089 debug_method_add (w
, "optimization 3");
10098 /* Text changed drastically or point moved off of line. */
10099 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10102 CHARPOS (this_line_start_pos
) = 0;
10103 consider_all_windows_p
|= buffer_shared
> 1;
10104 ++clear_face_cache_count
;
10107 /* Build desired matrices, and update the display. If
10108 consider_all_windows_p is non-zero, do it for all windows on all
10109 frames. Otherwise do it for selected_window, only. */
10111 if (consider_all_windows_p
)
10113 Lisp_Object tail
, frame
;
10114 int i
, n
= 0, size
= 50;
10115 struct frame
**updated
10116 = (struct frame
**) alloca (size
* sizeof *updated
);
10118 /* Clear the face cache eventually. */
10119 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
10121 clear_face_cache (0);
10122 clear_face_cache_count
= 0;
10125 /* Recompute # windows showing selected buffer. This will be
10126 incremented each time such a window is displayed. */
10129 FOR_EACH_FRAME (tail
, frame
)
10131 struct frame
*f
= XFRAME (frame
);
10133 if (FRAME_WINDOW_P (f
) || f
== sf
)
10135 if (! EQ (frame
, selected_frame
))
10136 /* Select the frame, for the sake of frame-local
10138 select_frame_for_redisplay (frame
);
10140 #ifdef HAVE_WINDOW_SYSTEM
10141 if (clear_face_cache_count
% 50 == 0
10142 && FRAME_WINDOW_P (f
))
10143 clear_image_cache (f
, 0);
10144 #endif /* HAVE_WINDOW_SYSTEM */
10146 /* Mark all the scroll bars to be removed; we'll redeem
10147 the ones we want when we redisplay their windows. */
10148 if (condemn_scroll_bars_hook
)
10149 condemn_scroll_bars_hook (f
);
10151 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10152 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10154 /* Any scroll bars which redisplay_windows should have
10155 nuked should now go away. */
10156 if (judge_scroll_bars_hook
)
10157 judge_scroll_bars_hook (f
);
10159 /* If fonts changed, display again. */
10160 /* ??? rms: I suspect it is a mistake to jump all the way
10161 back to retry here. It should just retry this frame. */
10162 if (fonts_changed_p
)
10165 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10167 /* See if we have to hscroll. */
10168 if (hscroll_windows (f
->root_window
))
10171 /* Prevent various kinds of signals during display
10172 update. stdio is not robust about handling
10173 signals, which can cause an apparent I/O
10175 if (interrupt_input
)
10176 unrequest_sigio ();
10179 /* Update the display. */
10180 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10181 pause
|= update_frame (f
, 0, 0);
10182 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10189 int nbytes
= size
* sizeof *updated
;
10190 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
10191 bcopy (updated
, p
, nbytes
);
10202 /* Do the mark_window_display_accurate after all windows have
10203 been redisplayed because this call resets flags in buffers
10204 which are needed for proper redisplay. */
10205 for (i
= 0; i
< n
; ++i
)
10207 struct frame
*f
= updated
[i
];
10208 mark_window_display_accurate (f
->root_window
, 1);
10209 if (frame_up_to_date_hook
)
10210 frame_up_to_date_hook (f
);
10214 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10216 Lisp_Object mini_window
;
10217 struct frame
*mini_frame
;
10219 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10220 /* Use list_of_error, not Qerror, so that
10221 we catch only errors and don't run the debugger. */
10222 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10224 redisplay_window_error
);
10226 /* Compare desired and current matrices, perform output. */
10229 /* If fonts changed, display again. */
10230 if (fonts_changed_p
)
10233 /* Prevent various kinds of signals during display update.
10234 stdio is not robust about handling signals,
10235 which can cause an apparent I/O error. */
10236 if (interrupt_input
)
10237 unrequest_sigio ();
10240 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10242 if (hscroll_windows (selected_window
))
10245 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10246 pause
= update_frame (sf
, 0, 0);
10249 /* We may have called echo_area_display at the top of this
10250 function. If the echo area is on another frame, that may
10251 have put text on a frame other than the selected one, so the
10252 above call to update_frame would not have caught it. Catch
10254 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10255 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10257 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10259 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10260 pause
|= update_frame (mini_frame
, 0, 0);
10261 if (!pause
&& hscroll_windows (mini_window
))
10266 /* If display was paused because of pending input, make sure we do a
10267 thorough update the next time. */
10270 /* Prevent the optimization at the beginning of
10271 redisplay_internal that tries a single-line update of the
10272 line containing the cursor in the selected window. */
10273 CHARPOS (this_line_start_pos
) = 0;
10275 /* Let the overlay arrow be updated the next time. */
10276 update_overlay_arrows (0);
10278 /* If we pause after scrolling, some rows in the current
10279 matrices of some windows are not valid. */
10280 if (!WINDOW_FULL_WIDTH_P (w
)
10281 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10282 update_mode_lines
= 1;
10286 if (!consider_all_windows_p
)
10288 /* This has already been done above if
10289 consider_all_windows_p is set. */
10290 mark_window_display_accurate_1 (w
, 1);
10292 /* Say overlay arrows are up to date. */
10293 update_overlay_arrows (1);
10295 if (frame_up_to_date_hook
!= 0)
10296 frame_up_to_date_hook (sf
);
10299 update_mode_lines
= 0;
10300 windows_or_buffers_changed
= 0;
10301 cursor_type_changed
= 0;
10304 /* Start SIGIO interrupts coming again. Having them off during the
10305 code above makes it less likely one will discard output, but not
10306 impossible, since there might be stuff in the system buffer here.
10307 But it is much hairier to try to do anything about that. */
10308 if (interrupt_input
)
10312 /* If a frame has become visible which was not before, redisplay
10313 again, so that we display it. Expose events for such a frame
10314 (which it gets when becoming visible) don't call the parts of
10315 redisplay constructing glyphs, so simply exposing a frame won't
10316 display anything in this case. So, we have to display these
10317 frames here explicitly. */
10320 Lisp_Object tail
, frame
;
10323 FOR_EACH_FRAME (tail
, frame
)
10325 int this_is_visible
= 0;
10327 if (XFRAME (frame
)->visible
)
10328 this_is_visible
= 1;
10329 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10330 if (XFRAME (frame
)->visible
)
10331 this_is_visible
= 1;
10333 if (this_is_visible
)
10337 if (new_count
!= number_of_visible_frames
)
10338 windows_or_buffers_changed
++;
10341 /* Change frame size now if a change is pending. */
10342 do_pending_window_change (1);
10344 /* If we just did a pending size change, or have additional
10345 visible frames, redisplay again. */
10346 if (windows_or_buffers_changed
&& !pause
)
10350 unbind_to (count
, Qnil
);
10355 /* Redisplay, but leave alone any recent echo area message unless
10356 another message has been requested in its place.
10358 This is useful in situations where you need to redisplay but no
10359 user action has occurred, making it inappropriate for the message
10360 area to be cleared. See tracking_off and
10361 wait_reading_process_input for examples of these situations.
10363 FROM_WHERE is an integer saying from where this function was
10364 called. This is useful for debugging. */
10367 redisplay_preserve_echo_area (from_where
)
10370 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10372 if (!NILP (echo_area_buffer
[1]))
10374 /* We have a previously displayed message, but no current
10375 message. Redisplay the previous message. */
10376 display_last_displayed_message_p
= 1;
10377 redisplay_internal (1);
10378 display_last_displayed_message_p
= 0;
10381 redisplay_internal (1);
10385 /* Function registered with record_unwind_protect in
10386 redisplay_internal. Reset redisplaying_p to the value it had
10387 before redisplay_internal was called, and clear
10388 prevent_freeing_realized_faces_p. It also selects the previously
10392 unwind_redisplay (val
)
10395 Lisp_Object old_redisplaying_p
, old_frame
;
10397 old_redisplaying_p
= XCAR (val
);
10398 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10399 old_frame
= XCDR (val
);
10400 if (! EQ (old_frame
, selected_frame
))
10401 select_frame_for_redisplay (old_frame
);
10406 /* Mark the display of window W as accurate or inaccurate. If
10407 ACCURATE_P is non-zero mark display of W as accurate. If
10408 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10409 redisplay_internal is called. */
10412 mark_window_display_accurate_1 (w
, accurate_p
)
10416 if (BUFFERP (w
->buffer
))
10418 struct buffer
*b
= XBUFFER (w
->buffer
);
10421 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
10422 w
->last_overlay_modified
10423 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
10425 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
10429 b
->clip_changed
= 0;
10430 b
->prevent_redisplay_optimizations_p
= 0;
10432 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
10433 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
10434 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
10435 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
10437 w
->current_matrix
->buffer
= b
;
10438 w
->current_matrix
->begv
= BUF_BEGV (b
);
10439 w
->current_matrix
->zv
= BUF_ZV (b
);
10441 w
->last_cursor
= w
->cursor
;
10442 w
->last_cursor_off_p
= w
->cursor_off_p
;
10444 if (w
== XWINDOW (selected_window
))
10445 w
->last_point
= make_number (BUF_PT (b
));
10447 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
10453 w
->window_end_valid
= w
->buffer
;
10454 #if 0 /* This is incorrect with variable-height lines. */
10455 xassert (XINT (w
->window_end_vpos
)
10456 < (WINDOW_TOTAL_LINES (w
)
10457 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
10459 w
->update_mode_line
= Qnil
;
10464 /* Mark the display of windows in the window tree rooted at WINDOW as
10465 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
10466 windows as accurate. If ACCURATE_P is zero, arrange for windows to
10467 be redisplayed the next time redisplay_internal is called. */
10470 mark_window_display_accurate (window
, accurate_p
)
10471 Lisp_Object window
;
10476 for (; !NILP (window
); window
= w
->next
)
10478 w
= XWINDOW (window
);
10479 mark_window_display_accurate_1 (w
, accurate_p
);
10481 if (!NILP (w
->vchild
))
10482 mark_window_display_accurate (w
->vchild
, accurate_p
);
10483 if (!NILP (w
->hchild
))
10484 mark_window_display_accurate (w
->hchild
, accurate_p
);
10489 update_overlay_arrows (1);
10493 /* Force a thorough redisplay the next time by setting
10494 last_arrow_position and last_arrow_string to t, which is
10495 unequal to any useful value of Voverlay_arrow_... */
10496 update_overlay_arrows (-1);
10501 /* Return value in display table DP (Lisp_Char_Table *) for character
10502 C. Since a display table doesn't have any parent, we don't have to
10503 follow parent. Do not call this function directly but use the
10504 macro DISP_CHAR_VECTOR. */
10507 disp_char_vector (dp
, c
)
10508 struct Lisp_Char_Table
*dp
;
10514 if (SINGLE_BYTE_CHAR_P (c
))
10515 return (dp
->contents
[c
]);
10517 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
10520 else if (code
[2] < 32)
10523 /* Here, the possible range of code[0] (== charset ID) is
10524 128..max_charset. Since the top level char table contains data
10525 for multibyte characters after 256th element, we must increment
10526 code[0] by 128 to get a correct index. */
10528 code
[3] = -1; /* anchor */
10530 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
10532 val
= dp
->contents
[code
[i
]];
10533 if (!SUB_CHAR_TABLE_P (val
))
10534 return (NILP (val
) ? dp
->defalt
: val
);
10537 /* Here, val is a sub char table. We return the default value of
10539 return (dp
->defalt
);
10544 /***********************************************************************
10546 ***********************************************************************/
10548 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
10551 redisplay_windows (window
)
10552 Lisp_Object window
;
10554 while (!NILP (window
))
10556 struct window
*w
= XWINDOW (window
);
10558 if (!NILP (w
->hchild
))
10559 redisplay_windows (w
->hchild
);
10560 else if (!NILP (w
->vchild
))
10561 redisplay_windows (w
->vchild
);
10564 displayed_buffer
= XBUFFER (w
->buffer
);
10565 /* Use list_of_error, not Qerror, so that
10566 we catch only errors and don't run the debugger. */
10567 internal_condition_case_1 (redisplay_window_0
, window
,
10569 redisplay_window_error
);
10577 redisplay_window_error ()
10579 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
10584 redisplay_window_0 (window
)
10585 Lisp_Object window
;
10587 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10588 redisplay_window (window
, 0);
10593 redisplay_window_1 (window
)
10594 Lisp_Object window
;
10596 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10597 redisplay_window (window
, 1);
10602 /* Increment GLYPH until it reaches END or CONDITION fails while
10603 adding (GLYPH)->pixel_width to X. */
10605 #define SKIP_GLYPHS(glyph, end, x, condition) \
10608 (x) += (glyph)->pixel_width; \
10611 while ((glyph) < (end) && (condition))
10614 /* Set cursor position of W. PT is assumed to be displayed in ROW.
10615 DELTA is the number of bytes by which positions recorded in ROW
10616 differ from current buffer positions. */
10619 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
10621 struct glyph_row
*row
;
10622 struct glyph_matrix
*matrix
;
10623 int delta
, delta_bytes
, dy
, dvpos
;
10625 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
10626 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
10627 /* The first glyph that starts a sequence of glyphs from string. */
10628 struct glyph
*string_start
;
10629 /* The X coordinate of string_start. */
10630 int string_start_x
;
10631 /* The last known character position. */
10632 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
10633 /* The last known character position before string_start. */
10634 int string_before_pos
;
10636 int pt_old
= PT
- delta
;
10638 /* Skip over glyphs not having an object at the start of the row.
10639 These are special glyphs like truncation marks on terminal
10641 if (row
->displays_text_p
)
10643 && INTEGERP (glyph
->object
)
10644 && glyph
->charpos
< 0)
10646 x
+= glyph
->pixel_width
;
10650 string_start
= NULL
;
10652 && !INTEGERP (glyph
->object
)
10653 && (!BUFFERP (glyph
->object
)
10654 || (last_pos
= glyph
->charpos
) < pt_old
))
10656 if (! STRINGP (glyph
->object
))
10658 string_start
= NULL
;
10659 x
+= glyph
->pixel_width
;
10664 string_before_pos
= last_pos
;
10665 string_start
= glyph
;
10666 string_start_x
= x
;
10667 /* Skip all glyphs from string. */
10668 SKIP_GLYPHS (glyph
, end
, x
, STRINGP (glyph
->object
));
10673 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
10675 /* We may have skipped over point because the previous glyphs
10676 are from string. As there's no easy way to know the
10677 character position of the current glyph, find the correct
10678 glyph on point by scanning from string_start again. */
10680 Lisp_Object string
;
10683 limit
= make_number (pt_old
+ 1);
10685 glyph
= string_start
;
10686 x
= string_start_x
;
10687 string
= glyph
->object
;
10688 pos
= string_buffer_position (w
, string
, string_before_pos
);
10689 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
10690 because we always put cursor after overlay strings. */
10691 while (pos
== 0 && glyph
< end
)
10693 string
= glyph
->object
;
10694 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10696 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
10699 while (glyph
< end
)
10701 pos
= XINT (Fnext_single_char_property_change
10702 (make_number (pos
), Qdisplay
, Qnil
, limit
));
10705 /* Skip glyphs from the same string. */
10706 string
= glyph
->object
;
10707 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10708 /* Skip glyphs from an overlay. */
10710 && ! string_buffer_position (w
, glyph
->object
, pos
))
10712 string
= glyph
->object
;
10713 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10718 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
10720 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
10721 w
->cursor
.y
= row
->y
+ dy
;
10723 if (w
== XWINDOW (selected_window
))
10725 if (!row
->continued_p
10726 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
10729 this_line_buffer
= XBUFFER (w
->buffer
);
10731 CHARPOS (this_line_start_pos
)
10732 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
10733 BYTEPOS (this_line_start_pos
)
10734 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
10736 CHARPOS (this_line_end_pos
)
10737 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
10738 BYTEPOS (this_line_end_pos
)
10739 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
10741 this_line_y
= w
->cursor
.y
;
10742 this_line_pixel_height
= row
->height
;
10743 this_line_vpos
= w
->cursor
.vpos
;
10744 this_line_start_x
= row
->x
;
10747 CHARPOS (this_line_start_pos
) = 0;
10752 /* Run window scroll functions, if any, for WINDOW with new window
10753 start STARTP. Sets the window start of WINDOW to that position.
10755 We assume that the window's buffer is really current. */
10757 static INLINE
struct text_pos
10758 run_window_scroll_functions (window
, startp
)
10759 Lisp_Object window
;
10760 struct text_pos startp
;
10762 struct window
*w
= XWINDOW (window
);
10763 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
10765 if (current_buffer
!= XBUFFER (w
->buffer
))
10768 if (!NILP (Vwindow_scroll_functions
))
10770 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
10771 make_number (CHARPOS (startp
)));
10772 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10773 /* In case the hook functions switch buffers. */
10774 if (current_buffer
!= XBUFFER (w
->buffer
))
10775 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10782 /* Make sure the line containing the cursor is fully visible.
10783 A value of 1 means there is nothing to be done.
10784 (Either the line is fully visible, or it cannot be made so,
10785 or we cannot tell.)
10787 If FORCE_P is non-zero, return 0 even if partial visible cursor row
10788 is higher than window.
10790 A value of 0 means the caller should do scrolling
10791 as if point had gone off the screen. */
10794 make_cursor_line_fully_visible (w
, force_p
)
10798 struct glyph_matrix
*matrix
;
10799 struct glyph_row
*row
;
10802 /* It's not always possible to find the cursor, e.g, when a window
10803 is full of overlay strings. Don't do anything in that case. */
10804 if (w
->cursor
.vpos
< 0)
10807 matrix
= w
->desired_matrix
;
10808 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
10810 /* If the cursor row is not partially visible, there's nothing to do. */
10811 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
10814 /* If the row the cursor is in is taller than the window's height,
10815 it's not clear what to do, so do nothing. */
10816 window_height
= window_box_height (w
);
10817 if (row
->height
>= window_height
)
10819 if (!force_p
|| w
->vscroll
)
10825 /* This code used to try to scroll the window just enough to make
10826 the line visible. It returned 0 to say that the caller should
10827 allocate larger glyph matrices. */
10829 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
10831 int dy
= row
->height
- row
->visible_height
;
10834 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
10836 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
10838 int dy
= - (row
->height
- row
->visible_height
);
10841 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
10844 /* When we change the cursor y-position of the selected window,
10845 change this_line_y as well so that the display optimization for
10846 the cursor line of the selected window in redisplay_internal uses
10847 the correct y-position. */
10848 if (w
== XWINDOW (selected_window
))
10849 this_line_y
= w
->cursor
.y
;
10851 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
10852 redisplay with larger matrices. */
10853 if (matrix
->nrows
< required_matrix_height (w
))
10855 fonts_changed_p
= 1;
10864 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
10865 non-zero means only WINDOW is redisplayed in redisplay_internal.
10866 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
10867 in redisplay_window to bring a partially visible line into view in
10868 the case that only the cursor has moved.
10870 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
10871 last screen line's vertical height extends past the end of the screen.
10875 1 if scrolling succeeded
10877 0 if scrolling didn't find point.
10879 -1 if new fonts have been loaded so that we must interrupt
10880 redisplay, adjust glyph matrices, and try again. */
10886 SCROLLING_NEED_LARGER_MATRICES
10890 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
10891 scroll_step
, temp_scroll_step
, last_line_misfit
)
10892 Lisp_Object window
;
10893 int just_this_one_p
;
10894 EMACS_INT scroll_conservatively
, scroll_step
;
10895 int temp_scroll_step
;
10896 int last_line_misfit
;
10898 struct window
*w
= XWINDOW (window
);
10899 struct frame
*f
= XFRAME (w
->frame
);
10900 struct text_pos scroll_margin_pos
;
10901 struct text_pos pos
;
10902 struct text_pos startp
;
10904 Lisp_Object window_end
;
10905 int this_scroll_margin
;
10909 int amount_to_scroll
= 0;
10910 Lisp_Object aggressive
;
10912 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
10915 debug_method_add (w
, "try_scrolling");
10918 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10920 /* Compute scroll margin height in pixels. We scroll when point is
10921 within this distance from the top or bottom of the window. */
10922 if (scroll_margin
> 0)
10924 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
10925 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
10928 this_scroll_margin
= 0;
10930 /* Force scroll_conservatively to have a reasonable value so it doesn't
10931 cause an overflow while computing how much to scroll. */
10932 if (scroll_conservatively
)
10933 scroll_conservatively
= min (scroll_conservatively
,
10934 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
10936 /* Compute how much we should try to scroll maximally to bring point
10938 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
10939 scroll_max
= max (scroll_step
,
10940 max (scroll_conservatively
, temp_scroll_step
));
10941 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
10942 || NUMBERP (current_buffer
->scroll_up_aggressively
))
10943 /* We're trying to scroll because of aggressive scrolling
10944 but no scroll_step is set. Choose an arbitrary one. Maybe
10945 there should be a variable for this. */
10949 scroll_max
*= FRAME_LINE_HEIGHT (f
);
10951 /* Decide whether we have to scroll down. Start at the window end
10952 and move this_scroll_margin up to find the position of the scroll
10954 window_end
= Fwindow_end (window
, Qt
);
10958 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
10959 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
10961 if (this_scroll_margin
|| extra_scroll_margin_lines
)
10963 start_display (&it
, w
, scroll_margin_pos
);
10964 if (this_scroll_margin
)
10965 move_it_vertically (&it
, - this_scroll_margin
);
10966 if (extra_scroll_margin_lines
)
10967 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
10968 scroll_margin_pos
= it
.current
.pos
;
10971 if (PT
>= CHARPOS (scroll_margin_pos
))
10975 /* Point is in the scroll margin at the bottom of the window, or
10976 below. Compute a new window start that makes point visible. */
10978 /* Compute the distance from the scroll margin to PT.
10979 Give up if the distance is greater than scroll_max. */
10980 start_display (&it
, w
, scroll_margin_pos
);
10982 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10983 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10985 /* To make point visible, we have to move the window start
10986 down so that the line the cursor is in is visible, which
10987 means we have to add in the height of the cursor line. */
10988 dy
= line_bottom_y (&it
) - y0
;
10990 if (dy
> scroll_max
)
10991 return SCROLLING_FAILED
;
10993 /* Move the window start down. If scrolling conservatively,
10994 move it just enough down to make point visible. If
10995 scroll_step is set, move it down by scroll_step. */
10996 start_display (&it
, w
, startp
);
10998 if (scroll_conservatively
)
10999 /* Set AMOUNT_TO_SCROLL to at least one line,
11000 and at most scroll_conservatively lines. */
11002 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11003 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11004 else if (scroll_step
|| temp_scroll_step
)
11005 amount_to_scroll
= scroll_max
;
11008 aggressive
= current_buffer
->scroll_up_aggressively
;
11009 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11010 if (NUMBERP (aggressive
))
11012 double float_amount
= XFLOATINT (aggressive
) * height
;
11013 amount_to_scroll
= float_amount
;
11014 if (amount_to_scroll
== 0 && float_amount
> 0)
11015 amount_to_scroll
= 1;
11019 if (amount_to_scroll
<= 0)
11020 return SCROLLING_FAILED
;
11022 /* If moving by amount_to_scroll leaves STARTP unchanged,
11023 move it down one screen line. */
11025 move_it_vertically (&it
, amount_to_scroll
);
11026 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
11027 move_it_by_lines (&it
, 1, 1);
11028 startp
= it
.current
.pos
;
11032 /* See if point is inside the scroll margin at the top of the
11034 scroll_margin_pos
= startp
;
11035 if (this_scroll_margin
)
11037 start_display (&it
, w
, startp
);
11038 move_it_vertically (&it
, this_scroll_margin
);
11039 scroll_margin_pos
= it
.current
.pos
;
11042 if (PT
< CHARPOS (scroll_margin_pos
))
11044 /* Point is in the scroll margin at the top of the window or
11045 above what is displayed in the window. */
11048 /* Compute the vertical distance from PT to the scroll
11049 margin position. Give up if distance is greater than
11051 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
11052 start_display (&it
, w
, pos
);
11054 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11055 it
.last_visible_y
, -1,
11056 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11057 dy
= it
.current_y
- y0
;
11058 if (dy
> scroll_max
)
11059 return SCROLLING_FAILED
;
11061 /* Compute new window start. */
11062 start_display (&it
, w
, startp
);
11064 if (scroll_conservatively
)
11066 max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11067 else if (scroll_step
|| temp_scroll_step
)
11068 amount_to_scroll
= scroll_max
;
11071 aggressive
= current_buffer
->scroll_down_aggressively
;
11072 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11073 if (NUMBERP (aggressive
))
11075 double float_amount
= XFLOATINT (aggressive
) * height
;
11076 amount_to_scroll
= float_amount
;
11077 if (amount_to_scroll
== 0 && float_amount
> 0)
11078 amount_to_scroll
= 1;
11082 if (amount_to_scroll
<= 0)
11083 return SCROLLING_FAILED
;
11085 move_it_vertically (&it
, - amount_to_scroll
);
11086 startp
= it
.current
.pos
;
11090 /* Run window scroll functions. */
11091 startp
= run_window_scroll_functions (window
, startp
);
11093 /* Display the window. Give up if new fonts are loaded, or if point
11095 if (!try_window (window
, startp
))
11096 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11097 else if (w
->cursor
.vpos
< 0)
11099 clear_glyph_matrix (w
->desired_matrix
);
11100 rc
= SCROLLING_FAILED
;
11104 /* Maybe forget recorded base line for line number display. */
11105 if (!just_this_one_p
11106 || current_buffer
->clip_changed
11107 || BEG_UNCHANGED
< CHARPOS (startp
))
11108 w
->base_line_number
= Qnil
;
11110 /* If cursor ends up on a partially visible line,
11111 treat that as being off the bottom of the screen. */
11112 if (! make_cursor_line_fully_visible (w
, extra_scroll_margin_lines
<= 1))
11114 clear_glyph_matrix (w
->desired_matrix
);
11115 ++extra_scroll_margin_lines
;
11118 rc
= SCROLLING_SUCCESS
;
11125 /* Compute a suitable window start for window W if display of W starts
11126 on a continuation line. Value is non-zero if a new window start
11129 The new window start will be computed, based on W's width, starting
11130 from the start of the continued line. It is the start of the
11131 screen line with the minimum distance from the old start W->start. */
11134 compute_window_start_on_continuation_line (w
)
11137 struct text_pos pos
, start_pos
;
11138 int window_start_changed_p
= 0;
11140 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
11142 /* If window start is on a continuation line... Window start may be
11143 < BEGV in case there's invisible text at the start of the
11144 buffer (M-x rmail, for example). */
11145 if (CHARPOS (start_pos
) > BEGV
11146 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
11149 struct glyph_row
*row
;
11151 /* Handle the case that the window start is out of range. */
11152 if (CHARPOS (start_pos
) < BEGV
)
11153 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
11154 else if (CHARPOS (start_pos
) > ZV
)
11155 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
11157 /* Find the start of the continued line. This should be fast
11158 because scan_buffer is fast (newline cache). */
11159 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
11160 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
11161 row
, DEFAULT_FACE_ID
);
11162 reseat_at_previous_visible_line_start (&it
);
11164 /* If the line start is "too far" away from the window start,
11165 say it takes too much time to compute a new window start. */
11166 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
11167 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
11169 int min_distance
, distance
;
11171 /* Move forward by display lines to find the new window
11172 start. If window width was enlarged, the new start can
11173 be expected to be > the old start. If window width was
11174 decreased, the new window start will be < the old start.
11175 So, we're looking for the display line start with the
11176 minimum distance from the old window start. */
11177 pos
= it
.current
.pos
;
11178 min_distance
= INFINITY
;
11179 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
11180 distance
< min_distance
)
11182 min_distance
= distance
;
11183 pos
= it
.current
.pos
;
11184 move_it_by_lines (&it
, 1, 0);
11187 /* Set the window start there. */
11188 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
11189 window_start_changed_p
= 1;
11193 return window_start_changed_p
;
11197 /* Try cursor movement in case text has not changed in window WINDOW,
11198 with window start STARTP. Value is
11200 CURSOR_MOVEMENT_SUCCESS if successful
11202 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
11204 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
11205 display. *SCROLL_STEP is set to 1, under certain circumstances, if
11206 we want to scroll as if scroll-step were set to 1. See the code.
11208 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
11209 which case we have to abort this redisplay, and adjust matrices
11214 CURSOR_MOVEMENT_SUCCESS
,
11215 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11216 CURSOR_MOVEMENT_MUST_SCROLL
,
11217 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11221 try_cursor_movement (window
, startp
, scroll_step
)
11222 Lisp_Object window
;
11223 struct text_pos startp
;
11226 struct window
*w
= XWINDOW (window
);
11227 struct frame
*f
= XFRAME (w
->frame
);
11228 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11231 if (inhibit_try_cursor_movement
)
11235 /* Handle case where text has not changed, only point, and it has
11236 not moved off the frame. */
11237 if (/* Point may be in this window. */
11238 PT
>= CHARPOS (startp
)
11239 /* Selective display hasn't changed. */
11240 && !current_buffer
->clip_changed
11241 /* Function force-mode-line-update is used to force a thorough
11242 redisplay. It sets either windows_or_buffers_changed or
11243 update_mode_lines. So don't take a shortcut here for these
11245 && !update_mode_lines
11246 && !windows_or_buffers_changed
11247 && !cursor_type_changed
11248 /* Can't use this case if highlighting a region. When a
11249 region exists, cursor movement has to do more than just
11251 && !(!NILP (Vtransient_mark_mode
)
11252 && !NILP (current_buffer
->mark_active
))
11253 && NILP (w
->region_showing
)
11254 && NILP (Vshow_trailing_whitespace
)
11255 /* Right after splitting windows, last_point may be nil. */
11256 && INTEGERP (w
->last_point
)
11257 /* This code is not used for mini-buffer for the sake of the case
11258 of redisplaying to replace an echo area message; since in
11259 that case the mini-buffer contents per se are usually
11260 unchanged. This code is of no real use in the mini-buffer
11261 since the handling of this_line_start_pos, etc., in redisplay
11262 handles the same cases. */
11263 && !EQ (window
, minibuf_window
)
11264 /* When splitting windows or for new windows, it happens that
11265 redisplay is called with a nil window_end_vpos or one being
11266 larger than the window. This should really be fixed in
11267 window.c. I don't have this on my list, now, so we do
11268 approximately the same as the old redisplay code. --gerd. */
11269 && INTEGERP (w
->window_end_vpos
)
11270 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11271 && (FRAME_WINDOW_P (f
)
11272 || !overlay_arrow_in_current_buffer_p ()))
11274 int this_scroll_margin
;
11275 struct glyph_row
*row
= NULL
;
11278 debug_method_add (w
, "cursor movement");
11281 /* Scroll if point within this distance from the top or bottom
11282 of the window. This is a pixel value. */
11283 this_scroll_margin
= max (0, scroll_margin
);
11284 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11285 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11287 /* Start with the row the cursor was displayed during the last
11288 not paused redisplay. Give up if that row is not valid. */
11289 if (w
->last_cursor
.vpos
< 0
11290 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11291 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11294 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11295 if (row
->mode_line_p
)
11297 if (!row
->enabled_p
)
11298 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11301 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11304 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11306 if (PT
> XFASTINT (w
->last_point
))
11308 /* Point has moved forward. */
11309 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11310 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11312 xassert (row
->enabled_p
);
11316 /* The end position of a row equals the start position
11317 of the next row. If PT is there, we would rather
11318 display it in the next line. */
11319 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11320 && MATRIX_ROW_END_CHARPOS (row
) == PT
11321 && !cursor_row_p (w
, row
))
11324 /* If within the scroll margin, scroll. Note that
11325 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11326 the next line would be drawn, and that
11327 this_scroll_margin can be zero. */
11328 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11329 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11330 /* Line is completely visible last line in window
11331 and PT is to be set in the next line. */
11332 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11333 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11334 && !row
->ends_at_zv_p
11335 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11338 else if (PT
< XFASTINT (w
->last_point
))
11340 /* Cursor has to be moved backward. Note that PT >=
11341 CHARPOS (startp) because of the outer
11343 while (!row
->mode_line_p
11344 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11345 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11346 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
11347 && (row
->y
> this_scroll_margin
11348 || CHARPOS (startp
) == BEGV
))
11350 xassert (row
->enabled_p
);
11354 /* Consider the following case: Window starts at BEGV,
11355 there is invisible, intangible text at BEGV, so that
11356 display starts at some point START > BEGV. It can
11357 happen that we are called with PT somewhere between
11358 BEGV and START. Try to handle that case. */
11359 if (row
< w
->current_matrix
->rows
11360 || row
->mode_line_p
)
11362 row
= w
->current_matrix
->rows
;
11363 if (row
->mode_line_p
)
11367 /* Due to newlines in overlay strings, we may have to
11368 skip forward over overlay strings. */
11369 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11370 && MATRIX_ROW_END_CHARPOS (row
) == PT
11371 && !cursor_row_p (w
, row
))
11374 /* If within the scroll margin, scroll. */
11375 if (row
->y
< this_scroll_margin
11376 && CHARPOS (startp
) != BEGV
)
11380 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
11381 || PT
> MATRIX_ROW_END_CHARPOS (row
))
11383 /* if PT is not in the glyph row, give up. */
11384 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11386 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
11388 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
11389 && !row
->ends_at_zv_p
11390 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11391 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11392 else if (row
->height
> window_box_height (w
))
11394 /* If we end up in a partially visible line, let's
11395 make it fully visible, except when it's taller
11396 than the window, in which case we can't do much
11399 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11403 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11404 if (!make_cursor_line_fully_visible (w
, 0))
11405 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11407 rc
= CURSOR_MOVEMENT_SUCCESS
;
11411 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11414 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11415 rc
= CURSOR_MOVEMENT_SUCCESS
;
11424 set_vertical_scroll_bar (w
)
11427 int start
, end
, whole
;
11429 /* Calculate the start and end positions for the current window.
11430 At some point, it would be nice to choose between scrollbars
11431 which reflect the whole buffer size, with special markers
11432 indicating narrowing, and scrollbars which reflect only the
11435 Note that mini-buffers sometimes aren't displaying any text. */
11436 if (!MINI_WINDOW_P (w
)
11437 || (w
== XWINDOW (minibuf_window
)
11438 && NILP (echo_area_buffer
[0])))
11440 struct buffer
*buf
= XBUFFER (w
->buffer
);
11441 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
11442 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
11443 /* I don't think this is guaranteed to be right. For the
11444 moment, we'll pretend it is. */
11445 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
11449 if (whole
< (end
- start
))
11450 whole
= end
- start
;
11453 start
= end
= whole
= 0;
11455 /* Indicate what this scroll bar ought to be displaying now. */
11456 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
11460 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
11461 selected_window is redisplayed.
11463 We can return without actually redisplaying the window if
11464 fonts_changed_p is nonzero. In that case, redisplay_internal will
11468 redisplay_window (window
, just_this_one_p
)
11469 Lisp_Object window
;
11470 int just_this_one_p
;
11472 struct window
*w
= XWINDOW (window
);
11473 struct frame
*f
= XFRAME (w
->frame
);
11474 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11475 struct buffer
*old
= current_buffer
;
11476 struct text_pos lpoint
, opoint
, startp
;
11477 int update_mode_line
;
11480 /* Record it now because it's overwritten. */
11481 int current_matrix_up_to_date_p
= 0;
11482 int used_current_matrix_p
= 0;
11483 /* This is less strict than current_matrix_up_to_date_p.
11484 It indictes that the buffer contents and narrowing are unchanged. */
11485 int buffer_unchanged_p
= 0;
11486 int temp_scroll_step
= 0;
11487 int count
= SPECPDL_INDEX ();
11489 int centering_position
;
11490 int last_line_misfit
= 0;
11492 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11495 /* W must be a leaf window here. */
11496 xassert (!NILP (w
->buffer
));
11498 *w
->desired_matrix
->method
= 0;
11501 specbind (Qinhibit_point_motion_hooks
, Qt
);
11503 reconsider_clip_changes (w
, buffer
);
11505 /* Has the mode line to be updated? */
11506 update_mode_line
= (!NILP (w
->update_mode_line
)
11507 || update_mode_lines
11508 || buffer
->clip_changed
11509 || buffer
->prevent_redisplay_optimizations_p
);
11511 if (MINI_WINDOW_P (w
))
11513 if (w
== XWINDOW (echo_area_window
)
11514 && !NILP (echo_area_buffer
[0]))
11516 if (update_mode_line
)
11517 /* We may have to update a tty frame's menu bar or a
11518 tool-bar. Example `M-x C-h C-h C-g'. */
11519 goto finish_menu_bars
;
11521 /* We've already displayed the echo area glyphs in this window. */
11522 goto finish_scroll_bars
;
11524 else if ((w
!= XWINDOW (minibuf_window
)
11525 || minibuf_level
== 0)
11526 /* When buffer is nonempty, redisplay window normally. */
11527 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
11528 /* Quail displays non-mini buffers in minibuffer window.
11529 In that case, redisplay the window normally. */
11530 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
11532 /* W is a mini-buffer window, but it's not active, so clear
11534 int yb
= window_text_bottom_y (w
);
11535 struct glyph_row
*row
;
11538 for (y
= 0, row
= w
->desired_matrix
->rows
;
11540 y
+= row
->height
, ++row
)
11541 blank_row (w
, row
, y
);
11542 goto finish_scroll_bars
;
11545 clear_glyph_matrix (w
->desired_matrix
);
11548 /* Otherwise set up data on this window; select its buffer and point
11550 /* Really select the buffer, for the sake of buffer-local
11552 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11553 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
11555 current_matrix_up_to_date_p
11556 = (!NILP (w
->window_end_valid
)
11557 && !current_buffer
->clip_changed
11558 && !current_buffer
->prevent_redisplay_optimizations_p
11559 && XFASTINT (w
->last_modified
) >= MODIFF
11560 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11563 = (!NILP (w
->window_end_valid
)
11564 && !current_buffer
->clip_changed
11565 && XFASTINT (w
->last_modified
) >= MODIFF
11566 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11568 /* When windows_or_buffers_changed is non-zero, we can't rely on
11569 the window end being valid, so set it to nil there. */
11570 if (windows_or_buffers_changed
)
11572 /* If window starts on a continuation line, maybe adjust the
11573 window start in case the window's width changed. */
11574 if (XMARKER (w
->start
)->buffer
== current_buffer
)
11575 compute_window_start_on_continuation_line (w
);
11577 w
->window_end_valid
= Qnil
;
11580 /* Some sanity checks. */
11581 CHECK_WINDOW_END (w
);
11582 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
11584 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
11587 /* If %c is in mode line, update it if needed. */
11588 if (!NILP (w
->column_number_displayed
)
11589 /* This alternative quickly identifies a common case
11590 where no change is needed. */
11591 && !(PT
== XFASTINT (w
->last_point
)
11592 && XFASTINT (w
->last_modified
) >= MODIFF
11593 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11594 && (XFASTINT (w
->column_number_displayed
)
11595 != (int) current_column ())) /* iftc */
11596 update_mode_line
= 1;
11598 /* Count number of windows showing the selected buffer. An indirect
11599 buffer counts as its base buffer. */
11600 if (!just_this_one_p
)
11602 struct buffer
*current_base
, *window_base
;
11603 current_base
= current_buffer
;
11604 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11605 if (current_base
->base_buffer
)
11606 current_base
= current_base
->base_buffer
;
11607 if (window_base
->base_buffer
)
11608 window_base
= window_base
->base_buffer
;
11609 if (current_base
== window_base
)
11613 /* Point refers normally to the selected window. For any other
11614 window, set up appropriate value. */
11615 if (!EQ (window
, selected_window
))
11617 int new_pt
= XMARKER (w
->pointm
)->charpos
;
11618 int new_pt_byte
= marker_byte_position (w
->pointm
);
11622 new_pt_byte
= BEGV_BYTE
;
11623 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
11625 else if (new_pt
> (ZV
- 1))
11628 new_pt_byte
= ZV_BYTE
;
11629 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
11632 /* We don't use SET_PT so that the point-motion hooks don't run. */
11633 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
11636 /* If any of the character widths specified in the display table
11637 have changed, invalidate the width run cache. It's true that
11638 this may be a bit late to catch such changes, but the rest of
11639 redisplay goes (non-fatally) haywire when the display table is
11640 changed, so why should we worry about doing any better? */
11641 if (current_buffer
->width_run_cache
)
11643 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
11645 if (! disptab_matches_widthtab (disptab
,
11646 XVECTOR (current_buffer
->width_table
)))
11648 invalidate_region_cache (current_buffer
,
11649 current_buffer
->width_run_cache
,
11651 recompute_width_table (current_buffer
, disptab
);
11655 /* If window-start is screwed up, choose a new one. */
11656 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
11659 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11661 /* If someone specified a new starting point but did not insist,
11662 check whether it can be used. */
11663 if (!NILP (w
->optional_new_start
)
11664 && CHARPOS (startp
) >= BEGV
11665 && CHARPOS (startp
) <= ZV
)
11667 w
->optional_new_start
= Qnil
;
11668 start_display (&it
, w
, startp
);
11669 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11670 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11671 if (IT_CHARPOS (it
) == PT
)
11672 w
->force_start
= Qt
;
11673 /* IT may overshoot PT if text at PT is invisible. */
11674 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
11675 w
->force_start
= Qt
;
11680 /* Handle case where place to start displaying has been specified,
11681 unless the specified location is outside the accessible range. */
11682 if (!NILP (w
->force_start
)
11683 || w
->frozen_window_start_p
)
11685 /* We set this later on if we have to adjust point. */
11688 w
->force_start
= Qnil
;
11690 w
->window_end_valid
= Qnil
;
11692 /* Forget any recorded base line for line number display. */
11693 if (!buffer_unchanged_p
)
11694 w
->base_line_number
= Qnil
;
11696 /* Redisplay the mode line. Select the buffer properly for that.
11697 Also, run the hook window-scroll-functions
11698 because we have scrolled. */
11699 /* Note, we do this after clearing force_start because
11700 if there's an error, it is better to forget about force_start
11701 than to get into an infinite loop calling the hook functions
11702 and having them get more errors. */
11703 if (!update_mode_line
11704 || ! NILP (Vwindow_scroll_functions
))
11706 update_mode_line
= 1;
11707 w
->update_mode_line
= Qt
;
11708 startp
= run_window_scroll_functions (window
, startp
);
11711 w
->last_modified
= make_number (0);
11712 w
->last_overlay_modified
= make_number (0);
11713 if (CHARPOS (startp
) < BEGV
)
11714 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
11715 else if (CHARPOS (startp
) > ZV
)
11716 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
11718 /* Redisplay, then check if cursor has been set during the
11719 redisplay. Give up if new fonts were loaded. */
11720 if (!try_window (window
, startp
))
11722 w
->force_start
= Qt
;
11723 clear_glyph_matrix (w
->desired_matrix
);
11724 goto need_larger_matrices
;
11727 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
11729 /* If point does not appear, try to move point so it does
11730 appear. The desired matrix has been built above, so we
11731 can use it here. */
11732 new_vpos
= window_box_height (w
) / 2;
11735 if (!make_cursor_line_fully_visible (w
, 0))
11737 /* Point does appear, but on a line partly visible at end of window.
11738 Move it back to a fully-visible line. */
11739 new_vpos
= window_box_height (w
);
11742 /* If we need to move point for either of the above reasons,
11743 now actually do it. */
11746 struct glyph_row
*row
;
11748 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
11749 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
11752 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
11753 MATRIX_ROW_START_BYTEPOS (row
));
11755 if (w
!= XWINDOW (selected_window
))
11756 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
11757 else if (current_buffer
== old
)
11758 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11760 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
11762 /* If we are highlighting the region, then we just changed
11763 the region, so redisplay to show it. */
11764 if (!NILP (Vtransient_mark_mode
)
11765 && !NILP (current_buffer
->mark_active
))
11767 clear_glyph_matrix (w
->desired_matrix
);
11768 if (!try_window (window
, startp
))
11769 goto need_larger_matrices
;
11774 debug_method_add (w
, "forced window start");
11779 /* Handle case where text has not changed, only point, and it has
11780 not moved off the frame, and we are not retrying after hscroll.
11781 (current_matrix_up_to_date_p is nonzero when retrying.) */
11782 if (current_matrix_up_to_date_p
11783 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
11784 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
11788 case CURSOR_MOVEMENT_SUCCESS
:
11789 used_current_matrix_p
= 1;
11792 #if 0 /* try_cursor_movement never returns this value. */
11793 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
11794 goto need_larger_matrices
;
11797 case CURSOR_MOVEMENT_MUST_SCROLL
:
11798 goto try_to_scroll
;
11804 /* If current starting point was originally the beginning of a line
11805 but no longer is, find a new starting point. */
11806 else if (!NILP (w
->start_at_line_beg
)
11807 && !(CHARPOS (startp
) <= BEGV
11808 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
11811 debug_method_add (w
, "recenter 1");
11816 /* Try scrolling with try_window_id. Value is > 0 if update has
11817 been done, it is -1 if we know that the same window start will
11818 not work. It is 0 if unsuccessful for some other reason. */
11819 else if ((tem
= try_window_id (w
)) != 0)
11822 debug_method_add (w
, "try_window_id %d", tem
);
11825 if (fonts_changed_p
)
11826 goto need_larger_matrices
;
11830 /* Otherwise try_window_id has returned -1 which means that we
11831 don't want the alternative below this comment to execute. */
11833 else if (CHARPOS (startp
) >= BEGV
11834 && CHARPOS (startp
) <= ZV
11835 && PT
>= CHARPOS (startp
)
11836 && (CHARPOS (startp
) < ZV
11837 /* Avoid starting at end of buffer. */
11838 || CHARPOS (startp
) == BEGV
11839 || (XFASTINT (w
->last_modified
) >= MODIFF
11840 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
11843 debug_method_add (w
, "same window start");
11846 /* Try to redisplay starting at same place as before.
11847 If point has not moved off frame, accept the results. */
11848 if (!current_matrix_up_to_date_p
11849 /* Don't use try_window_reusing_current_matrix in this case
11850 because a window scroll function can have changed the
11852 || !NILP (Vwindow_scroll_functions
)
11853 || MINI_WINDOW_P (w
)
11854 || !(used_current_matrix_p
=
11855 try_window_reusing_current_matrix (w
)))
11857 IF_DEBUG (debug_method_add (w
, "1"));
11858 try_window (window
, startp
);
11861 if (fonts_changed_p
)
11862 goto need_larger_matrices
;
11864 if (w
->cursor
.vpos
>= 0)
11866 if (!just_this_one_p
11867 || current_buffer
->clip_changed
11868 || BEG_UNCHANGED
< CHARPOS (startp
))
11869 /* Forget any recorded base line for line number display. */
11870 w
->base_line_number
= Qnil
;
11872 if (!make_cursor_line_fully_visible (w
, 1))
11874 clear_glyph_matrix (w
->desired_matrix
);
11875 last_line_misfit
= 1;
11877 /* Drop through and scroll. */
11882 clear_glyph_matrix (w
->desired_matrix
);
11887 w
->last_modified
= make_number (0);
11888 w
->last_overlay_modified
= make_number (0);
11890 /* Redisplay the mode line. Select the buffer properly for that. */
11891 if (!update_mode_line
)
11893 update_mode_line
= 1;
11894 w
->update_mode_line
= Qt
;
11897 /* Try to scroll by specified few lines. */
11898 if ((scroll_conservatively
11900 || temp_scroll_step
11901 || NUMBERP (current_buffer
->scroll_up_aggressively
)
11902 || NUMBERP (current_buffer
->scroll_down_aggressively
))
11903 && !current_buffer
->clip_changed
11904 && CHARPOS (startp
) >= BEGV
11905 && CHARPOS (startp
) <= ZV
)
11907 /* The function returns -1 if new fonts were loaded, 1 if
11908 successful, 0 if not successful. */
11909 int rc
= try_scrolling (window
, just_this_one_p
,
11910 scroll_conservatively
,
11912 temp_scroll_step
, last_line_misfit
);
11915 case SCROLLING_SUCCESS
:
11918 case SCROLLING_NEED_LARGER_MATRICES
:
11919 goto need_larger_matrices
;
11921 case SCROLLING_FAILED
:
11929 /* Finally, just choose place to start which centers point */
11932 centering_position
= window_box_height (w
) / 2;
11935 /* Jump here with centering_position already set to 0. */
11938 debug_method_add (w
, "recenter");
11941 /* w->vscroll = 0; */
11943 /* Forget any previously recorded base line for line number display. */
11944 if (!buffer_unchanged_p
)
11945 w
->base_line_number
= Qnil
;
11947 /* Move backward half the height of the window. */
11948 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
11949 it
.current_y
= it
.last_visible_y
;
11950 move_it_vertically_backward (&it
, centering_position
);
11951 xassert (IT_CHARPOS (it
) >= BEGV
);
11953 /* The function move_it_vertically_backward may move over more
11954 than the specified y-distance. If it->w is small, e.g. a
11955 mini-buffer window, we may end up in front of the window's
11956 display area. Start displaying at the start of the line
11957 containing PT in this case. */
11958 if (it
.current_y
<= 0)
11960 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
11961 move_it_vertically (&it
, 0);
11962 xassert (IT_CHARPOS (it
) <= PT
);
11966 it
.current_x
= it
.hpos
= 0;
11968 /* Set startp here explicitly in case that helps avoid an infinite loop
11969 in case the window-scroll-functions functions get errors. */
11970 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
11972 /* Run scroll hooks. */
11973 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
11975 /* Redisplay the window. */
11976 if (!current_matrix_up_to_date_p
11977 || windows_or_buffers_changed
11978 || cursor_type_changed
11979 /* Don't use try_window_reusing_current_matrix in this case
11980 because it can have changed the buffer. */
11981 || !NILP (Vwindow_scroll_functions
)
11982 || !just_this_one_p
11983 || MINI_WINDOW_P (w
)
11984 || !(used_current_matrix_p
=
11985 try_window_reusing_current_matrix (w
)))
11986 try_window (window
, startp
);
11988 /* If new fonts have been loaded (due to fontsets), give up. We
11989 have to start a new redisplay since we need to re-adjust glyph
11991 if (fonts_changed_p
)
11992 goto need_larger_matrices
;
11994 /* If cursor did not appear assume that the middle of the window is
11995 in the first line of the window. Do it again with the next line.
11996 (Imagine a window of height 100, displaying two lines of height
11997 60. Moving back 50 from it->last_visible_y will end in the first
11999 if (w
->cursor
.vpos
< 0)
12001 if (!NILP (w
->window_end_valid
)
12002 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
12004 clear_glyph_matrix (w
->desired_matrix
);
12005 move_it_by_lines (&it
, 1, 0);
12006 try_window (window
, it
.current
.pos
);
12008 else if (PT
< IT_CHARPOS (it
))
12010 clear_glyph_matrix (w
->desired_matrix
);
12011 move_it_by_lines (&it
, -1, 0);
12012 try_window (window
, it
.current
.pos
);
12016 /* Not much we can do about it. */
12020 /* Consider the following case: Window starts at BEGV, there is
12021 invisible, intangible text at BEGV, so that display starts at
12022 some point START > BEGV. It can happen that we are called with
12023 PT somewhere between BEGV and START. Try to handle that case. */
12024 if (w
->cursor
.vpos
< 0)
12026 struct glyph_row
*row
= w
->current_matrix
->rows
;
12027 if (row
->mode_line_p
)
12029 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12032 if (!make_cursor_line_fully_visible (w
, centering_position
> 0))
12034 /* If vscroll is enabled, disable it and try again. */
12038 clear_glyph_matrix (w
->desired_matrix
);
12042 /* If centering point failed to make the whole line visible,
12043 put point at the top instead. That has to make the whole line
12044 visible, if it can be done. */
12045 clear_glyph_matrix (w
->desired_matrix
);
12046 centering_position
= 0;
12052 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12053 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
12054 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
12057 /* Display the mode line, if we must. */
12058 if ((update_mode_line
12059 /* If window not full width, must redo its mode line
12060 if (a) the window to its side is being redone and
12061 (b) we do a frame-based redisplay. This is a consequence
12062 of how inverted lines are drawn in frame-based redisplay. */
12063 || (!just_this_one_p
12064 && !FRAME_WINDOW_P (f
)
12065 && !WINDOW_FULL_WIDTH_P (w
))
12066 /* Line number to display. */
12067 || INTEGERP (w
->base_line_pos
)
12068 /* Column number is displayed and different from the one displayed. */
12069 || (!NILP (w
->column_number_displayed
)
12070 && (XFASTINT (w
->column_number_displayed
)
12071 != (int) current_column ()))) /* iftc */
12072 /* This means that the window has a mode line. */
12073 && (WINDOW_WANTS_MODELINE_P (w
)
12074 || WINDOW_WANTS_HEADER_LINE_P (w
)))
12076 display_mode_lines (w
);
12078 /* If mode line height has changed, arrange for a thorough
12079 immediate redisplay using the correct mode line height. */
12080 if (WINDOW_WANTS_MODELINE_P (w
)
12081 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12083 fonts_changed_p
= 1;
12084 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12085 = DESIRED_MODE_LINE_HEIGHT (w
);
12088 /* If top line height has changed, arrange for a thorough
12089 immediate redisplay using the correct mode line height. */
12090 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12091 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
12093 fonts_changed_p
= 1;
12094 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
12095 = DESIRED_HEADER_LINE_HEIGHT (w
);
12098 if (fonts_changed_p
)
12099 goto need_larger_matrices
;
12102 if (!line_number_displayed
12103 && !BUFFERP (w
->base_line_pos
))
12105 w
->base_line_pos
= Qnil
;
12106 w
->base_line_number
= Qnil
;
12111 /* When we reach a frame's selected window, redo the frame's menu bar. */
12112 if (update_mode_line
12113 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
12115 int redisplay_menu_p
= 0;
12116 int redisplay_tool_bar_p
= 0;
12118 if (FRAME_WINDOW_P (f
))
12120 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
12121 || defined (USE_GTK)
12122 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
12124 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12128 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12130 if (redisplay_menu_p
)
12131 display_menu_bar (w
);
12133 #ifdef HAVE_WINDOW_SYSTEM
12135 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
12137 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
12138 && (FRAME_TOOL_BAR_LINES (f
) > 0
12139 || auto_resize_tool_bars_p
);
12143 if (redisplay_tool_bar_p
)
12144 redisplay_tool_bar (f
);
12148 #ifdef HAVE_WINDOW_SYSTEM
12149 if (update_window_fringes (w
, 0)
12150 && !just_this_one_p
12151 && (used_current_matrix_p
|| overlay_arrow_seen
)
12152 && !w
->pseudo_window_p
)
12156 draw_window_fringes (w
);
12160 #endif /* HAVE_WINDOW_SYSTEM */
12162 /* We go to this label, with fonts_changed_p nonzero,
12163 if it is necessary to try again using larger glyph matrices.
12164 We have to redeem the scroll bar even in this case,
12165 because the loop in redisplay_internal expects that. */
12166 need_larger_matrices
:
12168 finish_scroll_bars
:
12170 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
12172 /* Set the thumb's position and size. */
12173 set_vertical_scroll_bar (w
);
12175 /* Note that we actually used the scroll bar attached to this
12176 window, so it shouldn't be deleted at the end of redisplay. */
12177 redeem_scroll_bar_hook (w
);
12180 /* Restore current_buffer and value of point in it. */
12181 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
12182 set_buffer_internal_1 (old
);
12183 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12185 unbind_to (count
, Qnil
);
12189 /* Build the complete desired matrix of WINDOW with a window start
12190 buffer position POS. Value is non-zero if successful. It is zero
12191 if fonts were loaded during redisplay which makes re-adjusting
12192 glyph matrices necessary. */
12195 try_window (window
, pos
)
12196 Lisp_Object window
;
12197 struct text_pos pos
;
12199 struct window
*w
= XWINDOW (window
);
12201 struct glyph_row
*last_text_row
= NULL
;
12203 /* Make POS the new window start. */
12204 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
12206 /* Mark cursor position as unknown. No overlay arrow seen. */
12207 w
->cursor
.vpos
= -1;
12208 overlay_arrow_seen
= 0;
12210 /* Initialize iterator and info to start at POS. */
12211 start_display (&it
, w
, pos
);
12213 /* Display all lines of W. */
12214 while (it
.current_y
< it
.last_visible_y
)
12216 if (display_line (&it
))
12217 last_text_row
= it
.glyph_row
- 1;
12218 if (fonts_changed_p
)
12222 /* If bottom moved off end of frame, change mode line percentage. */
12223 if (XFASTINT (w
->window_end_pos
) <= 0
12224 && Z
!= IT_CHARPOS (it
))
12225 w
->update_mode_line
= Qt
;
12227 /* Set window_end_pos to the offset of the last character displayed
12228 on the window from the end of current_buffer. Set
12229 window_end_vpos to its row number. */
12232 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
12233 w
->window_end_bytepos
12234 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12236 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12238 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12239 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12240 ->displays_text_p
);
12244 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12245 w
->window_end_pos
= make_number (Z
- ZV
);
12246 w
->window_end_vpos
= make_number (0);
12249 /* But that is not valid info until redisplay finishes. */
12250 w
->window_end_valid
= Qnil
;
12256 /************************************************************************
12257 Window redisplay reusing current matrix when buffer has not changed
12258 ************************************************************************/
12260 /* Try redisplay of window W showing an unchanged buffer with a
12261 different window start than the last time it was displayed by
12262 reusing its current matrix. Value is non-zero if successful.
12263 W->start is the new window start. */
12266 try_window_reusing_current_matrix (w
)
12269 struct frame
*f
= XFRAME (w
->frame
);
12270 struct glyph_row
*row
, *bottom_row
;
12273 struct text_pos start
, new_start
;
12274 int nrows_scrolled
, i
;
12275 struct glyph_row
*last_text_row
;
12276 struct glyph_row
*last_reused_text_row
;
12277 struct glyph_row
*start_row
;
12278 int start_vpos
, min_y
, max_y
;
12281 if (inhibit_try_window_reusing
)
12285 if (/* This function doesn't handle terminal frames. */
12286 !FRAME_WINDOW_P (f
)
12287 /* Don't try to reuse the display if windows have been split
12289 || windows_or_buffers_changed
12290 || cursor_type_changed
)
12293 /* Can't do this if region may have changed. */
12294 if ((!NILP (Vtransient_mark_mode
)
12295 && !NILP (current_buffer
->mark_active
))
12296 || !NILP (w
->region_showing
)
12297 || !NILP (Vshow_trailing_whitespace
))
12300 /* If top-line visibility has changed, give up. */
12301 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12302 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12305 /* Give up if old or new display is scrolled vertically. We could
12306 make this function handle this, but right now it doesn't. */
12307 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12308 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
12311 /* The variable new_start now holds the new window start. The old
12312 start `start' can be determined from the current matrix. */
12313 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
12314 start
= start_row
->start
.pos
;
12315 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12317 /* Clear the desired matrix for the display below. */
12318 clear_glyph_matrix (w
->desired_matrix
);
12320 if (CHARPOS (new_start
) <= CHARPOS (start
))
12324 /* Don't use this method if the display starts with an ellipsis
12325 displayed for invisible text. It's not easy to handle that case
12326 below, and it's certainly not worth the effort since this is
12327 not a frequent case. */
12328 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
12331 IF_DEBUG (debug_method_add (w
, "twu1"));
12333 /* Display up to a row that can be reused. The variable
12334 last_text_row is set to the last row displayed that displays
12335 text. Note that it.vpos == 0 if or if not there is a
12336 header-line; it's not the same as the MATRIX_ROW_VPOS! */
12337 start_display (&it
, w
, new_start
);
12338 first_row_y
= it
.current_y
;
12339 w
->cursor
.vpos
= -1;
12340 last_text_row
= last_reused_text_row
= NULL
;
12342 while (it
.current_y
< it
.last_visible_y
12343 && IT_CHARPOS (it
) < CHARPOS (start
)
12344 && !fonts_changed_p
)
12345 if (display_line (&it
))
12346 last_text_row
= it
.glyph_row
- 1;
12348 /* A value of current_y < last_visible_y means that we stopped
12349 at the previous window start, which in turn means that we
12350 have at least one reusable row. */
12351 if (it
.current_y
< it
.last_visible_y
)
12353 /* IT.vpos always starts from 0; it counts text lines. */
12354 nrows_scrolled
= it
.vpos
;
12356 /* Find PT if not already found in the lines displayed. */
12357 if (w
->cursor
.vpos
< 0)
12359 int dy
= it
.current_y
- first_row_y
;
12361 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12362 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
12364 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
12365 dy
, nrows_scrolled
);
12368 clear_glyph_matrix (w
->desired_matrix
);
12373 /* Scroll the display. Do it before the current matrix is
12374 changed. The problem here is that update has not yet
12375 run, i.e. part of the current matrix is not up to date.
12376 scroll_run_hook will clear the cursor, and use the
12377 current matrix to get the height of the row the cursor is
12379 run
.current_y
= first_row_y
;
12380 run
.desired_y
= it
.current_y
;
12381 run
.height
= it
.last_visible_y
- it
.current_y
;
12383 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
12386 rif
->update_window_begin_hook (w
);
12387 rif
->clear_window_mouse_face (w
);
12388 rif
->scroll_run_hook (w
, &run
);
12389 rif
->update_window_end_hook (w
, 0, 0);
12393 /* Shift current matrix down by nrows_scrolled lines. */
12394 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12395 rotate_matrix (w
->current_matrix
,
12397 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12400 /* Disable lines that must be updated. */
12401 for (i
= 0; i
< it
.vpos
; ++i
)
12402 (start_row
+ i
)->enabled_p
= 0;
12404 /* Re-compute Y positions. */
12405 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12406 max_y
= it
.last_visible_y
;
12407 for (row
= start_row
+ nrows_scrolled
;
12411 row
->y
= it
.current_y
;
12412 row
->visible_height
= row
->height
;
12414 if (row
->y
< min_y
)
12415 row
->visible_height
-= min_y
- row
->y
;
12416 if (row
->y
+ row
->height
> max_y
)
12417 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12418 row
->redraw_fringe_bitmaps_p
= 1;
12420 it
.current_y
+= row
->height
;
12422 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12423 last_reused_text_row
= row
;
12424 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
12428 /* Disable lines in the current matrix which are now
12429 below the window. */
12430 for (++row
; row
< bottom_row
; ++row
)
12431 row
->enabled_p
= 0;
12434 /* Update window_end_pos etc.; last_reused_text_row is the last
12435 reused row from the current matrix containing text, if any.
12436 The value of last_text_row is the last displayed line
12437 containing text. */
12438 if (last_reused_text_row
)
12440 w
->window_end_bytepos
12441 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
12443 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
12445 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
12446 w
->current_matrix
));
12448 else if (last_text_row
)
12450 w
->window_end_bytepos
12451 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12453 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12455 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12459 /* This window must be completely empty. */
12460 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12461 w
->window_end_pos
= make_number (Z
- ZV
);
12462 w
->window_end_vpos
= make_number (0);
12464 w
->window_end_valid
= Qnil
;
12466 /* Update hint: don't try scrolling again in update_window. */
12467 w
->desired_matrix
->no_scrolling_p
= 1;
12470 debug_method_add (w
, "try_window_reusing_current_matrix 1");
12474 else if (CHARPOS (new_start
) > CHARPOS (start
))
12476 struct glyph_row
*pt_row
, *row
;
12477 struct glyph_row
*first_reusable_row
;
12478 struct glyph_row
*first_row_to_display
;
12480 int yb
= window_text_bottom_y (w
);
12482 /* Find the row starting at new_start, if there is one. Don't
12483 reuse a partially visible line at the end. */
12484 first_reusable_row
= start_row
;
12485 while (first_reusable_row
->enabled_p
12486 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
12487 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12488 < CHARPOS (new_start
)))
12489 ++first_reusable_row
;
12491 /* Give up if there is no row to reuse. */
12492 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
12493 || !first_reusable_row
->enabled_p
12494 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12495 != CHARPOS (new_start
)))
12498 /* We can reuse fully visible rows beginning with
12499 first_reusable_row to the end of the window. Set
12500 first_row_to_display to the first row that cannot be reused.
12501 Set pt_row to the row containing point, if there is any. */
12503 for (first_row_to_display
= first_reusable_row
;
12504 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
12505 ++first_row_to_display
)
12507 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
12508 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
12509 pt_row
= first_row_to_display
;
12512 /* Start displaying at the start of first_row_to_display. */
12513 xassert (first_row_to_display
->y
< yb
);
12514 init_to_row_start (&it
, w
, first_row_to_display
);
12516 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
12518 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
12520 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
12521 + WINDOW_HEADER_LINE_HEIGHT (w
));
12523 /* Display lines beginning with first_row_to_display in the
12524 desired matrix. Set last_text_row to the last row displayed
12525 that displays text. */
12526 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
12527 if (pt_row
== NULL
)
12528 w
->cursor
.vpos
= -1;
12529 last_text_row
= NULL
;
12530 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
12531 if (display_line (&it
))
12532 last_text_row
= it
.glyph_row
- 1;
12534 /* Give up If point isn't in a row displayed or reused. */
12535 if (w
->cursor
.vpos
< 0)
12537 clear_glyph_matrix (w
->desired_matrix
);
12541 /* If point is in a reused row, adjust y and vpos of the cursor
12545 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
12546 w
->current_matrix
);
12547 w
->cursor
.y
-= first_reusable_row
->y
;
12550 /* Scroll the display. */
12551 run
.current_y
= first_reusable_row
->y
;
12552 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12553 run
.height
= it
.last_visible_y
- run
.current_y
;
12554 dy
= run
.current_y
- run
.desired_y
;
12559 rif
->update_window_begin_hook (w
);
12560 rif
->clear_window_mouse_face (w
);
12561 rif
->scroll_run_hook (w
, &run
);
12562 rif
->update_window_end_hook (w
, 0, 0);
12566 /* Adjust Y positions of reused rows. */
12567 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12568 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12569 max_y
= it
.last_visible_y
;
12570 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
12573 row
->visible_height
= row
->height
;
12574 if (row
->y
< min_y
)
12575 row
->visible_height
-= min_y
- row
->y
;
12576 if (row
->y
+ row
->height
> max_y
)
12577 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12578 row
->redraw_fringe_bitmaps_p
= 1;
12581 /* Scroll the current matrix. */
12582 xassert (nrows_scrolled
> 0);
12583 rotate_matrix (w
->current_matrix
,
12585 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12588 /* Disable rows not reused. */
12589 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
12590 row
->enabled_p
= 0;
12592 /* Adjust window end. A null value of last_text_row means that
12593 the window end is in reused rows which in turn means that
12594 only its vpos can have changed. */
12597 w
->window_end_bytepos
12598 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12600 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12602 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12607 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
12610 w
->window_end_valid
= Qnil
;
12611 w
->desired_matrix
->no_scrolling_p
= 1;
12614 debug_method_add (w
, "try_window_reusing_current_matrix 2");
12624 /************************************************************************
12625 Window redisplay reusing current matrix when buffer has changed
12626 ************************************************************************/
12628 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
12629 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
12631 static struct glyph_row
*
12632 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
12633 struct glyph_row
*));
12636 /* Return the last row in MATRIX displaying text. If row START is
12637 non-null, start searching with that row. IT gives the dimensions
12638 of the display. Value is null if matrix is empty; otherwise it is
12639 a pointer to the row found. */
12641 static struct glyph_row
*
12642 find_last_row_displaying_text (matrix
, it
, start
)
12643 struct glyph_matrix
*matrix
;
12645 struct glyph_row
*start
;
12647 struct glyph_row
*row
, *row_found
;
12649 /* Set row_found to the last row in IT->w's current matrix
12650 displaying text. The loop looks funny but think of partially
12653 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
12654 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12656 xassert (row
->enabled_p
);
12658 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
12667 /* Return the last row in the current matrix of W that is not affected
12668 by changes at the start of current_buffer that occurred since W's
12669 current matrix was built. Value is null if no such row exists.
12671 BEG_UNCHANGED us the number of characters unchanged at the start of
12672 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
12673 first changed character in current_buffer. Characters at positions <
12674 BEG + BEG_UNCHANGED are at the same buffer positions as they were
12675 when the current matrix was built. */
12677 static struct glyph_row
*
12678 find_last_unchanged_at_beg_row (w
)
12681 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
12682 struct glyph_row
*row
;
12683 struct glyph_row
*row_found
= NULL
;
12684 int yb
= window_text_bottom_y (w
);
12686 /* Find the last row displaying unchanged text. */
12687 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12688 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12689 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
12691 if (/* If row ends before first_changed_pos, it is unchanged,
12692 except in some case. */
12693 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
12694 /* When row ends in ZV and we write at ZV it is not
12696 && !row
->ends_at_zv_p
12697 /* When first_changed_pos is the end of a continued line,
12698 row is not unchanged because it may be no longer
12700 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
12701 && (row
->continued_p
12702 || row
->exact_window_width_line_p
)))
12705 /* Stop if last visible row. */
12706 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
12716 /* Find the first glyph row in the current matrix of W that is not
12717 affected by changes at the end of current_buffer since the
12718 time W's current matrix was built.
12720 Return in *DELTA the number of chars by which buffer positions in
12721 unchanged text at the end of current_buffer must be adjusted.
12723 Return in *DELTA_BYTES the corresponding number of bytes.
12725 Value is null if no such row exists, i.e. all rows are affected by
12728 static struct glyph_row
*
12729 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
12731 int *delta
, *delta_bytes
;
12733 struct glyph_row
*row
;
12734 struct glyph_row
*row_found
= NULL
;
12736 *delta
= *delta_bytes
= 0;
12738 /* Display must not have been paused, otherwise the current matrix
12739 is not up to date. */
12740 if (NILP (w
->window_end_valid
))
12743 /* A value of window_end_pos >= END_UNCHANGED means that the window
12744 end is in the range of changed text. If so, there is no
12745 unchanged row at the end of W's current matrix. */
12746 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
12749 /* Set row to the last row in W's current matrix displaying text. */
12750 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
12752 /* If matrix is entirely empty, no unchanged row exists. */
12753 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12755 /* The value of row is the last glyph row in the matrix having a
12756 meaningful buffer position in it. The end position of row
12757 corresponds to window_end_pos. This allows us to translate
12758 buffer positions in the current matrix to current buffer
12759 positions for characters not in changed text. */
12760 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
12761 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
12762 int last_unchanged_pos
, last_unchanged_pos_old
;
12763 struct glyph_row
*first_text_row
12764 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12766 *delta
= Z
- Z_old
;
12767 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
12769 /* Set last_unchanged_pos to the buffer position of the last
12770 character in the buffer that has not been changed. Z is the
12771 index + 1 of the last character in current_buffer, i.e. by
12772 subtracting END_UNCHANGED we get the index of the last
12773 unchanged character, and we have to add BEG to get its buffer
12775 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
12776 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
12778 /* Search backward from ROW for a row displaying a line that
12779 starts at a minimum position >= last_unchanged_pos_old. */
12780 for (; row
> first_text_row
; --row
)
12782 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12785 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
12790 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
12797 /* Make sure that glyph rows in the current matrix of window W
12798 reference the same glyph memory as corresponding rows in the
12799 frame's frame matrix. This function is called after scrolling W's
12800 current matrix on a terminal frame in try_window_id and
12801 try_window_reusing_current_matrix. */
12804 sync_frame_with_window_matrix_rows (w
)
12807 struct frame
*f
= XFRAME (w
->frame
);
12808 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
12810 /* Preconditions: W must be a leaf window and full-width. Its frame
12811 must have a frame matrix. */
12812 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
12813 xassert (WINDOW_FULL_WIDTH_P (w
));
12814 xassert (!FRAME_WINDOW_P (f
));
12816 /* If W is a full-width window, glyph pointers in W's current matrix
12817 have, by definition, to be the same as glyph pointers in the
12818 corresponding frame matrix. Note that frame matrices have no
12819 marginal areas (see build_frame_matrix). */
12820 window_row
= w
->current_matrix
->rows
;
12821 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
12822 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
12823 while (window_row
< window_row_end
)
12825 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
12826 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
12828 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
12829 frame_row
->glyphs
[TEXT_AREA
] = start
;
12830 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
12831 frame_row
->glyphs
[LAST_AREA
] = end
;
12833 /* Disable frame rows whose corresponding window rows have
12834 been disabled in try_window_id. */
12835 if (!window_row
->enabled_p
)
12836 frame_row
->enabled_p
= 0;
12838 ++window_row
, ++frame_row
;
12843 /* Find the glyph row in window W containing CHARPOS. Consider all
12844 rows between START and END (not inclusive). END null means search
12845 all rows to the end of the display area of W. Value is the row
12846 containing CHARPOS or null. */
12849 row_containing_pos (w
, charpos
, start
, end
, dy
)
12852 struct glyph_row
*start
, *end
;
12855 struct glyph_row
*row
= start
;
12858 /* If we happen to start on a header-line, skip that. */
12859 if (row
->mode_line_p
)
12862 if ((end
&& row
>= end
) || !row
->enabled_p
)
12865 last_y
= window_text_bottom_y (w
) - dy
;
12869 /* Give up if we have gone too far. */
12870 if (end
&& row
>= end
)
12872 /* This formerly returned if they were equal.
12873 I think that both quantities are of a "last plus one" type;
12874 if so, when they are equal, the row is within the screen. -- rms. */
12875 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
12878 /* If it is in this row, return this row. */
12879 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
12880 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
12881 /* The end position of a row equals the start
12882 position of the next row. If CHARPOS is there, we
12883 would rather display it in the next line, except
12884 when this line ends in ZV. */
12885 && !row
->ends_at_zv_p
12886 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12887 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
12894 /* Try to redisplay window W by reusing its existing display. W's
12895 current matrix must be up to date when this function is called,
12896 i.e. window_end_valid must not be nil.
12900 1 if display has been updated
12901 0 if otherwise unsuccessful
12902 -1 if redisplay with same window start is known not to succeed
12904 The following steps are performed:
12906 1. Find the last row in the current matrix of W that is not
12907 affected by changes at the start of current_buffer. If no such row
12910 2. Find the first row in W's current matrix that is not affected by
12911 changes at the end of current_buffer. Maybe there is no such row.
12913 3. Display lines beginning with the row + 1 found in step 1 to the
12914 row found in step 2 or, if step 2 didn't find a row, to the end of
12917 4. If cursor is not known to appear on the window, give up.
12919 5. If display stopped at the row found in step 2, scroll the
12920 display and current matrix as needed.
12922 6. Maybe display some lines at the end of W, if we must. This can
12923 happen under various circumstances, like a partially visible line
12924 becoming fully visible, or because newly displayed lines are displayed
12925 in smaller font sizes.
12927 7. Update W's window end information. */
12933 struct frame
*f
= XFRAME (w
->frame
);
12934 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
12935 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
12936 struct glyph_row
*last_unchanged_at_beg_row
;
12937 struct glyph_row
*first_unchanged_at_end_row
;
12938 struct glyph_row
*row
;
12939 struct glyph_row
*bottom_row
;
12942 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
12943 struct text_pos start_pos
;
12945 int first_unchanged_at_end_vpos
= 0;
12946 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
12947 struct text_pos start
;
12948 int first_changed_charpos
, last_changed_charpos
;
12951 if (inhibit_try_window_id
)
12955 /* This is handy for debugging. */
12957 #define GIVE_UP(X) \
12959 fprintf (stderr, "try_window_id give up %d\n", (X)); \
12963 #define GIVE_UP(X) return 0
12966 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
12968 /* Don't use this for mini-windows because these can show
12969 messages and mini-buffers, and we don't handle that here. */
12970 if (MINI_WINDOW_P (w
))
12973 /* This flag is used to prevent redisplay optimizations. */
12974 if (windows_or_buffers_changed
|| cursor_type_changed
)
12977 /* Verify that narrowing has not changed.
12978 Also verify that we were not told to prevent redisplay optimizations.
12979 It would be nice to further
12980 reduce the number of cases where this prevents try_window_id. */
12981 if (current_buffer
->clip_changed
12982 || current_buffer
->prevent_redisplay_optimizations_p
)
12985 /* Window must either use window-based redisplay or be full width. */
12986 if (!FRAME_WINDOW_P (f
)
12987 && (!line_ins_del_ok
12988 || !WINDOW_FULL_WIDTH_P (w
)))
12991 /* Give up if point is not known NOT to appear in W. */
12992 if (PT
< CHARPOS (start
))
12995 /* Another way to prevent redisplay optimizations. */
12996 if (XFASTINT (w
->last_modified
) == 0)
12999 /* Verify that window is not hscrolled. */
13000 if (XFASTINT (w
->hscroll
) != 0)
13003 /* Verify that display wasn't paused. */
13004 if (NILP (w
->window_end_valid
))
13007 /* Can't use this if highlighting a region because a cursor movement
13008 will do more than just set the cursor. */
13009 if (!NILP (Vtransient_mark_mode
)
13010 && !NILP (current_buffer
->mark_active
))
13013 /* Likewise if highlighting trailing whitespace. */
13014 if (!NILP (Vshow_trailing_whitespace
))
13017 /* Likewise if showing a region. */
13018 if (!NILP (w
->region_showing
))
13021 /* Can use this if overlay arrow position and or string have changed. */
13022 if (overlay_arrows_changed_p ())
13026 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
13027 only if buffer has really changed. The reason is that the gap is
13028 initially at Z for freshly visited files. The code below would
13029 set end_unchanged to 0 in that case. */
13030 if (MODIFF
> SAVE_MODIFF
13031 /* This seems to happen sometimes after saving a buffer. */
13032 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
13034 if (GPT
- BEG
< BEG_UNCHANGED
)
13035 BEG_UNCHANGED
= GPT
- BEG
;
13036 if (Z
- GPT
< END_UNCHANGED
)
13037 END_UNCHANGED
= Z
- GPT
;
13040 /* The position of the first and last character that has been changed. */
13041 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
13042 last_changed_charpos
= Z
- END_UNCHANGED
;
13044 /* If window starts after a line end, and the last change is in
13045 front of that newline, then changes don't affect the display.
13046 This case happens with stealth-fontification. Note that although
13047 the display is unchanged, glyph positions in the matrix have to
13048 be adjusted, of course. */
13049 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13050 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13051 && ((last_changed_charpos
< CHARPOS (start
)
13052 && CHARPOS (start
) == BEGV
)
13053 || (last_changed_charpos
< CHARPOS (start
) - 1
13054 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
13056 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
13057 struct glyph_row
*r0
;
13059 /* Compute how many chars/bytes have been added to or removed
13060 from the buffer. */
13061 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13062 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13064 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13066 /* Give up if PT is not in the window. Note that it already has
13067 been checked at the start of try_window_id that PT is not in
13068 front of the window start. */
13069 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
13072 /* If window start is unchanged, we can reuse the whole matrix
13073 as is, after adjusting glyph positions. No need to compute
13074 the window end again, since its offset from Z hasn't changed. */
13075 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13076 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
13077 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
13078 /* PT must not be in a partially visible line. */
13079 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
13080 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13082 /* Adjust positions in the glyph matrix. */
13083 if (delta
|| delta_bytes
)
13085 struct glyph_row
*r1
13086 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13087 increment_matrix_positions (w
->current_matrix
,
13088 MATRIX_ROW_VPOS (r0
, current_matrix
),
13089 MATRIX_ROW_VPOS (r1
, current_matrix
),
13090 delta
, delta_bytes
);
13093 /* Set the cursor. */
13094 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13096 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13103 /* Handle the case that changes are all below what is displayed in
13104 the window, and that PT is in the window. This shortcut cannot
13105 be taken if ZV is visible in the window, and text has been added
13106 there that is visible in the window. */
13107 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
13108 /* ZV is not visible in the window, or there are no
13109 changes at ZV, actually. */
13110 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
13111 || first_changed_charpos
== last_changed_charpos
))
13113 struct glyph_row
*r0
;
13115 /* Give up if PT is not in the window. Note that it already has
13116 been checked at the start of try_window_id that PT is not in
13117 front of the window start. */
13118 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
13121 /* If window start is unchanged, we can reuse the whole matrix
13122 as is, without changing glyph positions since no text has
13123 been added/removed in front of the window end. */
13124 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13125 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
13126 /* PT must not be in a partially visible line. */
13127 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
13128 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13130 /* We have to compute the window end anew since text
13131 can have been added/removed after it. */
13133 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13134 w
->window_end_bytepos
13135 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13137 /* Set the cursor. */
13138 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13140 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13147 /* Give up if window start is in the changed area.
13149 The condition used to read
13151 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
13153 but why that was tested escapes me at the moment. */
13154 if (CHARPOS (start
) >= first_changed_charpos
13155 && CHARPOS (start
) <= last_changed_charpos
)
13158 /* Check that window start agrees with the start of the first glyph
13159 row in its current matrix. Check this after we know the window
13160 start is not in changed text, otherwise positions would not be
13162 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13163 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
13166 /* Give up if the window ends in strings. Overlay strings
13167 at the end are difficult to handle, so don't try. */
13168 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
13169 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
13172 /* Compute the position at which we have to start displaying new
13173 lines. Some of the lines at the top of the window might be
13174 reusable because they are not displaying changed text. Find the
13175 last row in W's current matrix not affected by changes at the
13176 start of current_buffer. Value is null if changes start in the
13177 first line of window. */
13178 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
13179 if (last_unchanged_at_beg_row
)
13181 /* Avoid starting to display in the moddle of a character, a TAB
13182 for instance. This is easier than to set up the iterator
13183 exactly, and it's not a frequent case, so the additional
13184 effort wouldn't really pay off. */
13185 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
13186 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
13187 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
13188 --last_unchanged_at_beg_row
;
13190 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
13193 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
13195 start_pos
= it
.current
.pos
;
13197 /* Start displaying new lines in the desired matrix at the same
13198 vpos we would use in the current matrix, i.e. below
13199 last_unchanged_at_beg_row. */
13200 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
13202 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13203 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
13205 xassert (it
.hpos
== 0 && it
.current_x
== 0);
13209 /* There are no reusable lines at the start of the window.
13210 Start displaying in the first text line. */
13211 start_display (&it
, w
, start
);
13212 it
.vpos
= it
.first_vpos
;
13213 start_pos
= it
.current
.pos
;
13216 /* Find the first row that is not affected by changes at the end of
13217 the buffer. Value will be null if there is no unchanged row, in
13218 which case we must redisplay to the end of the window. delta
13219 will be set to the value by which buffer positions beginning with
13220 first_unchanged_at_end_row have to be adjusted due to text
13222 first_unchanged_at_end_row
13223 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
13224 IF_DEBUG (debug_delta
= delta
);
13225 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
13227 /* Set stop_pos to the buffer position up to which we will have to
13228 display new lines. If first_unchanged_at_end_row != NULL, this
13229 is the buffer position of the start of the line displayed in that
13230 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
13231 that we don't stop at a buffer position. */
13233 if (first_unchanged_at_end_row
)
13235 xassert (last_unchanged_at_beg_row
== NULL
13236 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
13238 /* If this is a continuation line, move forward to the next one
13239 that isn't. Changes in lines above affect this line.
13240 Caution: this may move first_unchanged_at_end_row to a row
13241 not displaying text. */
13242 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
13243 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13244 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13245 < it
.last_visible_y
))
13246 ++first_unchanged_at_end_row
;
13248 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13249 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13250 >= it
.last_visible_y
))
13251 first_unchanged_at_end_row
= NULL
;
13254 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13256 first_unchanged_at_end_vpos
13257 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13258 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13261 else if (last_unchanged_at_beg_row
== NULL
)
13267 /* Either there is no unchanged row at the end, or the one we have
13268 now displays text. This is a necessary condition for the window
13269 end pos calculation at the end of this function. */
13270 xassert (first_unchanged_at_end_row
== NULL
13271 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
13273 debug_last_unchanged_at_beg_vpos
13274 = (last_unchanged_at_beg_row
13275 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
13277 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
13279 #endif /* GLYPH_DEBUG != 0 */
13282 /* Display new lines. Set last_text_row to the last new line
13283 displayed which has text on it, i.e. might end up as being the
13284 line where the window_end_vpos is. */
13285 w
->cursor
.vpos
= -1;
13286 last_text_row
= NULL
;
13287 overlay_arrow_seen
= 0;
13288 while (it
.current_y
< it
.last_visible_y
13289 && !fonts_changed_p
13290 && (first_unchanged_at_end_row
== NULL
13291 || IT_CHARPOS (it
) < stop_pos
))
13293 if (display_line (&it
))
13294 last_text_row
= it
.glyph_row
- 1;
13297 if (fonts_changed_p
)
13301 /* Compute differences in buffer positions, y-positions etc. for
13302 lines reused at the bottom of the window. Compute what we can
13304 if (first_unchanged_at_end_row
13305 /* No lines reused because we displayed everything up to the
13306 bottom of the window. */
13307 && it
.current_y
< it
.last_visible_y
)
13310 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
13312 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
13313 run
.current_y
= first_unchanged_at_end_row
->y
;
13314 run
.desired_y
= run
.current_y
+ dy
;
13315 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
13319 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
13320 first_unchanged_at_end_row
= NULL
;
13322 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
13325 /* Find the cursor if not already found. We have to decide whether
13326 PT will appear on this window (it sometimes doesn't, but this is
13327 not a very frequent case.) This decision has to be made before
13328 the current matrix is altered. A value of cursor.vpos < 0 means
13329 that PT is either in one of the lines beginning at
13330 first_unchanged_at_end_row or below the window. Don't care for
13331 lines that might be displayed later at the window end; as
13332 mentioned, this is not a frequent case. */
13333 if (w
->cursor
.vpos
< 0)
13335 /* Cursor in unchanged rows at the top? */
13336 if (PT
< CHARPOS (start_pos
)
13337 && last_unchanged_at_beg_row
)
13339 row
= row_containing_pos (w
, PT
,
13340 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
13341 last_unchanged_at_beg_row
+ 1, 0);
13343 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13346 /* Start from first_unchanged_at_end_row looking for PT. */
13347 else if (first_unchanged_at_end_row
)
13349 row
= row_containing_pos (w
, PT
- delta
,
13350 first_unchanged_at_end_row
, NULL
, 0);
13352 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
13353 delta_bytes
, dy
, dvpos
);
13356 /* Give up if cursor was not found. */
13357 if (w
->cursor
.vpos
< 0)
13359 clear_glyph_matrix (w
->desired_matrix
);
13364 /* Don't let the cursor end in the scroll margins. */
13366 int this_scroll_margin
, cursor_height
;
13368 this_scroll_margin
= max (0, scroll_margin
);
13369 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13370 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13371 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
13373 if ((w
->cursor
.y
< this_scroll_margin
13374 && CHARPOS (start
) > BEGV
)
13375 /* Don't take scroll margin into account at the bottom because
13376 old redisplay didn't do it either. */
13377 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
13379 w
->cursor
.vpos
= -1;
13380 clear_glyph_matrix (w
->desired_matrix
);
13385 /* Scroll the display. Do it before changing the current matrix so
13386 that xterm.c doesn't get confused about where the cursor glyph is
13388 if (dy
&& run
.height
)
13392 if (FRAME_WINDOW_P (f
))
13394 rif
->update_window_begin_hook (w
);
13395 rif
->clear_window_mouse_face (w
);
13396 rif
->scroll_run_hook (w
, &run
);
13397 rif
->update_window_end_hook (w
, 0, 0);
13401 /* Terminal frame. In this case, dvpos gives the number of
13402 lines to scroll by; dvpos < 0 means scroll up. */
13403 int first_unchanged_at_end_vpos
13404 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
13405 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
13406 int end
= (WINDOW_TOP_EDGE_LINE (w
)
13407 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
13408 + window_internal_height (w
));
13410 /* Perform the operation on the screen. */
13413 /* Scroll last_unchanged_at_beg_row to the end of the
13414 window down dvpos lines. */
13415 set_terminal_window (end
);
13417 /* On dumb terminals delete dvpos lines at the end
13418 before inserting dvpos empty lines. */
13419 if (!scroll_region_ok
)
13420 ins_del_lines (end
- dvpos
, -dvpos
);
13422 /* Insert dvpos empty lines in front of
13423 last_unchanged_at_beg_row. */
13424 ins_del_lines (from
, dvpos
);
13426 else if (dvpos
< 0)
13428 /* Scroll up last_unchanged_at_beg_vpos to the end of
13429 the window to last_unchanged_at_beg_vpos - |dvpos|. */
13430 set_terminal_window (end
);
13432 /* Delete dvpos lines in front of
13433 last_unchanged_at_beg_vpos. ins_del_lines will set
13434 the cursor to the given vpos and emit |dvpos| delete
13436 ins_del_lines (from
+ dvpos
, dvpos
);
13438 /* On a dumb terminal insert dvpos empty lines at the
13440 if (!scroll_region_ok
)
13441 ins_del_lines (end
+ dvpos
, -dvpos
);
13444 set_terminal_window (0);
13450 /* Shift reused rows of the current matrix to the right position.
13451 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
13453 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13454 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
13457 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
13458 bottom_vpos
, dvpos
);
13459 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
13462 else if (dvpos
> 0)
13464 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
13465 bottom_vpos
, dvpos
);
13466 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
13467 first_unchanged_at_end_vpos
+ dvpos
, 0);
13470 /* For frame-based redisplay, make sure that current frame and window
13471 matrix are in sync with respect to glyph memory. */
13472 if (!FRAME_WINDOW_P (f
))
13473 sync_frame_with_window_matrix_rows (w
);
13475 /* Adjust buffer positions in reused rows. */
13477 increment_matrix_positions (current_matrix
,
13478 first_unchanged_at_end_vpos
+ dvpos
,
13479 bottom_vpos
, delta
, delta_bytes
);
13481 /* Adjust Y positions. */
13483 shift_glyph_matrix (w
, current_matrix
,
13484 first_unchanged_at_end_vpos
+ dvpos
,
13487 if (first_unchanged_at_end_row
)
13488 first_unchanged_at_end_row
+= dvpos
;
13490 /* If scrolling up, there may be some lines to display at the end of
13492 last_text_row_at_end
= NULL
;
13495 /* Scrolling up can leave for example a partially visible line
13496 at the end of the window to be redisplayed. */
13497 /* Set last_row to the glyph row in the current matrix where the
13498 window end line is found. It has been moved up or down in
13499 the matrix by dvpos. */
13500 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
13501 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
13503 /* If last_row is the window end line, it should display text. */
13504 xassert (last_row
->displays_text_p
);
13506 /* If window end line was partially visible before, begin
13507 displaying at that line. Otherwise begin displaying with the
13508 line following it. */
13509 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
13511 init_to_row_start (&it
, w
, last_row
);
13512 it
.vpos
= last_vpos
;
13513 it
.current_y
= last_row
->y
;
13517 init_to_row_end (&it
, w
, last_row
);
13518 it
.vpos
= 1 + last_vpos
;
13519 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
13523 /* We may start in a continuation line. If so, we have to
13524 get the right continuation_lines_width and current_x. */
13525 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
13526 it
.hpos
= it
.current_x
= 0;
13528 /* Display the rest of the lines at the window end. */
13529 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13530 while (it
.current_y
< it
.last_visible_y
13531 && !fonts_changed_p
)
13533 /* Is it always sure that the display agrees with lines in
13534 the current matrix? I don't think so, so we mark rows
13535 displayed invalid in the current matrix by setting their
13536 enabled_p flag to zero. */
13537 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
13538 if (display_line (&it
))
13539 last_text_row_at_end
= it
.glyph_row
- 1;
13543 /* Update window_end_pos and window_end_vpos. */
13544 if (first_unchanged_at_end_row
13545 && first_unchanged_at_end_row
->y
< it
.last_visible_y
13546 && !last_text_row_at_end
)
13548 /* Window end line if one of the preserved rows from the current
13549 matrix. Set row to the last row displaying text in current
13550 matrix starting at first_unchanged_at_end_row, after
13552 xassert (first_unchanged_at_end_row
->displays_text_p
);
13553 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
13554 first_unchanged_at_end_row
);
13555 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
13557 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13558 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13560 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
13561 xassert (w
->window_end_bytepos
>= 0);
13562 IF_DEBUG (debug_method_add (w
, "A"));
13564 else if (last_text_row_at_end
)
13567 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
13568 w
->window_end_bytepos
13569 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
13571 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
13572 xassert (w
->window_end_bytepos
>= 0);
13573 IF_DEBUG (debug_method_add (w
, "B"));
13575 else if (last_text_row
)
13577 /* We have displayed either to the end of the window or at the
13578 end of the window, i.e. the last row with text is to be found
13579 in the desired matrix. */
13581 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13582 w
->window_end_bytepos
13583 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13585 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
13586 xassert (w
->window_end_bytepos
>= 0);
13588 else if (first_unchanged_at_end_row
== NULL
13589 && last_text_row
== NULL
13590 && last_text_row_at_end
== NULL
)
13592 /* Displayed to end of window, but no line containing text was
13593 displayed. Lines were deleted at the end of the window. */
13594 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
13595 int vpos
= XFASTINT (w
->window_end_vpos
);
13596 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
13597 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
13600 row
== NULL
&& vpos
>= first_vpos
;
13601 --vpos
, --current_row
, --desired_row
)
13603 if (desired_row
->enabled_p
)
13605 if (desired_row
->displays_text_p
)
13608 else if (current_row
->displays_text_p
)
13612 xassert (row
!= NULL
);
13613 w
->window_end_vpos
= make_number (vpos
+ 1);
13614 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13615 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13616 xassert (w
->window_end_bytepos
>= 0);
13617 IF_DEBUG (debug_method_add (w
, "C"));
13622 #if 0 /* This leads to problems, for instance when the cursor is
13623 at ZV, and the cursor line displays no text. */
13624 /* Disable rows below what's displayed in the window. This makes
13625 debugging easier. */
13626 enable_glyph_matrix_rows (current_matrix
,
13627 XFASTINT (w
->window_end_vpos
) + 1,
13631 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
13632 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
13634 /* Record that display has not been completed. */
13635 w
->window_end_valid
= Qnil
;
13636 w
->desired_matrix
->no_scrolling_p
= 1;
13644 /***********************************************************************
13645 More debugging support
13646 ***********************************************************************/
13650 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
13651 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
13652 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
13655 /* Dump the contents of glyph matrix MATRIX on stderr.
13657 GLYPHS 0 means don't show glyph contents.
13658 GLYPHS 1 means show glyphs in short form
13659 GLYPHS > 1 means show glyphs in long form. */
13662 dump_glyph_matrix (matrix
, glyphs
)
13663 struct glyph_matrix
*matrix
;
13667 for (i
= 0; i
< matrix
->nrows
; ++i
)
13668 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
13672 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
13673 the glyph row and area where the glyph comes from. */
13676 dump_glyph (row
, glyph
, area
)
13677 struct glyph_row
*row
;
13678 struct glyph
*glyph
;
13681 if (glyph
->type
== CHAR_GLYPH
)
13684 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13685 glyph
- row
->glyphs
[TEXT_AREA
],
13688 (BUFFERP (glyph
->object
)
13690 : (STRINGP (glyph
->object
)
13693 glyph
->pixel_width
,
13695 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
13699 glyph
->left_box_line_p
,
13700 glyph
->right_box_line_p
);
13702 else if (glyph
->type
== STRETCH_GLYPH
)
13705 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13706 glyph
- row
->glyphs
[TEXT_AREA
],
13709 (BUFFERP (glyph
->object
)
13711 : (STRINGP (glyph
->object
)
13714 glyph
->pixel_width
,
13718 glyph
->left_box_line_p
,
13719 glyph
->right_box_line_p
);
13721 else if (glyph
->type
== IMAGE_GLYPH
)
13724 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13725 glyph
- row
->glyphs
[TEXT_AREA
],
13728 (BUFFERP (glyph
->object
)
13730 : (STRINGP (glyph
->object
)
13733 glyph
->pixel_width
,
13737 glyph
->left_box_line_p
,
13738 glyph
->right_box_line_p
);
13743 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
13744 GLYPHS 0 means don't show glyph contents.
13745 GLYPHS 1 means show glyphs in short form
13746 GLYPHS > 1 means show glyphs in long form. */
13749 dump_glyph_row (row
, vpos
, glyphs
)
13750 struct glyph_row
*row
;
13755 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
13756 fprintf (stderr
, "=======================================================================\n");
13758 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
13759 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
13761 MATRIX_ROW_START_CHARPOS (row
),
13762 MATRIX_ROW_END_CHARPOS (row
),
13763 row
->used
[TEXT_AREA
],
13764 row
->contains_overlapping_glyphs_p
,
13766 row
->truncated_on_left_p
,
13767 row
->truncated_on_right_p
,
13768 row
->overlay_arrow_p
,
13770 MATRIX_ROW_CONTINUATION_LINE_P (row
),
13771 row
->displays_text_p
,
13774 row
->ends_in_middle_of_char_p
,
13775 row
->starts_in_middle_of_char_p
,
13781 row
->visible_height
,
13784 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
13785 row
->end
.overlay_string_index
,
13786 row
->continuation_lines_width
);
13787 fprintf (stderr
, "%9d %5d\n",
13788 CHARPOS (row
->start
.string_pos
),
13789 CHARPOS (row
->end
.string_pos
));
13790 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
13791 row
->end
.dpvec_index
);
13798 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
13800 struct glyph
*glyph
= row
->glyphs
[area
];
13801 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
13803 /* Glyph for a line end in text. */
13804 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
13807 if (glyph
< glyph_end
)
13808 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
13810 for (; glyph
< glyph_end
; ++glyph
)
13811 dump_glyph (row
, glyph
, area
);
13814 else if (glyphs
== 1)
13818 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
13820 char *s
= (char *) alloca (row
->used
[area
] + 1);
13823 for (i
= 0; i
< row
->used
[area
]; ++i
)
13825 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
13826 if (glyph
->type
== CHAR_GLYPH
13827 && glyph
->u
.ch
< 0x80
13828 && glyph
->u
.ch
>= ' ')
13829 s
[i
] = glyph
->u
.ch
;
13835 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
13841 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
13842 Sdump_glyph_matrix
, 0, 1, "p",
13843 doc
: /* Dump the current matrix of the selected window to stderr.
13844 Shows contents of glyph row structures. With non-nil
13845 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
13846 glyphs in short form, otherwise show glyphs in long form. */)
13848 Lisp_Object glyphs
;
13850 struct window
*w
= XWINDOW (selected_window
);
13851 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13853 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
13854 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
13855 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
13856 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
13857 fprintf (stderr
, "=============================================\n");
13858 dump_glyph_matrix (w
->current_matrix
,
13859 NILP (glyphs
) ? 0 : XINT (glyphs
));
13864 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
13865 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
13868 struct frame
*f
= XFRAME (selected_frame
);
13869 dump_glyph_matrix (f
->current_matrix
, 1);
13874 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
13875 doc
: /* Dump glyph row ROW to stderr.
13876 GLYPH 0 means don't dump glyphs.
13877 GLYPH 1 means dump glyphs in short form.
13878 GLYPH > 1 or omitted means dump glyphs in long form. */)
13880 Lisp_Object row
, glyphs
;
13882 struct glyph_matrix
*matrix
;
13885 CHECK_NUMBER (row
);
13886 matrix
= XWINDOW (selected_window
)->current_matrix
;
13888 if (vpos
>= 0 && vpos
< matrix
->nrows
)
13889 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
13891 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
13896 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
13897 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
13898 GLYPH 0 means don't dump glyphs.
13899 GLYPH 1 means dump glyphs in short form.
13900 GLYPH > 1 or omitted means dump glyphs in long form. */)
13902 Lisp_Object row
, glyphs
;
13904 struct frame
*sf
= SELECTED_FRAME ();
13905 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
13908 CHECK_NUMBER (row
);
13910 if (vpos
>= 0 && vpos
< m
->nrows
)
13911 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
13912 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
13917 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
13918 doc
: /* Toggle tracing of redisplay.
13919 With ARG, turn tracing on if and only if ARG is positive. */)
13924 trace_redisplay_p
= !trace_redisplay_p
;
13927 arg
= Fprefix_numeric_value (arg
);
13928 trace_redisplay_p
= XINT (arg
) > 0;
13935 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
13936 doc
: /* Like `format', but print result to stderr.
13937 usage: (trace-to-stderr STRING &rest OBJECTS) */)
13942 Lisp_Object s
= Fformat (nargs
, args
);
13943 fprintf (stderr
, "%s", SDATA (s
));
13947 #endif /* GLYPH_DEBUG */
13951 /***********************************************************************
13952 Building Desired Matrix Rows
13953 ***********************************************************************/
13955 /* Return a temporary glyph row holding the glyphs of an overlay
13956 arrow. Only used for non-window-redisplay windows. */
13958 static struct glyph_row
*
13959 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
13961 Lisp_Object overlay_arrow_string
;
13963 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13964 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13965 struct buffer
*old
= current_buffer
;
13966 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
13967 int arrow_len
= SCHARS (overlay_arrow_string
);
13968 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
13969 const unsigned char *p
;
13972 int n_glyphs_before
;
13974 set_buffer_temp (buffer
);
13975 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
13976 it
.glyph_row
->used
[TEXT_AREA
] = 0;
13977 SET_TEXT_POS (it
.position
, 0, 0);
13979 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
13981 while (p
< arrow_end
)
13983 Lisp_Object face
, ilisp
;
13985 /* Get the next character. */
13987 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
13989 it
.c
= *p
, it
.len
= 1;
13992 /* Get its face. */
13993 ilisp
= make_number (p
- arrow_string
);
13994 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
13995 it
.face_id
= compute_char_face (f
, it
.c
, face
);
13997 /* Compute its width, get its glyphs. */
13998 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
13999 SET_TEXT_POS (it
.position
, -1, -1);
14000 PRODUCE_GLYPHS (&it
);
14002 /* If this character doesn't fit any more in the line, we have
14003 to remove some glyphs. */
14004 if (it
.current_x
> it
.last_visible_x
)
14006 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14011 set_buffer_temp (old
);
14012 return it
.glyph_row
;
14016 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
14017 glyphs are only inserted for terminal frames since we can't really
14018 win with truncation glyphs when partially visible glyphs are
14019 involved. Which glyphs to insert is determined by
14020 produce_special_glyphs. */
14023 insert_left_trunc_glyphs (it
)
14026 struct it truncate_it
;
14027 struct glyph
*from
, *end
, *to
, *toend
;
14029 xassert (!FRAME_WINDOW_P (it
->f
));
14031 /* Get the truncation glyphs. */
14033 truncate_it
.current_x
= 0;
14034 truncate_it
.face_id
= DEFAULT_FACE_ID
;
14035 truncate_it
.glyph_row
= &scratch_glyph_row
;
14036 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
14037 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
14038 truncate_it
.object
= make_number (0);
14039 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
14041 /* Overwrite glyphs from IT with truncation glyphs. */
14042 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14043 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
14044 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
14045 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
14050 /* There may be padding glyphs left over. Overwrite them too. */
14051 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
14053 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14059 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
14063 /* Compute the pixel height and width of IT->glyph_row.
14065 Most of the time, ascent and height of a display line will be equal
14066 to the max_ascent and max_height values of the display iterator
14067 structure. This is not the case if
14069 1. We hit ZV without displaying anything. In this case, max_ascent
14070 and max_height will be zero.
14072 2. We have some glyphs that don't contribute to the line height.
14073 (The glyph row flag contributes_to_line_height_p is for future
14074 pixmap extensions).
14076 The first case is easily covered by using default values because in
14077 these cases, the line height does not really matter, except that it
14078 must not be zero. */
14081 compute_line_metrics (it
)
14084 struct glyph_row
*row
= it
->glyph_row
;
14087 if (FRAME_WINDOW_P (it
->f
))
14089 int i
, min_y
, max_y
;
14091 /* The line may consist of one space only, that was added to
14092 place the cursor on it. If so, the row's height hasn't been
14094 if (row
->height
== 0)
14096 if (it
->max_ascent
+ it
->max_descent
== 0)
14097 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
14098 row
->ascent
= it
->max_ascent
;
14099 row
->height
= it
->max_ascent
+ it
->max_descent
;
14100 row
->phys_ascent
= it
->max_phys_ascent
;
14101 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14104 /* Compute the width of this line. */
14105 row
->pixel_width
= row
->x
;
14106 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
14107 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
14109 xassert (row
->pixel_width
>= 0);
14110 xassert (row
->ascent
>= 0 && row
->height
> 0);
14112 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
14113 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
14115 /* If first line's physical ascent is larger than its logical
14116 ascent, use the physical ascent, and make the row taller.
14117 This makes accented characters fully visible. */
14118 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
14119 && row
->phys_ascent
> row
->ascent
)
14121 row
->height
+= row
->phys_ascent
- row
->ascent
;
14122 row
->ascent
= row
->phys_ascent
;
14125 /* Compute how much of the line is visible. */
14126 row
->visible_height
= row
->height
;
14128 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
14129 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
14131 if (row
->y
< min_y
)
14132 row
->visible_height
-= min_y
- row
->y
;
14133 if (row
->y
+ row
->height
> max_y
)
14134 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14138 row
->pixel_width
= row
->used
[TEXT_AREA
];
14139 if (row
->continued_p
)
14140 row
->pixel_width
-= it
->continuation_pixel_width
;
14141 else if (row
->truncated_on_right_p
)
14142 row
->pixel_width
-= it
->truncation_pixel_width
;
14143 row
->ascent
= row
->phys_ascent
= 0;
14144 row
->height
= row
->phys_height
= row
->visible_height
= 1;
14147 /* Compute a hash code for this row. */
14149 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14150 for (i
= 0; i
< row
->used
[area
]; ++i
)
14151 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
14152 + row
->glyphs
[area
][i
].u
.val
14153 + row
->glyphs
[area
][i
].face_id
14154 + row
->glyphs
[area
][i
].padding_p
14155 + (row
->glyphs
[area
][i
].type
<< 2));
14157 it
->max_ascent
= it
->max_descent
= 0;
14158 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
14162 /* Append one space to the glyph row of iterator IT if doing a
14163 window-based redisplay. The space has the same face as
14164 IT->face_id. Value is non-zero if a space was added.
14166 This function is called to make sure that there is always one glyph
14167 at the end of a glyph row that the cursor can be set on under
14168 window-systems. (If there weren't such a glyph we would not know
14169 how wide and tall a box cursor should be displayed).
14171 At the same time this space let's a nicely handle clearing to the
14172 end of the line if the row ends in italic text. */
14175 append_space_for_newline (it
, default_face_p
)
14177 int default_face_p
;
14179 if (FRAME_WINDOW_P (it
->f
))
14181 int n
= it
->glyph_row
->used
[TEXT_AREA
];
14183 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
14184 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
14186 /* Save some values that must not be changed.
14187 Must save IT->c and IT->len because otherwise
14188 ITERATOR_AT_END_P wouldn't work anymore after
14189 append_space_for_newline has been called. */
14190 enum display_element_type saved_what
= it
->what
;
14191 int saved_c
= it
->c
, saved_len
= it
->len
;
14192 int saved_x
= it
->current_x
;
14193 int saved_face_id
= it
->face_id
;
14194 struct text_pos saved_pos
;
14195 Lisp_Object saved_object
;
14198 saved_object
= it
->object
;
14199 saved_pos
= it
->position
;
14201 it
->what
= IT_CHARACTER
;
14202 bzero (&it
->position
, sizeof it
->position
);
14203 it
->object
= make_number (0);
14207 if (default_face_p
)
14208 it
->face_id
= DEFAULT_FACE_ID
;
14209 else if (it
->face_before_selective_p
)
14210 it
->face_id
= it
->saved_face_id
;
14211 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14212 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
14214 PRODUCE_GLYPHS (it
);
14216 it
->override_ascent
= -1;
14217 it
->constrain_row_ascent_descent_p
= 0;
14218 it
->current_x
= saved_x
;
14219 it
->object
= saved_object
;
14220 it
->position
= saved_pos
;
14221 it
->what
= saved_what
;
14222 it
->face_id
= saved_face_id
;
14223 it
->len
= saved_len
;
14233 /* Extend the face of the last glyph in the text area of IT->glyph_row
14234 to the end of the display line. Called from display_line.
14235 If the glyph row is empty, add a space glyph to it so that we
14236 know the face to draw. Set the glyph row flag fill_line_p. */
14239 extend_face_to_end_of_line (it
)
14243 struct frame
*f
= it
->f
;
14245 /* If line is already filled, do nothing. */
14246 if (it
->current_x
>= it
->last_visible_x
)
14249 /* Face extension extends the background and box of IT->face_id
14250 to the end of the line. If the background equals the background
14251 of the frame, we don't have to do anything. */
14252 if (it
->face_before_selective_p
)
14253 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14255 face
= FACE_FROM_ID (f
, it
->face_id
);
14257 if (FRAME_WINDOW_P (f
)
14258 && face
->box
== FACE_NO_BOX
14259 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
14263 /* Set the glyph row flag indicating that the face of the last glyph
14264 in the text area has to be drawn to the end of the text area. */
14265 it
->glyph_row
->fill_line_p
= 1;
14267 /* If current character of IT is not ASCII, make sure we have the
14268 ASCII face. This will be automatically undone the next time
14269 get_next_display_element returns a multibyte character. Note
14270 that the character will always be single byte in unibyte text. */
14271 if (!SINGLE_BYTE_CHAR_P (it
->c
))
14273 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
14276 if (FRAME_WINDOW_P (f
))
14278 /* If the row is empty, add a space with the current face of IT,
14279 so that we know which face to draw. */
14280 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
14282 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
14283 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
14284 it
->glyph_row
->used
[TEXT_AREA
] = 1;
14289 /* Save some values that must not be changed. */
14290 int saved_x
= it
->current_x
;
14291 struct text_pos saved_pos
;
14292 Lisp_Object saved_object
;
14293 enum display_element_type saved_what
= it
->what
;
14294 int saved_face_id
= it
->face_id
;
14296 saved_object
= it
->object
;
14297 saved_pos
= it
->position
;
14299 it
->what
= IT_CHARACTER
;
14300 bzero (&it
->position
, sizeof it
->position
);
14301 it
->object
= make_number (0);
14304 it
->face_id
= face
->id
;
14306 PRODUCE_GLYPHS (it
);
14308 while (it
->current_x
<= it
->last_visible_x
)
14309 PRODUCE_GLYPHS (it
);
14311 /* Don't count these blanks really. It would let us insert a left
14312 truncation glyph below and make us set the cursor on them, maybe. */
14313 it
->current_x
= saved_x
;
14314 it
->object
= saved_object
;
14315 it
->position
= saved_pos
;
14316 it
->what
= saved_what
;
14317 it
->face_id
= saved_face_id
;
14322 /* Value is non-zero if text starting at CHARPOS in current_buffer is
14323 trailing whitespace. */
14326 trailing_whitespace_p (charpos
)
14329 int bytepos
= CHAR_TO_BYTE (charpos
);
14332 while (bytepos
< ZV_BYTE
14333 && (c
= FETCH_CHAR (bytepos
),
14334 c
== ' ' || c
== '\t'))
14337 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
14339 if (bytepos
!= PT_BYTE
)
14346 /* Highlight trailing whitespace, if any, in ROW. */
14349 highlight_trailing_whitespace (f
, row
)
14351 struct glyph_row
*row
;
14353 int used
= row
->used
[TEXT_AREA
];
14357 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
14358 struct glyph
*glyph
= start
+ used
- 1;
14360 /* Skip over glyphs inserted to display the cursor at the
14361 end of a line, for extending the face of the last glyph
14362 to the end of the line on terminals, and for truncation
14363 and continuation glyphs. */
14364 while (glyph
>= start
14365 && glyph
->type
== CHAR_GLYPH
14366 && INTEGERP (glyph
->object
))
14369 /* If last glyph is a space or stretch, and it's trailing
14370 whitespace, set the face of all trailing whitespace glyphs in
14371 IT->glyph_row to `trailing-whitespace'. */
14373 && BUFFERP (glyph
->object
)
14374 && (glyph
->type
== STRETCH_GLYPH
14375 || (glyph
->type
== CHAR_GLYPH
14376 && glyph
->u
.ch
== ' '))
14377 && trailing_whitespace_p (glyph
->charpos
))
14379 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
14381 while (glyph
>= start
14382 && BUFFERP (glyph
->object
)
14383 && (glyph
->type
== STRETCH_GLYPH
14384 || (glyph
->type
== CHAR_GLYPH
14385 && glyph
->u
.ch
== ' ')))
14386 (glyph
--)->face_id
= face_id
;
14392 /* Value is non-zero if glyph row ROW in window W should be
14393 used to hold the cursor. */
14396 cursor_row_p (w
, row
)
14398 struct glyph_row
*row
;
14400 int cursor_row_p
= 1;
14402 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
14404 /* If the row ends with a newline from a string, we don't want
14405 the cursor there (if the row is continued it doesn't end in a
14407 if (CHARPOS (row
->end
.string_pos
) >= 0
14408 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14409 cursor_row_p
= row
->continued_p
;
14411 /* If the row ends at ZV, display the cursor at the end of that
14412 row instead of at the start of the row below. */
14413 else if (row
->ends_at_zv_p
)
14419 return cursor_row_p
;
14423 /* Construct the glyph row IT->glyph_row in the desired matrix of
14424 IT->w from text at the current position of IT. See dispextern.h
14425 for an overview of struct it. Value is non-zero if
14426 IT->glyph_row displays text, as opposed to a line displaying ZV
14433 struct glyph_row
*row
= it
->glyph_row
;
14434 int overlay_arrow_bitmap
;
14435 Lisp_Object overlay_arrow_string
;
14437 /* We always start displaying at hpos zero even if hscrolled. */
14438 xassert (it
->hpos
== 0 && it
->current_x
== 0);
14440 /* We must not display in a row that's not a text row. */
14441 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
14442 < it
->w
->desired_matrix
->nrows
);
14444 /* Is IT->w showing the region? */
14445 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
14447 /* Clear the result glyph row and enable it. */
14448 prepare_desired_row (row
);
14450 row
->y
= it
->current_y
;
14451 row
->start
= it
->start
;
14452 row
->continuation_lines_width
= it
->continuation_lines_width
;
14453 row
->displays_text_p
= 1;
14454 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
14455 it
->starts_in_middle_of_char_p
= 0;
14457 /* Arrange the overlays nicely for our purposes. Usually, we call
14458 display_line on only one line at a time, in which case this
14459 can't really hurt too much, or we call it on lines which appear
14460 one after another in the buffer, in which case all calls to
14461 recenter_overlay_lists but the first will be pretty cheap. */
14462 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
14464 /* Move over display elements that are not visible because we are
14465 hscrolled. This may stop at an x-position < IT->first_visible_x
14466 if the first glyph is partially visible or if we hit a line end. */
14467 if (it
->current_x
< it
->first_visible_x
)
14468 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
14469 MOVE_TO_POS
| MOVE_TO_X
);
14471 /* Get the initial row height. This is either the height of the
14472 text hscrolled, if there is any, or zero. */
14473 row
->ascent
= it
->max_ascent
;
14474 row
->height
= it
->max_ascent
+ it
->max_descent
;
14475 row
->phys_ascent
= it
->max_phys_ascent
;
14476 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14478 /* Loop generating characters. The loop is left with IT on the next
14479 character to display. */
14482 int n_glyphs_before
, hpos_before
, x_before
;
14484 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
14486 /* Retrieve the next thing to display. Value is zero if end of
14488 if (!get_next_display_element (it
))
14490 /* Maybe add a space at the end of this line that is used to
14491 display the cursor there under X. Set the charpos of the
14492 first glyph of blank lines not corresponding to any text
14494 #ifdef HAVE_WINDOW_SYSTEM
14495 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14496 row
->exact_window_width_line_p
= 1;
14498 #endif /* HAVE_WINDOW_SYSTEM */
14499 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
14500 || row
->used
[TEXT_AREA
] == 0)
14502 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
14503 row
->displays_text_p
= 0;
14505 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
14506 && (!MINI_WINDOW_P (it
->w
)
14507 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
14508 row
->indicate_empty_line_p
= 1;
14511 it
->continuation_lines_width
= 0;
14512 row
->ends_at_zv_p
= 1;
14516 /* Now, get the metrics of what we want to display. This also
14517 generates glyphs in `row' (which is IT->glyph_row). */
14518 n_glyphs_before
= row
->used
[TEXT_AREA
];
14521 /* Remember the line height so far in case the next element doesn't
14522 fit on the line. */
14523 if (!it
->truncate_lines_p
)
14525 ascent
= it
->max_ascent
;
14526 descent
= it
->max_descent
;
14527 phys_ascent
= it
->max_phys_ascent
;
14528 phys_descent
= it
->max_phys_descent
;
14531 PRODUCE_GLYPHS (it
);
14533 /* If this display element was in marginal areas, continue with
14535 if (it
->area
!= TEXT_AREA
)
14537 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14538 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14539 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14540 row
->phys_height
= max (row
->phys_height
,
14541 it
->max_phys_ascent
+ it
->max_phys_descent
);
14542 set_iterator_to_next (it
, 1);
14546 /* Does the display element fit on the line? If we truncate
14547 lines, we should draw past the right edge of the window. If
14548 we don't truncate, we want to stop so that we can display the
14549 continuation glyph before the right margin. If lines are
14550 continued, there are two possible strategies for characters
14551 resulting in more than 1 glyph (e.g. tabs): Display as many
14552 glyphs as possible in this line and leave the rest for the
14553 continuation line, or display the whole element in the next
14554 line. Original redisplay did the former, so we do it also. */
14555 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
14556 hpos_before
= it
->hpos
;
14559 if (/* Not a newline. */
14561 /* Glyphs produced fit entirely in the line. */
14562 && it
->current_x
< it
->last_visible_x
)
14564 it
->hpos
+= nglyphs
;
14565 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14566 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14567 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14568 row
->phys_height
= max (row
->phys_height
,
14569 it
->max_phys_ascent
+ it
->max_phys_descent
);
14570 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
14571 row
->x
= x
- it
->first_visible_x
;
14576 struct glyph
*glyph
;
14578 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
14580 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14581 new_x
= x
+ glyph
->pixel_width
;
14583 if (/* Lines are continued. */
14584 !it
->truncate_lines_p
14585 && (/* Glyph doesn't fit on the line. */
14586 new_x
> it
->last_visible_x
14587 /* Or it fits exactly on a window system frame. */
14588 || (new_x
== it
->last_visible_x
14589 && FRAME_WINDOW_P (it
->f
))))
14591 /* End of a continued line. */
14594 || (new_x
== it
->last_visible_x
14595 && FRAME_WINDOW_P (it
->f
)))
14597 /* Current glyph is the only one on the line or
14598 fits exactly on the line. We must continue
14599 the line because we can't draw the cursor
14600 after the glyph. */
14601 row
->continued_p
= 1;
14602 it
->current_x
= new_x
;
14603 it
->continuation_lines_width
+= new_x
;
14605 if (i
== nglyphs
- 1)
14607 set_iterator_to_next (it
, 1);
14608 #ifdef HAVE_WINDOW_SYSTEM
14609 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14611 if (!get_next_display_element (it
))
14613 row
->exact_window_width_line_p
= 1;
14614 it
->continuation_lines_width
= 0;
14615 row
->continued_p
= 0;
14616 row
->ends_at_zv_p
= 1;
14618 else if (ITERATOR_AT_END_OF_LINE_P (it
))
14620 row
->continued_p
= 0;
14621 row
->exact_window_width_line_p
= 1;
14624 #endif /* HAVE_WINDOW_SYSTEM */
14627 else if (CHAR_GLYPH_PADDING_P (*glyph
)
14628 && !FRAME_WINDOW_P (it
->f
))
14630 /* A padding glyph that doesn't fit on this line.
14631 This means the whole character doesn't fit
14633 row
->used
[TEXT_AREA
] = n_glyphs_before
;
14635 /* Fill the rest of the row with continuation
14636 glyphs like in 20.x. */
14637 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
14638 < row
->glyphs
[1 + TEXT_AREA
])
14639 produce_special_glyphs (it
, IT_CONTINUATION
);
14641 row
->continued_p
= 1;
14642 it
->current_x
= x_before
;
14643 it
->continuation_lines_width
+= x_before
;
14645 /* Restore the height to what it was before the
14646 element not fitting on the line. */
14647 it
->max_ascent
= ascent
;
14648 it
->max_descent
= descent
;
14649 it
->max_phys_ascent
= phys_ascent
;
14650 it
->max_phys_descent
= phys_descent
;
14652 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
14654 /* A TAB that extends past the right edge of the
14655 window. This produces a single glyph on
14656 window system frames. We leave the glyph in
14657 this row and let it fill the row, but don't
14658 consume the TAB. */
14659 it
->continuation_lines_width
+= it
->last_visible_x
;
14660 row
->ends_in_middle_of_char_p
= 1;
14661 row
->continued_p
= 1;
14662 glyph
->pixel_width
= it
->last_visible_x
- x
;
14663 it
->starts_in_middle_of_char_p
= 1;
14667 /* Something other than a TAB that draws past
14668 the right edge of the window. Restore
14669 positions to values before the element. */
14670 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14672 /* Display continuation glyphs. */
14673 if (!FRAME_WINDOW_P (it
->f
))
14674 produce_special_glyphs (it
, IT_CONTINUATION
);
14675 row
->continued_p
= 1;
14677 it
->continuation_lines_width
+= x
;
14679 if (nglyphs
> 1 && i
> 0)
14681 row
->ends_in_middle_of_char_p
= 1;
14682 it
->starts_in_middle_of_char_p
= 1;
14685 /* Restore the height to what it was before the
14686 element not fitting on the line. */
14687 it
->max_ascent
= ascent
;
14688 it
->max_descent
= descent
;
14689 it
->max_phys_ascent
= phys_ascent
;
14690 it
->max_phys_descent
= phys_descent
;
14695 else if (new_x
> it
->first_visible_x
)
14697 /* Increment number of glyphs actually displayed. */
14700 if (x
< it
->first_visible_x
)
14701 /* Glyph is partially visible, i.e. row starts at
14702 negative X position. */
14703 row
->x
= x
- it
->first_visible_x
;
14707 /* Glyph is completely off the left margin of the
14708 window. This should not happen because of the
14709 move_it_in_display_line at the start of this
14710 function, unless the text display area of the
14711 window is empty. */
14712 xassert (it
->first_visible_x
<= it
->last_visible_x
);
14716 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14717 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14718 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14719 row
->phys_height
= max (row
->phys_height
,
14720 it
->max_phys_ascent
+ it
->max_phys_descent
);
14722 /* End of this display line if row is continued. */
14723 if (row
->continued_p
|| row
->ends_at_zv_p
)
14728 /* Is this a line end? If yes, we're also done, after making
14729 sure that a non-default face is extended up to the right
14730 margin of the window. */
14731 if (ITERATOR_AT_END_OF_LINE_P (it
))
14733 int used_before
= row
->used
[TEXT_AREA
];
14735 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
14737 #ifdef HAVE_WINDOW_SYSTEM
14738 /* Add a space at the end of the line that is used to
14739 display the cursor there. */
14740 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14741 append_space_for_newline (it
, 0);
14742 #endif /* HAVE_WINDOW_SYSTEM */
14744 /* Extend the face to the end of the line. */
14745 extend_face_to_end_of_line (it
);
14747 /* Make sure we have the position. */
14748 if (used_before
== 0)
14749 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
14751 /* Consume the line end. This skips over invisible lines. */
14752 set_iterator_to_next (it
, 1);
14753 it
->continuation_lines_width
= 0;
14757 /* Proceed with next display element. Note that this skips
14758 over lines invisible because of selective display. */
14759 set_iterator_to_next (it
, 1);
14761 /* If we truncate lines, we are done when the last displayed
14762 glyphs reach past the right margin of the window. */
14763 if (it
->truncate_lines_p
14764 && (FRAME_WINDOW_P (it
->f
)
14765 ? (it
->current_x
>= it
->last_visible_x
)
14766 : (it
->current_x
> it
->last_visible_x
)))
14768 /* Maybe add truncation glyphs. */
14769 if (!FRAME_WINDOW_P (it
->f
))
14773 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14774 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14777 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14779 row
->used
[TEXT_AREA
] = i
;
14780 produce_special_glyphs (it
, IT_TRUNCATION
);
14783 #ifdef HAVE_WINDOW_SYSTEM
14786 /* Don't truncate if we can overflow newline into fringe. */
14787 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14789 if (!get_next_display_element (it
))
14791 #ifdef HAVE_WINDOW_SYSTEM
14792 it
->continuation_lines_width
= 0;
14793 row
->ends_at_zv_p
= 1;
14794 row
->exact_window_width_line_p
= 1;
14796 #endif /* HAVE_WINDOW_SYSTEM */
14798 if (ITERATOR_AT_END_OF_LINE_P (it
))
14800 row
->exact_window_width_line_p
= 1;
14801 goto at_end_of_line
;
14805 #endif /* HAVE_WINDOW_SYSTEM */
14807 row
->truncated_on_right_p
= 1;
14808 it
->continuation_lines_width
= 0;
14809 reseat_at_next_visible_line_start (it
, 0);
14810 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
14811 it
->hpos
= hpos_before
;
14812 it
->current_x
= x_before
;
14817 /* If line is not empty and hscrolled, maybe insert truncation glyphs
14818 at the left window margin. */
14819 if (it
->first_visible_x
14820 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
14822 if (!FRAME_WINDOW_P (it
->f
))
14823 insert_left_trunc_glyphs (it
);
14824 row
->truncated_on_left_p
= 1;
14827 /* If the start of this line is the overlay arrow-position, then
14828 mark this glyph row as the one containing the overlay arrow.
14829 This is clearly a mess with variable size fonts. It would be
14830 better to let it be displayed like cursors under X. */
14831 if (! overlay_arrow_seen
14832 && (overlay_arrow_string
14833 = overlay_arrow_at_row (it
->f
, row
, &overlay_arrow_bitmap
),
14834 !NILP (overlay_arrow_string
)))
14836 /* Overlay arrow in window redisplay is a fringe bitmap. */
14837 if (!FRAME_WINDOW_P (it
->f
))
14839 struct glyph_row
*arrow_row
14840 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
14841 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
14842 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
14843 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
14844 struct glyph
*p2
, *end
;
14846 /* Copy the arrow glyphs. */
14847 while (glyph
< arrow_end
)
14850 /* Throw away padding glyphs. */
14852 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
14853 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
14859 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
14863 overlay_arrow_seen
= 1;
14864 it
->w
->overlay_arrow_bitmap
= overlay_arrow_bitmap
;
14865 row
->overlay_arrow_p
= 1;
14868 /* Compute pixel dimensions of this line. */
14869 compute_line_metrics (it
);
14871 /* Remember the position at which this line ends. */
14872 row
->end
= it
->current
;
14874 /* Save fringe bitmaps in this row. */
14875 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
14876 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
14877 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
14878 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
14880 it
->left_user_fringe_bitmap
= 0;
14881 it
->left_user_fringe_face_id
= 0;
14882 it
->right_user_fringe_bitmap
= 0;
14883 it
->right_user_fringe_face_id
= 0;
14885 /* Maybe set the cursor. */
14886 if (it
->w
->cursor
.vpos
< 0
14887 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
14888 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
14889 && cursor_row_p (it
->w
, row
))
14890 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
14892 /* Highlight trailing whitespace. */
14893 if (!NILP (Vshow_trailing_whitespace
))
14894 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
14896 /* Prepare for the next line. This line starts horizontally at (X
14897 HPOS) = (0 0). Vertical positions are incremented. As a
14898 convenience for the caller, IT->glyph_row is set to the next
14900 it
->current_x
= it
->hpos
= 0;
14901 it
->current_y
+= row
->height
;
14904 it
->start
= it
->current
;
14905 return row
->displays_text_p
;
14910 /***********************************************************************
14912 ***********************************************************************/
14914 /* Redisplay the menu bar in the frame for window W.
14916 The menu bar of X frames that don't have X toolkit support is
14917 displayed in a special window W->frame->menu_bar_window.
14919 The menu bar of terminal frames is treated specially as far as
14920 glyph matrices are concerned. Menu bar lines are not part of
14921 windows, so the update is done directly on the frame matrix rows
14922 for the menu bar. */
14925 display_menu_bar (w
)
14928 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14933 /* Don't do all this for graphical frames. */
14935 if (!NILP (Vwindow_system
))
14938 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
14943 if (FRAME_MAC_P (f
))
14947 #ifdef USE_X_TOOLKIT
14948 xassert (!FRAME_WINDOW_P (f
));
14949 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
14950 it
.first_visible_x
= 0;
14951 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
14952 #else /* not USE_X_TOOLKIT */
14953 if (FRAME_WINDOW_P (f
))
14955 /* Menu bar lines are displayed in the desired matrix of the
14956 dummy window menu_bar_window. */
14957 struct window
*menu_w
;
14958 xassert (WINDOWP (f
->menu_bar_window
));
14959 menu_w
= XWINDOW (f
->menu_bar_window
);
14960 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
14962 it
.first_visible_x
= 0;
14963 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
14967 /* This is a TTY frame, i.e. character hpos/vpos are used as
14969 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
14971 it
.first_visible_x
= 0;
14972 it
.last_visible_x
= FRAME_COLS (f
);
14974 #endif /* not USE_X_TOOLKIT */
14976 if (! mode_line_inverse_video
)
14977 /* Force the menu-bar to be displayed in the default face. */
14978 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
14980 /* Clear all rows of the menu bar. */
14981 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
14983 struct glyph_row
*row
= it
.glyph_row
+ i
;
14984 clear_glyph_row (row
);
14985 row
->enabled_p
= 1;
14986 row
->full_width_p
= 1;
14989 /* Display all items of the menu bar. */
14990 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
14991 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
14993 Lisp_Object string
;
14995 /* Stop at nil string. */
14996 string
= AREF (items
, i
+ 1);
15000 /* Remember where item was displayed. */
15001 AREF (items
, i
+ 3) = make_number (it
.hpos
);
15003 /* Display the item, pad with one space. */
15004 if (it
.current_x
< it
.last_visible_x
)
15005 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
15006 SCHARS (string
) + 1, 0, 0, -1);
15009 /* Fill out the line with spaces. */
15010 if (it
.current_x
< it
.last_visible_x
)
15011 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
15013 /* Compute the total height of the lines. */
15014 compute_line_metrics (&it
);
15019 /***********************************************************************
15021 ***********************************************************************/
15023 /* Redisplay mode lines in the window tree whose root is WINDOW. If
15024 FORCE is non-zero, redisplay mode lines unconditionally.
15025 Otherwise, redisplay only mode lines that are garbaged. Value is
15026 the number of windows whose mode lines were redisplayed. */
15029 redisplay_mode_lines (window
, force
)
15030 Lisp_Object window
;
15035 while (!NILP (window
))
15037 struct window
*w
= XWINDOW (window
);
15039 if (WINDOWP (w
->hchild
))
15040 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
15041 else if (WINDOWP (w
->vchild
))
15042 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
15044 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
15045 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
15047 struct text_pos lpoint
;
15048 struct buffer
*old
= current_buffer
;
15050 /* Set the window's buffer for the mode line display. */
15051 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15052 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15054 /* Point refers normally to the selected window. For any
15055 other window, set up appropriate value. */
15056 if (!EQ (window
, selected_window
))
15058 struct text_pos pt
;
15060 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
15061 if (CHARPOS (pt
) < BEGV
)
15062 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15063 else if (CHARPOS (pt
) > (ZV
- 1))
15064 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
15066 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
15069 /* Display mode lines. */
15070 clear_glyph_matrix (w
->desired_matrix
);
15071 if (display_mode_lines (w
))
15074 w
->must_be_updated_p
= 1;
15077 /* Restore old settings. */
15078 set_buffer_internal_1 (old
);
15079 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15089 /* Display the mode and/or top line of window W. Value is the number
15090 of mode lines displayed. */
15093 display_mode_lines (w
)
15096 Lisp_Object old_selected_window
, old_selected_frame
;
15099 old_selected_frame
= selected_frame
;
15100 selected_frame
= w
->frame
;
15101 old_selected_window
= selected_window
;
15102 XSETWINDOW (selected_window
, w
);
15104 /* These will be set while the mode line specs are processed. */
15105 line_number_displayed
= 0;
15106 w
->column_number_displayed
= Qnil
;
15108 if (WINDOW_WANTS_MODELINE_P (w
))
15110 struct window
*sel_w
= XWINDOW (old_selected_window
);
15112 /* Select mode line face based on the real selected window. */
15113 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
15114 current_buffer
->mode_line_format
);
15118 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15120 display_mode_line (w
, HEADER_LINE_FACE_ID
,
15121 current_buffer
->header_line_format
);
15125 selected_frame
= old_selected_frame
;
15126 selected_window
= old_selected_window
;
15131 /* Display mode or top line of window W. FACE_ID specifies which line
15132 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
15133 FORMAT is the mode line format to display. Value is the pixel
15134 height of the mode line displayed. */
15137 display_mode_line (w
, face_id
, format
)
15139 enum face_id face_id
;
15140 Lisp_Object format
;
15145 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15146 prepare_desired_row (it
.glyph_row
);
15148 it
.glyph_row
->mode_line_p
= 1;
15150 if (! mode_line_inverse_video
)
15151 /* Force the mode-line to be displayed in the default face. */
15152 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15154 /* Temporarily make frame's keyboard the current kboard so that
15155 kboard-local variables in the mode_line_format will get the right
15157 push_frame_kboard (it
.f
);
15158 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15159 pop_frame_kboard ();
15161 /* Fill up with spaces. */
15162 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
15164 compute_line_metrics (&it
);
15165 it
.glyph_row
->full_width_p
= 1;
15166 it
.glyph_row
->continued_p
= 0;
15167 it
.glyph_row
->truncated_on_left_p
= 0;
15168 it
.glyph_row
->truncated_on_right_p
= 0;
15170 /* Make a 3D mode-line have a shadow at its right end. */
15171 face
= FACE_FROM_ID (it
.f
, face_id
);
15172 extend_face_to_end_of_line (&it
);
15173 if (face
->box
!= FACE_NO_BOX
)
15175 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
15176 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
15177 last
->right_box_line_p
= 1;
15180 return it
.glyph_row
->height
;
15183 /* Alist that caches the results of :propertize.
15184 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
15185 Lisp_Object mode_line_proptrans_alist
;
15187 /* List of strings making up the mode-line. */
15188 Lisp_Object mode_line_string_list
;
15190 /* Base face property when building propertized mode line string. */
15191 static Lisp_Object mode_line_string_face
;
15192 static Lisp_Object mode_line_string_face_prop
;
15195 /* Contribute ELT to the mode line for window IT->w. How it
15196 translates into text depends on its data type.
15198 IT describes the display environment in which we display, as usual.
15200 DEPTH is the depth in recursion. It is used to prevent
15201 infinite recursion here.
15203 FIELD_WIDTH is the number of characters the display of ELT should
15204 occupy in the mode line, and PRECISION is the maximum number of
15205 characters to display from ELT's representation. See
15206 display_string for details.
15208 Returns the hpos of the end of the text generated by ELT.
15210 PROPS is a property list to add to any string we encounter.
15212 If RISKY is nonzero, remove (disregard) any properties in any string
15213 we encounter, and ignore :eval and :propertize.
15215 If the global variable `frame_title_ptr' is non-NULL, then the output
15216 is passed to `store_frame_title' instead of `display_string'. */
15219 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
15222 int field_width
, precision
;
15223 Lisp_Object elt
, props
;
15226 int n
= 0, field
, prec
;
15231 elt
= build_string ("*too-deep*");
15235 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
15239 /* A string: output it and check for %-constructs within it. */
15241 const unsigned char *this, *lisp_string
;
15243 if (!NILP (props
) || risky
)
15245 Lisp_Object oprops
, aelt
;
15246 oprops
= Ftext_properties_at (make_number (0), elt
);
15248 if (NILP (Fequal (props
, oprops
)) || risky
)
15250 /* If the starting string has properties,
15251 merge the specified ones onto the existing ones. */
15252 if (! NILP (oprops
) && !risky
)
15256 oprops
= Fcopy_sequence (oprops
);
15258 while (CONSP (tem
))
15260 oprops
= Fplist_put (oprops
, XCAR (tem
),
15261 XCAR (XCDR (tem
)));
15262 tem
= XCDR (XCDR (tem
));
15267 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
15268 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
15270 mode_line_proptrans_alist
15271 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
15278 elt
= Fcopy_sequence (elt
);
15279 Fset_text_properties (make_number (0), Flength (elt
),
15281 /* Add this item to mode_line_proptrans_alist. */
15282 mode_line_proptrans_alist
15283 = Fcons (Fcons (elt
, props
),
15284 mode_line_proptrans_alist
);
15285 /* Truncate mode_line_proptrans_alist
15286 to at most 50 elements. */
15287 tem
= Fnthcdr (make_number (50),
15288 mode_line_proptrans_alist
);
15290 XSETCDR (tem
, Qnil
);
15295 this = SDATA (elt
);
15296 lisp_string
= this;
15300 prec
= precision
- n
;
15301 if (frame_title_ptr
)
15302 n
+= store_frame_title (SDATA (elt
), -1, prec
);
15303 else if (!NILP (mode_line_string_list
))
15304 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
15306 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
15307 0, prec
, 0, STRING_MULTIBYTE (elt
));
15312 while ((precision
<= 0 || n
< precision
)
15314 && (frame_title_ptr
15315 || !NILP (mode_line_string_list
)
15316 || it
->current_x
< it
->last_visible_x
))
15318 const unsigned char *last
= this;
15320 /* Advance to end of string or next format specifier. */
15321 while ((c
= *this++) != '\0' && c
!= '%')
15324 if (this - 1 != last
)
15326 /* Output to end of string or up to '%'. Field width
15327 is length of string. Don't output more than
15328 PRECISION allows us. */
15331 prec
= chars_in_text (last
, this - last
);
15332 if (precision
> 0 && prec
> precision
- n
)
15333 prec
= precision
- n
;
15335 if (frame_title_ptr
)
15336 n
+= store_frame_title (last
, 0, prec
);
15337 else if (!NILP (mode_line_string_list
))
15339 int bytepos
= last
- lisp_string
;
15340 int charpos
= string_byte_to_char (elt
, bytepos
);
15341 n
+= store_mode_line_string (NULL
,
15342 Fsubstring (elt
, make_number (charpos
),
15343 make_number (charpos
+ prec
)),
15348 int bytepos
= last
- lisp_string
;
15349 int charpos
= string_byte_to_char (elt
, bytepos
);
15350 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
15352 STRING_MULTIBYTE (elt
));
15355 else /* c == '%' */
15357 const unsigned char *percent_position
= this;
15359 /* Get the specified minimum width. Zero means
15362 while ((c
= *this++) >= '0' && c
<= '9')
15363 field
= field
* 10 + c
- '0';
15365 /* Don't pad beyond the total padding allowed. */
15366 if (field_width
- n
> 0 && field
> field_width
- n
)
15367 field
= field_width
- n
;
15369 /* Note that either PRECISION <= 0 or N < PRECISION. */
15370 prec
= precision
- n
;
15373 n
+= display_mode_element (it
, depth
, field
, prec
,
15374 Vglobal_mode_string
, props
,
15379 int bytepos
, charpos
;
15380 unsigned char *spec
;
15382 bytepos
= percent_position
- lisp_string
;
15383 charpos
= (STRING_MULTIBYTE (elt
)
15384 ? string_byte_to_char (elt
, bytepos
)
15388 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
15390 if (frame_title_ptr
)
15391 n
+= store_frame_title (spec
, field
, prec
);
15392 else if (!NILP (mode_line_string_list
))
15394 int len
= strlen (spec
);
15395 Lisp_Object tem
= make_string (spec
, len
);
15396 props
= Ftext_properties_at (make_number (charpos
), elt
);
15397 /* Should only keep face property in props */
15398 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
15402 int nglyphs_before
, nwritten
;
15404 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
15405 nwritten
= display_string (spec
, Qnil
, elt
,
15410 /* Assign to the glyphs written above the
15411 string where the `%x' came from, position
15415 struct glyph
*glyph
15416 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
15420 for (i
= 0; i
< nwritten
; ++i
)
15422 glyph
[i
].object
= elt
;
15423 glyph
[i
].charpos
= charpos
;
15438 /* A symbol: process the value of the symbol recursively
15439 as if it appeared here directly. Avoid error if symbol void.
15440 Special case: if value of symbol is a string, output the string
15443 register Lisp_Object tem
;
15445 /* If the variable is not marked as risky to set
15446 then its contents are risky to use. */
15447 if (NILP (Fget (elt
, Qrisky_local_variable
)))
15450 tem
= Fboundp (elt
);
15453 tem
= Fsymbol_value (elt
);
15454 /* If value is a string, output that string literally:
15455 don't check for % within it. */
15459 if (!EQ (tem
, elt
))
15461 /* Give up right away for nil or t. */
15471 register Lisp_Object car
, tem
;
15473 /* A cons cell: five distinct cases.
15474 If first element is :eval or :propertize, do something special.
15475 If first element is a string or a cons, process all the elements
15476 and effectively concatenate them.
15477 If first element is a negative number, truncate displaying cdr to
15478 at most that many characters. If positive, pad (with spaces)
15479 to at least that many characters.
15480 If first element is a symbol, process the cadr or caddr recursively
15481 according to whether the symbol's value is non-nil or nil. */
15483 if (EQ (car
, QCeval
))
15485 /* An element of the form (:eval FORM) means evaluate FORM
15486 and use the result as mode line elements. */
15491 if (CONSP (XCDR (elt
)))
15494 spec
= safe_eval (XCAR (XCDR (elt
)));
15495 n
+= display_mode_element (it
, depth
, field_width
- n
,
15496 precision
- n
, spec
, props
,
15500 else if (EQ (car
, QCpropertize
))
15502 /* An element of the form (:propertize ELT PROPS...)
15503 means display ELT but applying properties PROPS. */
15508 if (CONSP (XCDR (elt
)))
15509 n
+= display_mode_element (it
, depth
, field_width
- n
,
15510 precision
- n
, XCAR (XCDR (elt
)),
15511 XCDR (XCDR (elt
)), risky
);
15513 else if (SYMBOLP (car
))
15515 tem
= Fboundp (car
);
15519 /* elt is now the cdr, and we know it is a cons cell.
15520 Use its car if CAR has a non-nil value. */
15523 tem
= Fsymbol_value (car
);
15530 /* Symbol's value is nil (or symbol is unbound)
15531 Get the cddr of the original list
15532 and if possible find the caddr and use that. */
15536 else if (!CONSP (elt
))
15541 else if (INTEGERP (car
))
15543 register int lim
= XINT (car
);
15547 /* Negative int means reduce maximum width. */
15548 if (precision
<= 0)
15551 precision
= min (precision
, -lim
);
15555 /* Padding specified. Don't let it be more than
15556 current maximum. */
15558 lim
= min (precision
, lim
);
15560 /* If that's more padding than already wanted, queue it.
15561 But don't reduce padding already specified even if
15562 that is beyond the current truncation point. */
15563 field_width
= max (lim
, field_width
);
15567 else if (STRINGP (car
) || CONSP (car
))
15569 register int limit
= 50;
15570 /* Limit is to protect against circular lists. */
15573 && (precision
<= 0 || n
< precision
))
15575 n
+= display_mode_element (it
, depth
, field_width
- n
,
15576 precision
- n
, XCAR (elt
),
15586 elt
= build_string ("*invalid*");
15590 /* Pad to FIELD_WIDTH. */
15591 if (field_width
> 0 && n
< field_width
)
15593 if (frame_title_ptr
)
15594 n
+= store_frame_title ("", field_width
- n
, 0);
15595 else if (!NILP (mode_line_string_list
))
15596 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
15598 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
15605 /* Store a mode-line string element in mode_line_string_list.
15607 If STRING is non-null, display that C string. Otherwise, the Lisp
15608 string LISP_STRING is displayed.
15610 FIELD_WIDTH is the minimum number of output glyphs to produce.
15611 If STRING has fewer characters than FIELD_WIDTH, pad to the right
15612 with spaces. FIELD_WIDTH <= 0 means don't pad.
15614 PRECISION is the maximum number of characters to output from
15615 STRING. PRECISION <= 0 means don't truncate the string.
15617 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
15618 properties to the string.
15620 PROPS are the properties to add to the string.
15621 The mode_line_string_face face property is always added to the string.
15624 static int store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
15626 Lisp_Object lisp_string
;
15635 if (string
!= NULL
)
15637 len
= strlen (string
);
15638 if (precision
> 0 && len
> precision
)
15640 lisp_string
= make_string (string
, len
);
15642 props
= mode_line_string_face_prop
;
15643 else if (!NILP (mode_line_string_face
))
15645 Lisp_Object face
= Fplist_get (props
, Qface
);
15646 props
= Fcopy_sequence (props
);
15648 face
= mode_line_string_face
;
15650 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15651 props
= Fplist_put (props
, Qface
, face
);
15653 Fadd_text_properties (make_number (0), make_number (len
),
15654 props
, lisp_string
);
15658 len
= XFASTINT (Flength (lisp_string
));
15659 if (precision
> 0 && len
> precision
)
15662 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
15665 if (!NILP (mode_line_string_face
))
15669 props
= Ftext_properties_at (make_number (0), lisp_string
);
15670 face
= Fplist_get (props
, Qface
);
15672 face
= mode_line_string_face
;
15674 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15675 props
= Fcons (Qface
, Fcons (face
, Qnil
));
15677 lisp_string
= Fcopy_sequence (lisp_string
);
15680 Fadd_text_properties (make_number (0), make_number (len
),
15681 props
, lisp_string
);
15686 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15690 if (field_width
> len
)
15692 field_width
-= len
;
15693 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
15695 Fadd_text_properties (make_number (0), make_number (field_width
),
15696 props
, lisp_string
);
15697 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15705 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
15707 doc
: /* Return the mode-line of selected window as a string.
15708 First optional arg FORMAT specifies a different format string (see
15709 `mode-line-format' for details) to use. If FORMAT is t, return
15710 the buffer's header-line. Second optional arg WINDOW specifies a
15711 different window to use as the context for the formatting.
15712 If third optional arg NO-PROPS is non-nil, string is not propertized. */)
15713 (format
, window
, no_props
)
15714 Lisp_Object format
, window
, no_props
;
15719 struct buffer
*old_buffer
= NULL
;
15720 enum face_id face_id
= DEFAULT_FACE_ID
;
15723 window
= selected_window
;
15724 CHECK_WINDOW (window
);
15725 w
= XWINDOW (window
);
15726 CHECK_BUFFER (w
->buffer
);
15728 if (XBUFFER (w
->buffer
) != current_buffer
)
15730 old_buffer
= current_buffer
;
15731 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15734 if (NILP (format
) || EQ (format
, Qt
))
15736 face_id
= NILP (format
)
15737 ? CURRENT_MODE_LINE_FACE_ID (w
) :
15738 HEADER_LINE_FACE_ID
;
15739 format
= NILP (format
)
15740 ? current_buffer
->mode_line_format
15741 : current_buffer
->header_line_format
;
15744 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15746 if (NILP (no_props
))
15748 mode_line_string_face
=
15749 (face_id
== MODE_LINE_FACE_ID
? Qmode_line
:
15750 face_id
== MODE_LINE_INACTIVE_FACE_ID
? Qmode_line_inactive
:
15751 face_id
== HEADER_LINE_FACE_ID
? Qheader_line
: Qnil
);
15753 mode_line_string_face_prop
=
15754 NILP (mode_line_string_face
) ? Qnil
:
15755 Fcons (Qface
, Fcons (mode_line_string_face
, Qnil
));
15757 /* We need a dummy last element in mode_line_string_list to
15758 indicate we are building the propertized mode-line string.
15759 Using mode_line_string_face_prop here GC protects it. */
15760 mode_line_string_list
=
15761 Fcons (mode_line_string_face_prop
, Qnil
);
15762 frame_title_ptr
= NULL
;
15766 mode_line_string_face_prop
= Qnil
;
15767 mode_line_string_list
= Qnil
;
15768 frame_title_ptr
= frame_title_buf
;
15771 push_frame_kboard (it
.f
);
15772 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15773 pop_frame_kboard ();
15776 set_buffer_internal_1 (old_buffer
);
15778 if (NILP (no_props
))
15781 mode_line_string_list
= Fnreverse (mode_line_string_list
);
15782 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
15783 make_string ("", 0));
15784 mode_line_string_face_prop
= Qnil
;
15785 mode_line_string_list
= Qnil
;
15789 len
= frame_title_ptr
- frame_title_buf
;
15790 if (len
> 0 && frame_title_ptr
[-1] == '-')
15792 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
15793 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
15795 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
15796 if (len
> frame_title_ptr
- frame_title_buf
)
15797 len
= frame_title_ptr
- frame_title_buf
;
15800 frame_title_ptr
= NULL
;
15801 return make_string (frame_title_buf
, len
);
15804 /* Write a null-terminated, right justified decimal representation of
15805 the positive integer D to BUF using a minimal field width WIDTH. */
15808 pint2str (buf
, width
, d
)
15809 register char *buf
;
15810 register int width
;
15813 register char *p
= buf
;
15821 *p
++ = d
% 10 + '0';
15826 for (width
-= (int) (p
- buf
); width
> 0; --width
)
15837 /* Write a null-terminated, right justified decimal and "human
15838 readable" representation of the nonnegative integer D to BUF using
15839 a minimal field width WIDTH. D should be smaller than 999.5e24. */
15841 static const char power_letter
[] =
15855 pint2hrstr (buf
, width
, d
)
15860 /* We aim to represent the nonnegative integer D as
15861 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
15864 /* -1 means: do not use TENTHS. */
15868 /* Length of QUOTIENT.TENTHS as a string. */
15874 if (1000 <= quotient
)
15876 /* Scale to the appropriate EXPONENT. */
15879 remainder
= quotient
% 1000;
15883 while (1000 <= quotient
);
15885 /* Round to nearest and decide whether to use TENTHS or not. */
15888 tenths
= remainder
/ 100;
15889 if (50 <= remainder
% 100)
15895 if (quotient
== 10)
15902 if (500 <= remainder
)
15903 if (quotient
< 999)
15913 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
15914 if (tenths
== -1 && quotient
<= 99)
15921 p
= psuffix
= buf
+ max (width
, length
);
15923 /* Print EXPONENT. */
15925 *psuffix
++ = power_letter
[exponent
];
15928 /* Print TENTHS. */
15931 *--p
= '0' + tenths
;
15935 /* Print QUOTIENT. */
15938 int digit
= quotient
% 10;
15939 *--p
= '0' + digit
;
15941 while ((quotient
/= 10) != 0);
15943 /* Print leading spaces. */
15948 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
15949 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
15950 type of CODING_SYSTEM. Return updated pointer into BUF. */
15952 static unsigned char invalid_eol_type
[] = "(*invalid*)";
15955 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
15956 Lisp_Object coding_system
;
15957 register char *buf
;
15961 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
15962 const unsigned char *eol_str
;
15964 /* The EOL conversion we are using. */
15965 Lisp_Object eoltype
;
15967 val
= Fget (coding_system
, Qcoding_system
);
15970 if (!VECTORP (val
)) /* Not yet decided. */
15975 eoltype
= eol_mnemonic_undecided
;
15976 /* Don't mention EOL conversion if it isn't decided. */
15980 Lisp_Object eolvalue
;
15982 eolvalue
= Fget (coding_system
, Qeol_type
);
15985 *buf
++ = XFASTINT (AREF (val
, 1));
15989 /* The EOL conversion that is normal on this system. */
15991 if (NILP (eolvalue
)) /* Not yet decided. */
15992 eoltype
= eol_mnemonic_undecided
;
15993 else if (VECTORP (eolvalue
)) /* Not yet decided. */
15994 eoltype
= eol_mnemonic_undecided
;
15995 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
15996 eoltype
= (XFASTINT (eolvalue
) == 0
15997 ? eol_mnemonic_unix
15998 : (XFASTINT (eolvalue
) == 1
15999 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
16005 /* Mention the EOL conversion if it is not the usual one. */
16006 if (STRINGP (eoltype
))
16008 eol_str
= SDATA (eoltype
);
16009 eol_str_len
= SBYTES (eoltype
);
16011 else if (INTEGERP (eoltype
)
16012 && CHAR_VALID_P (XINT (eoltype
), 0))
16014 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
16015 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
16020 eol_str
= invalid_eol_type
;
16021 eol_str_len
= sizeof (invalid_eol_type
) - 1;
16023 bcopy (eol_str
, buf
, eol_str_len
);
16024 buf
+= eol_str_len
;
16030 /* Return a string for the output of a mode line %-spec for window W,
16031 generated by character C. PRECISION >= 0 means don't return a
16032 string longer than that value. FIELD_WIDTH > 0 means pad the
16033 string returned with spaces to that value. Return 1 in *MULTIBYTE
16034 if the result is multibyte text. */
16036 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
16039 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
16042 int field_width
, precision
;
16046 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16047 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
16048 struct buffer
*b
= XBUFFER (w
->buffer
);
16056 if (!NILP (b
->read_only
))
16058 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16063 /* This differs from %* only for a modified read-only buffer. */
16064 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16066 if (!NILP (b
->read_only
))
16071 /* This differs from %* in ignoring read-only-ness. */
16072 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16084 if (command_loop_level
> 5)
16086 p
= decode_mode_spec_buf
;
16087 for (i
= 0; i
< command_loop_level
; i
++)
16090 return decode_mode_spec_buf
;
16098 if (command_loop_level
> 5)
16100 p
= decode_mode_spec_buf
;
16101 for (i
= 0; i
< command_loop_level
; i
++)
16104 return decode_mode_spec_buf
;
16111 /* Let lots_of_dashes be a string of infinite length. */
16112 if (!NILP (mode_line_string_list
))
16114 if (field_width
<= 0
16115 || field_width
> sizeof (lots_of_dashes
))
16117 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
16118 decode_mode_spec_buf
[i
] = '-';
16119 decode_mode_spec_buf
[i
] = '\0';
16120 return decode_mode_spec_buf
;
16123 return lots_of_dashes
;
16132 int col
= (int) current_column (); /* iftc */
16133 w
->column_number_displayed
= make_number (col
);
16134 pint2str (decode_mode_spec_buf
, field_width
, col
);
16135 return decode_mode_spec_buf
;
16139 /* %F displays the frame name. */
16140 if (!NILP (f
->title
))
16141 return (char *) SDATA (f
->title
);
16142 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
16143 return (char *) SDATA (f
->name
);
16152 int size
= ZV
- BEGV
;
16153 pint2str (decode_mode_spec_buf
, field_width
, size
);
16154 return decode_mode_spec_buf
;
16159 int size
= ZV
- BEGV
;
16160 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
16161 return decode_mode_spec_buf
;
16166 int startpos
= XMARKER (w
->start
)->charpos
;
16167 int startpos_byte
= marker_byte_position (w
->start
);
16168 int line
, linepos
, linepos_byte
, topline
;
16170 int height
= WINDOW_TOTAL_LINES (w
);
16172 /* If we decided that this buffer isn't suitable for line numbers,
16173 don't forget that too fast. */
16174 if (EQ (w
->base_line_pos
, w
->buffer
))
16176 /* But do forget it, if the window shows a different buffer now. */
16177 else if (BUFFERP (w
->base_line_pos
))
16178 w
->base_line_pos
= Qnil
;
16180 /* If the buffer is very big, don't waste time. */
16181 if (INTEGERP (Vline_number_display_limit
)
16182 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
16184 w
->base_line_pos
= Qnil
;
16185 w
->base_line_number
= Qnil
;
16189 if (!NILP (w
->base_line_number
)
16190 && !NILP (w
->base_line_pos
)
16191 && XFASTINT (w
->base_line_pos
) <= startpos
)
16193 line
= XFASTINT (w
->base_line_number
);
16194 linepos
= XFASTINT (w
->base_line_pos
);
16195 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
16200 linepos
= BUF_BEGV (b
);
16201 linepos_byte
= BUF_BEGV_BYTE (b
);
16204 /* Count lines from base line to window start position. */
16205 nlines
= display_count_lines (linepos
, linepos_byte
,
16209 topline
= nlines
+ line
;
16211 /* Determine a new base line, if the old one is too close
16212 or too far away, or if we did not have one.
16213 "Too close" means it's plausible a scroll-down would
16214 go back past it. */
16215 if (startpos
== BUF_BEGV (b
))
16217 w
->base_line_number
= make_number (topline
);
16218 w
->base_line_pos
= make_number (BUF_BEGV (b
));
16220 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
16221 || linepos
== BUF_BEGV (b
))
16223 int limit
= BUF_BEGV (b
);
16224 int limit_byte
= BUF_BEGV_BYTE (b
);
16226 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
16228 if (startpos
- distance
> limit
)
16230 limit
= startpos
- distance
;
16231 limit_byte
= CHAR_TO_BYTE (limit
);
16234 nlines
= display_count_lines (startpos
, startpos_byte
,
16236 - (height
* 2 + 30),
16238 /* If we couldn't find the lines we wanted within
16239 line_number_display_limit_width chars per line,
16240 give up on line numbers for this window. */
16241 if (position
== limit_byte
&& limit
== startpos
- distance
)
16243 w
->base_line_pos
= w
->buffer
;
16244 w
->base_line_number
= Qnil
;
16248 w
->base_line_number
= make_number (topline
- nlines
);
16249 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
16252 /* Now count lines from the start pos to point. */
16253 nlines
= display_count_lines (startpos
, startpos_byte
,
16254 PT_BYTE
, PT
, &junk
);
16256 /* Record that we did display the line number. */
16257 line_number_displayed
= 1;
16259 /* Make the string to show. */
16260 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
16261 return decode_mode_spec_buf
;
16264 char* p
= decode_mode_spec_buf
;
16265 int pad
= field_width
- 2;
16271 return decode_mode_spec_buf
;
16277 obj
= b
->mode_name
;
16281 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
16287 int pos
= marker_position (w
->start
);
16288 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16290 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
16292 if (pos
<= BUF_BEGV (b
))
16297 else if (pos
<= BUF_BEGV (b
))
16301 if (total
> 1000000)
16302 /* Do it differently for a large value, to avoid overflow. */
16303 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16305 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16306 /* We can't normally display a 3-digit number,
16307 so get us a 2-digit number that is close. */
16310 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16311 return decode_mode_spec_buf
;
16315 /* Display percentage of size above the bottom of the screen. */
16318 int toppos
= marker_position (w
->start
);
16319 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
16320 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16322 if (botpos
>= BUF_ZV (b
))
16324 if (toppos
<= BUF_BEGV (b
))
16331 if (total
> 1000000)
16332 /* Do it differently for a large value, to avoid overflow. */
16333 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16335 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16336 /* We can't normally display a 3-digit number,
16337 so get us a 2-digit number that is close. */
16340 if (toppos
<= BUF_BEGV (b
))
16341 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
16343 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16344 return decode_mode_spec_buf
;
16349 /* status of process */
16350 obj
= Fget_buffer_process (w
->buffer
);
16352 return "no process";
16353 #ifdef subprocesses
16354 obj
= Fsymbol_name (Fprocess_status (obj
));
16358 case 't': /* indicate TEXT or BINARY */
16359 #ifdef MODE_LINE_BINARY_TEXT
16360 return MODE_LINE_BINARY_TEXT (b
);
16366 /* coding-system (not including end-of-line format) */
16368 /* coding-system (including end-of-line type) */
16370 int eol_flag
= (c
== 'Z');
16371 char *p
= decode_mode_spec_buf
;
16373 if (! FRAME_WINDOW_P (f
))
16375 /* No need to mention EOL here--the terminal never needs
16376 to do EOL conversion. */
16377 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
16378 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
16380 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
16383 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
16384 #ifdef subprocesses
16385 obj
= Fget_buffer_process (Fcurrent_buffer ());
16386 if (PROCESSP (obj
))
16388 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
16390 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
16393 #endif /* subprocesses */
16396 return decode_mode_spec_buf
;
16402 *multibyte
= STRING_MULTIBYTE (obj
);
16403 return (char *) SDATA (obj
);
16410 /* Count up to COUNT lines starting from START / START_BYTE.
16411 But don't go beyond LIMIT_BYTE.
16412 Return the number of lines thus found (always nonnegative).
16414 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
16417 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
16418 int start
, start_byte
, limit_byte
, count
;
16421 register unsigned char *cursor
;
16422 unsigned char *base
;
16424 register int ceiling
;
16425 register unsigned char *ceiling_addr
;
16426 int orig_count
= count
;
16428 /* If we are not in selective display mode,
16429 check only for newlines. */
16430 int selective_display
= (!NILP (current_buffer
->selective_display
)
16431 && !INTEGERP (current_buffer
->selective_display
));
16435 while (start_byte
< limit_byte
)
16437 ceiling
= BUFFER_CEILING_OF (start_byte
);
16438 ceiling
= min (limit_byte
- 1, ceiling
);
16439 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
16440 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
16443 if (selective_display
)
16444 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
16447 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
16450 if (cursor
!= ceiling_addr
)
16454 start_byte
+= cursor
- base
+ 1;
16455 *byte_pos_ptr
= start_byte
;
16459 if (++cursor
== ceiling_addr
)
16465 start_byte
+= cursor
- base
;
16470 while (start_byte
> limit_byte
)
16472 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
16473 ceiling
= max (limit_byte
, ceiling
);
16474 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
16475 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
16478 if (selective_display
)
16479 while (--cursor
!= ceiling_addr
16480 && *cursor
!= '\n' && *cursor
!= 015)
16483 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
16486 if (cursor
!= ceiling_addr
)
16490 start_byte
+= cursor
- base
+ 1;
16491 *byte_pos_ptr
= start_byte
;
16492 /* When scanning backwards, we should
16493 not count the newline posterior to which we stop. */
16494 return - orig_count
- 1;
16500 /* Here we add 1 to compensate for the last decrement
16501 of CURSOR, which took it past the valid range. */
16502 start_byte
+= cursor
- base
+ 1;
16506 *byte_pos_ptr
= limit_byte
;
16509 return - orig_count
+ count
;
16510 return orig_count
- count
;
16516 /***********************************************************************
16518 ***********************************************************************/
16520 /* Display a NUL-terminated string, starting with index START.
16522 If STRING is non-null, display that C string. Otherwise, the Lisp
16523 string LISP_STRING is displayed.
16525 If FACE_STRING is not nil, FACE_STRING_POS is a position in
16526 FACE_STRING. Display STRING or LISP_STRING with the face at
16527 FACE_STRING_POS in FACE_STRING:
16529 Display the string in the environment given by IT, but use the
16530 standard display table, temporarily.
16532 FIELD_WIDTH is the minimum number of output glyphs to produce.
16533 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16534 with spaces. If STRING has more characters, more than FIELD_WIDTH
16535 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
16537 PRECISION is the maximum number of characters to output from
16538 STRING. PRECISION < 0 means don't truncate the string.
16540 This is roughly equivalent to printf format specifiers:
16542 FIELD_WIDTH PRECISION PRINTF
16543 ----------------------------------------
16549 MULTIBYTE zero means do not display multibyte chars, > 0 means do
16550 display them, and < 0 means obey the current buffer's value of
16551 enable_multibyte_characters.
16553 Value is the number of glyphs produced. */
16556 display_string (string
, lisp_string
, face_string
, face_string_pos
,
16557 start
, it
, field_width
, precision
, max_x
, multibyte
)
16558 unsigned char *string
;
16559 Lisp_Object lisp_string
;
16560 Lisp_Object face_string
;
16561 int face_string_pos
;
16564 int field_width
, precision
, max_x
;
16567 int hpos_at_start
= it
->hpos
;
16568 int saved_face_id
= it
->face_id
;
16569 struct glyph_row
*row
= it
->glyph_row
;
16571 /* Initialize the iterator IT for iteration over STRING beginning
16572 with index START. */
16573 reseat_to_string (it
, string
, lisp_string
, start
,
16574 precision
, field_width
, multibyte
);
16576 /* If displaying STRING, set up the face of the iterator
16577 from LISP_STRING, if that's given. */
16578 if (STRINGP (face_string
))
16584 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
16585 0, it
->region_beg_charpos
,
16586 it
->region_end_charpos
,
16587 &endptr
, it
->base_face_id
, 0);
16588 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16589 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
16592 /* Set max_x to the maximum allowed X position. Don't let it go
16593 beyond the right edge of the window. */
16595 max_x
= it
->last_visible_x
;
16597 max_x
= min (max_x
, it
->last_visible_x
);
16599 /* Skip over display elements that are not visible. because IT->w is
16601 if (it
->current_x
< it
->first_visible_x
)
16602 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
16603 MOVE_TO_POS
| MOVE_TO_X
);
16605 row
->ascent
= it
->max_ascent
;
16606 row
->height
= it
->max_ascent
+ it
->max_descent
;
16607 row
->phys_ascent
= it
->max_phys_ascent
;
16608 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16610 /* This condition is for the case that we are called with current_x
16611 past last_visible_x. */
16612 while (it
->current_x
< max_x
)
16614 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
16616 /* Get the next display element. */
16617 if (!get_next_display_element (it
))
16620 /* Produce glyphs. */
16621 x_before
= it
->current_x
;
16622 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16623 PRODUCE_GLYPHS (it
);
16625 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
16628 while (i
< nglyphs
)
16630 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16632 if (!it
->truncate_lines_p
16633 && x
+ glyph
->pixel_width
> max_x
)
16635 /* End of continued line or max_x reached. */
16636 if (CHAR_GLYPH_PADDING_P (*glyph
))
16638 /* A wide character is unbreakable. */
16639 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16640 it
->current_x
= x_before
;
16644 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16649 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
16651 /* Glyph is at least partially visible. */
16653 if (x
< it
->first_visible_x
)
16654 it
->glyph_row
->x
= x
- it
->first_visible_x
;
16658 /* Glyph is off the left margin of the display area.
16659 Should not happen. */
16663 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16664 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16665 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16666 row
->phys_height
= max (row
->phys_height
,
16667 it
->max_phys_ascent
+ it
->max_phys_descent
);
16668 x
+= glyph
->pixel_width
;
16672 /* Stop if max_x reached. */
16676 /* Stop at line ends. */
16677 if (ITERATOR_AT_END_OF_LINE_P (it
))
16679 it
->continuation_lines_width
= 0;
16683 set_iterator_to_next (it
, 1);
16685 /* Stop if truncating at the right edge. */
16686 if (it
->truncate_lines_p
16687 && it
->current_x
>= it
->last_visible_x
)
16689 /* Add truncation mark, but don't do it if the line is
16690 truncated at a padding space. */
16691 if (IT_CHARPOS (*it
) < it
->string_nchars
)
16693 if (!FRAME_WINDOW_P (it
->f
))
16697 if (it
->current_x
> it
->last_visible_x
)
16699 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16700 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16702 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16704 row
->used
[TEXT_AREA
] = i
;
16705 produce_special_glyphs (it
, IT_TRUNCATION
);
16708 produce_special_glyphs (it
, IT_TRUNCATION
);
16710 it
->glyph_row
->truncated_on_right_p
= 1;
16716 /* Maybe insert a truncation at the left. */
16717 if (it
->first_visible_x
16718 && IT_CHARPOS (*it
) > 0)
16720 if (!FRAME_WINDOW_P (it
->f
))
16721 insert_left_trunc_glyphs (it
);
16722 it
->glyph_row
->truncated_on_left_p
= 1;
16725 it
->face_id
= saved_face_id
;
16727 /* Value is number of columns displayed. */
16728 return it
->hpos
- hpos_at_start
;
16733 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
16734 appears as an element of LIST or as the car of an element of LIST.
16735 If PROPVAL is a list, compare each element against LIST in that
16736 way, and return 1/2 if any element of PROPVAL is found in LIST.
16737 Otherwise return 0. This function cannot quit.
16738 The return value is 2 if the text is invisible but with an ellipsis
16739 and 1 if it's invisible and without an ellipsis. */
16742 invisible_p (propval
, list
)
16743 register Lisp_Object propval
;
16746 register Lisp_Object tail
, proptail
;
16748 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
16750 register Lisp_Object tem
;
16752 if (EQ (propval
, tem
))
16754 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
16755 return NILP (XCDR (tem
)) ? 1 : 2;
16758 if (CONSP (propval
))
16760 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
16762 Lisp_Object propelt
;
16763 propelt
= XCAR (proptail
);
16764 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
16766 register Lisp_Object tem
;
16768 if (EQ (propelt
, tem
))
16770 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
16771 return NILP (XCDR (tem
)) ? 1 : 2;
16779 /* Calculate a width or height in pixels from a specification using
16780 the following elements:
16783 NUM - a (fractional) multiple of the default font width/height
16784 (NUM) - specifies exactly NUM pixels
16785 UNIT - a fixed number of pixels, see below.
16786 ELEMENT - size of a display element in pixels, see below.
16787 (NUM . SPEC) - equals NUM * SPEC
16788 (+ SPEC SPEC ...) - add pixel values
16789 (- SPEC SPEC ...) - subtract pixel values
16790 (- SPEC) - negate pixel value
16793 INT or FLOAT - a number constant
16794 SYMBOL - use symbol's (buffer local) variable binding.
16797 in - pixels per inch *)
16798 mm - pixels per 1/1000 meter *)
16799 cm - pixels per 1/100 meter *)
16800 width - width of current font in pixels.
16801 height - height of current font in pixels.
16803 *) using the ratio(s) defined in display-pixels-per-inch.
16807 left-fringe - left fringe width in pixels
16808 right-fringe - right fringe width in pixels
16810 left-margin - left margin width in pixels
16811 right-margin - right margin width in pixels
16813 scroll-bar - scroll-bar area width in pixels
16817 Pixels corresponding to 5 inches:
16820 Total width of non-text areas on left side of window (if scroll-bar is on left):
16821 '(space :width (+ left-fringe left-margin scroll-bar))
16823 Align to first text column (in header line):
16824 '(space :align-to 0)
16826 Align to middle of text area minus half the width of variable `my-image'
16827 containing a loaded image:
16828 '(space :align-to (0.5 . (- text my-image)))
16830 Width of left margin minus width of 1 character in the default font:
16831 '(space :width (- left-margin 1))
16833 Width of left margin minus width of 2 characters in the current font:
16834 '(space :width (- left-margin (2 . width)))
16836 Center 1 character over left-margin (in header line):
16837 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
16839 Different ways to express width of left fringe plus left margin minus one pixel:
16840 '(space :width (- (+ left-fringe left-margin) (1)))
16841 '(space :width (+ left-fringe left-margin (- (1))))
16842 '(space :width (+ left-fringe left-margin (-1)))
16846 #define NUMVAL(X) \
16847 ((INTEGERP (X) || FLOATP (X)) \
16852 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
16857 int width_p
, *align_to
;
16861 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
16862 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
16865 return OK_PIXELS (0);
16867 if (SYMBOLP (prop
))
16869 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
16871 char *unit
= SDATA (SYMBOL_NAME (prop
));
16873 if (unit
[0] == 'i' && unit
[1] == 'n')
16875 else if (unit
[0] == 'm' && unit
[1] == 'm')
16877 else if (unit
[0] == 'c' && unit
[1] == 'm')
16884 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
16885 || (CONSP (Vdisplay_pixels_per_inch
)
16887 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
16888 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
16890 return OK_PIXELS (ppi
/ pixels
);
16896 #ifdef HAVE_WINDOW_SYSTEM
16897 if (EQ (prop
, Qheight
))
16898 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
16899 if (EQ (prop
, Qwidth
))
16900 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
16902 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
16903 return OK_PIXELS (1);
16906 if (EQ (prop
, Qtext
))
16907 return OK_PIXELS (width_p
16908 ? window_box_width (it
->w
, TEXT_AREA
)
16909 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
16911 if (align_to
&& *align_to
< 0)
16914 if (EQ (prop
, Qleft
))
16915 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
16916 if (EQ (prop
, Qright
))
16917 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
16918 if (EQ (prop
, Qcenter
))
16919 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
16920 + window_box_width (it
->w
, TEXT_AREA
) / 2);
16921 if (EQ (prop
, Qleft_fringe
))
16922 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
16923 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
16924 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
16925 if (EQ (prop
, Qright_fringe
))
16926 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
16927 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
16928 : window_box_right_offset (it
->w
, TEXT_AREA
));
16929 if (EQ (prop
, Qleft_margin
))
16930 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
16931 if (EQ (prop
, Qright_margin
))
16932 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
16933 if (EQ (prop
, Qscroll_bar
))
16934 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
16936 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
16937 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
16938 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
16943 if (EQ (prop
, Qleft_fringe
))
16944 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
16945 if (EQ (prop
, Qright_fringe
))
16946 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
16947 if (EQ (prop
, Qleft_margin
))
16948 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
16949 if (EQ (prop
, Qright_margin
))
16950 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
16951 if (EQ (prop
, Qscroll_bar
))
16952 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
16955 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
16958 if (INTEGERP (prop
) || FLOATP (prop
))
16960 int base_unit
= (width_p
16961 ? FRAME_COLUMN_WIDTH (it
->f
)
16962 : FRAME_LINE_HEIGHT (it
->f
));
16963 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
16968 Lisp_Object car
= XCAR (prop
);
16969 Lisp_Object cdr
= XCDR (prop
);
16973 #ifdef HAVE_WINDOW_SYSTEM
16974 if (valid_image_p (prop
))
16976 int id
= lookup_image (it
->f
, prop
);
16977 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
16979 return OK_PIXELS (width_p
? img
->width
: img
->height
);
16982 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
16988 while (CONSP (cdr
))
16990 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
16991 font
, width_p
, align_to
))
16994 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
16999 if (EQ (car
, Qminus
))
17001 return OK_PIXELS (pixels
);
17004 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
17007 if (INTEGERP (car
) || FLOATP (car
))
17010 pixels
= XFLOATINT (car
);
17012 return OK_PIXELS (pixels
);
17013 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
17014 font
, width_p
, align_to
))
17015 return OK_PIXELS (pixels
* fact
);
17026 /***********************************************************************
17028 ***********************************************************************/
17030 #ifdef HAVE_WINDOW_SYSTEM
17035 dump_glyph_string (s
)
17036 struct glyph_string
*s
;
17038 fprintf (stderr
, "glyph string\n");
17039 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
17040 s
->x
, s
->y
, s
->width
, s
->height
);
17041 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
17042 fprintf (stderr
, " hl = %d\n", s
->hl
);
17043 fprintf (stderr
, " left overhang = %d, right = %d\n",
17044 s
->left_overhang
, s
->right_overhang
);
17045 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
17046 fprintf (stderr
, " extends to end of line = %d\n",
17047 s
->extends_to_end_of_line_p
);
17048 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
17049 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
17052 #endif /* GLYPH_DEBUG */
17054 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
17055 of XChar2b structures for S; it can't be allocated in
17056 init_glyph_string because it must be allocated via `alloca'. W
17057 is the window on which S is drawn. ROW and AREA are the glyph row
17058 and area within the row from which S is constructed. START is the
17059 index of the first glyph structure covered by S. HL is a
17060 face-override for drawing S. */
17063 #define OPTIONAL_HDC(hdc) hdc,
17064 #define DECLARE_HDC(hdc) HDC hdc;
17065 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
17066 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
17069 #ifndef OPTIONAL_HDC
17070 #define OPTIONAL_HDC(hdc)
17071 #define DECLARE_HDC(hdc)
17072 #define ALLOCATE_HDC(hdc, f)
17073 #define RELEASE_HDC(hdc, f)
17077 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
17078 struct glyph_string
*s
;
17082 struct glyph_row
*row
;
17083 enum glyph_row_area area
;
17085 enum draw_glyphs_face hl
;
17087 bzero (s
, sizeof *s
);
17089 s
->f
= XFRAME (w
->frame
);
17093 s
->display
= FRAME_X_DISPLAY (s
->f
);
17094 s
->window
= FRAME_X_WINDOW (s
->f
);
17095 s
->char2b
= char2b
;
17099 s
->first_glyph
= row
->glyphs
[area
] + start
;
17100 s
->height
= row
->height
;
17101 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
17103 /* Display the internal border below the tool-bar window. */
17104 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
17105 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
17107 s
->ybase
= s
->y
+ row
->ascent
;
17111 /* Append the list of glyph strings with head H and tail T to the list
17112 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
17115 append_glyph_string_lists (head
, tail
, h
, t
)
17116 struct glyph_string
**head
, **tail
;
17117 struct glyph_string
*h
, *t
;
17131 /* Prepend the list of glyph strings with head H and tail T to the
17132 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
17136 prepend_glyph_string_lists (head
, tail
, h
, t
)
17137 struct glyph_string
**head
, **tail
;
17138 struct glyph_string
*h
, *t
;
17152 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
17153 Set *HEAD and *TAIL to the resulting list. */
17156 append_glyph_string (head
, tail
, s
)
17157 struct glyph_string
**head
, **tail
;
17158 struct glyph_string
*s
;
17160 s
->next
= s
->prev
= NULL
;
17161 append_glyph_string_lists (head
, tail
, s
, s
);
17165 /* Get face and two-byte form of character glyph GLYPH on frame F.
17166 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
17167 a pointer to a realized face that is ready for display. */
17169 static INLINE
struct face
*
17170 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
17172 struct glyph
*glyph
;
17178 xassert (glyph
->type
== CHAR_GLYPH
);
17179 face
= FACE_FROM_ID (f
, glyph
->face_id
);
17184 if (!glyph
->multibyte_p
)
17186 /* Unibyte case. We don't have to encode, but we have to make
17187 sure to use a face suitable for unibyte. */
17188 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17190 else if (glyph
->u
.ch
< 128
17191 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
17193 /* Case of ASCII in a face known to fit ASCII. */
17194 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17198 int c1
, c2
, charset
;
17200 /* Split characters into bytes. If c2 is -1 afterwards, C is
17201 really a one-byte character so that byte1 is zero. */
17202 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
17204 STORE_XCHAR2B (char2b
, c1
, c2
);
17206 STORE_XCHAR2B (char2b
, 0, c1
);
17208 /* Maybe encode the character in *CHAR2B. */
17209 if (charset
!= CHARSET_ASCII
)
17211 struct font_info
*font_info
17212 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17215 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
17219 /* Make sure X resources of the face are allocated. */
17220 xassert (face
!= NULL
);
17221 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17226 /* Fill glyph string S with composition components specified by S->cmp.
17228 FACES is an array of faces for all components of this composition.
17229 S->gidx is the index of the first component for S.
17230 OVERLAPS_P non-zero means S should draw the foreground only, and
17231 use its physical height for clipping.
17233 Value is the index of a component not in S. */
17236 fill_composite_glyph_string (s
, faces
, overlaps_p
)
17237 struct glyph_string
*s
;
17238 struct face
**faces
;
17245 s
->for_overlaps_p
= overlaps_p
;
17247 s
->face
= faces
[s
->gidx
];
17248 s
->font
= s
->face
->font
;
17249 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17251 /* For all glyphs of this composition, starting at the offset
17252 S->gidx, until we reach the end of the definition or encounter a
17253 glyph that requires the different face, add it to S. */
17255 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
17258 /* All glyph strings for the same composition has the same width,
17259 i.e. the width set for the first component of the composition. */
17261 s
->width
= s
->first_glyph
->pixel_width
;
17263 /* If the specified font could not be loaded, use the frame's
17264 default font, but record the fact that we couldn't load it in
17265 the glyph string so that we can draw rectangles for the
17266 characters of the glyph string. */
17267 if (s
->font
== NULL
)
17269 s
->font_not_found_p
= 1;
17270 s
->font
= FRAME_FONT (s
->f
);
17273 /* Adjust base line for subscript/superscript text. */
17274 s
->ybase
+= s
->first_glyph
->voffset
;
17276 xassert (s
->face
&& s
->face
->gc
);
17278 /* This glyph string must always be drawn with 16-bit functions. */
17281 return s
->gidx
+ s
->nchars
;
17285 /* Fill glyph string S from a sequence of character glyphs.
17287 FACE_ID is the face id of the string. START is the index of the
17288 first glyph to consider, END is the index of the last + 1.
17289 OVERLAPS_P non-zero means S should draw the foreground only, and
17290 use its physical height for clipping.
17292 Value is the index of the first glyph not in S. */
17295 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
17296 struct glyph_string
*s
;
17298 int start
, end
, overlaps_p
;
17300 struct glyph
*glyph
, *last
;
17302 int glyph_not_available_p
;
17304 xassert (s
->f
== XFRAME (s
->w
->frame
));
17305 xassert (s
->nchars
== 0);
17306 xassert (start
>= 0 && end
> start
);
17308 s
->for_overlaps_p
= overlaps_p
,
17309 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17310 last
= s
->row
->glyphs
[s
->area
] + end
;
17311 voffset
= glyph
->voffset
;
17313 glyph_not_available_p
= glyph
->glyph_not_available_p
;
17315 while (glyph
< last
17316 && glyph
->type
== CHAR_GLYPH
17317 && glyph
->voffset
== voffset
17318 /* Same face id implies same font, nowadays. */
17319 && glyph
->face_id
== face_id
17320 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
17324 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
17325 s
->char2b
+ s
->nchars
,
17327 s
->two_byte_p
= two_byte_p
;
17329 xassert (s
->nchars
<= end
- start
);
17330 s
->width
+= glyph
->pixel_width
;
17334 s
->font
= s
->face
->font
;
17335 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17337 /* If the specified font could not be loaded, use the frame's font,
17338 but record the fact that we couldn't load it in
17339 S->font_not_found_p so that we can draw rectangles for the
17340 characters of the glyph string. */
17341 if (s
->font
== NULL
|| glyph_not_available_p
)
17343 s
->font_not_found_p
= 1;
17344 s
->font
= FRAME_FONT (s
->f
);
17347 /* Adjust base line for subscript/superscript text. */
17348 s
->ybase
+= voffset
;
17350 xassert (s
->face
&& s
->face
->gc
);
17351 return glyph
- s
->row
->glyphs
[s
->area
];
17355 /* Fill glyph string S from image glyph S->first_glyph. */
17358 fill_image_glyph_string (s
)
17359 struct glyph_string
*s
;
17361 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
17362 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
17364 s
->slice
= s
->first_glyph
->slice
;
17365 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
17366 s
->font
= s
->face
->font
;
17367 s
->width
= s
->first_glyph
->pixel_width
;
17369 /* Adjust base line for subscript/superscript text. */
17370 s
->ybase
+= s
->first_glyph
->voffset
;
17374 /* Fill glyph string S from a sequence of stretch glyphs.
17376 ROW is the glyph row in which the glyphs are found, AREA is the
17377 area within the row. START is the index of the first glyph to
17378 consider, END is the index of the last + 1.
17380 Value is the index of the first glyph not in S. */
17383 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
17384 struct glyph_string
*s
;
17385 struct glyph_row
*row
;
17386 enum glyph_row_area area
;
17389 struct glyph
*glyph
, *last
;
17390 int voffset
, face_id
;
17392 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
17394 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17395 last
= s
->row
->glyphs
[s
->area
] + end
;
17396 face_id
= glyph
->face_id
;
17397 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
17398 s
->font
= s
->face
->font
;
17399 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17400 s
->width
= glyph
->pixel_width
;
17401 voffset
= glyph
->voffset
;
17405 && glyph
->type
== STRETCH_GLYPH
17406 && glyph
->voffset
== voffset
17407 && glyph
->face_id
== face_id
);
17409 s
->width
+= glyph
->pixel_width
;
17411 /* Adjust base line for subscript/superscript text. */
17412 s
->ybase
+= voffset
;
17414 /* The case that face->gc == 0 is handled when drawing the glyph
17415 string by calling PREPARE_FACE_FOR_DISPLAY. */
17417 return glyph
- s
->row
->glyphs
[s
->area
];
17422 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
17423 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
17424 assumed to be zero. */
17427 x_get_glyph_overhangs (glyph
, f
, left
, right
)
17428 struct glyph
*glyph
;
17432 *left
= *right
= 0;
17434 if (glyph
->type
== CHAR_GLYPH
)
17438 struct font_info
*font_info
;
17442 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
17444 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17445 if (font
/* ++KFS: Should this be font_info ? */
17446 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
17448 if (pcm
->rbearing
> pcm
->width
)
17449 *right
= pcm
->rbearing
- pcm
->width
;
17450 if (pcm
->lbearing
< 0)
17451 *left
= -pcm
->lbearing
;
17457 /* Return the index of the first glyph preceding glyph string S that
17458 is overwritten by S because of S's left overhang. Value is -1
17459 if no glyphs are overwritten. */
17462 left_overwritten (s
)
17463 struct glyph_string
*s
;
17467 if (s
->left_overhang
)
17470 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17471 int first
= s
->first_glyph
- glyphs
;
17473 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
17474 x
-= glyphs
[i
].pixel_width
;
17485 /* Return the index of the first glyph preceding glyph string S that
17486 is overwriting S because of its right overhang. Value is -1 if no
17487 glyph in front of S overwrites S. */
17490 left_overwriting (s
)
17491 struct glyph_string
*s
;
17494 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17495 int first
= s
->first_glyph
- glyphs
;
17499 for (i
= first
- 1; i
>= 0; --i
)
17502 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17505 x
-= glyphs
[i
].pixel_width
;
17512 /* Return the index of the last glyph following glyph string S that is
17513 not overwritten by S because of S's right overhang. Value is -1 if
17514 no such glyph is found. */
17517 right_overwritten (s
)
17518 struct glyph_string
*s
;
17522 if (s
->right_overhang
)
17525 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17526 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17527 int end
= s
->row
->used
[s
->area
];
17529 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
17530 x
+= glyphs
[i
].pixel_width
;
17539 /* Return the index of the last glyph following glyph string S that
17540 overwrites S because of its left overhang. Value is negative
17541 if no such glyph is found. */
17544 right_overwriting (s
)
17545 struct glyph_string
*s
;
17548 int end
= s
->row
->used
[s
->area
];
17549 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17550 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17554 for (i
= first
; i
< end
; ++i
)
17557 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17560 x
+= glyphs
[i
].pixel_width
;
17567 /* Get face and two-byte form of character C in face FACE_ID on frame
17568 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
17569 means we want to display multibyte text. DISPLAY_P non-zero means
17570 make sure that X resources for the face returned are allocated.
17571 Value is a pointer to a realized face that is ready for display if
17572 DISPLAY_P is non-zero. */
17574 static INLINE
struct face
*
17575 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
17579 int multibyte_p
, display_p
;
17581 struct face
*face
= FACE_FROM_ID (f
, face_id
);
17585 /* Unibyte case. We don't have to encode, but we have to make
17586 sure to use a face suitable for unibyte. */
17587 STORE_XCHAR2B (char2b
, 0, c
);
17588 face_id
= FACE_FOR_CHAR (f
, face
, c
);
17589 face
= FACE_FROM_ID (f
, face_id
);
17591 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
17593 /* Case of ASCII in a face known to fit ASCII. */
17594 STORE_XCHAR2B (char2b
, 0, c
);
17598 int c1
, c2
, charset
;
17600 /* Split characters into bytes. If c2 is -1 afterwards, C is
17601 really a one-byte character so that byte1 is zero. */
17602 SPLIT_CHAR (c
, charset
, c1
, c2
);
17604 STORE_XCHAR2B (char2b
, c1
, c2
);
17606 STORE_XCHAR2B (char2b
, 0, c1
);
17608 /* Maybe encode the character in *CHAR2B. */
17609 if (face
->font
!= NULL
)
17611 struct font_info
*font_info
17612 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17614 rif
->encode_char (c
, char2b
, font_info
, 0);
17618 /* Make sure X resources of the face are allocated. */
17619 #ifdef HAVE_X_WINDOWS
17623 xassert (face
!= NULL
);
17624 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17631 /* Set background width of glyph string S. START is the index of the
17632 first glyph following S. LAST_X is the right-most x-position + 1
17633 in the drawing area. */
17636 set_glyph_string_background_width (s
, start
, last_x
)
17637 struct glyph_string
*s
;
17641 /* If the face of this glyph string has to be drawn to the end of
17642 the drawing area, set S->extends_to_end_of_line_p. */
17643 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
17645 if (start
== s
->row
->used
[s
->area
]
17646 && s
->area
== TEXT_AREA
17647 && ((s
->hl
== DRAW_NORMAL_TEXT
17648 && (s
->row
->fill_line_p
17649 || s
->face
->background
!= default_face
->background
17650 || s
->face
->stipple
!= default_face
->stipple
17651 || s
->row
->mouse_face_p
))
17652 || s
->hl
== DRAW_MOUSE_FACE
17653 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
17654 && s
->row
->fill_line_p
)))
17655 s
->extends_to_end_of_line_p
= 1;
17657 /* If S extends its face to the end of the line, set its
17658 background_width to the distance to the right edge of the drawing
17660 if (s
->extends_to_end_of_line_p
)
17661 s
->background_width
= last_x
- s
->x
+ 1;
17663 s
->background_width
= s
->width
;
17667 /* Compute overhangs and x-positions for glyph string S and its
17668 predecessors, or successors. X is the starting x-position for S.
17669 BACKWARD_P non-zero means process predecessors. */
17672 compute_overhangs_and_x (s
, x
, backward_p
)
17673 struct glyph_string
*s
;
17681 if (rif
->compute_glyph_string_overhangs
)
17682 rif
->compute_glyph_string_overhangs (s
);
17692 if (rif
->compute_glyph_string_overhangs
)
17693 rif
->compute_glyph_string_overhangs (s
);
17703 /* The following macros are only called from draw_glyphs below.
17704 They reference the following parameters of that function directly:
17705 `w', `row', `area', and `overlap_p'
17706 as well as the following local variables:
17707 `s', `f', and `hdc' (in W32) */
17710 /* On W32, silently add local `hdc' variable to argument list of
17711 init_glyph_string. */
17712 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17713 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
17715 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17716 init_glyph_string (s, char2b, w, row, area, start, hl)
17719 /* Add a glyph string for a stretch glyph to the list of strings
17720 between HEAD and TAIL. START is the index of the stretch glyph in
17721 row area AREA of glyph row ROW. END is the index of the last glyph
17722 in that glyph row area. X is the current output position assigned
17723 to the new glyph string constructed. HL overrides that face of the
17724 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17725 is the right-most x-position of the drawing area. */
17727 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
17728 and below -- keep them on one line. */
17729 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17732 s = (struct glyph_string *) alloca (sizeof *s); \
17733 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17734 START = fill_stretch_glyph_string (s, row, area, START, END); \
17735 append_glyph_string (&HEAD, &TAIL, s); \
17741 /* Add a glyph string for an image glyph to the list of strings
17742 between HEAD and TAIL. START is the index of the image glyph in
17743 row area AREA of glyph row ROW. END is the index of the last glyph
17744 in that glyph row area. X is the current output position assigned
17745 to the new glyph string constructed. HL overrides that face of the
17746 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17747 is the right-most x-position of the drawing area. */
17749 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17752 s = (struct glyph_string *) alloca (sizeof *s); \
17753 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17754 fill_image_glyph_string (s); \
17755 append_glyph_string (&HEAD, &TAIL, s); \
17762 /* Add a glyph string for a sequence of character glyphs to the list
17763 of strings between HEAD and TAIL. START is the index of the first
17764 glyph in row area AREA of glyph row ROW that is part of the new
17765 glyph string. END is the index of the last glyph in that glyph row
17766 area. X is the current output position assigned to the new glyph
17767 string constructed. HL overrides that face of the glyph; e.g. it
17768 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
17769 right-most x-position of the drawing area. */
17771 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
17777 c = (row)->glyphs[area][START].u.ch; \
17778 face_id = (row)->glyphs[area][START].face_id; \
17780 s = (struct glyph_string *) alloca (sizeof *s); \
17781 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
17782 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
17783 append_glyph_string (&HEAD, &TAIL, s); \
17785 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
17790 /* Add a glyph string for a composite sequence to the list of strings
17791 between HEAD and TAIL. START is the index of the first glyph in
17792 row area AREA of glyph row ROW that is part of the new glyph
17793 string. END is the index of the last glyph in that glyph row area.
17794 X is the current output position assigned to the new glyph string
17795 constructed. HL overrides that face of the glyph; e.g. it is
17796 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
17797 x-position of the drawing area. */
17799 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17801 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
17802 int face_id = (row)->glyphs[area][START].face_id; \
17803 struct face *base_face = FACE_FROM_ID (f, face_id); \
17804 struct composition *cmp = composition_table[cmp_id]; \
17805 int glyph_len = cmp->glyph_len; \
17807 struct face **faces; \
17808 struct glyph_string *first_s = NULL; \
17811 base_face = base_face->ascii_face; \
17812 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
17813 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
17814 /* At first, fill in `char2b' and `faces'. */ \
17815 for (n = 0; n < glyph_len; n++) \
17817 int c = COMPOSITION_GLYPH (cmp, n); \
17818 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
17819 faces[n] = FACE_FROM_ID (f, this_face_id); \
17820 get_char_face_and_encoding (f, c, this_face_id, \
17821 char2b + n, 1, 1); \
17824 /* Make glyph_strings for each glyph sequence that is drawable by \
17825 the same face, and append them to HEAD/TAIL. */ \
17826 for (n = 0; n < cmp->glyph_len;) \
17828 s = (struct glyph_string *) alloca (sizeof *s); \
17829 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
17830 append_glyph_string (&(HEAD), &(TAIL), s); \
17838 n = fill_composite_glyph_string (s, faces, overlaps_p); \
17846 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
17847 of AREA of glyph row ROW on window W between indices START and END.
17848 HL overrides the face for drawing glyph strings, e.g. it is
17849 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
17850 x-positions of the drawing area.
17852 This is an ugly monster macro construct because we must use alloca
17853 to allocate glyph strings (because draw_glyphs can be called
17854 asynchronously). */
17856 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
17859 HEAD = TAIL = NULL; \
17860 while (START < END) \
17862 struct glyph *first_glyph = (row)->glyphs[area] + START; \
17863 switch (first_glyph->type) \
17866 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
17870 case COMPOSITE_GLYPH: \
17871 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
17875 case STRETCH_GLYPH: \
17876 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
17880 case IMAGE_GLYPH: \
17881 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
17889 set_glyph_string_background_width (s, START, LAST_X); \
17896 /* Draw glyphs between START and END in AREA of ROW on window W,
17897 starting at x-position X. X is relative to AREA in W. HL is a
17898 face-override with the following meaning:
17900 DRAW_NORMAL_TEXT draw normally
17901 DRAW_CURSOR draw in cursor face
17902 DRAW_MOUSE_FACE draw in mouse face.
17903 DRAW_INVERSE_VIDEO draw in mode line face
17904 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
17905 DRAW_IMAGE_RAISED draw an image with a raised relief around it
17907 If OVERLAPS_P is non-zero, draw only the foreground of characters
17908 and clip to the physical height of ROW.
17910 Value is the x-position reached, relative to AREA of W. */
17913 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
17916 struct glyph_row
*row
;
17917 enum glyph_row_area area
;
17919 enum draw_glyphs_face hl
;
17922 struct glyph_string
*head
, *tail
;
17923 struct glyph_string
*s
;
17924 int last_x
, area_width
;
17927 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17930 ALLOCATE_HDC (hdc
, f
);
17932 /* Let's rather be paranoid than getting a SEGV. */
17933 end
= min (end
, row
->used
[area
]);
17934 start
= max (0, start
);
17935 start
= min (end
, start
);
17937 /* Translate X to frame coordinates. Set last_x to the right
17938 end of the drawing area. */
17939 if (row
->full_width_p
)
17941 /* X is relative to the left edge of W, without scroll bars
17943 x
+= WINDOW_LEFT_EDGE_X (w
);
17944 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
17948 int area_left
= window_box_left (w
, area
);
17950 area_width
= window_box_width (w
, area
);
17951 last_x
= area_left
+ area_width
;
17954 /* Build a doubly-linked list of glyph_string structures between
17955 head and tail from what we have to draw. Note that the macro
17956 BUILD_GLYPH_STRINGS will modify its start parameter. That's
17957 the reason we use a separate variable `i'. */
17959 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
17961 x_reached
= tail
->x
+ tail
->background_width
;
17965 /* If there are any glyphs with lbearing < 0 or rbearing > width in
17966 the row, redraw some glyphs in front or following the glyph
17967 strings built above. */
17968 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
17971 struct glyph_string
*h
, *t
;
17973 /* Compute overhangs for all glyph strings. */
17974 if (rif
->compute_glyph_string_overhangs
)
17975 for (s
= head
; s
; s
= s
->next
)
17976 rif
->compute_glyph_string_overhangs (s
);
17978 /* Prepend glyph strings for glyphs in front of the first glyph
17979 string that are overwritten because of the first glyph
17980 string's left overhang. The background of all strings
17981 prepended must be drawn because the first glyph string
17983 i
= left_overwritten (head
);
17987 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
17988 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
17990 compute_overhangs_and_x (t
, head
->x
, 1);
17991 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
17994 /* Prepend glyph strings for glyphs in front of the first glyph
17995 string that overwrite that glyph string because of their
17996 right overhang. For these strings, only the foreground must
17997 be drawn, because it draws over the glyph string at `head'.
17998 The background must not be drawn because this would overwrite
17999 right overhangs of preceding glyphs for which no glyph
18001 i
= left_overwriting (head
);
18004 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
18005 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18006 for (s
= h
; s
; s
= s
->next
)
18007 s
->background_filled_p
= 1;
18008 compute_overhangs_and_x (t
, head
->x
, 1);
18009 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18012 /* Append glyphs strings for glyphs following the last glyph
18013 string tail that are overwritten by tail. The background of
18014 these strings has to be drawn because tail's foreground draws
18016 i
= right_overwritten (tail
);
18019 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18020 DRAW_NORMAL_TEXT
, x
, last_x
);
18021 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18022 append_glyph_string_lists (&head
, &tail
, h
, t
);
18025 /* Append glyph strings for glyphs following the last glyph
18026 string tail that overwrite tail. The foreground of such
18027 glyphs has to be drawn because it writes into the background
18028 of tail. The background must not be drawn because it could
18029 paint over the foreground of following glyphs. */
18030 i
= right_overwriting (tail
);
18033 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18034 DRAW_NORMAL_TEXT
, x
, last_x
);
18035 for (s
= h
; s
; s
= s
->next
)
18036 s
->background_filled_p
= 1;
18037 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18038 append_glyph_string_lists (&head
, &tail
, h
, t
);
18042 /* Draw all strings. */
18043 for (s
= head
; s
; s
= s
->next
)
18044 rif
->draw_glyph_string (s
);
18046 if (area
== TEXT_AREA
18047 && !row
->full_width_p
18048 /* When drawing overlapping rows, only the glyph strings'
18049 foreground is drawn, which doesn't erase a cursor
18053 int x0
= head
? head
->x
: x
;
18054 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
18056 int text_left
= window_box_left (w
, TEXT_AREA
);
18060 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
18061 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
18064 /* Value is the x-position up to which drawn, relative to AREA of W.
18065 This doesn't include parts drawn because of overhangs. */
18066 if (row
->full_width_p
)
18067 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
18069 x_reached
-= window_box_left (w
, area
);
18071 RELEASE_HDC (hdc
, f
);
18077 /* Store one glyph for IT->char_to_display in IT->glyph_row.
18078 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18084 struct glyph
*glyph
;
18085 enum glyph_row_area area
= it
->area
;
18087 xassert (it
->glyph_row
);
18088 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
18090 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18091 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18093 glyph
->charpos
= CHARPOS (it
->position
);
18094 glyph
->object
= it
->object
;
18095 glyph
->pixel_width
= it
->pixel_width
;
18096 glyph
->ascent
= it
->ascent
;
18097 glyph
->descent
= it
->descent
;
18098 glyph
->voffset
= it
->voffset
;
18099 glyph
->type
= CHAR_GLYPH
;
18100 glyph
->multibyte_p
= it
->multibyte_p
;
18101 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18102 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18103 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18104 || it
->phys_descent
> it
->descent
);
18105 glyph
->padding_p
= 0;
18106 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
18107 glyph
->face_id
= it
->face_id
;
18108 glyph
->u
.ch
= it
->char_to_display
;
18109 glyph
->slice
= null_glyph_slice
;
18110 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18111 ++it
->glyph_row
->used
[area
];
18115 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
18116 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18119 append_composite_glyph (it
)
18122 struct glyph
*glyph
;
18123 enum glyph_row_area area
= it
->area
;
18125 xassert (it
->glyph_row
);
18127 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18128 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18130 glyph
->charpos
= CHARPOS (it
->position
);
18131 glyph
->object
= it
->object
;
18132 glyph
->pixel_width
= it
->pixel_width
;
18133 glyph
->ascent
= it
->ascent
;
18134 glyph
->descent
= it
->descent
;
18135 glyph
->voffset
= it
->voffset
;
18136 glyph
->type
= COMPOSITE_GLYPH
;
18137 glyph
->multibyte_p
= it
->multibyte_p
;
18138 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18139 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18140 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18141 || it
->phys_descent
> it
->descent
);
18142 glyph
->padding_p
= 0;
18143 glyph
->glyph_not_available_p
= 0;
18144 glyph
->face_id
= it
->face_id
;
18145 glyph
->u
.cmp_id
= it
->cmp_id
;
18146 glyph
->slice
= null_glyph_slice
;
18147 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18148 ++it
->glyph_row
->used
[area
];
18153 /* Change IT->ascent and IT->height according to the setting of
18157 take_vertical_position_into_account (it
)
18162 if (it
->voffset
< 0)
18163 /* Increase the ascent so that we can display the text higher
18165 it
->ascent
-= it
->voffset
;
18167 /* Increase the descent so that we can display the text lower
18169 it
->descent
+= it
->voffset
;
18174 /* Produce glyphs/get display metrics for the image IT is loaded with.
18175 See the description of struct display_iterator in dispextern.h for
18176 an overview of struct display_iterator. */
18179 produce_image_glyph (it
)
18184 int face_ascent
, glyph_ascent
;
18185 struct glyph_slice slice
;
18187 xassert (it
->what
== IT_IMAGE
);
18189 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18191 /* Make sure X resources of the face is loaded. */
18192 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18194 if (it
->image_id
< 0)
18196 /* Fringe bitmap. */
18197 it
->ascent
= it
->phys_ascent
= 0;
18198 it
->descent
= it
->phys_descent
= 0;
18199 it
->pixel_width
= 0;
18204 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
18206 /* Make sure X resources of the image is loaded. */
18207 prepare_image_for_display (it
->f
, img
);
18209 slice
.x
= slice
.y
= 0;
18210 slice
.width
= img
->width
;
18211 slice
.height
= img
->height
;
18213 if (INTEGERP (it
->slice
.x
))
18214 slice
.x
= XINT (it
->slice
.x
);
18215 else if (FLOATP (it
->slice
.x
))
18216 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
18218 if (INTEGERP (it
->slice
.y
))
18219 slice
.y
= XINT (it
->slice
.y
);
18220 else if (FLOATP (it
->slice
.y
))
18221 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
18223 if (INTEGERP (it
->slice
.width
))
18224 slice
.width
= XINT (it
->slice
.width
);
18225 else if (FLOATP (it
->slice
.width
))
18226 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
18228 if (INTEGERP (it
->slice
.height
))
18229 slice
.height
= XINT (it
->slice
.height
);
18230 else if (FLOATP (it
->slice
.height
))
18231 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
18233 if (slice
.x
>= img
->width
)
18234 slice
.x
= img
->width
;
18235 if (slice
.y
>= img
->height
)
18236 slice
.y
= img
->height
;
18237 if (slice
.x
+ slice
.width
>= img
->width
)
18238 slice
.width
= img
->width
- slice
.x
;
18239 if (slice
.y
+ slice
.height
> img
->height
)
18240 slice
.height
= img
->height
- slice
.y
;
18242 if (slice
.width
== 0 || slice
.height
== 0)
18245 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
18247 it
->descent
= slice
.height
- glyph_ascent
;
18249 it
->descent
+= img
->vmargin
;
18250 if (slice
.y
+ slice
.height
== img
->height
)
18251 it
->descent
+= img
->vmargin
;
18252 it
->phys_descent
= it
->descent
;
18254 it
->pixel_width
= slice
.width
;
18256 it
->pixel_width
+= img
->hmargin
;
18257 if (slice
.x
+ slice
.width
== img
->width
)
18258 it
->pixel_width
+= img
->hmargin
;
18260 /* It's quite possible for images to have an ascent greater than
18261 their height, so don't get confused in that case. */
18262 if (it
->descent
< 0)
18265 #if 0 /* this breaks image tiling */
18266 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
18267 face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
18268 if (face_ascent
> it
->ascent
)
18269 it
->ascent
= it
->phys_ascent
= face_ascent
;
18274 if (face
->box
!= FACE_NO_BOX
)
18276 if (face
->box_line_width
> 0)
18279 it
->ascent
+= face
->box_line_width
;
18280 if (slice
.y
+ slice
.height
== img
->height
)
18281 it
->descent
+= face
->box_line_width
;
18284 if (it
->start_of_box_run_p
&& slice
.x
== 0)
18285 it
->pixel_width
+= abs (face
->box_line_width
);
18286 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
18287 it
->pixel_width
+= abs (face
->box_line_width
);
18290 take_vertical_position_into_account (it
);
18294 struct glyph
*glyph
;
18295 enum glyph_row_area area
= it
->area
;
18297 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18298 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18300 glyph
->charpos
= CHARPOS (it
->position
);
18301 glyph
->object
= it
->object
;
18302 glyph
->pixel_width
= it
->pixel_width
;
18303 glyph
->ascent
= glyph_ascent
;
18304 glyph
->descent
= it
->descent
;
18305 glyph
->voffset
= it
->voffset
;
18306 glyph
->type
= IMAGE_GLYPH
;
18307 glyph
->multibyte_p
= it
->multibyte_p
;
18308 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18309 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18310 glyph
->overlaps_vertically_p
= 0;
18311 glyph
->padding_p
= 0;
18312 glyph
->glyph_not_available_p
= 0;
18313 glyph
->face_id
= it
->face_id
;
18314 glyph
->u
.img_id
= img
->id
;
18315 glyph
->slice
= slice
;
18316 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18317 ++it
->glyph_row
->used
[area
];
18323 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
18324 of the glyph, WIDTH and HEIGHT are the width and height of the
18325 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
18328 append_stretch_glyph (it
, object
, width
, height
, ascent
)
18330 Lisp_Object object
;
18334 struct glyph
*glyph
;
18335 enum glyph_row_area area
= it
->area
;
18337 xassert (ascent
>= 0 && ascent
<= height
);
18339 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18340 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18342 glyph
->charpos
= CHARPOS (it
->position
);
18343 glyph
->object
= object
;
18344 glyph
->pixel_width
= width
;
18345 glyph
->ascent
= ascent
;
18346 glyph
->descent
= height
- ascent
;
18347 glyph
->voffset
= it
->voffset
;
18348 glyph
->type
= STRETCH_GLYPH
;
18349 glyph
->multibyte_p
= it
->multibyte_p
;
18350 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18351 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18352 glyph
->overlaps_vertically_p
= 0;
18353 glyph
->padding_p
= 0;
18354 glyph
->glyph_not_available_p
= 0;
18355 glyph
->face_id
= it
->face_id
;
18356 glyph
->u
.stretch
.ascent
= ascent
;
18357 glyph
->u
.stretch
.height
= height
;
18358 glyph
->slice
= null_glyph_slice
;
18359 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18360 ++it
->glyph_row
->used
[area
];
18365 /* Produce a stretch glyph for iterator IT. IT->object is the value
18366 of the glyph property displayed. The value must be a list
18367 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
18370 1. `:width WIDTH' specifies that the space should be WIDTH *
18371 canonical char width wide. WIDTH may be an integer or floating
18374 2. `:relative-width FACTOR' specifies that the width of the stretch
18375 should be computed from the width of the first character having the
18376 `glyph' property, and should be FACTOR times that width.
18378 3. `:align-to HPOS' specifies that the space should be wide enough
18379 to reach HPOS, a value in canonical character units.
18381 Exactly one of the above pairs must be present.
18383 4. `:height HEIGHT' specifies that the height of the stretch produced
18384 should be HEIGHT, measured in canonical character units.
18386 5. `:relative-height FACTOR' specifies that the height of the
18387 stretch should be FACTOR times the height of the characters having
18388 the glyph property.
18390 Either none or exactly one of 4 or 5 must be present.
18392 6. `:ascent ASCENT' specifies that ASCENT percent of the height
18393 of the stretch should be used for the ascent of the stretch.
18394 ASCENT must be in the range 0 <= ASCENT <= 100. */
18397 produce_stretch_glyph (it
)
18400 /* (space :width WIDTH :height HEIGHT ...) */
18401 Lisp_Object prop
, plist
;
18402 int width
= 0, height
= 0, align_to
= -1;
18403 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
18406 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18407 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
18409 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18411 /* List should start with `space'. */
18412 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
18413 plist
= XCDR (it
->object
);
18415 /* Compute the width of the stretch. */
18416 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
18417 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
18419 /* Absolute width `:width WIDTH' specified and valid. */
18420 zero_width_ok_p
= 1;
18423 else if (prop
= Fplist_get (plist
, QCrelative_width
),
18426 /* Relative width `:relative-width FACTOR' specified and valid.
18427 Compute the width of the characters having the `glyph'
18430 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
18433 if (it
->multibyte_p
)
18435 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
18436 - IT_BYTEPOS (*it
));
18437 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
18440 it2
.c
= *p
, it2
.len
= 1;
18442 it2
.glyph_row
= NULL
;
18443 it2
.what
= IT_CHARACTER
;
18444 x_produce_glyphs (&it2
);
18445 width
= NUMVAL (prop
) * it2
.pixel_width
;
18447 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
18448 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
18450 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
18451 align_to
= (align_to
< 0
18453 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
18454 else if (align_to
< 0)
18455 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
18456 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
18457 zero_width_ok_p
= 1;
18460 /* Nothing specified -> width defaults to canonical char width. */
18461 width
= FRAME_COLUMN_WIDTH (it
->f
);
18463 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
18466 /* Compute height. */
18467 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
18468 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
18471 zero_height_ok_p
= 1;
18473 else if (prop
= Fplist_get (plist
, QCrelative_height
),
18475 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
18477 height
= FONT_HEIGHT (font
);
18479 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
18482 /* Compute percentage of height used for ascent. If
18483 `:ascent ASCENT' is present and valid, use that. Otherwise,
18484 derive the ascent from the font in use. */
18485 if (prop
= Fplist_get (plist
, QCascent
),
18486 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
18487 ascent
= height
* NUMVAL (prop
) / 100.0;
18488 else if (!NILP (prop
)
18489 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
18490 ascent
= min (max (0, (int)tem
), height
);
18492 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
18494 if (width
> 0 && height
> 0 && it
->glyph_row
)
18496 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
18497 if (!STRINGP (object
))
18498 object
= it
->w
->buffer
;
18499 append_stretch_glyph (it
, object
, width
, height
, ascent
);
18502 it
->pixel_width
= width
;
18503 it
->ascent
= it
->phys_ascent
= ascent
;
18504 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
18505 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
18507 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
18509 if (face
->box_line_width
> 0)
18511 it
->ascent
+= face
->box_line_width
;
18512 it
->descent
+= face
->box_line_width
;
18515 if (it
->start_of_box_run_p
)
18516 it
->pixel_width
+= abs (face
->box_line_width
);
18517 if (it
->end_of_box_run_p
)
18518 it
->pixel_width
+= abs (face
->box_line_width
);
18521 take_vertical_position_into_account (it
);
18524 /* Calculate line-height and line-spacing properties.
18525 An integer value specifies explicit pixel value.
18526 A float value specifies relative value to current face height.
18527 A cons (float . face-name) specifies relative value to
18528 height of specified face font.
18530 Returns height in pixels, or nil. */
18533 calc_line_height_property (it
, prop
, font
, boff
, total
)
18539 Lisp_Object position
, val
;
18540 Lisp_Object face_name
= Qnil
;
18541 int ascent
, descent
, height
, override
;
18543 if (STRINGP (it
->object
))
18544 position
= make_number (IT_STRING_CHARPOS (*it
));
18546 position
= make_number (IT_CHARPOS (*it
));
18548 val
= Fget_char_property (position
, prop
, it
->object
);
18553 if (total
&& CONSP (val
) && EQ (XCAR (val
), Qtotal
))
18559 if (INTEGERP (val
))
18564 face_name
= XCDR (val
);
18567 else if (SYMBOLP (val
))
18573 override
= EQ (prop
, Qline_height
);
18575 if (NILP (face_name
))
18577 font
= FRAME_FONT (it
->f
);
18578 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18580 else if (EQ (face_name
, Qt
))
18588 struct font_info
*font_info
;
18590 face_id
= lookup_named_face (it
->f
, face_name
, ' ');
18592 return make_number (-1);
18594 face
= FACE_FROM_ID (it
->f
, face_id
);
18597 return make_number (-1);
18599 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18600 boff
= font_info
->baseline_offset
;
18601 if (font_info
->vertical_centering
)
18602 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18605 ascent
= FONT_BASE (font
) + boff
;
18606 descent
= FONT_DESCENT (font
) - boff
;
18610 it
->override_ascent
= ascent
;
18611 it
->override_descent
= descent
;
18612 it
->override_boff
= boff
;
18615 height
= ascent
+ descent
;
18617 height
= (int)(XFLOAT_DATA (val
) * height
);
18618 else if (INTEGERP (val
))
18619 height
*= XINT (val
);
18621 return make_number (height
);
18626 Produce glyphs/get display metrics for the display element IT is
18627 loaded with. See the description of struct display_iterator in
18628 dispextern.h for an overview of struct display_iterator. */
18631 x_produce_glyphs (it
)
18634 int extra_line_spacing
= it
->extra_line_spacing
;
18636 it
->glyph_not_available_p
= 0;
18638 if (it
->what
== IT_CHARACTER
)
18642 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18644 int font_not_found_p
;
18645 struct font_info
*font_info
;
18646 int boff
; /* baseline offset */
18647 /* We may change it->multibyte_p upon unibyte<->multibyte
18648 conversion. So, save the current value now and restore it
18651 Note: It seems that we don't have to record multibyte_p in
18652 struct glyph because the character code itself tells if or
18653 not the character is multibyte. Thus, in the future, we must
18654 consider eliminating the field `multibyte_p' in the struct
18656 int saved_multibyte_p
= it
->multibyte_p
;
18658 /* Maybe translate single-byte characters to multibyte, or the
18660 it
->char_to_display
= it
->c
;
18661 if (!ASCII_BYTE_P (it
->c
))
18663 if (unibyte_display_via_language_environment
18664 && SINGLE_BYTE_CHAR_P (it
->c
)
18666 || !NILP (Vnonascii_translation_table
)))
18668 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
18669 it
->multibyte_p
= 1;
18670 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18671 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18673 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
18674 && !it
->multibyte_p
)
18676 it
->multibyte_p
= 1;
18677 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18678 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18682 /* Get font to use. Encode IT->char_to_display. */
18683 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
18684 &char2b
, it
->multibyte_p
, 0);
18687 /* When no suitable font found, use the default font. */
18688 font_not_found_p
= font
== NULL
;
18689 if (font_not_found_p
)
18691 font
= FRAME_FONT (it
->f
);
18692 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18697 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18698 boff
= font_info
->baseline_offset
;
18699 if (font_info
->vertical_centering
)
18700 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18703 if (it
->char_to_display
>= ' '
18704 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
18706 /* Either unibyte or ASCII. */
18711 pcm
= rif
->per_char_metric (font
, &char2b
,
18712 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
18714 if (it
->override_ascent
>= 0)
18716 it
->ascent
= it
->override_ascent
;
18717 it
->descent
= it
->override_descent
;
18718 boff
= it
->override_boff
;
18722 it
->ascent
= FONT_BASE (font
) + boff
;
18723 it
->descent
= FONT_DESCENT (font
) - boff
;
18728 it
->phys_ascent
= pcm
->ascent
+ boff
;
18729 it
->phys_descent
= pcm
->descent
- boff
;
18730 it
->pixel_width
= pcm
->width
;
18734 it
->glyph_not_available_p
= 1;
18735 it
->phys_ascent
= it
->ascent
;
18736 it
->phys_descent
= it
->descent
;
18737 it
->pixel_width
= FONT_WIDTH (font
);
18740 if (it
->constrain_row_ascent_descent_p
)
18742 if (it
->descent
> it
->max_descent
)
18744 it
->ascent
+= it
->descent
- it
->max_descent
;
18745 it
->descent
= it
->max_descent
;
18747 if (it
->ascent
> it
->max_ascent
)
18749 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
18750 it
->ascent
= it
->max_ascent
;
18752 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
18753 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
18754 extra_line_spacing
= 0;
18757 /* If this is a space inside a region of text with
18758 `space-width' property, change its width. */
18759 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
18761 it
->pixel_width
*= XFLOATINT (it
->space_width
);
18763 /* If face has a box, add the box thickness to the character
18764 height. If character has a box line to the left and/or
18765 right, add the box line width to the character's width. */
18766 if (face
->box
!= FACE_NO_BOX
)
18768 int thick
= face
->box_line_width
;
18772 it
->ascent
+= thick
;
18773 it
->descent
+= thick
;
18778 if (it
->start_of_box_run_p
)
18779 it
->pixel_width
+= thick
;
18780 if (it
->end_of_box_run_p
)
18781 it
->pixel_width
+= thick
;
18784 /* If face has an overline, add the height of the overline
18785 (1 pixel) and a 1 pixel margin to the character height. */
18786 if (face
->overline_p
)
18789 if (it
->constrain_row_ascent_descent_p
)
18791 if (it
->ascent
> it
->max_ascent
)
18792 it
->ascent
= it
->max_ascent
;
18793 if (it
->descent
> it
->max_descent
)
18794 it
->descent
= it
->max_descent
;
18797 take_vertical_position_into_account (it
);
18799 /* If we have to actually produce glyphs, do it. */
18804 /* Translate a space with a `space-width' property
18805 into a stretch glyph. */
18806 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
18807 / FONT_HEIGHT (font
));
18808 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
18809 it
->ascent
+ it
->descent
, ascent
);
18814 /* If characters with lbearing or rbearing are displayed
18815 in this line, record that fact in a flag of the
18816 glyph row. This is used to optimize X output code. */
18817 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
18818 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
18821 else if (it
->char_to_display
== '\n')
18823 /* A newline has no width but we need the height of the line.
18824 But if previous part of the line set a height, don't
18825 increase that height */
18827 Lisp_Object height
;
18829 it
->override_ascent
= -1;
18830 it
->pixel_width
= 0;
18833 height
= calc_line_height_property(it
, Qline_height
, font
, boff
, 0);
18835 if (it
->override_ascent
>= 0)
18837 it
->ascent
= it
->override_ascent
;
18838 it
->descent
= it
->override_descent
;
18839 boff
= it
->override_boff
;
18843 it
->ascent
= FONT_BASE (font
) + boff
;
18844 it
->descent
= FONT_DESCENT (font
) - boff
;
18847 if (EQ (height
, make_number(0)))
18849 if (it
->descent
> it
->max_descent
)
18851 it
->ascent
+= it
->descent
- it
->max_descent
;
18852 it
->descent
= it
->max_descent
;
18854 if (it
->ascent
> it
->max_ascent
)
18856 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
18857 it
->ascent
= it
->max_ascent
;
18859 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
18860 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
18861 it
->constrain_row_ascent_descent_p
= 1;
18862 extra_line_spacing
= 0;
18866 Lisp_Object spacing
;
18869 it
->phys_ascent
= it
->ascent
;
18870 it
->phys_descent
= it
->descent
;
18872 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
18873 && face
->box
!= FACE_NO_BOX
18874 && face
->box_line_width
> 0)
18876 it
->ascent
+= face
->box_line_width
;
18877 it
->descent
+= face
->box_line_width
;
18880 && XINT (height
) > it
->ascent
+ it
->descent
)
18881 it
->ascent
= XINT (height
) - it
->descent
;
18883 spacing
= calc_line_height_property(it
, Qline_spacing
, font
, boff
, &total
);
18884 if (INTEGERP (spacing
))
18886 extra_line_spacing
= XINT (spacing
);
18888 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
18892 else if (it
->char_to_display
== '\t')
18894 int tab_width
= it
->tab_width
* FRAME_COLUMN_WIDTH (it
->f
);
18895 int x
= it
->current_x
+ it
->continuation_lines_width
;
18896 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
18898 /* If the distance from the current position to the next tab
18899 stop is less than a canonical character width, use the
18900 tab stop after that. */
18901 if (next_tab_x
- x
< FRAME_COLUMN_WIDTH (it
->f
))
18902 next_tab_x
+= tab_width
;
18904 it
->pixel_width
= next_tab_x
- x
;
18906 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
18907 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18911 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
18912 it
->ascent
+ it
->descent
, it
->ascent
);
18917 /* A multi-byte character. Assume that the display width of the
18918 character is the width of the character multiplied by the
18919 width of the font. */
18921 /* If we found a font, this font should give us the right
18922 metrics. If we didn't find a font, use the frame's
18923 default font and calculate the width of the character
18924 from the charset width; this is what old redisplay code
18927 pcm
= rif
->per_char_metric (font
, &char2b
,
18928 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
18930 if (font_not_found_p
|| !pcm
)
18932 int charset
= CHAR_CHARSET (it
->char_to_display
);
18934 it
->glyph_not_available_p
= 1;
18935 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
18936 * CHARSET_WIDTH (charset
));
18937 it
->phys_ascent
= FONT_BASE (font
) + boff
;
18938 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18942 it
->pixel_width
= pcm
->width
;
18943 it
->phys_ascent
= pcm
->ascent
+ boff
;
18944 it
->phys_descent
= pcm
->descent
- boff
;
18946 && (pcm
->lbearing
< 0
18947 || pcm
->rbearing
> pcm
->width
))
18948 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
18951 it
->ascent
= FONT_BASE (font
) + boff
;
18952 it
->descent
= FONT_DESCENT (font
) - boff
;
18953 if (face
->box
!= FACE_NO_BOX
)
18955 int thick
= face
->box_line_width
;
18959 it
->ascent
+= thick
;
18960 it
->descent
+= thick
;
18965 if (it
->start_of_box_run_p
)
18966 it
->pixel_width
+= thick
;
18967 if (it
->end_of_box_run_p
)
18968 it
->pixel_width
+= thick
;
18971 /* If face has an overline, add the height of the overline
18972 (1 pixel) and a 1 pixel margin to the character height. */
18973 if (face
->overline_p
)
18976 take_vertical_position_into_account (it
);
18981 it
->multibyte_p
= saved_multibyte_p
;
18983 else if (it
->what
== IT_COMPOSITION
)
18985 /* Note: A composition is represented as one glyph in the
18986 glyph matrix. There are no padding glyphs. */
18989 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18991 int font_not_found_p
;
18992 struct font_info
*font_info
;
18993 int boff
; /* baseline offset */
18994 struct composition
*cmp
= composition_table
[it
->cmp_id
];
18996 /* Maybe translate single-byte characters to multibyte. */
18997 it
->char_to_display
= it
->c
;
18998 if (unibyte_display_via_language_environment
18999 && SINGLE_BYTE_CHAR_P (it
->c
)
19002 && !NILP (Vnonascii_translation_table
))))
19004 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19007 /* Get face and font to use. Encode IT->char_to_display. */
19008 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19009 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19010 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19011 &char2b
, it
->multibyte_p
, 0);
19014 /* When no suitable font found, use the default font. */
19015 font_not_found_p
= font
== NULL
;
19016 if (font_not_found_p
)
19018 font
= FRAME_FONT (it
->f
);
19019 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19024 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19025 boff
= font_info
->baseline_offset
;
19026 if (font_info
->vertical_centering
)
19027 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19030 /* There are no padding glyphs, so there is only one glyph to
19031 produce for the composition. Important is that pixel_width,
19032 ascent and descent are the values of what is drawn by
19033 draw_glyphs (i.e. the values of the overall glyphs composed). */
19036 /* If we have not yet calculated pixel size data of glyphs of
19037 the composition for the current face font, calculate them
19038 now. Theoretically, we have to check all fonts for the
19039 glyphs, but that requires much time and memory space. So,
19040 here we check only the font of the first glyph. This leads
19041 to incorrect display very rarely, and C-l (recenter) can
19042 correct the display anyway. */
19043 if (cmp
->font
!= (void *) font
)
19045 /* Ascent and descent of the font of the first character of
19046 this composition (adjusted by baseline offset). Ascent
19047 and descent of overall glyphs should not be less than
19048 them respectively. */
19049 int font_ascent
= FONT_BASE (font
) + boff
;
19050 int font_descent
= FONT_DESCENT (font
) - boff
;
19051 /* Bounding box of the overall glyphs. */
19052 int leftmost
, rightmost
, lowest
, highest
;
19053 int i
, width
, ascent
, descent
;
19055 cmp
->font
= (void *) font
;
19057 /* Initialize the bounding box. */
19059 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19060 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
19062 width
= pcm
->width
;
19063 ascent
= pcm
->ascent
;
19064 descent
= pcm
->descent
;
19068 width
= FONT_WIDTH (font
);
19069 ascent
= FONT_BASE (font
);
19070 descent
= FONT_DESCENT (font
);
19074 lowest
= - descent
+ boff
;
19075 highest
= ascent
+ boff
;
19079 && font_info
->default_ascent
19080 && CHAR_TABLE_P (Vuse_default_ascent
)
19081 && !NILP (Faref (Vuse_default_ascent
,
19082 make_number (it
->char_to_display
))))
19083 highest
= font_info
->default_ascent
+ boff
;
19085 /* Draw the first glyph at the normal position. It may be
19086 shifted to right later if some other glyphs are drawn at
19088 cmp
->offsets
[0] = 0;
19089 cmp
->offsets
[1] = boff
;
19091 /* Set cmp->offsets for the remaining glyphs. */
19092 for (i
= 1; i
< cmp
->glyph_len
; i
++)
19094 int left
, right
, btm
, top
;
19095 int ch
= COMPOSITION_GLYPH (cmp
, i
);
19096 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
19098 face
= FACE_FROM_ID (it
->f
, face_id
);
19099 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
19100 &char2b
, it
->multibyte_p
, 0);
19104 font
= FRAME_FONT (it
->f
);
19105 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19111 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19112 boff
= font_info
->baseline_offset
;
19113 if (font_info
->vertical_centering
)
19114 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19118 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19119 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
19121 width
= pcm
->width
;
19122 ascent
= pcm
->ascent
;
19123 descent
= pcm
->descent
;
19127 width
= FONT_WIDTH (font
);
19132 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
19134 /* Relative composition with or without
19135 alternate chars. */
19136 left
= (leftmost
+ rightmost
- width
) / 2;
19137 btm
= - descent
+ boff
;
19138 if (font_info
&& font_info
->relative_compose
19139 && (! CHAR_TABLE_P (Vignore_relative_composition
)
19140 || NILP (Faref (Vignore_relative_composition
,
19141 make_number (ch
)))))
19144 if (- descent
>= font_info
->relative_compose
)
19145 /* One extra pixel between two glyphs. */
19147 else if (ascent
<= 0)
19148 /* One extra pixel between two glyphs. */
19149 btm
= lowest
- 1 - ascent
- descent
;
19154 /* A composition rule is specified by an integer
19155 value that encodes global and new reference
19156 points (GREF and NREF). GREF and NREF are
19157 specified by numbers as below:
19159 0---1---2 -- ascent
19163 9--10--11 -- center
19165 ---3---4---5--- baseline
19167 6---7---8 -- descent
19169 int rule
= COMPOSITION_RULE (cmp
, i
);
19170 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
19172 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
19173 grefx
= gref
% 3, nrefx
= nref
% 3;
19174 grefy
= gref
/ 3, nrefy
= nref
/ 3;
19177 + grefx
* (rightmost
- leftmost
) / 2
19178 - nrefx
* width
/ 2);
19179 btm
= ((grefy
== 0 ? highest
19181 : grefy
== 2 ? lowest
19182 : (highest
+ lowest
) / 2)
19183 - (nrefy
== 0 ? ascent
+ descent
19184 : nrefy
== 1 ? descent
- boff
19186 : (ascent
+ descent
) / 2));
19189 cmp
->offsets
[i
* 2] = left
;
19190 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
19192 /* Update the bounding box of the overall glyphs. */
19193 right
= left
+ width
;
19194 top
= btm
+ descent
+ ascent
;
19195 if (left
< leftmost
)
19197 if (right
> rightmost
)
19205 /* If there are glyphs whose x-offsets are negative,
19206 shift all glyphs to the right and make all x-offsets
19210 for (i
= 0; i
< cmp
->glyph_len
; i
++)
19211 cmp
->offsets
[i
* 2] -= leftmost
;
19212 rightmost
-= leftmost
;
19215 cmp
->pixel_width
= rightmost
;
19216 cmp
->ascent
= highest
;
19217 cmp
->descent
= - lowest
;
19218 if (cmp
->ascent
< font_ascent
)
19219 cmp
->ascent
= font_ascent
;
19220 if (cmp
->descent
< font_descent
)
19221 cmp
->descent
= font_descent
;
19224 it
->pixel_width
= cmp
->pixel_width
;
19225 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
19226 it
->descent
= it
->phys_descent
= cmp
->descent
;
19228 if (face
->box
!= FACE_NO_BOX
)
19230 int thick
= face
->box_line_width
;
19234 it
->ascent
+= thick
;
19235 it
->descent
+= thick
;
19240 if (it
->start_of_box_run_p
)
19241 it
->pixel_width
+= thick
;
19242 if (it
->end_of_box_run_p
)
19243 it
->pixel_width
+= thick
;
19246 /* If face has an overline, add the height of the overline
19247 (1 pixel) and a 1 pixel margin to the character height. */
19248 if (face
->overline_p
)
19251 take_vertical_position_into_account (it
);
19254 append_composite_glyph (it
);
19256 else if (it
->what
== IT_IMAGE
)
19257 produce_image_glyph (it
);
19258 else if (it
->what
== IT_STRETCH
)
19259 produce_stretch_glyph (it
);
19261 /* Accumulate dimensions. Note: can't assume that it->descent > 0
19262 because this isn't true for images with `:ascent 100'. */
19263 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
19264 if (it
->area
== TEXT_AREA
)
19265 it
->current_x
+= it
->pixel_width
;
19267 if (extra_line_spacing
> 0)
19268 it
->descent
+= extra_line_spacing
;
19270 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
19271 it
->max_descent
= max (it
->max_descent
, it
->descent
);
19272 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
19273 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
19277 Output LEN glyphs starting at START at the nominal cursor position.
19278 Advance the nominal cursor over the text. The global variable
19279 updated_window contains the window being updated, updated_row is
19280 the glyph row being updated, and updated_area is the area of that
19281 row being updated. */
19284 x_write_glyphs (start
, len
)
19285 struct glyph
*start
;
19290 xassert (updated_window
&& updated_row
);
19293 /* Write glyphs. */
19295 hpos
= start
- updated_row
->glyphs
[updated_area
];
19296 x
= draw_glyphs (updated_window
, output_cursor
.x
,
19297 updated_row
, updated_area
,
19299 DRAW_NORMAL_TEXT
, 0);
19301 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
19302 if (updated_area
== TEXT_AREA
19303 && updated_window
->phys_cursor_on_p
19304 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
19305 && updated_window
->phys_cursor
.hpos
>= hpos
19306 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
19307 updated_window
->phys_cursor_on_p
= 0;
19311 /* Advance the output cursor. */
19312 output_cursor
.hpos
+= len
;
19313 output_cursor
.x
= x
;
19318 Insert LEN glyphs from START at the nominal cursor position. */
19321 x_insert_glyphs (start
, len
)
19322 struct glyph
*start
;
19327 int line_height
, shift_by_width
, shifted_region_width
;
19328 struct glyph_row
*row
;
19329 struct glyph
*glyph
;
19330 int frame_x
, frame_y
, hpos
;
19332 xassert (updated_window
&& updated_row
);
19334 w
= updated_window
;
19335 f
= XFRAME (WINDOW_FRAME (w
));
19337 /* Get the height of the line we are in. */
19339 line_height
= row
->height
;
19341 /* Get the width of the glyphs to insert. */
19342 shift_by_width
= 0;
19343 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
19344 shift_by_width
+= glyph
->pixel_width
;
19346 /* Get the width of the region to shift right. */
19347 shifted_region_width
= (window_box_width (w
, updated_area
)
19352 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
19353 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
19355 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
19356 line_height
, shift_by_width
);
19358 /* Write the glyphs. */
19359 hpos
= start
- row
->glyphs
[updated_area
];
19360 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
19362 DRAW_NORMAL_TEXT
, 0);
19364 /* Advance the output cursor. */
19365 output_cursor
.hpos
+= len
;
19366 output_cursor
.x
+= shift_by_width
;
19372 Erase the current text line from the nominal cursor position
19373 (inclusive) to pixel column TO_X (exclusive). The idea is that
19374 everything from TO_X onward is already erased.
19376 TO_X is a pixel position relative to updated_area of
19377 updated_window. TO_X == -1 means clear to the end of this area. */
19380 x_clear_end_of_line (to_x
)
19384 struct window
*w
= updated_window
;
19385 int max_x
, min_y
, max_y
;
19386 int from_x
, from_y
, to_y
;
19388 xassert (updated_window
&& updated_row
);
19389 f
= XFRAME (w
->frame
);
19391 if (updated_row
->full_width_p
)
19392 max_x
= WINDOW_TOTAL_WIDTH (w
);
19394 max_x
= window_box_width (w
, updated_area
);
19395 max_y
= window_text_bottom_y (w
);
19397 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
19398 of window. For TO_X > 0, truncate to end of drawing area. */
19404 to_x
= min (to_x
, max_x
);
19406 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
19408 /* Notice if the cursor will be cleared by this operation. */
19409 if (!updated_row
->full_width_p
)
19410 notice_overwritten_cursor (w
, updated_area
,
19411 output_cursor
.x
, -1,
19413 MATRIX_ROW_BOTTOM_Y (updated_row
));
19415 from_x
= output_cursor
.x
;
19417 /* Translate to frame coordinates. */
19418 if (updated_row
->full_width_p
)
19420 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
19421 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
19425 int area_left
= window_box_left (w
, updated_area
);
19426 from_x
+= area_left
;
19430 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
19431 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
19432 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
19434 /* Prevent inadvertently clearing to end of the X window. */
19435 if (to_x
> from_x
&& to_y
> from_y
)
19438 rif
->clear_frame_area (f
, from_x
, from_y
,
19439 to_x
- from_x
, to_y
- from_y
);
19444 #endif /* HAVE_WINDOW_SYSTEM */
19448 /***********************************************************************
19450 ***********************************************************************/
19452 /* Value is the internal representation of the specified cursor type
19453 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
19454 of the bar cursor. */
19456 static enum text_cursor_kinds
19457 get_specified_cursor_type (arg
, width
)
19461 enum text_cursor_kinds type
;
19466 if (EQ (arg
, Qbox
))
19467 return FILLED_BOX_CURSOR
;
19469 if (EQ (arg
, Qhollow
))
19470 return HOLLOW_BOX_CURSOR
;
19472 if (EQ (arg
, Qbar
))
19479 && EQ (XCAR (arg
), Qbar
)
19480 && INTEGERP (XCDR (arg
))
19481 && XINT (XCDR (arg
)) >= 0)
19483 *width
= XINT (XCDR (arg
));
19487 if (EQ (arg
, Qhbar
))
19490 return HBAR_CURSOR
;
19494 && EQ (XCAR (arg
), Qhbar
)
19495 && INTEGERP (XCDR (arg
))
19496 && XINT (XCDR (arg
)) >= 0)
19498 *width
= XINT (XCDR (arg
));
19499 return HBAR_CURSOR
;
19502 /* Treat anything unknown as "hollow box cursor".
19503 It was bad to signal an error; people have trouble fixing
19504 .Xdefaults with Emacs, when it has something bad in it. */
19505 type
= HOLLOW_BOX_CURSOR
;
19510 /* Set the default cursor types for specified frame. */
19512 set_frame_cursor_types (f
, arg
)
19519 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
19520 FRAME_CURSOR_WIDTH (f
) = width
;
19522 /* By default, set up the blink-off state depending on the on-state. */
19524 tem
= Fassoc (arg
, Vblink_cursor_alist
);
19527 FRAME_BLINK_OFF_CURSOR (f
)
19528 = get_specified_cursor_type (XCDR (tem
), &width
);
19529 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
19532 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
19536 /* Return the cursor we want to be displayed in window W. Return
19537 width of bar/hbar cursor through WIDTH arg. Return with
19538 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
19539 (i.e. if the `system caret' should track this cursor).
19541 In a mini-buffer window, we want the cursor only to appear if we
19542 are reading input from this window. For the selected window, we
19543 want the cursor type given by the frame parameter or buffer local
19544 setting of cursor-type. If explicitly marked off, draw no cursor.
19545 In all other cases, we want a hollow box cursor. */
19547 static enum text_cursor_kinds
19548 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
19550 struct glyph
*glyph
;
19552 int *active_cursor
;
19554 struct frame
*f
= XFRAME (w
->frame
);
19555 struct buffer
*b
= XBUFFER (w
->buffer
);
19556 int cursor_type
= DEFAULT_CURSOR
;
19557 Lisp_Object alt_cursor
;
19558 int non_selected
= 0;
19560 *active_cursor
= 1;
19563 if (cursor_in_echo_area
19564 && FRAME_HAS_MINIBUF_P (f
)
19565 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
19567 if (w
== XWINDOW (echo_area_window
))
19569 *width
= FRAME_CURSOR_WIDTH (f
);
19570 return FRAME_DESIRED_CURSOR (f
);
19573 *active_cursor
= 0;
19577 /* Nonselected window or nonselected frame. */
19578 else if (w
!= XWINDOW (f
->selected_window
)
19579 #ifdef HAVE_WINDOW_SYSTEM
19580 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
19584 *active_cursor
= 0;
19586 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
19592 /* Never display a cursor in a window in which cursor-type is nil. */
19593 if (NILP (b
->cursor_type
))
19596 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
19599 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
19600 return get_specified_cursor_type (alt_cursor
, width
);
19603 /* Get the normal cursor type for this window. */
19604 if (EQ (b
->cursor_type
, Qt
))
19606 cursor_type
= FRAME_DESIRED_CURSOR (f
);
19607 *width
= FRAME_CURSOR_WIDTH (f
);
19610 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
19612 /* Use normal cursor if not blinked off. */
19613 if (!w
->cursor_off_p
)
19615 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
19616 if (cursor_type
== FILLED_BOX_CURSOR
)
19617 cursor_type
= HOLLOW_BOX_CURSOR
;
19619 return cursor_type
;
19622 /* Cursor is blinked off, so determine how to "toggle" it. */
19624 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
19625 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
19626 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
19628 /* Then see if frame has specified a specific blink off cursor type. */
19629 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
19631 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
19632 return FRAME_BLINK_OFF_CURSOR (f
);
19636 /* Some people liked having a permanently visible blinking cursor,
19637 while others had very strong opinions against it. So it was
19638 decided to remove it. KFS 2003-09-03 */
19640 /* Finally perform built-in cursor blinking:
19641 filled box <-> hollow box
19642 wide [h]bar <-> narrow [h]bar
19643 narrow [h]bar <-> no cursor
19644 other type <-> no cursor */
19646 if (cursor_type
== FILLED_BOX_CURSOR
)
19647 return HOLLOW_BOX_CURSOR
;
19649 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
19652 return cursor_type
;
19660 #ifdef HAVE_WINDOW_SYSTEM
19662 /* Notice when the text cursor of window W has been completely
19663 overwritten by a drawing operation that outputs glyphs in AREA
19664 starting at X0 and ending at X1 in the line starting at Y0 and
19665 ending at Y1. X coordinates are area-relative. X1 < 0 means all
19666 the rest of the line after X0 has been written. Y coordinates
19667 are window-relative. */
19670 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
19672 enum glyph_row_area area
;
19673 int x0
, y0
, x1
, y1
;
19675 int cx0
, cx1
, cy0
, cy1
;
19676 struct glyph_row
*row
;
19678 if (!w
->phys_cursor_on_p
)
19680 if (area
!= TEXT_AREA
)
19683 row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
;
19684 if (!row
->displays_text_p
)
19687 if (row
->cursor_in_fringe_p
)
19689 row
->cursor_in_fringe_p
= 0;
19690 draw_fringe_bitmap (w
, row
, 0);
19691 w
->phys_cursor_on_p
= 0;
19695 cx0
= w
->phys_cursor
.x
;
19696 cx1
= cx0
+ w
->phys_cursor_width
;
19697 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
19700 /* The cursor image will be completely removed from the
19701 screen if the output area intersects the cursor area in
19702 y-direction. When we draw in [y0 y1[, and some part of
19703 the cursor is at y < y0, that part must have been drawn
19704 before. When scrolling, the cursor is erased before
19705 actually scrolling, so we don't come here. When not
19706 scrolling, the rows above the old cursor row must have
19707 changed, and in this case these rows must have written
19708 over the cursor image.
19710 Likewise if part of the cursor is below y1, with the
19711 exception of the cursor being in the first blank row at
19712 the buffer and window end because update_text_area
19713 doesn't draw that row. (Except when it does, but
19714 that's handled in update_text_area.) */
19716 cy0
= w
->phys_cursor
.y
;
19717 cy1
= cy0
+ w
->phys_cursor_height
;
19718 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
19721 w
->phys_cursor_on_p
= 0;
19724 #endif /* HAVE_WINDOW_SYSTEM */
19727 /************************************************************************
19729 ************************************************************************/
19731 #ifdef HAVE_WINDOW_SYSTEM
19734 Fix the display of area AREA of overlapping row ROW in window W. */
19737 x_fix_overlapping_area (w
, row
, area
)
19739 struct glyph_row
*row
;
19740 enum glyph_row_area area
;
19747 for (i
= 0; i
< row
->used
[area
];)
19749 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
19751 int start
= i
, start_x
= x
;
19755 x
+= row
->glyphs
[area
][i
].pixel_width
;
19758 while (i
< row
->used
[area
]
19759 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
19761 draw_glyphs (w
, start_x
, row
, area
,
19763 DRAW_NORMAL_TEXT
, 1);
19767 x
+= row
->glyphs
[area
][i
].pixel_width
;
19777 Draw the cursor glyph of window W in glyph row ROW. See the
19778 comment of draw_glyphs for the meaning of HL. */
19781 draw_phys_cursor_glyph (w
, row
, hl
)
19783 struct glyph_row
*row
;
19784 enum draw_glyphs_face hl
;
19786 /* If cursor hpos is out of bounds, don't draw garbage. This can
19787 happen in mini-buffer windows when switching between echo area
19788 glyphs and mini-buffer. */
19789 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
19791 int on_p
= w
->phys_cursor_on_p
;
19793 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
19794 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
19796 w
->phys_cursor_on_p
= on_p
;
19798 if (hl
== DRAW_CURSOR
)
19799 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
19800 /* When we erase the cursor, and ROW is overlapped by other
19801 rows, make sure that these overlapping parts of other rows
19803 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
19805 if (row
> w
->current_matrix
->rows
19806 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
19807 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
19809 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
19810 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
19811 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
19818 Erase the image of a cursor of window W from the screen. */
19821 erase_phys_cursor (w
)
19824 struct frame
*f
= XFRAME (w
->frame
);
19825 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
19826 int hpos
= w
->phys_cursor
.hpos
;
19827 int vpos
= w
->phys_cursor
.vpos
;
19828 int mouse_face_here_p
= 0;
19829 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
19830 struct glyph_row
*cursor_row
;
19831 struct glyph
*cursor_glyph
;
19832 enum draw_glyphs_face hl
;
19834 /* No cursor displayed or row invalidated => nothing to do on the
19836 if (w
->phys_cursor_type
== NO_CURSOR
)
19837 goto mark_cursor_off
;
19839 /* VPOS >= active_glyphs->nrows means that window has been resized.
19840 Don't bother to erase the cursor. */
19841 if (vpos
>= active_glyphs
->nrows
)
19842 goto mark_cursor_off
;
19844 /* If row containing cursor is marked invalid, there is nothing we
19846 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
19847 if (!cursor_row
->enabled_p
)
19848 goto mark_cursor_off
;
19850 /* If row is completely invisible, don't attempt to delete a cursor which
19851 isn't there. This can happen if cursor is at top of a window, and
19852 we switch to a buffer with a header line in that window. */
19853 if (cursor_row
->visible_height
<= 0)
19854 goto mark_cursor_off
;
19856 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
19857 if (cursor_row
->cursor_in_fringe_p
)
19859 cursor_row
->cursor_in_fringe_p
= 0;
19860 draw_fringe_bitmap (w
, cursor_row
, 0);
19861 goto mark_cursor_off
;
19864 /* This can happen when the new row is shorter than the old one.
19865 In this case, either draw_glyphs or clear_end_of_line
19866 should have cleared the cursor. Note that we wouldn't be
19867 able to erase the cursor in this case because we don't have a
19868 cursor glyph at hand. */
19869 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
19870 goto mark_cursor_off
;
19872 /* If the cursor is in the mouse face area, redisplay that when
19873 we clear the cursor. */
19874 if (! NILP (dpyinfo
->mouse_face_window
)
19875 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
19876 && (vpos
> dpyinfo
->mouse_face_beg_row
19877 || (vpos
== dpyinfo
->mouse_face_beg_row
19878 && hpos
>= dpyinfo
->mouse_face_beg_col
))
19879 && (vpos
< dpyinfo
->mouse_face_end_row
19880 || (vpos
== dpyinfo
->mouse_face_end_row
19881 && hpos
< dpyinfo
->mouse_face_end_col
))
19882 /* Don't redraw the cursor's spot in mouse face if it is at the
19883 end of a line (on a newline). The cursor appears there, but
19884 mouse highlighting does not. */
19885 && cursor_row
->used
[TEXT_AREA
] > hpos
)
19886 mouse_face_here_p
= 1;
19888 /* Maybe clear the display under the cursor. */
19889 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
19892 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
19894 cursor_glyph
= get_phys_cursor_glyph (w
);
19895 if (cursor_glyph
== NULL
)
19896 goto mark_cursor_off
;
19898 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
19899 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
19901 rif
->clear_frame_area (f
, x
, y
,
19902 cursor_glyph
->pixel_width
, cursor_row
->visible_height
);
19905 /* Erase the cursor by redrawing the character underneath it. */
19906 if (mouse_face_here_p
)
19907 hl
= DRAW_MOUSE_FACE
;
19909 hl
= DRAW_NORMAL_TEXT
;
19910 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
19913 w
->phys_cursor_on_p
= 0;
19914 w
->phys_cursor_type
= NO_CURSOR
;
19919 Display or clear cursor of window W. If ON is zero, clear the
19920 cursor. If it is non-zero, display the cursor. If ON is nonzero,
19921 where to put the cursor is specified by HPOS, VPOS, X and Y. */
19924 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
19926 int on
, hpos
, vpos
, x
, y
;
19928 struct frame
*f
= XFRAME (w
->frame
);
19929 int new_cursor_type
;
19930 int new_cursor_width
;
19932 struct glyph_row
*glyph_row
;
19933 struct glyph
*glyph
;
19935 /* This is pointless on invisible frames, and dangerous on garbaged
19936 windows and frames; in the latter case, the frame or window may
19937 be in the midst of changing its size, and x and y may be off the
19939 if (! FRAME_VISIBLE_P (f
)
19940 || FRAME_GARBAGED_P (f
)
19941 || vpos
>= w
->current_matrix
->nrows
19942 || hpos
>= w
->current_matrix
->matrix_w
)
19945 /* If cursor is off and we want it off, return quickly. */
19946 if (!on
&& !w
->phys_cursor_on_p
)
19949 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
19950 /* If cursor row is not enabled, we don't really know where to
19951 display the cursor. */
19952 if (!glyph_row
->enabled_p
)
19954 w
->phys_cursor_on_p
= 0;
19959 if (!glyph_row
->exact_window_width_line_p
19960 || hpos
< glyph_row
->used
[TEXT_AREA
])
19961 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
19963 xassert (interrupt_input_blocked
);
19965 /* Set new_cursor_type to the cursor we want to be displayed. */
19966 new_cursor_type
= get_window_cursor_type (w
, glyph
,
19967 &new_cursor_width
, &active_cursor
);
19969 /* If cursor is currently being shown and we don't want it to be or
19970 it is in the wrong place, or the cursor type is not what we want,
19972 if (w
->phys_cursor_on_p
19974 || w
->phys_cursor
.x
!= x
19975 || w
->phys_cursor
.y
!= y
19976 || new_cursor_type
!= w
->phys_cursor_type
19977 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
19978 && new_cursor_width
!= w
->phys_cursor_width
)))
19979 erase_phys_cursor (w
);
19981 /* Don't check phys_cursor_on_p here because that flag is only set
19982 to zero in some cases where we know that the cursor has been
19983 completely erased, to avoid the extra work of erasing the cursor
19984 twice. In other words, phys_cursor_on_p can be 1 and the cursor
19985 still not be visible, or it has only been partly erased. */
19988 w
->phys_cursor_ascent
= glyph_row
->ascent
;
19989 w
->phys_cursor_height
= glyph_row
->height
;
19991 /* Set phys_cursor_.* before x_draw_.* is called because some
19992 of them may need the information. */
19993 w
->phys_cursor
.x
= x
;
19994 w
->phys_cursor
.y
= glyph_row
->y
;
19995 w
->phys_cursor
.hpos
= hpos
;
19996 w
->phys_cursor
.vpos
= vpos
;
19999 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
20000 new_cursor_type
, new_cursor_width
,
20001 on
, active_cursor
);
20005 /* Switch the display of W's cursor on or off, according to the value
20009 update_window_cursor (w
, on
)
20013 /* Don't update cursor in windows whose frame is in the process
20014 of being deleted. */
20015 if (w
->current_matrix
)
20018 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20019 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20025 /* Call update_window_cursor with parameter ON_P on all leaf windows
20026 in the window tree rooted at W. */
20029 update_cursor_in_window_tree (w
, on_p
)
20035 if (!NILP (w
->hchild
))
20036 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
20037 else if (!NILP (w
->vchild
))
20038 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
20040 update_window_cursor (w
, on_p
);
20042 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
20048 Display the cursor on window W, or clear it, according to ON_P.
20049 Don't change the cursor's position. */
20052 x_update_cursor (f
, on_p
)
20056 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
20061 Clear the cursor of window W to background color, and mark the
20062 cursor as not shown. This is used when the text where the cursor
20063 is is about to be rewritten. */
20069 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
20070 update_window_cursor (w
, 0);
20075 Display the active region described by mouse_face_* according to DRAW. */
20078 show_mouse_face (dpyinfo
, draw
)
20079 Display_Info
*dpyinfo
;
20080 enum draw_glyphs_face draw
;
20082 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
20083 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20085 if (/* If window is in the process of being destroyed, don't bother
20087 w
->current_matrix
!= NULL
20088 /* Don't update mouse highlight if hidden */
20089 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
20090 /* Recognize when we are called to operate on rows that don't exist
20091 anymore. This can happen when a window is split. */
20092 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
20094 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
20095 struct glyph_row
*row
, *first
, *last
;
20097 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20098 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20100 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
20102 int start_hpos
, end_hpos
, start_x
;
20104 /* For all but the first row, the highlight starts at column 0. */
20107 start_hpos
= dpyinfo
->mouse_face_beg_col
;
20108 start_x
= dpyinfo
->mouse_face_beg_x
;
20117 end_hpos
= dpyinfo
->mouse_face_end_col
;
20119 end_hpos
= row
->used
[TEXT_AREA
];
20121 if (end_hpos
> start_hpos
)
20123 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
20124 start_hpos
, end_hpos
,
20128 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
20132 /* When we've written over the cursor, arrange for it to
20133 be displayed again. */
20134 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
20137 display_and_set_cursor (w
, 1,
20138 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20139 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20144 /* Change the mouse cursor. */
20145 if (draw
== DRAW_NORMAL_TEXT
)
20146 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
20147 else if (draw
== DRAW_MOUSE_FACE
)
20148 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
20150 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
20154 Clear out the mouse-highlighted active region.
20155 Redraw it un-highlighted first. Value is non-zero if mouse
20156 face was actually drawn unhighlighted. */
20159 clear_mouse_face (dpyinfo
)
20160 Display_Info
*dpyinfo
;
20164 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
20166 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
20170 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
20171 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
20172 dpyinfo
->mouse_face_window
= Qnil
;
20173 dpyinfo
->mouse_face_overlay
= Qnil
;
20179 Non-zero if physical cursor of window W is within mouse face. */
20182 cursor_in_mouse_face_p (w
)
20185 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
20186 int in_mouse_face
= 0;
20188 if (WINDOWP (dpyinfo
->mouse_face_window
)
20189 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
20191 int hpos
= w
->phys_cursor
.hpos
;
20192 int vpos
= w
->phys_cursor
.vpos
;
20194 if (vpos
>= dpyinfo
->mouse_face_beg_row
20195 && vpos
<= dpyinfo
->mouse_face_end_row
20196 && (vpos
> dpyinfo
->mouse_face_beg_row
20197 || hpos
>= dpyinfo
->mouse_face_beg_col
)
20198 && (vpos
< dpyinfo
->mouse_face_end_row
20199 || hpos
< dpyinfo
->mouse_face_end_col
20200 || dpyinfo
->mouse_face_past_end
))
20204 return in_mouse_face
;
20210 /* Find the glyph matrix position of buffer position CHARPOS in window
20211 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
20212 current glyphs must be up to date. If CHARPOS is above window
20213 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
20214 of last line in W. In the row containing CHARPOS, stop before glyphs
20215 having STOP as object. */
20217 #if 1 /* This is a version of fast_find_position that's more correct
20218 in the presence of hscrolling, for example. I didn't install
20219 it right away because the problem fixed is minor, it failed
20220 in 20.x as well, and I think it's too risky to install
20221 so near the release of 21.1. 2001-09-25 gerd. */
20224 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
20227 int *hpos
, *vpos
, *x
, *y
;
20230 struct glyph_row
*row
, *first
;
20231 struct glyph
*glyph
, *end
;
20234 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20235 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
20238 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
20240 *x
= *y
= *hpos
= *vpos
= 0;
20245 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
20252 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
20254 glyph
= row
->glyphs
[TEXT_AREA
];
20255 end
= glyph
+ row
->used
[TEXT_AREA
];
20257 /* Skip over glyphs not having an object at the start of the row.
20258 These are special glyphs like truncation marks on terminal
20260 if (row
->displays_text_p
)
20262 && INTEGERP (glyph
->object
)
20263 && !EQ (stop
, glyph
->object
)
20264 && glyph
->charpos
< 0)
20266 *x
+= glyph
->pixel_width
;
20271 && !INTEGERP (glyph
->object
)
20272 && !EQ (stop
, glyph
->object
)
20273 && (!BUFFERP (glyph
->object
)
20274 || glyph
->charpos
< charpos
))
20276 *x
+= glyph
->pixel_width
;
20280 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
20287 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
20290 int *hpos
, *vpos
, *x
, *y
;
20295 int maybe_next_line_p
= 0;
20296 int line_start_position
;
20297 int yb
= window_text_bottom_y (w
);
20298 struct glyph_row
*row
, *best_row
;
20299 int row_vpos
, best_row_vpos
;
20302 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20303 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
20305 while (row
->y
< yb
)
20307 if (row
->used
[TEXT_AREA
])
20308 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
20310 line_start_position
= 0;
20312 if (line_start_position
> pos
)
20314 /* If the position sought is the end of the buffer,
20315 don't include the blank lines at the bottom of the window. */
20316 else if (line_start_position
== pos
20317 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
20319 maybe_next_line_p
= 1;
20322 else if (line_start_position
> 0)
20325 best_row_vpos
= row_vpos
;
20328 if (row
->y
+ row
->height
>= yb
)
20335 /* Find the right column within BEST_ROW. */
20337 current_x
= best_row
->x
;
20338 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
20340 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
20341 int charpos
= glyph
->charpos
;
20343 if (BUFFERP (glyph
->object
))
20345 if (charpos
== pos
)
20348 *vpos
= best_row_vpos
;
20353 else if (charpos
> pos
)
20356 else if (EQ (glyph
->object
, stop
))
20361 current_x
+= glyph
->pixel_width
;
20364 /* If we're looking for the end of the buffer,
20365 and we didn't find it in the line we scanned,
20366 use the start of the following line. */
20367 if (maybe_next_line_p
)
20372 current_x
= best_row
->x
;
20375 *vpos
= best_row_vpos
;
20376 *hpos
= lastcol
+ 1;
20385 /* Find the position of the glyph for position POS in OBJECT in
20386 window W's current matrix, and return in *X, *Y the pixel
20387 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
20389 RIGHT_P non-zero means return the position of the right edge of the
20390 glyph, RIGHT_P zero means return the left edge position.
20392 If no glyph for POS exists in the matrix, return the position of
20393 the glyph with the next smaller position that is in the matrix, if
20394 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
20395 exists in the matrix, return the position of the glyph with the
20396 next larger position in OBJECT.
20398 Value is non-zero if a glyph was found. */
20401 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
20404 Lisp_Object object
;
20405 int *hpos
, *vpos
, *x
, *y
;
20408 int yb
= window_text_bottom_y (w
);
20409 struct glyph_row
*r
;
20410 struct glyph
*best_glyph
= NULL
;
20411 struct glyph_row
*best_row
= NULL
;
20414 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20415 r
->enabled_p
&& r
->y
< yb
;
20418 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
20419 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
20422 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
20423 if (EQ (g
->object
, object
))
20425 if (g
->charpos
== pos
)
20432 else if (best_glyph
== NULL
20433 || ((abs (g
->charpos
- pos
)
20434 < abs (best_glyph
->charpos
- pos
))
20437 : g
->charpos
> pos
)))
20451 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
20455 *x
+= best_glyph
->pixel_width
;
20460 *vpos
= best_row
- w
->current_matrix
->rows
;
20463 return best_glyph
!= NULL
;
20467 /* See if position X, Y is within a hot-spot of an image. */
20470 on_hot_spot_p (hot_spot
, x
, y
)
20471 Lisp_Object hot_spot
;
20474 if (!CONSP (hot_spot
))
20477 if (EQ (XCAR (hot_spot
), Qrect
))
20479 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
20480 Lisp_Object rect
= XCDR (hot_spot
);
20484 if (!CONSP (XCAR (rect
)))
20486 if (!CONSP (XCDR (rect
)))
20488 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
20490 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
20492 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
20494 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
20498 else if (EQ (XCAR (hot_spot
), Qcircle
))
20500 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
20501 Lisp_Object circ
= XCDR (hot_spot
);
20502 Lisp_Object lr
, lx0
, ly0
;
20504 && CONSP (XCAR (circ
))
20505 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
20506 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
20507 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
20509 double r
= XFLOATINT (lr
);
20510 double dx
= XINT (lx0
) - x
;
20511 double dy
= XINT (ly0
) - y
;
20512 return (dx
* dx
+ dy
* dy
<= r
* r
);
20515 else if (EQ (XCAR (hot_spot
), Qpoly
))
20517 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
20518 if (VECTORP (XCDR (hot_spot
)))
20520 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
20521 Lisp_Object
*poly
= v
->contents
;
20525 Lisp_Object lx
, ly
;
20528 /* Need an even number of coordinates, and at least 3 edges. */
20529 if (n
< 6 || n
& 1)
20532 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
20533 If count is odd, we are inside polygon. Pixels on edges
20534 may or may not be included depending on actual geometry of the
20536 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
20537 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
20539 x0
= XINT (lx
), y0
= XINT (ly
);
20540 for (i
= 0; i
< n
; i
+= 2)
20542 int x1
= x0
, y1
= y0
;
20543 if ((lx
= poly
[i
], !INTEGERP (lx
))
20544 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
20546 x0
= XINT (lx
), y0
= XINT (ly
);
20548 /* Does this segment cross the X line? */
20556 if (y
> y0
&& y
> y1
)
20558 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
20564 /* If we don't understand the format, pretend we're not in the hot-spot. */
20569 find_hot_spot (map
, x
, y
)
20573 while (CONSP (map
))
20575 if (CONSP (XCAR (map
))
20576 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
20584 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
20586 doc
: /* Lookup in image map MAP coordinates X and Y.
20587 An image map is an alist where each element has the format (AREA ID PLIST).
20588 An AREA is specified as either a rectangle, a circle, or a polygon:
20589 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
20590 pixel coordinates of the upper left and bottom right corners.
20591 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
20592 and the radius of the circle; r may be a float or integer.
20593 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
20594 vector describes one corner in the polygon.
20595 Returns the alist element for the first matching AREA in MAP. */)
20606 return find_hot_spot (map
, XINT (x
), XINT (y
));
20610 /* Display frame CURSOR, optionally using shape defined by POINTER. */
20612 define_frame_cursor1 (f
, cursor
, pointer
)
20615 Lisp_Object pointer
;
20617 if (!NILP (pointer
))
20619 if (EQ (pointer
, Qarrow
))
20620 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20621 else if (EQ (pointer
, Qhand
))
20622 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
20623 else if (EQ (pointer
, Qtext
))
20624 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
20625 else if (EQ (pointer
, intern ("hdrag")))
20626 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
20627 #ifdef HAVE_X_WINDOWS
20628 else if (EQ (pointer
, intern ("vdrag")))
20629 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
20631 else if (EQ (pointer
, intern ("hourglass")))
20632 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
20633 else if (EQ (pointer
, Qmodeline
))
20634 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
20636 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20639 if (cursor
!= No_Cursor
)
20640 rif
->define_frame_cursor (f
, cursor
);
20643 /* Take proper action when mouse has moved to the mode or header line
20644 or marginal area AREA of window W, x-position X and y-position Y.
20645 X is relative to the start of the text display area of W, so the
20646 width of bitmap areas and scroll bars must be subtracted to get a
20647 position relative to the start of the mode line. */
20650 note_mode_line_or_margin_highlight (w
, x
, y
, area
)
20653 enum window_part area
;
20655 struct frame
*f
= XFRAME (w
->frame
);
20656 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20657 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20658 Lisp_Object pointer
= Qnil
;
20659 int charpos
, dx
, dy
, width
, height
;
20660 Lisp_Object string
, object
= Qnil
;
20661 Lisp_Object pos
, help
;
20663 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
20664 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
20665 &object
, &dx
, &dy
, &width
, &height
);
20668 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
20669 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
20670 &object
, &dx
, &dy
, &width
, &height
);
20675 if (IMAGEP (object
))
20677 Lisp_Object image_map
, hotspot
;
20678 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
20680 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
20682 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
20684 Lisp_Object area_id
, plist
;
20686 area_id
= XCAR (hotspot
);
20687 /* Could check AREA_ID to see if we enter/leave this hot-spot.
20688 If so, we could look for mouse-enter, mouse-leave
20689 properties in PLIST (and do something...). */
20690 if ((plist
= XCDR (hotspot
), CONSP (plist
)))
20692 pointer
= Fplist_get (plist
, Qpointer
);
20693 if (NILP (pointer
))
20695 help
= Fplist_get (plist
, Qhelp_echo
);
20698 help_echo_string
= help
;
20699 /* Is this correct? ++kfs */
20700 XSETWINDOW (help_echo_window
, w
);
20701 help_echo_object
= w
->buffer
;
20702 help_echo_pos
= charpos
;
20705 if (NILP (pointer
))
20706 pointer
= Fplist_get (XCDR (object
), QCpointer
);
20710 if (STRINGP (string
))
20712 pos
= make_number (charpos
);
20713 /* If we're on a string with `help-echo' text property, arrange
20714 for the help to be displayed. This is done by setting the
20715 global variable help_echo_string to the help string. */
20716 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
20719 help_echo_string
= help
;
20720 XSETWINDOW (help_echo_window
, w
);
20721 help_echo_object
= string
;
20722 help_echo_pos
= charpos
;
20725 if (NILP (pointer
))
20726 pointer
= Fget_text_property (pos
, Qpointer
, string
);
20728 /* Change the mouse pointer according to what is under X/Y. */
20729 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
20732 map
= Fget_text_property (pos
, Qlocal_map
, string
);
20733 if (!KEYMAPP (map
))
20734 map
= Fget_text_property (pos
, Qkeymap
, string
);
20735 if (!KEYMAPP (map
))
20736 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
20740 define_frame_cursor1 (f
, cursor
, pointer
);
20745 Take proper action when the mouse has moved to position X, Y on
20746 frame F as regards highlighting characters that have mouse-face
20747 properties. Also de-highlighting chars where the mouse was before.
20748 X and Y can be negative or out of range. */
20751 note_mouse_highlight (f
, x
, y
)
20755 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20756 enum window_part part
;
20757 Lisp_Object window
;
20759 Cursor cursor
= No_Cursor
;
20760 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
20763 /* When a menu is active, don't highlight because this looks odd. */
20764 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
20765 if (popup_activated ())
20769 if (NILP (Vmouse_highlight
)
20770 || !f
->glyphs_initialized_p
)
20773 dpyinfo
->mouse_face_mouse_x
= x
;
20774 dpyinfo
->mouse_face_mouse_y
= y
;
20775 dpyinfo
->mouse_face_mouse_frame
= f
;
20777 if (dpyinfo
->mouse_face_defer
)
20780 if (gc_in_progress
)
20782 dpyinfo
->mouse_face_deferred_gc
= 1;
20786 /* Which window is that in? */
20787 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
20789 /* If we were displaying active text in another window, clear that. */
20790 if (! EQ (window
, dpyinfo
->mouse_face_window
))
20791 clear_mouse_face (dpyinfo
);
20793 /* Not on a window -> return. */
20794 if (!WINDOWP (window
))
20797 /* Reset help_echo_string. It will get recomputed below. */
20798 help_echo_string
= Qnil
;
20800 /* Convert to window-relative pixel coordinates. */
20801 w
= XWINDOW (window
);
20802 frame_to_window_pixel_xy (w
, &x
, &y
);
20804 /* Handle tool-bar window differently since it doesn't display a
20806 if (EQ (window
, f
->tool_bar_window
))
20808 note_tool_bar_highlight (f
, x
, y
);
20812 /* Mouse is on the mode, header line or margin? */
20813 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
20814 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
20816 note_mode_line_or_margin_highlight (w
, x
, y
, part
);
20820 if (part
== ON_VERTICAL_BORDER
)
20821 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
20822 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
)
20823 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20825 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
20827 /* Are we in a window whose display is up to date?
20828 And verify the buffer's text has not changed. */
20829 b
= XBUFFER (w
->buffer
);
20830 if (part
== ON_TEXT
20831 && EQ (w
->window_end_valid
, w
->buffer
)
20832 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
20833 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
20835 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
20836 struct glyph
*glyph
;
20837 Lisp_Object object
;
20838 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
20839 Lisp_Object
*overlay_vec
= NULL
;
20841 struct buffer
*obuf
;
20842 int obegv
, ozv
, same_region
;
20844 /* Find the glyph under X/Y. */
20845 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
20847 /* Look for :pointer property on image. */
20848 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
20850 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
20851 if (img
!= NULL
&& IMAGEP (img
->spec
))
20853 Lisp_Object image_map
, hotspot
;
20854 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
20856 && (hotspot
= find_hot_spot (image_map
,
20857 glyph
->slice
.x
+ dx
,
20858 glyph
->slice
.y
+ dy
),
20860 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
20862 Lisp_Object area_id
, plist
;
20864 area_id
= XCAR (hotspot
);
20865 /* Could check AREA_ID to see if we enter/leave this hot-spot.
20866 If so, we could look for mouse-enter, mouse-leave
20867 properties in PLIST (and do something...). */
20868 if ((plist
= XCDR (hotspot
), CONSP (plist
)))
20870 pointer
= Fplist_get (plist
, Qpointer
);
20871 if (NILP (pointer
))
20873 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
20874 if (!NILP (help_echo_string
))
20876 help_echo_window
= window
;
20877 help_echo_object
= glyph
->object
;
20878 help_echo_pos
= glyph
->charpos
;
20882 if (NILP (pointer
))
20883 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
20887 /* Clear mouse face if X/Y not over text. */
20889 || area
!= TEXT_AREA
20890 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
20892 if (clear_mouse_face (dpyinfo
))
20893 cursor
= No_Cursor
;
20894 if (NILP (pointer
))
20896 if (area
!= TEXT_AREA
)
20897 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20899 pointer
= Vvoid_text_area_pointer
;
20904 pos
= glyph
->charpos
;
20905 object
= glyph
->object
;
20906 if (!STRINGP (object
) && !BUFFERP (object
))
20909 /* If we get an out-of-range value, return now; avoid an error. */
20910 if (BUFFERP (object
) && pos
> BUF_Z (b
))
20913 /* Make the window's buffer temporarily current for
20914 overlays_at and compute_char_face. */
20915 obuf
= current_buffer
;
20916 current_buffer
= b
;
20922 /* Is this char mouse-active or does it have help-echo? */
20923 position
= make_number (pos
);
20925 if (BUFFERP (object
))
20927 /* Put all the overlays we want in a vector in overlay_vec. */
20928 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
20929 /* Sort overlays into increasing priority order. */
20930 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
20935 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
20936 && vpos
>= dpyinfo
->mouse_face_beg_row
20937 && vpos
<= dpyinfo
->mouse_face_end_row
20938 && (vpos
> dpyinfo
->mouse_face_beg_row
20939 || hpos
>= dpyinfo
->mouse_face_beg_col
)
20940 && (vpos
< dpyinfo
->mouse_face_end_row
20941 || hpos
< dpyinfo
->mouse_face_end_col
20942 || dpyinfo
->mouse_face_past_end
));
20945 cursor
= No_Cursor
;
20947 /* Check mouse-face highlighting. */
20949 /* If there exists an overlay with mouse-face overlapping
20950 the one we are currently highlighting, we have to
20951 check if we enter the overlapping overlay, and then
20952 highlight only that. */
20953 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
20954 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
20956 /* Find the highest priority overlay that has a mouse-face
20959 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
20961 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
20962 if (!NILP (mouse_face
))
20963 overlay
= overlay_vec
[i
];
20966 /* If we're actually highlighting the same overlay as
20967 before, there's no need to do that again. */
20968 if (!NILP (overlay
)
20969 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
20970 goto check_help_echo
;
20972 dpyinfo
->mouse_face_overlay
= overlay
;
20974 /* Clear the display of the old active region, if any. */
20975 if (clear_mouse_face (dpyinfo
))
20976 cursor
= No_Cursor
;
20978 /* If no overlay applies, get a text property. */
20979 if (NILP (overlay
))
20980 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
20982 /* Handle the overlay case. */
20983 if (!NILP (overlay
))
20985 /* Find the range of text around this char that
20986 should be active. */
20987 Lisp_Object before
, after
;
20990 before
= Foverlay_start (overlay
);
20991 after
= Foverlay_end (overlay
);
20992 /* Record this as the current active region. */
20993 fast_find_position (w
, XFASTINT (before
),
20994 &dpyinfo
->mouse_face_beg_col
,
20995 &dpyinfo
->mouse_face_beg_row
,
20996 &dpyinfo
->mouse_face_beg_x
,
20997 &dpyinfo
->mouse_face_beg_y
, Qnil
);
20999 dpyinfo
->mouse_face_past_end
21000 = !fast_find_position (w
, XFASTINT (after
),
21001 &dpyinfo
->mouse_face_end_col
,
21002 &dpyinfo
->mouse_face_end_row
,
21003 &dpyinfo
->mouse_face_end_x
,
21004 &dpyinfo
->mouse_face_end_y
, Qnil
);
21005 dpyinfo
->mouse_face_window
= window
;
21007 dpyinfo
->mouse_face_face_id
21008 = face_at_buffer_position (w
, pos
, 0, 0,
21010 !dpyinfo
->mouse_face_hidden
);
21012 /* Display it as active. */
21013 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21014 cursor
= No_Cursor
;
21016 /* Handle the text property case. */
21017 else if (!NILP (mouse_face
) && BUFFERP (object
))
21019 /* Find the range of text around this char that
21020 should be active. */
21021 Lisp_Object before
, after
, beginning
, end
;
21024 beginning
= Fmarker_position (w
->start
);
21025 end
= make_number (BUF_Z (XBUFFER (object
))
21026 - XFASTINT (w
->window_end_pos
));
21028 = Fprevious_single_property_change (make_number (pos
+ 1),
21030 object
, beginning
);
21032 = Fnext_single_property_change (position
, Qmouse_face
,
21035 /* Record this as the current active region. */
21036 fast_find_position (w
, XFASTINT (before
),
21037 &dpyinfo
->mouse_face_beg_col
,
21038 &dpyinfo
->mouse_face_beg_row
,
21039 &dpyinfo
->mouse_face_beg_x
,
21040 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21041 dpyinfo
->mouse_face_past_end
21042 = !fast_find_position (w
, XFASTINT (after
),
21043 &dpyinfo
->mouse_face_end_col
,
21044 &dpyinfo
->mouse_face_end_row
,
21045 &dpyinfo
->mouse_face_end_x
,
21046 &dpyinfo
->mouse_face_end_y
, Qnil
);
21047 dpyinfo
->mouse_face_window
= window
;
21049 if (BUFFERP (object
))
21050 dpyinfo
->mouse_face_face_id
21051 = face_at_buffer_position (w
, pos
, 0, 0,
21053 !dpyinfo
->mouse_face_hidden
);
21055 /* Display it as active. */
21056 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21057 cursor
= No_Cursor
;
21059 else if (!NILP (mouse_face
) && STRINGP (object
))
21064 b
= Fprevious_single_property_change (make_number (pos
+ 1),
21067 e
= Fnext_single_property_change (position
, Qmouse_face
,
21070 b
= make_number (0);
21072 e
= make_number (SCHARS (object
) - 1);
21073 fast_find_string_pos (w
, XINT (b
), object
,
21074 &dpyinfo
->mouse_face_beg_col
,
21075 &dpyinfo
->mouse_face_beg_row
,
21076 &dpyinfo
->mouse_face_beg_x
,
21077 &dpyinfo
->mouse_face_beg_y
, 0);
21078 fast_find_string_pos (w
, XINT (e
), object
,
21079 &dpyinfo
->mouse_face_end_col
,
21080 &dpyinfo
->mouse_face_end_row
,
21081 &dpyinfo
->mouse_face_end_x
,
21082 &dpyinfo
->mouse_face_end_y
, 1);
21083 dpyinfo
->mouse_face_past_end
= 0;
21084 dpyinfo
->mouse_face_window
= window
;
21085 dpyinfo
->mouse_face_face_id
21086 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
21087 glyph
->face_id
, 1);
21088 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21089 cursor
= No_Cursor
;
21091 else if (STRINGP (object
) && NILP (mouse_face
))
21093 /* A string which doesn't have mouse-face, but
21094 the text ``under'' it might have. */
21095 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
21096 int start
= MATRIX_ROW_START_CHARPOS (r
);
21098 pos
= string_buffer_position (w
, object
, start
);
21100 mouse_face
= get_char_property_and_overlay (make_number (pos
),
21104 if (!NILP (mouse_face
) && !NILP (overlay
))
21106 Lisp_Object before
= Foverlay_start (overlay
);
21107 Lisp_Object after
= Foverlay_end (overlay
);
21110 /* Note that we might not be able to find position
21111 BEFORE in the glyph matrix if the overlay is
21112 entirely covered by a `display' property. In
21113 this case, we overshoot. So let's stop in
21114 the glyph matrix before glyphs for OBJECT. */
21115 fast_find_position (w
, XFASTINT (before
),
21116 &dpyinfo
->mouse_face_beg_col
,
21117 &dpyinfo
->mouse_face_beg_row
,
21118 &dpyinfo
->mouse_face_beg_x
,
21119 &dpyinfo
->mouse_face_beg_y
,
21122 dpyinfo
->mouse_face_past_end
21123 = !fast_find_position (w
, XFASTINT (after
),
21124 &dpyinfo
->mouse_face_end_col
,
21125 &dpyinfo
->mouse_face_end_row
,
21126 &dpyinfo
->mouse_face_end_x
,
21127 &dpyinfo
->mouse_face_end_y
,
21129 dpyinfo
->mouse_face_window
= window
;
21130 dpyinfo
->mouse_face_face_id
21131 = face_at_buffer_position (w
, pos
, 0, 0,
21133 !dpyinfo
->mouse_face_hidden
);
21135 /* Display it as active. */
21136 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21137 cursor
= No_Cursor
;
21144 /* Look for a `help-echo' property. */
21145 if (NILP (help_echo_string
)) {
21146 Lisp_Object help
, overlay
;
21148 /* Check overlays first. */
21149 help
= overlay
= Qnil
;
21150 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
21152 overlay
= overlay_vec
[i
];
21153 help
= Foverlay_get (overlay
, Qhelp_echo
);
21158 help_echo_string
= help
;
21159 help_echo_window
= window
;
21160 help_echo_object
= overlay
;
21161 help_echo_pos
= pos
;
21165 Lisp_Object object
= glyph
->object
;
21166 int charpos
= glyph
->charpos
;
21168 /* Try text properties. */
21169 if (STRINGP (object
)
21171 && charpos
< SCHARS (object
))
21173 help
= Fget_text_property (make_number (charpos
),
21174 Qhelp_echo
, object
);
21177 /* If the string itself doesn't specify a help-echo,
21178 see if the buffer text ``under'' it does. */
21179 struct glyph_row
*r
21180 = MATRIX_ROW (w
->current_matrix
, vpos
);
21181 int start
= MATRIX_ROW_START_CHARPOS (r
);
21182 int pos
= string_buffer_position (w
, object
, start
);
21185 help
= Fget_char_property (make_number (pos
),
21186 Qhelp_echo
, w
->buffer
);
21190 object
= w
->buffer
;
21195 else if (BUFFERP (object
)
21198 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
21203 help_echo_string
= help
;
21204 help_echo_window
= window
;
21205 help_echo_object
= object
;
21206 help_echo_pos
= charpos
;
21211 /* Look for a `pointer' property. */
21212 if (NILP (pointer
))
21214 /* Check overlays first. */
21215 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
21216 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
21218 if (NILP (pointer
))
21220 Lisp_Object object
= glyph
->object
;
21221 int charpos
= glyph
->charpos
;
21223 /* Try text properties. */
21224 if (STRINGP (object
)
21226 && charpos
< SCHARS (object
))
21228 pointer
= Fget_text_property (make_number (charpos
),
21230 if (NILP (pointer
))
21232 /* If the string itself doesn't specify a pointer,
21233 see if the buffer text ``under'' it does. */
21234 struct glyph_row
*r
21235 = MATRIX_ROW (w
->current_matrix
, vpos
);
21236 int start
= MATRIX_ROW_START_CHARPOS (r
);
21237 int pos
= string_buffer_position (w
, object
, start
);
21239 pointer
= Fget_char_property (make_number (pos
),
21240 Qpointer
, w
->buffer
);
21243 else if (BUFFERP (object
)
21246 pointer
= Fget_text_property (make_number (charpos
),
21253 current_buffer
= obuf
;
21258 define_frame_cursor1 (f
, cursor
, pointer
);
21263 Clear any mouse-face on window W. This function is part of the
21264 redisplay interface, and is called from try_window_id and similar
21265 functions to ensure the mouse-highlight is off. */
21268 x_clear_window_mouse_face (w
)
21271 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21272 Lisp_Object window
;
21275 XSETWINDOW (window
, w
);
21276 if (EQ (window
, dpyinfo
->mouse_face_window
))
21277 clear_mouse_face (dpyinfo
);
21283 Just discard the mouse face information for frame F, if any.
21284 This is used when the size of F is changed. */
21287 cancel_mouse_face (f
)
21290 Lisp_Object window
;
21291 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21293 window
= dpyinfo
->mouse_face_window
;
21294 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
21296 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21297 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21298 dpyinfo
->mouse_face_window
= Qnil
;
21303 #endif /* HAVE_WINDOW_SYSTEM */
21306 /***********************************************************************
21308 ***********************************************************************/
21310 #ifdef HAVE_WINDOW_SYSTEM
21312 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
21313 which intersects rectangle R. R is in window-relative coordinates. */
21316 expose_area (w
, row
, r
, area
)
21318 struct glyph_row
*row
;
21320 enum glyph_row_area area
;
21322 struct glyph
*first
= row
->glyphs
[area
];
21323 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
21324 struct glyph
*last
;
21325 int first_x
, start_x
, x
;
21327 if (area
== TEXT_AREA
&& row
->fill_line_p
)
21328 /* If row extends face to end of line write the whole line. */
21329 draw_glyphs (w
, 0, row
, area
,
21330 0, row
->used
[area
],
21331 DRAW_NORMAL_TEXT
, 0);
21334 /* Set START_X to the window-relative start position for drawing glyphs of
21335 AREA. The first glyph of the text area can be partially visible.
21336 The first glyphs of other areas cannot. */
21337 start_x
= window_box_left_offset (w
, area
);
21339 if (area
== TEXT_AREA
)
21342 /* Find the first glyph that must be redrawn. */
21344 && x
+ first
->pixel_width
< r
->x
)
21346 x
+= first
->pixel_width
;
21350 /* Find the last one. */
21354 && x
< r
->x
+ r
->width
)
21356 x
+= last
->pixel_width
;
21362 draw_glyphs (w
, first_x
- start_x
, row
, area
,
21363 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
21364 DRAW_NORMAL_TEXT
, 0);
21369 /* Redraw the parts of the glyph row ROW on window W intersecting
21370 rectangle R. R is in window-relative coordinates. Value is
21371 non-zero if mouse-face was overwritten. */
21374 expose_line (w
, row
, r
)
21376 struct glyph_row
*row
;
21379 xassert (row
->enabled_p
);
21381 if (row
->mode_line_p
|| w
->pseudo_window_p
)
21382 draw_glyphs (w
, 0, row
, TEXT_AREA
,
21383 0, row
->used
[TEXT_AREA
],
21384 DRAW_NORMAL_TEXT
, 0);
21387 if (row
->used
[LEFT_MARGIN_AREA
])
21388 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
21389 if (row
->used
[TEXT_AREA
])
21390 expose_area (w
, row
, r
, TEXT_AREA
);
21391 if (row
->used
[RIGHT_MARGIN_AREA
])
21392 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
21393 draw_row_fringe_bitmaps (w
, row
);
21396 return row
->mouse_face_p
;
21400 /* Redraw those parts of glyphs rows during expose event handling that
21401 overlap other rows. Redrawing of an exposed line writes over parts
21402 of lines overlapping that exposed line; this function fixes that.
21404 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
21405 row in W's current matrix that is exposed and overlaps other rows.
21406 LAST_OVERLAPPING_ROW is the last such row. */
21409 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
21411 struct glyph_row
*first_overlapping_row
;
21412 struct glyph_row
*last_overlapping_row
;
21414 struct glyph_row
*row
;
21416 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
21417 if (row
->overlapping_p
)
21419 xassert (row
->enabled_p
&& !row
->mode_line_p
);
21421 if (row
->used
[LEFT_MARGIN_AREA
])
21422 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
21424 if (row
->used
[TEXT_AREA
])
21425 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
21427 if (row
->used
[RIGHT_MARGIN_AREA
])
21428 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
21433 /* Return non-zero if W's cursor intersects rectangle R. */
21436 phys_cursor_in_rect_p (w
, r
)
21440 XRectangle cr
, result
;
21441 struct glyph
*cursor_glyph
;
21443 cursor_glyph
= get_phys_cursor_glyph (w
);
21446 /* r is relative to W's box, but w->phys_cursor.x is relative
21447 to left edge of W's TEXT area. Adjust it. */
21448 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
21449 cr
.y
= w
->phys_cursor
.y
;
21450 cr
.width
= cursor_glyph
->pixel_width
;
21451 cr
.height
= w
->phys_cursor_height
;
21452 /* ++KFS: W32 version used W32-specific IntersectRect here, but
21453 I assume the effect is the same -- and this is portable. */
21454 return x_intersect_rectangles (&cr
, r
, &result
);
21462 Draw a vertical window border to the right of window W if W doesn't
21463 have vertical scroll bars. */
21466 x_draw_vertical_border (w
)
21469 /* We could do better, if we knew what type of scroll-bar the adjacent
21470 windows (on either side) have... But we don't :-(
21471 However, I think this works ok. ++KFS 2003-04-25 */
21473 /* Redraw borders between horizontally adjacent windows. Don't
21474 do it for frames with vertical scroll bars because either the
21475 right scroll bar of a window, or the left scroll bar of its
21476 neighbor will suffice as a border. */
21477 if (!WINDOW_RIGHTMOST_P (w
)
21478 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
21480 int x0
, x1
, y0
, y1
;
21482 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21485 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
21487 else if (!WINDOW_LEFTMOST_P (w
)
21488 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
21490 int x0
, x1
, y0
, y1
;
21492 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21495 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
21500 /* Redraw the part of window W intersection rectangle FR. Pixel
21501 coordinates in FR are frame-relative. Call this function with
21502 input blocked. Value is non-zero if the exposure overwrites
21506 expose_window (w
, fr
)
21510 struct frame
*f
= XFRAME (w
->frame
);
21512 int mouse_face_overwritten_p
= 0;
21514 /* If window is not yet fully initialized, do nothing. This can
21515 happen when toolkit scroll bars are used and a window is split.
21516 Reconfiguring the scroll bar will generate an expose for a newly
21518 if (w
->current_matrix
== NULL
)
21521 /* When we're currently updating the window, display and current
21522 matrix usually don't agree. Arrange for a thorough display
21524 if (w
== updated_window
)
21526 SET_FRAME_GARBAGED (f
);
21530 /* Frame-relative pixel rectangle of W. */
21531 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
21532 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
21533 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
21534 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
21536 if (x_intersect_rectangles (fr
, &wr
, &r
))
21538 int yb
= window_text_bottom_y (w
);
21539 struct glyph_row
*row
;
21540 int cursor_cleared_p
;
21541 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
21543 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
21544 r
.x
, r
.y
, r
.width
, r
.height
));
21546 /* Convert to window coordinates. */
21547 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
21548 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
21550 /* Turn off the cursor. */
21551 if (!w
->pseudo_window_p
21552 && phys_cursor_in_rect_p (w
, &r
))
21554 x_clear_cursor (w
);
21555 cursor_cleared_p
= 1;
21558 cursor_cleared_p
= 0;
21560 /* Update lines intersecting rectangle R. */
21561 first_overlapping_row
= last_overlapping_row
= NULL
;
21562 for (row
= w
->current_matrix
->rows
;
21567 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
21569 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
21570 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
21571 || (r
.y
>= y0
&& r
.y
< y1
)
21572 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
21574 if (row
->overlapping_p
)
21576 if (first_overlapping_row
== NULL
)
21577 first_overlapping_row
= row
;
21578 last_overlapping_row
= row
;
21581 if (expose_line (w
, row
, &r
))
21582 mouse_face_overwritten_p
= 1;
21589 /* Display the mode line if there is one. */
21590 if (WINDOW_WANTS_MODELINE_P (w
)
21591 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
21593 && row
->y
< r
.y
+ r
.height
)
21595 if (expose_line (w
, row
, &r
))
21596 mouse_face_overwritten_p
= 1;
21599 if (!w
->pseudo_window_p
)
21601 /* Fix the display of overlapping rows. */
21602 if (first_overlapping_row
)
21603 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
21605 /* Draw border between windows. */
21606 x_draw_vertical_border (w
);
21608 /* Turn the cursor on again. */
21609 if (cursor_cleared_p
)
21610 update_window_cursor (w
, 1);
21615 /* Display scroll bar for this window. */
21616 if (!NILP (w
->vertical_scroll_bar
))
21619 If this doesn't work here (maybe some header files are missing),
21620 make a function in macterm.c and call it to do the job! */
21622 = SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (w
->vertical_scroll_bar
));
21628 return mouse_face_overwritten_p
;
21633 /* Redraw (parts) of all windows in the window tree rooted at W that
21634 intersect R. R contains frame pixel coordinates. Value is
21635 non-zero if the exposure overwrites mouse-face. */
21638 expose_window_tree (w
, r
)
21642 struct frame
*f
= XFRAME (w
->frame
);
21643 int mouse_face_overwritten_p
= 0;
21645 while (w
&& !FRAME_GARBAGED_P (f
))
21647 if (!NILP (w
->hchild
))
21648 mouse_face_overwritten_p
21649 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
21650 else if (!NILP (w
->vchild
))
21651 mouse_face_overwritten_p
21652 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
21654 mouse_face_overwritten_p
|= expose_window (w
, r
);
21656 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
21659 return mouse_face_overwritten_p
;
21664 Redisplay an exposed area of frame F. X and Y are the upper-left
21665 corner of the exposed rectangle. W and H are width and height of
21666 the exposed area. All are pixel values. W or H zero means redraw
21667 the entire frame. */
21670 expose_frame (f
, x
, y
, w
, h
)
21675 int mouse_face_overwritten_p
= 0;
21677 TRACE ((stderr
, "expose_frame "));
21679 /* No need to redraw if frame will be redrawn soon. */
21680 if (FRAME_GARBAGED_P (f
))
21682 TRACE ((stderr
, " garbaged\n"));
21687 /* MAC_TODO: this is a kludge, but if scroll bars are not activated
21688 or deactivated here, for unknown reasons, activated scroll bars
21689 are shown in deactivated frames in some instances. */
21690 if (f
== FRAME_MAC_DISPLAY_INFO (f
)->x_focus_frame
)
21691 activate_scroll_bars (f
);
21693 deactivate_scroll_bars (f
);
21696 /* If basic faces haven't been realized yet, there is no point in
21697 trying to redraw anything. This can happen when we get an expose
21698 event while Emacs is starting, e.g. by moving another window. */
21699 if (FRAME_FACE_CACHE (f
) == NULL
21700 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
21702 TRACE ((stderr
, " no faces\n"));
21706 if (w
== 0 || h
== 0)
21709 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
21710 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
21720 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
21721 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
21723 if (WINDOWP (f
->tool_bar_window
))
21724 mouse_face_overwritten_p
21725 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
21727 #ifdef HAVE_X_WINDOWS
21729 #ifndef USE_X_TOOLKIT
21730 if (WINDOWP (f
->menu_bar_window
))
21731 mouse_face_overwritten_p
21732 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
21733 #endif /* not USE_X_TOOLKIT */
21737 /* Some window managers support a focus-follows-mouse style with
21738 delayed raising of frames. Imagine a partially obscured frame,
21739 and moving the mouse into partially obscured mouse-face on that
21740 frame. The visible part of the mouse-face will be highlighted,
21741 then the WM raises the obscured frame. With at least one WM, KDE
21742 2.1, Emacs is not getting any event for the raising of the frame
21743 (even tried with SubstructureRedirectMask), only Expose events.
21744 These expose events will draw text normally, i.e. not
21745 highlighted. Which means we must redo the highlight here.
21746 Subsume it under ``we love X''. --gerd 2001-08-15 */
21747 /* Included in Windows version because Windows most likely does not
21748 do the right thing if any third party tool offers
21749 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
21750 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
21752 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21753 if (f
== dpyinfo
->mouse_face_mouse_frame
)
21755 int x
= dpyinfo
->mouse_face_mouse_x
;
21756 int y
= dpyinfo
->mouse_face_mouse_y
;
21757 clear_mouse_face (dpyinfo
);
21758 note_mouse_highlight (f
, x
, y
);
21765 Determine the intersection of two rectangles R1 and R2. Return
21766 the intersection in *RESULT. Value is non-zero if RESULT is not
21770 x_intersect_rectangles (r1
, r2
, result
)
21771 XRectangle
*r1
, *r2
, *result
;
21773 XRectangle
*left
, *right
;
21774 XRectangle
*upper
, *lower
;
21775 int intersection_p
= 0;
21777 /* Rearrange so that R1 is the left-most rectangle. */
21779 left
= r1
, right
= r2
;
21781 left
= r2
, right
= r1
;
21783 /* X0 of the intersection is right.x0, if this is inside R1,
21784 otherwise there is no intersection. */
21785 if (right
->x
<= left
->x
+ left
->width
)
21787 result
->x
= right
->x
;
21789 /* The right end of the intersection is the minimum of the
21790 the right ends of left and right. */
21791 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
21794 /* Same game for Y. */
21796 upper
= r1
, lower
= r2
;
21798 upper
= r2
, lower
= r1
;
21800 /* The upper end of the intersection is lower.y0, if this is inside
21801 of upper. Otherwise, there is no intersection. */
21802 if (lower
->y
<= upper
->y
+ upper
->height
)
21804 result
->y
= lower
->y
;
21806 /* The lower end of the intersection is the minimum of the lower
21807 ends of upper and lower. */
21808 result
->height
= (min (lower
->y
+ lower
->height
,
21809 upper
->y
+ upper
->height
)
21811 intersection_p
= 1;
21815 return intersection_p
;
21818 #endif /* HAVE_WINDOW_SYSTEM */
21821 /***********************************************************************
21823 ***********************************************************************/
21828 Vwith_echo_area_save_vector
= Qnil
;
21829 staticpro (&Vwith_echo_area_save_vector
);
21831 Vmessage_stack
= Qnil
;
21832 staticpro (&Vmessage_stack
);
21834 Qinhibit_redisplay
= intern ("inhibit-redisplay");
21835 staticpro (&Qinhibit_redisplay
);
21837 message_dolog_marker1
= Fmake_marker ();
21838 staticpro (&message_dolog_marker1
);
21839 message_dolog_marker2
= Fmake_marker ();
21840 staticpro (&message_dolog_marker2
);
21841 message_dolog_marker3
= Fmake_marker ();
21842 staticpro (&message_dolog_marker3
);
21845 defsubr (&Sdump_frame_glyph_matrix
);
21846 defsubr (&Sdump_glyph_matrix
);
21847 defsubr (&Sdump_glyph_row
);
21848 defsubr (&Sdump_tool_bar_row
);
21849 defsubr (&Strace_redisplay
);
21850 defsubr (&Strace_to_stderr
);
21852 #ifdef HAVE_WINDOW_SYSTEM
21853 defsubr (&Stool_bar_lines_needed
);
21854 defsubr (&Slookup_image_map
);
21856 defsubr (&Sformat_mode_line
);
21858 staticpro (&Qmenu_bar_update_hook
);
21859 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
21861 staticpro (&Qoverriding_terminal_local_map
);
21862 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
21864 staticpro (&Qoverriding_local_map
);
21865 Qoverriding_local_map
= intern ("overriding-local-map");
21867 staticpro (&Qwindow_scroll_functions
);
21868 Qwindow_scroll_functions
= intern ("window-scroll-functions");
21870 staticpro (&Qredisplay_end_trigger_functions
);
21871 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
21873 staticpro (&Qinhibit_point_motion_hooks
);
21874 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
21876 QCdata
= intern (":data");
21877 staticpro (&QCdata
);
21878 Qdisplay
= intern ("display");
21879 staticpro (&Qdisplay
);
21880 Qspace_width
= intern ("space-width");
21881 staticpro (&Qspace_width
);
21882 Qraise
= intern ("raise");
21883 staticpro (&Qraise
);
21884 Qslice
= intern ("slice");
21885 staticpro (&Qslice
);
21886 Qspace
= intern ("space");
21887 staticpro (&Qspace
);
21888 Qmargin
= intern ("margin");
21889 staticpro (&Qmargin
);
21890 Qpointer
= intern ("pointer");
21891 staticpro (&Qpointer
);
21892 Qleft_margin
= intern ("left-margin");
21893 staticpro (&Qleft_margin
);
21894 Qright_margin
= intern ("right-margin");
21895 staticpro (&Qright_margin
);
21896 Qcenter
= intern ("center");
21897 staticpro (&Qcenter
);
21898 Qline_height
= intern ("line-height");
21899 staticpro (&Qline_height
);
21900 Qtotal
= intern ("total");
21901 staticpro (&Qtotal
);
21902 QCalign_to
= intern (":align-to");
21903 staticpro (&QCalign_to
);
21904 QCrelative_width
= intern (":relative-width");
21905 staticpro (&QCrelative_width
);
21906 QCrelative_height
= intern (":relative-height");
21907 staticpro (&QCrelative_height
);
21908 QCeval
= intern (":eval");
21909 staticpro (&QCeval
);
21910 QCpropertize
= intern (":propertize");
21911 staticpro (&QCpropertize
);
21912 QCfile
= intern (":file");
21913 staticpro (&QCfile
);
21914 Qfontified
= intern ("fontified");
21915 staticpro (&Qfontified
);
21916 Qfontification_functions
= intern ("fontification-functions");
21917 staticpro (&Qfontification_functions
);
21918 Qtrailing_whitespace
= intern ("trailing-whitespace");
21919 staticpro (&Qtrailing_whitespace
);
21920 Qimage
= intern ("image");
21921 staticpro (&Qimage
);
21922 QCmap
= intern (":map");
21923 staticpro (&QCmap
);
21924 QCpointer
= intern (":pointer");
21925 staticpro (&QCpointer
);
21926 Qrect
= intern ("rect");
21927 staticpro (&Qrect
);
21928 Qcircle
= intern ("circle");
21929 staticpro (&Qcircle
);
21930 Qpoly
= intern ("poly");
21931 staticpro (&Qpoly
);
21932 Qmessage_truncate_lines
= intern ("message-truncate-lines");
21933 staticpro (&Qmessage_truncate_lines
);
21934 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
21935 staticpro (&Qcursor_in_non_selected_windows
);
21936 Qgrow_only
= intern ("grow-only");
21937 staticpro (&Qgrow_only
);
21938 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
21939 staticpro (&Qinhibit_menubar_update
);
21940 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
21941 staticpro (&Qinhibit_eval_during_redisplay
);
21942 Qposition
= intern ("position");
21943 staticpro (&Qposition
);
21944 Qbuffer_position
= intern ("buffer-position");
21945 staticpro (&Qbuffer_position
);
21946 Qobject
= intern ("object");
21947 staticpro (&Qobject
);
21948 Qbar
= intern ("bar");
21950 Qhbar
= intern ("hbar");
21951 staticpro (&Qhbar
);
21952 Qbox
= intern ("box");
21954 Qhollow
= intern ("hollow");
21955 staticpro (&Qhollow
);
21956 Qhand
= intern ("hand");
21957 staticpro (&Qhand
);
21958 Qarrow
= intern ("arrow");
21959 staticpro (&Qarrow
);
21960 Qtext
= intern ("text");
21961 staticpro (&Qtext
);
21962 Qrisky_local_variable
= intern ("risky-local-variable");
21963 staticpro (&Qrisky_local_variable
);
21964 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
21965 staticpro (&Qinhibit_free_realized_faces
);
21967 list_of_error
= Fcons (Fcons (intern ("error"),
21968 Fcons (intern ("void-variable"), Qnil
)),
21970 staticpro (&list_of_error
);
21972 Qlast_arrow_position
= intern ("last-arrow-position");
21973 staticpro (&Qlast_arrow_position
);
21974 Qlast_arrow_string
= intern ("last-arrow-string");
21975 staticpro (&Qlast_arrow_string
);
21977 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
21978 staticpro (&Qoverlay_arrow_string
);
21979 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
21980 staticpro (&Qoverlay_arrow_bitmap
);
21982 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
21983 staticpro (&echo_buffer
[0]);
21984 staticpro (&echo_buffer
[1]);
21986 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
21987 staticpro (&echo_area_buffer
[0]);
21988 staticpro (&echo_area_buffer
[1]);
21990 Vmessages_buffer_name
= build_string ("*Messages*");
21991 staticpro (&Vmessages_buffer_name
);
21993 mode_line_proptrans_alist
= Qnil
;
21994 staticpro (&mode_line_proptrans_alist
);
21996 mode_line_string_list
= Qnil
;
21997 staticpro (&mode_line_string_list
);
21999 help_echo_string
= Qnil
;
22000 staticpro (&help_echo_string
);
22001 help_echo_object
= Qnil
;
22002 staticpro (&help_echo_object
);
22003 help_echo_window
= Qnil
;
22004 staticpro (&help_echo_window
);
22005 previous_help_echo_string
= Qnil
;
22006 staticpro (&previous_help_echo_string
);
22007 help_echo_pos
= -1;
22009 #ifdef HAVE_WINDOW_SYSTEM
22010 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
22011 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
22012 For example, if a block cursor is over a tab, it will be drawn as
22013 wide as that tab on the display. */);
22014 x_stretch_cursor_p
= 0;
22017 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
22018 doc
: /* *Non-nil means highlight trailing whitespace.
22019 The face used for trailing whitespace is `trailing-whitespace'. */);
22020 Vshow_trailing_whitespace
= Qnil
;
22022 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
22023 doc
: /* *The pointer shape to show in void text areas.
22024 Nil means to show the text pointer. Other options are `arrow', `text',
22025 `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
22026 Vvoid_text_area_pointer
= Qarrow
;
22028 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
22029 doc
: /* Non-nil means don't actually do any redisplay.
22030 This is used for internal purposes. */);
22031 Vinhibit_redisplay
= Qnil
;
22033 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
22034 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
22035 Vglobal_mode_string
= Qnil
;
22037 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
22038 doc
: /* Marker for where to display an arrow on top of the buffer text.
22039 This must be the beginning of a line in order to work.
22040 See also `overlay-arrow-string'. */);
22041 Voverlay_arrow_position
= Qnil
;
22043 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
22044 doc
: /* String to display as an arrow in non-window frames.
22045 See also `overlay-arrow-position'. */);
22046 Voverlay_arrow_string
= Qnil
;
22048 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
22049 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
22050 The symbols on this list are examined during redisplay to determine
22051 where to display overlay arrows. */);
22052 Voverlay_arrow_variable_list
22053 = Fcons (intern ("overlay-arrow-position"), Qnil
);
22055 DEFVAR_INT ("scroll-step", &scroll_step
,
22056 doc
: /* *The number of lines to try scrolling a window by when point moves out.
22057 If that fails to bring point back on frame, point is centered instead.
22058 If this is zero, point is always centered after it moves off frame.
22059 If you want scrolling to always be a line at a time, you should set
22060 `scroll-conservatively' to a large value rather than set this to 1. */);
22062 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
22063 doc
: /* *Scroll up to this many lines, to bring point back on screen.
22064 A value of zero means to scroll the text to center point vertically
22065 in the window. */);
22066 scroll_conservatively
= 0;
22068 DEFVAR_INT ("scroll-margin", &scroll_margin
,
22069 doc
: /* *Number of lines of margin at the top and bottom of a window.
22070 Recenter the window whenever point gets within this many lines
22071 of the top or bottom of the window. */);
22074 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
22075 doc
: /* Pixels per inch on current display.
22076 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
22077 Vdisplay_pixels_per_inch
= make_float (72.0);
22080 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
22083 DEFVAR_BOOL ("truncate-partial-width-windows",
22084 &truncate_partial_width_windows
,
22085 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
22086 truncate_partial_width_windows
= 1;
22088 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
22089 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
22090 Any other value means to use the appropriate face, `mode-line',
22091 `header-line', or `menu' respectively. */);
22092 mode_line_inverse_video
= 1;
22094 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
22095 doc
: /* *Maximum buffer size for which line number should be displayed.
22096 If the buffer is bigger than this, the line number does not appear
22097 in the mode line. A value of nil means no limit. */);
22098 Vline_number_display_limit
= Qnil
;
22100 DEFVAR_INT ("line-number-display-limit-width",
22101 &line_number_display_limit_width
,
22102 doc
: /* *Maximum line width (in characters) for line number display.
22103 If the average length of the lines near point is bigger than this, then the
22104 line number may be omitted from the mode line. */);
22105 line_number_display_limit_width
= 200;
22107 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
22108 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
22109 highlight_nonselected_windows
= 0;
22111 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
22112 doc
: /* Non-nil if more than one frame is visible on this display.
22113 Minibuffer-only frames don't count, but iconified frames do.
22114 This variable is not guaranteed to be accurate except while processing
22115 `frame-title-format' and `icon-title-format'. */);
22117 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
22118 doc
: /* Template for displaying the title bar of visible frames.
22119 \(Assuming the window manager supports this feature.)
22120 This variable has the same structure as `mode-line-format' (which see),
22121 and is used only on frames for which no explicit name has been set
22122 \(see `modify-frame-parameters'). */);
22124 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
22125 doc
: /* Template for displaying the title bar of an iconified frame.
22126 \(Assuming the window manager supports this feature.)
22127 This variable has the same structure as `mode-line-format' (which see),
22128 and is used only on frames for which no explicit name has been set
22129 \(see `modify-frame-parameters'). */);
22131 = Vframe_title_format
22132 = Fcons (intern ("multiple-frames"),
22133 Fcons (build_string ("%b"),
22134 Fcons (Fcons (empty_string
,
22135 Fcons (intern ("invocation-name"),
22136 Fcons (build_string ("@"),
22137 Fcons (intern ("system-name"),
22141 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
22142 doc
: /* Maximum number of lines to keep in the message log buffer.
22143 If nil, disable message logging. If t, log messages but don't truncate
22144 the buffer when it becomes large. */);
22145 Vmessage_log_max
= make_number (50);
22147 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
22148 doc
: /* Functions called before redisplay, if window sizes have changed.
22149 The value should be a list of functions that take one argument.
22150 Just before redisplay, for each frame, if any of its windows have changed
22151 size since the last redisplay, or have been split or deleted,
22152 all the functions in the list are called, with the frame as argument. */);
22153 Vwindow_size_change_functions
= Qnil
;
22155 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
22156 doc
: /* List of Functions to call before redisplaying a window with scrolling.
22157 Each function is called with two arguments, the window
22158 and its new display-start position. Note that the value of `window-end'
22159 is not valid when these functions are called. */);
22160 Vwindow_scroll_functions
= Qnil
;
22162 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
22163 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
22164 mouse_autoselect_window
= 0;
22166 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
22167 doc
: /* *Non-nil means automatically resize tool-bars.
22168 This increases a tool-bar's height if not all tool-bar items are visible.
22169 It decreases a tool-bar's height when it would display blank lines
22171 auto_resize_tool_bars_p
= 1;
22173 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
22174 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
22175 auto_raise_tool_bar_buttons_p
= 1;
22177 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
22178 doc
: /* *Margin around tool-bar buttons in pixels.
22179 If an integer, use that for both horizontal and vertical margins.
22180 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
22181 HORZ specifying the horizontal margin, and VERT specifying the
22182 vertical margin. */);
22183 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
22185 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
22186 doc
: /* *Relief thickness of tool-bar buttons. */);
22187 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
22189 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
22190 doc
: /* List of functions to call to fontify regions of text.
22191 Each function is called with one argument POS. Functions must
22192 fontify a region starting at POS in the current buffer, and give
22193 fontified regions the property `fontified'. */);
22194 Vfontification_functions
= Qnil
;
22195 Fmake_variable_buffer_local (Qfontification_functions
);
22197 DEFVAR_BOOL ("unibyte-display-via-language-environment",
22198 &unibyte_display_via_language_environment
,
22199 doc
: /* *Non-nil means display unibyte text according to language environment.
22200 Specifically this means that unibyte non-ASCII characters
22201 are displayed by converting them to the equivalent multibyte characters
22202 according to the current language environment. As a result, they are
22203 displayed according to the current fontset. */);
22204 unibyte_display_via_language_environment
= 0;
22206 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
22207 doc
: /* *Maximum height for resizing mini-windows.
22208 If a float, it specifies a fraction of the mini-window frame's height.
22209 If an integer, it specifies a number of lines. */);
22210 Vmax_mini_window_height
= make_float (0.25);
22212 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
22213 doc
: /* *How to resize mini-windows.
22214 A value of nil means don't automatically resize mini-windows.
22215 A value of t means resize them to fit the text displayed in them.
22216 A value of `grow-only', the default, means let mini-windows grow
22217 only, until their display becomes empty, at which point the windows
22218 go back to their normal size. */);
22219 Vresize_mini_windows
= Qgrow_only
;
22221 DEFVAR_LISP ("cursor-in-non-selected-windows",
22222 &Vcursor_in_non_selected_windows
,
22223 doc
: /* *Cursor type to display in non-selected windows.
22224 t means to use hollow box cursor. See `cursor-type' for other values. */);
22225 Vcursor_in_non_selected_windows
= Qt
;
22227 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
22228 doc
: /* Alist specifying how to blink the cursor off.
22229 Each element has the form (ON-STATE . OFF-STATE). Whenever the
22230 `cursor-type' frame-parameter or variable equals ON-STATE,
22231 comparing using `equal', Emacs uses OFF-STATE to specify
22232 how to blink it off. */);
22233 Vblink_cursor_alist
= Qnil
;
22235 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
22236 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
22237 automatic_hscrolling_p
= 1;
22239 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
22240 doc
: /* *How many columns away from the window edge point is allowed to get
22241 before automatic hscrolling will horizontally scroll the window. */);
22242 hscroll_margin
= 5;
22244 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
22245 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
22246 When point is less than `automatic-hscroll-margin' columns from the window
22247 edge, automatic hscrolling will scroll the window by the amount of columns
22248 determined by this variable. If its value is a positive integer, scroll that
22249 many columns. If it's a positive floating-point number, it specifies the
22250 fraction of the window's width to scroll. If it's nil or zero, point will be
22251 centered horizontally after the scroll. Any other value, including negative
22252 numbers, are treated as if the value were zero.
22254 Automatic hscrolling always moves point outside the scroll margin, so if
22255 point was more than scroll step columns inside the margin, the window will
22256 scroll more than the value given by the scroll step.
22258 Note that the lower bound for automatic hscrolling specified by `scroll-left'
22259 and `scroll-right' overrides this variable's effect. */);
22260 Vhscroll_step
= make_number (0);
22262 DEFVAR_LISP ("image-types", &Vimage_types
,
22263 doc
: /* List of supported image types.
22264 Each element of the list is a symbol for a supported image type. */);
22265 Vimage_types
= Qnil
;
22267 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
22268 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
22269 Bind this around calls to `message' to let it take effect. */);
22270 message_truncate_lines
= 0;
22272 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
22273 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
22274 Can be used to update submenus whose contents should vary. */);
22275 Vmenu_bar_update_hook
= Qnil
;
22277 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
22278 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
22279 inhibit_menubar_update
= 0;
22281 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
22282 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
22283 inhibit_eval_during_redisplay
= 0;
22285 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
22286 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
22287 inhibit_free_realized_faces
= 0;
22290 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
22291 doc
: /* Inhibit try_window_id display optimization. */);
22292 inhibit_try_window_id
= 0;
22294 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
22295 doc
: /* Inhibit try_window_reusing display optimization. */);
22296 inhibit_try_window_reusing
= 0;
22298 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
22299 doc
: /* Inhibit try_cursor_movement display optimization. */);
22300 inhibit_try_cursor_movement
= 0;
22301 #endif /* GLYPH_DEBUG */
22305 /* Initialize this module when Emacs starts. */
22310 Lisp_Object root_window
;
22311 struct window
*mini_w
;
22313 current_header_line_height
= current_mode_line_height
= -1;
22315 CHARPOS (this_line_start_pos
) = 0;
22317 mini_w
= XWINDOW (minibuf_window
);
22318 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
22320 if (!noninteractive
)
22322 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
22325 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
22326 set_window_height (root_window
,
22327 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
22329 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
22330 set_window_height (minibuf_window
, 1, 0);
22332 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
22333 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
22335 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
22336 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
22337 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
22339 /* The default ellipsis glyphs `...'. */
22340 for (i
= 0; i
< 3; ++i
)
22341 default_invis_vector
[i
] = make_number ('.');
22345 /* Allocate the buffer for frame titles.
22346 Also used for `format-mode-line'. */
22348 frame_title_buf
= (char *) xmalloc (size
);
22349 frame_title_buf_end
= frame_title_buf
+ size
;
22350 frame_title_ptr
= NULL
;
22353 help_echo_showing_p
= 0;
22357 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
22358 (do not change this comment) */