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
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
205 #ifndef FRAME_X_OUTPUT
206 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
209 #define INFINITY 10000000
211 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
213 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
214 extern int pending_menu_activation
;
217 extern int interrupt_input
;
218 extern int command_loop_level
;
220 extern int minibuffer_auto_raise
;
221 extern Lisp_Object Vminibuffer_list
;
223 extern Lisp_Object Qface
;
224 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
226 extern Lisp_Object Voverriding_local_map
;
227 extern Lisp_Object Voverriding_local_map_menu_flag
;
228 extern Lisp_Object Qmenu_item
;
229 extern Lisp_Object Qwhen
;
230 extern Lisp_Object Qhelp_echo
;
232 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
233 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
234 Lisp_Object Qredisplay_end_trigger_functions
;
235 Lisp_Object Qinhibit_point_motion_hooks
;
236 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
237 Lisp_Object Qfontified
;
238 Lisp_Object Qgrow_only
;
239 Lisp_Object Qinhibit_eval_during_redisplay
;
240 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
243 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
246 Lisp_Object Qarrow
, Qhand
, Qtext
;
248 Lisp_Object Qrisky_local_variable
;
250 /* Holds the list (error). */
251 Lisp_Object list_of_error
;
253 /* Functions called to fontify regions of text. */
255 Lisp_Object Vfontification_functions
;
256 Lisp_Object Qfontification_functions
;
258 /* Non-zero means automatically select any window when the mouse
259 cursor moves into it. */
260 int mouse_autoselect_window
;
262 /* Non-zero means draw tool bar buttons raised when the mouse moves
265 int auto_raise_tool_bar_buttons_p
;
267 /* Margin around tool bar buttons in pixels. */
269 Lisp_Object Vtool_bar_button_margin
;
271 /* Thickness of shadow to draw around tool bar buttons. */
273 EMACS_INT tool_bar_button_relief
;
275 /* Non-zero means automatically resize tool-bars so that all tool-bar
276 items are visible, and no blank lines remain. */
278 int auto_resize_tool_bars_p
;
280 /* Non-zero means draw block and hollow cursor as wide as the glyph
281 under it. For example, if a block cursor is over a tab, it will be
282 drawn as wide as that tab on the display. */
284 int x_stretch_cursor_p
;
286 /* Non-nil means don't actually do any redisplay. */
288 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
290 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
292 int inhibit_eval_during_redisplay
;
294 /* Names of text properties relevant for redisplay. */
296 Lisp_Object Qdisplay
;
297 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
299 /* Symbols used in text property values. */
301 Lisp_Object Vdisplay_pixels_per_inch
;
302 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
303 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
304 Lisp_Object Qmargin
, Qpointer
;
305 extern Lisp_Object Qheight
;
306 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
307 extern Lisp_Object Qscroll_bar
;
309 /* Non-nil means highlight trailing whitespace. */
311 Lisp_Object Vshow_trailing_whitespace
;
313 /* Non-nil means show the text cursor in void text areas
314 i.e. in blank areas after eol and eob. This used to be
315 the default in 21.3. */
317 Lisp_Object Vvoid_text_area_pointer
;
319 /* Name of the face used to highlight trailing whitespace. */
321 Lisp_Object Qtrailing_whitespace
;
323 /* The symbol `image' which is the car of the lists used to represent
328 /* The image map types. */
329 Lisp_Object QCmap
, QCpointer
;
330 Lisp_Object Qrect
, Qcircle
, Qpoly
;
332 /* Non-zero means print newline to stdout before next mini-buffer
335 int noninteractive_need_newline
;
337 /* Non-zero means print newline to message log before next message. */
339 static int message_log_need_newline
;
341 /* Three markers that message_dolog uses.
342 It could allocate them itself, but that causes trouble
343 in handling memory-full errors. */
344 static Lisp_Object message_dolog_marker1
;
345 static Lisp_Object message_dolog_marker2
;
346 static Lisp_Object message_dolog_marker3
;
348 /* The buffer position of the first character appearing entirely or
349 partially on the line of the selected window which contains the
350 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
351 redisplay optimization in redisplay_internal. */
353 static struct text_pos this_line_start_pos
;
355 /* Number of characters past the end of the line above, including the
356 terminating newline. */
358 static struct text_pos this_line_end_pos
;
360 /* The vertical positions and the height of this line. */
362 static int this_line_vpos
;
363 static int this_line_y
;
364 static int this_line_pixel_height
;
366 /* X position at which this display line starts. Usually zero;
367 negative if first character is partially visible. */
369 static int this_line_start_x
;
371 /* Buffer that this_line_.* variables are referring to. */
373 static struct buffer
*this_line_buffer
;
375 /* Nonzero means truncate lines in all windows less wide than the
378 int truncate_partial_width_windows
;
380 /* A flag to control how to display unibyte 8-bit character. */
382 int unibyte_display_via_language_environment
;
384 /* Nonzero means we have more than one non-mini-buffer-only frame.
385 Not guaranteed to be accurate except while parsing
386 frame-title-format. */
390 Lisp_Object Vglobal_mode_string
;
392 /* Marker for where to display an arrow on top of the buffer text. */
394 Lisp_Object Voverlay_arrow_position
;
396 /* String to display for the arrow. Only used on terminal frames. */
398 Lisp_Object Voverlay_arrow_string
;
400 /* Values of those variables at last redisplay. However, if
401 Voverlay_arrow_position is a marker, last_arrow_position is its
402 numerical position. */
404 static Lisp_Object last_arrow_position
, last_arrow_string
;
406 /* Like mode-line-format, but for the title bar on a visible frame. */
408 Lisp_Object Vframe_title_format
;
410 /* Like mode-line-format, but for the title bar on an iconified frame. */
412 Lisp_Object Vicon_title_format
;
414 /* List of functions to call when a window's size changes. These
415 functions get one arg, a frame on which one or more windows' sizes
418 static Lisp_Object Vwindow_size_change_functions
;
420 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
422 /* Nonzero if overlay arrow has been displayed once in this window. */
424 static int overlay_arrow_seen
;
426 /* Nonzero means highlight the region even in nonselected windows. */
428 int highlight_nonselected_windows
;
430 /* If cursor motion alone moves point off frame, try scrolling this
431 many lines up or down if that will bring it back. */
433 static EMACS_INT scroll_step
;
435 /* Nonzero means scroll just far enough to bring point back on the
436 screen, when appropriate. */
438 static EMACS_INT scroll_conservatively
;
440 /* Recenter the window whenever point gets within this many lines of
441 the top or bottom of the window. This value is translated into a
442 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
443 that there is really a fixed pixel height scroll margin. */
445 EMACS_INT scroll_margin
;
447 /* Number of windows showing the buffer of the selected window (or
448 another buffer with the same base buffer). keyboard.c refers to
453 /* Vector containing glyphs for an ellipsis `...'. */
455 static Lisp_Object default_invis_vector
[3];
457 /* Zero means display the mode-line/header-line/menu-bar in the default face
458 (this slightly odd definition is for compatibility with previous versions
459 of emacs), non-zero means display them using their respective faces.
461 This variable is deprecated. */
463 int mode_line_inverse_video
;
465 /* Prompt to display in front of the mini-buffer contents. */
467 Lisp_Object minibuf_prompt
;
469 /* Width of current mini-buffer prompt. Only set after display_line
470 of the line that contains the prompt. */
472 int minibuf_prompt_width
;
474 /* This is the window where the echo area message was displayed. It
475 is always a mini-buffer window, but it may not be the same window
476 currently active as a mini-buffer. */
478 Lisp_Object echo_area_window
;
480 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
481 pushes the current message and the value of
482 message_enable_multibyte on the stack, the function restore_message
483 pops the stack and displays MESSAGE again. */
485 Lisp_Object Vmessage_stack
;
487 /* Nonzero means multibyte characters were enabled when the echo area
488 message was specified. */
490 int message_enable_multibyte
;
492 /* Nonzero if we should redraw the mode lines on the next redisplay. */
494 int update_mode_lines
;
496 /* Nonzero if window sizes or contents have changed since last
497 redisplay that finished. */
499 int windows_or_buffers_changed
;
501 /* Nonzero means a frame's cursor type has been changed. */
503 int cursor_type_changed
;
505 /* Nonzero after display_mode_line if %l was used and it displayed a
508 int line_number_displayed
;
510 /* Maximum buffer size for which to display line numbers. */
512 Lisp_Object Vline_number_display_limit
;
514 /* Line width to consider when repositioning for line number display. */
516 static EMACS_INT line_number_display_limit_width
;
518 /* Number of lines to keep in the message log buffer. t means
519 infinite. nil means don't log at all. */
521 Lisp_Object Vmessage_log_max
;
523 /* The name of the *Messages* buffer, a string. */
525 static Lisp_Object Vmessages_buffer_name
;
527 /* Current, index 0, and last displayed echo area message. Either
528 buffers from echo_buffers, or nil to indicate no message. */
530 Lisp_Object echo_area_buffer
[2];
532 /* The buffers referenced from echo_area_buffer. */
534 static Lisp_Object echo_buffer
[2];
536 /* A vector saved used in with_area_buffer to reduce consing. */
538 static Lisp_Object Vwith_echo_area_save_vector
;
540 /* Non-zero means display_echo_area should display the last echo area
541 message again. Set by redisplay_preserve_echo_area. */
543 static int display_last_displayed_message_p
;
545 /* Nonzero if echo area is being used by print; zero if being used by
548 int message_buf_print
;
550 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
552 Lisp_Object Qinhibit_menubar_update
;
553 int inhibit_menubar_update
;
555 /* Maximum height for resizing mini-windows. Either a float
556 specifying a fraction of the available height, or an integer
557 specifying a number of lines. */
559 Lisp_Object Vmax_mini_window_height
;
561 /* Non-zero means messages should be displayed with truncated
562 lines instead of being continued. */
564 int message_truncate_lines
;
565 Lisp_Object Qmessage_truncate_lines
;
567 /* Set to 1 in clear_message to make redisplay_internal aware
568 of an emptied echo area. */
570 static int message_cleared_p
;
572 /* Non-zero means we want a hollow cursor in windows that are not
573 selected. Zero means there's no cursor in such windows. */
575 Lisp_Object Vcursor_in_non_selected_windows
;
576 Lisp_Object Qcursor_in_non_selected_windows
;
578 /* How to blink the default frame cursor off. */
579 Lisp_Object Vblink_cursor_alist
;
581 /* A scratch glyph row with contents used for generating truncation
582 glyphs. Also used in direct_output_for_insert. */
584 #define MAX_SCRATCH_GLYPHS 100
585 struct glyph_row scratch_glyph_row
;
586 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
588 /* Ascent and height of the last line processed by move_it_to. */
590 static int last_max_ascent
, last_height
;
592 /* Non-zero if there's a help-echo in the echo area. */
594 int help_echo_showing_p
;
596 /* If >= 0, computed, exact values of mode-line and header-line height
597 to use in the macros CURRENT_MODE_LINE_HEIGHT and
598 CURRENT_HEADER_LINE_HEIGHT. */
600 int current_mode_line_height
, current_header_line_height
;
602 /* The maximum distance to look ahead for text properties. Values
603 that are too small let us call compute_char_face and similar
604 functions too often which is expensive. Values that are too large
605 let us call compute_char_face and alike too often because we
606 might not be interested in text properties that far away. */
608 #define TEXT_PROP_DISTANCE_LIMIT 100
612 /* Variables to turn off display optimizations from Lisp. */
614 int inhibit_try_window_id
, inhibit_try_window_reusing
;
615 int inhibit_try_cursor_movement
;
617 /* Non-zero means print traces of redisplay if compiled with
620 int trace_redisplay_p
;
622 #endif /* GLYPH_DEBUG */
624 #ifdef DEBUG_TRACE_MOVE
625 /* Non-zero means trace with TRACE_MOVE to stderr. */
628 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
630 #define TRACE_MOVE(x) (void) 0
633 /* Non-zero means automatically scroll windows horizontally to make
636 int automatic_hscrolling_p
;
638 /* How close to the margin can point get before the window is scrolled
640 EMACS_INT hscroll_margin
;
642 /* How much to scroll horizontally when point is inside the above margin. */
643 Lisp_Object Vhscroll_step
;
645 /* A list of symbols, one for each supported image type. */
647 Lisp_Object Vimage_types
;
649 /* The variable `resize-mini-windows'. If nil, don't resize
650 mini-windows. If t, always resize them to fit the text they
651 display. If `grow-only', let mini-windows grow only until they
654 Lisp_Object Vresize_mini_windows
;
656 /* Buffer being redisplayed -- for redisplay_window_error. */
658 struct buffer
*displayed_buffer
;
660 /* Value returned from text property handlers (see below). */
665 HANDLED_RECOMPUTE_PROPS
,
666 HANDLED_OVERLAY_STRING_CONSUMED
,
670 /* A description of text properties that redisplay is interested
675 /* The name of the property. */
678 /* A unique index for the property. */
681 /* A handler function called to set up iterator IT from the property
682 at IT's current position. Value is used to steer handle_stop. */
683 enum prop_handled (*handler
) P_ ((struct it
*it
));
686 static enum prop_handled handle_face_prop
P_ ((struct it
*));
687 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
688 static enum prop_handled handle_display_prop
P_ ((struct it
*));
689 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
690 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
691 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
693 /* Properties handled by iterators. */
695 static struct props it_props
[] =
697 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
698 /* Handle `face' before `display' because some sub-properties of
699 `display' need to know the face. */
700 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
701 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
702 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
703 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
707 /* Value is the position described by X. If X is a marker, value is
708 the marker_position of X. Otherwise, value is X. */
710 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
712 /* Enumeration returned by some move_it_.* functions internally. */
716 /* Not used. Undefined value. */
719 /* Move ended at the requested buffer position or ZV. */
720 MOVE_POS_MATCH_OR_ZV
,
722 /* Move ended at the requested X pixel position. */
725 /* Move within a line ended at the end of a line that must be
729 /* Move within a line ended at the end of a line that would
730 be displayed truncated. */
733 /* Move within a line ended at a line end. */
737 /* This counter is used to clear the face cache every once in a while
738 in redisplay_internal. It is incremented for each redisplay.
739 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
742 #define CLEAR_FACE_CACHE_COUNT 500
743 static int clear_face_cache_count
;
745 /* Non-zero while redisplay_internal is in progress. */
749 /* Non-zero means don't free realized faces. Bound while freeing
750 realized faces is dangerous because glyph matrices might still
753 int inhibit_free_realized_faces
;
754 Lisp_Object Qinhibit_free_realized_faces
;
756 /* If a string, XTread_socket generates an event to display that string.
757 (The display is done in read_char.) */
759 Lisp_Object help_echo_string
;
760 Lisp_Object help_echo_window
;
761 Lisp_Object help_echo_object
;
764 /* Temporary variable for XTread_socket. */
766 Lisp_Object previous_help_echo_string
;
770 /* Function prototypes. */
772 static void setup_for_ellipsis
P_ ((struct it
*));
773 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
774 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
775 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
776 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
777 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
778 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
781 static int invisible_text_between_p
P_ ((struct it
*, int, int));
784 static int next_element_from_ellipsis
P_ ((struct it
*));
785 static void pint2str
P_ ((char *, int, int));
786 static void pint2hrstr
P_ ((char *, int, int));
787 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
789 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
790 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
791 static void store_frame_title_char
P_ ((char));
792 static int store_frame_title
P_ ((const unsigned char *, int, int));
793 static void x_consider_frame_title
P_ ((Lisp_Object
));
794 static void handle_stop
P_ ((struct it
*));
795 static int tool_bar_lines_needed
P_ ((struct frame
*));
796 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
797 static void ensure_echo_area_buffers
P_ ((void));
798 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
799 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
800 static int with_echo_area_buffer
P_ ((struct window
*, int,
801 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
802 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
803 static void clear_garbaged_frames
P_ ((void));
804 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
805 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
806 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
807 static int display_echo_area
P_ ((struct window
*));
808 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
809 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
810 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
811 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
812 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
814 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
815 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
816 static void insert_left_trunc_glyphs
P_ ((struct it
*));
817 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
818 static void extend_face_to_end_of_line
P_ ((struct it
*));
819 static int append_space
P_ ((struct it
*, int));
820 static int make_cursor_line_fully_visible
P_ ((struct window
*));
821 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
822 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
823 static int trailing_whitespace_p
P_ ((int));
824 static int message_log_check_duplicate
P_ ((int, int, int, int));
825 static void push_it
P_ ((struct it
*));
826 static void pop_it
P_ ((struct it
*));
827 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
828 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
829 static void redisplay_internal
P_ ((int));
830 static int echo_area_display
P_ ((int));
831 static void redisplay_windows
P_ ((Lisp_Object
));
832 static void redisplay_window
P_ ((Lisp_Object
, int));
833 static Lisp_Object
redisplay_window_error ();
834 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
835 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
836 static void update_menu_bar
P_ ((struct frame
*, int));
837 static int try_window_reusing_current_matrix
P_ ((struct window
*));
838 static int try_window_id
P_ ((struct window
*));
839 static int display_line
P_ ((struct it
*));
840 static int display_mode_lines
P_ ((struct window
*));
841 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
842 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
843 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
844 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
845 static void display_menu_bar
P_ ((struct window
*));
846 static int display_count_lines
P_ ((int, int, int, int, int *));
847 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
848 int, int, struct it
*, int, int, int, int));
849 static void compute_line_metrics
P_ ((struct it
*));
850 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
851 static int get_overlay_strings
P_ ((struct it
*, int));
852 static void next_overlay_string
P_ ((struct it
*));
853 static void reseat
P_ ((struct it
*, struct text_pos
, int));
854 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
855 static void back_to_previous_visible_line_start
P_ ((struct it
*));
856 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
857 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
858 static int next_element_from_display_vector
P_ ((struct it
*));
859 static int next_element_from_string
P_ ((struct it
*));
860 static int next_element_from_c_string
P_ ((struct it
*));
861 static int next_element_from_buffer
P_ ((struct it
*));
862 static int next_element_from_composition
P_ ((struct it
*));
863 static int next_element_from_image
P_ ((struct it
*));
864 static int next_element_from_stretch
P_ ((struct it
*));
865 static void load_overlay_strings
P_ ((struct it
*, int));
866 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
867 struct display_pos
*));
868 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
869 Lisp_Object
, int, int, int, int));
870 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
872 void move_it_vertically_backward
P_ ((struct it
*, int));
873 static void init_to_row_start
P_ ((struct it
*, struct window
*,
874 struct glyph_row
*));
875 static int init_to_row_end
P_ ((struct it
*, struct window
*,
876 struct glyph_row
*));
877 static void back_to_previous_line_start
P_ ((struct it
*));
878 static int forward_to_next_line_start
P_ ((struct it
*, int *));
879 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
881 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
882 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
883 static int number_of_chars
P_ ((unsigned char *, int));
884 static void compute_stop_pos
P_ ((struct it
*));
885 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
887 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
888 static int next_overlay_change
P_ ((int));
889 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
890 Lisp_Object
, struct text_pos
*,
892 static int underlying_face_id
P_ ((struct it
*));
893 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
896 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
897 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
899 #ifdef HAVE_WINDOW_SYSTEM
901 static void update_tool_bar
P_ ((struct frame
*, int));
902 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
903 static int redisplay_tool_bar
P_ ((struct frame
*));
904 static void display_tool_bar_line
P_ ((struct it
*));
905 static void notice_overwritten_cursor
P_ ((struct window
*,
907 int, int, int, int));
911 #endif /* HAVE_WINDOW_SYSTEM */
914 /***********************************************************************
915 Window display dimensions
916 ***********************************************************************/
918 /* Return the bottom boundary y-position for text lines in window W.
919 This is the first y position at which a line cannot start.
920 It is relative to the top of the window.
922 This is the height of W minus the height of a mode line, if any. */
925 window_text_bottom_y (w
)
928 int height
= WINDOW_TOTAL_HEIGHT (w
);
930 if (WINDOW_WANTS_MODELINE_P (w
))
931 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
935 /* Return the pixel width of display area AREA of window W. AREA < 0
936 means return the total width of W, not including fringes to
937 the left and right of the window. */
940 window_box_width (w
, area
)
944 int cols
= XFASTINT (w
->total_cols
);
947 if (!w
->pseudo_window_p
)
949 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
951 if (area
== TEXT_AREA
)
953 if (INTEGERP (w
->left_margin_cols
))
954 cols
-= XFASTINT (w
->left_margin_cols
);
955 if (INTEGERP (w
->right_margin_cols
))
956 cols
-= XFASTINT (w
->right_margin_cols
);
957 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
959 else if (area
== LEFT_MARGIN_AREA
)
961 cols
= (INTEGERP (w
->left_margin_cols
)
962 ? XFASTINT (w
->left_margin_cols
) : 0);
965 else if (area
== RIGHT_MARGIN_AREA
)
967 cols
= (INTEGERP (w
->right_margin_cols
)
968 ? XFASTINT (w
->right_margin_cols
) : 0);
973 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
977 /* Return the pixel height of the display area of window W, not
978 including mode lines of W, if any. */
981 window_box_height (w
)
984 struct frame
*f
= XFRAME (w
->frame
);
985 int height
= WINDOW_TOTAL_HEIGHT (w
);
987 xassert (height
>= 0);
989 /* Note: the code below that determines the mode-line/header-line
990 height is essentially the same as that contained in the macro
991 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
992 the appropriate glyph row has its `mode_line_p' flag set,
993 and if it doesn't, uses estimate_mode_line_height instead. */
995 if (WINDOW_WANTS_MODELINE_P (w
))
997 struct glyph_row
*ml_row
998 = (w
->current_matrix
&& w
->current_matrix
->rows
999 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1001 if (ml_row
&& ml_row
->mode_line_p
)
1002 height
-= ml_row
->height
;
1004 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1007 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1009 struct glyph_row
*hl_row
1010 = (w
->current_matrix
&& w
->current_matrix
->rows
1011 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1013 if (hl_row
&& hl_row
->mode_line_p
)
1014 height
-= hl_row
->height
;
1016 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1019 /* With a very small font and a mode-line that's taller than
1020 default, we might end up with a negative height. */
1021 return max (0, height
);
1024 /* Return the window-relative coordinate of the left edge of display
1025 area AREA of window W. AREA < 0 means return the left edge of the
1026 whole window, to the right of the left fringe of W. */
1029 window_box_left_offset (w
, area
)
1035 if (w
->pseudo_window_p
)
1038 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1040 if (area
== TEXT_AREA
)
1041 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1042 + window_box_width (w
, LEFT_MARGIN_AREA
));
1043 else if (area
== RIGHT_MARGIN_AREA
)
1044 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1045 + window_box_width (w
, LEFT_MARGIN_AREA
)
1046 + window_box_width (w
, TEXT_AREA
)
1047 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1049 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1050 else if (area
== LEFT_MARGIN_AREA
1051 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1052 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1058 /* Return the window-relative coordinate of the right edge of display
1059 area AREA of window W. AREA < 0 means return the left edge of the
1060 whole window, to the left of the right fringe of W. */
1063 window_box_right_offset (w
, area
)
1067 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1070 /* Return the frame-relative coordinate of the left edge of display
1071 area AREA of window W. AREA < 0 means return the left edge of the
1072 whole window, to the right of the left fringe of W. */
1075 window_box_left (w
, area
)
1079 struct frame
*f
= XFRAME (w
->frame
);
1082 if (w
->pseudo_window_p
)
1083 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1085 x
= (WINDOW_LEFT_EDGE_X (w
)
1086 + window_box_left_offset (w
, area
));
1092 /* Return the frame-relative coordinate of the right edge of display
1093 area AREA of window W. AREA < 0 means return the left edge of the
1094 whole window, to the left of the right fringe of W. */
1097 window_box_right (w
, area
)
1101 return window_box_left (w
, area
) + window_box_width (w
, area
);
1104 /* Get the bounding box of the display area AREA of window W, without
1105 mode lines, in frame-relative coordinates. AREA < 0 means the
1106 whole window, not including the left and right fringes of
1107 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1108 coordinates of the upper-left corner of the box. Return in
1109 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1112 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1115 int *box_x
, *box_y
, *box_width
, *box_height
;
1118 *box_width
= window_box_width (w
, area
);
1120 *box_height
= window_box_height (w
);
1122 *box_x
= window_box_left (w
, area
);
1125 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1126 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1127 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1132 /* Get the bounding box of the display area AREA of window W, without
1133 mode lines. AREA < 0 means the whole window, not including the
1134 left and right fringe of the window. Return in *TOP_LEFT_X
1135 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1136 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1137 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1141 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1142 bottom_right_x
, bottom_right_y
)
1145 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1147 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1149 *bottom_right_x
+= *top_left_x
;
1150 *bottom_right_y
+= *top_left_y
;
1155 /***********************************************************************
1157 ***********************************************************************/
1159 /* Return the bottom y-position of the line the iterator IT is in.
1160 This can modify IT's settings. */
1166 int line_height
= it
->max_ascent
+ it
->max_descent
;
1167 int line_top_y
= it
->current_y
;
1169 if (line_height
== 0)
1172 line_height
= last_height
;
1173 else if (IT_CHARPOS (*it
) < ZV
)
1175 move_it_by_lines (it
, 1, 1);
1176 line_height
= (it
->max_ascent
|| it
->max_descent
1177 ? it
->max_ascent
+ it
->max_descent
1182 struct glyph_row
*row
= it
->glyph_row
;
1184 /* Use the default character height. */
1185 it
->glyph_row
= NULL
;
1186 it
->what
= IT_CHARACTER
;
1189 PRODUCE_GLYPHS (it
);
1190 line_height
= it
->ascent
+ it
->descent
;
1191 it
->glyph_row
= row
;
1195 return line_top_y
+ line_height
;
1199 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1200 1 if POS is visible and the line containing POS is fully visible.
1201 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1202 and header-lines heights. */
1205 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
1207 int charpos
, *fully
, exact_mode_line_heights_p
;
1210 struct text_pos top
;
1212 struct buffer
*old_buffer
= NULL
;
1214 if (XBUFFER (w
->buffer
) != current_buffer
)
1216 old_buffer
= current_buffer
;
1217 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1220 *fully
= visible_p
= 0;
1221 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1223 /* Compute exact mode line heights, if requested. */
1224 if (exact_mode_line_heights_p
)
1226 if (WINDOW_WANTS_MODELINE_P (w
))
1227 current_mode_line_height
1228 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1229 current_buffer
->mode_line_format
);
1231 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1232 current_header_line_height
1233 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1234 current_buffer
->header_line_format
);
1237 start_display (&it
, w
, top
);
1238 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1239 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1241 /* Note that we may overshoot because of invisible text. */
1242 if (IT_CHARPOS (it
) >= charpos
)
1244 int top_y
= it
.current_y
;
1245 int bottom_y
= line_bottom_y (&it
);
1246 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1248 if (top_y
< window_top_y
)
1249 visible_p
= bottom_y
> window_top_y
;
1250 else if (top_y
< it
.last_visible_y
)
1253 *fully
= bottom_y
<= it
.last_visible_y
;
1256 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1258 move_it_by_lines (&it
, 1, 0);
1259 if (charpos
< IT_CHARPOS (it
))
1267 set_buffer_internal_1 (old_buffer
);
1269 current_header_line_height
= current_mode_line_height
= -1;
1274 /* Return the next character from STR which is MAXLEN bytes long.
1275 Return in *LEN the length of the character. This is like
1276 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1277 we find one, we return a `?', but with the length of the invalid
1281 string_char_and_length (str
, maxlen
, len
)
1282 const unsigned char *str
;
1287 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1288 if (!CHAR_VALID_P (c
, 1))
1289 /* We may not change the length here because other places in Emacs
1290 don't use this function, i.e. they silently accept invalid
1299 /* Given a position POS containing a valid character and byte position
1300 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1302 static struct text_pos
1303 string_pos_nchars_ahead (pos
, string
, nchars
)
1304 struct text_pos pos
;
1308 xassert (STRINGP (string
) && nchars
>= 0);
1310 if (STRING_MULTIBYTE (string
))
1312 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1313 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1318 string_char_and_length (p
, rest
, &len
);
1319 p
+= len
, rest
-= len
;
1320 xassert (rest
>= 0);
1322 BYTEPOS (pos
) += len
;
1326 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1332 /* Value is the text position, i.e. character and byte position,
1333 for character position CHARPOS in STRING. */
1335 static INLINE
struct text_pos
1336 string_pos (charpos
, string
)
1340 struct text_pos pos
;
1341 xassert (STRINGP (string
));
1342 xassert (charpos
>= 0);
1343 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1348 /* Value is a text position, i.e. character and byte position, for
1349 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1350 means recognize multibyte characters. */
1352 static struct text_pos
1353 c_string_pos (charpos
, s
, multibyte_p
)
1358 struct text_pos pos
;
1360 xassert (s
!= NULL
);
1361 xassert (charpos
>= 0);
1365 int rest
= strlen (s
), len
;
1367 SET_TEXT_POS (pos
, 0, 0);
1370 string_char_and_length (s
, rest
, &len
);
1371 s
+= len
, rest
-= len
;
1372 xassert (rest
>= 0);
1374 BYTEPOS (pos
) += len
;
1378 SET_TEXT_POS (pos
, charpos
, charpos
);
1384 /* Value is the number of characters in C string S. MULTIBYTE_P
1385 non-zero means recognize multibyte characters. */
1388 number_of_chars (s
, multibyte_p
)
1396 int rest
= strlen (s
), len
;
1397 unsigned char *p
= (unsigned char *) s
;
1399 for (nchars
= 0; rest
> 0; ++nchars
)
1401 string_char_and_length (p
, rest
, &len
);
1402 rest
-= len
, p
+= len
;
1406 nchars
= strlen (s
);
1412 /* Compute byte position NEWPOS->bytepos corresponding to
1413 NEWPOS->charpos. POS is a known position in string STRING.
1414 NEWPOS->charpos must be >= POS.charpos. */
1417 compute_string_pos (newpos
, pos
, string
)
1418 struct text_pos
*newpos
, pos
;
1421 xassert (STRINGP (string
));
1422 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1424 if (STRING_MULTIBYTE (string
))
1425 *newpos
= string_pos_nchars_ahead (pos
, string
,
1426 CHARPOS (*newpos
) - CHARPOS (pos
));
1428 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1432 Return an estimation of the pixel height of mode or top lines on
1433 frame F. FACE_ID specifies what line's height to estimate. */
1436 estimate_mode_line_height (f
, face_id
)
1438 enum face_id face_id
;
1440 #ifdef HAVE_WINDOW_SYSTEM
1441 if (FRAME_WINDOW_P (f
))
1443 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1445 /* This function is called so early when Emacs starts that the face
1446 cache and mode line face are not yet initialized. */
1447 if (FRAME_FACE_CACHE (f
))
1449 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1453 height
= FONT_HEIGHT (face
->font
);
1454 if (face
->box_line_width
> 0)
1455 height
+= 2 * face
->box_line_width
;
1466 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1467 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1468 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1469 not force the value into range. */
1472 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1474 register int pix_x
, pix_y
;
1476 NativeRectangle
*bounds
;
1480 #ifdef HAVE_WINDOW_SYSTEM
1481 if (FRAME_WINDOW_P (f
))
1483 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1484 even for negative values. */
1486 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1488 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1490 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1491 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1494 STORE_NATIVE_RECT (*bounds
,
1495 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1496 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1497 FRAME_COLUMN_WIDTH (f
) - 1,
1498 FRAME_LINE_HEIGHT (f
) - 1);
1504 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1505 pix_x
= FRAME_TOTAL_COLS (f
);
1509 else if (pix_y
> FRAME_LINES (f
))
1510 pix_y
= FRAME_LINES (f
);
1520 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1521 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1522 can't tell the positions because W's display is not up to date,
1526 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1529 int *frame_x
, *frame_y
;
1531 #ifdef HAVE_WINDOW_SYSTEM
1532 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1536 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1537 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1539 if (display_completed
)
1541 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1542 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1543 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1549 hpos
+= glyph
->pixel_width
;
1553 /* If first glyph is partially visible, its first visible position is still 0. */
1565 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1566 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1577 #ifdef HAVE_WINDOW_SYSTEM
1579 /* Find the glyph under window-relative coordinates X/Y in window W.
1580 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1581 strings. Return in *HPOS and *VPOS the row and column number of
1582 the glyph found. Return in *AREA the glyph area containing X.
1583 Value is a pointer to the glyph found or null if X/Y is not on
1584 text, or we can't tell because W's current matrix is not up to
1587 static struct glyph
*
1588 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1591 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1593 struct glyph
*glyph
, *end
;
1594 struct glyph_row
*row
= NULL
;
1597 /* Find row containing Y. Give up if some row is not enabled. */
1598 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1600 row
= MATRIX_ROW (w
->current_matrix
, i
);
1601 if (!row
->enabled_p
)
1603 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1610 /* Give up if Y is not in the window. */
1611 if (i
== w
->current_matrix
->nrows
)
1614 /* Get the glyph area containing X. */
1615 if (w
->pseudo_window_p
)
1622 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1624 *area
= LEFT_MARGIN_AREA
;
1625 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1627 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1630 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1634 *area
= RIGHT_MARGIN_AREA
;
1635 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1639 /* Find glyph containing X. */
1640 glyph
= row
->glyphs
[*area
];
1641 end
= glyph
+ row
->used
[*area
];
1643 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1645 x
-= glyph
->pixel_width
;
1655 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1658 *hpos
= glyph
- row
->glyphs
[*area
];
1664 Convert frame-relative x/y to coordinates relative to window W.
1665 Takes pseudo-windows into account. */
1668 frame_to_window_pixel_xy (w
, x
, y
)
1672 if (w
->pseudo_window_p
)
1674 /* A pseudo-window is always full-width, and starts at the
1675 left edge of the frame, plus a frame border. */
1676 struct frame
*f
= XFRAME (w
->frame
);
1677 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1678 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1682 *x
-= WINDOW_LEFT_EDGE_X (w
);
1683 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1688 Return in *R the clipping rectangle for glyph string S. */
1691 get_glyph_string_clip_rect (s
, nr
)
1692 struct glyph_string
*s
;
1693 NativeRectangle
*nr
;
1697 if (s
->row
->full_width_p
)
1699 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1700 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1701 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1703 /* Unless displaying a mode or menu bar line, which are always
1704 fully visible, clip to the visible part of the row. */
1705 if (s
->w
->pseudo_window_p
)
1706 r
.height
= s
->row
->visible_height
;
1708 r
.height
= s
->height
;
1712 /* This is a text line that may be partially visible. */
1713 r
.x
= window_box_left (s
->w
, s
->area
);
1714 r
.width
= window_box_width (s
->w
, s
->area
);
1715 r
.height
= s
->row
->visible_height
;
1718 /* If S draws overlapping rows, it's sufficient to use the top and
1719 bottom of the window for clipping because this glyph string
1720 intentionally draws over other lines. */
1721 if (s
->for_overlaps_p
)
1723 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1724 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1728 /* Don't use S->y for clipping because it doesn't take partially
1729 visible lines into account. For example, it can be negative for
1730 partially visible lines at the top of a window. */
1731 if (!s
->row
->full_width_p
1732 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1733 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1735 r
.y
= max (0, s
->row
->y
);
1737 /* If drawing a tool-bar window, draw it over the internal border
1738 at the top of the window. */
1739 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1740 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1743 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1745 /* If drawing the cursor, don't let glyph draw outside its
1746 advertised boundaries. Cleartype does this under some circumstances. */
1747 if (s
->hl
== DRAW_CURSOR
)
1749 struct glyph
*glyph
= s
->first_glyph
;
1754 r
.width
-= s
->x
- r
.x
;
1757 r
.width
= min (r
.width
, glyph
->pixel_width
);
1759 /* Don't draw cursor glyph taller than our actual glyph. */
1760 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1761 if (height
< r
.height
)
1763 r
.y
= s
->ybase
+ glyph
->descent
- height
;
1768 #ifdef CONVERT_FROM_XRECT
1769 CONVERT_FROM_XRECT (r
, *nr
);
1775 #endif /* HAVE_WINDOW_SYSTEM */
1778 /***********************************************************************
1779 Lisp form evaluation
1780 ***********************************************************************/
1782 /* Error handler for safe_eval and safe_call. */
1785 safe_eval_handler (arg
)
1788 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1793 /* Evaluate SEXPR and return the result, or nil if something went
1794 wrong. Prevent redisplay during the evaluation. */
1802 if (inhibit_eval_during_redisplay
)
1806 int count
= SPECPDL_INDEX ();
1807 struct gcpro gcpro1
;
1810 specbind (Qinhibit_redisplay
, Qt
);
1811 /* Use Qt to ensure debugger does not run,
1812 so there is no possibility of wanting to redisplay. */
1813 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1816 val
= unbind_to (count
, val
);
1823 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1824 Return the result, or nil if something went wrong. Prevent
1825 redisplay during the evaluation. */
1828 safe_call (nargs
, args
)
1834 if (inhibit_eval_during_redisplay
)
1838 int count
= SPECPDL_INDEX ();
1839 struct gcpro gcpro1
;
1842 gcpro1
.nvars
= nargs
;
1843 specbind (Qinhibit_redisplay
, Qt
);
1844 /* Use Qt to ensure debugger does not run,
1845 so there is no possibility of wanting to redisplay. */
1846 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
1849 val
= unbind_to (count
, val
);
1856 /* Call function FN with one argument ARG.
1857 Return the result, or nil if something went wrong. */
1860 safe_call1 (fn
, arg
)
1861 Lisp_Object fn
, arg
;
1863 Lisp_Object args
[2];
1866 return safe_call (2, args
);
1871 /***********************************************************************
1873 ***********************************************************************/
1877 /* Define CHECK_IT to perform sanity checks on iterators.
1878 This is for debugging. It is too slow to do unconditionally. */
1884 if (it
->method
== next_element_from_string
)
1886 xassert (STRINGP (it
->string
));
1887 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1889 else if (it
->method
== next_element_from_buffer
)
1891 /* Check that character and byte positions agree. */
1892 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1896 xassert (it
->current
.dpvec_index
>= 0);
1898 xassert (it
->current
.dpvec_index
< 0);
1901 #define CHECK_IT(IT) check_it ((IT))
1905 #define CHECK_IT(IT) (void) 0
1912 /* Check that the window end of window W is what we expect it
1913 to be---the last row in the current matrix displaying text. */
1916 check_window_end (w
)
1919 if (!MINI_WINDOW_P (w
)
1920 && !NILP (w
->window_end_valid
))
1922 struct glyph_row
*row
;
1923 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1924 XFASTINT (w
->window_end_vpos
)),
1926 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1927 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1931 #define CHECK_WINDOW_END(W) check_window_end ((W))
1933 #else /* not GLYPH_DEBUG */
1935 #define CHECK_WINDOW_END(W) (void) 0
1937 #endif /* not GLYPH_DEBUG */
1941 /***********************************************************************
1942 Iterator initialization
1943 ***********************************************************************/
1945 /* Initialize IT for displaying current_buffer in window W, starting
1946 at character position CHARPOS. CHARPOS < 0 means that no buffer
1947 position is specified which is useful when the iterator is assigned
1948 a position later. BYTEPOS is the byte position corresponding to
1949 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
1951 If ROW is not null, calls to produce_glyphs with IT as parameter
1952 will produce glyphs in that row.
1954 BASE_FACE_ID is the id of a base face to use. It must be one of
1955 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
1956 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
1957 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
1959 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
1960 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
1961 will be initialized to use the corresponding mode line glyph row of
1962 the desired matrix of W. */
1965 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1968 int charpos
, bytepos
;
1969 struct glyph_row
*row
;
1970 enum face_id base_face_id
;
1972 int highlight_region_p
;
1974 /* Some precondition checks. */
1975 xassert (w
!= NULL
&& it
!= NULL
);
1976 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
1979 /* If face attributes have been changed since the last redisplay,
1980 free realized faces now because they depend on face definitions
1981 that might have changed. Don't free faces while there might be
1982 desired matrices pending which reference these faces. */
1983 if (face_change_count
&& !inhibit_free_realized_faces
)
1985 face_change_count
= 0;
1986 free_all_realized_faces (Qnil
);
1989 /* Use one of the mode line rows of W's desired matrix if
1993 if (base_face_id
== MODE_LINE_FACE_ID
1994 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
1995 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1996 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1997 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2001 bzero (it
, sizeof *it
);
2002 it
->current
.overlay_string_index
= -1;
2003 it
->current
.dpvec_index
= -1;
2004 it
->base_face_id
= base_face_id
;
2006 /* The window in which we iterate over current_buffer: */
2007 XSETWINDOW (it
->window
, w
);
2009 it
->f
= XFRAME (w
->frame
);
2011 /* Extra space between lines (on window systems only). */
2012 if (base_face_id
== DEFAULT_FACE_ID
2013 && FRAME_WINDOW_P (it
->f
))
2015 if (NATNUMP (current_buffer
->extra_line_spacing
))
2016 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2017 else if (it
->f
->extra_line_spacing
> 0)
2018 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2021 /* If realized faces have been removed, e.g. because of face
2022 attribute changes of named faces, recompute them. When running
2023 in batch mode, the face cache of the initial frame is null. If
2024 we happen to get called, make a dummy face cache. */
2025 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2026 init_frame_faces (it
->f
);
2027 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2028 recompute_basic_faces (it
->f
);
2030 /* Current value of the `space-width', and 'height' properties. */
2031 it
->space_width
= Qnil
;
2032 it
->font_height
= Qnil
;
2034 /* Are control characters displayed as `^C'? */
2035 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2037 /* -1 means everything between a CR and the following line end
2038 is invisible. >0 means lines indented more than this value are
2040 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2041 ? XFASTINT (current_buffer
->selective_display
)
2042 : (!NILP (current_buffer
->selective_display
)
2044 it
->selective_display_ellipsis_p
2045 = !NILP (current_buffer
->selective_display_ellipses
);
2047 /* Display table to use. */
2048 it
->dp
= window_display_table (w
);
2050 /* Are multibyte characters enabled in current_buffer? */
2051 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2053 /* Non-zero if we should highlight the region. */
2055 = (!NILP (Vtransient_mark_mode
)
2056 && !NILP (current_buffer
->mark_active
)
2057 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2059 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2060 start and end of a visible region in window IT->w. Set both to
2061 -1 to indicate no region. */
2062 if (highlight_region_p
2063 /* Maybe highlight only in selected window. */
2064 && (/* Either show region everywhere. */
2065 highlight_nonselected_windows
2066 /* Or show region in the selected window. */
2067 || w
== XWINDOW (selected_window
)
2068 /* Or show the region if we are in the mini-buffer and W is
2069 the window the mini-buffer refers to. */
2070 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2071 && WINDOWP (minibuf_selected_window
)
2072 && w
== XWINDOW (minibuf_selected_window
))))
2074 int charpos
= marker_position (current_buffer
->mark
);
2075 it
->region_beg_charpos
= min (PT
, charpos
);
2076 it
->region_end_charpos
= max (PT
, charpos
);
2079 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2081 /* Get the position at which the redisplay_end_trigger hook should
2082 be run, if it is to be run at all. */
2083 if (MARKERP (w
->redisplay_end_trigger
)
2084 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2085 it
->redisplay_end_trigger_charpos
2086 = marker_position (w
->redisplay_end_trigger
);
2087 else if (INTEGERP (w
->redisplay_end_trigger
))
2088 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2090 /* Correct bogus values of tab_width. */
2091 it
->tab_width
= XINT (current_buffer
->tab_width
);
2092 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2095 /* Are lines in the display truncated? */
2096 it
->truncate_lines_p
2097 = (base_face_id
!= DEFAULT_FACE_ID
2098 || XINT (it
->w
->hscroll
)
2099 || (truncate_partial_width_windows
2100 && !WINDOW_FULL_WIDTH_P (it
->w
))
2101 || !NILP (current_buffer
->truncate_lines
));
2103 /* Get dimensions of truncation and continuation glyphs. These are
2104 displayed as fringe bitmaps under X, so we don't need them for such
2106 if (!FRAME_WINDOW_P (it
->f
))
2108 if (it
->truncate_lines_p
)
2110 /* We will need the truncation glyph. */
2111 xassert (it
->glyph_row
== NULL
);
2112 produce_special_glyphs (it
, IT_TRUNCATION
);
2113 it
->truncation_pixel_width
= it
->pixel_width
;
2117 /* We will need the continuation glyph. */
2118 xassert (it
->glyph_row
== NULL
);
2119 produce_special_glyphs (it
, IT_CONTINUATION
);
2120 it
->continuation_pixel_width
= it
->pixel_width
;
2123 /* Reset these values to zero because the produce_special_glyphs
2124 above has changed them. */
2125 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2126 it
->phys_ascent
= it
->phys_descent
= 0;
2129 /* Set this after getting the dimensions of truncation and
2130 continuation glyphs, so that we don't produce glyphs when calling
2131 produce_special_glyphs, above. */
2132 it
->glyph_row
= row
;
2133 it
->area
= TEXT_AREA
;
2135 /* Get the dimensions of the display area. The display area
2136 consists of the visible window area plus a horizontally scrolled
2137 part to the left of the window. All x-values are relative to the
2138 start of this total display area. */
2139 if (base_face_id
!= DEFAULT_FACE_ID
)
2141 /* Mode lines, menu bar in terminal frames. */
2142 it
->first_visible_x
= 0;
2143 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2148 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2149 it
->last_visible_x
= (it
->first_visible_x
2150 + window_box_width (w
, TEXT_AREA
));
2152 /* If we truncate lines, leave room for the truncator glyph(s) at
2153 the right margin. Otherwise, leave room for the continuation
2154 glyph(s). Truncation and continuation glyphs are not inserted
2155 for window-based redisplay. */
2156 if (!FRAME_WINDOW_P (it
->f
))
2158 if (it
->truncate_lines_p
)
2159 it
->last_visible_x
-= it
->truncation_pixel_width
;
2161 it
->last_visible_x
-= it
->continuation_pixel_width
;
2164 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2165 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2168 /* Leave room for a border glyph. */
2169 if (!FRAME_WINDOW_P (it
->f
)
2170 && !WINDOW_RIGHTMOST_P (it
->w
))
2171 it
->last_visible_x
-= 1;
2173 it
->last_visible_y
= window_text_bottom_y (w
);
2175 /* For mode lines and alike, arrange for the first glyph having a
2176 left box line if the face specifies a box. */
2177 if (base_face_id
!= DEFAULT_FACE_ID
)
2181 it
->face_id
= base_face_id
;
2183 /* If we have a boxed mode line, make the first character appear
2184 with a left box line. */
2185 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2186 if (face
->box
!= FACE_NO_BOX
)
2187 it
->start_of_box_run_p
= 1;
2190 /* If a buffer position was specified, set the iterator there,
2191 getting overlays and face properties from that position. */
2192 if (charpos
>= BUF_BEG (current_buffer
))
2194 it
->end_charpos
= ZV
;
2196 IT_CHARPOS (*it
) = charpos
;
2198 /* Compute byte position if not specified. */
2199 if (bytepos
< charpos
)
2200 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2202 IT_BYTEPOS (*it
) = bytepos
;
2204 it
->start
= it
->current
;
2206 /* Compute faces etc. */
2207 reseat (it
, it
->current
.pos
, 1);
2214 /* Initialize IT for the display of window W with window start POS. */
2217 start_display (it
, w
, pos
)
2220 struct text_pos pos
;
2222 struct glyph_row
*row
;
2223 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2225 row
= w
->desired_matrix
->rows
+ first_vpos
;
2226 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2227 it
->first_vpos
= first_vpos
;
2229 if (!it
->truncate_lines_p
)
2231 int start_at_line_beg_p
;
2232 int first_y
= it
->current_y
;
2234 /* If window start is not at a line start, skip forward to POS to
2235 get the correct continuation lines width. */
2236 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2237 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2238 if (!start_at_line_beg_p
)
2242 reseat_at_previous_visible_line_start (it
);
2243 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2245 new_x
= it
->current_x
+ it
->pixel_width
;
2247 /* If lines are continued, this line may end in the middle
2248 of a multi-glyph character (e.g. a control character
2249 displayed as \003, or in the middle of an overlay
2250 string). In this case move_it_to above will not have
2251 taken us to the start of the continuation line but to the
2252 end of the continued line. */
2253 if (it
->current_x
> 0
2254 && !it
->truncate_lines_p
/* Lines are continued. */
2255 && (/* And glyph doesn't fit on the line. */
2256 new_x
> it
->last_visible_x
2257 /* Or it fits exactly and we're on a window
2259 || (new_x
== it
->last_visible_x
2260 && FRAME_WINDOW_P (it
->f
))))
2262 if (it
->current
.dpvec_index
>= 0
2263 || it
->current
.overlay_string_index
>= 0)
2265 set_iterator_to_next (it
, 1);
2266 move_it_in_display_line_to (it
, -1, -1, 0);
2269 it
->continuation_lines_width
+= it
->current_x
;
2272 /* We're starting a new display line, not affected by the
2273 height of the continued line, so clear the appropriate
2274 fields in the iterator structure. */
2275 it
->max_ascent
= it
->max_descent
= 0;
2276 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2278 it
->current_y
= first_y
;
2280 it
->current_x
= it
->hpos
= 0;
2284 #if 0 /* Don't assert the following because start_display is sometimes
2285 called intentionally with a window start that is not at a
2286 line start. Please leave this code in as a comment. */
2288 /* Window start should be on a line start, now. */
2289 xassert (it
->continuation_lines_width
2290 || IT_CHARPOS (it
) == BEGV
2291 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2296 /* Return 1 if POS is a position in ellipses displayed for invisible
2297 text. W is the window we display, for text property lookup. */
2300 in_ellipses_for_invisible_text_p (pos
, w
)
2301 struct display_pos
*pos
;
2304 Lisp_Object prop
, window
;
2306 int charpos
= CHARPOS (pos
->pos
);
2308 /* If POS specifies a position in a display vector, this might
2309 be for an ellipsis displayed for invisible text. We won't
2310 get the iterator set up for delivering that ellipsis unless
2311 we make sure that it gets aware of the invisible text. */
2312 if (pos
->dpvec_index
>= 0
2313 && pos
->overlay_string_index
< 0
2314 && CHARPOS (pos
->string_pos
) < 0
2316 && (XSETWINDOW (window
, w
),
2317 prop
= Fget_char_property (make_number (charpos
),
2318 Qinvisible
, window
),
2319 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2321 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2323 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2330 /* Initialize IT for stepping through current_buffer in window W,
2331 starting at position POS that includes overlay string and display
2332 vector/ control character translation position information. Value
2333 is zero if there are overlay strings with newlines at POS. */
2336 init_from_display_pos (it
, w
, pos
)
2339 struct display_pos
*pos
;
2341 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2342 int i
, overlay_strings_with_newlines
= 0;
2344 /* If POS specifies a position in a display vector, this might
2345 be for an ellipsis displayed for invisible text. We won't
2346 get the iterator set up for delivering that ellipsis unless
2347 we make sure that it gets aware of the invisible text. */
2348 if (in_ellipses_for_invisible_text_p (pos
, w
))
2354 /* Keep in mind: the call to reseat in init_iterator skips invisible
2355 text, so we might end up at a position different from POS. This
2356 is only a problem when POS is a row start after a newline and an
2357 overlay starts there with an after-string, and the overlay has an
2358 invisible property. Since we don't skip invisible text in
2359 display_line and elsewhere immediately after consuming the
2360 newline before the row start, such a POS will not be in a string,
2361 but the call to init_iterator below will move us to the
2363 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2365 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
2367 const char *s
= SDATA (it
->overlay_strings
[i
]);
2368 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2370 while (s
< e
&& *s
!= '\n')
2375 overlay_strings_with_newlines
= 1;
2380 /* If position is within an overlay string, set up IT to the right
2382 if (pos
->overlay_string_index
>= 0)
2386 /* If the first overlay string happens to have a `display'
2387 property for an image, the iterator will be set up for that
2388 image, and we have to undo that setup first before we can
2389 correct the overlay string index. */
2390 if (it
->method
== next_element_from_image
)
2393 /* We already have the first chunk of overlay strings in
2394 IT->overlay_strings. Load more until the one for
2395 pos->overlay_string_index is in IT->overlay_strings. */
2396 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2398 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2399 it
->current
.overlay_string_index
= 0;
2402 load_overlay_strings (it
, 0);
2403 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2407 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2408 relative_index
= (it
->current
.overlay_string_index
2409 % OVERLAY_STRING_CHUNK_SIZE
);
2410 it
->string
= it
->overlay_strings
[relative_index
];
2411 xassert (STRINGP (it
->string
));
2412 it
->current
.string_pos
= pos
->string_pos
;
2413 it
->method
= next_element_from_string
;
2416 #if 0 /* This is bogus because POS not having an overlay string
2417 position does not mean it's after the string. Example: A
2418 line starting with a before-string and initialization of IT
2419 to the previous row's end position. */
2420 else if (it
->current
.overlay_string_index
>= 0)
2422 /* If POS says we're already after an overlay string ending at
2423 POS, make sure to pop the iterator because it will be in
2424 front of that overlay string. When POS is ZV, we've thereby
2425 also ``processed'' overlay strings at ZV. */
2428 it
->current
.overlay_string_index
= -1;
2429 it
->method
= next_element_from_buffer
;
2430 if (CHARPOS (pos
->pos
) == ZV
)
2431 it
->overlay_strings_at_end_processed_p
= 1;
2435 if (CHARPOS (pos
->string_pos
) >= 0)
2437 /* Recorded position is not in an overlay string, but in another
2438 string. This can only be a string from a `display' property.
2439 IT should already be filled with that string. */
2440 it
->current
.string_pos
= pos
->string_pos
;
2441 xassert (STRINGP (it
->string
));
2444 /* Restore position in display vector translations, control
2445 character translations or ellipses. */
2446 if (pos
->dpvec_index
>= 0)
2448 if (it
->dpvec
== NULL
)
2449 get_next_display_element (it
);
2450 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2451 it
->current
.dpvec_index
= pos
->dpvec_index
;
2455 return !overlay_strings_with_newlines
;
2459 /* Initialize IT for stepping through current_buffer in window W
2460 starting at ROW->start. */
2463 init_to_row_start (it
, w
, row
)
2466 struct glyph_row
*row
;
2468 init_from_display_pos (it
, w
, &row
->start
);
2469 it
->start
= row
->start
;
2470 it
->continuation_lines_width
= row
->continuation_lines_width
;
2475 /* Initialize IT for stepping through current_buffer in window W
2476 starting in the line following ROW, i.e. starting at ROW->end.
2477 Value is zero if there are overlay strings with newlines at ROW's
2481 init_to_row_end (it
, w
, row
)
2484 struct glyph_row
*row
;
2488 if (init_from_display_pos (it
, w
, &row
->end
))
2490 if (row
->continued_p
)
2491 it
->continuation_lines_width
2492 = row
->continuation_lines_width
+ row
->pixel_width
;
2503 /***********************************************************************
2505 ***********************************************************************/
2507 /* Called when IT reaches IT->stop_charpos. Handle text property and
2508 overlay changes. Set IT->stop_charpos to the next position where
2515 enum prop_handled handled
;
2516 int handle_overlay_change_p
= 1;
2520 it
->current
.dpvec_index
= -1;
2524 handled
= HANDLED_NORMALLY
;
2526 /* Call text property handlers. */
2527 for (p
= it_props
; p
->handler
; ++p
)
2529 handled
= p
->handler (it
);
2531 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2533 else if (handled
== HANDLED_RETURN
)
2535 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2536 handle_overlay_change_p
= 0;
2539 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2541 /* Don't check for overlay strings below when set to deliver
2542 characters from a display vector. */
2543 if (it
->method
== next_element_from_display_vector
)
2544 handle_overlay_change_p
= 0;
2546 /* Handle overlay changes. */
2547 if (handle_overlay_change_p
)
2548 handled
= handle_overlay_change (it
);
2550 /* Determine where to stop next. */
2551 if (handled
== HANDLED_NORMALLY
)
2552 compute_stop_pos (it
);
2555 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2559 /* Compute IT->stop_charpos from text property and overlay change
2560 information for IT's current position. */
2563 compute_stop_pos (it
)
2566 register INTERVAL iv
, next_iv
;
2567 Lisp_Object object
, limit
, position
;
2569 /* If nowhere else, stop at the end. */
2570 it
->stop_charpos
= it
->end_charpos
;
2572 if (STRINGP (it
->string
))
2574 /* Strings are usually short, so don't limit the search for
2576 object
= it
->string
;
2578 position
= make_number (IT_STRING_CHARPOS (*it
));
2584 /* If next overlay change is in front of the current stop pos
2585 (which is IT->end_charpos), stop there. Note: value of
2586 next_overlay_change is point-max if no overlay change
2588 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2589 if (charpos
< it
->stop_charpos
)
2590 it
->stop_charpos
= charpos
;
2592 /* If showing the region, we have to stop at the region
2593 start or end because the face might change there. */
2594 if (it
->region_beg_charpos
> 0)
2596 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2597 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2598 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2599 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2602 /* Set up variables for computing the stop position from text
2603 property changes. */
2604 XSETBUFFER (object
, current_buffer
);
2605 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2606 position
= make_number (IT_CHARPOS (*it
));
2610 /* Get the interval containing IT's position. Value is a null
2611 interval if there isn't such an interval. */
2612 iv
= validate_interval_range (object
, &position
, &position
, 0);
2613 if (!NULL_INTERVAL_P (iv
))
2615 Lisp_Object values_here
[LAST_PROP_IDX
];
2618 /* Get properties here. */
2619 for (p
= it_props
; p
->handler
; ++p
)
2620 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2622 /* Look for an interval following iv that has different
2624 for (next_iv
= next_interval (iv
);
2625 (!NULL_INTERVAL_P (next_iv
)
2627 || XFASTINT (limit
) > next_iv
->position
));
2628 next_iv
= next_interval (next_iv
))
2630 for (p
= it_props
; p
->handler
; ++p
)
2632 Lisp_Object new_value
;
2634 new_value
= textget (next_iv
->plist
, *p
->name
);
2635 if (!EQ (values_here
[p
->idx
], new_value
))
2643 if (!NULL_INTERVAL_P (next_iv
))
2645 if (INTEGERP (limit
)
2646 && next_iv
->position
>= XFASTINT (limit
))
2647 /* No text property change up to limit. */
2648 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2650 /* Text properties change in next_iv. */
2651 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2655 xassert (STRINGP (it
->string
)
2656 || (it
->stop_charpos
>= BEGV
2657 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2661 /* Return the position of the next overlay change after POS in
2662 current_buffer. Value is point-max if no overlay change
2663 follows. This is like `next-overlay-change' but doesn't use
2667 next_overlay_change (pos
)
2672 Lisp_Object
*overlays
;
2676 /* Get all overlays at the given position. */
2678 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2679 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2680 if (noverlays
> len
)
2683 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2684 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2687 /* If any of these overlays ends before endpos,
2688 use its ending point instead. */
2689 for (i
= 0; i
< noverlays
; ++i
)
2694 oend
= OVERLAY_END (overlays
[i
]);
2695 oendpos
= OVERLAY_POSITION (oend
);
2696 endpos
= min (endpos
, oendpos
);
2704 /***********************************************************************
2706 ***********************************************************************/
2708 /* Handle changes in the `fontified' property of the current buffer by
2709 calling hook functions from Qfontification_functions to fontify
2712 static enum prop_handled
2713 handle_fontified_prop (it
)
2716 Lisp_Object prop
, pos
;
2717 enum prop_handled handled
= HANDLED_NORMALLY
;
2719 /* Get the value of the `fontified' property at IT's current buffer
2720 position. (The `fontified' property doesn't have a special
2721 meaning in strings.) If the value is nil, call functions from
2722 Qfontification_functions. */
2723 if (!STRINGP (it
->string
)
2725 && !NILP (Vfontification_functions
)
2726 && !NILP (Vrun_hooks
)
2727 && (pos
= make_number (IT_CHARPOS (*it
)),
2728 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2731 int count
= SPECPDL_INDEX ();
2734 val
= Vfontification_functions
;
2735 specbind (Qfontification_functions
, Qnil
);
2737 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2738 safe_call1 (val
, pos
);
2741 Lisp_Object globals
, fn
;
2742 struct gcpro gcpro1
, gcpro2
;
2745 GCPRO2 (val
, globals
);
2747 for (; CONSP (val
); val
= XCDR (val
))
2753 /* A value of t indicates this hook has a local
2754 binding; it means to run the global binding too.
2755 In a global value, t should not occur. If it
2756 does, we must ignore it to avoid an endless
2758 for (globals
= Fdefault_value (Qfontification_functions
);
2760 globals
= XCDR (globals
))
2762 fn
= XCAR (globals
);
2764 safe_call1 (fn
, pos
);
2768 safe_call1 (fn
, pos
);
2774 unbind_to (count
, Qnil
);
2776 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2777 something. This avoids an endless loop if they failed to
2778 fontify the text for which reason ever. */
2779 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2780 handled
= HANDLED_RECOMPUTE_PROPS
;
2788 /***********************************************************************
2790 ***********************************************************************/
2792 /* Set up iterator IT from face properties at its current position.
2793 Called from handle_stop. */
2795 static enum prop_handled
2796 handle_face_prop (it
)
2799 int new_face_id
, next_stop
;
2801 if (!STRINGP (it
->string
))
2804 = face_at_buffer_position (it
->w
,
2806 it
->region_beg_charpos
,
2807 it
->region_end_charpos
,
2810 + TEXT_PROP_DISTANCE_LIMIT
),
2813 /* Is this a start of a run of characters with box face?
2814 Caveat: this can be called for a freshly initialized
2815 iterator; face_id is -1 in this case. We know that the new
2816 face will not change until limit, i.e. if the new face has a
2817 box, all characters up to limit will have one. But, as
2818 usual, we don't know whether limit is really the end. */
2819 if (new_face_id
!= it
->face_id
)
2821 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2823 /* If new face has a box but old face has not, this is
2824 the start of a run of characters with box, i.e. it has
2825 a shadow on the left side. The value of face_id of the
2826 iterator will be -1 if this is the initial call that gets
2827 the face. In this case, we have to look in front of IT's
2828 position and see whether there is a face != new_face_id. */
2829 it
->start_of_box_run_p
2830 = (new_face
->box
!= FACE_NO_BOX
2831 && (it
->face_id
>= 0
2832 || IT_CHARPOS (*it
) == BEG
2833 || new_face_id
!= face_before_it_pos (it
)));
2834 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2839 int base_face_id
, bufpos
;
2841 if (it
->current
.overlay_string_index
>= 0)
2842 bufpos
= IT_CHARPOS (*it
);
2846 /* For strings from a buffer, i.e. overlay strings or strings
2847 from a `display' property, use the face at IT's current
2848 buffer position as the base face to merge with, so that
2849 overlay strings appear in the same face as surrounding
2850 text, unless they specify their own faces. */
2851 base_face_id
= underlying_face_id (it
);
2853 new_face_id
= face_at_string_position (it
->w
,
2855 IT_STRING_CHARPOS (*it
),
2857 it
->region_beg_charpos
,
2858 it
->region_end_charpos
,
2862 #if 0 /* This shouldn't be neccessary. Let's check it. */
2863 /* If IT is used to display a mode line we would really like to
2864 use the mode line face instead of the frame's default face. */
2865 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2866 && new_face_id
== DEFAULT_FACE_ID
)
2867 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
2870 /* Is this a start of a run of characters with box? Caveat:
2871 this can be called for a freshly allocated iterator; face_id
2872 is -1 is this case. We know that the new face will not
2873 change until the next check pos, i.e. if the new face has a
2874 box, all characters up to that position will have a
2875 box. But, as usual, we don't know whether that position
2876 is really the end. */
2877 if (new_face_id
!= it
->face_id
)
2879 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2880 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2882 /* If new face has a box but old face hasn't, this is the
2883 start of a run of characters with box, i.e. it has a
2884 shadow on the left side. */
2885 it
->start_of_box_run_p
2886 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2887 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2891 it
->face_id
= new_face_id
;
2892 return HANDLED_NORMALLY
;
2896 /* Return the ID of the face ``underlying'' IT's current position,
2897 which is in a string. If the iterator is associated with a
2898 buffer, return the face at IT's current buffer position.
2899 Otherwise, use the iterator's base_face_id. */
2902 underlying_face_id (it
)
2905 int face_id
= it
->base_face_id
, i
;
2907 xassert (STRINGP (it
->string
));
2909 for (i
= it
->sp
- 1; i
>= 0; --i
)
2910 if (NILP (it
->stack
[i
].string
))
2911 face_id
= it
->stack
[i
].face_id
;
2917 /* Compute the face one character before or after the current position
2918 of IT. BEFORE_P non-zero means get the face in front of IT's
2919 position. Value is the id of the face. */
2922 face_before_or_after_it_pos (it
, before_p
)
2927 int next_check_charpos
;
2928 struct text_pos pos
;
2930 xassert (it
->s
== NULL
);
2932 if (STRINGP (it
->string
))
2934 int bufpos
, base_face_id
;
2936 /* No face change past the end of the string (for the case
2937 we are padding with spaces). No face change before the
2939 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
2940 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2943 /* Set pos to the position before or after IT's current position. */
2945 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2947 /* For composition, we must check the character after the
2949 pos
= (it
->what
== IT_COMPOSITION
2950 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2951 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2953 if (it
->current
.overlay_string_index
>= 0)
2954 bufpos
= IT_CHARPOS (*it
);
2958 base_face_id
= underlying_face_id (it
);
2960 /* Get the face for ASCII, or unibyte. */
2961 face_id
= face_at_string_position (it
->w
,
2965 it
->region_beg_charpos
,
2966 it
->region_end_charpos
,
2967 &next_check_charpos
,
2970 /* Correct the face for charsets different from ASCII. Do it
2971 for the multibyte case only. The face returned above is
2972 suitable for unibyte text if IT->string is unibyte. */
2973 if (STRING_MULTIBYTE (it
->string
))
2975 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
2976 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
2978 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2980 c
= string_char_and_length (p
, rest
, &len
);
2981 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2986 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2987 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2990 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2991 pos
= it
->current
.pos
;
2994 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2997 if (it
->what
== IT_COMPOSITION
)
2998 /* For composition, we must check the position after the
3000 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3002 INC_TEXT_POS (pos
, it
->multibyte_p
);
3005 /* Determine face for CHARSET_ASCII, or unibyte. */
3006 face_id
= face_at_buffer_position (it
->w
,
3008 it
->region_beg_charpos
,
3009 it
->region_end_charpos
,
3010 &next_check_charpos
,
3013 /* Correct the face for charsets different from ASCII. Do it
3014 for the multibyte case only. The face returned above is
3015 suitable for unibyte text if current_buffer is unibyte. */
3016 if (it
->multibyte_p
)
3018 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3019 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3020 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3029 /***********************************************************************
3031 ***********************************************************************/
3033 /* Set up iterator IT from invisible properties at its current
3034 position. Called from handle_stop. */
3036 static enum prop_handled
3037 handle_invisible_prop (it
)
3040 enum prop_handled handled
= HANDLED_NORMALLY
;
3042 if (STRINGP (it
->string
))
3044 extern Lisp_Object Qinvisible
;
3045 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3047 /* Get the value of the invisible text property at the
3048 current position. Value will be nil if there is no such
3050 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3051 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3054 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3056 handled
= HANDLED_RECOMPUTE_PROPS
;
3058 /* Get the position at which the next change of the
3059 invisible text property can be found in IT->string.
3060 Value will be nil if the property value is the same for
3061 all the rest of IT->string. */
3062 XSETINT (limit
, SCHARS (it
->string
));
3063 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3066 /* Text at current position is invisible. The next
3067 change in the property is at position end_charpos.
3068 Move IT's current position to that position. */
3069 if (INTEGERP (end_charpos
)
3070 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3072 struct text_pos old
;
3073 old
= it
->current
.string_pos
;
3074 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3075 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3079 /* The rest of the string is invisible. If this is an
3080 overlay string, proceed with the next overlay string
3081 or whatever comes and return a character from there. */
3082 if (it
->current
.overlay_string_index
>= 0)
3084 next_overlay_string (it
);
3085 /* Don't check for overlay strings when we just
3086 finished processing them. */
3087 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3091 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3092 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3099 int invis_p
, newpos
, next_stop
, start_charpos
;
3100 Lisp_Object pos
, prop
, overlay
;
3102 /* First of all, is there invisible text at this position? */
3103 start_charpos
= IT_CHARPOS (*it
);
3104 pos
= make_number (IT_CHARPOS (*it
));
3105 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3107 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3109 /* If we are on invisible text, skip over it. */
3110 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3112 /* Record whether we have to display an ellipsis for the
3114 int display_ellipsis_p
= invis_p
== 2;
3116 handled
= HANDLED_RECOMPUTE_PROPS
;
3118 /* Loop skipping over invisible text. The loop is left at
3119 ZV or with IT on the first char being visible again. */
3122 /* Try to skip some invisible text. Return value is the
3123 position reached which can be equal to IT's position
3124 if there is nothing invisible here. This skips both
3125 over invisible text properties and overlays with
3126 invisible property. */
3127 newpos
= skip_invisible (IT_CHARPOS (*it
),
3128 &next_stop
, ZV
, it
->window
);
3130 /* If we skipped nothing at all we weren't at invisible
3131 text in the first place. If everything to the end of
3132 the buffer was skipped, end the loop. */
3133 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3137 /* We skipped some characters but not necessarily
3138 all there are. Check if we ended up on visible
3139 text. Fget_char_property returns the property of
3140 the char before the given position, i.e. if we
3141 get invis_p = 0, this means that the char at
3142 newpos is visible. */
3143 pos
= make_number (newpos
);
3144 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3145 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3148 /* If we ended up on invisible text, proceed to
3149 skip starting with next_stop. */
3151 IT_CHARPOS (*it
) = next_stop
;
3155 /* The position newpos is now either ZV or on visible text. */
3156 IT_CHARPOS (*it
) = newpos
;
3157 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3159 /* If there are before-strings at the start of invisible
3160 text, and the text is invisible because of a text
3161 property, arrange to show before-strings because 20.x did
3162 it that way. (If the text is invisible because of an
3163 overlay property instead of a text property, this is
3164 already handled in the overlay code.) */
3166 && get_overlay_strings (it
, start_charpos
))
3168 handled
= HANDLED_RECOMPUTE_PROPS
;
3169 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3171 else if (display_ellipsis_p
)
3172 setup_for_ellipsis (it
);
3180 /* Make iterator IT return `...' next. */
3183 setup_for_ellipsis (it
)
3187 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3189 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3190 it
->dpvec
= v
->contents
;
3191 it
->dpend
= v
->contents
+ v
->size
;
3195 /* Default `...'. */
3196 it
->dpvec
= default_invis_vector
;
3197 it
->dpend
= default_invis_vector
+ 3;
3200 /* The ellipsis display does not replace the display of the
3201 character at the new position. Indicate this by setting
3202 IT->dpvec_char_len to zero. */
3203 it
->dpvec_char_len
= 0;
3205 it
->current
.dpvec_index
= 0;
3206 it
->method
= next_element_from_display_vector
;
3211 /***********************************************************************
3213 ***********************************************************************/
3215 /* Set up iterator IT from `display' property at its current position.
3216 Called from handle_stop. */
3218 static enum prop_handled
3219 handle_display_prop (it
)
3222 Lisp_Object prop
, object
;
3223 struct text_pos
*position
;
3224 int display_replaced_p
= 0;
3226 if (STRINGP (it
->string
))
3228 object
= it
->string
;
3229 position
= &it
->current
.string_pos
;
3233 object
= it
->w
->buffer
;
3234 position
= &it
->current
.pos
;
3237 /* Reset those iterator values set from display property values. */
3238 it
->font_height
= Qnil
;
3239 it
->space_width
= Qnil
;
3242 /* We don't support recursive `display' properties, i.e. string
3243 values that have a string `display' property, that have a string
3244 `display' property etc. */
3245 if (!it
->string_from_display_prop_p
)
3246 it
->area
= TEXT_AREA
;
3248 prop
= Fget_char_property (make_number (position
->charpos
),
3251 return HANDLED_NORMALLY
;
3254 /* Simple properties. */
3255 && !EQ (XCAR (prop
), Qimage
)
3256 && !EQ (XCAR (prop
), Qspace
)
3257 && !EQ (XCAR (prop
), Qwhen
)
3258 && !EQ (XCAR (prop
), Qspace_width
)
3259 && !EQ (XCAR (prop
), Qheight
)
3260 && !EQ (XCAR (prop
), Qraise
)
3261 /* Marginal area specifications. */
3262 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3263 && !NILP (XCAR (prop
)))
3265 for (; CONSP (prop
); prop
= XCDR (prop
))
3267 if (handle_single_display_prop (it
, XCAR (prop
), object
,
3268 position
, display_replaced_p
))
3269 display_replaced_p
= 1;
3272 else if (VECTORP (prop
))
3275 for (i
= 0; i
< ASIZE (prop
); ++i
)
3276 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
3277 position
, display_replaced_p
))
3278 display_replaced_p
= 1;
3282 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
3283 display_replaced_p
= 1;
3286 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3290 /* Value is the position of the end of the `display' property starting
3291 at START_POS in OBJECT. */
3293 static struct text_pos
3294 display_prop_end (it
, object
, start_pos
)
3297 struct text_pos start_pos
;
3300 struct text_pos end_pos
;
3302 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3303 Qdisplay
, object
, Qnil
);
3304 CHARPOS (end_pos
) = XFASTINT (end
);
3305 if (STRINGP (object
))
3306 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3308 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3314 /* Set up IT from a single `display' sub-property value PROP. OBJECT
3315 is the object in which the `display' property was found. *POSITION
3316 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3317 means that we previously saw a display sub-property which already
3318 replaced text display with something else, for example an image;
3319 ignore such properties after the first one has been processed.
3321 If PROP is a `space' or `image' sub-property, set *POSITION to the
3322 end position of the `display' property.
3324 Value is non-zero if something was found which replaces the display
3325 of buffer or string text. */
3328 handle_single_display_prop (it
, prop
, object
, position
,
3329 display_replaced_before_p
)
3333 struct text_pos
*position
;
3334 int display_replaced_before_p
;
3337 int replaces_text_display_p
= 0;
3340 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
3341 evaluated. If the result is nil, VALUE is ignored. */
3343 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3352 if (!NILP (form
) && !EQ (form
, Qt
))
3354 int count
= SPECPDL_INDEX ();
3355 struct gcpro gcpro1
;
3357 /* Bind `object' to the object having the `display' property, a
3358 buffer or string. Bind `position' to the position in the
3359 object where the property was found, and `buffer-position'
3360 to the current position in the buffer. */
3361 specbind (Qobject
, object
);
3362 specbind (Qposition
, make_number (CHARPOS (*position
)));
3363 specbind (Qbuffer_position
,
3364 make_number (STRINGP (object
)
3365 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3367 form
= safe_eval (form
);
3369 unbind_to (count
, Qnil
);
3376 && EQ (XCAR (prop
), Qheight
)
3377 && CONSP (XCDR (prop
)))
3379 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3382 /* `(height HEIGHT)'. */
3383 it
->font_height
= XCAR (XCDR (prop
));
3384 if (!NILP (it
->font_height
))
3386 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3387 int new_height
= -1;
3389 if (CONSP (it
->font_height
)
3390 && (EQ (XCAR (it
->font_height
), Qplus
)
3391 || EQ (XCAR (it
->font_height
), Qminus
))
3392 && CONSP (XCDR (it
->font_height
))
3393 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3395 /* `(+ N)' or `(- N)' where N is an integer. */
3396 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3397 if (EQ (XCAR (it
->font_height
), Qplus
))
3399 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3401 else if (FUNCTIONP (it
->font_height
))
3403 /* Call function with current height as argument.
3404 Value is the new height. */
3406 height
= safe_call1 (it
->font_height
,
3407 face
->lface
[LFACE_HEIGHT_INDEX
]);
3408 if (NUMBERP (height
))
3409 new_height
= XFLOATINT (height
);
3411 else if (NUMBERP (it
->font_height
))
3413 /* Value is a multiple of the canonical char height. */
3416 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3417 new_height
= (XFLOATINT (it
->font_height
)
3418 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3422 /* Evaluate IT->font_height with `height' bound to the
3423 current specified height to get the new height. */
3425 int count
= SPECPDL_INDEX ();
3427 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3428 value
= safe_eval (it
->font_height
);
3429 unbind_to (count
, Qnil
);
3431 if (NUMBERP (value
))
3432 new_height
= XFLOATINT (value
);
3436 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3439 else if (CONSP (prop
)
3440 && EQ (XCAR (prop
), Qspace_width
)
3441 && CONSP (XCDR (prop
)))
3443 /* `(space_width WIDTH)'. */
3444 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3447 value
= XCAR (XCDR (prop
));
3448 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3449 it
->space_width
= value
;
3451 else if (CONSP (prop
)
3452 && EQ (XCAR (prop
), Qraise
)
3453 && CONSP (XCDR (prop
)))
3455 /* `(raise FACTOR)'. */
3456 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3459 #ifdef HAVE_WINDOW_SYSTEM
3460 value
= XCAR (XCDR (prop
));
3461 if (NUMBERP (value
))
3463 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3464 it
->voffset
= - (XFLOATINT (value
)
3465 * (FONT_HEIGHT (face
->font
)));
3467 #endif /* HAVE_WINDOW_SYSTEM */
3469 else if (!it
->string_from_display_prop_p
)
3471 /* `((margin left-margin) VALUE)' or `((margin right-margin)
3472 VALUE) or `((margin nil) VALUE)' or VALUE. */
3473 Lisp_Object location
, value
;
3474 struct text_pos start_pos
;
3477 /* Characters having this form of property are not displayed, so
3478 we have to find the end of the property. */
3479 start_pos
= *position
;
3480 *position
= display_prop_end (it
, object
, start_pos
);
3483 /* Let's stop at the new position and assume that all
3484 text properties change there. */
3485 it
->stop_charpos
= position
->charpos
;
3487 location
= Qunbound
;
3488 if (CONSP (prop
) && CONSP (XCAR (prop
)))
3492 value
= XCDR (prop
);
3494 value
= XCAR (value
);
3497 if (EQ (XCAR (tem
), Qmargin
)
3498 && (tem
= XCDR (tem
),
3499 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3501 || EQ (tem
, Qleft_margin
)
3502 || EQ (tem
, Qright_margin
))))
3506 if (EQ (location
, Qunbound
))
3512 #ifdef HAVE_WINDOW_SYSTEM
3513 if (FRAME_TERMCAP_P (it
->f
))
3514 valid_p
= STRINGP (value
);
3516 valid_p
= (STRINGP (value
)
3517 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3518 || valid_image_p (value
));
3519 #else /* not HAVE_WINDOW_SYSTEM */
3520 valid_p
= STRINGP (value
);
3521 #endif /* not HAVE_WINDOW_SYSTEM */
3523 if ((EQ (location
, Qleft_margin
)
3524 || EQ (location
, Qright_margin
)
3527 && !display_replaced_before_p
)
3529 replaces_text_display_p
= 1;
3531 /* Save current settings of IT so that we can restore them
3532 when we are finished with the glyph property value. */
3535 if (NILP (location
))
3536 it
->area
= TEXT_AREA
;
3537 else if (EQ (location
, Qleft_margin
))
3538 it
->area
= LEFT_MARGIN_AREA
;
3540 it
->area
= RIGHT_MARGIN_AREA
;
3542 if (STRINGP (value
))
3545 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3546 it
->current
.overlay_string_index
= -1;
3547 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3548 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3549 it
->method
= next_element_from_string
;
3550 it
->stop_charpos
= 0;
3551 it
->string_from_display_prop_p
= 1;
3552 /* Say that we haven't consumed the characters with
3553 `display' property yet. The call to pop_it in
3554 set_iterator_to_next will clean this up. */
3555 *position
= start_pos
;
3557 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3559 it
->method
= next_element_from_stretch
;
3561 it
->current
.pos
= it
->position
= start_pos
;
3563 #ifdef HAVE_WINDOW_SYSTEM
3566 it
->what
= IT_IMAGE
;
3567 it
->image_id
= lookup_image (it
->f
, value
);
3568 it
->position
= start_pos
;
3569 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3570 it
->method
= next_element_from_image
;
3572 /* Say that we haven't consumed the characters with
3573 `display' property yet. The call to pop_it in
3574 set_iterator_to_next will clean this up. */
3575 *position
= start_pos
;
3577 #endif /* HAVE_WINDOW_SYSTEM */
3580 /* Invalid property or property not supported. Restore
3581 the position to what it was before. */
3582 *position
= start_pos
;
3585 return replaces_text_display_p
;
3589 /* Check if PROP is a display sub-property value whose text should be
3590 treated as intangible. */
3593 single_display_prop_intangible_p (prop
)
3596 /* Skip over `when FORM'. */
3597 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3611 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3612 we don't need to treat text as intangible. */
3613 if (EQ (XCAR (prop
), Qmargin
))
3621 || EQ (XCAR (prop
), Qleft_margin
)
3622 || EQ (XCAR (prop
), Qright_margin
))
3626 return (CONSP (prop
)
3627 && (EQ (XCAR (prop
), Qimage
)
3628 || EQ (XCAR (prop
), Qspace
)));
3632 /* Check if PROP is a display property value whose text should be
3633 treated as intangible. */
3636 display_prop_intangible_p (prop
)
3640 && CONSP (XCAR (prop
))
3641 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3643 /* A list of sub-properties. */
3644 while (CONSP (prop
))
3646 if (single_display_prop_intangible_p (XCAR (prop
)))
3651 else if (VECTORP (prop
))
3653 /* A vector of sub-properties. */
3655 for (i
= 0; i
< ASIZE (prop
); ++i
)
3656 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3660 return single_display_prop_intangible_p (prop
);
3666 /* Return 1 if PROP is a display sub-property value containing STRING. */
3669 single_display_prop_string_p (prop
, string
)
3670 Lisp_Object prop
, string
;
3672 if (EQ (string
, prop
))
3675 /* Skip over `when FORM'. */
3676 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3685 /* Skip over `margin LOCATION'. */
3686 if (EQ (XCAR (prop
), Qmargin
))
3697 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3701 /* Return 1 if STRING appears in the `display' property PROP. */
3704 display_prop_string_p (prop
, string
)
3705 Lisp_Object prop
, string
;
3708 && CONSP (XCAR (prop
))
3709 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3711 /* A list of sub-properties. */
3712 while (CONSP (prop
))
3714 if (single_display_prop_string_p (XCAR (prop
), string
))
3719 else if (VECTORP (prop
))
3721 /* A vector of sub-properties. */
3723 for (i
= 0; i
< ASIZE (prop
); ++i
)
3724 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3728 return single_display_prop_string_p (prop
, string
);
3734 /* Determine from which buffer position in W's buffer STRING comes
3735 from. AROUND_CHARPOS is an approximate position where it could
3736 be from. Value is the buffer position or 0 if it couldn't be
3739 W's buffer must be current.
3741 This function is necessary because we don't record buffer positions
3742 in glyphs generated from strings (to keep struct glyph small).
3743 This function may only use code that doesn't eval because it is
3744 called asynchronously from note_mouse_highlight. */
3747 string_buffer_position (w
, string
, around_charpos
)
3752 Lisp_Object limit
, prop
, pos
;
3753 const int MAX_DISTANCE
= 1000;
3756 pos
= make_number (around_charpos
);
3757 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3758 while (!found
&& !EQ (pos
, limit
))
3760 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3761 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3764 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3769 pos
= make_number (around_charpos
);
3770 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3771 while (!found
&& !EQ (pos
, limit
))
3773 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3774 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3777 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3782 return found
? XINT (pos
) : 0;
3787 /***********************************************************************
3788 `composition' property
3789 ***********************************************************************/
3791 /* Set up iterator IT from `composition' property at its current
3792 position. Called from handle_stop. */
3794 static enum prop_handled
3795 handle_composition_prop (it
)
3798 Lisp_Object prop
, string
;
3799 int pos
, pos_byte
, end
;
3800 enum prop_handled handled
= HANDLED_NORMALLY
;
3802 if (STRINGP (it
->string
))
3804 pos
= IT_STRING_CHARPOS (*it
);
3805 pos_byte
= IT_STRING_BYTEPOS (*it
);
3806 string
= it
->string
;
3810 pos
= IT_CHARPOS (*it
);
3811 pos_byte
= IT_BYTEPOS (*it
);
3815 /* If there's a valid composition and point is not inside of the
3816 composition (in the case that the composition is from the current
3817 buffer), draw a glyph composed from the composition components. */
3818 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3819 && COMPOSITION_VALID_P (pos
, end
, prop
)
3820 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3822 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3826 it
->method
= next_element_from_composition
;
3828 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3829 /* For a terminal, draw only the first character of the
3831 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3832 it
->len
= (STRINGP (it
->string
)
3833 ? string_char_to_byte (it
->string
, end
)
3834 : CHAR_TO_BYTE (end
)) - pos_byte
;
3835 it
->stop_charpos
= end
;
3836 handled
= HANDLED_RETURN
;
3845 /***********************************************************************
3847 ***********************************************************************/
3849 /* The following structure is used to record overlay strings for
3850 later sorting in load_overlay_strings. */
3852 struct overlay_entry
3854 Lisp_Object overlay
;
3861 /* Set up iterator IT from overlay strings at its current position.
3862 Called from handle_stop. */
3864 static enum prop_handled
3865 handle_overlay_change (it
)
3868 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
3869 return HANDLED_RECOMPUTE_PROPS
;
3871 return HANDLED_NORMALLY
;
3875 /* Set up the next overlay string for delivery by IT, if there is an
3876 overlay string to deliver. Called by set_iterator_to_next when the
3877 end of the current overlay string is reached. If there are more
3878 overlay strings to display, IT->string and
3879 IT->current.overlay_string_index are set appropriately here.
3880 Otherwise IT->string is set to nil. */
3883 next_overlay_string (it
)
3886 ++it
->current
.overlay_string_index
;
3887 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3889 /* No more overlay strings. Restore IT's settings to what
3890 they were before overlay strings were processed, and
3891 continue to deliver from current_buffer. */
3892 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
3895 xassert (it
->stop_charpos
>= BEGV
3896 && it
->stop_charpos
<= it
->end_charpos
);
3898 it
->current
.overlay_string_index
= -1;
3899 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3900 it
->n_overlay_strings
= 0;
3901 it
->method
= next_element_from_buffer
;
3903 /* If we're at the end of the buffer, record that we have
3904 processed the overlay strings there already, so that
3905 next_element_from_buffer doesn't try it again. */
3906 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3907 it
->overlay_strings_at_end_processed_p
= 1;
3909 /* If we have to display `...' for invisible text, set
3910 the iterator up for that. */
3911 if (display_ellipsis_p
)
3912 setup_for_ellipsis (it
);
3916 /* There are more overlay strings to process. If
3917 IT->current.overlay_string_index has advanced to a position
3918 where we must load IT->overlay_strings with more strings, do
3920 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3922 if (it
->current
.overlay_string_index
&& i
== 0)
3923 load_overlay_strings (it
, 0);
3925 /* Initialize IT to deliver display elements from the overlay
3927 it
->string
= it
->overlay_strings
[i
];
3928 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3929 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3930 it
->method
= next_element_from_string
;
3931 it
->stop_charpos
= 0;
3938 /* Compare two overlay_entry structures E1 and E2. Used as a
3939 comparison function for qsort in load_overlay_strings. Overlay
3940 strings for the same position are sorted so that
3942 1. All after-strings come in front of before-strings, except
3943 when they come from the same overlay.
3945 2. Within after-strings, strings are sorted so that overlay strings
3946 from overlays with higher priorities come first.
3948 2. Within before-strings, strings are sorted so that overlay
3949 strings from overlays with higher priorities come last.
3951 Value is analogous to strcmp. */
3955 compare_overlay_entries (e1
, e2
)
3958 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3959 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3962 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3964 /* Let after-strings appear in front of before-strings if
3965 they come from different overlays. */
3966 if (EQ (entry1
->overlay
, entry2
->overlay
))
3967 result
= entry1
->after_string_p
? 1 : -1;
3969 result
= entry1
->after_string_p
? -1 : 1;
3971 else if (entry1
->after_string_p
)
3972 /* After-strings sorted in order of decreasing priority. */
3973 result
= entry2
->priority
- entry1
->priority
;
3975 /* Before-strings sorted in order of increasing priority. */
3976 result
= entry1
->priority
- entry2
->priority
;
3982 /* Load the vector IT->overlay_strings with overlay strings from IT's
3983 current buffer position, or from CHARPOS if that is > 0. Set
3984 IT->n_overlays to the total number of overlay strings found.
3986 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3987 a time. On entry into load_overlay_strings,
3988 IT->current.overlay_string_index gives the number of overlay
3989 strings that have already been loaded by previous calls to this
3992 IT->add_overlay_start contains an additional overlay start
3993 position to consider for taking overlay strings from, if non-zero.
3994 This position comes into play when the overlay has an `invisible'
3995 property, and both before and after-strings. When we've skipped to
3996 the end of the overlay, because of its `invisible' property, we
3997 nevertheless want its before-string to appear.
3998 IT->add_overlay_start will contain the overlay start position
4001 Overlay strings are sorted so that after-string strings come in
4002 front of before-string strings. Within before and after-strings,
4003 strings are sorted by overlay priority. See also function
4004 compare_overlay_entries. */
4007 load_overlay_strings (it
, charpos
)
4011 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4012 Lisp_Object overlay
, window
, str
, invisible
;
4013 struct Lisp_Overlay
*ov
;
4016 int n
= 0, i
, j
, invis_p
;
4017 struct overlay_entry
*entries
4018 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4021 charpos
= IT_CHARPOS (*it
);
4023 /* Append the overlay string STRING of overlay OVERLAY to vector
4024 `entries' which has size `size' and currently contains `n'
4025 elements. AFTER_P non-zero means STRING is an after-string of
4027 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4030 Lisp_Object priority; \
4034 int new_size = 2 * size; \
4035 struct overlay_entry *old = entries; \
4037 (struct overlay_entry *) alloca (new_size \
4038 * sizeof *entries); \
4039 bcopy (old, entries, size * sizeof *entries); \
4043 entries[n].string = (STRING); \
4044 entries[n].overlay = (OVERLAY); \
4045 priority = Foverlay_get ((OVERLAY), Qpriority); \
4046 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4047 entries[n].after_string_p = (AFTER_P); \
4052 /* Process overlay before the overlay center. */
4053 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4055 XSETMISC (overlay
, ov
);
4056 xassert (OVERLAYP (overlay
));
4057 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4058 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4063 /* Skip this overlay if it doesn't start or end at IT's current
4065 if (end
!= charpos
&& start
!= charpos
)
4068 /* Skip this overlay if it doesn't apply to IT->w. */
4069 window
= Foverlay_get (overlay
, Qwindow
);
4070 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4073 /* If the text ``under'' the overlay is invisible, both before-
4074 and after-strings from this overlay are visible; start and
4075 end position are indistinguishable. */
4076 invisible
= Foverlay_get (overlay
, Qinvisible
);
4077 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4079 /* If overlay has a non-empty before-string, record it. */
4080 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4081 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4083 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4085 /* If overlay has a non-empty after-string, record it. */
4086 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4087 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4089 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4092 /* Process overlays after the overlay center. */
4093 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4095 XSETMISC (overlay
, ov
);
4096 xassert (OVERLAYP (overlay
));
4097 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4098 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4100 if (start
> charpos
)
4103 /* Skip this overlay if it doesn't start or end at IT's current
4105 if (end
!= charpos
&& start
!= charpos
)
4108 /* Skip this overlay if it doesn't apply to IT->w. */
4109 window
= Foverlay_get (overlay
, Qwindow
);
4110 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4113 /* If the text ``under'' the overlay is invisible, it has a zero
4114 dimension, and both before- and after-strings apply. */
4115 invisible
= Foverlay_get (overlay
, Qinvisible
);
4116 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4118 /* If overlay has a non-empty before-string, record it. */
4119 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4120 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4122 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4124 /* If overlay has a non-empty after-string, record it. */
4125 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4126 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4128 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4131 #undef RECORD_OVERLAY_STRING
4135 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4137 /* Record the total number of strings to process. */
4138 it
->n_overlay_strings
= n
;
4140 /* IT->current.overlay_string_index is the number of overlay strings
4141 that have already been consumed by IT. Copy some of the
4142 remaining overlay strings to IT->overlay_strings. */
4144 j
= it
->current
.overlay_string_index
;
4145 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4146 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4152 /* Get the first chunk of overlay strings at IT's current buffer
4153 position, or at CHARPOS if that is > 0. Value is non-zero if at
4154 least one overlay string was found. */
4157 get_overlay_strings (it
, charpos
)
4161 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4162 process. This fills IT->overlay_strings with strings, and sets
4163 IT->n_overlay_strings to the total number of strings to process.
4164 IT->pos.overlay_string_index has to be set temporarily to zero
4165 because load_overlay_strings needs this; it must be set to -1
4166 when no overlay strings are found because a zero value would
4167 indicate a position in the first overlay string. */
4168 it
->current
.overlay_string_index
= 0;
4169 load_overlay_strings (it
, charpos
);
4171 /* If we found overlay strings, set up IT to deliver display
4172 elements from the first one. Otherwise set up IT to deliver
4173 from current_buffer. */
4174 if (it
->n_overlay_strings
)
4176 /* Make sure we know settings in current_buffer, so that we can
4177 restore meaningful values when we're done with the overlay
4179 compute_stop_pos (it
);
4180 xassert (it
->face_id
>= 0);
4182 /* Save IT's settings. They are restored after all overlay
4183 strings have been processed. */
4184 xassert (it
->sp
== 0);
4187 /* Set up IT to deliver display elements from the first overlay
4189 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4190 it
->string
= it
->overlay_strings
[0];
4191 it
->stop_charpos
= 0;
4192 xassert (STRINGP (it
->string
));
4193 it
->end_charpos
= SCHARS (it
->string
);
4194 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4195 it
->method
= next_element_from_string
;
4200 it
->current
.overlay_string_index
= -1;
4201 it
->method
= next_element_from_buffer
;
4206 /* Value is non-zero if we found at least one overlay string. */
4207 return STRINGP (it
->string
);
4212 /***********************************************************************
4213 Saving and restoring state
4214 ***********************************************************************/
4216 /* Save current settings of IT on IT->stack. Called, for example,
4217 before setting up IT for an overlay string, to be able to restore
4218 IT's settings to what they were after the overlay string has been
4225 struct iterator_stack_entry
*p
;
4227 xassert (it
->sp
< 2);
4228 p
= it
->stack
+ it
->sp
;
4230 p
->stop_charpos
= it
->stop_charpos
;
4231 xassert (it
->face_id
>= 0);
4232 p
->face_id
= it
->face_id
;
4233 p
->string
= it
->string
;
4234 p
->pos
= it
->current
;
4235 p
->end_charpos
= it
->end_charpos
;
4236 p
->string_nchars
= it
->string_nchars
;
4238 p
->multibyte_p
= it
->multibyte_p
;
4239 p
->space_width
= it
->space_width
;
4240 p
->font_height
= it
->font_height
;
4241 p
->voffset
= it
->voffset
;
4242 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4243 p
->display_ellipsis_p
= 0;
4248 /* Restore IT's settings from IT->stack. Called, for example, when no
4249 more overlay strings must be processed, and we return to delivering
4250 display elements from a buffer, or when the end of a string from a
4251 `display' property is reached and we return to delivering display
4252 elements from an overlay string, or from a buffer. */
4258 struct iterator_stack_entry
*p
;
4260 xassert (it
->sp
> 0);
4262 p
= it
->stack
+ it
->sp
;
4263 it
->stop_charpos
= p
->stop_charpos
;
4264 it
->face_id
= p
->face_id
;
4265 it
->string
= p
->string
;
4266 it
->current
= p
->pos
;
4267 it
->end_charpos
= p
->end_charpos
;
4268 it
->string_nchars
= p
->string_nchars
;
4270 it
->multibyte_p
= p
->multibyte_p
;
4271 it
->space_width
= p
->space_width
;
4272 it
->font_height
= p
->font_height
;
4273 it
->voffset
= p
->voffset
;
4274 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4279 /***********************************************************************
4281 ***********************************************************************/
4283 /* Set IT's current position to the previous line start. */
4286 back_to_previous_line_start (it
)
4289 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4290 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4294 /* Move IT to the next line start.
4296 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4297 we skipped over part of the text (as opposed to moving the iterator
4298 continuously over the text). Otherwise, don't change the value
4301 Newlines may come from buffer text, overlay strings, or strings
4302 displayed via the `display' property. That's the reason we can't
4303 simply use find_next_newline_no_quit.
4305 Note that this function may not skip over invisible text that is so
4306 because of text properties and immediately follows a newline. If
4307 it would, function reseat_at_next_visible_line_start, when called
4308 from set_iterator_to_next, would effectively make invisible
4309 characters following a newline part of the wrong glyph row, which
4310 leads to wrong cursor motion. */
4313 forward_to_next_line_start (it
, skipped_p
)
4317 int old_selective
, newline_found_p
, n
;
4318 const int MAX_NEWLINE_DISTANCE
= 500;
4320 /* If already on a newline, just consume it to avoid unintended
4321 skipping over invisible text below. */
4322 if (it
->what
== IT_CHARACTER
4324 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4326 set_iterator_to_next (it
, 0);
4331 /* Don't handle selective display in the following. It's (a)
4332 unnecessary because it's done by the caller, and (b) leads to an
4333 infinite recursion because next_element_from_ellipsis indirectly
4334 calls this function. */
4335 old_selective
= it
->selective
;
4338 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4339 from buffer text. */
4340 for (n
= newline_found_p
= 0;
4341 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4342 n
+= STRINGP (it
->string
) ? 0 : 1)
4344 if (!get_next_display_element (it
))
4346 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4347 set_iterator_to_next (it
, 0);
4350 /* If we didn't find a newline near enough, see if we can use a
4352 if (!newline_found_p
)
4354 int start
= IT_CHARPOS (*it
);
4355 int limit
= find_next_newline_no_quit (start
, 1);
4358 xassert (!STRINGP (it
->string
));
4360 /* If there isn't any `display' property in sight, and no
4361 overlays, we can just use the position of the newline in
4363 if (it
->stop_charpos
>= limit
4364 || ((pos
= Fnext_single_property_change (make_number (start
),
4366 Qnil
, make_number (limit
)),
4368 && next_overlay_change (start
) == ZV
))
4370 IT_CHARPOS (*it
) = limit
;
4371 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4372 *skipped_p
= newline_found_p
= 1;
4376 while (get_next_display_element (it
)
4377 && !newline_found_p
)
4379 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4380 set_iterator_to_next (it
, 0);
4385 it
->selective
= old_selective
;
4386 return newline_found_p
;
4390 /* Set IT's current position to the previous visible line start. Skip
4391 invisible text that is so either due to text properties or due to
4392 selective display. Caution: this does not change IT->current_x and
4396 back_to_previous_visible_line_start (it
)
4401 /* Go back one newline if not on BEGV already. */
4402 if (IT_CHARPOS (*it
) > BEGV
)
4403 back_to_previous_line_start (it
);
4405 /* Move over lines that are invisible because of selective display
4406 or text properties. */
4407 while (IT_CHARPOS (*it
) > BEGV
4412 /* If selective > 0, then lines indented more than that values
4414 if (it
->selective
> 0
4415 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4416 (double) it
->selective
)) /* iftc */
4422 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
4423 Qinvisible
, it
->window
);
4424 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4428 /* Back one more newline if the current one is invisible. */
4430 back_to_previous_line_start (it
);
4433 xassert (IT_CHARPOS (*it
) >= BEGV
);
4434 xassert (IT_CHARPOS (*it
) == BEGV
4435 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4440 /* Reseat iterator IT at the previous visible line start. Skip
4441 invisible text that is so either due to text properties or due to
4442 selective display. At the end, update IT's overlay information,
4443 face information etc. */
4446 reseat_at_previous_visible_line_start (it
)
4449 back_to_previous_visible_line_start (it
);
4450 reseat (it
, it
->current
.pos
, 1);
4455 /* Reseat iterator IT on the next visible line start in the current
4456 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4457 preceding the line start. Skip over invisible text that is so
4458 because of selective display. Compute faces, overlays etc at the
4459 new position. Note that this function does not skip over text that
4460 is invisible because of text properties. */
4463 reseat_at_next_visible_line_start (it
, on_newline_p
)
4467 int newline_found_p
, skipped_p
= 0;
4469 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4471 /* Skip over lines that are invisible because they are indented
4472 more than the value of IT->selective. */
4473 if (it
->selective
> 0)
4474 while (IT_CHARPOS (*it
) < ZV
4475 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4476 (double) it
->selective
)) /* iftc */
4478 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4479 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4482 /* Position on the newline if that's what's requested. */
4483 if (on_newline_p
&& newline_found_p
)
4485 if (STRINGP (it
->string
))
4487 if (IT_STRING_CHARPOS (*it
) > 0)
4489 --IT_STRING_CHARPOS (*it
);
4490 --IT_STRING_BYTEPOS (*it
);
4493 else if (IT_CHARPOS (*it
) > BEGV
)
4497 reseat (it
, it
->current
.pos
, 0);
4501 reseat (it
, it
->current
.pos
, 0);
4508 /***********************************************************************
4509 Changing an iterator's position
4510 ***********************************************************************/
4512 /* Change IT's current position to POS in current_buffer. If FORCE_P
4513 is non-zero, always check for text properties at the new position.
4514 Otherwise, text properties are only looked up if POS >=
4515 IT->check_charpos of a property. */
4518 reseat (it
, pos
, force_p
)
4520 struct text_pos pos
;
4523 int original_pos
= IT_CHARPOS (*it
);
4525 reseat_1 (it
, pos
, 0);
4527 /* Determine where to check text properties. Avoid doing it
4528 where possible because text property lookup is very expensive. */
4530 || CHARPOS (pos
) > it
->stop_charpos
4531 || CHARPOS (pos
) < original_pos
)
4538 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4539 IT->stop_pos to POS, also. */
4542 reseat_1 (it
, pos
, set_stop_p
)
4544 struct text_pos pos
;
4547 /* Don't call this function when scanning a C string. */
4548 xassert (it
->s
== NULL
);
4550 /* POS must be a reasonable value. */
4551 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4553 it
->current
.pos
= it
->position
= pos
;
4554 XSETBUFFER (it
->object
, current_buffer
);
4555 it
->end_charpos
= ZV
;
4557 it
->current
.dpvec_index
= -1;
4558 it
->current
.overlay_string_index
= -1;
4559 IT_STRING_CHARPOS (*it
) = -1;
4560 IT_STRING_BYTEPOS (*it
) = -1;
4562 it
->method
= next_element_from_buffer
;
4563 /* RMS: I added this to fix a bug in move_it_vertically_backward
4564 where it->area continued to relate to the starting point
4565 for the backward motion. Bug report from
4566 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
4567 However, I am not sure whether reseat still does the right thing
4568 in general after this change. */
4569 it
->area
= TEXT_AREA
;
4570 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4572 it
->face_before_selective_p
= 0;
4575 it
->stop_charpos
= CHARPOS (pos
);
4579 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4580 If S is non-null, it is a C string to iterate over. Otherwise,
4581 STRING gives a Lisp string to iterate over.
4583 If PRECISION > 0, don't return more then PRECISION number of
4584 characters from the string.
4586 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4587 characters have been returned. FIELD_WIDTH < 0 means an infinite
4590 MULTIBYTE = 0 means disable processing of multibyte characters,
4591 MULTIBYTE > 0 means enable it,
4592 MULTIBYTE < 0 means use IT->multibyte_p.
4594 IT must be initialized via a prior call to init_iterator before
4595 calling this function. */
4598 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4603 int precision
, field_width
, multibyte
;
4605 /* No region in strings. */
4606 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4608 /* No text property checks performed by default, but see below. */
4609 it
->stop_charpos
= -1;
4611 /* Set iterator position and end position. */
4612 bzero (&it
->current
, sizeof it
->current
);
4613 it
->current
.overlay_string_index
= -1;
4614 it
->current
.dpvec_index
= -1;
4615 xassert (charpos
>= 0);
4617 /* If STRING is specified, use its multibyteness, otherwise use the
4618 setting of MULTIBYTE, if specified. */
4620 it
->multibyte_p
= multibyte
> 0;
4624 xassert (STRINGP (string
));
4625 it
->string
= string
;
4627 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4628 it
->method
= next_element_from_string
;
4629 it
->current
.string_pos
= string_pos (charpos
, string
);
4636 /* Note that we use IT->current.pos, not it->current.string_pos,
4637 for displaying C strings. */
4638 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4639 if (it
->multibyte_p
)
4641 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4642 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4646 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4647 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4650 it
->method
= next_element_from_c_string
;
4653 /* PRECISION > 0 means don't return more than PRECISION characters
4655 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4656 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4658 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4659 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4660 FIELD_WIDTH < 0 means infinite field width. This is useful for
4661 padding with `-' at the end of a mode line. */
4662 if (field_width
< 0)
4663 field_width
= INFINITY
;
4664 if (field_width
> it
->end_charpos
- charpos
)
4665 it
->end_charpos
= charpos
+ field_width
;
4667 /* Use the standard display table for displaying strings. */
4668 if (DISP_TABLE_P (Vstandard_display_table
))
4669 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4671 it
->stop_charpos
= charpos
;
4677 /***********************************************************************
4679 ***********************************************************************/
4681 /* Load IT's display element fields with information about the next
4682 display element from the current position of IT. Value is zero if
4683 end of buffer (or C string) is reached. */
4686 get_next_display_element (it
)
4689 /* Non-zero means that we found a display element. Zero means that
4690 we hit the end of what we iterate over. Performance note: the
4691 function pointer `method' used here turns out to be faster than
4692 using a sequence of if-statements. */
4693 int success_p
= (*it
->method
) (it
);
4695 if (it
->what
== IT_CHARACTER
)
4697 /* Map via display table or translate control characters.
4698 IT->c, IT->len etc. have been set to the next character by
4699 the function call above. If we have a display table, and it
4700 contains an entry for IT->c, translate it. Don't do this if
4701 IT->c itself comes from a display table, otherwise we could
4702 end up in an infinite recursion. (An alternative could be to
4703 count the recursion depth of this function and signal an
4704 error when a certain maximum depth is reached.) Is it worth
4706 if (success_p
&& it
->dpvec
== NULL
)
4711 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4714 struct Lisp_Vector
*v
= XVECTOR (dv
);
4716 /* Return the first character from the display table
4717 entry, if not empty. If empty, don't display the
4718 current character. */
4721 it
->dpvec_char_len
= it
->len
;
4722 it
->dpvec
= v
->contents
;
4723 it
->dpend
= v
->contents
+ v
->size
;
4724 it
->current
.dpvec_index
= 0;
4725 it
->method
= next_element_from_display_vector
;
4726 success_p
= get_next_display_element (it
);
4730 set_iterator_to_next (it
, 0);
4731 success_p
= get_next_display_element (it
);
4735 /* Translate control characters into `\003' or `^C' form.
4736 Control characters coming from a display table entry are
4737 currently not translated because we use IT->dpvec to hold
4738 the translation. This could easily be changed but I
4739 don't believe that it is worth doing.
4741 If it->multibyte_p is nonzero, eight-bit characters and
4742 non-printable multibyte characters are also translated to
4745 If it->multibyte_p is zero, eight-bit characters that
4746 don't have corresponding multibyte char code are also
4747 translated to octal form. */
4748 else if ((it
->c
< ' '
4749 && (it
->area
!= TEXT_AREA
4750 || (it
->c
!= '\n' && it
->c
!= '\t')))
4754 || !CHAR_PRINTABLE_P (it
->c
))
4756 && it
->c
== unibyte_char_to_multibyte (it
->c
))))
4758 /* IT->c is a control character which must be displayed
4759 either as '\003' or as `^C' where the '\\' and '^'
4760 can be defined in the display table. Fill
4761 IT->ctl_chars with glyphs for what we have to
4762 display. Then, set IT->dpvec to these glyphs. */
4765 if (it
->c
< 128 && it
->ctl_arrow_p
)
4767 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4769 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4770 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4771 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4773 g
= FAST_MAKE_GLYPH ('^', 0);
4774 XSETINT (it
->ctl_chars
[0], g
);
4776 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4777 XSETINT (it
->ctl_chars
[1], g
);
4779 /* Set up IT->dpvec and return first character from it. */
4780 it
->dpvec_char_len
= it
->len
;
4781 it
->dpvec
= it
->ctl_chars
;
4782 it
->dpend
= it
->dpvec
+ 2;
4783 it
->current
.dpvec_index
= 0;
4784 it
->method
= next_element_from_display_vector
;
4785 get_next_display_element (it
);
4789 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4794 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4796 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4797 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4798 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4800 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4802 if (SINGLE_BYTE_CHAR_P (it
->c
))
4803 str
[0] = it
->c
, len
= 1;
4806 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4809 /* It's an invalid character, which
4810 shouldn't happen actually, but due to
4811 bugs it may happen. Let's print the char
4812 as is, there's not much meaningful we can
4815 str
[1] = it
->c
>> 8;
4816 str
[2] = it
->c
>> 16;
4817 str
[3] = it
->c
>> 24;
4822 for (i
= 0; i
< len
; i
++)
4824 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4825 /* Insert three more glyphs into IT->ctl_chars for
4826 the octal display of the character. */
4827 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4828 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4829 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4830 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4831 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4832 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4835 /* Set up IT->dpvec and return the first character
4837 it
->dpvec_char_len
= it
->len
;
4838 it
->dpvec
= it
->ctl_chars
;
4839 it
->dpend
= it
->dpvec
+ len
* 4;
4840 it
->current
.dpvec_index
= 0;
4841 it
->method
= next_element_from_display_vector
;
4842 get_next_display_element (it
);
4847 /* Adjust face id for a multibyte character. There are no
4848 multibyte character in unibyte text. */
4851 && FRAME_WINDOW_P (it
->f
))
4853 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4854 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4858 /* Is this character the last one of a run of characters with
4859 box? If yes, set IT->end_of_box_run_p to 1. */
4866 it
->end_of_box_run_p
4867 = ((face_id
= face_after_it_pos (it
),
4868 face_id
!= it
->face_id
)
4869 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4870 face
->box
== FACE_NO_BOX
));
4873 /* Value is 0 if end of buffer or string reached. */
4878 /* Move IT to the next display element.
4880 RESEAT_P non-zero means if called on a newline in buffer text,
4881 skip to the next visible line start.
4883 Functions get_next_display_element and set_iterator_to_next are
4884 separate because I find this arrangement easier to handle than a
4885 get_next_display_element function that also increments IT's
4886 position. The way it is we can first look at an iterator's current
4887 display element, decide whether it fits on a line, and if it does,
4888 increment the iterator position. The other way around we probably
4889 would either need a flag indicating whether the iterator has to be
4890 incremented the next time, or we would have to implement a
4891 decrement position function which would not be easy to write. */
4894 set_iterator_to_next (it
, reseat_p
)
4898 /* Reset flags indicating start and end of a sequence of characters
4899 with box. Reset them at the start of this function because
4900 moving the iterator to a new position might set them. */
4901 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4903 if (it
->method
== next_element_from_buffer
)
4905 /* The current display element of IT is a character from
4906 current_buffer. Advance in the buffer, and maybe skip over
4907 invisible lines that are so because of selective display. */
4908 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4909 reseat_at_next_visible_line_start (it
, 0);
4912 xassert (it
->len
!= 0);
4913 IT_BYTEPOS (*it
) += it
->len
;
4914 IT_CHARPOS (*it
) += 1;
4915 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4918 else if (it
->method
== next_element_from_composition
)
4920 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4921 if (STRINGP (it
->string
))
4923 IT_STRING_BYTEPOS (*it
) += it
->len
;
4924 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4925 it
->method
= next_element_from_string
;
4926 goto consider_string_end
;
4930 IT_BYTEPOS (*it
) += it
->len
;
4931 IT_CHARPOS (*it
) += it
->cmp_len
;
4932 it
->method
= next_element_from_buffer
;
4935 else if (it
->method
== next_element_from_c_string
)
4937 /* Current display element of IT is from a C string. */
4938 IT_BYTEPOS (*it
) += it
->len
;
4939 IT_CHARPOS (*it
) += 1;
4941 else if (it
->method
== next_element_from_display_vector
)
4943 /* Current display element of IT is from a display table entry.
4944 Advance in the display table definition. Reset it to null if
4945 end reached, and continue with characters from buffers/
4947 ++it
->current
.dpvec_index
;
4949 /* Restore face of the iterator to what they were before the
4950 display vector entry (these entries may contain faces). */
4951 it
->face_id
= it
->saved_face_id
;
4953 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4956 it
->method
= next_element_from_c_string
;
4957 else if (STRINGP (it
->string
))
4958 it
->method
= next_element_from_string
;
4960 it
->method
= next_element_from_buffer
;
4963 it
->current
.dpvec_index
= -1;
4965 /* Skip over characters which were displayed via IT->dpvec. */
4966 if (it
->dpvec_char_len
< 0)
4967 reseat_at_next_visible_line_start (it
, 1);
4968 else if (it
->dpvec_char_len
> 0)
4970 it
->len
= it
->dpvec_char_len
;
4971 set_iterator_to_next (it
, reseat_p
);
4975 else if (it
->method
== next_element_from_string
)
4977 /* Current display element is a character from a Lisp string. */
4978 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4979 IT_STRING_BYTEPOS (*it
) += it
->len
;
4980 IT_STRING_CHARPOS (*it
) += 1;
4982 consider_string_end
:
4984 if (it
->current
.overlay_string_index
>= 0)
4986 /* IT->string is an overlay string. Advance to the
4987 next, if there is one. */
4988 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
4989 next_overlay_string (it
);
4993 /* IT->string is not an overlay string. If we reached
4994 its end, and there is something on IT->stack, proceed
4995 with what is on the stack. This can be either another
4996 string, this time an overlay string, or a buffer. */
4997 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5001 if (!STRINGP (it
->string
))
5002 it
->method
= next_element_from_buffer
;
5004 goto consider_string_end
;
5008 else if (it
->method
== next_element_from_image
5009 || it
->method
== next_element_from_stretch
)
5011 /* The position etc with which we have to proceed are on
5012 the stack. The position may be at the end of a string,
5013 if the `display' property takes up the whole string. */
5016 if (STRINGP (it
->string
))
5018 it
->method
= next_element_from_string
;
5019 goto consider_string_end
;
5022 it
->method
= next_element_from_buffer
;
5025 /* There are no other methods defined, so this should be a bug. */
5028 xassert (it
->method
!= next_element_from_string
5029 || (STRINGP (it
->string
)
5030 && IT_STRING_CHARPOS (*it
) >= 0));
5034 /* Load IT's display element fields with information about the next
5035 display element which comes from a display table entry or from the
5036 result of translating a control character to one of the forms `^C'
5037 or `\003'. IT->dpvec holds the glyphs to return as characters. */
5040 next_element_from_display_vector (it
)
5044 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5046 /* Remember the current face id in case glyphs specify faces.
5047 IT's face is restored in set_iterator_to_next. */
5048 it
->saved_face_id
= it
->face_id
;
5050 if (INTEGERP (*it
->dpvec
)
5051 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5056 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5057 it
->c
= FAST_GLYPH_CHAR (g
);
5058 it
->len
= CHAR_BYTES (it
->c
);
5060 /* The entry may contain a face id to use. Such a face id is
5061 the id of a Lisp face, not a realized face. A face id of
5062 zero means no face is specified. */
5063 lface_id
= FAST_GLYPH_FACE (g
);
5066 /* The function returns -1 if lface_id is invalid. */
5067 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
5069 it
->face_id
= face_id
;
5073 /* Display table entry is invalid. Return a space. */
5074 it
->c
= ' ', it
->len
= 1;
5076 /* Don't change position and object of the iterator here. They are
5077 still the values of the character that had this display table
5078 entry or was translated, and that's what we want. */
5079 it
->what
= IT_CHARACTER
;
5084 /* Load IT with the next display element from Lisp string IT->string.
5085 IT->current.string_pos is the current position within the string.
5086 If IT->current.overlay_string_index >= 0, the Lisp string is an
5090 next_element_from_string (it
)
5093 struct text_pos position
;
5095 xassert (STRINGP (it
->string
));
5096 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5097 position
= it
->current
.string_pos
;
5099 /* Time to check for invisible text? */
5100 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5101 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5105 /* Since a handler may have changed IT->method, we must
5107 return get_next_display_element (it
);
5110 if (it
->current
.overlay_string_index
>= 0)
5112 /* Get the next character from an overlay string. In overlay
5113 strings, There is no field width or padding with spaces to
5115 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5120 else if (STRING_MULTIBYTE (it
->string
))
5122 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5123 const unsigned char *s
= (SDATA (it
->string
)
5124 + IT_STRING_BYTEPOS (*it
));
5125 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5129 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5135 /* Get the next character from a Lisp string that is not an
5136 overlay string. Such strings come from the mode line, for
5137 example. We may have to pad with spaces, or truncate the
5138 string. See also next_element_from_c_string. */
5139 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5144 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5146 /* Pad with spaces. */
5147 it
->c
= ' ', it
->len
= 1;
5148 CHARPOS (position
) = BYTEPOS (position
) = -1;
5150 else if (STRING_MULTIBYTE (it
->string
))
5152 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5153 const unsigned char *s
= (SDATA (it
->string
)
5154 + IT_STRING_BYTEPOS (*it
));
5155 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5159 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5164 /* Record what we have and where it came from. Note that we store a
5165 buffer position in IT->position although it could arguably be a
5167 it
->what
= IT_CHARACTER
;
5168 it
->object
= it
->string
;
5169 it
->position
= position
;
5174 /* Load IT with next display element from C string IT->s.
5175 IT->string_nchars is the maximum number of characters to return
5176 from the string. IT->end_charpos may be greater than
5177 IT->string_nchars when this function is called, in which case we
5178 may have to return padding spaces. Value is zero if end of string
5179 reached, including padding spaces. */
5182 next_element_from_c_string (it
)
5188 it
->what
= IT_CHARACTER
;
5189 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5192 /* IT's position can be greater IT->string_nchars in case a field
5193 width or precision has been specified when the iterator was
5195 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5197 /* End of the game. */
5201 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5203 /* Pad with spaces. */
5204 it
->c
= ' ', it
->len
= 1;
5205 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5207 else if (it
->multibyte_p
)
5209 /* Implementation note: The calls to strlen apparently aren't a
5210 performance problem because there is no noticeable performance
5211 difference between Emacs running in unibyte or multibyte mode. */
5212 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5213 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5217 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5223 /* Set up IT to return characters from an ellipsis, if appropriate.
5224 The definition of the ellipsis glyphs may come from a display table
5225 entry. This function Fills IT with the first glyph from the
5226 ellipsis if an ellipsis is to be displayed. */
5229 next_element_from_ellipsis (it
)
5232 if (it
->selective_display_ellipsis_p
)
5234 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
5236 /* Use the display table definition for `...'. Invalid glyphs
5237 will be handled by the method returning elements from dpvec. */
5238 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
5239 it
->dpvec_char_len
= it
->len
;
5240 it
->dpvec
= v
->contents
;
5241 it
->dpend
= v
->contents
+ v
->size
;
5242 it
->current
.dpvec_index
= 0;
5243 it
->method
= next_element_from_display_vector
;
5247 /* Use default `...' which is stored in default_invis_vector. */
5248 it
->dpvec_char_len
= it
->len
;
5249 it
->dpvec
= default_invis_vector
;
5250 it
->dpend
= default_invis_vector
+ 3;
5251 it
->current
.dpvec_index
= 0;
5252 it
->method
= next_element_from_display_vector
;
5257 /* The face at the current position may be different from the
5258 face we find after the invisible text. Remember what it
5259 was in IT->saved_face_id, and signal that it's there by
5260 setting face_before_selective_p. */
5261 it
->saved_face_id
= it
->face_id
;
5262 it
->method
= next_element_from_buffer
;
5263 reseat_at_next_visible_line_start (it
, 1);
5264 it
->face_before_selective_p
= 1;
5267 return get_next_display_element (it
);
5271 /* Deliver an image display element. The iterator IT is already
5272 filled with image information (done in handle_display_prop). Value
5277 next_element_from_image (it
)
5280 it
->what
= IT_IMAGE
;
5285 /* Fill iterator IT with next display element from a stretch glyph
5286 property. IT->object is the value of the text property. Value is
5290 next_element_from_stretch (it
)
5293 it
->what
= IT_STRETCH
;
5298 /* Load IT with the next display element from current_buffer. Value
5299 is zero if end of buffer reached. IT->stop_charpos is the next
5300 position at which to stop and check for text properties or buffer
5304 next_element_from_buffer (it
)
5309 /* Check this assumption, otherwise, we would never enter the
5310 if-statement, below. */
5311 xassert (IT_CHARPOS (*it
) >= BEGV
5312 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
5314 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
5316 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5318 int overlay_strings_follow_p
;
5320 /* End of the game, except when overlay strings follow that
5321 haven't been returned yet. */
5322 if (it
->overlay_strings_at_end_processed_p
)
5323 overlay_strings_follow_p
= 0;
5326 it
->overlay_strings_at_end_processed_p
= 1;
5327 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
5330 if (overlay_strings_follow_p
)
5331 success_p
= get_next_display_element (it
);
5335 it
->position
= it
->current
.pos
;
5342 return get_next_display_element (it
);
5347 /* No face changes, overlays etc. in sight, so just return a
5348 character from current_buffer. */
5351 /* Maybe run the redisplay end trigger hook. Performance note:
5352 This doesn't seem to cost measurable time. */
5353 if (it
->redisplay_end_trigger_charpos
5355 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
5356 run_redisplay_end_trigger_hook (it
);
5358 /* Get the next character, maybe multibyte. */
5359 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
5360 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
5362 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
5363 - IT_BYTEPOS (*it
));
5364 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
5367 it
->c
= *p
, it
->len
= 1;
5369 /* Record what we have and where it came from. */
5370 it
->what
= IT_CHARACTER
;;
5371 it
->object
= it
->w
->buffer
;
5372 it
->position
= it
->current
.pos
;
5374 /* Normally we return the character found above, except when we
5375 really want to return an ellipsis for selective display. */
5380 /* A value of selective > 0 means hide lines indented more
5381 than that number of columns. */
5382 if (it
->selective
> 0
5383 && IT_CHARPOS (*it
) + 1 < ZV
5384 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
5385 IT_BYTEPOS (*it
) + 1,
5386 (double) it
->selective
)) /* iftc */
5388 success_p
= next_element_from_ellipsis (it
);
5389 it
->dpvec_char_len
= -1;
5392 else if (it
->c
== '\r' && it
->selective
== -1)
5394 /* A value of selective == -1 means that everything from the
5395 CR to the end of the line is invisible, with maybe an
5396 ellipsis displayed for it. */
5397 success_p
= next_element_from_ellipsis (it
);
5398 it
->dpvec_char_len
= -1;
5403 /* Value is zero if end of buffer reached. */
5404 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
5409 /* Run the redisplay end trigger hook for IT. */
5412 run_redisplay_end_trigger_hook (it
)
5415 Lisp_Object args
[3];
5417 /* IT->glyph_row should be non-null, i.e. we should be actually
5418 displaying something, or otherwise we should not run the hook. */
5419 xassert (it
->glyph_row
);
5421 /* Set up hook arguments. */
5422 args
[0] = Qredisplay_end_trigger_functions
;
5423 args
[1] = it
->window
;
5424 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
5425 it
->redisplay_end_trigger_charpos
= 0;
5427 /* Since we are *trying* to run these functions, don't try to run
5428 them again, even if they get an error. */
5429 it
->w
->redisplay_end_trigger
= Qnil
;
5430 Frun_hook_with_args (3, args
);
5432 /* Notice if it changed the face of the character we are on. */
5433 handle_face_prop (it
);
5437 /* Deliver a composition display element. The iterator IT is already
5438 filled with composition information (done in
5439 handle_composition_prop). Value is always 1. */
5442 next_element_from_composition (it
)
5445 it
->what
= IT_COMPOSITION
;
5446 it
->position
= (STRINGP (it
->string
)
5447 ? it
->current
.string_pos
5454 /***********************************************************************
5455 Moving an iterator without producing glyphs
5456 ***********************************************************************/
5458 /* Move iterator IT to a specified buffer or X position within one
5459 line on the display without producing glyphs.
5461 OP should be a bit mask including some or all of these bits:
5462 MOVE_TO_X: Stop on reaching x-position TO_X.
5463 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5464 Regardless of OP's value, stop in reaching the end of the display line.
5466 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5467 This means, in particular, that TO_X includes window's horizontal
5470 The return value has several possible values that
5471 say what condition caused the scan to stop:
5473 MOVE_POS_MATCH_OR_ZV
5474 - when TO_POS or ZV was reached.
5477 -when TO_X was reached before TO_POS or ZV were reached.
5480 - when we reached the end of the display area and the line must
5484 - when we reached the end of the display area and the line is
5488 - when we stopped at a line end, i.e. a newline or a CR and selective
5491 static enum move_it_result
5492 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5494 int to_charpos
, to_x
, op
;
5496 enum move_it_result result
= MOVE_UNDEFINED
;
5497 struct glyph_row
*saved_glyph_row
;
5499 /* Don't produce glyphs in produce_glyphs. */
5500 saved_glyph_row
= it
->glyph_row
;
5501 it
->glyph_row
= NULL
;
5505 int x
, i
, ascent
= 0, descent
= 0;
5507 /* Stop when ZV or TO_CHARPOS reached. */
5508 if (!get_next_display_element (it
)
5509 || ((op
& MOVE_TO_POS
) != 0
5510 && BUFFERP (it
->object
)
5511 && IT_CHARPOS (*it
) >= to_charpos
))
5513 result
= MOVE_POS_MATCH_OR_ZV
;
5517 /* The call to produce_glyphs will get the metrics of the
5518 display element IT is loaded with. We record in x the
5519 x-position before this display element in case it does not
5523 /* Remember the line height so far in case the next element doesn't
5525 if (!it
->truncate_lines_p
)
5527 ascent
= it
->max_ascent
;
5528 descent
= it
->max_descent
;
5531 PRODUCE_GLYPHS (it
);
5533 if (it
->area
!= TEXT_AREA
)
5535 set_iterator_to_next (it
, 1);
5539 /* The number of glyphs we get back in IT->nglyphs will normally
5540 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5541 character on a terminal frame, or (iii) a line end. For the
5542 second case, IT->nglyphs - 1 padding glyphs will be present
5543 (on X frames, there is only one glyph produced for a
5544 composite character.
5546 The behavior implemented below means, for continuation lines,
5547 that as many spaces of a TAB as fit on the current line are
5548 displayed there. For terminal frames, as many glyphs of a
5549 multi-glyph character are displayed in the current line, too.
5550 This is what the old redisplay code did, and we keep it that
5551 way. Under X, the whole shape of a complex character must
5552 fit on the line or it will be completely displayed in the
5555 Note that both for tabs and padding glyphs, all glyphs have
5559 /* More than one glyph or glyph doesn't fit on line. All
5560 glyphs have the same width. */
5561 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5564 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5566 new_x
= x
+ single_glyph_width
;
5568 /* We want to leave anything reaching TO_X to the caller. */
5569 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5572 result
= MOVE_X_REACHED
;
5575 else if (/* Lines are continued. */
5576 !it
->truncate_lines_p
5577 && (/* And glyph doesn't fit on the line. */
5578 new_x
> it
->last_visible_x
5579 /* Or it fits exactly and we're on a window
5581 || (new_x
== it
->last_visible_x
5582 && FRAME_WINDOW_P (it
->f
))))
5584 if (/* IT->hpos == 0 means the very first glyph
5585 doesn't fit on the line, e.g. a wide image. */
5587 || (new_x
== it
->last_visible_x
5588 && FRAME_WINDOW_P (it
->f
)))
5591 it
->current_x
= new_x
;
5592 if (i
== it
->nglyphs
- 1)
5593 set_iterator_to_next (it
, 1);
5598 it
->max_ascent
= ascent
;
5599 it
->max_descent
= descent
;
5602 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5604 result
= MOVE_LINE_CONTINUED
;
5607 else if (new_x
> it
->first_visible_x
)
5609 /* Glyph is visible. Increment number of glyphs that
5610 would be displayed. */
5615 /* Glyph is completely off the left margin of the display
5616 area. Nothing to do. */
5620 if (result
!= MOVE_UNDEFINED
)
5623 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5625 /* Stop when TO_X specified and reached. This check is
5626 necessary here because of lines consisting of a line end,
5627 only. The line end will not produce any glyphs and we
5628 would never get MOVE_X_REACHED. */
5629 xassert (it
->nglyphs
== 0);
5630 result
= MOVE_X_REACHED
;
5634 /* Is this a line end? If yes, we're done. */
5635 if (ITERATOR_AT_END_OF_LINE_P (it
))
5637 result
= MOVE_NEWLINE_OR_CR
;
5641 /* The current display element has been consumed. Advance
5643 set_iterator_to_next (it
, 1);
5645 /* Stop if lines are truncated and IT's current x-position is
5646 past the right edge of the window now. */
5647 if (it
->truncate_lines_p
5648 && it
->current_x
>= it
->last_visible_x
)
5650 result
= MOVE_LINE_TRUNCATED
;
5655 /* Restore the iterator settings altered at the beginning of this
5657 it
->glyph_row
= saved_glyph_row
;
5662 /* Move IT forward until it satisfies one or more of the criteria in
5663 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
5665 OP is a bit-mask that specifies where to stop, and in particular,
5666 which of those four position arguments makes a difference. See the
5667 description of enum move_operation_enum.
5669 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5670 screen line, this function will set IT to the next position >
5674 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5676 int to_charpos
, to_x
, to_y
, to_vpos
;
5679 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5685 if (op
& MOVE_TO_VPOS
)
5687 /* If no TO_CHARPOS and no TO_X specified, stop at the
5688 start of the line TO_VPOS. */
5689 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5691 if (it
->vpos
== to_vpos
)
5697 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5701 /* TO_VPOS >= 0 means stop at TO_X in the line at
5702 TO_VPOS, or at TO_POS, whichever comes first. */
5703 if (it
->vpos
== to_vpos
)
5709 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5711 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5716 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5718 /* We have reached TO_X but not in the line we want. */
5719 skip
= move_it_in_display_line_to (it
, to_charpos
,
5721 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5729 else if (op
& MOVE_TO_Y
)
5731 struct it it_backup
;
5733 /* TO_Y specified means stop at TO_X in the line containing
5734 TO_Y---or at TO_CHARPOS if this is reached first. The
5735 problem is that we can't really tell whether the line
5736 contains TO_Y before we have completely scanned it, and
5737 this may skip past TO_X. What we do is to first scan to
5740 If TO_X is not specified, use a TO_X of zero. The reason
5741 is to make the outcome of this function more predictable.
5742 If we didn't use TO_X == 0, we would stop at the end of
5743 the line which is probably not what a caller would expect
5745 skip
= move_it_in_display_line_to (it
, to_charpos
,
5749 | (op
& MOVE_TO_POS
)));
5751 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5752 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5758 /* If TO_X was reached, we would like to know whether TO_Y
5759 is in the line. This can only be said if we know the
5760 total line height which requires us to scan the rest of
5762 if (skip
== MOVE_X_REACHED
)
5765 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5766 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5768 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5771 /* Now, decide whether TO_Y is in this line. */
5772 line_height
= it
->max_ascent
+ it
->max_descent
;
5773 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5775 if (to_y
>= it
->current_y
5776 && to_y
< it
->current_y
+ line_height
)
5778 if (skip
== MOVE_X_REACHED
)
5779 /* If TO_Y is in this line and TO_X was reached above,
5780 we scanned too far. We have to restore IT's settings
5781 to the ones before skipping. */
5785 else if (skip
== MOVE_X_REACHED
)
5788 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5796 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5800 case MOVE_POS_MATCH_OR_ZV
:
5804 case MOVE_NEWLINE_OR_CR
:
5805 set_iterator_to_next (it
, 1);
5806 it
->continuation_lines_width
= 0;
5809 case MOVE_LINE_TRUNCATED
:
5810 it
->continuation_lines_width
= 0;
5811 reseat_at_next_visible_line_start (it
, 0);
5812 if ((op
& MOVE_TO_POS
) != 0
5813 && IT_CHARPOS (*it
) > to_charpos
)
5820 case MOVE_LINE_CONTINUED
:
5821 it
->continuation_lines_width
+= it
->current_x
;
5828 /* Reset/increment for the next run. */
5829 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5830 it
->current_x
= it
->hpos
= 0;
5831 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5833 last_height
= it
->max_ascent
+ it
->max_descent
;
5834 last_max_ascent
= it
->max_ascent
;
5835 it
->max_ascent
= it
->max_descent
= 0;
5840 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5844 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5846 If DY > 0, move IT backward at least that many pixels. DY = 0
5847 means move IT backward to the preceding line start or BEGV. This
5848 function may move over more than DY pixels if IT->current_y - DY
5849 ends up in the middle of a line; in this case IT->current_y will be
5850 set to the top of the line moved to. */
5853 move_it_vertically_backward (it
, dy
)
5859 int start_pos
= IT_CHARPOS (*it
);
5863 /* Estimate how many newlines we must move back. */
5864 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
5866 /* Set the iterator's position that many lines back. */
5867 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5868 back_to_previous_visible_line_start (it
);
5870 /* Reseat the iterator here. When moving backward, we don't want
5871 reseat to skip forward over invisible text, set up the iterator
5872 to deliver from overlay strings at the new position etc. So,
5873 use reseat_1 here. */
5874 reseat_1 (it
, it
->current
.pos
, 1);
5876 /* We are now surely at a line start. */
5877 it
->current_x
= it
->hpos
= 0;
5878 it
->continuation_lines_width
= 0;
5880 /* Move forward and see what y-distance we moved. First move to the
5881 start of the next line so that we get its height. We need this
5882 height to be able to tell whether we reached the specified
5885 it2
.max_ascent
= it2
.max_descent
= 0;
5886 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5887 MOVE_TO_POS
| MOVE_TO_VPOS
);
5888 xassert (IT_CHARPOS (*it
) >= BEGV
);
5891 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5892 xassert (IT_CHARPOS (*it
) >= BEGV
);
5893 /* H is the actual vertical distance from the position in *IT
5894 and the starting position. */
5895 h
= it2
.current_y
- it
->current_y
;
5896 /* NLINES is the distance in number of lines. */
5897 nlines
= it2
.vpos
- it
->vpos
;
5899 /* Correct IT's y and vpos position
5900 so that they are relative to the starting point. */
5906 /* DY == 0 means move to the start of the screen line. The
5907 value of nlines is > 0 if continuation lines were involved. */
5909 move_it_by_lines (it
, nlines
, 1);
5910 xassert (IT_CHARPOS (*it
) <= start_pos
);
5914 /* The y-position we try to reach, relative to *IT.
5915 Note that H has been subtracted in front of the if-statement. */
5916 int target_y
= it
->current_y
+ h
- dy
;
5917 int y0
= it3
.current_y
;
5918 int y1
= line_bottom_y (&it3
);
5919 int line_height
= y1
- y0
;
5921 /* If we did not reach target_y, try to move further backward if
5922 we can. If we moved too far backward, try to move forward. */
5923 if (target_y
< it
->current_y
5924 /* This is heuristic. In a window that's 3 lines high, with
5925 a line height of 13 pixels each, recentering with point
5926 on the bottom line will try to move -39/2 = 19 pixels
5927 backward. Try to avoid moving into the first line. */
5928 && it
->current_y
- target_y
> line_height
/ 3 * 2
5929 && IT_CHARPOS (*it
) > BEGV
)
5931 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
5932 target_y
- it
->current_y
));
5933 move_it_vertically (it
, target_y
- it
->current_y
);
5934 xassert (IT_CHARPOS (*it
) >= BEGV
);
5936 else if (target_y
>= it
->current_y
+ line_height
5937 && IT_CHARPOS (*it
) < ZV
)
5939 /* Should move forward by at least one line, maybe more.
5941 Note: Calling move_it_by_lines can be expensive on
5942 terminal frames, where compute_motion is used (via
5943 vmotion) to do the job, when there are very long lines
5944 and truncate-lines is nil. That's the reason for
5945 treating terminal frames specially here. */
5947 if (!FRAME_WINDOW_P (it
->f
))
5948 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
5953 move_it_by_lines (it
, 1, 1);
5955 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
5958 xassert (IT_CHARPOS (*it
) >= BEGV
);
5964 /* Move IT by a specified amount of pixel lines DY. DY negative means
5965 move backwards. DY = 0 means move to start of screen line. At the
5966 end, IT will be on the start of a screen line. */
5969 move_it_vertically (it
, dy
)
5974 move_it_vertically_backward (it
, -dy
);
5977 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5978 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5979 MOVE_TO_POS
| MOVE_TO_Y
);
5980 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5982 /* If buffer ends in ZV without a newline, move to the start of
5983 the line to satisfy the post-condition. */
5984 if (IT_CHARPOS (*it
) == ZV
5985 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5986 move_it_by_lines (it
, 0, 0);
5991 /* Move iterator IT past the end of the text line it is in. */
5994 move_it_past_eol (it
)
5997 enum move_it_result rc
;
5999 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6000 if (rc
== MOVE_NEWLINE_OR_CR
)
6001 set_iterator_to_next (it
, 0);
6005 #if 0 /* Currently not used. */
6007 /* Return non-zero if some text between buffer positions START_CHARPOS
6008 and END_CHARPOS is invisible. IT->window is the window for text
6012 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6014 int start_charpos
, end_charpos
;
6016 Lisp_Object prop
, limit
;
6017 int invisible_found_p
;
6019 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6021 /* Is text at START invisible? */
6022 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6024 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6025 invisible_found_p
= 1;
6028 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6030 make_number (end_charpos
));
6031 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6034 return invisible_found_p
;
6040 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6041 negative means move up. DVPOS == 0 means move to the start of the
6042 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6043 NEED_Y_P is zero, IT->current_y will be left unchanged.
6045 Further optimization ideas: If we would know that IT->f doesn't use
6046 a face with proportional font, we could be faster for
6047 truncate-lines nil. */
6050 move_it_by_lines (it
, dvpos
, need_y_p
)
6052 int dvpos
, need_y_p
;
6054 struct position pos
;
6056 if (!FRAME_WINDOW_P (it
->f
))
6058 struct text_pos textpos
;
6060 /* We can use vmotion on frames without proportional fonts. */
6061 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6062 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6063 reseat (it
, textpos
, 1);
6064 it
->vpos
+= pos
.vpos
;
6065 it
->current_y
+= pos
.vpos
;
6067 else if (dvpos
== 0)
6069 /* DVPOS == 0 means move to the start of the screen line. */
6070 move_it_vertically_backward (it
, 0);
6071 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6074 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6078 int start_charpos
, i
;
6080 /* Start at the beginning of the screen line containing IT's
6082 move_it_vertically_backward (it
, 0);
6084 /* Go back -DVPOS visible lines and reseat the iterator there. */
6085 start_charpos
= IT_CHARPOS (*it
);
6086 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
6087 back_to_previous_visible_line_start (it
);
6088 reseat (it
, it
->current
.pos
, 1);
6089 it
->current_x
= it
->hpos
= 0;
6091 /* Above call may have moved too far if continuation lines
6092 are involved. Scan forward and see if it did. */
6094 it2
.vpos
= it2
.current_y
= 0;
6095 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6096 it
->vpos
-= it2
.vpos
;
6097 it
->current_y
-= it2
.current_y
;
6098 it
->current_x
= it
->hpos
= 0;
6100 /* If we moved too far, move IT some lines forward. */
6101 if (it2
.vpos
> -dvpos
)
6103 int delta
= it2
.vpos
+ dvpos
;
6104 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6109 /* Return 1 if IT points into the middle of a display vector. */
6112 in_display_vector_p (it
)
6115 return (it
->method
== next_element_from_display_vector
6116 && it
->current
.dpvec_index
> 0
6117 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6121 /***********************************************************************
6123 ***********************************************************************/
6126 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6130 add_to_log (format
, arg1
, arg2
)
6132 Lisp_Object arg1
, arg2
;
6134 Lisp_Object args
[3];
6135 Lisp_Object msg
, fmt
;
6138 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6140 /* Do nothing if called asynchronously. Inserting text into
6141 a buffer may call after-change-functions and alike and
6142 that would means running Lisp asynchronously. */
6143 if (handling_signal
)
6147 GCPRO4 (fmt
, msg
, arg1
, arg2
);
6149 args
[0] = fmt
= build_string (format
);
6152 msg
= Fformat (3, args
);
6154 len
= SBYTES (msg
) + 1;
6155 buffer
= (char *) alloca (len
);
6156 bcopy (SDATA (msg
), buffer
, len
);
6158 message_dolog (buffer
, len
- 1, 1, 0);
6163 /* Output a newline in the *Messages* buffer if "needs" one. */
6166 message_log_maybe_newline ()
6168 if (message_log_need_newline
)
6169 message_dolog ("", 0, 1, 0);
6173 /* Add a string M of length NBYTES to the message log, optionally
6174 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
6175 nonzero, means interpret the contents of M as multibyte. This
6176 function calls low-level routines in order to bypass text property
6177 hooks, etc. which might not be safe to run. */
6180 message_dolog (m
, nbytes
, nlflag
, multibyte
)
6182 int nbytes
, nlflag
, multibyte
;
6184 if (!NILP (Vmemory_full
))
6187 if (!NILP (Vmessage_log_max
))
6189 struct buffer
*oldbuf
;
6190 Lisp_Object oldpoint
, oldbegv
, oldzv
;
6191 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6192 int point_at_end
= 0;
6194 Lisp_Object old_deactivate_mark
, tem
;
6195 struct gcpro gcpro1
;
6197 old_deactivate_mark
= Vdeactivate_mark
;
6198 oldbuf
= current_buffer
;
6199 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
6200 current_buffer
->undo_list
= Qt
;
6202 oldpoint
= message_dolog_marker1
;
6203 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
6204 oldbegv
= message_dolog_marker2
;
6205 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
6206 oldzv
= message_dolog_marker3
;
6207 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
6208 GCPRO1 (old_deactivate_mark
);
6216 BEGV_BYTE
= BEG_BYTE
;
6219 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6221 /* Insert the string--maybe converting multibyte to single byte
6222 or vice versa, so that all the text fits the buffer. */
6224 && NILP (current_buffer
->enable_multibyte_characters
))
6226 int i
, c
, char_bytes
;
6227 unsigned char work
[1];
6229 /* Convert a multibyte string to single-byte
6230 for the *Message* buffer. */
6231 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
6233 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
6234 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6236 : multibyte_char_to_unibyte (c
, Qnil
));
6237 insert_1_both (work
, 1, 1, 1, 0, 0);
6240 else if (! multibyte
6241 && ! NILP (current_buffer
->enable_multibyte_characters
))
6243 int i
, c
, char_bytes
;
6244 unsigned char *msg
= (unsigned char *) m
;
6245 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6246 /* Convert a single-byte string to multibyte
6247 for the *Message* buffer. */
6248 for (i
= 0; i
< nbytes
; i
++)
6250 c
= unibyte_char_to_multibyte (msg
[i
]);
6251 char_bytes
= CHAR_STRING (c
, str
);
6252 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
6256 insert_1 (m
, nbytes
, 1, 0, 0);
6260 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
6261 insert_1 ("\n", 1, 1, 0, 0);
6263 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6265 this_bol_byte
= PT_BYTE
;
6267 /* See if this line duplicates the previous one.
6268 If so, combine duplicates. */
6271 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6273 prev_bol_byte
= PT_BYTE
;
6275 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
6276 this_bol
, this_bol_byte
);
6279 del_range_both (prev_bol
, prev_bol_byte
,
6280 this_bol
, this_bol_byte
, 0);
6286 /* If you change this format, don't forget to also
6287 change message_log_check_duplicate. */
6288 sprintf (dupstr
, " [%d times]", dup
);
6289 duplen
= strlen (dupstr
);
6290 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
6291 insert_1 (dupstr
, duplen
, 1, 0, 1);
6296 /* If we have more than the desired maximum number of lines
6297 in the *Messages* buffer now, delete the oldest ones.
6298 This is safe because we don't have undo in this buffer. */
6300 if (NATNUMP (Vmessage_log_max
))
6302 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
6303 -XFASTINT (Vmessage_log_max
) - 1, 0);
6304 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
6307 BEGV
= XMARKER (oldbegv
)->charpos
;
6308 BEGV_BYTE
= marker_byte_position (oldbegv
);
6317 ZV
= XMARKER (oldzv
)->charpos
;
6318 ZV_BYTE
= marker_byte_position (oldzv
);
6322 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6324 /* We can't do Fgoto_char (oldpoint) because it will run some
6326 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
6327 XMARKER (oldpoint
)->bytepos
);
6330 unchain_marker (XMARKER (oldpoint
));
6331 unchain_marker (XMARKER (oldbegv
));
6332 unchain_marker (XMARKER (oldzv
));
6334 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
6335 set_buffer_internal (oldbuf
);
6337 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6338 message_log_need_newline
= !nlflag
;
6339 Vdeactivate_mark
= old_deactivate_mark
;
6344 /* We are at the end of the buffer after just having inserted a newline.
6345 (Note: We depend on the fact we won't be crossing the gap.)
6346 Check to see if the most recent message looks a lot like the previous one.
6347 Return 0 if different, 1 if the new one should just replace it, or a
6348 value N > 1 if we should also append " [N times]". */
6351 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
6352 int prev_bol
, this_bol
;
6353 int prev_bol_byte
, this_bol_byte
;
6356 int len
= Z_BYTE
- 1 - this_bol_byte
;
6358 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
6359 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
6361 for (i
= 0; i
< len
; i
++)
6363 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
6371 if (*p1
++ == ' ' && *p1
++ == '[')
6374 while (*p1
>= '0' && *p1
<= '9')
6375 n
= n
* 10 + *p1
++ - '0';
6376 if (strncmp (p1
, " times]\n", 8) == 0)
6383 /* Display an echo area message M with a specified length of NBYTES
6384 bytes. The string may include null characters. If M is 0, clear
6385 out any existing message, and let the mini-buffer text show
6388 The buffer M must continue to exist until after the echo area gets
6389 cleared or some other message gets displayed there. This means do
6390 not pass text that is stored in a Lisp string; do not pass text in
6391 a buffer that was alloca'd. */
6394 message2 (m
, nbytes
, multibyte
)
6399 /* First flush out any partial line written with print. */
6400 message_log_maybe_newline ();
6402 message_dolog (m
, nbytes
, 1, multibyte
);
6403 message2_nolog (m
, nbytes
, multibyte
);
6407 /* The non-logging counterpart of message2. */
6410 message2_nolog (m
, nbytes
, multibyte
)
6412 int nbytes
, multibyte
;
6414 struct frame
*sf
= SELECTED_FRAME ();
6415 message_enable_multibyte
= multibyte
;
6419 if (noninteractive_need_newline
)
6420 putc ('\n', stderr
);
6421 noninteractive_need_newline
= 0;
6423 fwrite (m
, nbytes
, 1, stderr
);
6424 if (cursor_in_echo_area
== 0)
6425 fprintf (stderr
, "\n");
6428 /* A null message buffer means that the frame hasn't really been
6429 initialized yet. Error messages get reported properly by
6430 cmd_error, so this must be just an informative message; toss it. */
6431 else if (INTERACTIVE
6432 && sf
->glyphs_initialized_p
6433 && FRAME_MESSAGE_BUF (sf
))
6435 Lisp_Object mini_window
;
6438 /* Get the frame containing the mini-buffer
6439 that the selected frame is using. */
6440 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6441 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6443 FRAME_SAMPLE_VISIBILITY (f
);
6444 if (FRAME_VISIBLE_P (sf
)
6445 && ! FRAME_VISIBLE_P (f
))
6446 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
6450 set_message (m
, Qnil
, nbytes
, multibyte
);
6451 if (minibuffer_auto_raise
)
6452 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6455 clear_message (1, 1);
6457 do_pending_window_change (0);
6458 echo_area_display (1);
6459 do_pending_window_change (0);
6460 if (FRAME_DISPLAY (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6461 (*FRAME_DISPLAY (f
)->frame_up_to_date_hook
) (f
);
6466 /* Display an echo area message M with a specified length of NBYTES
6467 bytes. The string may include null characters. If M is not a
6468 string, clear out any existing message, and let the mini-buffer
6469 text show through. */
6472 message3 (m
, nbytes
, multibyte
)
6477 struct gcpro gcpro1
;
6481 /* First flush out any partial line written with print. */
6482 message_log_maybe_newline ();
6484 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
6485 message3_nolog (m
, nbytes
, multibyte
);
6491 /* The non-logging version of message3. */
6494 message3_nolog (m
, nbytes
, multibyte
)
6496 int nbytes
, multibyte
;
6498 struct frame
*sf
= SELECTED_FRAME ();
6499 message_enable_multibyte
= multibyte
;
6503 if (noninteractive_need_newline
)
6504 putc ('\n', stderr
);
6505 noninteractive_need_newline
= 0;
6507 fwrite (SDATA (m
), nbytes
, 1, stderr
);
6508 if (cursor_in_echo_area
== 0)
6509 fprintf (stderr
, "\n");
6512 /* A null message buffer means that the frame hasn't really been
6513 initialized yet. Error messages get reported properly by
6514 cmd_error, so this must be just an informative message; toss it. */
6515 else if (INTERACTIVE
6516 && sf
->glyphs_initialized_p
6517 && FRAME_MESSAGE_BUF (sf
))
6519 Lisp_Object mini_window
;
6523 /* Get the frame containing the mini-buffer
6524 that the selected frame is using. */
6525 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6526 frame
= XWINDOW (mini_window
)->frame
;
6529 FRAME_SAMPLE_VISIBILITY (f
);
6530 if (FRAME_VISIBLE_P (sf
)
6531 && !FRAME_VISIBLE_P (f
))
6532 Fmake_frame_visible (frame
);
6534 if (STRINGP (m
) && SCHARS (m
) > 0)
6536 set_message (NULL
, m
, nbytes
, multibyte
);
6537 if (minibuffer_auto_raise
)
6538 Fraise_frame (frame
);
6541 clear_message (1, 1);
6543 do_pending_window_change (0);
6544 echo_area_display (1);
6545 do_pending_window_change (0);
6546 if (FRAME_DISPLAY (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6547 (*FRAME_DISPLAY (f
)->frame_up_to_date_hook
) (f
);
6552 /* Display a null-terminated echo area message M. If M is 0, clear
6553 out any existing message, and let the mini-buffer text show through.
6555 The buffer M must continue to exist until after the echo area gets
6556 cleared or some other message gets displayed there. Do not pass
6557 text that is stored in a Lisp string. Do not pass text in a buffer
6558 that was alloca'd. */
6564 message2 (m
, (m
? strlen (m
) : 0), 0);
6568 /* The non-logging counterpart of message1. */
6574 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6577 /* Display a message M which contains a single %s
6578 which gets replaced with STRING. */
6581 message_with_string (m
, string
, log
)
6586 CHECK_STRING (string
);
6592 if (noninteractive_need_newline
)
6593 putc ('\n', stderr
);
6594 noninteractive_need_newline
= 0;
6595 fprintf (stderr
, m
, SDATA (string
));
6596 if (cursor_in_echo_area
== 0)
6597 fprintf (stderr
, "\n");
6601 else if (INTERACTIVE
)
6603 /* The frame whose minibuffer we're going to display the message on.
6604 It may be larger than the selected frame, so we need
6605 to use its buffer, not the selected frame's buffer. */
6606 Lisp_Object mini_window
;
6607 struct frame
*f
, *sf
= SELECTED_FRAME ();
6609 /* Get the frame containing the minibuffer
6610 that the selected frame is using. */
6611 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6612 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6614 /* A null message buffer means that the frame hasn't really been
6615 initialized yet. Error messages get reported properly by
6616 cmd_error, so this must be just an informative message; toss it. */
6617 if (FRAME_MESSAGE_BUF (f
))
6619 Lisp_Object args
[2], message
;
6620 struct gcpro gcpro1
, gcpro2
;
6622 args
[0] = build_string (m
);
6623 args
[1] = message
= string
;
6624 GCPRO2 (args
[0], message
);
6627 message
= Fformat (2, args
);
6630 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6632 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6636 /* Print should start at the beginning of the message
6637 buffer next time. */
6638 message_buf_print
= 0;
6644 /* Dump an informative message to the minibuf. If M is 0, clear out
6645 any existing message, and let the mini-buffer text show through. */
6649 message (m
, a1
, a2
, a3
)
6651 EMACS_INT a1
, a2
, a3
;
6657 if (noninteractive_need_newline
)
6658 putc ('\n', stderr
);
6659 noninteractive_need_newline
= 0;
6660 fprintf (stderr
, m
, a1
, a2
, a3
);
6661 if (cursor_in_echo_area
== 0)
6662 fprintf (stderr
, "\n");
6666 else if (INTERACTIVE
)
6668 /* The frame whose mini-buffer we're going to display the message
6669 on. It may be larger than the selected frame, so we need to
6670 use its buffer, not the selected frame's buffer. */
6671 Lisp_Object mini_window
;
6672 struct frame
*f
, *sf
= SELECTED_FRAME ();
6674 /* Get the frame containing the mini-buffer
6675 that the selected frame is using. */
6676 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6677 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6679 /* A null message buffer means that the frame hasn't really been
6680 initialized yet. Error messages get reported properly by
6681 cmd_error, so this must be just an informative message; toss
6683 if (FRAME_MESSAGE_BUF (f
))
6694 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6695 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6697 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6698 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6700 #endif /* NO_ARG_ARRAY */
6702 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6707 /* Print should start at the beginning of the message
6708 buffer next time. */
6709 message_buf_print
= 0;
6715 /* The non-logging version of message. */
6718 message_nolog (m
, a1
, a2
, a3
)
6720 EMACS_INT a1
, a2
, a3
;
6722 Lisp_Object old_log_max
;
6723 old_log_max
= Vmessage_log_max
;
6724 Vmessage_log_max
= Qnil
;
6725 message (m
, a1
, a2
, a3
);
6726 Vmessage_log_max
= old_log_max
;
6730 /* Display the current message in the current mini-buffer. This is
6731 only called from error handlers in process.c, and is not time
6737 if (!NILP (echo_area_buffer
[0]))
6740 string
= Fcurrent_message ();
6741 message3 (string
, SBYTES (string
),
6742 !NILP (current_buffer
->enable_multibyte_characters
));
6747 /* Make sure echo area buffers in `echo_buffers' are live.
6748 If they aren't, make new ones. */
6751 ensure_echo_area_buffers ()
6755 for (i
= 0; i
< 2; ++i
)
6756 if (!BUFFERP (echo_buffer
[i
])
6757 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6760 Lisp_Object old_buffer
;
6763 old_buffer
= echo_buffer
[i
];
6764 sprintf (name
, " *Echo Area %d*", i
);
6765 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6766 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6768 for (j
= 0; j
< 2; ++j
)
6769 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6770 echo_area_buffer
[j
] = echo_buffer
[i
];
6775 /* Call FN with args A1..A4 with either the current or last displayed
6776 echo_area_buffer as current buffer.
6778 WHICH zero means use the current message buffer
6779 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6780 from echo_buffer[] and clear it.
6782 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6783 suitable buffer from echo_buffer[] and clear it.
6785 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6786 that the current message becomes the last displayed one, make
6787 choose a suitable buffer for echo_area_buffer[0], and clear it.
6789 Value is what FN returns. */
6792 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6795 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6801 int this_one
, the_other
, clear_buffer_p
, rc
;
6802 int count
= SPECPDL_INDEX ();
6804 /* If buffers aren't live, make new ones. */
6805 ensure_echo_area_buffers ();
6810 this_one
= 0, the_other
= 1;
6812 this_one
= 1, the_other
= 0;
6815 this_one
= 0, the_other
= 1;
6818 /* We need a fresh one in case the current echo buffer equals
6819 the one containing the last displayed echo area message. */
6820 if (!NILP (echo_area_buffer
[this_one
])
6821 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6822 echo_area_buffer
[this_one
] = Qnil
;
6825 /* Choose a suitable buffer from echo_buffer[] is we don't
6827 if (NILP (echo_area_buffer
[this_one
]))
6829 echo_area_buffer
[this_one
]
6830 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6831 ? echo_buffer
[the_other
]
6832 : echo_buffer
[this_one
]);
6836 buffer
= echo_area_buffer
[this_one
];
6838 /* Don't get confused by reusing the buffer used for echoing
6839 for a different purpose. */
6840 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
6843 record_unwind_protect (unwind_with_echo_area_buffer
,
6844 with_echo_area_buffer_unwind_data (w
));
6846 /* Make the echo area buffer current. Note that for display
6847 purposes, it is not necessary that the displayed window's buffer
6848 == current_buffer, except for text property lookup. So, let's
6849 only set that buffer temporarily here without doing a full
6850 Fset_window_buffer. We must also change w->pointm, though,
6851 because otherwise an assertions in unshow_buffer fails, and Emacs
6853 set_buffer_internal_1 (XBUFFER (buffer
));
6857 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6860 current_buffer
->undo_list
= Qt
;
6861 current_buffer
->read_only
= Qnil
;
6862 specbind (Qinhibit_read_only
, Qt
);
6863 specbind (Qinhibit_modification_hooks
, Qt
);
6865 if (clear_buffer_p
&& Z
> BEG
)
6868 xassert (BEGV
>= BEG
);
6869 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6871 rc
= fn (a1
, a2
, a3
, a4
);
6873 xassert (BEGV
>= BEG
);
6874 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6876 unbind_to (count
, Qnil
);
6881 /* Save state that should be preserved around the call to the function
6882 FN called in with_echo_area_buffer. */
6885 with_echo_area_buffer_unwind_data (w
)
6891 /* Reduce consing by keeping one vector in
6892 Vwith_echo_area_save_vector. */
6893 vector
= Vwith_echo_area_save_vector
;
6894 Vwith_echo_area_save_vector
= Qnil
;
6897 vector
= Fmake_vector (make_number (7), Qnil
);
6899 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6900 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6901 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6905 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6906 AREF (vector
, i
) = w
->buffer
; ++i
;
6907 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6908 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6913 for (; i
< end
; ++i
)
6914 AREF (vector
, i
) = Qnil
;
6917 xassert (i
== ASIZE (vector
));
6922 /* Restore global state from VECTOR which was created by
6923 with_echo_area_buffer_unwind_data. */
6926 unwind_with_echo_area_buffer (vector
)
6929 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6930 Vdeactivate_mark
= AREF (vector
, 1);
6931 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6933 if (WINDOWP (AREF (vector
, 3)))
6936 Lisp_Object buffer
, charpos
, bytepos
;
6938 w
= XWINDOW (AREF (vector
, 3));
6939 buffer
= AREF (vector
, 4);
6940 charpos
= AREF (vector
, 5);
6941 bytepos
= AREF (vector
, 6);
6944 set_marker_both (w
->pointm
, buffer
,
6945 XFASTINT (charpos
), XFASTINT (bytepos
));
6948 Vwith_echo_area_save_vector
= vector
;
6953 /* Set up the echo area for use by print functions. MULTIBYTE_P
6954 non-zero means we will print multibyte. */
6957 setup_echo_area_for_printing (multibyte_p
)
6960 /* If we can't find an echo area any more, exit. */
6961 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
6964 ensure_echo_area_buffers ();
6966 if (!message_buf_print
)
6968 /* A message has been output since the last time we printed.
6969 Choose a fresh echo area buffer. */
6970 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6971 echo_area_buffer
[0] = echo_buffer
[1];
6973 echo_area_buffer
[0] = echo_buffer
[0];
6975 /* Switch to that buffer and clear it. */
6976 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6977 current_buffer
->truncate_lines
= Qnil
;
6981 int count
= SPECPDL_INDEX ();
6982 specbind (Qinhibit_read_only
, Qt
);
6983 /* Note that undo recording is always disabled. */
6985 unbind_to (count
, Qnil
);
6987 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6989 /* Set up the buffer for the multibyteness we need. */
6991 != !NILP (current_buffer
->enable_multibyte_characters
))
6992 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
6994 /* Raise the frame containing the echo area. */
6995 if (minibuffer_auto_raise
)
6997 struct frame
*sf
= SELECTED_FRAME ();
6998 Lisp_Object mini_window
;
6999 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7000 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7003 message_log_maybe_newline ();
7004 message_buf_print
= 1;
7008 if (NILP (echo_area_buffer
[0]))
7010 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7011 echo_area_buffer
[0] = echo_buffer
[1];
7013 echo_area_buffer
[0] = echo_buffer
[0];
7016 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7018 /* Someone switched buffers between print requests. */
7019 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7020 current_buffer
->truncate_lines
= Qnil
;
7026 /* Display an echo area message in window W. Value is non-zero if W's
7027 height is changed. If display_last_displayed_message_p is
7028 non-zero, display the message that was last displayed, otherwise
7029 display the current message. */
7032 display_echo_area (w
)
7035 int i
, no_message_p
, window_height_changed_p
, count
;
7037 /* Temporarily disable garbage collections while displaying the echo
7038 area. This is done because a GC can print a message itself.
7039 That message would modify the echo area buffer's contents while a
7040 redisplay of the buffer is going on, and seriously confuse
7042 count
= inhibit_garbage_collection ();
7044 /* If there is no message, we must call display_echo_area_1
7045 nevertheless because it resizes the window. But we will have to
7046 reset the echo_area_buffer in question to nil at the end because
7047 with_echo_area_buffer will sets it to an empty buffer. */
7048 i
= display_last_displayed_message_p
? 1 : 0;
7049 no_message_p
= NILP (echo_area_buffer
[i
]);
7051 window_height_changed_p
7052 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7053 display_echo_area_1
,
7054 (EMACS_INT
) w
, Qnil
, 0, 0);
7057 echo_area_buffer
[i
] = Qnil
;
7059 unbind_to (count
, Qnil
);
7060 return window_height_changed_p
;
7064 /* Helper for display_echo_area. Display the current buffer which
7065 contains the current echo area message in window W, a mini-window,
7066 a pointer to which is passed in A1. A2..A4 are currently not used.
7067 Change the height of W so that all of the message is displayed.
7068 Value is non-zero if height of W was changed. */
7071 display_echo_area_1 (a1
, a2
, a3
, a4
)
7076 struct window
*w
= (struct window
*) a1
;
7078 struct text_pos start
;
7079 int window_height_changed_p
= 0;
7081 /* Do this before displaying, so that we have a large enough glyph
7082 matrix for the display. */
7083 window_height_changed_p
= resize_mini_window (w
, 0);
7086 clear_glyph_matrix (w
->desired_matrix
);
7087 XSETWINDOW (window
, w
);
7088 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
7089 try_window (window
, start
);
7091 return window_height_changed_p
;
7095 /* Resize the echo area window to exactly the size needed for the
7096 currently displayed message, if there is one. If a mini-buffer
7097 is active, don't shrink it. */
7100 resize_echo_area_exactly ()
7102 if (BUFFERP (echo_area_buffer
[0])
7103 && WINDOWP (echo_area_window
))
7105 struct window
*w
= XWINDOW (echo_area_window
);
7107 Lisp_Object resize_exactly
;
7109 if (minibuf_level
== 0)
7110 resize_exactly
= Qt
;
7112 resize_exactly
= Qnil
;
7114 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7115 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7118 ++windows_or_buffers_changed
;
7119 ++update_mode_lines
;
7120 redisplay_internal (0);
7126 /* Callback function for with_echo_area_buffer, when used from
7127 resize_echo_area_exactly. A1 contains a pointer to the window to
7128 resize, EXACTLY non-nil means resize the mini-window exactly to the
7129 size of the text displayed. A3 and A4 are not used. Value is what
7130 resize_mini_window returns. */
7133 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
7135 Lisp_Object exactly
;
7138 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
7142 /* Resize mini-window W to fit the size of its contents. EXACT:P
7143 means size the window exactly to the size needed. Otherwise, it's
7144 only enlarged until W's buffer is empty. Value is non-zero if
7145 the window height has been changed. */
7148 resize_mini_window (w
, exact_p
)
7152 struct frame
*f
= XFRAME (w
->frame
);
7153 int window_height_changed_p
= 0;
7155 xassert (MINI_WINDOW_P (w
));
7157 /* Don't resize windows while redisplaying a window; it would
7158 confuse redisplay functions when the size of the window they are
7159 displaying changes from under them. Such a resizing can happen,
7160 for instance, when which-func prints a long message while
7161 we are running fontification-functions. We're running these
7162 functions with safe_call which binds inhibit-redisplay to t. */
7163 if (!NILP (Vinhibit_redisplay
))
7166 /* Nil means don't try to resize. */
7167 if (NILP (Vresize_mini_windows
)
7168 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
7171 if (!FRAME_MINIBUF_ONLY_P (f
))
7174 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7175 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
7176 int height
, max_height
;
7177 int unit
= FRAME_LINE_HEIGHT (f
);
7178 struct text_pos start
;
7179 struct buffer
*old_current_buffer
= NULL
;
7181 if (current_buffer
!= XBUFFER (w
->buffer
))
7183 old_current_buffer
= current_buffer
;
7184 set_buffer_internal (XBUFFER (w
->buffer
));
7187 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
7189 /* Compute the max. number of lines specified by the user. */
7190 if (FLOATP (Vmax_mini_window_height
))
7191 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
7192 else if (INTEGERP (Vmax_mini_window_height
))
7193 max_height
= XINT (Vmax_mini_window_height
);
7195 max_height
= total_height
/ 4;
7197 /* Correct that max. height if it's bogus. */
7198 max_height
= max (1, max_height
);
7199 max_height
= min (total_height
, max_height
);
7201 /* Find out the height of the text in the window. */
7202 if (it
.truncate_lines_p
)
7207 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
7208 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
7209 height
= it
.current_y
+ last_height
;
7211 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
7212 height
-= it
.extra_line_spacing
;
7213 height
= (height
+ unit
- 1) / unit
;
7216 /* Compute a suitable window start. */
7217 if (height
> max_height
)
7219 height
= max_height
;
7220 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
7221 move_it_vertically_backward (&it
, (height
- 1) * unit
);
7222 start
= it
.current
.pos
;
7225 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
7226 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
7228 if (EQ (Vresize_mini_windows
, Qgrow_only
))
7230 /* Let it grow only, until we display an empty message, in which
7231 case the window shrinks again. */
7232 if (height
> WINDOW_TOTAL_LINES (w
))
7234 int old_height
= WINDOW_TOTAL_LINES (w
);
7235 freeze_window_starts (f
, 1);
7236 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7237 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7239 else if (height
< WINDOW_TOTAL_LINES (w
)
7240 && (exact_p
|| BEGV
== ZV
))
7242 int old_height
= WINDOW_TOTAL_LINES (w
);
7243 freeze_window_starts (f
, 0);
7244 shrink_mini_window (w
);
7245 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7250 /* Always resize to exact size needed. */
7251 if (height
> WINDOW_TOTAL_LINES (w
))
7253 int old_height
= WINDOW_TOTAL_LINES (w
);
7254 freeze_window_starts (f
, 1);
7255 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7256 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7258 else if (height
< WINDOW_TOTAL_LINES (w
))
7260 int old_height
= WINDOW_TOTAL_LINES (w
);
7261 freeze_window_starts (f
, 0);
7262 shrink_mini_window (w
);
7266 freeze_window_starts (f
, 1);
7267 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7270 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7274 if (old_current_buffer
)
7275 set_buffer_internal (old_current_buffer
);
7278 return window_height_changed_p
;
7282 /* Value is the current message, a string, or nil if there is no
7290 if (NILP (echo_area_buffer
[0]))
7294 with_echo_area_buffer (0, 0, current_message_1
,
7295 (EMACS_INT
) &msg
, Qnil
, 0, 0);
7297 echo_area_buffer
[0] = Qnil
;
7305 current_message_1 (a1
, a2
, a3
, a4
)
7310 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
7313 *msg
= make_buffer_string (BEG
, Z
, 1);
7320 /* Push the current message on Vmessage_stack for later restauration
7321 by restore_message. Value is non-zero if the current message isn't
7322 empty. This is a relatively infrequent operation, so it's not
7323 worth optimizing. */
7329 msg
= current_message ();
7330 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
7331 return STRINGP (msg
);
7335 /* Restore message display from the top of Vmessage_stack. */
7342 xassert (CONSP (Vmessage_stack
));
7343 msg
= XCAR (Vmessage_stack
);
7345 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
7347 message3_nolog (msg
, 0, 0);
7351 /* Handler for record_unwind_protect calling pop_message. */
7354 pop_message_unwind (dummy
)
7361 /* Pop the top-most entry off Vmessage_stack. */
7366 xassert (CONSP (Vmessage_stack
));
7367 Vmessage_stack
= XCDR (Vmessage_stack
);
7371 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
7372 exits. If the stack is not empty, we have a missing pop_message
7376 check_message_stack ()
7378 if (!NILP (Vmessage_stack
))
7383 /* Truncate to NCHARS what will be displayed in the echo area the next
7384 time we display it---but don't redisplay it now. */
7387 truncate_echo_area (nchars
)
7391 echo_area_buffer
[0] = Qnil
;
7392 /* A null message buffer means that the frame hasn't really been
7393 initialized yet. Error messages get reported properly by
7394 cmd_error, so this must be just an informative message; toss it. */
7395 else if (!noninteractive
7397 && !NILP (echo_area_buffer
[0]))
7399 struct frame
*sf
= SELECTED_FRAME ();
7400 if (FRAME_MESSAGE_BUF (sf
))
7401 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
7406 /* Helper function for truncate_echo_area. Truncate the current
7407 message to at most NCHARS characters. */
7410 truncate_message_1 (nchars
, a2
, a3
, a4
)
7415 if (BEG
+ nchars
< Z
)
7416 del_range (BEG
+ nchars
, Z
);
7418 echo_area_buffer
[0] = Qnil
;
7423 /* Set the current message to a substring of S or STRING.
7425 If STRING is a Lisp string, set the message to the first NBYTES
7426 bytes from STRING. NBYTES zero means use the whole string. If
7427 STRING is multibyte, the message will be displayed multibyte.
7429 If S is not null, set the message to the first LEN bytes of S. LEN
7430 zero means use the whole string. MULTIBYTE_P non-zero means S is
7431 multibyte. Display the message multibyte in that case. */
7434 set_message (s
, string
, nbytes
, multibyte_p
)
7437 int nbytes
, multibyte_p
;
7439 message_enable_multibyte
7440 = ((s
&& multibyte_p
)
7441 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
7443 with_echo_area_buffer (0, -1, set_message_1
,
7444 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
7445 message_buf_print
= 0;
7446 help_echo_showing_p
= 0;
7450 /* Helper function for set_message. Arguments have the same meaning
7451 as there, with A1 corresponding to S and A2 corresponding to STRING
7452 This function is called with the echo area buffer being
7456 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
7459 EMACS_INT nbytes
, multibyte_p
;
7461 const char *s
= (const char *) a1
;
7462 Lisp_Object string
= a2
;
7466 /* Change multibyteness of the echo buffer appropriately. */
7467 if (message_enable_multibyte
7468 != !NILP (current_buffer
->enable_multibyte_characters
))
7469 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
7471 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
7473 /* Insert new message at BEG. */
7474 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7476 if (STRINGP (string
))
7481 nbytes
= SBYTES (string
);
7482 nchars
= string_byte_to_char (string
, nbytes
);
7484 /* This function takes care of single/multibyte conversion. We
7485 just have to ensure that the echo area buffer has the right
7486 setting of enable_multibyte_characters. */
7487 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7492 nbytes
= strlen (s
);
7494 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
7496 /* Convert from multi-byte to single-byte. */
7498 unsigned char work
[1];
7500 /* Convert a multibyte string to single-byte. */
7501 for (i
= 0; i
< nbytes
; i
+= n
)
7503 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
7504 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7506 : multibyte_char_to_unibyte (c
, Qnil
));
7507 insert_1_both (work
, 1, 1, 1, 0, 0);
7510 else if (!multibyte_p
7511 && !NILP (current_buffer
->enable_multibyte_characters
))
7513 /* Convert from single-byte to multi-byte. */
7515 const unsigned char *msg
= (const unsigned char *) s
;
7516 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7518 /* Convert a single-byte string to multibyte. */
7519 for (i
= 0; i
< nbytes
; i
++)
7521 c
= unibyte_char_to_multibyte (msg
[i
]);
7522 n
= CHAR_STRING (c
, str
);
7523 insert_1_both (str
, 1, n
, 1, 0, 0);
7527 insert_1 (s
, nbytes
, 1, 0, 0);
7534 /* Clear messages. CURRENT_P non-zero means clear the current
7535 message. LAST_DISPLAYED_P non-zero means clear the message
7539 clear_message (current_p
, last_displayed_p
)
7540 int current_p
, last_displayed_p
;
7544 echo_area_buffer
[0] = Qnil
;
7545 message_cleared_p
= 1;
7548 if (last_displayed_p
)
7549 echo_area_buffer
[1] = Qnil
;
7551 message_buf_print
= 0;
7554 /* Clear garbaged frames.
7556 This function is used where the old redisplay called
7557 redraw_garbaged_frames which in turn called redraw_frame which in
7558 turn called clear_frame. The call to clear_frame was a source of
7559 flickering. I believe a clear_frame is not necessary. It should
7560 suffice in the new redisplay to invalidate all current matrices,
7561 and ensure a complete redisplay of all windows. */
7564 clear_garbaged_frames ()
7568 Lisp_Object tail
, frame
;
7569 int changed_count
= 0;
7571 FOR_EACH_FRAME (tail
, frame
)
7573 struct frame
*f
= XFRAME (frame
);
7575 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7578 Fredraw_frame (frame
);
7579 clear_current_matrices (f
);
7588 ++windows_or_buffers_changed
;
7593 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7594 is non-zero update selected_frame. Value is non-zero if the
7595 mini-windows height has been changed. */
7598 echo_area_display (update_frame_p
)
7601 Lisp_Object mini_window
;
7604 int window_height_changed_p
= 0;
7605 struct frame
*sf
= SELECTED_FRAME ();
7607 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7608 w
= XWINDOW (mini_window
);
7609 f
= XFRAME (WINDOW_FRAME (w
));
7611 /* Don't display if frame is invisible or not yet initialized. */
7612 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7615 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7617 #ifdef HAVE_WINDOW_SYSTEM
7618 /* When Emacs starts, selected_frame may be the initial terminal
7619 frame. If we let this through, a message would be displayed on
7621 if (FRAME_TERMCAP_P (XFRAME (selected_frame
))
7622 && FRAME_TTY (XFRAME (selected_frame
))->type
== NULL
)
7624 #endif /* HAVE_WINDOW_SYSTEM */
7627 /* Redraw garbaged frames. */
7629 clear_garbaged_frames ();
7631 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7633 echo_area_window
= mini_window
;
7634 window_height_changed_p
= display_echo_area (w
);
7635 w
->must_be_updated_p
= 1;
7637 /* Update the display, unless called from redisplay_internal.
7638 Also don't update the screen during redisplay itself. The
7639 update will happen at the end of redisplay, and an update
7640 here could cause confusion. */
7641 if (update_frame_p
&& !redisplaying_p
)
7645 /* If the display update has been interrupted by pending
7646 input, update mode lines in the frame. Due to the
7647 pending input, it might have been that redisplay hasn't
7648 been called, so that mode lines above the echo area are
7649 garbaged. This looks odd, so we prevent it here. */
7650 if (!display_completed
)
7651 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7653 if (window_height_changed_p
7654 /* Don't do this if Emacs is shutting down. Redisplay
7655 needs to run hooks. */
7656 && !NILP (Vrun_hooks
))
7658 /* Must update other windows. Likewise as in other
7659 cases, don't let this update be interrupted by
7661 int count
= SPECPDL_INDEX ();
7662 specbind (Qredisplay_dont_pause
, Qt
);
7663 windows_or_buffers_changed
= 1;
7664 redisplay_internal (0);
7665 unbind_to (count
, Qnil
);
7667 else if (FRAME_WINDOW_P (f
) && n
== 0)
7669 /* Window configuration is the same as before.
7670 Can do with a display update of the echo area,
7671 unless we displayed some mode lines. */
7672 update_single_window (w
, 1);
7673 FRAME_RIF (f
)->flush_display (f
);
7676 update_frame (f
, 1, 1);
7678 /* If cursor is in the echo area, make sure that the next
7679 redisplay displays the minibuffer, so that the cursor will
7680 be replaced with what the minibuffer wants. */
7681 if (cursor_in_echo_area
)
7682 ++windows_or_buffers_changed
;
7685 else if (!EQ (mini_window
, selected_window
))
7686 windows_or_buffers_changed
++;
7688 /* Last displayed message is now the current message. */
7689 echo_area_buffer
[1] = echo_area_buffer
[0];
7691 /* Prevent redisplay optimization in redisplay_internal by resetting
7692 this_line_start_pos. This is done because the mini-buffer now
7693 displays the message instead of its buffer text. */
7694 if (EQ (mini_window
, selected_window
))
7695 CHARPOS (this_line_start_pos
) = 0;
7697 return window_height_changed_p
;
7702 /***********************************************************************
7704 ***********************************************************************/
7707 /* The frame title buffering code is also used by Fformat_mode_line.
7708 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
7710 /* A buffer for constructing frame titles in it; allocated from the
7711 heap in init_xdisp and resized as needed in store_frame_title_char. */
7713 static char *frame_title_buf
;
7715 /* The buffer's end, and a current output position in it. */
7717 static char *frame_title_buf_end
;
7718 static char *frame_title_ptr
;
7721 /* Store a single character C for the frame title in frame_title_buf.
7722 Re-allocate frame_title_buf if necessary. */
7726 store_frame_title_char (char c
)
7728 store_frame_title_char (c
)
7732 /* If output position has reached the end of the allocated buffer,
7733 double the buffer's size. */
7734 if (frame_title_ptr
== frame_title_buf_end
)
7736 int len
= frame_title_ptr
- frame_title_buf
;
7737 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7738 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7739 frame_title_buf_end
= frame_title_buf
+ new_size
;
7740 frame_title_ptr
= frame_title_buf
+ len
;
7743 *frame_title_ptr
++ = c
;
7747 /* Store part of a frame title in frame_title_buf, beginning at
7748 frame_title_ptr. STR is the string to store. Do not copy
7749 characters that yield more columns than PRECISION; PRECISION <= 0
7750 means copy the whole string. Pad with spaces until FIELD_WIDTH
7751 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7752 pad. Called from display_mode_element when it is used to build a
7756 store_frame_title (str
, field_width
, precision
)
7757 const unsigned char *str
;
7758 int field_width
, precision
;
7763 /* Copy at most PRECISION chars from STR. */
7764 nbytes
= strlen (str
);
7765 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7767 store_frame_title_char (*str
++);
7769 /* Fill up with spaces until FIELD_WIDTH reached. */
7770 while (field_width
> 0
7773 store_frame_title_char (' ');
7780 #ifdef HAVE_WINDOW_SYSTEM
7782 /* Set the title of FRAME, if it has changed. The title format is
7783 Vicon_title_format if FRAME is iconified, otherwise it is
7784 frame_title_format. */
7787 x_consider_frame_title (frame
)
7790 struct frame
*f
= XFRAME (frame
);
7792 if (FRAME_WINDOW_P (f
)
7793 || FRAME_MINIBUF_ONLY_P (f
)
7794 || f
->explicit_name
)
7796 /* Do we have more than one visible frame on this X display? */
7799 struct buffer
*obuf
;
7803 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7805 Lisp_Object other_frame
= XCAR (tail
);
7806 struct frame
*tf
= XFRAME (other_frame
);
7809 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7810 && !FRAME_MINIBUF_ONLY_P (tf
)
7811 && !EQ (other_frame
, tip_frame
)
7812 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7816 /* Set global variable indicating that multiple frames exist. */
7817 multiple_frames
= CONSP (tail
);
7819 /* Switch to the buffer of selected window of the frame. Set up
7820 frame_title_ptr so that display_mode_element will output into it;
7821 then display the title. */
7822 obuf
= current_buffer
;
7823 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
7824 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7825 frame_title_ptr
= frame_title_buf
;
7826 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7827 NULL
, DEFAULT_FACE_ID
);
7828 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
7829 len
= frame_title_ptr
- frame_title_buf
;
7830 frame_title_ptr
= NULL
;
7831 set_buffer_internal_1 (obuf
);
7833 /* Set the title only if it's changed. This avoids consing in
7834 the common case where it hasn't. (If it turns out that we've
7835 already wasted too much time by walking through the list with
7836 display_mode_element, then we might need to optimize at a
7837 higher level than this.) */
7838 if (! STRINGP (f
->name
)
7839 || SBYTES (f
->name
) != len
7840 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
7841 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7845 #endif /* not HAVE_WINDOW_SYSTEM */
7850 /***********************************************************************
7852 ***********************************************************************/
7855 /* Prepare for redisplay by updating menu-bar item lists when
7856 appropriate. This can call eval. */
7859 prepare_menu_bars ()
7862 struct gcpro gcpro1
, gcpro2
;
7864 Lisp_Object tooltip_frame
;
7866 #ifdef HAVE_WINDOW_SYSTEM
7867 tooltip_frame
= tip_frame
;
7869 tooltip_frame
= Qnil
;
7872 /* Update all frame titles based on their buffer names, etc. We do
7873 this before the menu bars so that the buffer-menu will show the
7874 up-to-date frame titles. */
7875 #ifdef HAVE_WINDOW_SYSTEM
7876 if (windows_or_buffers_changed
|| update_mode_lines
)
7878 Lisp_Object tail
, frame
;
7880 FOR_EACH_FRAME (tail
, frame
)
7883 if (!EQ (frame
, tooltip_frame
)
7884 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7885 x_consider_frame_title (frame
);
7888 #endif /* HAVE_WINDOW_SYSTEM */
7890 /* Update the menu bar item lists, if appropriate. This has to be
7891 done before any actual redisplay or generation of display lines. */
7892 all_windows
= (update_mode_lines
7893 || buffer_shared
> 1
7894 || windows_or_buffers_changed
);
7897 Lisp_Object tail
, frame
;
7898 int count
= SPECPDL_INDEX ();
7900 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7902 FOR_EACH_FRAME (tail
, frame
)
7906 /* Ignore tooltip frame. */
7907 if (EQ (frame
, tooltip_frame
))
7910 /* If a window on this frame changed size, report that to
7911 the user and clear the size-change flag. */
7912 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7914 Lisp_Object functions
;
7916 /* Clear flag first in case we get an error below. */
7917 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7918 functions
= Vwindow_size_change_functions
;
7919 GCPRO2 (tail
, functions
);
7921 while (CONSP (functions
))
7923 call1 (XCAR (functions
), frame
);
7924 functions
= XCDR (functions
);
7930 update_menu_bar (f
, 0);
7931 #ifdef HAVE_WINDOW_SYSTEM
7932 update_tool_bar (f
, 0);
7937 unbind_to (count
, Qnil
);
7941 struct frame
*sf
= SELECTED_FRAME ();
7942 update_menu_bar (sf
, 1);
7943 #ifdef HAVE_WINDOW_SYSTEM
7944 update_tool_bar (sf
, 1);
7948 /* Motif needs this. See comment in xmenu.c. Turn it off when
7949 pending_menu_activation is not defined. */
7950 #ifdef USE_X_TOOLKIT
7951 pending_menu_activation
= 0;
7956 /* Update the menu bar item list for frame F. This has to be done
7957 before we start to fill in any display lines, because it can call
7960 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
7963 update_menu_bar (f
, save_match_data
)
7965 int save_match_data
;
7968 register struct window
*w
;
7970 /* If called recursively during a menu update, do nothing. This can
7971 happen when, for instance, an activate-menubar-hook causes a
7973 if (inhibit_menubar_update
)
7976 window
= FRAME_SELECTED_WINDOW (f
);
7977 w
= XWINDOW (window
);
7979 #if 0 /* The if statement below this if statement used to include the
7980 condition !NILP (w->update_mode_line), rather than using
7981 update_mode_lines directly, and this if statement may have
7982 been added to make that condition work. Now the if
7983 statement below matches its comment, this isn't needed. */
7984 if (update_mode_lines
)
7985 w
->update_mode_line
= Qt
;
7988 if (FRAME_WINDOW_P (f
)
7990 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
7991 || defined (USE_GTK)
7992 FRAME_EXTERNAL_MENU_BAR (f
)
7994 FRAME_MENU_BAR_LINES (f
) > 0
7996 : FRAME_MENU_BAR_LINES (f
) > 0)
7998 /* If the user has switched buffers or windows, we need to
7999 recompute to reflect the new bindings. But we'll
8000 recompute when update_mode_lines is set too; that means
8001 that people can use force-mode-line-update to request
8002 that the menu bar be recomputed. The adverse effect on
8003 the rest of the redisplay algorithm is about the same as
8004 windows_or_buffers_changed anyway. */
8005 if (windows_or_buffers_changed
8006 /* This used to test w->update_mode_line, but we believe
8007 there is no need to recompute the menu in that case. */
8008 || update_mode_lines
8009 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8010 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8011 != !NILP (w
->last_had_star
))
8012 || ((!NILP (Vtransient_mark_mode
)
8013 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8014 != !NILP (w
->region_showing
)))
8016 struct buffer
*prev
= current_buffer
;
8017 int count
= SPECPDL_INDEX ();
8019 specbind (Qinhibit_menubar_update
, Qt
);
8021 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8022 if (save_match_data
)
8023 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8024 if (NILP (Voverriding_local_map_menu_flag
))
8026 specbind (Qoverriding_terminal_local_map
, Qnil
);
8027 specbind (Qoverriding_local_map
, Qnil
);
8030 /* Run the Lucid hook. */
8031 safe_run_hooks (Qactivate_menubar_hook
);
8033 /* If it has changed current-menubar from previous value,
8034 really recompute the menu-bar from the value. */
8035 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8036 call0 (Qrecompute_lucid_menubar
);
8038 safe_run_hooks (Qmenu_bar_update_hook
);
8039 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
8041 /* Redisplay the menu bar in case we changed it. */
8042 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8043 || defined (USE_GTK)
8044 if (FRAME_WINDOW_P (f
)
8045 #if defined (MAC_OS)
8046 /* All frames on Mac OS share the same menubar. So only the
8047 selected frame should be allowed to set it. */
8048 && f
== SELECTED_FRAME ()
8051 set_frame_menubar (f
, 0, 0);
8053 /* On a terminal screen, the menu bar is an ordinary screen
8054 line, and this makes it get updated. */
8055 w
->update_mode_line
= Qt
;
8056 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8057 /* In the non-toolkit version, the menu bar is an ordinary screen
8058 line, and this makes it get updated. */
8059 w
->update_mode_line
= Qt
;
8060 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8062 unbind_to (count
, Qnil
);
8063 set_buffer_internal_1 (prev
);
8070 /***********************************************************************
8072 ***********************************************************************/
8074 #ifdef HAVE_WINDOW_SYSTEM
8077 Nominal cursor position -- where to draw output.
8078 HPOS and VPOS are window relative glyph matrix coordinates.
8079 X and Y are window relative pixel coordinates. */
8081 struct cursor_pos output_cursor
;
8085 Set the global variable output_cursor to CURSOR. All cursor
8086 positions are relative to updated_window. */
8089 set_output_cursor (cursor
)
8090 struct cursor_pos
*cursor
;
8092 output_cursor
.hpos
= cursor
->hpos
;
8093 output_cursor
.vpos
= cursor
->vpos
;
8094 output_cursor
.x
= cursor
->x
;
8095 output_cursor
.y
= cursor
->y
;
8100 Set a nominal cursor position.
8102 HPOS and VPOS are column/row positions in a window glyph matrix. X
8103 and Y are window text area relative pixel positions.
8105 If this is done during an update, updated_window will contain the
8106 window that is being updated and the position is the future output
8107 cursor position for that window. If updated_window is null, use
8108 selected_window and display the cursor at the given position. */
8111 x_cursor_to (vpos
, hpos
, y
, x
)
8112 int vpos
, hpos
, y
, x
;
8116 /* If updated_window is not set, work on selected_window. */
8120 w
= XWINDOW (selected_window
);
8122 /* Set the output cursor. */
8123 output_cursor
.hpos
= hpos
;
8124 output_cursor
.vpos
= vpos
;
8125 output_cursor
.x
= x
;
8126 output_cursor
.y
= y
;
8128 /* If not called as part of an update, really display the cursor.
8129 This will also set the cursor position of W. */
8130 if (updated_window
== NULL
)
8133 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8134 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
8135 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
8140 #endif /* HAVE_WINDOW_SYSTEM */
8143 /***********************************************************************
8145 ***********************************************************************/
8147 #ifdef HAVE_WINDOW_SYSTEM
8149 /* Where the mouse was last time we reported a mouse event. */
8151 FRAME_PTR last_mouse_frame
;
8153 /* Tool-bar item index of the item on which a mouse button was pressed
8156 int last_tool_bar_item
;
8159 /* Update the tool-bar item list for frame F. This has to be done
8160 before we start to fill in any display lines. Called from
8161 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8162 and restore it here. */
8165 update_tool_bar (f
, save_match_data
)
8167 int save_match_data
;
8170 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
8172 int do_update
= WINDOWP (f
->tool_bar_window
)
8173 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
8181 window
= FRAME_SELECTED_WINDOW (f
);
8182 w
= XWINDOW (window
);
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 || !NILP (w
->update_mode_line
)
8193 || update_mode_lines
8194 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8195 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8196 != !NILP (w
->last_had_star
))
8197 || ((!NILP (Vtransient_mark_mode
)
8198 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8199 != !NILP (w
->region_showing
)))
8201 struct buffer
*prev
= current_buffer
;
8202 int count
= SPECPDL_INDEX ();
8203 Lisp_Object old_tool_bar
;
8204 struct gcpro gcpro1
;
8206 /* Set current_buffer to the buffer of the selected
8207 window of the frame, so that we get the right local
8209 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8211 /* Save match data, if we must. */
8212 if (save_match_data
)
8213 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8215 /* Make sure that we don't accidentally use bogus keymaps. */
8216 if (NILP (Voverriding_local_map_menu_flag
))
8218 specbind (Qoverriding_terminal_local_map
, Qnil
);
8219 specbind (Qoverriding_local_map
, Qnil
);
8222 old_tool_bar
= f
->tool_bar_items
;
8223 GCPRO1 (old_tool_bar
);
8225 /* Build desired tool-bar items from keymaps. */
8228 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
8231 /* Redisplay the tool-bar if we changed it. */
8232 if (! NILP (Fequal (old_tool_bar
, f
->tool_bar_items
)))
8233 w
->update_mode_line
= Qt
;
8237 unbind_to (count
, Qnil
);
8238 set_buffer_internal_1 (prev
);
8244 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8245 F's desired tool-bar contents. F->tool_bar_items must have
8246 been set up previously by calling prepare_menu_bars. */
8249 build_desired_tool_bar_string (f
)
8252 int i
, size
, size_needed
;
8253 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8254 Lisp_Object image
, plist
, props
;
8256 image
= plist
= props
= Qnil
;
8257 GCPRO3 (image
, plist
, props
);
8259 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
8260 Otherwise, make a new string. */
8262 /* The size of the string we might be able to reuse. */
8263 size
= (STRINGP (f
->desired_tool_bar_string
)
8264 ? SCHARS (f
->desired_tool_bar_string
)
8267 /* We need one space in the string for each image. */
8268 size_needed
= f
->n_tool_bar_items
;
8270 /* Reuse f->desired_tool_bar_string, if possible. */
8271 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
8272 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
8276 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
8277 Fremove_text_properties (make_number (0), make_number (size
),
8278 props
, f
->desired_tool_bar_string
);
8281 /* Put a `display' property on the string for the images to display,
8282 put a `menu_item' property on tool-bar items with a value that
8283 is the index of the item in F's tool-bar item vector. */
8284 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
8286 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
8288 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8289 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8290 int hmargin
, vmargin
, relief
, idx
, end
;
8291 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
8293 /* If image is a vector, choose the image according to the
8295 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
8296 if (VECTORP (image
))
8300 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
8301 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
8304 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
8305 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
8307 xassert (ASIZE (image
) >= idx
);
8308 image
= AREF (image
, idx
);
8313 /* Ignore invalid image specifications. */
8314 if (!valid_image_p (image
))
8317 /* Display the tool-bar button pressed, or depressed. */
8318 plist
= Fcopy_sequence (XCDR (image
));
8320 /* Compute margin and relief to draw. */
8321 relief
= (tool_bar_button_relief
>= 0
8322 ? tool_bar_button_relief
8323 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
8324 hmargin
= vmargin
= relief
;
8326 if (INTEGERP (Vtool_bar_button_margin
)
8327 && XINT (Vtool_bar_button_margin
) > 0)
8329 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
8330 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
8332 else if (CONSP (Vtool_bar_button_margin
))
8334 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
8335 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
8336 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
8338 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
8339 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
8340 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
8343 if (auto_raise_tool_bar_buttons_p
)
8345 /* Add a `:relief' property to the image spec if the item is
8349 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
8356 /* If image is selected, display it pressed, i.e. with a
8357 negative relief. If it's not selected, display it with a
8359 plist
= Fplist_put (plist
, QCrelief
,
8361 ? make_number (-relief
)
8362 : make_number (relief
)));
8367 /* Put a margin around the image. */
8368 if (hmargin
|| vmargin
)
8370 if (hmargin
== vmargin
)
8371 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
8373 plist
= Fplist_put (plist
, QCmargin
,
8374 Fcons (make_number (hmargin
),
8375 make_number (vmargin
)));
8378 /* If button is not enabled, and we don't have special images
8379 for the disabled state, make the image appear disabled by
8380 applying an appropriate algorithm to it. */
8381 if (!enabled_p
&& idx
< 0)
8382 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
8384 /* Put a `display' text property on the string for the image to
8385 display. Put a `menu-item' property on the string that gives
8386 the start of this item's properties in the tool-bar items
8388 image
= Fcons (Qimage
, plist
);
8389 props
= list4 (Qdisplay
, image
,
8390 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
8392 /* Let the last image hide all remaining spaces in the tool bar
8393 string. The string can be longer than needed when we reuse a
8395 if (i
+ 1 == f
->n_tool_bar_items
)
8396 end
= SCHARS (f
->desired_tool_bar_string
);
8399 Fadd_text_properties (make_number (i
), make_number (end
),
8400 props
, f
->desired_tool_bar_string
);
8408 /* Display one line of the tool-bar of frame IT->f. */
8411 display_tool_bar_line (it
)
8414 struct glyph_row
*row
= it
->glyph_row
;
8415 int max_x
= it
->last_visible_x
;
8418 prepare_desired_row (row
);
8419 row
->y
= it
->current_y
;
8421 /* Note that this isn't made use of if the face hasn't a box,
8422 so there's no need to check the face here. */
8423 it
->start_of_box_run_p
= 1;
8425 while (it
->current_x
< max_x
)
8427 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
8429 /* Get the next display element. */
8430 if (!get_next_display_element (it
))
8433 /* Produce glyphs. */
8434 x_before
= it
->current_x
;
8435 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
8436 PRODUCE_GLYPHS (it
);
8438 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
8443 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
8445 if (x
+ glyph
->pixel_width
> max_x
)
8447 /* Glyph doesn't fit on line. */
8448 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
8454 x
+= glyph
->pixel_width
;
8458 /* Stop at line ends. */
8459 if (ITERATOR_AT_END_OF_LINE_P (it
))
8462 set_iterator_to_next (it
, 1);
8467 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
8468 extend_face_to_end_of_line (it
);
8469 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
8470 last
->right_box_line_p
= 1;
8471 if (last
== row
->glyphs
[TEXT_AREA
])
8472 last
->left_box_line_p
= 1;
8473 compute_line_metrics (it
);
8475 /* If line is empty, make it occupy the rest of the tool-bar. */
8476 if (!row
->displays_text_p
)
8478 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
8479 row
->ascent
= row
->phys_ascent
= 0;
8482 row
->full_width_p
= 1;
8483 row
->continued_p
= 0;
8484 row
->truncated_on_left_p
= 0;
8485 row
->truncated_on_right_p
= 0;
8487 it
->current_x
= it
->hpos
= 0;
8488 it
->current_y
+= row
->height
;
8494 /* Value is the number of screen lines needed to make all tool-bar
8495 items of frame F visible. */
8498 tool_bar_lines_needed (f
)
8501 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8504 /* Initialize an iterator for iteration over
8505 F->desired_tool_bar_string in the tool-bar window of frame F. */
8506 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8507 it
.first_visible_x
= 0;
8508 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8509 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8511 while (!ITERATOR_AT_END_P (&it
))
8513 it
.glyph_row
= w
->desired_matrix
->rows
;
8514 clear_glyph_row (it
.glyph_row
);
8515 display_tool_bar_line (&it
);
8518 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
8522 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
8524 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
8533 frame
= selected_frame
;
8535 CHECK_FRAME (frame
);
8538 if (WINDOWP (f
->tool_bar_window
)
8539 || (w
= XWINDOW (f
->tool_bar_window
),
8540 WINDOW_TOTAL_LINES (w
) > 0))
8542 update_tool_bar (f
, 1);
8543 if (f
->n_tool_bar_items
)
8545 build_desired_tool_bar_string (f
);
8546 nlines
= tool_bar_lines_needed (f
);
8550 return make_number (nlines
);
8554 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
8555 height should be changed. */
8558 redisplay_tool_bar (f
)
8563 struct glyph_row
*row
;
8564 int change_height_p
= 0;
8567 if (FRAME_EXTERNAL_TOOL_BAR (f
))
8568 update_frame_tool_bar (f
);
8572 /* If frame hasn't a tool-bar window or if it is zero-height, don't
8573 do anything. This means you must start with tool-bar-lines
8574 non-zero to get the auto-sizing effect. Or in other words, you
8575 can turn off tool-bars by specifying tool-bar-lines zero. */
8576 if (!WINDOWP (f
->tool_bar_window
)
8577 || (w
= XWINDOW (f
->tool_bar_window
),
8578 WINDOW_TOTAL_LINES (w
) == 0))
8581 /* Set up an iterator for the tool-bar window. */
8582 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8583 it
.first_visible_x
= 0;
8584 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8587 /* Build a string that represents the contents of the tool-bar. */
8588 build_desired_tool_bar_string (f
);
8589 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8591 /* Display as many lines as needed to display all tool-bar items. */
8592 while (it
.current_y
< it
.last_visible_y
)
8593 display_tool_bar_line (&it
);
8595 /* It doesn't make much sense to try scrolling in the tool-bar
8596 window, so don't do it. */
8597 w
->desired_matrix
->no_scrolling_p
= 1;
8598 w
->must_be_updated_p
= 1;
8600 if (auto_resize_tool_bars_p
)
8604 /* If we couldn't display everything, change the tool-bar's
8606 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
8607 change_height_p
= 1;
8609 /* If there are blank lines at the end, except for a partially
8610 visible blank line at the end that is smaller than
8611 FRAME_LINE_HEIGHT, change the tool-bar's height. */
8612 row
= it
.glyph_row
- 1;
8613 if (!row
->displays_text_p
8614 && row
->height
>= FRAME_LINE_HEIGHT (f
))
8615 change_height_p
= 1;
8617 /* If row displays tool-bar items, but is partially visible,
8618 change the tool-bar's height. */
8619 if (row
->displays_text_p
8620 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
8621 change_height_p
= 1;
8623 /* Resize windows as needed by changing the `tool-bar-lines'
8626 && (nlines
= tool_bar_lines_needed (f
),
8627 nlines
!= WINDOW_TOTAL_LINES (w
)))
8629 extern Lisp_Object Qtool_bar_lines
;
8631 int old_height
= WINDOW_TOTAL_LINES (w
);
8633 XSETFRAME (frame
, f
);
8634 clear_glyph_matrix (w
->desired_matrix
);
8635 Fmodify_frame_parameters (frame
,
8636 Fcons (Fcons (Qtool_bar_lines
,
8637 make_number (nlines
)),
8639 if (WINDOW_TOTAL_LINES (w
) != old_height
)
8640 fonts_changed_p
= 1;
8644 return change_height_p
;
8648 /* Get information about the tool-bar item which is displayed in GLYPH
8649 on frame F. Return in *PROP_IDX the index where tool-bar item
8650 properties start in F->tool_bar_items. Value is zero if
8651 GLYPH doesn't display a tool-bar item. */
8654 tool_bar_item_info (f
, glyph
, prop_idx
)
8656 struct glyph
*glyph
;
8663 /* This function can be called asynchronously, which means we must
8664 exclude any possibility that Fget_text_property signals an
8666 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
8667 charpos
= max (0, charpos
);
8669 /* Get the text property `menu-item' at pos. The value of that
8670 property is the start index of this item's properties in
8671 F->tool_bar_items. */
8672 prop
= Fget_text_property (make_number (charpos
),
8673 Qmenu_item
, f
->current_tool_bar_string
);
8674 if (INTEGERP (prop
))
8676 *prop_idx
= XINT (prop
);
8686 /* Get information about the tool-bar item at position X/Y on frame F.
8687 Return in *GLYPH a pointer to the glyph of the tool-bar item in
8688 the current matrix of the tool-bar window of F, or NULL if not
8689 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
8690 item in F->tool_bar_items. Value is
8692 -1 if X/Y is not on a tool-bar item
8693 0 if X/Y is on the same item that was highlighted before.
8697 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
8700 struct glyph
**glyph
;
8701 int *hpos
, *vpos
, *prop_idx
;
8703 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8704 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8707 /* Find the glyph under X/Y. */
8708 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
8712 /* Get the start of this tool-bar item's properties in
8713 f->tool_bar_items. */
8714 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
8717 /* Is mouse on the highlighted item? */
8718 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
8719 && *vpos
>= dpyinfo
->mouse_face_beg_row
8720 && *vpos
<= dpyinfo
->mouse_face_end_row
8721 && (*vpos
> dpyinfo
->mouse_face_beg_row
8722 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
8723 && (*vpos
< dpyinfo
->mouse_face_end_row
8724 || *hpos
< dpyinfo
->mouse_face_end_col
8725 || dpyinfo
->mouse_face_past_end
))
8733 Handle mouse button event on the tool-bar of frame F, at
8734 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
8735 0 for button release. MODIFIERS is event modifiers for button
8739 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
8742 unsigned int modifiers
;
8744 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8745 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8746 int hpos
, vpos
, prop_idx
;
8747 struct glyph
*glyph
;
8748 Lisp_Object enabled_p
;
8750 /* If not on the highlighted tool-bar item, return. */
8751 frame_to_window_pixel_xy (w
, &x
, &y
);
8752 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
8755 /* If item is disabled, do nothing. */
8756 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
8757 if (NILP (enabled_p
))
8762 /* Show item in pressed state. */
8763 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
8764 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
8765 last_tool_bar_item
= prop_idx
;
8769 Lisp_Object key
, frame
;
8770 struct input_event event
;
8773 /* Show item in released state. */
8774 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
8775 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
8777 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
8779 XSETFRAME (frame
, f
);
8780 event
.kind
= TOOL_BAR_EVENT
;
8781 event
.frame_or_window
= frame
;
8783 kbd_buffer_store_event (&event
);
8785 event
.kind
= TOOL_BAR_EVENT
;
8786 event
.frame_or_window
= frame
;
8788 event
.modifiers
= modifiers
;
8789 kbd_buffer_store_event (&event
);
8790 last_tool_bar_item
= -1;
8795 /* Possibly highlight a tool-bar item on frame F when mouse moves to
8796 tool-bar window-relative coordinates X/Y. Called from
8797 note_mouse_highlight. */
8800 note_tool_bar_highlight (f
, x
, y
)
8804 Lisp_Object window
= f
->tool_bar_window
;
8805 struct window
*w
= XWINDOW (window
);
8806 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8808 struct glyph
*glyph
;
8809 struct glyph_row
*row
;
8811 Lisp_Object enabled_p
;
8813 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
8814 int mouse_down_p
, rc
;
8816 /* Function note_mouse_highlight is called with negative x(y
8817 values when mouse moves outside of the frame. */
8818 if (x
<= 0 || y
<= 0)
8820 clear_mouse_face (dpyinfo
);
8824 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
8827 /* Not on tool-bar item. */
8828 clear_mouse_face (dpyinfo
);
8832 /* On same tool-bar item as before. */
8835 clear_mouse_face (dpyinfo
);
8837 /* Mouse is down, but on different tool-bar item? */
8838 mouse_down_p
= (dpyinfo
->grabbed
8839 && f
== last_mouse_frame
8840 && FRAME_LIVE_P (f
));
8842 && last_tool_bar_item
!= prop_idx
)
8845 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
8846 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
8848 /* If tool-bar item is not enabled, don't highlight it. */
8849 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
8850 if (!NILP (enabled_p
))
8852 /* Compute the x-position of the glyph. In front and past the
8853 image is a space. We include this in the highlighted area. */
8854 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
8855 for (i
= x
= 0; i
< hpos
; ++i
)
8856 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
8858 /* Record this as the current active region. */
8859 dpyinfo
->mouse_face_beg_col
= hpos
;
8860 dpyinfo
->mouse_face_beg_row
= vpos
;
8861 dpyinfo
->mouse_face_beg_x
= x
;
8862 dpyinfo
->mouse_face_beg_y
= row
->y
;
8863 dpyinfo
->mouse_face_past_end
= 0;
8865 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
8866 dpyinfo
->mouse_face_end_row
= vpos
;
8867 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
8868 dpyinfo
->mouse_face_end_y
= row
->y
;
8869 dpyinfo
->mouse_face_window
= window
;
8870 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
8872 /* Display it as active. */
8873 show_mouse_face (dpyinfo
, draw
);
8874 dpyinfo
->mouse_face_image_state
= draw
;
8879 /* Set help_echo_string to a help string to display for this tool-bar item.
8880 XTread_socket does the rest. */
8881 help_echo_object
= help_echo_window
= Qnil
;
8883 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
8884 if (NILP (help_echo_string
))
8885 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
8888 #endif /* HAVE_WINDOW_SYSTEM */
8892 /***********************************************************************
8894 ***********************************************************************/
8896 #ifdef HAVE_WINDOW_SYSTEM
8898 /* An arrow like this: `<-'. */
8899 static unsigned char left_bits
[] = {
8900 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
8902 /* Right truncation arrow bitmap `->'. */
8903 static unsigned char right_bits
[] = {
8904 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
8906 /* Marker for continued lines. */
8907 static unsigned char continued_bits
[] = {
8908 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
8910 /* Marker for continuation lines. */
8911 static unsigned char continuation_bits
[] = {
8912 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
8914 /* Overlay arrow bitmap. A triangular arrow. */
8915 static unsigned char ov_bits
[] = {
8916 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
8918 /* Bitmap drawn to indicate lines not displaying text if
8919 `indicate-empty-lines' is non-nil. */
8920 static unsigned char zv_bits
[] = {
8921 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8922 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8923 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8924 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8925 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8926 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8927 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8928 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00};
8930 struct fringe_bitmap fringe_bitmaps
[MAX_FRINGE_BITMAPS
] =
8932 { 0, 0, 0, NULL
/* NO_FRINGE_BITMAP */ },
8933 { 8, sizeof (left_bits
), 0, left_bits
},
8934 { 8, sizeof (right_bits
), 0, right_bits
},
8935 { 8, sizeof (continued_bits
), 0, continued_bits
},
8936 { 8, sizeof (continuation_bits
), 0, continuation_bits
},
8937 { 8, sizeof (ov_bits
), 0, ov_bits
},
8938 { 8, sizeof (zv_bits
), 3, zv_bits
}
8942 /* Draw the bitmap WHICH in one of the left or right fringes of
8943 window W. ROW is the glyph row for which to display the bitmap; it
8944 determines the vertical position at which the bitmap has to be
8948 draw_fringe_bitmap (w
, row
, which
, left_p
)
8950 struct glyph_row
*row
;
8951 enum fringe_bitmap_type which
;
8954 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8955 struct draw_fringe_bitmap_params p
;
8957 /* Convert row to frame coordinates. */
8958 p
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
8961 p
.wd
= fringe_bitmaps
[which
].width
;
8963 p
.h
= fringe_bitmaps
[which
].height
;
8964 p
.dh
= (fringe_bitmaps
[which
].period
8965 ? (p
.y
% fringe_bitmaps
[which
].period
)
8968 /* Clip bitmap if too high. */
8969 if (p
.h
> row
->height
)
8972 p
.face
= FACE_FROM_ID (f
, FRINGE_FACE_ID
);
8973 PREPARE_FACE_FOR_DISPLAY (f
, p
.face
);
8975 /* Clear left fringe if no bitmap to draw or if bitmap doesn't fill
8980 int wd
= WINDOW_LEFT_FRINGE_WIDTH (w
);
8981 int x
= window_box_left (w
, (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
8986 p
.x
= x
- p
.wd
- (wd
- p
.wd
) / 2;
8988 if (p
.wd
< wd
|| row
->height
> p
.h
)
8990 /* If W has a vertical border to its left, don't draw over it. */
8991 wd
-= ((!WINDOW_LEFTMOST_P (w
)
8992 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
9000 int x
= window_box_right (w
,
9001 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
9004 int wd
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
9007 p
.x
= x
+ (wd
- p
.wd
) / 2;
9008 /* Clear right fringe if no bitmap to draw of if bitmap doesn't fill
9010 if (p
.wd
< wd
|| row
->height
> p
.h
)
9019 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
9021 p
.by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, row
->y
));
9022 p
.ny
= row
->visible_height
;
9025 /* Adjust y to the offset in the row to start drawing the bitmap. */
9026 p
.y
+= (row
->height
- p
.h
) / 2;
9028 FRAME_RIF (f
)->draw_fringe_bitmap (w
, row
, &p
);
9031 /* Draw fringe bitmaps for glyph row ROW on window W. Call this
9032 function with input blocked. */
9035 draw_row_fringe_bitmaps (w
, row
)
9037 struct glyph_row
*row
;
9039 enum fringe_bitmap_type bitmap
;
9041 xassert (interrupt_input_blocked
);
9043 /* If row is completely invisible, because of vscrolling, we
9044 don't have to draw anything. */
9045 if (row
->visible_height
<= 0)
9048 if (WINDOW_LEFT_FRINGE_WIDTH (w
) != 0)
9050 /* Decide which bitmap to draw in the left fringe. */
9051 if (row
->overlay_arrow_p
)
9052 bitmap
= OVERLAY_ARROW_BITMAP
;
9053 else if (row
->truncated_on_left_p
)
9054 bitmap
= LEFT_TRUNCATION_BITMAP
;
9055 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
9056 bitmap
= CONTINUATION_LINE_BITMAP
;
9057 else if (row
->indicate_empty_line_p
)
9058 bitmap
= ZV_LINE_BITMAP
;
9060 bitmap
= NO_FRINGE_BITMAP
;
9062 draw_fringe_bitmap (w
, row
, bitmap
, 1);
9065 if (WINDOW_RIGHT_FRINGE_WIDTH (w
) != 0)
9067 /* Decide which bitmap to draw in the right fringe. */
9068 if (row
->truncated_on_right_p
)
9069 bitmap
= RIGHT_TRUNCATION_BITMAP
;
9070 else if (row
->continued_p
)
9071 bitmap
= CONTINUED_LINE_BITMAP
;
9072 else if (row
->indicate_empty_line_p
&& WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
9073 bitmap
= ZV_LINE_BITMAP
;
9075 bitmap
= NO_FRINGE_BITMAP
;
9077 draw_fringe_bitmap (w
, row
, bitmap
, 0);
9082 /* Compute actual fringe widths for frame F.
9084 If REDRAW is 1, redraw F if the fringe settings was actually
9085 modified and F is visible.
9087 Since the combined left and right fringe must occupy an integral
9088 number of columns, we may need to add some pixels to each fringe.
9089 Typically, we add an equal amount (+/- 1 pixel) to each fringe,
9090 but a negative width value is taken literally (after negating it).
9092 We never make the fringes narrower than specified. It is planned
9093 to make fringe bitmaps customizable and expandable, and at that
9094 time, the user will typically specify the minimum number of pixels
9095 needed for his bitmaps, so we shouldn't select anything less than
9100 compute_fringe_widths (f
, redraw
)
9104 int o_left
= FRAME_LEFT_FRINGE_WIDTH (f
);
9105 int o_right
= FRAME_RIGHT_FRINGE_WIDTH (f
);
9106 int o_cols
= FRAME_FRINGE_COLS (f
);
9108 Lisp_Object left_fringe
= Fassq (Qleft_fringe
, f
->param_alist
);
9109 Lisp_Object right_fringe
= Fassq (Qright_fringe
, f
->param_alist
);
9110 int left_fringe_width
, right_fringe_width
;
9112 if (!NILP (left_fringe
))
9113 left_fringe
= Fcdr (left_fringe
);
9114 if (!NILP (right_fringe
))
9115 right_fringe
= Fcdr (right_fringe
);
9117 left_fringe_width
= ((NILP (left_fringe
) || !INTEGERP (left_fringe
)) ? 8 :
9118 XINT (left_fringe
));
9119 right_fringe_width
= ((NILP (right_fringe
) || !INTEGERP (right_fringe
)) ? 8 :
9120 XINT (right_fringe
));
9122 if (left_fringe_width
|| right_fringe_width
)
9124 int left_wid
= left_fringe_width
>= 0 ? left_fringe_width
: -left_fringe_width
;
9125 int right_wid
= right_fringe_width
>= 0 ? right_fringe_width
: -right_fringe_width
;
9126 int conf_wid
= left_wid
+ right_wid
;
9127 int font_wid
= FRAME_COLUMN_WIDTH (f
);
9128 int cols
= (left_wid
+ right_wid
+ font_wid
-1) / font_wid
;
9129 int real_wid
= cols
* font_wid
;
9130 if (left_wid
&& right_wid
)
9132 if (left_fringe_width
< 0)
9134 /* Left fringe width is fixed, adjust right fringe if necessary */
9135 FRAME_LEFT_FRINGE_WIDTH (f
) = left_wid
;
9136 FRAME_RIGHT_FRINGE_WIDTH (f
) = real_wid
- left_wid
;
9138 else if (right_fringe_width
< 0)
9140 /* Right fringe width is fixed, adjust left fringe if necessary */
9141 FRAME_LEFT_FRINGE_WIDTH (f
) = real_wid
- right_wid
;
9142 FRAME_RIGHT_FRINGE_WIDTH (f
) = right_wid
;
9146 /* Adjust both fringes with an equal amount.
9147 Note that we are doing integer arithmetic here, so don't
9148 lose a pixel if the total width is an odd number. */
9149 int fill
= real_wid
- conf_wid
;
9150 FRAME_LEFT_FRINGE_WIDTH (f
) = left_wid
+ fill
/2;
9151 FRAME_RIGHT_FRINGE_WIDTH (f
) = right_wid
+ fill
- fill
/2;
9154 else if (left_fringe_width
)
9156 FRAME_LEFT_FRINGE_WIDTH (f
) = real_wid
;
9157 FRAME_RIGHT_FRINGE_WIDTH (f
) = 0;
9161 FRAME_LEFT_FRINGE_WIDTH (f
) = 0;
9162 FRAME_RIGHT_FRINGE_WIDTH (f
) = real_wid
;
9164 FRAME_FRINGE_COLS (f
) = cols
;
9168 FRAME_LEFT_FRINGE_WIDTH (f
) = 0;
9169 FRAME_RIGHT_FRINGE_WIDTH (f
) = 0;
9170 FRAME_FRINGE_COLS (f
) = 0;
9173 if (redraw
&& FRAME_VISIBLE_P (f
))
9174 if (o_left
!= FRAME_LEFT_FRINGE_WIDTH (f
) ||
9175 o_right
!= FRAME_RIGHT_FRINGE_WIDTH (f
) ||
9176 o_cols
!= FRAME_FRINGE_COLS (f
))
9180 #endif /* HAVE_WINDOW_SYSTEM */
9184 /************************************************************************
9185 Horizontal scrolling
9186 ************************************************************************/
9188 static int hscroll_window_tree
P_ ((Lisp_Object
));
9189 static int hscroll_windows
P_ ((Lisp_Object
));
9191 /* For all leaf windows in the window tree rooted at WINDOW, set their
9192 hscroll value so that PT is (i) visible in the window, and (ii) so
9193 that it is not within a certain margin at the window's left and
9194 right border. Value is non-zero if any window's hscroll has been
9198 hscroll_window_tree (window
)
9201 int hscrolled_p
= 0;
9202 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9203 int hscroll_step_abs
= 0;
9204 double hscroll_step_rel
= 0;
9206 if (hscroll_relative_p
)
9208 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9209 if (hscroll_step_rel
< 0)
9211 hscroll_relative_p
= 0;
9212 hscroll_step_abs
= 0;
9215 else if (INTEGERP (Vhscroll_step
))
9217 hscroll_step_abs
= XINT (Vhscroll_step
);
9218 if (hscroll_step_abs
< 0)
9219 hscroll_step_abs
= 0;
9222 hscroll_step_abs
= 0;
9224 while (WINDOWP (window
))
9226 struct window
*w
= XWINDOW (window
);
9228 if (WINDOWP (w
->hchild
))
9229 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9230 else if (WINDOWP (w
->vchild
))
9231 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9232 else if (w
->cursor
.vpos
>= 0)
9235 int text_area_width
;
9236 struct glyph_row
*current_cursor_row
9237 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9238 struct glyph_row
*desired_cursor_row
9239 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9240 struct glyph_row
*cursor_row
9241 = (desired_cursor_row
->enabled_p
9242 ? desired_cursor_row
9243 : current_cursor_row
);
9245 text_area_width
= window_box_width (w
, TEXT_AREA
);
9247 /* Scroll when cursor is inside this scroll margin. */
9248 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9250 if ((XFASTINT (w
->hscroll
)
9251 && w
->cursor
.x
<= h_margin
)
9252 || (cursor_row
->enabled_p
9253 && cursor_row
->truncated_on_right_p
9254 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9258 struct buffer
*saved_current_buffer
;
9262 /* Find point in a display of infinite width. */
9263 saved_current_buffer
= current_buffer
;
9264 current_buffer
= XBUFFER (w
->buffer
);
9266 if (w
== XWINDOW (selected_window
))
9267 pt
= BUF_PT (current_buffer
);
9270 pt
= marker_position (w
->pointm
);
9271 pt
= max (BEGV
, pt
);
9275 /* Move iterator to pt starting at cursor_row->start in
9276 a line with infinite width. */
9277 init_to_row_start (&it
, w
, cursor_row
);
9278 it
.last_visible_x
= INFINITY
;
9279 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9280 current_buffer
= saved_current_buffer
;
9282 /* Position cursor in window. */
9283 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9284 hscroll
= max (0, it
.current_x
- text_area_width
/ 2)
9285 / FRAME_COLUMN_WIDTH (it
.f
);
9286 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9288 if (hscroll_relative_p
)
9289 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9292 wanted_x
= text_area_width
9293 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9296 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9300 if (hscroll_relative_p
)
9301 wanted_x
= text_area_width
* hscroll_step_rel
9304 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9307 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9309 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9311 /* Don't call Fset_window_hscroll if value hasn't
9312 changed because it will prevent redisplay
9314 if (XFASTINT (w
->hscroll
) != hscroll
)
9316 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9317 w
->hscroll
= make_number (hscroll
);
9326 /* Value is non-zero if hscroll of any leaf window has been changed. */
9331 /* Set hscroll so that cursor is visible and not inside horizontal
9332 scroll margins for all windows in the tree rooted at WINDOW. See
9333 also hscroll_window_tree above. Value is non-zero if any window's
9334 hscroll has been changed. If it has, desired matrices on the frame
9335 of WINDOW are cleared. */
9338 hscroll_windows (window
)
9343 if (automatic_hscrolling_p
)
9345 hscrolled_p
= hscroll_window_tree (window
);
9347 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9356 /************************************************************************
9358 ************************************************************************/
9360 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9361 to a non-zero value. This is sometimes handy to have in a debugger
9366 /* First and last unchanged row for try_window_id. */
9368 int debug_first_unchanged_at_end_vpos
;
9369 int debug_last_unchanged_at_beg_vpos
;
9371 /* Delta vpos and y. */
9373 int debug_dvpos
, debug_dy
;
9375 /* Delta in characters and bytes for try_window_id. */
9377 int debug_delta
, debug_delta_bytes
;
9379 /* Values of window_end_pos and window_end_vpos at the end of
9382 EMACS_INT debug_end_pos
, debug_end_vpos
;
9384 /* Append a string to W->desired_matrix->method. FMT is a printf
9385 format string. A1...A9 are a supplement for a variable-length
9386 argument list. If trace_redisplay_p is non-zero also printf the
9387 resulting string to stderr. */
9390 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9393 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9396 char *method
= w
->desired_matrix
->method
;
9397 int len
= strlen (method
);
9398 int size
= sizeof w
->desired_matrix
->method
;
9399 int remaining
= size
- len
- 1;
9401 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9402 if (len
&& remaining
)
9408 strncpy (method
+ len
, buffer
, remaining
);
9410 if (trace_redisplay_p
)
9411 fprintf (stderr
, "%p (%s): %s\n",
9413 ((BUFFERP (w
->buffer
)
9414 && STRINGP (XBUFFER (w
->buffer
)->name
))
9415 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9420 #endif /* GLYPH_DEBUG */
9423 /* Value is non-zero if all changes in window W, which displays
9424 current_buffer, are in the text between START and END. START is a
9425 buffer position, END is given as a distance from Z. Used in
9426 redisplay_internal for display optimization. */
9429 text_outside_line_unchanged_p (w
, start
, end
)
9433 int unchanged_p
= 1;
9435 /* If text or overlays have changed, see where. */
9436 if (XFASTINT (w
->last_modified
) < MODIFF
9437 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9439 /* Gap in the line? */
9440 if (GPT
< start
|| Z
- GPT
< end
)
9443 /* Changes start in front of the line, or end after it? */
9445 && (BEG_UNCHANGED
< start
- 1
9446 || END_UNCHANGED
< end
))
9449 /* If selective display, can't optimize if changes start at the
9450 beginning of the line. */
9452 && INTEGERP (current_buffer
->selective_display
)
9453 && XINT (current_buffer
->selective_display
) > 0
9454 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9457 /* If there are overlays at the start or end of the line, these
9458 may have overlay strings with newlines in them. A change at
9459 START, for instance, may actually concern the display of such
9460 overlay strings as well, and they are displayed on different
9461 lines. So, quickly rule out this case. (For the future, it
9462 might be desirable to implement something more telling than
9463 just BEG/END_UNCHANGED.) */
9466 if (BEG
+ BEG_UNCHANGED
== start
9467 && overlay_touches_p (start
))
9469 if (END_UNCHANGED
== end
9470 && overlay_touches_p (Z
- end
))
9479 /* Do a frame update, taking possible shortcuts into account. This is
9480 the main external entry point for redisplay.
9482 If the last redisplay displayed an echo area message and that message
9483 is no longer requested, we clear the echo area or bring back the
9484 mini-buffer if that is in use. */
9489 redisplay_internal (0);
9493 /* Return 1 if point moved out of or into a composition. Otherwise
9494 return 0. PREV_BUF and PREV_PT are the last point buffer and
9495 position. BUF and PT are the current point buffer and position. */
9498 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
9499 struct buffer
*prev_buf
, *buf
;
9506 XSETBUFFER (buffer
, buf
);
9507 /* Check a composition at the last point if point moved within the
9509 if (prev_buf
== buf
)
9512 /* Point didn't move. */
9515 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
9516 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
9517 && COMPOSITION_VALID_P (start
, end
, prop
)
9518 && start
< prev_pt
&& end
> prev_pt
)
9519 /* The last point was within the composition. Return 1 iff
9520 point moved out of the composition. */
9521 return (pt
<= start
|| pt
>= end
);
9524 /* Check a composition at the current point. */
9525 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
9526 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
9527 && COMPOSITION_VALID_P (start
, end
, prop
)
9528 && start
< pt
&& end
> pt
);
9532 /* Reconsider the setting of B->clip_changed which is displayed
9536 reconsider_clip_changes (w
, b
)
9541 && !NILP (w
->window_end_valid
)
9542 && w
->current_matrix
->buffer
== b
9543 && w
->current_matrix
->zv
== BUF_ZV (b
)
9544 && w
->current_matrix
->begv
== BUF_BEGV (b
))
9545 b
->clip_changed
= 0;
9547 /* If display wasn't paused, and W is not a tool bar window, see if
9548 point has been moved into or out of a composition. In that case,
9549 we set b->clip_changed to 1 to force updating the screen. If
9550 b->clip_changed has already been set to 1, we can skip this
9552 if (!b
->clip_changed
9553 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
9557 if (w
== XWINDOW (selected_window
))
9558 pt
= BUF_PT (current_buffer
);
9560 pt
= marker_position (w
->pointm
);
9562 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
9563 || pt
!= XINT (w
->last_point
))
9564 && check_point_in_composition (w
->current_matrix
->buffer
,
9565 XINT (w
->last_point
),
9566 XBUFFER (w
->buffer
), pt
))
9567 b
->clip_changed
= 1;
9572 /* Select FRAME to forward the values of frame-local variables into C
9573 variables so that the redisplay routines can access those values
9577 select_frame_for_redisplay (frame
)
9580 Lisp_Object tail
, sym
, val
;
9581 Lisp_Object old
= selected_frame
;
9583 selected_frame
= frame
;
9585 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9586 if (CONSP (XCAR (tail
))
9587 && (sym
= XCAR (XCAR (tail
)),
9589 && (sym
= indirect_variable (sym
),
9590 val
= SYMBOL_VALUE (sym
),
9591 (BUFFER_LOCAL_VALUEP (val
)
9592 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9593 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9594 Fsymbol_value (sym
);
9596 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9597 if (CONSP (XCAR (tail
))
9598 && (sym
= XCAR (XCAR (tail
)),
9600 && (sym
= indirect_variable (sym
),
9601 val
= SYMBOL_VALUE (sym
),
9602 (BUFFER_LOCAL_VALUEP (val
)
9603 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9604 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9605 Fsymbol_value (sym
);
9609 #define STOP_POLLING \
9610 do { if (! polling_stopped_here) stop_polling (); \
9611 polling_stopped_here = 1; } while (0)
9613 #define RESUME_POLLING \
9614 do { if (polling_stopped_here) start_polling (); \
9615 polling_stopped_here = 0; } while (0)
9618 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
9619 response to any user action; therefore, we should preserve the echo
9620 area. (Actually, our caller does that job.) Perhaps in the future
9621 avoid recentering windows if it is not necessary; currently that
9622 causes some problems. */
9625 redisplay_internal (preserve_echo_area
)
9626 int preserve_echo_area
;
9628 struct window
*w
= XWINDOW (selected_window
);
9629 struct frame
*f
= XFRAME (w
->frame
);
9631 int must_finish
= 0;
9632 struct text_pos tlbufpos
, tlendpos
;
9633 int number_of_visible_frames
;
9635 struct frame
*sf
= SELECTED_FRAME ();
9636 int polling_stopped_here
= 0;
9638 /* Non-zero means redisplay has to consider all windows on all
9639 frames. Zero means, only selected_window is considered. */
9640 int consider_all_windows_p
;
9642 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
9644 /* No redisplay if running in batch mode or frame is not yet fully
9645 initialized, or redisplay is explicitly turned off by setting
9646 Vinhibit_redisplay. */
9648 || !NILP (Vinhibit_redisplay
)
9649 || !f
->glyphs_initialized_p
)
9652 /* The flag redisplay_performed_directly_p is set by
9653 direct_output_for_insert when it already did the whole screen
9654 update necessary. */
9655 if (redisplay_performed_directly_p
)
9657 redisplay_performed_directly_p
= 0;
9658 if (!hscroll_windows (selected_window
))
9662 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
9663 if (popup_activated ())
9667 /* I don't think this happens but let's be paranoid. */
9671 /* Record a function that resets redisplaying_p to its old value
9672 when we leave this function. */
9673 count
= SPECPDL_INDEX ();
9674 record_unwind_protect (unwind_redisplay
,
9675 Fcons (make_number (redisplaying_p
), selected_frame
));
9677 specbind (Qinhibit_free_realized_faces
, Qnil
);
9681 reconsider_clip_changes (w
, current_buffer
);
9683 /* If new fonts have been loaded that make a glyph matrix adjustment
9684 necessary, do it. */
9685 if (fonts_changed_p
)
9687 adjust_glyphs (NULL
);
9688 ++windows_or_buffers_changed
;
9689 fonts_changed_p
= 0;
9692 /* If face_change_count is non-zero, init_iterator will free all
9693 realized faces, which includes the faces referenced from current
9694 matrices. So, we can't reuse current matrices in this case. */
9695 if (face_change_count
)
9696 ++windows_or_buffers_changed
;
9698 if (FRAME_TERMCAP_P (sf
)
9699 && FRAME_TTY (sf
)->previous_terminal_frame
!= sf
)
9701 /* Since frames on a single ASCII terminal share the same
9702 display area, displaying a different frame means redisplay
9704 windows_or_buffers_changed
++;
9705 SET_FRAME_GARBAGED (sf
);
9706 FRAME_TTY (sf
)->previous_terminal_frame
= sf
;
9709 /* Set the visible flags for all frames. Do this before checking
9710 for resized or garbaged frames; they want to know if their frames
9711 are visible. See the comment in frame.h for
9712 FRAME_SAMPLE_VISIBILITY. */
9714 Lisp_Object tail
, frame
;
9716 number_of_visible_frames
= 0;
9718 FOR_EACH_FRAME (tail
, frame
)
9720 struct frame
*f
= XFRAME (frame
);
9722 FRAME_SAMPLE_VISIBILITY (f
);
9723 if (FRAME_VISIBLE_P (f
))
9724 ++number_of_visible_frames
;
9725 clear_desired_matrices (f
);
9730 /* Notice any pending interrupt request to change frame size. */
9731 do_pending_window_change (1);
9733 /* Clear frames marked as garbaged. */
9735 clear_garbaged_frames ();
9737 /* Build menubar and tool-bar items. */
9738 prepare_menu_bars ();
9740 if (windows_or_buffers_changed
)
9741 update_mode_lines
++;
9743 /* Detect case that we need to write or remove a star in the mode line. */
9744 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
9746 w
->update_mode_line
= Qt
;
9747 if (buffer_shared
> 1)
9748 update_mode_lines
++;
9751 /* If %c is in the mode line, update it if needed. */
9752 if (!NILP (w
->column_number_displayed
)
9753 /* This alternative quickly identifies a common case
9754 where no change is needed. */
9755 && !(PT
== XFASTINT (w
->last_point
)
9756 && XFASTINT (w
->last_modified
) >= MODIFF
9757 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9758 && (XFASTINT (w
->column_number_displayed
)
9759 != (int) current_column ())) /* iftc */
9760 w
->update_mode_line
= Qt
;
9762 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
9764 /* The variable buffer_shared is set in redisplay_window and
9765 indicates that we redisplay a buffer in different windows. See
9767 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
9768 || cursor_type_changed
);
9770 /* If specs for an arrow have changed, do thorough redisplay
9771 to ensure we remove any arrow that should no longer exist. */
9772 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
9773 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
9774 consider_all_windows_p
= windows_or_buffers_changed
= 1;
9776 /* Normally the message* functions will have already displayed and
9777 updated the echo area, but the frame may have been trashed, or
9778 the update may have been preempted, so display the echo area
9779 again here. Checking message_cleared_p captures the case that
9780 the echo area should be cleared. */
9781 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
9782 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
9783 || (message_cleared_p
9784 && minibuf_level
== 0
9785 /* If the mini-window is currently selected, this means the
9786 echo-area doesn't show through. */
9787 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
9789 int window_height_changed_p
= echo_area_display (0);
9792 /* If we don't display the current message, don't clear the
9793 message_cleared_p flag, because, if we did, we wouldn't clear
9794 the echo area in the next redisplay which doesn't preserve
9796 if (!display_last_displayed_message_p
)
9797 message_cleared_p
= 0;
9799 if (fonts_changed_p
)
9801 else if (window_height_changed_p
)
9803 consider_all_windows_p
= 1;
9804 ++update_mode_lines
;
9805 ++windows_or_buffers_changed
;
9807 /* If window configuration was changed, frames may have been
9808 marked garbaged. Clear them or we will experience
9809 surprises wrt scrolling. */
9811 clear_garbaged_frames ();
9814 else if (EQ (selected_window
, minibuf_window
)
9815 && (current_buffer
->clip_changed
9816 || XFASTINT (w
->last_modified
) < MODIFF
9817 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9818 && resize_mini_window (w
, 0))
9820 /* Resized active mini-window to fit the size of what it is
9821 showing if its contents might have changed. */
9823 consider_all_windows_p
= 1;
9824 ++windows_or_buffers_changed
;
9825 ++update_mode_lines
;
9827 /* If window configuration was changed, frames may have been
9828 marked garbaged. Clear them or we will experience
9829 surprises wrt scrolling. */
9831 clear_garbaged_frames ();
9835 /* If showing the region, and mark has changed, we must redisplay
9836 the whole window. The assignment to this_line_start_pos prevents
9837 the optimization directly below this if-statement. */
9838 if (((!NILP (Vtransient_mark_mode
)
9839 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9840 != !NILP (w
->region_showing
))
9841 || (!NILP (w
->region_showing
)
9842 && !EQ (w
->region_showing
,
9843 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
9844 CHARPOS (this_line_start_pos
) = 0;
9846 /* Optimize the case that only the line containing the cursor in the
9847 selected window has changed. Variables starting with this_ are
9848 set in display_line and record information about the line
9849 containing the cursor. */
9850 tlbufpos
= this_line_start_pos
;
9851 tlendpos
= this_line_end_pos
;
9852 if (!consider_all_windows_p
9853 && CHARPOS (tlbufpos
) > 0
9854 && NILP (w
->update_mode_line
)
9855 && !current_buffer
->clip_changed
9856 && !current_buffer
->prevent_redisplay_optimizations_p
9857 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
9858 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
9859 /* Make sure recorded data applies to current buffer, etc. */
9860 && this_line_buffer
== current_buffer
9861 && current_buffer
== XBUFFER (w
->buffer
)
9862 && NILP (w
->force_start
)
9863 && NILP (w
->optional_new_start
)
9864 /* Point must be on the line that we have info recorded about. */
9865 && PT
>= CHARPOS (tlbufpos
)
9866 && PT
<= Z
- CHARPOS (tlendpos
)
9867 /* All text outside that line, including its final newline,
9868 must be unchanged */
9869 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
9870 CHARPOS (tlendpos
)))
9872 if (CHARPOS (tlbufpos
) > BEGV
9873 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
9874 && (CHARPOS (tlbufpos
) == ZV
9875 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
9876 /* Former continuation line has disappeared by becoming empty */
9878 else if (XFASTINT (w
->last_modified
) < MODIFF
9879 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
9880 || MINI_WINDOW_P (w
))
9882 /* We have to handle the case of continuation around a
9883 wide-column character (See the comment in indent.c around
9886 For instance, in the following case:
9888 -------- Insert --------
9889 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
9890 J_I_ ==> J_I_ `^^' are cursors.
9894 As we have to redraw the line above, we should goto cancel. */
9897 int line_height_before
= this_line_pixel_height
;
9899 /* Note that start_display will handle the case that the
9900 line starting at tlbufpos is a continuation lines. */
9901 start_display (&it
, w
, tlbufpos
);
9903 /* Implementation note: It this still necessary? */
9904 if (it
.current_x
!= this_line_start_x
)
9907 TRACE ((stderr
, "trying display optimization 1\n"));
9908 w
->cursor
.vpos
= -1;
9909 overlay_arrow_seen
= 0;
9910 it
.vpos
= this_line_vpos
;
9911 it
.current_y
= this_line_y
;
9912 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
9915 /* If line contains point, is not continued,
9916 and ends at same distance from eob as before, we win */
9917 if (w
->cursor
.vpos
>= 0
9918 /* Line is not continued, otherwise this_line_start_pos
9919 would have been set to 0 in display_line. */
9920 && CHARPOS (this_line_start_pos
)
9921 /* Line ends as before. */
9922 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
9923 /* Line has same height as before. Otherwise other lines
9924 would have to be shifted up or down. */
9925 && this_line_pixel_height
== line_height_before
)
9927 /* If this is not the window's last line, we must adjust
9928 the charstarts of the lines below. */
9929 if (it
.current_y
< it
.last_visible_y
)
9931 struct glyph_row
*row
9932 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
9933 int delta
, delta_bytes
;
9935 if (Z
- CHARPOS (tlendpos
) == ZV
)
9937 /* This line ends at end of (accessible part of)
9938 buffer. There is no newline to count. */
9940 - CHARPOS (tlendpos
)
9941 - MATRIX_ROW_START_CHARPOS (row
));
9942 delta_bytes
= (Z_BYTE
9943 - BYTEPOS (tlendpos
)
9944 - MATRIX_ROW_START_BYTEPOS (row
));
9948 /* This line ends in a newline. Must take
9949 account of the newline and the rest of the
9950 text that follows. */
9952 - CHARPOS (tlendpos
)
9953 - MATRIX_ROW_START_CHARPOS (row
));
9954 delta_bytes
= (Z_BYTE
9955 - BYTEPOS (tlendpos
)
9956 - MATRIX_ROW_START_BYTEPOS (row
));
9959 increment_matrix_positions (w
->current_matrix
,
9961 w
->current_matrix
->nrows
,
9962 delta
, delta_bytes
);
9965 /* If this row displays text now but previously didn't,
9966 or vice versa, w->window_end_vpos may have to be
9968 if ((it
.glyph_row
- 1)->displays_text_p
)
9970 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
9971 XSETINT (w
->window_end_vpos
, this_line_vpos
);
9973 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
9974 && this_line_vpos
> 0)
9975 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
9976 w
->window_end_valid
= Qnil
;
9978 /* Update hint: No need to try to scroll in update_window. */
9979 w
->desired_matrix
->no_scrolling_p
= 1;
9982 *w
->desired_matrix
->method
= 0;
9983 debug_method_add (w
, "optimization 1");
9990 else if (/* Cursor position hasn't changed. */
9991 PT
== XFASTINT (w
->last_point
)
9992 /* Make sure the cursor was last displayed
9993 in this window. Otherwise we have to reposition it. */
9994 && 0 <= w
->cursor
.vpos
9995 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
9999 do_pending_window_change (1);
10001 /* We used to always goto end_of_redisplay here, but this
10002 isn't enough if we have a blinking cursor. */
10003 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10004 goto end_of_redisplay
;
10008 /* If highlighting the region, or if the cursor is in the echo area,
10009 then we can't just move the cursor. */
10010 else if (! (!NILP (Vtransient_mark_mode
)
10011 && !NILP (current_buffer
->mark_active
))
10012 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10013 || highlight_nonselected_windows
)
10014 && NILP (w
->region_showing
)
10015 && NILP (Vshow_trailing_whitespace
)
10016 && !cursor_in_echo_area
)
10019 struct glyph_row
*row
;
10021 /* Skip from tlbufpos to PT and see where it is. Note that
10022 PT may be in invisible text. If so, we will end at the
10023 next visible position. */
10024 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10025 NULL
, DEFAULT_FACE_ID
);
10026 it
.current_x
= this_line_start_x
;
10027 it
.current_y
= this_line_y
;
10028 it
.vpos
= this_line_vpos
;
10030 /* The call to move_it_to stops in front of PT, but
10031 moves over before-strings. */
10032 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10034 if (it
.vpos
== this_line_vpos
10035 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10038 xassert (this_line_vpos
== it
.vpos
);
10039 xassert (this_line_y
== it
.current_y
);
10040 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10042 *w
->desired_matrix
->method
= 0;
10043 debug_method_add (w
, "optimization 3");
10052 /* Text changed drastically or point moved off of line. */
10053 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10056 CHARPOS (this_line_start_pos
) = 0;
10057 consider_all_windows_p
|= buffer_shared
> 1;
10058 ++clear_face_cache_count
;
10061 /* Build desired matrices, and update the display. If
10062 consider_all_windows_p is non-zero, do it for all windows on all
10063 frames. Otherwise do it for selected_window, only. */
10065 if (consider_all_windows_p
)
10067 Lisp_Object tail
, frame
;
10068 int i
, n
= 0, size
= 50;
10069 struct frame
**updated
10070 = (struct frame
**) alloca (size
* sizeof *updated
);
10072 /* Clear the face cache eventually. */
10073 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
10075 clear_face_cache (0);
10076 clear_face_cache_count
= 0;
10079 /* Recompute # windows showing selected buffer. This will be
10080 incremented each time such a window is displayed. */
10083 FOR_EACH_FRAME (tail
, frame
)
10085 struct frame
*f
= XFRAME (frame
);
10087 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
10089 if (! EQ (frame
, selected_frame
))
10090 /* Select the frame, for the sake of frame-local
10092 select_frame_for_redisplay (frame
);
10094 #ifdef HAVE_WINDOW_SYSTEM
10095 if (clear_face_cache_count
% 50 == 0
10096 && FRAME_WINDOW_P (f
))
10097 clear_image_cache (f
, 0);
10098 #endif /* HAVE_WINDOW_SYSTEM */
10100 /* Mark all the scroll bars to be removed; we'll redeem
10101 the ones we want when we redisplay their windows. */
10102 if (FRAME_DISPLAY (f
)->condemn_scroll_bars_hook
)
10103 FRAME_DISPLAY (f
)->condemn_scroll_bars_hook (f
);
10105 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10106 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10108 /* Any scroll bars which redisplay_windows should have
10109 nuked should now go away. */
10110 if (FRAME_DISPLAY (f
)->judge_scroll_bars_hook
)
10111 FRAME_DISPLAY (f
)->judge_scroll_bars_hook (f
);
10113 /* If fonts changed, display again. */
10114 /* ??? rms: I suspect it is a mistake to jump all the way
10115 back to retry here. It should just retry this frame. */
10116 if (fonts_changed_p
)
10119 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10121 /* See if we have to hscroll. */
10122 if (hscroll_windows (f
->root_window
))
10125 /* Prevent various kinds of signals during display
10126 update. stdio is not robust about handling
10127 signals, which can cause an apparent I/O
10129 if (interrupt_input
)
10130 unrequest_sigio ();
10133 /* Update the display. */
10134 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10135 pause
|= update_frame (f
, 0, 0);
10136 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10143 int nbytes
= size
* sizeof *updated
;
10144 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
10145 bcopy (updated
, p
, nbytes
);
10156 /* Do the mark_window_display_accurate after all windows have
10157 been redisplayed because this call resets flags in buffers
10158 which are needed for proper redisplay. */
10159 for (i
= 0; i
< n
; ++i
)
10161 struct frame
*f
= updated
[i
];
10162 mark_window_display_accurate (f
->root_window
, 1);
10163 if (FRAME_DISPLAY (f
)->frame_up_to_date_hook
)
10164 FRAME_DISPLAY (f
)->frame_up_to_date_hook (f
);
10168 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10170 Lisp_Object mini_window
;
10171 struct frame
*mini_frame
;
10173 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10174 /* Use list_of_error, not Qerror, so that
10175 we catch only errors and don't run the debugger. */
10176 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10178 redisplay_window_error
);
10180 /* Compare desired and current matrices, perform output. */
10183 /* If fonts changed, display again. */
10184 if (fonts_changed_p
)
10187 /* Prevent various kinds of signals during display update.
10188 stdio is not robust about handling signals,
10189 which can cause an apparent I/O error. */
10190 if (interrupt_input
)
10191 unrequest_sigio ();
10194 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10196 if (hscroll_windows (selected_window
))
10199 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10200 pause
= update_frame (sf
, 0, 0);
10203 /* We may have called echo_area_display at the top of this
10204 function. If the echo area is on another frame, that may
10205 have put text on a frame other than the selected one, so the
10206 above call to update_frame would not have caught it. Catch
10208 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10209 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10211 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10213 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10214 pause
|= update_frame (mini_frame
, 0, 0);
10215 if (!pause
&& hscroll_windows (mini_window
))
10220 /* If display was paused because of pending input, make sure we do a
10221 thorough update the next time. */
10224 /* Prevent the optimization at the beginning of
10225 redisplay_internal that tries a single-line update of the
10226 line containing the cursor in the selected window. */
10227 CHARPOS (this_line_start_pos
) = 0;
10229 /* Let the overlay arrow be updated the next time. */
10230 if (!NILP (last_arrow_position
))
10232 last_arrow_position
= Qt
;
10233 last_arrow_string
= Qt
;
10236 /* If we pause after scrolling, some rows in the current
10237 matrices of some windows are not valid. */
10238 if (!WINDOW_FULL_WIDTH_P (w
)
10239 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10240 update_mode_lines
= 1;
10244 if (!consider_all_windows_p
)
10246 /* This has already been done above if
10247 consider_all_windows_p is set. */
10248 mark_window_display_accurate_1 (w
, 1);
10250 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
10251 last_arrow_string
= Voverlay_arrow_string
;
10253 if (FRAME_DISPLAY (sf
)->frame_up_to_date_hook
!= 0)
10254 FRAME_DISPLAY (sf
)->frame_up_to_date_hook (sf
);
10257 update_mode_lines
= 0;
10258 windows_or_buffers_changed
= 0;
10259 cursor_type_changed
= 0;
10262 /* Start SIGIO interrupts coming again. Having them off during the
10263 code above makes it less likely one will discard output, but not
10264 impossible, since there might be stuff in the system buffer here.
10265 But it is much hairier to try to do anything about that. */
10266 if (interrupt_input
)
10270 /* If a frame has become visible which was not before, redisplay
10271 again, so that we display it. Expose events for such a frame
10272 (which it gets when becoming visible) don't call the parts of
10273 redisplay constructing glyphs, so simply exposing a frame won't
10274 display anything in this case. So, we have to display these
10275 frames here explicitly. */
10278 Lisp_Object tail
, frame
;
10281 FOR_EACH_FRAME (tail
, frame
)
10283 int this_is_visible
= 0;
10285 if (XFRAME (frame
)->visible
)
10286 this_is_visible
= 1;
10287 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10288 if (XFRAME (frame
)->visible
)
10289 this_is_visible
= 1;
10291 if (this_is_visible
)
10295 if (new_count
!= number_of_visible_frames
)
10296 windows_or_buffers_changed
++;
10299 /* Change frame size now if a change is pending. */
10300 do_pending_window_change (1);
10302 /* If we just did a pending size change, or have additional
10303 visible frames, redisplay again. */
10304 if (windows_or_buffers_changed
&& !pause
)
10308 unbind_to (count
, Qnil
);
10313 /* Redisplay, but leave alone any recent echo area message unless
10314 another message has been requested in its place.
10316 This is useful in situations where you need to redisplay but no
10317 user action has occurred, making it inappropriate for the message
10318 area to be cleared. See tracking_off and
10319 wait_reading_process_input for examples of these situations.
10321 FROM_WHERE is an integer saying from where this function was
10322 called. This is useful for debugging. */
10325 redisplay_preserve_echo_area (from_where
)
10328 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10330 if (!NILP (echo_area_buffer
[1]))
10332 /* We have a previously displayed message, but no current
10333 message. Redisplay the previous message. */
10334 display_last_displayed_message_p
= 1;
10335 redisplay_internal (1);
10336 display_last_displayed_message_p
= 0;
10339 redisplay_internal (1);
10343 /* Function registered with record_unwind_protect in
10344 redisplay_internal. Reset redisplaying_p to the value it had
10345 before redisplay_internal was called, and clear
10346 prevent_freeing_realized_faces_p. It also selects the previously
10350 unwind_redisplay (val
)
10353 Lisp_Object old_redisplaying_p
, old_frame
;
10355 old_redisplaying_p
= XCAR (val
);
10356 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10357 old_frame
= XCDR (val
);
10358 if (! EQ (old_frame
, selected_frame
))
10359 select_frame_for_redisplay (old_frame
);
10364 /* Mark the display of window W as accurate or inaccurate. If
10365 ACCURATE_P is non-zero mark display of W as accurate. If
10366 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10367 redisplay_internal is called. */
10370 mark_window_display_accurate_1 (w
, accurate_p
)
10374 if (BUFFERP (w
->buffer
))
10376 struct buffer
*b
= XBUFFER (w
->buffer
);
10379 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
10380 w
->last_overlay_modified
10381 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
10383 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
10387 b
->clip_changed
= 0;
10388 b
->prevent_redisplay_optimizations_p
= 0;
10390 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
10391 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
10392 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
10393 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
10395 w
->current_matrix
->buffer
= b
;
10396 w
->current_matrix
->begv
= BUF_BEGV (b
);
10397 w
->current_matrix
->zv
= BUF_ZV (b
);
10399 w
->last_cursor
= w
->cursor
;
10400 w
->last_cursor_off_p
= w
->cursor_off_p
;
10402 if (w
== XWINDOW (selected_window
))
10403 w
->last_point
= make_number (BUF_PT (b
));
10405 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
10411 w
->window_end_valid
= w
->buffer
;
10412 #if 0 /* This is incorrect with variable-height lines. */
10413 xassert (XINT (w
->window_end_vpos
)
10414 < (WINDOW_TOTAL_LINES (w
)
10415 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
10417 w
->update_mode_line
= Qnil
;
10422 /* Mark the display of windows in the window tree rooted at WINDOW as
10423 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
10424 windows as accurate. If ACCURATE_P is zero, arrange for windows to
10425 be redisplayed the next time redisplay_internal is called. */
10428 mark_window_display_accurate (window
, accurate_p
)
10429 Lisp_Object window
;
10434 for (; !NILP (window
); window
= w
->next
)
10436 w
= XWINDOW (window
);
10437 mark_window_display_accurate_1 (w
, accurate_p
);
10439 if (!NILP (w
->vchild
))
10440 mark_window_display_accurate (w
->vchild
, accurate_p
);
10441 if (!NILP (w
->hchild
))
10442 mark_window_display_accurate (w
->hchild
, accurate_p
);
10447 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
10448 last_arrow_string
= Voverlay_arrow_string
;
10452 /* Force a thorough redisplay the next time by setting
10453 last_arrow_position and last_arrow_string to t, which is
10454 unequal to any useful value of Voverlay_arrow_... */
10455 last_arrow_position
= Qt
;
10456 last_arrow_string
= Qt
;
10461 /* Return value in display table DP (Lisp_Char_Table *) for character
10462 C. Since a display table doesn't have any parent, we don't have to
10463 follow parent. Do not call this function directly but use the
10464 macro DISP_CHAR_VECTOR. */
10467 disp_char_vector (dp
, c
)
10468 struct Lisp_Char_Table
*dp
;
10474 if (SINGLE_BYTE_CHAR_P (c
))
10475 return (dp
->contents
[c
]);
10477 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
10480 else if (code
[2] < 32)
10483 /* Here, the possible range of code[0] (== charset ID) is
10484 128..max_charset. Since the top level char table contains data
10485 for multibyte characters after 256th element, we must increment
10486 code[0] by 128 to get a correct index. */
10488 code
[3] = -1; /* anchor */
10490 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
10492 val
= dp
->contents
[code
[i
]];
10493 if (!SUB_CHAR_TABLE_P (val
))
10494 return (NILP (val
) ? dp
->defalt
: val
);
10497 /* Here, val is a sub char table. We return the default value of
10499 return (dp
->defalt
);
10504 /***********************************************************************
10506 ***********************************************************************/
10508 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
10511 redisplay_windows (window
)
10512 Lisp_Object window
;
10514 while (!NILP (window
))
10516 struct window
*w
= XWINDOW (window
);
10518 if (!NILP (w
->hchild
))
10519 redisplay_windows (w
->hchild
);
10520 else if (!NILP (w
->vchild
))
10521 redisplay_windows (w
->vchild
);
10524 displayed_buffer
= XBUFFER (w
->buffer
);
10525 /* Use list_of_error, not Qerror, so that
10526 we catch only errors and don't run the debugger. */
10527 internal_condition_case_1 (redisplay_window_0
, window
,
10529 redisplay_window_error
);
10537 redisplay_window_error ()
10539 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
10544 redisplay_window_0 (window
)
10545 Lisp_Object window
;
10547 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10548 redisplay_window (window
, 0);
10553 redisplay_window_1 (window
)
10554 Lisp_Object window
;
10556 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10557 redisplay_window (window
, 1);
10562 /* Increment GLYPH until it reaches END or CONDITION fails while
10563 adding (GLYPH)->pixel_width to X. */
10565 #define SKIP_GLYPHS(glyph, end, x, condition) \
10568 (x) += (glyph)->pixel_width; \
10571 while ((glyph) < (end) && (condition))
10574 /* Set cursor position of W. PT is assumed to be displayed in ROW.
10575 DELTA is the number of bytes by which positions recorded in ROW
10576 differ from current buffer positions. */
10579 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
10581 struct glyph_row
*row
;
10582 struct glyph_matrix
*matrix
;
10583 int delta
, delta_bytes
, dy
, dvpos
;
10585 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
10586 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
10587 /* The first glyph that starts a sequence of glyphs from string. */
10588 struct glyph
*string_start
;
10589 /* The X coordinate of string_start. */
10590 int string_start_x
;
10591 /* The last known character position. */
10592 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
10593 /* The last known character position before string_start. */
10594 int string_before_pos
;
10596 int pt_old
= PT
- delta
;
10598 /* Skip over glyphs not having an object at the start of the row.
10599 These are special glyphs like truncation marks on terminal
10601 if (row
->displays_text_p
)
10603 && INTEGERP (glyph
->object
)
10604 && glyph
->charpos
< 0)
10606 x
+= glyph
->pixel_width
;
10610 string_start
= NULL
;
10612 && !INTEGERP (glyph
->object
)
10613 && (!BUFFERP (glyph
->object
)
10614 || (last_pos
= glyph
->charpos
) < pt_old
))
10616 if (! STRINGP (glyph
->object
))
10618 string_start
= NULL
;
10619 x
+= glyph
->pixel_width
;
10624 string_before_pos
= last_pos
;
10625 string_start
= glyph
;
10626 string_start_x
= x
;
10627 /* Skip all glyphs from string. */
10628 SKIP_GLYPHS (glyph
, end
, x
, STRINGP (glyph
->object
));
10633 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
10635 /* We may have skipped over point because the previous glyphs
10636 are from string. As there's no easy way to know the
10637 character position of the current glyph, find the correct
10638 glyph on point by scanning from string_start again. */
10640 Lisp_Object string
;
10643 limit
= make_number (pt_old
+ 1);
10645 glyph
= string_start
;
10646 x
= string_start_x
;
10647 string
= glyph
->object
;
10648 pos
= string_buffer_position (w
, string
, string_before_pos
);
10649 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
10650 because we always put cursor after overlay strings. */
10651 while (pos
== 0 && glyph
< end
)
10653 string
= glyph
->object
;
10654 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10656 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
10659 while (glyph
< end
)
10661 pos
= XINT (Fnext_single_char_property_change
10662 (make_number (pos
), Qdisplay
, Qnil
, limit
));
10665 /* Skip glyphs from the same string. */
10666 string
= glyph
->object
;
10667 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10668 /* Skip glyphs from an overlay. */
10670 && ! string_buffer_position (w
, glyph
->object
, pos
))
10672 string
= glyph
->object
;
10673 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10678 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
10680 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
10681 w
->cursor
.y
= row
->y
+ dy
;
10683 if (w
== XWINDOW (selected_window
))
10685 if (!row
->continued_p
10686 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
10689 this_line_buffer
= XBUFFER (w
->buffer
);
10691 CHARPOS (this_line_start_pos
)
10692 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
10693 BYTEPOS (this_line_start_pos
)
10694 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
10696 CHARPOS (this_line_end_pos
)
10697 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
10698 BYTEPOS (this_line_end_pos
)
10699 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
10701 this_line_y
= w
->cursor
.y
;
10702 this_line_pixel_height
= row
->height
;
10703 this_line_vpos
= w
->cursor
.vpos
;
10704 this_line_start_x
= row
->x
;
10707 CHARPOS (this_line_start_pos
) = 0;
10712 /* Run window scroll functions, if any, for WINDOW with new window
10713 start STARTP. Sets the window start of WINDOW to that position.
10715 We assume that the window's buffer is really current. */
10717 static INLINE
struct text_pos
10718 run_window_scroll_functions (window
, startp
)
10719 Lisp_Object window
;
10720 struct text_pos startp
;
10722 struct window
*w
= XWINDOW (window
);
10723 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
10725 if (current_buffer
!= XBUFFER (w
->buffer
))
10728 if (!NILP (Vwindow_scroll_functions
))
10730 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
10731 make_number (CHARPOS (startp
)));
10732 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10733 /* In case the hook functions switch buffers. */
10734 if (current_buffer
!= XBUFFER (w
->buffer
))
10735 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10742 /* Make sure the line containing the cursor is fully visible.
10743 A value of 1 means there is nothing to be done.
10744 (Either the line is fully visible, or it cannot be made so,
10745 or we cannot tell.)
10746 A value of 0 means the caller should do scrolling
10747 as if point had gone off the screen. */
10750 make_cursor_line_fully_visible (w
)
10753 struct glyph_matrix
*matrix
;
10754 struct glyph_row
*row
;
10757 /* It's not always possible to find the cursor, e.g, when a window
10758 is full of overlay strings. Don't do anything in that case. */
10759 if (w
->cursor
.vpos
< 0)
10762 matrix
= w
->desired_matrix
;
10763 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
10765 /* If the cursor row is not partially visible, there's nothing to do. */
10766 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
10769 /* If the row the cursor is in is taller than the window's height,
10770 it's not clear what to do, so do nothing. */
10771 window_height
= window_box_height (w
);
10772 if (row
->height
>= window_height
)
10778 /* This code used to try to scroll the window just enough to make
10779 the line visible. It returned 0 to say that the caller should
10780 allocate larger glyph matrices. */
10782 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
10784 int dy
= row
->height
- row
->visible_height
;
10787 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
10789 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
10791 int dy
= - (row
->height
- row
->visible_height
);
10794 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
10797 /* When we change the cursor y-position of the selected window,
10798 change this_line_y as well so that the display optimization for
10799 the cursor line of the selected window in redisplay_internal uses
10800 the correct y-position. */
10801 if (w
== XWINDOW (selected_window
))
10802 this_line_y
= w
->cursor
.y
;
10804 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
10805 redisplay with larger matrices. */
10806 if (matrix
->nrows
< required_matrix_height (w
))
10808 fonts_changed_p
= 1;
10817 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
10818 non-zero means only WINDOW is redisplayed in redisplay_internal.
10819 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
10820 in redisplay_window to bring a partially visible line into view in
10821 the case that only the cursor has moved.
10823 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
10824 last screen line's vertical height extends past the end of the screen.
10828 1 if scrolling succeeded
10830 0 if scrolling didn't find point.
10832 -1 if new fonts have been loaded so that we must interrupt
10833 redisplay, adjust glyph matrices, and try again. */
10839 SCROLLING_NEED_LARGER_MATRICES
10843 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
10844 scroll_step
, temp_scroll_step
, last_line_misfit
)
10845 Lisp_Object window
;
10846 int just_this_one_p
;
10847 EMACS_INT scroll_conservatively
, scroll_step
;
10848 int temp_scroll_step
;
10849 int last_line_misfit
;
10851 struct window
*w
= XWINDOW (window
);
10852 struct frame
*f
= XFRAME (w
->frame
);
10853 struct text_pos scroll_margin_pos
;
10854 struct text_pos pos
;
10855 struct text_pos startp
;
10857 Lisp_Object window_end
;
10858 int this_scroll_margin
;
10862 int amount_to_scroll
= 0;
10863 Lisp_Object aggressive
;
10865 int end_scroll_margin
;
10868 debug_method_add (w
, "try_scrolling");
10871 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10873 /* Compute scroll margin height in pixels. We scroll when point is
10874 within this distance from the top or bottom of the window. */
10875 if (scroll_margin
> 0)
10877 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
10878 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
10881 this_scroll_margin
= 0;
10883 /* Compute how much we should try to scroll maximally to bring point
10885 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
10886 scroll_max
= max (scroll_step
,
10887 max (scroll_conservatively
, temp_scroll_step
));
10888 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
10889 || NUMBERP (current_buffer
->scroll_up_aggressively
))
10890 /* We're trying to scroll because of aggressive scrolling
10891 but no scroll_step is set. Choose an arbitrary one. Maybe
10892 there should be a variable for this. */
10896 scroll_max
*= FRAME_LINE_HEIGHT (f
);
10898 /* Decide whether we have to scroll down. Start at the window end
10899 and move this_scroll_margin up to find the position of the scroll
10901 window_end
= Fwindow_end (window
, Qt
);
10905 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
10906 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
10908 end_scroll_margin
= this_scroll_margin
+ !!last_line_misfit
;
10909 if (end_scroll_margin
)
10911 start_display (&it
, w
, scroll_margin_pos
);
10912 move_it_vertically (&it
, - end_scroll_margin
);
10913 scroll_margin_pos
= it
.current
.pos
;
10916 if (PT
>= CHARPOS (scroll_margin_pos
))
10920 /* Point is in the scroll margin at the bottom of the window, or
10921 below. Compute a new window start that makes point visible. */
10923 /* Compute the distance from the scroll margin to PT.
10924 Give up if the distance is greater than scroll_max. */
10925 start_display (&it
, w
, scroll_margin_pos
);
10927 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10928 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10930 /* To make point visible, we have to move the window start
10931 down so that the line the cursor is in is visible, which
10932 means we have to add in the height of the cursor line. */
10933 dy
= line_bottom_y (&it
) - y0
;
10935 if (dy
> scroll_max
)
10936 return SCROLLING_FAILED
;
10938 /* Move the window start down. If scrolling conservatively,
10939 move it just enough down to make point visible. If
10940 scroll_step is set, move it down by scroll_step. */
10941 start_display (&it
, w
, startp
);
10943 if (scroll_conservatively
)
10944 /* Set AMOUNT_TO_SCROLL to at least one line,
10945 and at most scroll_conservatively lines. */
10947 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
10948 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
10949 else if (scroll_step
|| temp_scroll_step
)
10950 amount_to_scroll
= scroll_max
;
10953 aggressive
= current_buffer
->scroll_up_aggressively
;
10954 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
10955 if (NUMBERP (aggressive
))
10956 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
10959 if (amount_to_scroll
<= 0)
10960 return SCROLLING_FAILED
;
10962 /* If moving by amount_to_scroll leaves STARTP unchanged,
10963 move it down one screen line. */
10965 move_it_vertically (&it
, amount_to_scroll
);
10966 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
10967 move_it_by_lines (&it
, 1, 1);
10968 startp
= it
.current
.pos
;
10972 /* See if point is inside the scroll margin at the top of the
10974 scroll_margin_pos
= startp
;
10975 if (this_scroll_margin
)
10977 start_display (&it
, w
, startp
);
10978 move_it_vertically (&it
, this_scroll_margin
);
10979 scroll_margin_pos
= it
.current
.pos
;
10982 if (PT
< CHARPOS (scroll_margin_pos
))
10984 /* Point is in the scroll margin at the top of the window or
10985 above what is displayed in the window. */
10988 /* Compute the vertical distance from PT to the scroll
10989 margin position. Give up if distance is greater than
10991 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
10992 start_display (&it
, w
, pos
);
10994 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
10995 it
.last_visible_y
, -1,
10996 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10997 dy
= it
.current_y
- y0
;
10998 if (dy
> scroll_max
)
10999 return SCROLLING_FAILED
;
11001 /* Compute new window start. */
11002 start_display (&it
, w
, startp
);
11004 if (scroll_conservatively
)
11006 max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11007 else if (scroll_step
|| temp_scroll_step
)
11008 amount_to_scroll
= scroll_max
;
11011 aggressive
= current_buffer
->scroll_down_aggressively
;
11012 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11013 if (NUMBERP (aggressive
))
11014 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
11017 if (amount_to_scroll
<= 0)
11018 return SCROLLING_FAILED
;
11020 move_it_vertically (&it
, - amount_to_scroll
);
11021 startp
= it
.current
.pos
;
11025 /* Run window scroll functions. */
11026 startp
= run_window_scroll_functions (window
, startp
);
11028 /* Display the window. Give up if new fonts are loaded, or if point
11030 if (!try_window (window
, startp
))
11031 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11032 else if (w
->cursor
.vpos
< 0)
11034 clear_glyph_matrix (w
->desired_matrix
);
11035 rc
= SCROLLING_FAILED
;
11039 /* Maybe forget recorded base line for line number display. */
11040 if (!just_this_one_p
11041 || current_buffer
->clip_changed
11042 || BEG_UNCHANGED
< CHARPOS (startp
))
11043 w
->base_line_number
= Qnil
;
11045 /* If cursor ends up on a partially visible line,
11046 treat that as being off the bottom of the screen. */
11047 if (! make_cursor_line_fully_visible (w
))
11049 clear_glyph_matrix (w
->desired_matrix
);
11050 last_line_misfit
= 1;
11053 rc
= SCROLLING_SUCCESS
;
11060 /* Compute a suitable window start for window W if display of W starts
11061 on a continuation line. Value is non-zero if a new window start
11064 The new window start will be computed, based on W's width, starting
11065 from the start of the continued line. It is the start of the
11066 screen line with the minimum distance from the old start W->start. */
11069 compute_window_start_on_continuation_line (w
)
11072 struct text_pos pos
, start_pos
;
11073 int window_start_changed_p
= 0;
11075 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
11077 /* If window start is on a continuation line... Window start may be
11078 < BEGV in case there's invisible text at the start of the
11079 buffer (M-x rmail, for example). */
11080 if (CHARPOS (start_pos
) > BEGV
11081 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
11084 struct glyph_row
*row
;
11086 /* Handle the case that the window start is out of range. */
11087 if (CHARPOS (start_pos
) < BEGV
)
11088 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
11089 else if (CHARPOS (start_pos
) > ZV
)
11090 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
11092 /* Find the start of the continued line. This should be fast
11093 because scan_buffer is fast (newline cache). */
11094 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
11095 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
11096 row
, DEFAULT_FACE_ID
);
11097 reseat_at_previous_visible_line_start (&it
);
11099 /* If the line start is "too far" away from the window start,
11100 say it takes too much time to compute a new window start. */
11101 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
11102 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
11104 int min_distance
, distance
;
11106 /* Move forward by display lines to find the new window
11107 start. If window width was enlarged, the new start can
11108 be expected to be > the old start. If window width was
11109 decreased, the new window start will be < the old start.
11110 So, we're looking for the display line start with the
11111 minimum distance from the old window start. */
11112 pos
= it
.current
.pos
;
11113 min_distance
= INFINITY
;
11114 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
11115 distance
< min_distance
)
11117 min_distance
= distance
;
11118 pos
= it
.current
.pos
;
11119 move_it_by_lines (&it
, 1, 0);
11122 /* Set the window start there. */
11123 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
11124 window_start_changed_p
= 1;
11128 return window_start_changed_p
;
11132 /* Try cursor movement in case text has not changed in window WINDOW,
11133 with window start STARTP. Value is
11135 CURSOR_MOVEMENT_SUCCESS if successful
11137 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
11139 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
11140 display. *SCROLL_STEP is set to 1, under certain circumstances, if
11141 we want to scroll as if scroll-step were set to 1. See the code.
11143 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
11144 which case we have to abort this redisplay, and adjust matrices
11149 CURSOR_MOVEMENT_SUCCESS
,
11150 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11151 CURSOR_MOVEMENT_MUST_SCROLL
,
11152 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11156 try_cursor_movement (window
, startp
, scroll_step
)
11157 Lisp_Object window
;
11158 struct text_pos startp
;
11161 struct window
*w
= XWINDOW (window
);
11162 struct frame
*f
= XFRAME (w
->frame
);
11163 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11166 if (inhibit_try_cursor_movement
)
11170 /* Handle case where text has not changed, only point, and it has
11171 not moved off the frame. */
11172 if (/* Point may be in this window. */
11173 PT
>= CHARPOS (startp
)
11174 /* Selective display hasn't changed. */
11175 && !current_buffer
->clip_changed
11176 /* Function force-mode-line-update is used to force a thorough
11177 redisplay. It sets either windows_or_buffers_changed or
11178 update_mode_lines. So don't take a shortcut here for these
11180 && !update_mode_lines
11181 && !windows_or_buffers_changed
11182 && !cursor_type_changed
11183 /* Can't use this case if highlighting a region. When a
11184 region exists, cursor movement has to do more than just
11186 && !(!NILP (Vtransient_mark_mode
)
11187 && !NILP (current_buffer
->mark_active
))
11188 && NILP (w
->region_showing
)
11189 && NILP (Vshow_trailing_whitespace
)
11190 /* Right after splitting windows, last_point may be nil. */
11191 && INTEGERP (w
->last_point
)
11192 /* This code is not used for mini-buffer for the sake of the case
11193 of redisplaying to replace an echo area message; since in
11194 that case the mini-buffer contents per se are usually
11195 unchanged. This code is of no real use in the mini-buffer
11196 since the handling of this_line_start_pos, etc., in redisplay
11197 handles the same cases. */
11198 && !EQ (window
, minibuf_window
)
11199 /* When splitting windows or for new windows, it happens that
11200 redisplay is called with a nil window_end_vpos or one being
11201 larger than the window. This should really be fixed in
11202 window.c. I don't have this on my list, now, so we do
11203 approximately the same as the old redisplay code. --gerd. */
11204 && INTEGERP (w
->window_end_vpos
)
11205 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11206 && (FRAME_WINDOW_P (f
)
11207 || !MARKERP (Voverlay_arrow_position
)
11208 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
11210 int this_scroll_margin
;
11211 struct glyph_row
*row
= NULL
;
11214 debug_method_add (w
, "cursor movement");
11217 /* Scroll if point within this distance from the top or bottom
11218 of the window. This is a pixel value. */
11219 this_scroll_margin
= max (0, scroll_margin
);
11220 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11221 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11223 /* Start with the row the cursor was displayed during the last
11224 not paused redisplay. Give up if that row is not valid. */
11225 if (w
->last_cursor
.vpos
< 0
11226 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11227 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11230 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11231 if (row
->mode_line_p
)
11233 if (!row
->enabled_p
)
11234 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11237 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11240 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11242 if (PT
> XFASTINT (w
->last_point
))
11244 /* Point has moved forward. */
11245 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11246 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11248 xassert (row
->enabled_p
);
11252 /* The end position of a row equals the start position
11253 of the next row. If PT is there, we would rather
11254 display it in the next line. */
11255 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11256 && MATRIX_ROW_END_CHARPOS (row
) == PT
11257 && !cursor_row_p (w
, row
))
11260 /* If within the scroll margin, scroll. Note that
11261 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11262 the next line would be drawn, and that
11263 this_scroll_margin can be zero. */
11264 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11265 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11266 /* Line is completely visible last line in window
11267 and PT is to be set in the next line. */
11268 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11269 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11270 && !row
->ends_at_zv_p
11271 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11274 else if (PT
< XFASTINT (w
->last_point
))
11276 /* Cursor has to be moved backward. Note that PT >=
11277 CHARPOS (startp) because of the outer
11279 while (!row
->mode_line_p
11280 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11281 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11282 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
11283 && (row
->y
> this_scroll_margin
11284 || CHARPOS (startp
) == BEGV
))
11286 xassert (row
->enabled_p
);
11290 /* Consider the following case: Window starts at BEGV,
11291 there is invisible, intangible text at BEGV, so that
11292 display starts at some point START > BEGV. It can
11293 happen that we are called with PT somewhere between
11294 BEGV and START. Try to handle that case. */
11295 if (row
< w
->current_matrix
->rows
11296 || row
->mode_line_p
)
11298 row
= w
->current_matrix
->rows
;
11299 if (row
->mode_line_p
)
11303 /* Due to newlines in overlay strings, we may have to
11304 skip forward over overlay strings. */
11305 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11306 && MATRIX_ROW_END_CHARPOS (row
) == PT
11307 && !cursor_row_p (w
, row
))
11310 /* If within the scroll margin, scroll. */
11311 if (row
->y
< this_scroll_margin
11312 && CHARPOS (startp
) != BEGV
)
11316 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
11317 || PT
> MATRIX_ROW_END_CHARPOS (row
))
11319 /* if PT is not in the glyph row, give up. */
11320 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11322 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
11324 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
11325 && !row
->ends_at_zv_p
11326 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11327 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11328 else if (row
->height
> window_box_height (w
))
11330 /* If we end up in a partially visible line, let's
11331 make it fully visible, except when it's taller
11332 than the window, in which case we can't do much
11335 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11339 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11340 if (!make_cursor_line_fully_visible (w
))
11341 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11343 rc
= CURSOR_MOVEMENT_SUCCESS
;
11347 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11350 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11351 rc
= CURSOR_MOVEMENT_SUCCESS
;
11360 set_vertical_scroll_bar (w
)
11363 int start
, end
, whole
;
11365 /* Calculate the start and end positions for the current window.
11366 At some point, it would be nice to choose between scrollbars
11367 which reflect the whole buffer size, with special markers
11368 indicating narrowing, and scrollbars which reflect only the
11371 Note that mini-buffers sometimes aren't displaying any text. */
11372 if (!MINI_WINDOW_P (w
)
11373 || (w
== XWINDOW (minibuf_window
)
11374 && NILP (echo_area_buffer
[0])))
11376 struct buffer
*buf
= XBUFFER (w
->buffer
);
11377 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
11378 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
11379 /* I don't think this is guaranteed to be right. For the
11380 moment, we'll pretend it is. */
11381 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
11385 if (whole
< (end
- start
))
11386 whole
= end
- start
;
11389 start
= end
= whole
= 0;
11391 /* Indicate what this scroll bar ought to be displaying now. */
11392 if (FRAME_DISPLAY (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
11393 (*FRAME_DISPLAY (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
11394 (w
, end
- start
, whole
, start
);
11397 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
11398 selected_window is redisplayed.
11400 We can return without actually redisplaying the window if
11401 fonts_changed_p is nonzero. In that case, redisplay_internal will
11405 redisplay_window (window
, just_this_one_p
)
11406 Lisp_Object window
;
11407 int just_this_one_p
;
11409 struct window
*w
= XWINDOW (window
);
11410 struct frame
*f
= XFRAME (w
->frame
);
11411 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11412 struct buffer
*old
= current_buffer
;
11413 struct text_pos lpoint
, opoint
, startp
;
11414 int update_mode_line
;
11417 /* Record it now because it's overwritten. */
11418 int current_matrix_up_to_date_p
= 0;
11419 /* This is less strict than current_matrix_up_to_date_p.
11420 It indictes that the buffer contents and narrowing are unchanged. */
11421 int buffer_unchanged_p
= 0;
11422 int temp_scroll_step
= 0;
11423 int count
= SPECPDL_INDEX ();
11425 int centering_position
;
11426 int last_line_misfit
= 0;
11428 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11431 /* W must be a leaf window here. */
11432 xassert (!NILP (w
->buffer
));
11434 *w
->desired_matrix
->method
= 0;
11437 specbind (Qinhibit_point_motion_hooks
, Qt
);
11439 reconsider_clip_changes (w
, buffer
);
11441 /* Has the mode line to be updated? */
11442 update_mode_line
= (!NILP (w
->update_mode_line
)
11443 || update_mode_lines
11444 || buffer
->clip_changed
11445 || buffer
->prevent_redisplay_optimizations_p
);
11447 if (MINI_WINDOW_P (w
))
11449 if (w
== XWINDOW (echo_area_window
)
11450 && !NILP (echo_area_buffer
[0]))
11452 if (update_mode_line
)
11453 /* We may have to update a tty frame's menu bar or a
11454 tool-bar. Example `M-x C-h C-h C-g'. */
11455 goto finish_menu_bars
;
11457 /* We've already displayed the echo area glyphs in this window. */
11458 goto finish_scroll_bars
;
11460 else if ((w
!= XWINDOW (minibuf_window
)
11461 || minibuf_level
== 0)
11462 /* When buffer is nonempty, redisplay window normally. */
11463 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
11464 /* Quail displays non-mini buffers in minibuffer window.
11465 In that case, redisplay the window normally. */
11466 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
11468 /* W is a mini-buffer window, but it's not active, so clear
11470 int yb
= window_text_bottom_y (w
);
11471 struct glyph_row
*row
;
11474 for (y
= 0, row
= w
->desired_matrix
->rows
;
11476 y
+= row
->height
, ++row
)
11477 blank_row (w
, row
, y
);
11478 goto finish_scroll_bars
;
11481 clear_glyph_matrix (w
->desired_matrix
);
11484 /* Otherwise set up data on this window; select its buffer and point
11486 /* Really select the buffer, for the sake of buffer-local
11488 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11489 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
11491 current_matrix_up_to_date_p
11492 = (!NILP (w
->window_end_valid
)
11493 && !current_buffer
->clip_changed
11494 && !current_buffer
->prevent_redisplay_optimizations_p
11495 && XFASTINT (w
->last_modified
) >= MODIFF
11496 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11499 = (!NILP (w
->window_end_valid
)
11500 && !current_buffer
->clip_changed
11501 && XFASTINT (w
->last_modified
) >= MODIFF
11502 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11504 /* When windows_or_buffers_changed is non-zero, we can't rely on
11505 the window end being valid, so set it to nil there. */
11506 if (windows_or_buffers_changed
)
11508 /* If window starts on a continuation line, maybe adjust the
11509 window start in case the window's width changed. */
11510 if (XMARKER (w
->start
)->buffer
== current_buffer
)
11511 compute_window_start_on_continuation_line (w
);
11513 w
->window_end_valid
= Qnil
;
11516 /* Some sanity checks. */
11517 CHECK_WINDOW_END (w
);
11518 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
11520 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
11523 /* If %c is in mode line, update it if needed. */
11524 if (!NILP (w
->column_number_displayed
)
11525 /* This alternative quickly identifies a common case
11526 where no change is needed. */
11527 && !(PT
== XFASTINT (w
->last_point
)
11528 && XFASTINT (w
->last_modified
) >= MODIFF
11529 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11530 && (XFASTINT (w
->column_number_displayed
)
11531 != (int) current_column ())) /* iftc */
11532 update_mode_line
= 1;
11534 /* Count number of windows showing the selected buffer. An indirect
11535 buffer counts as its base buffer. */
11536 if (!just_this_one_p
)
11538 struct buffer
*current_base
, *window_base
;
11539 current_base
= current_buffer
;
11540 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11541 if (current_base
->base_buffer
)
11542 current_base
= current_base
->base_buffer
;
11543 if (window_base
->base_buffer
)
11544 window_base
= window_base
->base_buffer
;
11545 if (current_base
== window_base
)
11549 /* Point refers normally to the selected window. For any other
11550 window, set up appropriate value. */
11551 if (!EQ (window
, selected_window
))
11553 int new_pt
= XMARKER (w
->pointm
)->charpos
;
11554 int new_pt_byte
= marker_byte_position (w
->pointm
);
11558 new_pt_byte
= BEGV_BYTE
;
11559 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
11561 else if (new_pt
> (ZV
- 1))
11564 new_pt_byte
= ZV_BYTE
;
11565 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
11568 /* We don't use SET_PT so that the point-motion hooks don't run. */
11569 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
11572 /* If any of the character widths specified in the display table
11573 have changed, invalidate the width run cache. It's true that
11574 this may be a bit late to catch such changes, but the rest of
11575 redisplay goes (non-fatally) haywire when the display table is
11576 changed, so why should we worry about doing any better? */
11577 if (current_buffer
->width_run_cache
)
11579 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
11581 if (! disptab_matches_widthtab (disptab
,
11582 XVECTOR (current_buffer
->width_table
)))
11584 invalidate_region_cache (current_buffer
,
11585 current_buffer
->width_run_cache
,
11587 recompute_width_table (current_buffer
, disptab
);
11591 /* If window-start is screwed up, choose a new one. */
11592 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
11595 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11597 /* If someone specified a new starting point but did not insist,
11598 check whether it can be used. */
11599 if (!NILP (w
->optional_new_start
)
11600 && CHARPOS (startp
) >= BEGV
11601 && CHARPOS (startp
) <= ZV
)
11603 w
->optional_new_start
= Qnil
;
11604 start_display (&it
, w
, startp
);
11605 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11606 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11607 if (IT_CHARPOS (it
) == PT
)
11608 w
->force_start
= Qt
;
11609 /* IT may overshoot PT if text at PT is invisible. */
11610 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
11611 w
->force_start
= Qt
;
11616 /* Handle case where place to start displaying has been specified,
11617 unless the specified location is outside the accessible range. */
11618 if (!NILP (w
->force_start
)
11619 || w
->frozen_window_start_p
)
11621 /* We set this later on if we have to adjust point. */
11624 w
->force_start
= Qnil
;
11626 w
->window_end_valid
= Qnil
;
11628 /* Forget any recorded base line for line number display. */
11629 if (!buffer_unchanged_p
)
11630 w
->base_line_number
= Qnil
;
11632 /* Redisplay the mode line. Select the buffer properly for that.
11633 Also, run the hook window-scroll-functions
11634 because we have scrolled. */
11635 /* Note, we do this after clearing force_start because
11636 if there's an error, it is better to forget about force_start
11637 than to get into an infinite loop calling the hook functions
11638 and having them get more errors. */
11639 if (!update_mode_line
11640 || ! NILP (Vwindow_scroll_functions
))
11642 update_mode_line
= 1;
11643 w
->update_mode_line
= Qt
;
11644 startp
= run_window_scroll_functions (window
, startp
);
11647 w
->last_modified
= make_number (0);
11648 w
->last_overlay_modified
= make_number (0);
11649 if (CHARPOS (startp
) < BEGV
)
11650 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
11651 else if (CHARPOS (startp
) > ZV
)
11652 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
11654 /* Redisplay, then check if cursor has been set during the
11655 redisplay. Give up if new fonts were loaded. */
11656 if (!try_window (window
, startp
))
11658 w
->force_start
= Qt
;
11659 clear_glyph_matrix (w
->desired_matrix
);
11660 goto need_larger_matrices
;
11663 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
11665 /* If point does not appear, try to move point so it does
11666 appear. The desired matrix has been built above, so we
11667 can use it here. */
11668 new_vpos
= window_box_height (w
) / 2;
11671 if (!make_cursor_line_fully_visible (w
))
11673 /* Point does appear, but on a line partly visible at end of window.
11674 Move it back to a fully-visible line. */
11675 new_vpos
= window_box_height (w
);
11678 /* If we need to move point for either of the above reasons,
11679 now actually do it. */
11682 struct glyph_row
*row
;
11684 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
11685 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
11688 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
11689 MATRIX_ROW_START_BYTEPOS (row
));
11691 if (w
!= XWINDOW (selected_window
))
11692 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
11693 else if (current_buffer
== old
)
11694 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11696 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
11698 /* If we are highlighting the region, then we just changed
11699 the region, so redisplay to show it. */
11700 if (!NILP (Vtransient_mark_mode
)
11701 && !NILP (current_buffer
->mark_active
))
11703 clear_glyph_matrix (w
->desired_matrix
);
11704 if (!try_window (window
, startp
))
11705 goto need_larger_matrices
;
11710 debug_method_add (w
, "forced window start");
11715 /* Handle case where text has not changed, only point, and it has
11716 not moved off the frame, and we are not retrying after hscroll.
11717 (current_matrix_up_to_date_p is nonzero when retrying.) */
11718 if (current_matrix_up_to_date_p
11719 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
11720 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
11724 case CURSOR_MOVEMENT_SUCCESS
:
11727 #if 0 /* try_cursor_movement never returns this value. */
11728 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
11729 goto need_larger_matrices
;
11732 case CURSOR_MOVEMENT_MUST_SCROLL
:
11733 goto try_to_scroll
;
11739 /* If current starting point was originally the beginning of a line
11740 but no longer is, find a new starting point. */
11741 else if (!NILP (w
->start_at_line_beg
)
11742 && !(CHARPOS (startp
) <= BEGV
11743 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
11746 debug_method_add (w
, "recenter 1");
11751 /* Try scrolling with try_window_id. Value is > 0 if update has
11752 been done, it is -1 if we know that the same window start will
11753 not work. It is 0 if unsuccessful for some other reason. */
11754 else if ((tem
= try_window_id (w
)) != 0)
11757 debug_method_add (w
, "try_window_id %d", tem
);
11760 if (fonts_changed_p
)
11761 goto need_larger_matrices
;
11765 /* Otherwise try_window_id has returned -1 which means that we
11766 don't want the alternative below this comment to execute. */
11768 else if (CHARPOS (startp
) >= BEGV
11769 && CHARPOS (startp
) <= ZV
11770 && PT
>= CHARPOS (startp
)
11771 && (CHARPOS (startp
) < ZV
11772 /* Avoid starting at end of buffer. */
11773 || CHARPOS (startp
) == BEGV
11774 || (XFASTINT (w
->last_modified
) >= MODIFF
11775 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
11778 debug_method_add (w
, "same window start");
11781 /* Try to redisplay starting at same place as before.
11782 If point has not moved off frame, accept the results. */
11783 if (!current_matrix_up_to_date_p
11784 /* Don't use try_window_reusing_current_matrix in this case
11785 because a window scroll function can have changed the
11787 || !NILP (Vwindow_scroll_functions
)
11788 || MINI_WINDOW_P (w
)
11789 || !try_window_reusing_current_matrix (w
))
11791 IF_DEBUG (debug_method_add (w
, "1"));
11792 try_window (window
, startp
);
11795 if (fonts_changed_p
)
11796 goto need_larger_matrices
;
11798 if (w
->cursor
.vpos
>= 0)
11800 if (!just_this_one_p
11801 || current_buffer
->clip_changed
11802 || BEG_UNCHANGED
< CHARPOS (startp
))
11803 /* Forget any recorded base line for line number display. */
11804 w
->base_line_number
= Qnil
;
11806 if (!make_cursor_line_fully_visible (w
))
11808 clear_glyph_matrix (w
->desired_matrix
);
11809 last_line_misfit
= 1;
11811 /* Drop through and scroll. */
11816 clear_glyph_matrix (w
->desired_matrix
);
11821 w
->last_modified
= make_number (0);
11822 w
->last_overlay_modified
= make_number (0);
11824 /* Redisplay the mode line. Select the buffer properly for that. */
11825 if (!update_mode_line
)
11827 update_mode_line
= 1;
11828 w
->update_mode_line
= Qt
;
11831 /* Try to scroll by specified few lines. */
11832 if ((scroll_conservatively
11834 || temp_scroll_step
11835 || NUMBERP (current_buffer
->scroll_up_aggressively
)
11836 || NUMBERP (current_buffer
->scroll_down_aggressively
))
11837 && !current_buffer
->clip_changed
11838 && CHARPOS (startp
) >= BEGV
11839 && CHARPOS (startp
) <= ZV
)
11841 /* The function returns -1 if new fonts were loaded, 1 if
11842 successful, 0 if not successful. */
11843 int rc
= try_scrolling (window
, just_this_one_p
,
11844 scroll_conservatively
,
11846 temp_scroll_step
, last_line_misfit
);
11849 case SCROLLING_SUCCESS
:
11852 case SCROLLING_NEED_LARGER_MATRICES
:
11853 goto need_larger_matrices
;
11855 case SCROLLING_FAILED
:
11863 /* Finally, just choose place to start which centers point */
11866 centering_position
= window_box_height (w
) / 2;
11869 /* Jump here with centering_position already set to 0. */
11872 debug_method_add (w
, "recenter");
11875 /* w->vscroll = 0; */
11877 /* Forget any previously recorded base line for line number display. */
11878 if (!buffer_unchanged_p
)
11879 w
->base_line_number
= Qnil
;
11881 /* Move backward half the height of the window. */
11882 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
11883 it
.current_y
= it
.last_visible_y
;
11884 move_it_vertically_backward (&it
, centering_position
);
11885 xassert (IT_CHARPOS (it
) >= BEGV
);
11887 /* The function move_it_vertically_backward may move over more
11888 than the specified y-distance. If it->w is small, e.g. a
11889 mini-buffer window, we may end up in front of the window's
11890 display area. Start displaying at the start of the line
11891 containing PT in this case. */
11892 if (it
.current_y
<= 0)
11894 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
11895 move_it_vertically (&it
, 0);
11896 xassert (IT_CHARPOS (it
) <= PT
);
11900 it
.current_x
= it
.hpos
= 0;
11902 /* Set startp here explicitly in case that helps avoid an infinite loop
11903 in case the window-scroll-functions functions get errors. */
11904 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
11906 /* Run scroll hooks. */
11907 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
11909 /* Redisplay the window. */
11910 if (!current_matrix_up_to_date_p
11911 || windows_or_buffers_changed
11912 || cursor_type_changed
11913 /* Don't use try_window_reusing_current_matrix in this case
11914 because it can have changed the buffer. */
11915 || !NILP (Vwindow_scroll_functions
)
11916 || !just_this_one_p
11917 || MINI_WINDOW_P (w
)
11918 || !try_window_reusing_current_matrix (w
))
11919 try_window (window
, startp
);
11921 /* If new fonts have been loaded (due to fontsets), give up. We
11922 have to start a new redisplay since we need to re-adjust glyph
11924 if (fonts_changed_p
)
11925 goto need_larger_matrices
;
11927 /* If cursor did not appear assume that the middle of the window is
11928 in the first line of the window. Do it again with the next line.
11929 (Imagine a window of height 100, displaying two lines of height
11930 60. Moving back 50 from it->last_visible_y will end in the first
11932 if (w
->cursor
.vpos
< 0)
11934 if (!NILP (w
->window_end_valid
)
11935 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
11937 clear_glyph_matrix (w
->desired_matrix
);
11938 move_it_by_lines (&it
, 1, 0);
11939 try_window (window
, it
.current
.pos
);
11941 else if (PT
< IT_CHARPOS (it
))
11943 clear_glyph_matrix (w
->desired_matrix
);
11944 move_it_by_lines (&it
, -1, 0);
11945 try_window (window
, it
.current
.pos
);
11949 /* Not much we can do about it. */
11953 /* Consider the following case: Window starts at BEGV, there is
11954 invisible, intangible text at BEGV, so that display starts at
11955 some point START > BEGV. It can happen that we are called with
11956 PT somewhere between BEGV and START. Try to handle that case. */
11957 if (w
->cursor
.vpos
< 0)
11959 struct glyph_row
*row
= w
->current_matrix
->rows
;
11960 if (row
->mode_line_p
)
11962 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11965 if (!make_cursor_line_fully_visible (w
))
11967 /* If vscroll is enabled, disable it and try again. */
11971 clear_glyph_matrix (w
->desired_matrix
);
11975 /* If centering point failed to make the whole line visible,
11976 put point at the top instead. That has to make the whole line
11977 visible, if it can be done. */
11978 centering_position
= 0;
11984 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11985 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
11986 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
11989 /* Display the mode line, if we must. */
11990 if ((update_mode_line
11991 /* If window not full width, must redo its mode line
11992 if (a) the window to its side is being redone and
11993 (b) we do a frame-based redisplay. This is a consequence
11994 of how inverted lines are drawn in frame-based redisplay. */
11995 || (!just_this_one_p
11996 && !FRAME_WINDOW_P (f
)
11997 && !WINDOW_FULL_WIDTH_P (w
))
11998 /* Line number to display. */
11999 || INTEGERP (w
->base_line_pos
)
12000 /* Column number is displayed and different from the one displayed. */
12001 || (!NILP (w
->column_number_displayed
)
12002 && (XFASTINT (w
->column_number_displayed
)
12003 != (int) current_column ()))) /* iftc */
12004 /* This means that the window has a mode line. */
12005 && (WINDOW_WANTS_MODELINE_P (w
)
12006 || WINDOW_WANTS_HEADER_LINE_P (w
)))
12008 display_mode_lines (w
);
12010 /* If mode line height has changed, arrange for a thorough
12011 immediate redisplay using the correct mode line height. */
12012 if (WINDOW_WANTS_MODELINE_P (w
)
12013 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12015 fonts_changed_p
= 1;
12016 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12017 = DESIRED_MODE_LINE_HEIGHT (w
);
12020 /* If top line height has changed, arrange for a thorough
12021 immediate redisplay using the correct mode line height. */
12022 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12023 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
12025 fonts_changed_p
= 1;
12026 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
12027 = DESIRED_HEADER_LINE_HEIGHT (w
);
12030 if (fonts_changed_p
)
12031 goto need_larger_matrices
;
12034 if (!line_number_displayed
12035 && !BUFFERP (w
->base_line_pos
))
12037 w
->base_line_pos
= Qnil
;
12038 w
->base_line_number
= Qnil
;
12043 /* When we reach a frame's selected window, redo the frame's menu bar. */
12044 if (update_mode_line
12045 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
12047 int redisplay_menu_p
= 0;
12048 int redisplay_tool_bar_p
= 0;
12050 if (FRAME_WINDOW_P (f
))
12052 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
12053 || defined (USE_GTK)
12054 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
12056 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12060 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12062 if (redisplay_menu_p
)
12063 display_menu_bar (w
);
12065 #ifdef HAVE_WINDOW_SYSTEM
12067 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
12069 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
12070 && (FRAME_TOOL_BAR_LINES (f
) > 0
12071 || auto_resize_tool_bars_p
);
12075 if (redisplay_tool_bar_p
)
12076 redisplay_tool_bar (f
);
12080 /* We go to this label, with fonts_changed_p nonzero,
12081 if it is necessary to try again using larger glyph matrices.
12082 We have to redeem the scroll bar even in this case,
12083 because the loop in redisplay_internal expects that. */
12084 need_larger_matrices
:
12086 finish_scroll_bars
:
12088 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
12090 /* Set the thumb's position and size. */
12091 set_vertical_scroll_bar (w
);
12093 /* Note that we actually used the scroll bar attached to this
12094 window, so it shouldn't be deleted at the end of redisplay. */
12095 if (FRAME_DISPLAY (f
)->redeem_scroll_bar_hook
)
12096 (*FRAME_DISPLAY (f
)->redeem_scroll_bar_hook
) (w
);
12099 /* Restore current_buffer and value of point in it. */
12100 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
12101 set_buffer_internal_1 (old
);
12102 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12104 unbind_to (count
, Qnil
);
12108 /* Build the complete desired matrix of WINDOW with a window start
12109 buffer position POS. Value is non-zero if successful. It is zero
12110 if fonts were loaded during redisplay which makes re-adjusting
12111 glyph matrices necessary. */
12114 try_window (window
, pos
)
12115 Lisp_Object window
;
12116 struct text_pos pos
;
12118 struct window
*w
= XWINDOW (window
);
12120 struct glyph_row
*last_text_row
= NULL
;
12122 /* Make POS the new window start. */
12123 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
12125 /* Mark cursor position as unknown. No overlay arrow seen. */
12126 w
->cursor
.vpos
= -1;
12127 overlay_arrow_seen
= 0;
12129 /* Initialize iterator and info to start at POS. */
12130 start_display (&it
, w
, pos
);
12132 /* Display all lines of W. */
12133 while (it
.current_y
< it
.last_visible_y
)
12135 if (display_line (&it
))
12136 last_text_row
= it
.glyph_row
- 1;
12137 if (fonts_changed_p
)
12141 /* If bottom moved off end of frame, change mode line percentage. */
12142 if (XFASTINT (w
->window_end_pos
) <= 0
12143 && Z
!= IT_CHARPOS (it
))
12144 w
->update_mode_line
= Qt
;
12146 /* Set window_end_pos to the offset of the last character displayed
12147 on the window from the end of current_buffer. Set
12148 window_end_vpos to its row number. */
12151 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
12152 w
->window_end_bytepos
12153 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12155 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12157 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12158 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12159 ->displays_text_p
);
12163 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12164 w
->window_end_pos
= make_number (Z
- ZV
);
12165 w
->window_end_vpos
= make_number (0);
12168 /* But that is not valid info until redisplay finishes. */
12169 w
->window_end_valid
= Qnil
;
12175 /************************************************************************
12176 Window redisplay reusing current matrix when buffer has not changed
12177 ************************************************************************/
12179 /* Try redisplay of window W showing an unchanged buffer with a
12180 different window start than the last time it was displayed by
12181 reusing its current matrix. Value is non-zero if successful.
12182 W->start is the new window start. */
12185 try_window_reusing_current_matrix (w
)
12188 struct frame
*f
= XFRAME (w
->frame
);
12189 struct glyph_row
*row
, *bottom_row
;
12192 struct text_pos start
, new_start
;
12193 int nrows_scrolled
, i
;
12194 struct glyph_row
*last_text_row
;
12195 struct glyph_row
*last_reused_text_row
;
12196 struct glyph_row
*start_row
;
12197 int start_vpos
, min_y
, max_y
;
12200 if (inhibit_try_window_reusing
)
12204 if (/* This function doesn't handle terminal frames. */
12205 !FRAME_WINDOW_P (f
)
12206 /* Don't try to reuse the display if windows have been split
12208 || windows_or_buffers_changed
12209 || cursor_type_changed
)
12212 /* Can't do this if region may have changed. */
12213 if ((!NILP (Vtransient_mark_mode
)
12214 && !NILP (current_buffer
->mark_active
))
12215 || !NILP (w
->region_showing
)
12216 || !NILP (Vshow_trailing_whitespace
))
12219 /* If top-line visibility has changed, give up. */
12220 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12221 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12224 /* Give up if old or new display is scrolled vertically. We could
12225 make this function handle this, but right now it doesn't. */
12226 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12227 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
12230 /* The variable new_start now holds the new window start. The old
12231 start `start' can be determined from the current matrix. */
12232 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
12233 start
= start_row
->start
.pos
;
12234 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12236 /* Clear the desired matrix for the display below. */
12237 clear_glyph_matrix (w
->desired_matrix
);
12239 if (CHARPOS (new_start
) <= CHARPOS (start
))
12243 /* Don't use this method if the display starts with an ellipsis
12244 displayed for invisible text. It's not easy to handle that case
12245 below, and it's certainly not worth the effort since this is
12246 not a frequent case. */
12247 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
12250 IF_DEBUG (debug_method_add (w
, "twu1"));
12252 /* Display up to a row that can be reused. The variable
12253 last_text_row is set to the last row displayed that displays
12254 text. Note that it.vpos == 0 if or if not there is a
12255 header-line; it's not the same as the MATRIX_ROW_VPOS! */
12256 start_display (&it
, w
, new_start
);
12257 first_row_y
= it
.current_y
;
12258 w
->cursor
.vpos
= -1;
12259 last_text_row
= last_reused_text_row
= NULL
;
12261 while (it
.current_y
< it
.last_visible_y
12262 && IT_CHARPOS (it
) < CHARPOS (start
)
12263 && !fonts_changed_p
)
12264 if (display_line (&it
))
12265 last_text_row
= it
.glyph_row
- 1;
12267 /* A value of current_y < last_visible_y means that we stopped
12268 at the previous window start, which in turn means that we
12269 have at least one reusable row. */
12270 if (it
.current_y
< it
.last_visible_y
)
12272 /* IT.vpos always starts from 0; it counts text lines. */
12273 nrows_scrolled
= it
.vpos
;
12275 /* Find PT if not already found in the lines displayed. */
12276 if (w
->cursor
.vpos
< 0)
12278 int dy
= it
.current_y
- first_row_y
;
12280 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12281 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
12283 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
12284 dy
, nrows_scrolled
);
12287 clear_glyph_matrix (w
->desired_matrix
);
12292 /* Scroll the display. Do it before the current matrix is
12293 changed. The problem here is that update has not yet
12294 run, i.e. part of the current matrix is not up to date.
12295 scroll_run_hook will clear the cursor, and use the
12296 current matrix to get the height of the row the cursor is
12298 run
.current_y
= first_row_y
;
12299 run
.desired_y
= it
.current_y
;
12300 run
.height
= it
.last_visible_y
- it
.current_y
;
12302 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
12305 FRAME_RIF (f
)->update_window_begin_hook (w
);
12306 FRAME_RIF (f
)->clear_window_mouse_face (w
);
12307 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
12308 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
12312 /* Shift current matrix down by nrows_scrolled lines. */
12313 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12314 rotate_matrix (w
->current_matrix
,
12316 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12319 /* Disable lines that must be updated. */
12320 for (i
= 0; i
< it
.vpos
; ++i
)
12321 (start_row
+ i
)->enabled_p
= 0;
12323 /* Re-compute Y positions. */
12324 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12325 max_y
= it
.last_visible_y
;
12326 for (row
= start_row
+ nrows_scrolled
;
12330 row
->y
= it
.current_y
;
12331 row
->visible_height
= row
->height
;
12333 if (row
->y
< min_y
)
12334 row
->visible_height
-= min_y
- row
->y
;
12335 if (row
->y
+ row
->height
> max_y
)
12336 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12338 it
.current_y
+= row
->height
;
12340 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12341 last_reused_text_row
= row
;
12342 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
12346 /* Disable lines in the current matrix which are now
12347 below the window. */
12348 for (++row
; row
< bottom_row
; ++row
)
12349 row
->enabled_p
= 0;
12352 /* Update window_end_pos etc.; last_reused_text_row is the last
12353 reused row from the current matrix containing text, if any.
12354 The value of last_text_row is the last displayed line
12355 containing text. */
12356 if (last_reused_text_row
)
12358 w
->window_end_bytepos
12359 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
12361 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
12363 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
12364 w
->current_matrix
));
12366 else if (last_text_row
)
12368 w
->window_end_bytepos
12369 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12371 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12373 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12377 /* This window must be completely empty. */
12378 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12379 w
->window_end_pos
= make_number (Z
- ZV
);
12380 w
->window_end_vpos
= make_number (0);
12382 w
->window_end_valid
= Qnil
;
12384 /* Update hint: don't try scrolling again in update_window. */
12385 w
->desired_matrix
->no_scrolling_p
= 1;
12388 debug_method_add (w
, "try_window_reusing_current_matrix 1");
12392 else if (CHARPOS (new_start
) > CHARPOS (start
))
12394 struct glyph_row
*pt_row
, *row
;
12395 struct glyph_row
*first_reusable_row
;
12396 struct glyph_row
*first_row_to_display
;
12398 int yb
= window_text_bottom_y (w
);
12400 /* Find the row starting at new_start, if there is one. Don't
12401 reuse a partially visible line at the end. */
12402 first_reusable_row
= start_row
;
12403 while (first_reusable_row
->enabled_p
12404 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
12405 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12406 < CHARPOS (new_start
)))
12407 ++first_reusable_row
;
12409 /* Give up if there is no row to reuse. */
12410 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
12411 || !first_reusable_row
->enabled_p
12412 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12413 != CHARPOS (new_start
)))
12416 /* We can reuse fully visible rows beginning with
12417 first_reusable_row to the end of the window. Set
12418 first_row_to_display to the first row that cannot be reused.
12419 Set pt_row to the row containing point, if there is any. */
12421 for (first_row_to_display
= first_reusable_row
;
12422 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
12423 ++first_row_to_display
)
12425 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
12426 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
12427 pt_row
= first_row_to_display
;
12430 /* Start displaying at the start of first_row_to_display. */
12431 xassert (first_row_to_display
->y
< yb
);
12432 init_to_row_start (&it
, w
, first_row_to_display
);
12434 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
12436 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
12438 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
12439 + WINDOW_HEADER_LINE_HEIGHT (w
));
12441 /* Display lines beginning with first_row_to_display in the
12442 desired matrix. Set last_text_row to the last row displayed
12443 that displays text. */
12444 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
12445 if (pt_row
== NULL
)
12446 w
->cursor
.vpos
= -1;
12447 last_text_row
= NULL
;
12448 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
12449 if (display_line (&it
))
12450 last_text_row
= it
.glyph_row
- 1;
12452 /* Give up If point isn't in a row displayed or reused. */
12453 if (w
->cursor
.vpos
< 0)
12455 clear_glyph_matrix (w
->desired_matrix
);
12459 /* If point is in a reused row, adjust y and vpos of the cursor
12463 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
12464 w
->current_matrix
);
12465 w
->cursor
.y
-= first_reusable_row
->y
;
12468 /* Scroll the display. */
12469 run
.current_y
= first_reusable_row
->y
;
12470 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12471 run
.height
= it
.last_visible_y
- run
.current_y
;
12472 dy
= run
.current_y
- run
.desired_y
;
12476 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12478 FRAME_RIF (f
)->update_window_begin_hook (w
);
12479 FRAME_RIF (f
)->clear_window_mouse_face (w
);
12480 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
12481 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
12485 /* Adjust Y positions of reused rows. */
12486 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12487 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12488 max_y
= it
.last_visible_y
;
12489 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
12492 row
->visible_height
= row
->height
;
12493 if (row
->y
< min_y
)
12494 row
->visible_height
-= min_y
- row
->y
;
12495 if (row
->y
+ row
->height
> max_y
)
12496 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12499 /* Scroll the current matrix. */
12500 xassert (nrows_scrolled
> 0);
12501 rotate_matrix (w
->current_matrix
,
12503 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12506 /* Disable rows not reused. */
12507 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
12508 row
->enabled_p
= 0;
12510 /* Adjust window end. A null value of last_text_row means that
12511 the window end is in reused rows which in turn means that
12512 only its vpos can have changed. */
12515 w
->window_end_bytepos
12516 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12518 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12520 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12525 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
12528 w
->window_end_valid
= Qnil
;
12529 w
->desired_matrix
->no_scrolling_p
= 1;
12532 debug_method_add (w
, "try_window_reusing_current_matrix 2");
12542 /************************************************************************
12543 Window redisplay reusing current matrix when buffer has changed
12544 ************************************************************************/
12546 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
12547 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
12549 static struct glyph_row
*
12550 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
12551 struct glyph_row
*));
12554 /* Return the last row in MATRIX displaying text. If row START is
12555 non-null, start searching with that row. IT gives the dimensions
12556 of the display. Value is null if matrix is empty; otherwise it is
12557 a pointer to the row found. */
12559 static struct glyph_row
*
12560 find_last_row_displaying_text (matrix
, it
, start
)
12561 struct glyph_matrix
*matrix
;
12563 struct glyph_row
*start
;
12565 struct glyph_row
*row
, *row_found
;
12567 /* Set row_found to the last row in IT->w's current matrix
12568 displaying text. The loop looks funny but think of partially
12571 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
12572 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12574 xassert (row
->enabled_p
);
12576 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
12585 /* Return the last row in the current matrix of W that is not affected
12586 by changes at the start of current_buffer that occurred since W's
12587 current matrix was built. Value is null if no such row exists.
12589 BEG_UNCHANGED us the number of characters unchanged at the start of
12590 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
12591 first changed character in current_buffer. Characters at positions <
12592 BEG + BEG_UNCHANGED are at the same buffer positions as they were
12593 when the current matrix was built. */
12595 static struct glyph_row
*
12596 find_last_unchanged_at_beg_row (w
)
12599 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
12600 struct glyph_row
*row
;
12601 struct glyph_row
*row_found
= NULL
;
12602 int yb
= window_text_bottom_y (w
);
12604 /* Find the last row displaying unchanged text. */
12605 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12606 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12607 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
12609 if (/* If row ends before first_changed_pos, it is unchanged,
12610 except in some case. */
12611 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
12612 /* When row ends in ZV and we write at ZV it is not
12614 && !row
->ends_at_zv_p
12615 /* When first_changed_pos is the end of a continued line,
12616 row is not unchanged because it may be no longer
12618 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
12619 && row
->continued_p
))
12622 /* Stop if last visible row. */
12623 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
12633 /* Find the first glyph row in the current matrix of W that is not
12634 affected by changes at the end of current_buffer since the
12635 time W's current matrix was built.
12637 Return in *DELTA the number of chars by which buffer positions in
12638 unchanged text at the end of current_buffer must be adjusted.
12640 Return in *DELTA_BYTES the corresponding number of bytes.
12642 Value is null if no such row exists, i.e. all rows are affected by
12645 static struct glyph_row
*
12646 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
12648 int *delta
, *delta_bytes
;
12650 struct glyph_row
*row
;
12651 struct glyph_row
*row_found
= NULL
;
12653 *delta
= *delta_bytes
= 0;
12655 /* Display must not have been paused, otherwise the current matrix
12656 is not up to date. */
12657 if (NILP (w
->window_end_valid
))
12660 /* A value of window_end_pos >= END_UNCHANGED means that the window
12661 end is in the range of changed text. If so, there is no
12662 unchanged row at the end of W's current matrix. */
12663 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
12666 /* Set row to the last row in W's current matrix displaying text. */
12667 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
12669 /* If matrix is entirely empty, no unchanged row exists. */
12670 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12672 /* The value of row is the last glyph row in the matrix having a
12673 meaningful buffer position in it. The end position of row
12674 corresponds to window_end_pos. This allows us to translate
12675 buffer positions in the current matrix to current buffer
12676 positions for characters not in changed text. */
12677 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
12678 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
12679 int last_unchanged_pos
, last_unchanged_pos_old
;
12680 struct glyph_row
*first_text_row
12681 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12683 *delta
= Z
- Z_old
;
12684 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
12686 /* Set last_unchanged_pos to the buffer position of the last
12687 character in the buffer that has not been changed. Z is the
12688 index + 1 of the last character in current_buffer, i.e. by
12689 subtracting END_UNCHANGED we get the index of the last
12690 unchanged character, and we have to add BEG to get its buffer
12692 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
12693 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
12695 /* Search backward from ROW for a row displaying a line that
12696 starts at a minimum position >= last_unchanged_pos_old. */
12697 for (; row
> first_text_row
; --row
)
12699 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12702 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
12707 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
12714 /* Make sure that glyph rows in the current matrix of window W
12715 reference the same glyph memory as corresponding rows in the
12716 frame's frame matrix. This function is called after scrolling W's
12717 current matrix on a terminal frame in try_window_id and
12718 try_window_reusing_current_matrix. */
12721 sync_frame_with_window_matrix_rows (w
)
12724 struct frame
*f
= XFRAME (w
->frame
);
12725 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
12727 /* Preconditions: W must be a leaf window and full-width. Its frame
12728 must have a frame matrix. */
12729 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
12730 xassert (WINDOW_FULL_WIDTH_P (w
));
12731 xassert (!FRAME_WINDOW_P (f
));
12733 /* If W is a full-width window, glyph pointers in W's current matrix
12734 have, by definition, to be the same as glyph pointers in the
12735 corresponding frame matrix. Note that frame matrices have no
12736 marginal areas (see build_frame_matrix). */
12737 window_row
= w
->current_matrix
->rows
;
12738 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
12739 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
12740 while (window_row
< window_row_end
)
12742 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
12743 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
12745 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
12746 frame_row
->glyphs
[TEXT_AREA
] = start
;
12747 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
12748 frame_row
->glyphs
[LAST_AREA
] = end
;
12750 /* Disable frame rows whose corresponding window rows have
12751 been disabled in try_window_id. */
12752 if (!window_row
->enabled_p
)
12753 frame_row
->enabled_p
= 0;
12755 ++window_row
, ++frame_row
;
12760 /* Find the glyph row in window W containing CHARPOS. Consider all
12761 rows between START and END (not inclusive). END null means search
12762 all rows to the end of the display area of W. Value is the row
12763 containing CHARPOS or null. */
12766 row_containing_pos (w
, charpos
, start
, end
, dy
)
12769 struct glyph_row
*start
, *end
;
12772 struct glyph_row
*row
= start
;
12775 /* If we happen to start on a header-line, skip that. */
12776 if (row
->mode_line_p
)
12779 if ((end
&& row
>= end
) || !row
->enabled_p
)
12782 last_y
= window_text_bottom_y (w
) - dy
;
12786 /* Give up if we have gone too far. */
12787 if (end
&& row
>= end
)
12789 /* This formerly returned if they were equal.
12790 I think that both quantities are of a "last plus one" type;
12791 if so, when they are equal, the row is within the screen. -- rms. */
12792 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
12795 /* If it is in this row, return this row. */
12796 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
12797 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
12798 /* The end position of a row equals the start
12799 position of the next row. If CHARPOS is there, we
12800 would rather display it in the next line, except
12801 when this line ends in ZV. */
12802 && !row
->ends_at_zv_p
12803 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12804 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
12811 /* Try to redisplay window W by reusing its existing display. W's
12812 current matrix must be up to date when this function is called,
12813 i.e. window_end_valid must not be nil.
12817 1 if display has been updated
12818 0 if otherwise unsuccessful
12819 -1 if redisplay with same window start is known not to succeed
12821 The following steps are performed:
12823 1. Find the last row in the current matrix of W that is not
12824 affected by changes at the start of current_buffer. If no such row
12827 2. Find the first row in W's current matrix that is not affected by
12828 changes at the end of current_buffer. Maybe there is no such row.
12830 3. Display lines beginning with the row + 1 found in step 1 to the
12831 row found in step 2 or, if step 2 didn't find a row, to the end of
12834 4. If cursor is not known to appear on the window, give up.
12836 5. If display stopped at the row found in step 2, scroll the
12837 display and current matrix as needed.
12839 6. Maybe display some lines at the end of W, if we must. This can
12840 happen under various circumstances, like a partially visible line
12841 becoming fully visible, or because newly displayed lines are displayed
12842 in smaller font sizes.
12844 7. Update W's window end information. */
12850 struct frame
*f
= XFRAME (w
->frame
);
12851 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
12852 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
12853 struct glyph_row
*last_unchanged_at_beg_row
;
12854 struct glyph_row
*first_unchanged_at_end_row
;
12855 struct glyph_row
*row
;
12856 struct glyph_row
*bottom_row
;
12859 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
12860 struct text_pos start_pos
;
12862 int first_unchanged_at_end_vpos
= 0;
12863 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
12864 struct text_pos start
;
12865 int first_changed_charpos
, last_changed_charpos
;
12868 if (inhibit_try_window_id
)
12872 /* This is handy for debugging. */
12874 #define GIVE_UP(X) \
12876 fprintf (stderr, "try_window_id give up %d\n", (X)); \
12880 #define GIVE_UP(X) return 0
12883 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
12885 /* Don't use this for mini-windows because these can show
12886 messages and mini-buffers, and we don't handle that here. */
12887 if (MINI_WINDOW_P (w
))
12890 /* This flag is used to prevent redisplay optimizations. */
12891 if (windows_or_buffers_changed
|| cursor_type_changed
)
12894 /* Verify that narrowing has not changed.
12895 Also verify that we were not told to prevent redisplay optimizations.
12896 It would be nice to further
12897 reduce the number of cases where this prevents try_window_id. */
12898 if (current_buffer
->clip_changed
12899 || current_buffer
->prevent_redisplay_optimizations_p
)
12902 /* Window must either use window-based redisplay or be full width. */
12903 if (!FRAME_WINDOW_P (f
)
12904 && (!FRAME_LINE_INS_DEL_OK (f
)
12905 || !WINDOW_FULL_WIDTH_P (w
)))
12908 /* Give up if point is not known NOT to appear in W. */
12909 if (PT
< CHARPOS (start
))
12912 /* Another way to prevent redisplay optimizations. */
12913 if (XFASTINT (w
->last_modified
) == 0)
12916 /* Verify that window is not hscrolled. */
12917 if (XFASTINT (w
->hscroll
) != 0)
12920 /* Verify that display wasn't paused. */
12921 if (NILP (w
->window_end_valid
))
12924 /* Can't use this if highlighting a region because a cursor movement
12925 will do more than just set the cursor. */
12926 if (!NILP (Vtransient_mark_mode
)
12927 && !NILP (current_buffer
->mark_active
))
12930 /* Likewise if highlighting trailing whitespace. */
12931 if (!NILP (Vshow_trailing_whitespace
))
12934 /* Likewise if showing a region. */
12935 if (!NILP (w
->region_showing
))
12938 /* Can use this if overlay arrow position and or string have changed. */
12939 if (!EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
12940 || !EQ (last_arrow_string
, Voverlay_arrow_string
))
12944 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
12945 only if buffer has really changed. The reason is that the gap is
12946 initially at Z for freshly visited files. The code below would
12947 set end_unchanged to 0 in that case. */
12948 if (MODIFF
> SAVE_MODIFF
12949 /* This seems to happen sometimes after saving a buffer. */
12950 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
12952 if (GPT
- BEG
< BEG_UNCHANGED
)
12953 BEG_UNCHANGED
= GPT
- BEG
;
12954 if (Z
- GPT
< END_UNCHANGED
)
12955 END_UNCHANGED
= Z
- GPT
;
12958 /* The position of the first and last character that has been changed. */
12959 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
12960 last_changed_charpos
= Z
- END_UNCHANGED
;
12962 /* If window starts after a line end, and the last change is in
12963 front of that newline, then changes don't affect the display.
12964 This case happens with stealth-fontification. Note that although
12965 the display is unchanged, glyph positions in the matrix have to
12966 be adjusted, of course. */
12967 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
12968 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12969 && ((last_changed_charpos
< CHARPOS (start
)
12970 && CHARPOS (start
) == BEGV
)
12971 || (last_changed_charpos
< CHARPOS (start
) - 1
12972 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
12974 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
12975 struct glyph_row
*r0
;
12977 /* Compute how many chars/bytes have been added to or removed
12978 from the buffer. */
12979 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
12980 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
12982 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
12984 /* Give up if PT is not in the window. Note that it already has
12985 been checked at the start of try_window_id that PT is not in
12986 front of the window start. */
12987 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
12990 /* If window start is unchanged, we can reuse the whole matrix
12991 as is, after adjusting glyph positions. No need to compute
12992 the window end again, since its offset from Z hasn't changed. */
12993 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
12994 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
12995 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
12996 /* PT must not be in a partially visible line. */
12997 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
12998 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13000 /* Adjust positions in the glyph matrix. */
13001 if (delta
|| delta_bytes
)
13003 struct glyph_row
*r1
13004 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13005 increment_matrix_positions (w
->current_matrix
,
13006 MATRIX_ROW_VPOS (r0
, current_matrix
),
13007 MATRIX_ROW_VPOS (r1
, current_matrix
),
13008 delta
, delta_bytes
);
13011 /* Set the cursor. */
13012 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13014 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13021 /* Handle the case that changes are all below what is displayed in
13022 the window, and that PT is in the window. This shortcut cannot
13023 be taken if ZV is visible in the window, and text has been added
13024 there that is visible in the window. */
13025 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
13026 /* ZV is not visible in the window, or there are no
13027 changes at ZV, actually. */
13028 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
13029 || first_changed_charpos
== last_changed_charpos
))
13031 struct glyph_row
*r0
;
13033 /* Give up if PT is not in the window. Note that it already has
13034 been checked at the start of try_window_id that PT is not in
13035 front of the window start. */
13036 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
13039 /* If window start is unchanged, we can reuse the whole matrix
13040 as is, without changing glyph positions since no text has
13041 been added/removed in front of the window end. */
13042 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13043 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
13044 /* PT must not be in a partially visible line. */
13045 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
13046 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13048 /* We have to compute the window end anew since text
13049 can have been added/removed after it. */
13051 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13052 w
->window_end_bytepos
13053 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13055 /* Set the cursor. */
13056 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13058 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13065 /* Give up if window start is in the changed area.
13067 The condition used to read
13069 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
13071 but why that was tested escapes me at the moment. */
13072 if (CHARPOS (start
) >= first_changed_charpos
13073 && CHARPOS (start
) <= last_changed_charpos
)
13076 /* Check that window start agrees with the start of the first glyph
13077 row in its current matrix. Check this after we know the window
13078 start is not in changed text, otherwise positions would not be
13080 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13081 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
13084 /* Give up if the window ends in strings. Overlay strings
13085 at the end are difficult to handle, so don't try. */
13086 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
13087 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
13090 /* Compute the position at which we have to start displaying new
13091 lines. Some of the lines at the top of the window might be
13092 reusable because they are not displaying changed text. Find the
13093 last row in W's current matrix not affected by changes at the
13094 start of current_buffer. Value is null if changes start in the
13095 first line of window. */
13096 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
13097 if (last_unchanged_at_beg_row
)
13099 /* Avoid starting to display in the moddle of a character, a TAB
13100 for instance. This is easier than to set up the iterator
13101 exactly, and it's not a frequent case, so the additional
13102 effort wouldn't really pay off. */
13103 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
13104 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
13105 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
13106 --last_unchanged_at_beg_row
;
13108 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
13111 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
13113 start_pos
= it
.current
.pos
;
13115 /* Start displaying new lines in the desired matrix at the same
13116 vpos we would use in the current matrix, i.e. below
13117 last_unchanged_at_beg_row. */
13118 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
13120 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13121 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
13123 xassert (it
.hpos
== 0 && it
.current_x
== 0);
13127 /* There are no reusable lines at the start of the window.
13128 Start displaying in the first text line. */
13129 start_display (&it
, w
, start
);
13130 it
.vpos
= it
.first_vpos
;
13131 start_pos
= it
.current
.pos
;
13134 /* Find the first row that is not affected by changes at the end of
13135 the buffer. Value will be null if there is no unchanged row, in
13136 which case we must redisplay to the end of the window. delta
13137 will be set to the value by which buffer positions beginning with
13138 first_unchanged_at_end_row have to be adjusted due to text
13140 first_unchanged_at_end_row
13141 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
13142 IF_DEBUG (debug_delta
= delta
);
13143 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
13145 /* Set stop_pos to the buffer position up to which we will have to
13146 display new lines. If first_unchanged_at_end_row != NULL, this
13147 is the buffer position of the start of the line displayed in that
13148 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
13149 that we don't stop at a buffer position. */
13151 if (first_unchanged_at_end_row
)
13153 xassert (last_unchanged_at_beg_row
== NULL
13154 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
13156 /* If this is a continuation line, move forward to the next one
13157 that isn't. Changes in lines above affect this line.
13158 Caution: this may move first_unchanged_at_end_row to a row
13159 not displaying text. */
13160 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
13161 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13162 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13163 < it
.last_visible_y
))
13164 ++first_unchanged_at_end_row
;
13166 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13167 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13168 >= it
.last_visible_y
))
13169 first_unchanged_at_end_row
= NULL
;
13172 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13174 first_unchanged_at_end_vpos
13175 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13176 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13179 else if (last_unchanged_at_beg_row
== NULL
)
13185 /* Either there is no unchanged row at the end, or the one we have
13186 now displays text. This is a necessary condition for the window
13187 end pos calculation at the end of this function. */
13188 xassert (first_unchanged_at_end_row
== NULL
13189 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
13191 debug_last_unchanged_at_beg_vpos
13192 = (last_unchanged_at_beg_row
13193 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
13195 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
13197 #endif /* GLYPH_DEBUG != 0 */
13200 /* Display new lines. Set last_text_row to the last new line
13201 displayed which has text on it, i.e. might end up as being the
13202 line where the window_end_vpos is. */
13203 w
->cursor
.vpos
= -1;
13204 last_text_row
= NULL
;
13205 overlay_arrow_seen
= 0;
13206 while (it
.current_y
< it
.last_visible_y
13207 && !fonts_changed_p
13208 && (first_unchanged_at_end_row
== NULL
13209 || IT_CHARPOS (it
) < stop_pos
))
13211 if (display_line (&it
))
13212 last_text_row
= it
.glyph_row
- 1;
13215 if (fonts_changed_p
)
13219 /* Compute differences in buffer positions, y-positions etc. for
13220 lines reused at the bottom of the window. Compute what we can
13222 if (first_unchanged_at_end_row
13223 /* No lines reused because we displayed everything up to the
13224 bottom of the window. */
13225 && it
.current_y
< it
.last_visible_y
)
13228 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
13230 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
13231 run
.current_y
= first_unchanged_at_end_row
->y
;
13232 run
.desired_y
= run
.current_y
+ dy
;
13233 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
13237 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
13238 first_unchanged_at_end_row
= NULL
;
13240 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
13243 /* Find the cursor if not already found. We have to decide whether
13244 PT will appear on this window (it sometimes doesn't, but this is
13245 not a very frequent case.) This decision has to be made before
13246 the current matrix is altered. A value of cursor.vpos < 0 means
13247 that PT is either in one of the lines beginning at
13248 first_unchanged_at_end_row or below the window. Don't care for
13249 lines that might be displayed later at the window end; as
13250 mentioned, this is not a frequent case. */
13251 if (w
->cursor
.vpos
< 0)
13253 /* Cursor in unchanged rows at the top? */
13254 if (PT
< CHARPOS (start_pos
)
13255 && last_unchanged_at_beg_row
)
13257 row
= row_containing_pos (w
, PT
,
13258 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
13259 last_unchanged_at_beg_row
+ 1, 0);
13261 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13264 /* Start from first_unchanged_at_end_row looking for PT. */
13265 else if (first_unchanged_at_end_row
)
13267 row
= row_containing_pos (w
, PT
- delta
,
13268 first_unchanged_at_end_row
, NULL
, 0);
13270 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
13271 delta_bytes
, dy
, dvpos
);
13274 /* Give up if cursor was not found. */
13275 if (w
->cursor
.vpos
< 0)
13277 clear_glyph_matrix (w
->desired_matrix
);
13282 /* Don't let the cursor end in the scroll margins. */
13284 int this_scroll_margin
, cursor_height
;
13286 this_scroll_margin
= max (0, scroll_margin
);
13287 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13288 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13289 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
13291 if ((w
->cursor
.y
< this_scroll_margin
13292 && CHARPOS (start
) > BEGV
)
13293 /* Don't take scroll margin into account at the bottom because
13294 old redisplay didn't do it either. */
13295 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
13297 w
->cursor
.vpos
= -1;
13298 clear_glyph_matrix (w
->desired_matrix
);
13303 /* Scroll the display. Do it before changing the current matrix so
13304 that xterm.c doesn't get confused about where the cursor glyph is
13306 if (dy
&& run
.height
)
13310 if (FRAME_WINDOW_P (f
))
13312 FRAME_RIF (f
)->update_window_begin_hook (w
);
13313 FRAME_RIF (f
)->clear_window_mouse_face (w
);
13314 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
13315 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
13319 /* Terminal frame. In this case, dvpos gives the number of
13320 lines to scroll by; dvpos < 0 means scroll up. */
13321 int first_unchanged_at_end_vpos
13322 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
13323 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
13324 int end
= (WINDOW_TOP_EDGE_LINE (w
)
13325 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
13326 + window_internal_height (w
));
13328 /* Perform the operation on the screen. */
13331 /* Scroll last_unchanged_at_beg_row to the end of the
13332 window down dvpos lines. */
13333 set_terminal_window (end
);
13335 /* On dumb terminals delete dvpos lines at the end
13336 before inserting dvpos empty lines. */
13337 if (!FRAME_SCROLL_REGION_OK (f
))
13338 ins_del_lines (end
- dvpos
, -dvpos
);
13340 /* Insert dvpos empty lines in front of
13341 last_unchanged_at_beg_row. */
13342 ins_del_lines (from
, dvpos
);
13344 else if (dvpos
< 0)
13346 /* Scroll up last_unchanged_at_beg_vpos to the end of
13347 the window to last_unchanged_at_beg_vpos - |dvpos|. */
13348 set_terminal_window (end
);
13350 /* Delete dvpos lines in front of
13351 last_unchanged_at_beg_vpos. ins_del_lines will set
13352 the cursor to the given vpos and emit |dvpos| delete
13354 ins_del_lines (from
+ dvpos
, dvpos
);
13356 /* On a dumb terminal insert dvpos empty lines at the
13358 if (!FRAME_SCROLL_REGION_OK (f
))
13359 ins_del_lines (end
+ dvpos
, -dvpos
);
13362 set_terminal_window (0);
13368 /* Shift reused rows of the current matrix to the right position.
13369 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
13371 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13372 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
13375 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
13376 bottom_vpos
, dvpos
);
13377 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
13380 else if (dvpos
> 0)
13382 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
13383 bottom_vpos
, dvpos
);
13384 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
13385 first_unchanged_at_end_vpos
+ dvpos
, 0);
13388 /* For frame-based redisplay, make sure that current frame and window
13389 matrix are in sync with respect to glyph memory. */
13390 if (!FRAME_WINDOW_P (f
))
13391 sync_frame_with_window_matrix_rows (w
);
13393 /* Adjust buffer positions in reused rows. */
13395 increment_matrix_positions (current_matrix
,
13396 first_unchanged_at_end_vpos
+ dvpos
,
13397 bottom_vpos
, delta
, delta_bytes
);
13399 /* Adjust Y positions. */
13401 shift_glyph_matrix (w
, current_matrix
,
13402 first_unchanged_at_end_vpos
+ dvpos
,
13405 if (first_unchanged_at_end_row
)
13406 first_unchanged_at_end_row
+= dvpos
;
13408 /* If scrolling up, there may be some lines to display at the end of
13410 last_text_row_at_end
= NULL
;
13413 /* Scrolling up can leave for example a partially visible line
13414 at the end of the window to be redisplayed. */
13415 /* Set last_row to the glyph row in the current matrix where the
13416 window end line is found. It has been moved up or down in
13417 the matrix by dvpos. */
13418 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
13419 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
13421 /* If last_row is the window end line, it should display text. */
13422 xassert (last_row
->displays_text_p
);
13424 /* If window end line was partially visible before, begin
13425 displaying at that line. Otherwise begin displaying with the
13426 line following it. */
13427 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
13429 init_to_row_start (&it
, w
, last_row
);
13430 it
.vpos
= last_vpos
;
13431 it
.current_y
= last_row
->y
;
13435 init_to_row_end (&it
, w
, last_row
);
13436 it
.vpos
= 1 + last_vpos
;
13437 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
13441 /* We may start in a continuation line. If so, we have to
13442 get the right continuation_lines_width and current_x. */
13443 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
13444 it
.hpos
= it
.current_x
= 0;
13446 /* Display the rest of the lines at the window end. */
13447 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13448 while (it
.current_y
< it
.last_visible_y
13449 && !fonts_changed_p
)
13451 /* Is it always sure that the display agrees with lines in
13452 the current matrix? I don't think so, so we mark rows
13453 displayed invalid in the current matrix by setting their
13454 enabled_p flag to zero. */
13455 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
13456 if (display_line (&it
))
13457 last_text_row_at_end
= it
.glyph_row
- 1;
13461 /* Update window_end_pos and window_end_vpos. */
13462 if (first_unchanged_at_end_row
13463 && first_unchanged_at_end_row
->y
< it
.last_visible_y
13464 && !last_text_row_at_end
)
13466 /* Window end line if one of the preserved rows from the current
13467 matrix. Set row to the last row displaying text in current
13468 matrix starting at first_unchanged_at_end_row, after
13470 xassert (first_unchanged_at_end_row
->displays_text_p
);
13471 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
13472 first_unchanged_at_end_row
);
13473 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
13475 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13476 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13478 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
13479 xassert (w
->window_end_bytepos
>= 0);
13480 IF_DEBUG (debug_method_add (w
, "A"));
13482 else if (last_text_row_at_end
)
13485 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
13486 w
->window_end_bytepos
13487 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
13489 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
13490 xassert (w
->window_end_bytepos
>= 0);
13491 IF_DEBUG (debug_method_add (w
, "B"));
13493 else if (last_text_row
)
13495 /* We have displayed either to the end of the window or at the
13496 end of the window, i.e. the last row with text is to be found
13497 in the desired matrix. */
13499 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13500 w
->window_end_bytepos
13501 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13503 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
13504 xassert (w
->window_end_bytepos
>= 0);
13506 else if (first_unchanged_at_end_row
== NULL
13507 && last_text_row
== NULL
13508 && last_text_row_at_end
== NULL
)
13510 /* Displayed to end of window, but no line containing text was
13511 displayed. Lines were deleted at the end of the window. */
13512 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
13513 int vpos
= XFASTINT (w
->window_end_vpos
);
13514 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
13515 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
13518 row
== NULL
&& vpos
>= first_vpos
;
13519 --vpos
, --current_row
, --desired_row
)
13521 if (desired_row
->enabled_p
)
13523 if (desired_row
->displays_text_p
)
13526 else if (current_row
->displays_text_p
)
13530 xassert (row
!= NULL
);
13531 w
->window_end_vpos
= make_number (vpos
+ 1);
13532 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13533 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13534 xassert (w
->window_end_bytepos
>= 0);
13535 IF_DEBUG (debug_method_add (w
, "C"));
13540 #if 0 /* This leads to problems, for instance when the cursor is
13541 at ZV, and the cursor line displays no text. */
13542 /* Disable rows below what's displayed in the window. This makes
13543 debugging easier. */
13544 enable_glyph_matrix_rows (current_matrix
,
13545 XFASTINT (w
->window_end_vpos
) + 1,
13549 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
13550 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
13552 /* Record that display has not been completed. */
13553 w
->window_end_valid
= Qnil
;
13554 w
->desired_matrix
->no_scrolling_p
= 1;
13562 /***********************************************************************
13563 More debugging support
13564 ***********************************************************************/
13568 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
13569 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
13570 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
13573 /* Dump the contents of glyph matrix MATRIX on stderr.
13575 GLYPHS 0 means don't show glyph contents.
13576 GLYPHS 1 means show glyphs in short form
13577 GLYPHS > 1 means show glyphs in long form. */
13580 dump_glyph_matrix (matrix
, glyphs
)
13581 struct glyph_matrix
*matrix
;
13585 for (i
= 0; i
< matrix
->nrows
; ++i
)
13586 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
13590 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
13591 the glyph row and area where the glyph comes from. */
13594 dump_glyph (row
, glyph
, area
)
13595 struct glyph_row
*row
;
13596 struct glyph
*glyph
;
13599 if (glyph
->type
== CHAR_GLYPH
)
13602 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13603 glyph
- row
->glyphs
[TEXT_AREA
],
13606 (BUFFERP (glyph
->object
)
13608 : (STRINGP (glyph
->object
)
13611 glyph
->pixel_width
,
13613 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
13617 glyph
->left_box_line_p
,
13618 glyph
->right_box_line_p
);
13620 else if (glyph
->type
== STRETCH_GLYPH
)
13623 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13624 glyph
- row
->glyphs
[TEXT_AREA
],
13627 (BUFFERP (glyph
->object
)
13629 : (STRINGP (glyph
->object
)
13632 glyph
->pixel_width
,
13636 glyph
->left_box_line_p
,
13637 glyph
->right_box_line_p
);
13639 else if (glyph
->type
== IMAGE_GLYPH
)
13642 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13643 glyph
- row
->glyphs
[TEXT_AREA
],
13646 (BUFFERP (glyph
->object
)
13648 : (STRINGP (glyph
->object
)
13651 glyph
->pixel_width
,
13655 glyph
->left_box_line_p
,
13656 glyph
->right_box_line_p
);
13661 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
13662 GLYPHS 0 means don't show glyph contents.
13663 GLYPHS 1 means show glyphs in short form
13664 GLYPHS > 1 means show glyphs in long form. */
13667 dump_glyph_row (row
, vpos
, glyphs
)
13668 struct glyph_row
*row
;
13673 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
13674 fprintf (stderr
, "=======================================================================\n");
13676 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
13677 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
13679 MATRIX_ROW_START_CHARPOS (row
),
13680 MATRIX_ROW_END_CHARPOS (row
),
13681 row
->used
[TEXT_AREA
],
13682 row
->contains_overlapping_glyphs_p
,
13684 row
->truncated_on_left_p
,
13685 row
->truncated_on_right_p
,
13686 row
->overlay_arrow_p
,
13688 MATRIX_ROW_CONTINUATION_LINE_P (row
),
13689 row
->displays_text_p
,
13692 row
->ends_in_middle_of_char_p
,
13693 row
->starts_in_middle_of_char_p
,
13699 row
->visible_height
,
13702 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
13703 row
->end
.overlay_string_index
,
13704 row
->continuation_lines_width
);
13705 fprintf (stderr
, "%9d %5d\n",
13706 CHARPOS (row
->start
.string_pos
),
13707 CHARPOS (row
->end
.string_pos
));
13708 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
13709 row
->end
.dpvec_index
);
13716 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
13718 struct glyph
*glyph
= row
->glyphs
[area
];
13719 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
13721 /* Glyph for a line end in text. */
13722 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
13725 if (glyph
< glyph_end
)
13726 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
13728 for (; glyph
< glyph_end
; ++glyph
)
13729 dump_glyph (row
, glyph
, area
);
13732 else if (glyphs
== 1)
13736 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
13738 char *s
= (char *) alloca (row
->used
[area
] + 1);
13741 for (i
= 0; i
< row
->used
[area
]; ++i
)
13743 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
13744 if (glyph
->type
== CHAR_GLYPH
13745 && glyph
->u
.ch
< 0x80
13746 && glyph
->u
.ch
>= ' ')
13747 s
[i
] = glyph
->u
.ch
;
13753 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
13759 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
13760 Sdump_glyph_matrix
, 0, 1, "p",
13761 doc
: /* Dump the current matrix of the selected window to stderr.
13762 Shows contents of glyph row structures. With non-nil
13763 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
13764 glyphs in short form, otherwise show glyphs in long form. */)
13766 Lisp_Object glyphs
;
13768 struct window
*w
= XWINDOW (selected_window
);
13769 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13771 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
13772 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
13773 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
13774 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
13775 fprintf (stderr
, "=============================================\n");
13776 dump_glyph_matrix (w
->current_matrix
,
13777 NILP (glyphs
) ? 0 : XINT (glyphs
));
13782 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
13783 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
13786 struct frame
*f
= XFRAME (selected_frame
);
13787 dump_glyph_matrix (f
->current_matrix
, 1);
13792 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
13793 doc
: /* Dump glyph row ROW to stderr.
13794 GLYPH 0 means don't dump glyphs.
13795 GLYPH 1 means dump glyphs in short form.
13796 GLYPH > 1 or omitted means dump glyphs in long form. */)
13798 Lisp_Object row
, glyphs
;
13800 struct glyph_matrix
*matrix
;
13803 CHECK_NUMBER (row
);
13804 matrix
= XWINDOW (selected_window
)->current_matrix
;
13806 if (vpos
>= 0 && vpos
< matrix
->nrows
)
13807 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
13809 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
13814 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
13815 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
13816 GLYPH 0 means don't dump glyphs.
13817 GLYPH 1 means dump glyphs in short form.
13818 GLYPH > 1 or omitted means dump glyphs in long form. */)
13820 Lisp_Object row
, glyphs
;
13822 struct frame
*sf
= SELECTED_FRAME ();
13823 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
13826 CHECK_NUMBER (row
);
13828 if (vpos
>= 0 && vpos
< m
->nrows
)
13829 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
13830 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
13835 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
13836 doc
: /* Toggle tracing of redisplay.
13837 With ARG, turn tracing on if and only if ARG is positive. */)
13842 trace_redisplay_p
= !trace_redisplay_p
;
13845 arg
= Fprefix_numeric_value (arg
);
13846 trace_redisplay_p
= XINT (arg
) > 0;
13853 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
13854 doc
: /* Like `format', but print result to stderr.
13855 usage: (trace-to-stderr STRING &rest OBJECTS) */)
13860 Lisp_Object s
= Fformat (nargs
, args
);
13861 fprintf (stderr
, "%s", SDATA (s
));
13865 #endif /* GLYPH_DEBUG */
13869 /***********************************************************************
13870 Building Desired Matrix Rows
13871 ***********************************************************************/
13873 /* Return a temporary glyph row holding the glyphs of an overlay
13874 arrow. Only used for non-window-redisplay windows. */
13876 static struct glyph_row
*
13877 get_overlay_arrow_glyph_row (w
)
13880 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13881 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13882 struct buffer
*old
= current_buffer
;
13883 const unsigned char *arrow_string
= SDATA (Voverlay_arrow_string
);
13884 int arrow_len
= SCHARS (Voverlay_arrow_string
);
13885 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
13886 const unsigned char *p
;
13889 int n_glyphs_before
;
13891 set_buffer_temp (buffer
);
13892 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
13893 it
.glyph_row
->used
[TEXT_AREA
] = 0;
13894 SET_TEXT_POS (it
.position
, 0, 0);
13896 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
13898 while (p
< arrow_end
)
13900 Lisp_Object face
, ilisp
;
13902 /* Get the next character. */
13904 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
13906 it
.c
= *p
, it
.len
= 1;
13909 /* Get its face. */
13910 ilisp
= make_number (p
- arrow_string
);
13911 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
13912 it
.face_id
= compute_char_face (f
, it
.c
, face
);
13914 /* Compute its width, get its glyphs. */
13915 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
13916 SET_TEXT_POS (it
.position
, -1, -1);
13917 PRODUCE_GLYPHS (&it
);
13919 /* If this character doesn't fit any more in the line, we have
13920 to remove some glyphs. */
13921 if (it
.current_x
> it
.last_visible_x
)
13923 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
13928 set_buffer_temp (old
);
13929 return it
.glyph_row
;
13933 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
13934 glyphs are only inserted for terminal frames since we can't really
13935 win with truncation glyphs when partially visible glyphs are
13936 involved. Which glyphs to insert is determined by
13937 produce_special_glyphs. */
13940 insert_left_trunc_glyphs (it
)
13943 struct it truncate_it
;
13944 struct glyph
*from
, *end
, *to
, *toend
;
13946 xassert (!FRAME_WINDOW_P (it
->f
));
13948 /* Get the truncation glyphs. */
13950 truncate_it
.current_x
= 0;
13951 truncate_it
.face_id
= DEFAULT_FACE_ID
;
13952 truncate_it
.glyph_row
= &scratch_glyph_row
;
13953 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
13954 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
13955 truncate_it
.object
= make_number (0);
13956 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
13958 /* Overwrite glyphs from IT with truncation glyphs. */
13959 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
13960 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
13961 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
13962 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
13967 /* There may be padding glyphs left over. Overwrite them too. */
13968 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
13970 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
13976 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
13980 /* Compute the pixel height and width of IT->glyph_row.
13982 Most of the time, ascent and height of a display line will be equal
13983 to the max_ascent and max_height values of the display iterator
13984 structure. This is not the case if
13986 1. We hit ZV without displaying anything. In this case, max_ascent
13987 and max_height will be zero.
13989 2. We have some glyphs that don't contribute to the line height.
13990 (The glyph row flag contributes_to_line_height_p is for future
13991 pixmap extensions).
13993 The first case is easily covered by using default values because in
13994 these cases, the line height does not really matter, except that it
13995 must not be zero. */
13998 compute_line_metrics (it
)
14001 struct glyph_row
*row
= it
->glyph_row
;
14004 if (FRAME_WINDOW_P (it
->f
))
14006 int i
, min_y
, max_y
;
14008 /* The line may consist of one space only, that was added to
14009 place the cursor on it. If so, the row's height hasn't been
14011 if (row
->height
== 0)
14013 if (it
->max_ascent
+ it
->max_descent
== 0)
14014 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
14015 row
->ascent
= it
->max_ascent
;
14016 row
->height
= it
->max_ascent
+ it
->max_descent
;
14017 row
->phys_ascent
= it
->max_phys_ascent
;
14018 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14021 /* Compute the width of this line. */
14022 row
->pixel_width
= row
->x
;
14023 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
14024 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
14026 xassert (row
->pixel_width
>= 0);
14027 xassert (row
->ascent
>= 0 && row
->height
> 0);
14029 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
14030 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
14032 /* If first line's physical ascent is larger than its logical
14033 ascent, use the physical ascent, and make the row taller.
14034 This makes accented characters fully visible. */
14035 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
14036 && row
->phys_ascent
> row
->ascent
)
14038 row
->height
+= row
->phys_ascent
- row
->ascent
;
14039 row
->ascent
= row
->phys_ascent
;
14042 /* Compute how much of the line is visible. */
14043 row
->visible_height
= row
->height
;
14045 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
14046 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
14048 if (row
->y
< min_y
)
14049 row
->visible_height
-= min_y
- row
->y
;
14050 if (row
->y
+ row
->height
> max_y
)
14051 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14055 row
->pixel_width
= row
->used
[TEXT_AREA
];
14056 if (row
->continued_p
)
14057 row
->pixel_width
-= it
->continuation_pixel_width
;
14058 else if (row
->truncated_on_right_p
)
14059 row
->pixel_width
-= it
->truncation_pixel_width
;
14060 row
->ascent
= row
->phys_ascent
= 0;
14061 row
->height
= row
->phys_height
= row
->visible_height
= 1;
14064 /* Compute a hash code for this row. */
14066 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14067 for (i
= 0; i
< row
->used
[area
]; ++i
)
14068 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
14069 + row
->glyphs
[area
][i
].u
.val
14070 + row
->glyphs
[area
][i
].face_id
14071 + row
->glyphs
[area
][i
].padding_p
14072 + (row
->glyphs
[area
][i
].type
<< 2));
14074 it
->max_ascent
= it
->max_descent
= 0;
14075 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
14079 /* Append one space to the glyph row of iterator IT if doing a
14080 window-based redisplay. DEFAULT_FACE_P non-zero means let the
14081 space have the default face, otherwise let it have the same face as
14082 IT->face_id. Value is non-zero if a space was added.
14084 This function is called to make sure that there is always one glyph
14085 at the end of a glyph row that the cursor can be set on under
14086 window-systems. (If there weren't such a glyph we would not know
14087 how wide and tall a box cursor should be displayed).
14089 At the same time this space let's a nicely handle clearing to the
14090 end of the line if the row ends in italic text. */
14093 append_space (it
, default_face_p
)
14095 int default_face_p
;
14097 if (FRAME_WINDOW_P (it
->f
))
14099 int n
= it
->glyph_row
->used
[TEXT_AREA
];
14101 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
14102 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
14104 /* Save some values that must not be changed.
14105 Must save IT->c and IT->len because otherwise
14106 ITERATOR_AT_END_P wouldn't work anymore after
14107 append_space has been called. */
14108 enum display_element_type saved_what
= it
->what
;
14109 int saved_c
= it
->c
, saved_len
= it
->len
;
14110 int saved_x
= it
->current_x
;
14111 int saved_face_id
= it
->face_id
;
14112 struct text_pos saved_pos
;
14113 Lisp_Object saved_object
;
14116 saved_object
= it
->object
;
14117 saved_pos
= it
->position
;
14119 it
->what
= IT_CHARACTER
;
14120 bzero (&it
->position
, sizeof it
->position
);
14121 it
->object
= make_number (0);
14125 if (default_face_p
)
14126 it
->face_id
= DEFAULT_FACE_ID
;
14127 else if (it
->face_before_selective_p
)
14128 it
->face_id
= it
->saved_face_id
;
14129 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14130 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
14132 PRODUCE_GLYPHS (it
);
14134 it
->current_x
= saved_x
;
14135 it
->object
= saved_object
;
14136 it
->position
= saved_pos
;
14137 it
->what
= saved_what
;
14138 it
->face_id
= saved_face_id
;
14139 it
->len
= saved_len
;
14149 /* Extend the face of the last glyph in the text area of IT->glyph_row
14150 to the end of the display line. Called from display_line.
14151 If the glyph row is empty, add a space glyph to it so that we
14152 know the face to draw. Set the glyph row flag fill_line_p. */
14155 extend_face_to_end_of_line (it
)
14159 struct frame
*f
= it
->f
;
14161 /* If line is already filled, do nothing. */
14162 if (it
->current_x
>= it
->last_visible_x
)
14165 /* Face extension extends the background and box of IT->face_id
14166 to the end of the line. If the background equals the background
14167 of the frame, we don't have to do anything. */
14168 if (it
->face_before_selective_p
)
14169 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14171 face
= FACE_FROM_ID (f
, it
->face_id
);
14173 if (FRAME_WINDOW_P (f
)
14174 && face
->box
== FACE_NO_BOX
14175 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
14179 /* Set the glyph row flag indicating that the face of the last glyph
14180 in the text area has to be drawn to the end of the text area. */
14181 it
->glyph_row
->fill_line_p
= 1;
14183 /* If current character of IT is not ASCII, make sure we have the
14184 ASCII face. This will be automatically undone the next time
14185 get_next_display_element returns a multibyte character. Note
14186 that the character will always be single byte in unibyte text. */
14187 if (!SINGLE_BYTE_CHAR_P (it
->c
))
14189 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
14192 if (FRAME_WINDOW_P (f
))
14194 /* If the row is empty, add a space with the current face of IT,
14195 so that we know which face to draw. */
14196 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
14198 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
14199 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
14200 it
->glyph_row
->used
[TEXT_AREA
] = 1;
14205 /* Save some values that must not be changed. */
14206 int saved_x
= it
->current_x
;
14207 struct text_pos saved_pos
;
14208 Lisp_Object saved_object
;
14209 enum display_element_type saved_what
= it
->what
;
14210 int saved_face_id
= it
->face_id
;
14212 saved_object
= it
->object
;
14213 saved_pos
= it
->position
;
14215 it
->what
= IT_CHARACTER
;
14216 bzero (&it
->position
, sizeof it
->position
);
14217 it
->object
= make_number (0);
14220 it
->face_id
= face
->id
;
14222 PRODUCE_GLYPHS (it
);
14224 while (it
->current_x
<= it
->last_visible_x
)
14225 PRODUCE_GLYPHS (it
);
14227 /* Don't count these blanks really. It would let us insert a left
14228 truncation glyph below and make us set the cursor on them, maybe. */
14229 it
->current_x
= saved_x
;
14230 it
->object
= saved_object
;
14231 it
->position
= saved_pos
;
14232 it
->what
= saved_what
;
14233 it
->face_id
= saved_face_id
;
14238 /* Value is non-zero if text starting at CHARPOS in current_buffer is
14239 trailing whitespace. */
14242 trailing_whitespace_p (charpos
)
14245 int bytepos
= CHAR_TO_BYTE (charpos
);
14248 while (bytepos
< ZV_BYTE
14249 && (c
= FETCH_CHAR (bytepos
),
14250 c
== ' ' || c
== '\t'))
14253 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
14255 if (bytepos
!= PT_BYTE
)
14262 /* Highlight trailing whitespace, if any, in ROW. */
14265 highlight_trailing_whitespace (f
, row
)
14267 struct glyph_row
*row
;
14269 int used
= row
->used
[TEXT_AREA
];
14273 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
14274 struct glyph
*glyph
= start
+ used
- 1;
14276 /* Skip over glyphs inserted to display the cursor at the
14277 end of a line, for extending the face of the last glyph
14278 to the end of the line on terminals, and for truncation
14279 and continuation glyphs. */
14280 while (glyph
>= start
14281 && glyph
->type
== CHAR_GLYPH
14282 && INTEGERP (glyph
->object
))
14285 /* If last glyph is a space or stretch, and it's trailing
14286 whitespace, set the face of all trailing whitespace glyphs in
14287 IT->glyph_row to `trailing-whitespace'. */
14289 && BUFFERP (glyph
->object
)
14290 && (glyph
->type
== STRETCH_GLYPH
14291 || (glyph
->type
== CHAR_GLYPH
14292 && glyph
->u
.ch
== ' '))
14293 && trailing_whitespace_p (glyph
->charpos
))
14295 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
14297 while (glyph
>= start
14298 && BUFFERP (glyph
->object
)
14299 && (glyph
->type
== STRETCH_GLYPH
14300 || (glyph
->type
== CHAR_GLYPH
14301 && glyph
->u
.ch
== ' ')))
14302 (glyph
--)->face_id
= face_id
;
14308 /* Value is non-zero if glyph row ROW in window W should be
14309 used to hold the cursor. */
14312 cursor_row_p (w
, row
)
14314 struct glyph_row
*row
;
14316 int cursor_row_p
= 1;
14318 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
14320 /* If the row ends with a newline from a string, we don't want
14321 the cursor there (if the row is continued it doesn't end in a
14323 if (CHARPOS (row
->end
.string_pos
) >= 0
14324 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14325 cursor_row_p
= row
->continued_p
;
14327 /* If the row ends at ZV, display the cursor at the end of that
14328 row instead of at the start of the row below. */
14329 else if (row
->ends_at_zv_p
)
14335 return cursor_row_p
;
14339 /* Construct the glyph row IT->glyph_row in the desired matrix of
14340 IT->w from text at the current position of IT. See dispextern.h
14341 for an overview of struct it. Value is non-zero if
14342 IT->glyph_row displays text, as opposed to a line displaying ZV
14349 struct glyph_row
*row
= it
->glyph_row
;
14351 /* We always start displaying at hpos zero even if hscrolled. */
14352 xassert (it
->hpos
== 0 && it
->current_x
== 0);
14354 /* We must not display in a row that's not a text row. */
14355 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
14356 < it
->w
->desired_matrix
->nrows
);
14358 /* Is IT->w showing the region? */
14359 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
14361 /* Clear the result glyph row and enable it. */
14362 prepare_desired_row (row
);
14364 row
->y
= it
->current_y
;
14365 row
->start
= it
->start
;
14366 row
->continuation_lines_width
= it
->continuation_lines_width
;
14367 row
->displays_text_p
= 1;
14368 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
14369 it
->starts_in_middle_of_char_p
= 0;
14371 /* Arrange the overlays nicely for our purposes. Usually, we call
14372 display_line on only one line at a time, in which case this
14373 can't really hurt too much, or we call it on lines which appear
14374 one after another in the buffer, in which case all calls to
14375 recenter_overlay_lists but the first will be pretty cheap. */
14376 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
14378 /* Move over display elements that are not visible because we are
14379 hscrolled. This may stop at an x-position < IT->first_visible_x
14380 if the first glyph is partially visible or if we hit a line end. */
14381 if (it
->current_x
< it
->first_visible_x
)
14382 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
14383 MOVE_TO_POS
| MOVE_TO_X
);
14385 /* Get the initial row height. This is either the height of the
14386 text hscrolled, if there is any, or zero. */
14387 row
->ascent
= it
->max_ascent
;
14388 row
->height
= it
->max_ascent
+ it
->max_descent
;
14389 row
->phys_ascent
= it
->max_phys_ascent
;
14390 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14392 /* Loop generating characters. The loop is left with IT on the next
14393 character to display. */
14396 int n_glyphs_before
, hpos_before
, x_before
;
14398 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
14400 /* Retrieve the next thing to display. Value is zero if end of
14402 if (!get_next_display_element (it
))
14404 /* Maybe add a space at the end of this line that is used to
14405 display the cursor there under X. Set the charpos of the
14406 first glyph of blank lines not corresponding to any text
14408 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
14409 || row
->used
[TEXT_AREA
] == 0)
14411 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
14412 row
->displays_text_p
= 0;
14414 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
14415 && (!MINI_WINDOW_P (it
->w
)
14416 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
14417 row
->indicate_empty_line_p
= 1;
14420 it
->continuation_lines_width
= 0;
14421 row
->ends_at_zv_p
= 1;
14425 /* Now, get the metrics of what we want to display. This also
14426 generates glyphs in `row' (which is IT->glyph_row). */
14427 n_glyphs_before
= row
->used
[TEXT_AREA
];
14430 /* Remember the line height so far in case the next element doesn't
14431 fit on the line. */
14432 if (!it
->truncate_lines_p
)
14434 ascent
= it
->max_ascent
;
14435 descent
= it
->max_descent
;
14436 phys_ascent
= it
->max_phys_ascent
;
14437 phys_descent
= it
->max_phys_descent
;
14440 PRODUCE_GLYPHS (it
);
14442 /* If this display element was in marginal areas, continue with
14444 if (it
->area
!= TEXT_AREA
)
14446 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14447 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14448 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14449 row
->phys_height
= max (row
->phys_height
,
14450 it
->max_phys_ascent
+ it
->max_phys_descent
);
14451 set_iterator_to_next (it
, 1);
14455 /* Does the display element fit on the line? If we truncate
14456 lines, we should draw past the right edge of the window. If
14457 we don't truncate, we want to stop so that we can display the
14458 continuation glyph before the right margin. If lines are
14459 continued, there are two possible strategies for characters
14460 resulting in more than 1 glyph (e.g. tabs): Display as many
14461 glyphs as possible in this line and leave the rest for the
14462 continuation line, or display the whole element in the next
14463 line. Original redisplay did the former, so we do it also. */
14464 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
14465 hpos_before
= it
->hpos
;
14468 if (/* Not a newline. */
14470 /* Glyphs produced fit entirely in the line. */
14471 && it
->current_x
< it
->last_visible_x
)
14473 it
->hpos
+= nglyphs
;
14474 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14475 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14476 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14477 row
->phys_height
= max (row
->phys_height
,
14478 it
->max_phys_ascent
+ it
->max_phys_descent
);
14479 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
14480 row
->x
= x
- it
->first_visible_x
;
14485 struct glyph
*glyph
;
14487 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
14489 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14490 new_x
= x
+ glyph
->pixel_width
;
14492 if (/* Lines are continued. */
14493 !it
->truncate_lines_p
14494 && (/* Glyph doesn't fit on the line. */
14495 new_x
> it
->last_visible_x
14496 /* Or it fits exactly on a window system frame. */
14497 || (new_x
== it
->last_visible_x
14498 && FRAME_WINDOW_P (it
->f
))))
14500 /* End of a continued line. */
14503 || (new_x
== it
->last_visible_x
14504 && FRAME_WINDOW_P (it
->f
)))
14506 /* Current glyph is the only one on the line or
14507 fits exactly on the line. We must continue
14508 the line because we can't draw the cursor
14509 after the glyph. */
14510 row
->continued_p
= 1;
14511 it
->current_x
= new_x
;
14512 it
->continuation_lines_width
+= new_x
;
14514 if (i
== nglyphs
- 1)
14515 set_iterator_to_next (it
, 1);
14517 else if (CHAR_GLYPH_PADDING_P (*glyph
)
14518 && !FRAME_WINDOW_P (it
->f
))
14520 /* A padding glyph that doesn't fit on this line.
14521 This means the whole character doesn't fit
14523 row
->used
[TEXT_AREA
] = n_glyphs_before
;
14525 /* Fill the rest of the row with continuation
14526 glyphs like in 20.x. */
14527 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
14528 < row
->glyphs
[1 + TEXT_AREA
])
14529 produce_special_glyphs (it
, IT_CONTINUATION
);
14531 row
->continued_p
= 1;
14532 it
->current_x
= x_before
;
14533 it
->continuation_lines_width
+= x_before
;
14535 /* Restore the height to what it was before the
14536 element not fitting on the line. */
14537 it
->max_ascent
= ascent
;
14538 it
->max_descent
= descent
;
14539 it
->max_phys_ascent
= phys_ascent
;
14540 it
->max_phys_descent
= phys_descent
;
14542 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
14544 /* A TAB that extends past the right edge of the
14545 window. This produces a single glyph on
14546 window system frames. We leave the glyph in
14547 this row and let it fill the row, but don't
14548 consume the TAB. */
14549 it
->continuation_lines_width
+= it
->last_visible_x
;
14550 row
->ends_in_middle_of_char_p
= 1;
14551 row
->continued_p
= 1;
14552 glyph
->pixel_width
= it
->last_visible_x
- x
;
14553 it
->starts_in_middle_of_char_p
= 1;
14557 /* Something other than a TAB that draws past
14558 the right edge of the window. Restore
14559 positions to values before the element. */
14560 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14562 /* Display continuation glyphs. */
14563 if (!FRAME_WINDOW_P (it
->f
))
14564 produce_special_glyphs (it
, IT_CONTINUATION
);
14565 row
->continued_p
= 1;
14567 it
->continuation_lines_width
+= x
;
14569 if (nglyphs
> 1 && i
> 0)
14571 row
->ends_in_middle_of_char_p
= 1;
14572 it
->starts_in_middle_of_char_p
= 1;
14575 /* Restore the height to what it was before the
14576 element not fitting on the line. */
14577 it
->max_ascent
= ascent
;
14578 it
->max_descent
= descent
;
14579 it
->max_phys_ascent
= phys_ascent
;
14580 it
->max_phys_descent
= phys_descent
;
14585 else if (new_x
> it
->first_visible_x
)
14587 /* Increment number of glyphs actually displayed. */
14590 if (x
< it
->first_visible_x
)
14591 /* Glyph is partially visible, i.e. row starts at
14592 negative X position. */
14593 row
->x
= x
- it
->first_visible_x
;
14597 /* Glyph is completely off the left margin of the
14598 window. This should not happen because of the
14599 move_it_in_display_line at the start of this
14600 function, unless the text display area of the
14601 window is empty. */
14602 xassert (it
->first_visible_x
<= it
->last_visible_x
);
14606 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14607 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14608 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14609 row
->phys_height
= max (row
->phys_height
,
14610 it
->max_phys_ascent
+ it
->max_phys_descent
);
14612 /* End of this display line if row is continued. */
14613 if (row
->continued_p
)
14617 /* Is this a line end? If yes, we're also done, after making
14618 sure that a non-default face is extended up to the right
14619 margin of the window. */
14620 if (ITERATOR_AT_END_OF_LINE_P (it
))
14622 int used_before
= row
->used
[TEXT_AREA
];
14624 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
14626 /* Add a space at the end of the line that is used to
14627 display the cursor there. */
14628 append_space (it
, 0);
14630 /* Extend the face to the end of the line. */
14631 extend_face_to_end_of_line (it
);
14633 /* Make sure we have the position. */
14634 if (used_before
== 0)
14635 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
14637 /* Consume the line end. This skips over invisible lines. */
14638 set_iterator_to_next (it
, 1);
14639 it
->continuation_lines_width
= 0;
14643 /* Proceed with next display element. Note that this skips
14644 over lines invisible because of selective display. */
14645 set_iterator_to_next (it
, 1);
14647 /* If we truncate lines, we are done when the last displayed
14648 glyphs reach past the right margin of the window. */
14649 if (it
->truncate_lines_p
14650 && (FRAME_WINDOW_P (it
->f
)
14651 ? (it
->current_x
>= it
->last_visible_x
)
14652 : (it
->current_x
> it
->last_visible_x
)))
14654 /* Maybe add truncation glyphs. */
14655 if (!FRAME_WINDOW_P (it
->f
))
14659 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14660 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14663 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14665 row
->used
[TEXT_AREA
] = i
;
14666 produce_special_glyphs (it
, IT_TRUNCATION
);
14670 row
->truncated_on_right_p
= 1;
14671 it
->continuation_lines_width
= 0;
14672 reseat_at_next_visible_line_start (it
, 0);
14673 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
14674 it
->hpos
= hpos_before
;
14675 it
->current_x
= x_before
;
14680 /* If line is not empty and hscrolled, maybe insert truncation glyphs
14681 at the left window margin. */
14682 if (it
->first_visible_x
14683 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
14685 if (!FRAME_WINDOW_P (it
->f
))
14686 insert_left_trunc_glyphs (it
);
14687 row
->truncated_on_left_p
= 1;
14690 /* If the start of this line is the overlay arrow-position, then
14691 mark this glyph row as the one containing the overlay arrow.
14692 This is clearly a mess with variable size fonts. It would be
14693 better to let it be displayed like cursors under X. */
14694 if (MARKERP (Voverlay_arrow_position
)
14695 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
14696 && (MATRIX_ROW_START_CHARPOS (row
)
14697 == marker_position (Voverlay_arrow_position
))
14698 && STRINGP (Voverlay_arrow_string
)
14699 && ! overlay_arrow_seen
)
14701 /* Overlay arrow in window redisplay is a fringe bitmap. */
14702 if (!FRAME_WINDOW_P (it
->f
))
14704 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
14705 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
14706 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
14707 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
14708 struct glyph
*p2
, *end
;
14710 /* Copy the arrow glyphs. */
14711 while (glyph
< arrow_end
)
14714 /* Throw away padding glyphs. */
14716 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
14717 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
14723 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
14727 overlay_arrow_seen
= 1;
14728 row
->overlay_arrow_p
= 1;
14731 /* Compute pixel dimensions of this line. */
14732 compute_line_metrics (it
);
14734 /* Remember the position at which this line ends. */
14735 row
->end
= it
->current
;
14737 /* Maybe set the cursor. */
14738 if (it
->w
->cursor
.vpos
< 0
14739 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
14740 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
14741 && cursor_row_p (it
->w
, row
))
14742 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
14744 /* Highlight trailing whitespace. */
14745 if (!NILP (Vshow_trailing_whitespace
))
14746 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
14748 /* Prepare for the next line. This line starts horizontally at (X
14749 HPOS) = (0 0). Vertical positions are incremented. As a
14750 convenience for the caller, IT->glyph_row is set to the next
14752 it
->current_x
= it
->hpos
= 0;
14753 it
->current_y
+= row
->height
;
14756 it
->start
= it
->current
;
14757 return row
->displays_text_p
;
14762 /***********************************************************************
14764 ***********************************************************************/
14766 /* Redisplay the menu bar in the frame for window W.
14768 The menu bar of X frames that don't have X toolkit support is
14769 displayed in a special window W->frame->menu_bar_window.
14771 The menu bar of terminal frames is treated specially as far as
14772 glyph matrices are concerned. Menu bar lines are not part of
14773 windows, so the update is done directly on the frame matrix rows
14774 for the menu bar. */
14777 display_menu_bar (w
)
14780 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14785 /* Don't do all this for graphical frames. */
14787 if (!NILP (Vwindow_system
))
14790 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
14795 if (FRAME_MAC_P (f
))
14799 #ifdef USE_X_TOOLKIT
14800 xassert (!FRAME_WINDOW_P (f
));
14801 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
14802 it
.first_visible_x
= 0;
14803 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
14804 #else /* not USE_X_TOOLKIT */
14805 if (FRAME_WINDOW_P (f
))
14807 /* Menu bar lines are displayed in the desired matrix of the
14808 dummy window menu_bar_window. */
14809 struct window
*menu_w
;
14810 xassert (WINDOWP (f
->menu_bar_window
));
14811 menu_w
= XWINDOW (f
->menu_bar_window
);
14812 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
14814 it
.first_visible_x
= 0;
14815 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
14819 /* This is a TTY frame, i.e. character hpos/vpos are used as
14821 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
14823 it
.first_visible_x
= 0;
14824 it
.last_visible_x
= FRAME_COLS (f
);
14826 #endif /* not USE_X_TOOLKIT */
14828 if (! mode_line_inverse_video
)
14829 /* Force the menu-bar to be displayed in the default face. */
14830 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
14832 /* Clear all rows of the menu bar. */
14833 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
14835 struct glyph_row
*row
= it
.glyph_row
+ i
;
14836 clear_glyph_row (row
);
14837 row
->enabled_p
= 1;
14838 row
->full_width_p
= 1;
14841 /* Display all items of the menu bar. */
14842 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
14843 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
14845 Lisp_Object string
;
14847 /* Stop at nil string. */
14848 string
= AREF (items
, i
+ 1);
14852 /* Remember where item was displayed. */
14853 AREF (items
, i
+ 3) = make_number (it
.hpos
);
14855 /* Display the item, pad with one space. */
14856 if (it
.current_x
< it
.last_visible_x
)
14857 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
14858 SCHARS (string
) + 1, 0, 0, -1);
14861 /* Fill out the line with spaces. */
14862 if (it
.current_x
< it
.last_visible_x
)
14863 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
14865 /* Compute the total height of the lines. */
14866 compute_line_metrics (&it
);
14871 /***********************************************************************
14873 ***********************************************************************/
14875 /* Redisplay mode lines in the window tree whose root is WINDOW. If
14876 FORCE is non-zero, redisplay mode lines unconditionally.
14877 Otherwise, redisplay only mode lines that are garbaged. Value is
14878 the number of windows whose mode lines were redisplayed. */
14881 redisplay_mode_lines (window
, force
)
14882 Lisp_Object window
;
14887 while (!NILP (window
))
14889 struct window
*w
= XWINDOW (window
);
14891 if (WINDOWP (w
->hchild
))
14892 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
14893 else if (WINDOWP (w
->vchild
))
14894 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
14896 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
14897 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
14899 struct text_pos lpoint
;
14900 struct buffer
*old
= current_buffer
;
14902 /* Set the window's buffer for the mode line display. */
14903 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14904 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14906 /* Point refers normally to the selected window. For any
14907 other window, set up appropriate value. */
14908 if (!EQ (window
, selected_window
))
14910 struct text_pos pt
;
14912 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
14913 if (CHARPOS (pt
) < BEGV
)
14914 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
14915 else if (CHARPOS (pt
) > (ZV
- 1))
14916 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
14918 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
14921 /* Display mode lines. */
14922 clear_glyph_matrix (w
->desired_matrix
);
14923 if (display_mode_lines (w
))
14926 w
->must_be_updated_p
= 1;
14929 /* Restore old settings. */
14930 set_buffer_internal_1 (old
);
14931 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
14941 /* Display the mode and/or top line of window W. Value is the number
14942 of mode lines displayed. */
14945 display_mode_lines (w
)
14948 Lisp_Object old_selected_window
, old_selected_frame
;
14951 old_selected_frame
= selected_frame
;
14952 selected_frame
= w
->frame
;
14953 old_selected_window
= selected_window
;
14954 XSETWINDOW (selected_window
, w
);
14956 /* These will be set while the mode line specs are processed. */
14957 line_number_displayed
= 0;
14958 w
->column_number_displayed
= Qnil
;
14960 if (WINDOW_WANTS_MODELINE_P (w
))
14962 struct window
*sel_w
= XWINDOW (old_selected_window
);
14964 /* Select mode line face based on the real selected window. */
14965 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
14966 current_buffer
->mode_line_format
);
14970 if (WINDOW_WANTS_HEADER_LINE_P (w
))
14972 display_mode_line (w
, HEADER_LINE_FACE_ID
,
14973 current_buffer
->header_line_format
);
14977 selected_frame
= old_selected_frame
;
14978 selected_window
= old_selected_window
;
14983 /* Display mode or top line of window W. FACE_ID specifies which line
14984 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
14985 FORMAT is the mode line format to display. Value is the pixel
14986 height of the mode line displayed. */
14989 display_mode_line (w
, face_id
, format
)
14991 enum face_id face_id
;
14992 Lisp_Object format
;
14997 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
14998 prepare_desired_row (it
.glyph_row
);
15000 if (! mode_line_inverse_video
)
15001 /* Force the mode-line to be displayed in the default face. */
15002 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15004 /* Temporarily make frame's keyboard the current kboard so that
15005 kboard-local variables in the mode_line_format will get the right
15007 push_frame_kboard (it
.f
);
15008 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15009 pop_frame_kboard ();
15011 /* Fill up with spaces. */
15012 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
15014 compute_line_metrics (&it
);
15015 it
.glyph_row
->full_width_p
= 1;
15016 it
.glyph_row
->mode_line_p
= 1;
15017 it
.glyph_row
->continued_p
= 0;
15018 it
.glyph_row
->truncated_on_left_p
= 0;
15019 it
.glyph_row
->truncated_on_right_p
= 0;
15021 /* Make a 3D mode-line have a shadow at its right end. */
15022 face
= FACE_FROM_ID (it
.f
, face_id
);
15023 extend_face_to_end_of_line (&it
);
15024 if (face
->box
!= FACE_NO_BOX
)
15026 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
15027 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
15028 last
->right_box_line_p
= 1;
15031 return it
.glyph_row
->height
;
15034 /* Alist that caches the results of :propertize.
15035 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
15036 Lisp_Object mode_line_proptrans_alist
;
15038 /* List of strings making up the mode-line. */
15039 Lisp_Object mode_line_string_list
;
15041 /* Base face property when building propertized mode line string. */
15042 static Lisp_Object mode_line_string_face
;
15043 static Lisp_Object mode_line_string_face_prop
;
15046 /* Contribute ELT to the mode line for window IT->w. How it
15047 translates into text depends on its data type.
15049 IT describes the display environment in which we display, as usual.
15051 DEPTH is the depth in recursion. It is used to prevent
15052 infinite recursion here.
15054 FIELD_WIDTH is the number of characters the display of ELT should
15055 occupy in the mode line, and PRECISION is the maximum number of
15056 characters to display from ELT's representation. See
15057 display_string for details.
15059 Returns the hpos of the end of the text generated by ELT.
15061 PROPS is a property list to add to any string we encounter.
15063 If RISKY is nonzero, remove (disregard) any properties in any string
15064 we encounter, and ignore :eval and :propertize.
15066 If the global variable `frame_title_ptr' is non-NULL, then the output
15067 is passed to `store_frame_title' instead of `display_string'. */
15070 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
15073 int field_width
, precision
;
15074 Lisp_Object elt
, props
;
15077 int n
= 0, field
, prec
;
15082 elt
= build_string ("*too-deep*");
15086 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
15090 /* A string: output it and check for %-constructs within it. */
15092 const unsigned char *this, *lisp_string
;
15094 if (!NILP (props
) || risky
)
15096 Lisp_Object oprops
, aelt
;
15097 oprops
= Ftext_properties_at (make_number (0), elt
);
15099 if (NILP (Fequal (props
, oprops
)) || risky
)
15101 /* If the starting string has properties,
15102 merge the specified ones onto the existing ones. */
15103 if (! NILP (oprops
) && !risky
)
15107 oprops
= Fcopy_sequence (oprops
);
15109 while (CONSP (tem
))
15111 oprops
= Fplist_put (oprops
, XCAR (tem
),
15112 XCAR (XCDR (tem
)));
15113 tem
= XCDR (XCDR (tem
));
15118 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
15119 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
15121 mode_line_proptrans_alist
15122 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
15129 elt
= Fcopy_sequence (elt
);
15130 Fset_text_properties (make_number (0), Flength (elt
),
15132 /* Add this item to mode_line_proptrans_alist. */
15133 mode_line_proptrans_alist
15134 = Fcons (Fcons (elt
, props
),
15135 mode_line_proptrans_alist
);
15136 /* Truncate mode_line_proptrans_alist
15137 to at most 50 elements. */
15138 tem
= Fnthcdr (make_number (50),
15139 mode_line_proptrans_alist
);
15141 XSETCDR (tem
, Qnil
);
15146 this = SDATA (elt
);
15147 lisp_string
= this;
15151 prec
= precision
- n
;
15152 if (frame_title_ptr
)
15153 n
+= store_frame_title (SDATA (elt
), -1, prec
);
15154 else if (!NILP (mode_line_string_list
))
15155 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
15157 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
15158 0, prec
, 0, STRING_MULTIBYTE (elt
));
15163 while ((precision
<= 0 || n
< precision
)
15165 && (frame_title_ptr
15166 || !NILP (mode_line_string_list
)
15167 || it
->current_x
< it
->last_visible_x
))
15169 const unsigned char *last
= this;
15171 /* Advance to end of string or next format specifier. */
15172 while ((c
= *this++) != '\0' && c
!= '%')
15175 if (this - 1 != last
)
15177 /* Output to end of string or up to '%'. Field width
15178 is length of string. Don't output more than
15179 PRECISION allows us. */
15182 prec
= chars_in_text (last
, this - last
);
15183 if (precision
> 0 && prec
> precision
- n
)
15184 prec
= precision
- n
;
15186 if (frame_title_ptr
)
15187 n
+= store_frame_title (last
, 0, prec
);
15188 else if (!NILP (mode_line_string_list
))
15190 int bytepos
= last
- lisp_string
;
15191 int charpos
= string_byte_to_char (elt
, bytepos
);
15192 n
+= store_mode_line_string (NULL
,
15193 Fsubstring (elt
, make_number (charpos
),
15194 make_number (charpos
+ prec
)),
15199 int bytepos
= last
- lisp_string
;
15200 int charpos
= string_byte_to_char (elt
, bytepos
);
15201 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
15203 STRING_MULTIBYTE (elt
));
15206 else /* c == '%' */
15208 const unsigned char *percent_position
= this;
15210 /* Get the specified minimum width. Zero means
15213 while ((c
= *this++) >= '0' && c
<= '9')
15214 field
= field
* 10 + c
- '0';
15216 /* Don't pad beyond the total padding allowed. */
15217 if (field_width
- n
> 0 && field
> field_width
- n
)
15218 field
= field_width
- n
;
15220 /* Note that either PRECISION <= 0 or N < PRECISION. */
15221 prec
= precision
- n
;
15224 n
+= display_mode_element (it
, depth
, field
, prec
,
15225 Vglobal_mode_string
, props
,
15230 int bytepos
, charpos
;
15231 unsigned char *spec
;
15233 bytepos
= percent_position
- lisp_string
;
15234 charpos
= (STRING_MULTIBYTE (elt
)
15235 ? string_byte_to_char (elt
, bytepos
)
15239 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
15241 if (frame_title_ptr
)
15242 n
+= store_frame_title (spec
, field
, prec
);
15243 else if (!NILP (mode_line_string_list
))
15245 int len
= strlen (spec
);
15246 Lisp_Object tem
= make_string (spec
, len
);
15247 props
= Ftext_properties_at (make_number (charpos
), elt
);
15248 /* Should only keep face property in props */
15249 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
15253 int nglyphs_before
, nwritten
;
15255 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
15256 nwritten
= display_string (spec
, Qnil
, elt
,
15261 /* Assign to the glyphs written above the
15262 string where the `%x' came from, position
15266 struct glyph
*glyph
15267 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
15271 for (i
= 0; i
< nwritten
; ++i
)
15273 glyph
[i
].object
= elt
;
15274 glyph
[i
].charpos
= charpos
;
15289 /* A symbol: process the value of the symbol recursively
15290 as if it appeared here directly. Avoid error if symbol void.
15291 Special case: if value of symbol is a string, output the string
15294 register Lisp_Object tem
;
15296 /* If the variable is not marked as risky to set
15297 then its contents are risky to use. */
15298 if (NILP (Fget (elt
, Qrisky_local_variable
)))
15301 tem
= Fboundp (elt
);
15304 tem
= Fsymbol_value (elt
);
15305 /* If value is a string, output that string literally:
15306 don't check for % within it. */
15310 if (!EQ (tem
, elt
))
15312 /* Give up right away for nil or t. */
15322 register Lisp_Object car
, tem
;
15324 /* A cons cell: five distinct cases.
15325 If first element is :eval or :propertize, do something special.
15326 If first element is a string or a cons, process all the elements
15327 and effectively concatenate them.
15328 If first element is a negative number, truncate displaying cdr to
15329 at most that many characters. If positive, pad (with spaces)
15330 to at least that many characters.
15331 If first element is a symbol, process the cadr or caddr recursively
15332 according to whether the symbol's value is non-nil or nil. */
15334 if (EQ (car
, QCeval
))
15336 /* An element of the form (:eval FORM) means evaluate FORM
15337 and use the result as mode line elements. */
15342 if (CONSP (XCDR (elt
)))
15345 spec
= safe_eval (XCAR (XCDR (elt
)));
15346 n
+= display_mode_element (it
, depth
, field_width
- n
,
15347 precision
- n
, spec
, props
,
15351 else if (EQ (car
, QCpropertize
))
15353 /* An element of the form (:propertize ELT PROPS...)
15354 means display ELT but applying properties PROPS. */
15359 if (CONSP (XCDR (elt
)))
15360 n
+= display_mode_element (it
, depth
, field_width
- n
,
15361 precision
- n
, XCAR (XCDR (elt
)),
15362 XCDR (XCDR (elt
)), risky
);
15364 else if (SYMBOLP (car
))
15366 tem
= Fboundp (car
);
15370 /* elt is now the cdr, and we know it is a cons cell.
15371 Use its car if CAR has a non-nil value. */
15374 tem
= Fsymbol_value (car
);
15381 /* Symbol's value is nil (or symbol is unbound)
15382 Get the cddr of the original list
15383 and if possible find the caddr and use that. */
15387 else if (!CONSP (elt
))
15392 else if (INTEGERP (car
))
15394 register int lim
= XINT (car
);
15398 /* Negative int means reduce maximum width. */
15399 if (precision
<= 0)
15402 precision
= min (precision
, -lim
);
15406 /* Padding specified. Don't let it be more than
15407 current maximum. */
15409 lim
= min (precision
, lim
);
15411 /* If that's more padding than already wanted, queue it.
15412 But don't reduce padding already specified even if
15413 that is beyond the current truncation point. */
15414 field_width
= max (lim
, field_width
);
15418 else if (STRINGP (car
) || CONSP (car
))
15420 register int limit
= 50;
15421 /* Limit is to protect against circular lists. */
15424 && (precision
<= 0 || n
< precision
))
15426 n
+= display_mode_element (it
, depth
, field_width
- n
,
15427 precision
- n
, XCAR (elt
),
15437 elt
= build_string ("*invalid*");
15441 /* Pad to FIELD_WIDTH. */
15442 if (field_width
> 0 && n
< field_width
)
15444 if (frame_title_ptr
)
15445 n
+= store_frame_title ("", field_width
- n
, 0);
15446 else if (!NILP (mode_line_string_list
))
15447 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
15449 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
15456 /* Store a mode-line string element in mode_line_string_list.
15458 If STRING is non-null, display that C string. Otherwise, the Lisp
15459 string LISP_STRING is displayed.
15461 FIELD_WIDTH is the minimum number of output glyphs to produce.
15462 If STRING has fewer characters than FIELD_WIDTH, pad to the right
15463 with spaces. FIELD_WIDTH <= 0 means don't pad.
15465 PRECISION is the maximum number of characters to output from
15466 STRING. PRECISION <= 0 means don't truncate the string.
15468 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
15469 properties to the string.
15471 PROPS are the properties to add to the string.
15472 The mode_line_string_face face property is always added to the string.
15475 static int store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
15477 Lisp_Object lisp_string
;
15486 if (string
!= NULL
)
15488 len
= strlen (string
);
15489 if (precision
> 0 && len
> precision
)
15491 lisp_string
= make_string (string
, len
);
15493 props
= mode_line_string_face_prop
;
15494 else if (!NILP (mode_line_string_face
))
15496 Lisp_Object face
= Fplist_get (props
, Qface
);
15497 props
= Fcopy_sequence (props
);
15499 face
= mode_line_string_face
;
15501 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15502 props
= Fplist_put (props
, Qface
, face
);
15504 Fadd_text_properties (make_number (0), make_number (len
),
15505 props
, lisp_string
);
15509 len
= XFASTINT (Flength (lisp_string
));
15510 if (precision
> 0 && len
> precision
)
15513 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
15516 if (!NILP (mode_line_string_face
))
15520 props
= Ftext_properties_at (make_number (0), lisp_string
);
15521 face
= Fplist_get (props
, Qface
);
15523 face
= mode_line_string_face
;
15525 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15526 props
= Fcons (Qface
, Fcons (face
, Qnil
));
15528 lisp_string
= Fcopy_sequence (lisp_string
);
15531 Fadd_text_properties (make_number (0), make_number (len
),
15532 props
, lisp_string
);
15537 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15541 if (field_width
> len
)
15543 field_width
-= len
;
15544 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
15546 Fadd_text_properties (make_number (0), make_number (field_width
),
15547 props
, lisp_string
);
15548 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15556 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
15558 doc
: /* Return the mode-line of selected window as a string.
15559 First optional arg FORMAT specifies a different format string (see
15560 `mode-line-format' for details) to use. If FORMAT is t, return
15561 the buffer's header-line. Second optional arg WINDOW specifies a
15562 different window to use as the context for the formatting.
15563 If third optional arg NO-PROPS is non-nil, string is not propertized. */)
15564 (format
, window
, no_props
)
15565 Lisp_Object format
, window
, no_props
;
15570 struct buffer
*old_buffer
= NULL
;
15571 enum face_id face_id
= DEFAULT_FACE_ID
;
15574 window
= selected_window
;
15575 CHECK_WINDOW (window
);
15576 w
= XWINDOW (window
);
15577 CHECK_BUFFER (w
->buffer
);
15579 if (XBUFFER (w
->buffer
) != current_buffer
)
15581 old_buffer
= current_buffer
;
15582 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15585 if (NILP (format
) || EQ (format
, Qt
))
15587 face_id
= NILP (format
)
15588 ? CURRENT_MODE_LINE_FACE_ID (w
) :
15589 HEADER_LINE_FACE_ID
;
15590 format
= NILP (format
)
15591 ? current_buffer
->mode_line_format
15592 : current_buffer
->header_line_format
;
15595 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15597 if (NILP (no_props
))
15599 mode_line_string_face
=
15600 (face_id
== MODE_LINE_FACE_ID
? Qmode_line
:
15601 face_id
== MODE_LINE_INACTIVE_FACE_ID
? Qmode_line_inactive
:
15602 face_id
== HEADER_LINE_FACE_ID
? Qheader_line
: Qnil
);
15604 mode_line_string_face_prop
=
15605 NILP (mode_line_string_face
) ? Qnil
:
15606 Fcons (Qface
, Fcons (mode_line_string_face
, Qnil
));
15608 /* We need a dummy last element in mode_line_string_list to
15609 indicate we are building the propertized mode-line string.
15610 Using mode_line_string_face_prop here GC protects it. */
15611 mode_line_string_list
=
15612 Fcons (mode_line_string_face_prop
, Qnil
);
15613 frame_title_ptr
= NULL
;
15617 mode_line_string_face_prop
= Qnil
;
15618 mode_line_string_list
= Qnil
;
15619 frame_title_ptr
= frame_title_buf
;
15622 push_frame_kboard (it
.f
);
15623 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15624 pop_frame_kboard ();
15627 set_buffer_internal_1 (old_buffer
);
15629 if (NILP (no_props
))
15632 mode_line_string_list
= Fnreverse (mode_line_string_list
);
15633 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
15634 make_string ("", 0));
15635 mode_line_string_face_prop
= Qnil
;
15636 mode_line_string_list
= Qnil
;
15640 len
= frame_title_ptr
- frame_title_buf
;
15641 if (len
> 0 && frame_title_ptr
[-1] == '-')
15643 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
15644 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
15646 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
15647 if (len
> frame_title_ptr
- frame_title_buf
)
15648 len
= frame_title_ptr
- frame_title_buf
;
15651 frame_title_ptr
= NULL
;
15652 return make_string (frame_title_buf
, len
);
15655 /* Write a null-terminated, right justified decimal representation of
15656 the positive integer D to BUF using a minimal field width WIDTH. */
15659 pint2str (buf
, width
, d
)
15660 register char *buf
;
15661 register int width
;
15664 register char *p
= buf
;
15672 *p
++ = d
% 10 + '0';
15677 for (width
-= (int) (p
- buf
); width
> 0; --width
)
15688 /* Write a null-terminated, right justified decimal and "human
15689 readable" representation of the nonnegative integer D to BUF using
15690 a minimal field width WIDTH. D should be smaller than 999.5e24. */
15692 static const char power_letter
[] =
15706 pint2hrstr (buf
, width
, d
)
15711 /* We aim to represent the nonnegative integer D as
15712 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
15715 /* -1 means: do not use TENTHS. */
15719 /* Length of QUOTIENT.TENTHS as a string. */
15725 if (1000 <= quotient
)
15727 /* Scale to the appropriate EXPONENT. */
15730 remainder
= quotient
% 1000;
15734 while (1000 <= quotient
);
15736 /* Round to nearest and decide whether to use TENTHS or not. */
15739 tenths
= remainder
/ 100;
15740 if (50 <= remainder
% 100)
15746 if (quotient
== 10)
15753 if (500 <= remainder
)
15754 if (quotient
< 999)
15764 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
15765 if (tenths
== -1 && quotient
<= 99)
15772 p
= psuffix
= buf
+ max (width
, length
);
15774 /* Print EXPONENT. */
15776 *psuffix
++ = power_letter
[exponent
];
15779 /* Print TENTHS. */
15782 *--p
= '0' + tenths
;
15786 /* Print QUOTIENT. */
15789 int digit
= quotient
% 10;
15790 *--p
= '0' + digit
;
15792 while ((quotient
/= 10) != 0);
15794 /* Print leading spaces. */
15799 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
15800 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
15801 type of CODING_SYSTEM. Return updated pointer into BUF. */
15803 static unsigned char invalid_eol_type
[] = "(*invalid*)";
15806 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
15807 Lisp_Object coding_system
;
15808 register char *buf
;
15812 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
15813 const unsigned char *eol_str
;
15815 /* The EOL conversion we are using. */
15816 Lisp_Object eoltype
;
15818 val
= Fget (coding_system
, Qcoding_system
);
15821 if (!VECTORP (val
)) /* Not yet decided. */
15826 eoltype
= eol_mnemonic_undecided
;
15827 /* Don't mention EOL conversion if it isn't decided. */
15831 Lisp_Object eolvalue
;
15833 eolvalue
= Fget (coding_system
, Qeol_type
);
15836 *buf
++ = XFASTINT (AREF (val
, 1));
15840 /* The EOL conversion that is normal on this system. */
15842 if (NILP (eolvalue
)) /* Not yet decided. */
15843 eoltype
= eol_mnemonic_undecided
;
15844 else if (VECTORP (eolvalue
)) /* Not yet decided. */
15845 eoltype
= eol_mnemonic_undecided
;
15846 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
15847 eoltype
= (XFASTINT (eolvalue
) == 0
15848 ? eol_mnemonic_unix
15849 : (XFASTINT (eolvalue
) == 1
15850 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
15856 /* Mention the EOL conversion if it is not the usual one. */
15857 if (STRINGP (eoltype
))
15859 eol_str
= SDATA (eoltype
);
15860 eol_str_len
= SBYTES (eoltype
);
15862 else if (INTEGERP (eoltype
)
15863 && CHAR_VALID_P (XINT (eoltype
), 0))
15865 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
15866 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
15871 eol_str
= invalid_eol_type
;
15872 eol_str_len
= sizeof (invalid_eol_type
) - 1;
15874 bcopy (eol_str
, buf
, eol_str_len
);
15875 buf
+= eol_str_len
;
15881 /* Return a string for the output of a mode line %-spec for window W,
15882 generated by character C. PRECISION >= 0 means don't return a
15883 string longer than that value. FIELD_WIDTH > 0 means pad the
15884 string returned with spaces to that value. Return 1 in *MULTIBYTE
15885 if the result is multibyte text. */
15887 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
15890 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
15893 int field_width
, precision
;
15897 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15898 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
15899 struct buffer
*b
= XBUFFER (w
->buffer
);
15907 if (!NILP (b
->read_only
))
15909 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
15914 /* This differs from %* only for a modified read-only buffer. */
15915 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
15917 if (!NILP (b
->read_only
))
15922 /* This differs from %* in ignoring read-only-ness. */
15923 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
15935 if (command_loop_level
> 5)
15937 p
= decode_mode_spec_buf
;
15938 for (i
= 0; i
< command_loop_level
; i
++)
15941 return decode_mode_spec_buf
;
15949 if (command_loop_level
> 5)
15951 p
= decode_mode_spec_buf
;
15952 for (i
= 0; i
< command_loop_level
; i
++)
15955 return decode_mode_spec_buf
;
15962 /* Let lots_of_dashes be a string of infinite length. */
15963 if (!NILP (mode_line_string_list
))
15965 if (field_width
<= 0
15966 || field_width
> sizeof (lots_of_dashes
))
15968 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
15969 decode_mode_spec_buf
[i
] = '-';
15970 decode_mode_spec_buf
[i
] = '\0';
15971 return decode_mode_spec_buf
;
15974 return lots_of_dashes
;
15983 int col
= (int) current_column (); /* iftc */
15984 w
->column_number_displayed
= make_number (col
);
15985 pint2str (decode_mode_spec_buf
, field_width
, col
);
15986 return decode_mode_spec_buf
;
15990 /* %F displays the frame name. */
15991 if (!NILP (f
->title
))
15992 return (char *) SDATA (f
->title
);
15993 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
15994 return (char *) SDATA (f
->name
);
16003 int size
= ZV
- BEGV
;
16004 pint2str (decode_mode_spec_buf
, field_width
, size
);
16005 return decode_mode_spec_buf
;
16010 int size
= ZV
- BEGV
;
16011 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
16012 return decode_mode_spec_buf
;
16017 int startpos
= XMARKER (w
->start
)->charpos
;
16018 int startpos_byte
= marker_byte_position (w
->start
);
16019 int line
, linepos
, linepos_byte
, topline
;
16021 int height
= WINDOW_TOTAL_LINES (w
);
16023 /* If we decided that this buffer isn't suitable for line numbers,
16024 don't forget that too fast. */
16025 if (EQ (w
->base_line_pos
, w
->buffer
))
16027 /* But do forget it, if the window shows a different buffer now. */
16028 else if (BUFFERP (w
->base_line_pos
))
16029 w
->base_line_pos
= Qnil
;
16031 /* If the buffer is very big, don't waste time. */
16032 if (INTEGERP (Vline_number_display_limit
)
16033 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
16035 w
->base_line_pos
= Qnil
;
16036 w
->base_line_number
= Qnil
;
16040 if (!NILP (w
->base_line_number
)
16041 && !NILP (w
->base_line_pos
)
16042 && XFASTINT (w
->base_line_pos
) <= startpos
)
16044 line
= XFASTINT (w
->base_line_number
);
16045 linepos
= XFASTINT (w
->base_line_pos
);
16046 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
16051 linepos
= BUF_BEGV (b
);
16052 linepos_byte
= BUF_BEGV_BYTE (b
);
16055 /* Count lines from base line to window start position. */
16056 nlines
= display_count_lines (linepos
, linepos_byte
,
16060 topline
= nlines
+ line
;
16062 /* Determine a new base line, if the old one is too close
16063 or too far away, or if we did not have one.
16064 "Too close" means it's plausible a scroll-down would
16065 go back past it. */
16066 if (startpos
== BUF_BEGV (b
))
16068 w
->base_line_number
= make_number (topline
);
16069 w
->base_line_pos
= make_number (BUF_BEGV (b
));
16071 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
16072 || linepos
== BUF_BEGV (b
))
16074 int limit
= BUF_BEGV (b
);
16075 int limit_byte
= BUF_BEGV_BYTE (b
);
16077 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
16079 if (startpos
- distance
> limit
)
16081 limit
= startpos
- distance
;
16082 limit_byte
= CHAR_TO_BYTE (limit
);
16085 nlines
= display_count_lines (startpos
, startpos_byte
,
16087 - (height
* 2 + 30),
16089 /* If we couldn't find the lines we wanted within
16090 line_number_display_limit_width chars per line,
16091 give up on line numbers for this window. */
16092 if (position
== limit_byte
&& limit
== startpos
- distance
)
16094 w
->base_line_pos
= w
->buffer
;
16095 w
->base_line_number
= Qnil
;
16099 w
->base_line_number
= make_number (topline
- nlines
);
16100 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
16103 /* Now count lines from the start pos to point. */
16104 nlines
= display_count_lines (startpos
, startpos_byte
,
16105 PT_BYTE
, PT
, &junk
);
16107 /* Record that we did display the line number. */
16108 line_number_displayed
= 1;
16110 /* Make the string to show. */
16111 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
16112 return decode_mode_spec_buf
;
16115 char* p
= decode_mode_spec_buf
;
16116 int pad
= field_width
- 2;
16122 return decode_mode_spec_buf
;
16128 obj
= b
->mode_name
;
16132 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
16138 int pos
= marker_position (w
->start
);
16139 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16141 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
16143 if (pos
<= BUF_BEGV (b
))
16148 else if (pos
<= BUF_BEGV (b
))
16152 if (total
> 1000000)
16153 /* Do it differently for a large value, to avoid overflow. */
16154 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16156 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16157 /* We can't normally display a 3-digit number,
16158 so get us a 2-digit number that is close. */
16161 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16162 return decode_mode_spec_buf
;
16166 /* Display percentage of size above the bottom of the screen. */
16169 int toppos
= marker_position (w
->start
);
16170 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
16171 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16173 if (botpos
>= BUF_ZV (b
))
16175 if (toppos
<= BUF_BEGV (b
))
16182 if (total
> 1000000)
16183 /* Do it differently for a large value, to avoid overflow. */
16184 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16186 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16187 /* We can't normally display a 3-digit number,
16188 so get us a 2-digit number that is close. */
16191 if (toppos
<= BUF_BEGV (b
))
16192 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
16194 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16195 return decode_mode_spec_buf
;
16200 /* status of process */
16201 obj
= Fget_buffer_process (w
->buffer
);
16203 return "no process";
16204 #ifdef subprocesses
16205 obj
= Fsymbol_name (Fprocess_status (obj
));
16209 case 't': /* indicate TEXT or BINARY */
16210 #ifdef MODE_LINE_BINARY_TEXT
16211 return MODE_LINE_BINARY_TEXT (b
);
16217 /* %T is the frame name on a termcap frame, the empty string otherwise. */
16218 if (! FRAME_TERMCAP_P (f
))
16220 if (!NILP (f
->title
))
16221 return (char *) SDATA (f
->title
);
16222 return (char *) SDATA (f
->name
);
16225 /* coding-system (not including end-of-line format) */
16227 /* coding-system (including end-of-line type) */
16229 int eol_flag
= (c
== 'Z');
16230 char *p
= decode_mode_spec_buf
;
16232 if (! FRAME_WINDOW_P (f
))
16234 /* No need to mention EOL here--the terminal never needs
16235 to do EOL conversion. */
16236 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
16237 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
16239 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
16242 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
16243 #ifdef subprocesses
16244 obj
= Fget_buffer_process (Fcurrent_buffer ());
16245 if (PROCESSP (obj
))
16247 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
16249 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
16252 #endif /* subprocesses */
16255 return decode_mode_spec_buf
;
16261 *multibyte
= STRING_MULTIBYTE (obj
);
16262 return (char *) SDATA (obj
);
16269 /* Count up to COUNT lines starting from START / START_BYTE.
16270 But don't go beyond LIMIT_BYTE.
16271 Return the number of lines thus found (always nonnegative).
16273 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
16276 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
16277 int start
, start_byte
, limit_byte
, count
;
16280 register unsigned char *cursor
;
16281 unsigned char *base
;
16283 register int ceiling
;
16284 register unsigned char *ceiling_addr
;
16285 int orig_count
= count
;
16287 /* If we are not in selective display mode,
16288 check only for newlines. */
16289 int selective_display
= (!NILP (current_buffer
->selective_display
)
16290 && !INTEGERP (current_buffer
->selective_display
));
16294 while (start_byte
< limit_byte
)
16296 ceiling
= BUFFER_CEILING_OF (start_byte
);
16297 ceiling
= min (limit_byte
- 1, ceiling
);
16298 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
16299 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
16302 if (selective_display
)
16303 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
16306 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
16309 if (cursor
!= ceiling_addr
)
16313 start_byte
+= cursor
- base
+ 1;
16314 *byte_pos_ptr
= start_byte
;
16318 if (++cursor
== ceiling_addr
)
16324 start_byte
+= cursor
- base
;
16329 while (start_byte
> limit_byte
)
16331 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
16332 ceiling
= max (limit_byte
, ceiling
);
16333 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
16334 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
16337 if (selective_display
)
16338 while (--cursor
!= ceiling_addr
16339 && *cursor
!= '\n' && *cursor
!= 015)
16342 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
16345 if (cursor
!= ceiling_addr
)
16349 start_byte
+= cursor
- base
+ 1;
16350 *byte_pos_ptr
= start_byte
;
16351 /* When scanning backwards, we should
16352 not count the newline posterior to which we stop. */
16353 return - orig_count
- 1;
16359 /* Here we add 1 to compensate for the last decrement
16360 of CURSOR, which took it past the valid range. */
16361 start_byte
+= cursor
- base
+ 1;
16365 *byte_pos_ptr
= limit_byte
;
16368 return - orig_count
+ count
;
16369 return orig_count
- count
;
16375 /***********************************************************************
16377 ***********************************************************************/
16379 /* Display a NUL-terminated string, starting with index START.
16381 If STRING is non-null, display that C string. Otherwise, the Lisp
16382 string LISP_STRING is displayed.
16384 If FACE_STRING is not nil, FACE_STRING_POS is a position in
16385 FACE_STRING. Display STRING or LISP_STRING with the face at
16386 FACE_STRING_POS in FACE_STRING:
16388 Display the string in the environment given by IT, but use the
16389 standard display table, temporarily.
16391 FIELD_WIDTH is the minimum number of output glyphs to produce.
16392 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16393 with spaces. If STRING has more characters, more than FIELD_WIDTH
16394 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
16396 PRECISION is the maximum number of characters to output from
16397 STRING. PRECISION < 0 means don't truncate the string.
16399 This is roughly equivalent to printf format specifiers:
16401 FIELD_WIDTH PRECISION PRINTF
16402 ----------------------------------------
16408 MULTIBYTE zero means do not display multibyte chars, > 0 means do
16409 display them, and < 0 means obey the current buffer's value of
16410 enable_multibyte_characters.
16412 Value is the number of glyphs produced. */
16415 display_string (string
, lisp_string
, face_string
, face_string_pos
,
16416 start
, it
, field_width
, precision
, max_x
, multibyte
)
16417 unsigned char *string
;
16418 Lisp_Object lisp_string
;
16419 Lisp_Object face_string
;
16420 int face_string_pos
;
16423 int field_width
, precision
, max_x
;
16426 int hpos_at_start
= it
->hpos
;
16427 int saved_face_id
= it
->face_id
;
16428 struct glyph_row
*row
= it
->glyph_row
;
16430 /* Initialize the iterator IT for iteration over STRING beginning
16431 with index START. */
16432 reseat_to_string (it
, string
, lisp_string
, start
,
16433 precision
, field_width
, multibyte
);
16435 /* If displaying STRING, set up the face of the iterator
16436 from LISP_STRING, if that's given. */
16437 if (STRINGP (face_string
))
16443 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
16444 0, it
->region_beg_charpos
,
16445 it
->region_end_charpos
,
16446 &endptr
, it
->base_face_id
, 0);
16447 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16448 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
16451 /* Set max_x to the maximum allowed X position. Don't let it go
16452 beyond the right edge of the window. */
16454 max_x
= it
->last_visible_x
;
16456 max_x
= min (max_x
, it
->last_visible_x
);
16458 /* Skip over display elements that are not visible. because IT->w is
16460 if (it
->current_x
< it
->first_visible_x
)
16461 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
16462 MOVE_TO_POS
| MOVE_TO_X
);
16464 row
->ascent
= it
->max_ascent
;
16465 row
->height
= it
->max_ascent
+ it
->max_descent
;
16466 row
->phys_ascent
= it
->max_phys_ascent
;
16467 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16469 /* This condition is for the case that we are called with current_x
16470 past last_visible_x. */
16471 while (it
->current_x
< max_x
)
16473 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
16475 /* Get the next display element. */
16476 if (!get_next_display_element (it
))
16479 /* Produce glyphs. */
16480 x_before
= it
->current_x
;
16481 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16482 PRODUCE_GLYPHS (it
);
16484 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
16487 while (i
< nglyphs
)
16489 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16491 if (!it
->truncate_lines_p
16492 && x
+ glyph
->pixel_width
> max_x
)
16494 /* End of continued line or max_x reached. */
16495 if (CHAR_GLYPH_PADDING_P (*glyph
))
16497 /* A wide character is unbreakable. */
16498 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16499 it
->current_x
= x_before
;
16503 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16508 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
16510 /* Glyph is at least partially visible. */
16512 if (x
< it
->first_visible_x
)
16513 it
->glyph_row
->x
= x
- it
->first_visible_x
;
16517 /* Glyph is off the left margin of the display area.
16518 Should not happen. */
16522 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16523 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16524 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16525 row
->phys_height
= max (row
->phys_height
,
16526 it
->max_phys_ascent
+ it
->max_phys_descent
);
16527 x
+= glyph
->pixel_width
;
16531 /* Stop if max_x reached. */
16535 /* Stop at line ends. */
16536 if (ITERATOR_AT_END_OF_LINE_P (it
))
16538 it
->continuation_lines_width
= 0;
16542 set_iterator_to_next (it
, 1);
16544 /* Stop if truncating at the right edge. */
16545 if (it
->truncate_lines_p
16546 && it
->current_x
>= it
->last_visible_x
)
16548 /* Add truncation mark, but don't do it if the line is
16549 truncated at a padding space. */
16550 if (IT_CHARPOS (*it
) < it
->string_nchars
)
16552 if (!FRAME_WINDOW_P (it
->f
))
16556 if (it
->current_x
> it
->last_visible_x
)
16558 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16559 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16561 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16563 row
->used
[TEXT_AREA
] = i
;
16564 produce_special_glyphs (it
, IT_TRUNCATION
);
16567 produce_special_glyphs (it
, IT_TRUNCATION
);
16569 it
->glyph_row
->truncated_on_right_p
= 1;
16575 /* Maybe insert a truncation at the left. */
16576 if (it
->first_visible_x
16577 && IT_CHARPOS (*it
) > 0)
16579 if (!FRAME_WINDOW_P (it
->f
))
16580 insert_left_trunc_glyphs (it
);
16581 it
->glyph_row
->truncated_on_left_p
= 1;
16584 it
->face_id
= saved_face_id
;
16586 /* Value is number of columns displayed. */
16587 return it
->hpos
- hpos_at_start
;
16592 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
16593 appears as an element of LIST or as the car of an element of LIST.
16594 If PROPVAL is a list, compare each element against LIST in that
16595 way, and return 1/2 if any element of PROPVAL is found in LIST.
16596 Otherwise return 0. This function cannot quit.
16597 The return value is 2 if the text is invisible but with an ellipsis
16598 and 1 if it's invisible and without an ellipsis. */
16601 invisible_p (propval
, list
)
16602 register Lisp_Object propval
;
16605 register Lisp_Object tail
, proptail
;
16607 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
16609 register Lisp_Object tem
;
16611 if (EQ (propval
, tem
))
16613 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
16614 return NILP (XCDR (tem
)) ? 1 : 2;
16617 if (CONSP (propval
))
16619 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
16621 Lisp_Object propelt
;
16622 propelt
= XCAR (proptail
);
16623 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
16625 register Lisp_Object tem
;
16627 if (EQ (propelt
, tem
))
16629 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
16630 return NILP (XCDR (tem
)) ? 1 : 2;
16639 /***********************************************************************
16641 ***********************************************************************/
16643 #ifdef HAVE_WINDOW_SYSTEM
16648 dump_glyph_string (s
)
16649 struct glyph_string
*s
;
16651 fprintf (stderr
, "glyph string\n");
16652 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
16653 s
->x
, s
->y
, s
->width
, s
->height
);
16654 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
16655 fprintf (stderr
, " hl = %d\n", s
->hl
);
16656 fprintf (stderr
, " left overhang = %d, right = %d\n",
16657 s
->left_overhang
, s
->right_overhang
);
16658 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
16659 fprintf (stderr
, " extends to end of line = %d\n",
16660 s
->extends_to_end_of_line_p
);
16661 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
16662 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
16665 #endif /* GLYPH_DEBUG */
16667 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
16668 of XChar2b structures for S; it can't be allocated in
16669 init_glyph_string because it must be allocated via `alloca'. W
16670 is the window on which S is drawn. ROW and AREA are the glyph row
16671 and area within the row from which S is constructed. START is the
16672 index of the first glyph structure covered by S. HL is a
16673 face-override for drawing S. */
16676 #define OPTIONAL_HDC(hdc) hdc,
16677 #define DECLARE_HDC(hdc) HDC hdc;
16678 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
16679 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
16682 #ifndef OPTIONAL_HDC
16683 #define OPTIONAL_HDC(hdc)
16684 #define DECLARE_HDC(hdc)
16685 #define ALLOCATE_HDC(hdc, f)
16686 #define RELEASE_HDC(hdc, f)
16690 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
16691 struct glyph_string
*s
;
16695 struct glyph_row
*row
;
16696 enum glyph_row_area area
;
16698 enum draw_glyphs_face hl
;
16700 bzero (s
, sizeof *s
);
16702 s
->f
= XFRAME (w
->frame
);
16706 s
->display
= FRAME_X_DISPLAY (s
->f
);
16707 s
->window
= FRAME_X_WINDOW (s
->f
);
16708 s
->char2b
= char2b
;
16712 s
->first_glyph
= row
->glyphs
[area
] + start
;
16713 s
->height
= row
->height
;
16714 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
16716 /* Display the internal border below the tool-bar window. */
16717 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
16718 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
16720 s
->ybase
= s
->y
+ row
->ascent
;
16724 /* Append the list of glyph strings with head H and tail T to the list
16725 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
16728 append_glyph_string_lists (head
, tail
, h
, t
)
16729 struct glyph_string
**head
, **tail
;
16730 struct glyph_string
*h
, *t
;
16744 /* Prepend the list of glyph strings with head H and tail T to the
16745 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
16749 prepend_glyph_string_lists (head
, tail
, h
, t
)
16750 struct glyph_string
**head
, **tail
;
16751 struct glyph_string
*h
, *t
;
16765 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
16766 Set *HEAD and *TAIL to the resulting list. */
16769 append_glyph_string (head
, tail
, s
)
16770 struct glyph_string
**head
, **tail
;
16771 struct glyph_string
*s
;
16773 s
->next
= s
->prev
= NULL
;
16774 append_glyph_string_lists (head
, tail
, s
, s
);
16778 /* Get face and two-byte form of character glyph GLYPH on frame F.
16779 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
16780 a pointer to a realized face that is ready for display. */
16782 static INLINE
struct face
*
16783 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
16785 struct glyph
*glyph
;
16791 xassert (glyph
->type
== CHAR_GLYPH
);
16792 face
= FACE_FROM_ID (f
, glyph
->face_id
);
16797 if (!glyph
->multibyte_p
)
16799 /* Unibyte case. We don't have to encode, but we have to make
16800 sure to use a face suitable for unibyte. */
16801 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
16803 else if (glyph
->u
.ch
< 128
16804 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
16806 /* Case of ASCII in a face known to fit ASCII. */
16807 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
16811 int c1
, c2
, charset
;
16813 /* Split characters into bytes. If c2 is -1 afterwards, C is
16814 really a one-byte character so that byte1 is zero. */
16815 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
16817 STORE_XCHAR2B (char2b
, c1
, c2
);
16819 STORE_XCHAR2B (char2b
, 0, c1
);
16821 /* Maybe encode the character in *CHAR2B. */
16822 if (charset
!= CHARSET_ASCII
)
16824 struct font_info
*font_info
16825 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
16828 = FRAME_RIF (f
)->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
16832 /* Make sure X resources of the face are allocated. */
16833 xassert (face
!= NULL
);
16834 PREPARE_FACE_FOR_DISPLAY (f
, face
);
16839 /* Fill glyph string S with composition components specified by S->cmp.
16841 FACES is an array of faces for all components of this composition.
16842 S->gidx is the index of the first component for S.
16843 OVERLAPS_P non-zero means S should draw the foreground only, and
16844 use its physical height for clipping.
16846 Value is the index of a component not in S. */
16849 fill_composite_glyph_string (s
, faces
, overlaps_p
)
16850 struct glyph_string
*s
;
16851 struct face
**faces
;
16858 s
->for_overlaps_p
= overlaps_p
;
16860 s
->face
= faces
[s
->gidx
];
16861 s
->font
= s
->face
->font
;
16862 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
16864 /* For all glyphs of this composition, starting at the offset
16865 S->gidx, until we reach the end of the definition or encounter a
16866 glyph that requires the different face, add it to S. */
16868 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
16871 /* All glyph strings for the same composition has the same width,
16872 i.e. the width set for the first component of the composition. */
16874 s
->width
= s
->first_glyph
->pixel_width
;
16876 /* If the specified font could not be loaded, use the frame's
16877 default font, but record the fact that we couldn't load it in
16878 the glyph string so that we can draw rectangles for the
16879 characters of the glyph string. */
16880 if (s
->font
== NULL
)
16882 s
->font_not_found_p
= 1;
16883 s
->font
= FRAME_FONT (s
->f
);
16886 /* Adjust base line for subscript/superscript text. */
16887 s
->ybase
+= s
->first_glyph
->voffset
;
16889 xassert (s
->face
&& s
->face
->gc
);
16891 /* This glyph string must always be drawn with 16-bit functions. */
16894 return s
->gidx
+ s
->nchars
;
16898 /* Fill glyph string S from a sequence of character glyphs.
16900 FACE_ID is the face id of the string. START is the index of the
16901 first glyph to consider, END is the index of the last + 1.
16902 OVERLAPS_P non-zero means S should draw the foreground only, and
16903 use its physical height for clipping.
16905 Value is the index of the first glyph not in S. */
16908 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
16909 struct glyph_string
*s
;
16911 int start
, end
, overlaps_p
;
16913 struct glyph
*glyph
, *last
;
16915 int glyph_not_available_p
;
16917 xassert (s
->f
== XFRAME (s
->w
->frame
));
16918 xassert (s
->nchars
== 0);
16919 xassert (start
>= 0 && end
> start
);
16921 s
->for_overlaps_p
= overlaps_p
,
16922 glyph
= s
->row
->glyphs
[s
->area
] + start
;
16923 last
= s
->row
->glyphs
[s
->area
] + end
;
16924 voffset
= glyph
->voffset
;
16926 glyph_not_available_p
= glyph
->glyph_not_available_p
;
16928 while (glyph
< last
16929 && glyph
->type
== CHAR_GLYPH
16930 && glyph
->voffset
== voffset
16931 /* Same face id implies same font, nowadays. */
16932 && glyph
->face_id
== face_id
16933 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
16937 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
16938 s
->char2b
+ s
->nchars
,
16940 s
->two_byte_p
= two_byte_p
;
16942 xassert (s
->nchars
<= end
- start
);
16943 s
->width
+= glyph
->pixel_width
;
16947 s
->font
= s
->face
->font
;
16948 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
16950 /* If the specified font could not be loaded, use the frame's font,
16951 but record the fact that we couldn't load it in
16952 S->font_not_found_p so that we can draw rectangles for the
16953 characters of the glyph string. */
16954 if (s
->font
== NULL
|| glyph_not_available_p
)
16956 s
->font_not_found_p
= 1;
16957 s
->font
= FRAME_FONT (s
->f
);
16960 /* Adjust base line for subscript/superscript text. */
16961 s
->ybase
+= voffset
;
16963 xassert (s
->face
&& s
->face
->gc
);
16964 return glyph
- s
->row
->glyphs
[s
->area
];
16968 /* Fill glyph string S from image glyph S->first_glyph. */
16971 fill_image_glyph_string (s
)
16972 struct glyph_string
*s
;
16974 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
16975 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
16977 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
16978 s
->font
= s
->face
->font
;
16979 s
->width
= s
->first_glyph
->pixel_width
;
16981 /* Adjust base line for subscript/superscript text. */
16982 s
->ybase
+= s
->first_glyph
->voffset
;
16986 /* Fill glyph string S from a sequence of stretch glyphs.
16988 ROW is the glyph row in which the glyphs are found, AREA is the
16989 area within the row. START is the index of the first glyph to
16990 consider, END is the index of the last + 1.
16992 Value is the index of the first glyph not in S. */
16995 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
16996 struct glyph_string
*s
;
16997 struct glyph_row
*row
;
16998 enum glyph_row_area area
;
17001 struct glyph
*glyph
, *last
;
17002 int voffset
, face_id
;
17004 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
17006 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17007 last
= s
->row
->glyphs
[s
->area
] + end
;
17008 face_id
= glyph
->face_id
;
17009 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
17010 s
->font
= s
->face
->font
;
17011 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17012 s
->width
= glyph
->pixel_width
;
17013 voffset
= glyph
->voffset
;
17017 && glyph
->type
== STRETCH_GLYPH
17018 && glyph
->voffset
== voffset
17019 && glyph
->face_id
== face_id
);
17021 s
->width
+= glyph
->pixel_width
;
17023 /* Adjust base line for subscript/superscript text. */
17024 s
->ybase
+= voffset
;
17026 /* The case that face->gc == 0 is handled when drawing the glyph
17027 string by calling PREPARE_FACE_FOR_DISPLAY. */
17029 return glyph
- s
->row
->glyphs
[s
->area
];
17034 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
17035 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
17036 assumed to be zero. */
17039 x_get_glyph_overhangs (glyph
, f
, left
, right
)
17040 struct glyph
*glyph
;
17044 *left
= *right
= 0;
17046 if (glyph
->type
== CHAR_GLYPH
)
17050 struct font_info
*font_info
;
17054 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
17056 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17057 if (font
/* ++KFS: Should this be font_info ? */
17058 && (pcm
= FRAME_RIF (f
)->per_char_metric (font
, &char2b
, glyph
->font_type
)))
17060 if (pcm
->rbearing
> pcm
->width
)
17061 *right
= pcm
->rbearing
- pcm
->width
;
17062 if (pcm
->lbearing
< 0)
17063 *left
= -pcm
->lbearing
;
17069 /* Return the index of the first glyph preceding glyph string S that
17070 is overwritten by S because of S's left overhang. Value is -1
17071 if no glyphs are overwritten. */
17074 left_overwritten (s
)
17075 struct glyph_string
*s
;
17079 if (s
->left_overhang
)
17082 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17083 int first
= s
->first_glyph
- glyphs
;
17085 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
17086 x
-= glyphs
[i
].pixel_width
;
17097 /* Return the index of the first glyph preceding glyph string S that
17098 is overwriting S because of its right overhang. Value is -1 if no
17099 glyph in front of S overwrites S. */
17102 left_overwriting (s
)
17103 struct glyph_string
*s
;
17106 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17107 int first
= s
->first_glyph
- glyphs
;
17111 for (i
= first
- 1; i
>= 0; --i
)
17114 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17117 x
-= glyphs
[i
].pixel_width
;
17124 /* Return the index of the last glyph following glyph string S that is
17125 not overwritten by S because of S's right overhang. Value is -1 if
17126 no such glyph is found. */
17129 right_overwritten (s
)
17130 struct glyph_string
*s
;
17134 if (s
->right_overhang
)
17137 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17138 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17139 int end
= s
->row
->used
[s
->area
];
17141 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
17142 x
+= glyphs
[i
].pixel_width
;
17151 /* Return the index of the last glyph following glyph string S that
17152 overwrites S because of its left overhang. Value is negative
17153 if no such glyph is found. */
17156 right_overwriting (s
)
17157 struct glyph_string
*s
;
17160 int end
= s
->row
->used
[s
->area
];
17161 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17162 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17166 for (i
= first
; i
< end
; ++i
)
17169 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17172 x
+= glyphs
[i
].pixel_width
;
17179 /* Get face and two-byte form of character C in face FACE_ID on frame
17180 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
17181 means we want to display multibyte text. DISPLAY_P non-zero means
17182 make sure that X resources for the face returned are allocated.
17183 Value is a pointer to a realized face that is ready for display if
17184 DISPLAY_P is non-zero. */
17186 static INLINE
struct face
*
17187 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
17191 int multibyte_p
, display_p
;
17193 struct face
*face
= FACE_FROM_ID (f
, face_id
);
17197 /* Unibyte case. We don't have to encode, but we have to make
17198 sure to use a face suitable for unibyte. */
17199 STORE_XCHAR2B (char2b
, 0, c
);
17200 face_id
= FACE_FOR_CHAR (f
, face
, c
);
17201 face
= FACE_FROM_ID (f
, face_id
);
17203 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
17205 /* Case of ASCII in a face known to fit ASCII. */
17206 STORE_XCHAR2B (char2b
, 0, c
);
17210 int c1
, c2
, charset
;
17212 /* Split characters into bytes. If c2 is -1 afterwards, C is
17213 really a one-byte character so that byte1 is zero. */
17214 SPLIT_CHAR (c
, charset
, c1
, c2
);
17216 STORE_XCHAR2B (char2b
, c1
, c2
);
17218 STORE_XCHAR2B (char2b
, 0, c1
);
17220 /* Maybe encode the character in *CHAR2B. */
17221 if (face
->font
!= NULL
)
17223 struct font_info
*font_info
17224 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17226 FRAME_RIF (f
)->encode_char (c
, char2b
, font_info
, 0);
17230 /* Make sure X resources of the face are allocated. */
17231 #ifdef HAVE_X_WINDOWS
17235 xassert (face
!= NULL
);
17236 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17243 /* Set background width of glyph string S. START is the index of the
17244 first glyph following S. LAST_X is the right-most x-position + 1
17245 in the drawing area. */
17248 set_glyph_string_background_width (s
, start
, last_x
)
17249 struct glyph_string
*s
;
17253 /* If the face of this glyph string has to be drawn to the end of
17254 the drawing area, set S->extends_to_end_of_line_p. */
17255 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
17257 if (start
== s
->row
->used
[s
->area
]
17258 && s
->area
== TEXT_AREA
17259 && ((s
->hl
== DRAW_NORMAL_TEXT
17260 && (s
->row
->fill_line_p
17261 || s
->face
->background
!= default_face
->background
17262 || s
->face
->stipple
!= default_face
->stipple
17263 || s
->row
->mouse_face_p
))
17264 || s
->hl
== DRAW_MOUSE_FACE
17265 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
17266 && s
->row
->fill_line_p
)))
17267 s
->extends_to_end_of_line_p
= 1;
17269 /* If S extends its face to the end of the line, set its
17270 background_width to the distance to the right edge of the drawing
17272 if (s
->extends_to_end_of_line_p
)
17273 s
->background_width
= last_x
- s
->x
+ 1;
17275 s
->background_width
= s
->width
;
17279 /* Compute overhangs and x-positions for glyph string S and its
17280 predecessors, or successors. X is the starting x-position for S.
17281 BACKWARD_P non-zero means process predecessors. */
17284 compute_overhangs_and_x (s
, x
, backward_p
)
17285 struct glyph_string
*s
;
17293 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
17294 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
17304 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
17305 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
17315 /* The following macros are only called from draw_glyphs below.
17316 They reference the following parameters of that function directly:
17317 `w', `row', `area', and `overlap_p'
17318 as well as the following local variables:
17319 `s', `f', and `hdc' (in W32) */
17322 /* On W32, silently add local `hdc' variable to argument list of
17323 init_glyph_string. */
17324 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17325 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
17327 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17328 init_glyph_string (s, char2b, w, row, area, start, hl)
17331 /* Add a glyph string for a stretch glyph to the list of strings
17332 between HEAD and TAIL. START is the index of the stretch glyph in
17333 row area AREA of glyph row ROW. END is the index of the last glyph
17334 in that glyph row area. X is the current output position assigned
17335 to the new glyph string constructed. HL overrides that face of the
17336 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17337 is the right-most x-position of the drawing area. */
17339 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
17340 and below -- keep them on one line. */
17341 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17344 s = (struct glyph_string *) alloca (sizeof *s); \
17345 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17346 START = fill_stretch_glyph_string (s, row, area, START, END); \
17347 append_glyph_string (&HEAD, &TAIL, s); \
17353 /* Add a glyph string for an image glyph to the list of strings
17354 between HEAD and TAIL. START is the index of the image glyph in
17355 row area AREA of glyph row ROW. END is the index of the last glyph
17356 in that glyph row area. X is the current output position assigned
17357 to the new glyph string constructed. HL overrides that face of the
17358 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17359 is the right-most x-position of the drawing area. */
17361 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17364 s = (struct glyph_string *) alloca (sizeof *s); \
17365 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17366 fill_image_glyph_string (s); \
17367 append_glyph_string (&HEAD, &TAIL, s); \
17374 /* Add a glyph string for a sequence of character glyphs to the list
17375 of strings between HEAD and TAIL. START is the index of the first
17376 glyph in row area AREA of glyph row ROW that is part of the new
17377 glyph string. END is the index of the last glyph in that glyph row
17378 area. X is the current output position assigned to the new glyph
17379 string constructed. HL overrides that face of the glyph; e.g. it
17380 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
17381 right-most x-position of the drawing area. */
17383 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
17389 c = (row)->glyphs[area][START].u.ch; \
17390 face_id = (row)->glyphs[area][START].face_id; \
17392 s = (struct glyph_string *) alloca (sizeof *s); \
17393 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
17394 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
17395 append_glyph_string (&HEAD, &TAIL, s); \
17397 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
17402 /* Add a glyph string for a composite sequence to the list of strings
17403 between HEAD and TAIL. START is the index of the first glyph in
17404 row area AREA of glyph row ROW that is part of the new glyph
17405 string. END is the index of the last glyph in that glyph row area.
17406 X is the current output position assigned to the new glyph string
17407 constructed. HL overrides that face of the glyph; e.g. it is
17408 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
17409 x-position of the drawing area. */
17411 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17413 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
17414 int face_id = (row)->glyphs[area][START].face_id; \
17415 struct face *base_face = FACE_FROM_ID (f, face_id); \
17416 struct composition *cmp = composition_table[cmp_id]; \
17417 int glyph_len = cmp->glyph_len; \
17419 struct face **faces; \
17420 struct glyph_string *first_s = NULL; \
17423 base_face = base_face->ascii_face; \
17424 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
17425 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
17426 /* At first, fill in `char2b' and `faces'. */ \
17427 for (n = 0; n < glyph_len; n++) \
17429 int c = COMPOSITION_GLYPH (cmp, n); \
17430 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
17431 faces[n] = FACE_FROM_ID (f, this_face_id); \
17432 get_char_face_and_encoding (f, c, this_face_id, \
17433 char2b + n, 1, 1); \
17436 /* Make glyph_strings for each glyph sequence that is drawable by \
17437 the same face, and append them to HEAD/TAIL. */ \
17438 for (n = 0; n < cmp->glyph_len;) \
17440 s = (struct glyph_string *) alloca (sizeof *s); \
17441 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
17442 append_glyph_string (&(HEAD), &(TAIL), s); \
17450 n = fill_composite_glyph_string (s, faces, overlaps_p); \
17458 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
17459 of AREA of glyph row ROW on window W between indices START and END.
17460 HL overrides the face for drawing glyph strings, e.g. it is
17461 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
17462 x-positions of the drawing area.
17464 This is an ugly monster macro construct because we must use alloca
17465 to allocate glyph strings (because draw_glyphs can be called
17466 asynchronously). */
17468 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
17471 HEAD = TAIL = NULL; \
17472 while (START < END) \
17474 struct glyph *first_glyph = (row)->glyphs[area] + START; \
17475 switch (first_glyph->type) \
17478 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
17482 case COMPOSITE_GLYPH: \
17483 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
17487 case STRETCH_GLYPH: \
17488 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
17492 case IMAGE_GLYPH: \
17493 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
17501 set_glyph_string_background_width (s, START, LAST_X); \
17508 /* Draw glyphs between START and END in AREA of ROW on window W,
17509 starting at x-position X. X is relative to AREA in W. HL is a
17510 face-override with the following meaning:
17512 DRAW_NORMAL_TEXT draw normally
17513 DRAW_CURSOR draw in cursor face
17514 DRAW_MOUSE_FACE draw in mouse face.
17515 DRAW_INVERSE_VIDEO draw in mode line face
17516 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
17517 DRAW_IMAGE_RAISED draw an image with a raised relief around it
17519 If OVERLAPS_P is non-zero, draw only the foreground of characters
17520 and clip to the physical height of ROW.
17522 Value is the x-position reached, relative to AREA of W. */
17525 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
17528 struct glyph_row
*row
;
17529 enum glyph_row_area area
;
17531 enum draw_glyphs_face hl
;
17534 struct glyph_string
*head
, *tail
;
17535 struct glyph_string
*s
;
17536 int last_x
, area_width
;
17539 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17542 ALLOCATE_HDC (hdc
, f
);
17544 /* Let's rather be paranoid than getting a SEGV. */
17545 end
= min (end
, row
->used
[area
]);
17546 start
= max (0, start
);
17547 start
= min (end
, start
);
17549 /* Translate X to frame coordinates. Set last_x to the right
17550 end of the drawing area. */
17551 if (row
->full_width_p
)
17553 /* X is relative to the left edge of W, without scroll bars
17555 x
+= WINDOW_LEFT_EDGE_X (w
);
17556 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
17560 int area_left
= window_box_left (w
, area
);
17562 area_width
= window_box_width (w
, area
);
17563 last_x
= area_left
+ area_width
;
17566 /* Build a doubly-linked list of glyph_string structures between
17567 head and tail from what we have to draw. Note that the macro
17568 BUILD_GLYPH_STRINGS will modify its start parameter. That's
17569 the reason we use a separate variable `i'. */
17571 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
17573 x_reached
= tail
->x
+ tail
->background_width
;
17577 /* If there are any glyphs with lbearing < 0 or rbearing > width in
17578 the row, redraw some glyphs in front or following the glyph
17579 strings built above. */
17580 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
17583 struct glyph_string
*h
, *t
;
17585 /* Compute overhangs for all glyph strings. */
17586 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
17587 for (s
= head
; s
; s
= s
->next
)
17588 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
17590 /* Prepend glyph strings for glyphs in front of the first glyph
17591 string that are overwritten because of the first glyph
17592 string's left overhang. The background of all strings
17593 prepended must be drawn because the first glyph string
17595 i
= left_overwritten (head
);
17599 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
17600 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
17602 compute_overhangs_and_x (t
, head
->x
, 1);
17603 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
17606 /* Prepend glyph strings for glyphs in front of the first glyph
17607 string that overwrite that glyph string because of their
17608 right overhang. For these strings, only the foreground must
17609 be drawn, because it draws over the glyph string at `head'.
17610 The background must not be drawn because this would overwrite
17611 right overhangs of preceding glyphs for which no glyph
17613 i
= left_overwriting (head
);
17616 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
17617 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
17618 for (s
= h
; s
; s
= s
->next
)
17619 s
->background_filled_p
= 1;
17620 compute_overhangs_and_x (t
, head
->x
, 1);
17621 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
17624 /* Append glyphs strings for glyphs following the last glyph
17625 string tail that are overwritten by tail. The background of
17626 these strings has to be drawn because tail's foreground draws
17628 i
= right_overwritten (tail
);
17631 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
17632 DRAW_NORMAL_TEXT
, x
, last_x
);
17633 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
17634 append_glyph_string_lists (&head
, &tail
, h
, t
);
17637 /* Append glyph strings for glyphs following the last glyph
17638 string tail that overwrite tail. The foreground of such
17639 glyphs has to be drawn because it writes into the background
17640 of tail. The background must not be drawn because it could
17641 paint over the foreground of following glyphs. */
17642 i
= right_overwriting (tail
);
17645 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
17646 DRAW_NORMAL_TEXT
, x
, last_x
);
17647 for (s
= h
; s
; s
= s
->next
)
17648 s
->background_filled_p
= 1;
17649 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
17650 append_glyph_string_lists (&head
, &tail
, h
, t
);
17654 /* Draw all strings. */
17655 for (s
= head
; s
; s
= s
->next
)
17656 FRAME_RIF (f
)->draw_glyph_string (s
);
17658 if (area
== TEXT_AREA
17659 && !row
->full_width_p
17660 /* When drawing overlapping rows, only the glyph strings'
17661 foreground is drawn, which doesn't erase a cursor
17665 int x0
= head
? head
->x
: x
;
17666 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
17668 int text_left
= window_box_left (w
, TEXT_AREA
);
17672 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
17673 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
17676 /* Value is the x-position up to which drawn, relative to AREA of W.
17677 This doesn't include parts drawn because of overhangs. */
17678 if (row
->full_width_p
)
17679 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
17681 x_reached
-= window_box_left (w
, area
);
17683 RELEASE_HDC (hdc
, f
);
17689 /* Store one glyph for IT->char_to_display in IT->glyph_row.
17690 Called from x_produce_glyphs when IT->glyph_row is non-null. */
17696 struct glyph
*glyph
;
17697 enum glyph_row_area area
= it
->area
;
17699 xassert (it
->glyph_row
);
17700 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
17702 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
17703 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
17705 glyph
->charpos
= CHARPOS (it
->position
);
17706 glyph
->object
= it
->object
;
17707 glyph
->pixel_width
= it
->pixel_width
;
17708 glyph
->ascent
= it
->ascent
;
17709 glyph
->descent
= it
->descent
;
17710 glyph
->voffset
= it
->voffset
;
17711 glyph
->type
= CHAR_GLYPH
;
17712 glyph
->multibyte_p
= it
->multibyte_p
;
17713 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
17714 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
17715 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
17716 || it
->phys_descent
> it
->descent
);
17717 glyph
->padding_p
= 0;
17718 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
17719 glyph
->face_id
= it
->face_id
;
17720 glyph
->u
.ch
= it
->char_to_display
;
17721 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
17722 ++it
->glyph_row
->used
[area
];
17726 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
17727 Called from x_produce_glyphs when IT->glyph_row is non-null. */
17730 append_composite_glyph (it
)
17733 struct glyph
*glyph
;
17734 enum glyph_row_area area
= it
->area
;
17736 xassert (it
->glyph_row
);
17738 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
17739 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
17741 glyph
->charpos
= CHARPOS (it
->position
);
17742 glyph
->object
= it
->object
;
17743 glyph
->pixel_width
= it
->pixel_width
;
17744 glyph
->ascent
= it
->ascent
;
17745 glyph
->descent
= it
->descent
;
17746 glyph
->voffset
= it
->voffset
;
17747 glyph
->type
= COMPOSITE_GLYPH
;
17748 glyph
->multibyte_p
= it
->multibyte_p
;
17749 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
17750 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
17751 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
17752 || it
->phys_descent
> it
->descent
);
17753 glyph
->padding_p
= 0;
17754 glyph
->glyph_not_available_p
= 0;
17755 glyph
->face_id
= it
->face_id
;
17756 glyph
->u
.cmp_id
= it
->cmp_id
;
17757 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
17758 ++it
->glyph_row
->used
[area
];
17763 /* Change IT->ascent and IT->height according to the setting of
17767 take_vertical_position_into_account (it
)
17772 if (it
->voffset
< 0)
17773 /* Increase the ascent so that we can display the text higher
17775 it
->ascent
+= abs (it
->voffset
);
17777 /* Increase the descent so that we can display the text lower
17779 it
->descent
+= it
->voffset
;
17784 /* Produce glyphs/get display metrics for the image IT is loaded with.
17785 See the description of struct display_iterator in dispextern.h for
17786 an overview of struct display_iterator. */
17789 produce_image_glyph (it
)
17794 int face_ascent
, glyph_ascent
;
17796 xassert (it
->what
== IT_IMAGE
);
17798 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17799 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
17802 /* Make sure X resources of the face and image are loaded. */
17803 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
17804 prepare_image_for_display (it
->f
, img
);
17806 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
);
17807 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
17808 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
17810 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
17811 face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
17812 if (face_ascent
> it
->ascent
)
17813 it
->ascent
= it
->phys_ascent
= face_ascent
;
17817 if (face
->box
!= FACE_NO_BOX
)
17819 if (face
->box_line_width
> 0)
17821 it
->ascent
+= face
->box_line_width
;
17822 it
->descent
+= face
->box_line_width
;
17825 if (it
->start_of_box_run_p
)
17826 it
->pixel_width
+= abs (face
->box_line_width
);
17827 if (it
->end_of_box_run_p
)
17828 it
->pixel_width
+= abs (face
->box_line_width
);
17831 take_vertical_position_into_account (it
);
17835 struct glyph
*glyph
;
17836 enum glyph_row_area area
= it
->area
;
17838 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
17839 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
17841 glyph
->charpos
= CHARPOS (it
->position
);
17842 glyph
->object
= it
->object
;
17843 glyph
->pixel_width
= it
->pixel_width
;
17844 glyph
->ascent
= glyph_ascent
;
17845 glyph
->descent
= it
->descent
;
17846 glyph
->voffset
= it
->voffset
;
17847 glyph
->type
= IMAGE_GLYPH
;
17848 glyph
->multibyte_p
= it
->multibyte_p
;
17849 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
17850 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
17851 glyph
->overlaps_vertically_p
= 0;
17852 glyph
->padding_p
= 0;
17853 glyph
->glyph_not_available_p
= 0;
17854 glyph
->face_id
= it
->face_id
;
17855 glyph
->u
.img_id
= img
->id
;
17856 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
17857 ++it
->glyph_row
->used
[area
];
17863 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
17864 of the glyph, WIDTH and HEIGHT are the width and height of the
17865 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
17868 append_stretch_glyph (it
, object
, width
, height
, ascent
)
17870 Lisp_Object object
;
17874 struct glyph
*glyph
;
17875 enum glyph_row_area area
= it
->area
;
17877 xassert (ascent
>= 0 && ascent
<= height
);
17879 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
17880 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
17882 glyph
->charpos
= CHARPOS (it
->position
);
17883 glyph
->object
= object
;
17884 glyph
->pixel_width
= width
;
17885 glyph
->ascent
= ascent
;
17886 glyph
->descent
= height
- ascent
;
17887 glyph
->voffset
= it
->voffset
;
17888 glyph
->type
= STRETCH_GLYPH
;
17889 glyph
->multibyte_p
= it
->multibyte_p
;
17890 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
17891 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
17892 glyph
->overlaps_vertically_p
= 0;
17893 glyph
->padding_p
= 0;
17894 glyph
->glyph_not_available_p
= 0;
17895 glyph
->face_id
= it
->face_id
;
17896 glyph
->u
.stretch
.ascent
= ascent
;
17897 glyph
->u
.stretch
.height
= height
;
17898 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
17899 ++it
->glyph_row
->used
[area
];
17904 /* Calculate a width or height in pixels from a specification using
17905 the following elements:
17908 NUM - a (fractional) multiple of the default font width/height
17909 (NUM) - specifies exactly NUM pixels
17910 UNIT - a fixed number of pixels, see below.
17911 ELEMENT - size of a display element in pixels, see below.
17912 (NUM . SPEC) - equals NUM * SPEC
17913 (+ SPEC SPEC ...) - add pixel values
17914 (- SPEC SPEC ...) - subtract pixel values
17915 (- SPEC) - negate pixel value
17918 INT or FLOAT - a number constant
17919 SYMBOL - use symbol's (buffer local) variable binding.
17922 in - pixels per inch *)
17923 mm - pixels per 1/1000 meter *)
17924 cm - pixels per 1/100 meter *)
17925 width - width of current font in pixels.
17926 height - height of current font in pixels.
17928 *) using the ratio(s) defined in display-pixels-per-inch.
17932 left-fringe - left fringe width in pixels
17933 (left-fringe . nil) - left fringe width if inside margins, else 0
17934 (left-fringe . t) - left fringe width if outside margins, else 0
17936 right-fringe - right fringe width in pixels
17937 (right-fringe . nil) - right fringe width if inside margins, else 0
17938 (right-fringe . t) - right fringe width if outside margins, else 0
17940 left-margin - left margin width in pixels
17941 right-margin - right margin width in pixels
17943 scroll-bar - scroll-bar area width in pixels
17944 (scroll-bar . left) - scroll-bar width if on left, else 0
17945 (scroll-bar . right) - scroll-bar width if on right, else 0
17949 Pixels corresponding to 5 inches:
17952 Total width of non-text areas on left side of window:
17953 (+ left-fringe left-margin (scroll-bar . left))
17955 Total width of fringes if inside display margins:
17956 (+ (left-fringe) (right-fringe))
17958 Width of left margin minus width of 1 character in the default font:
17961 Width of left margin minus width of 2 characters in the current font:
17962 (- left-margin (2 . width))
17964 Width of left fringe plus left margin minus one pixel:
17965 (- (+ left-fringe left-margin) (1))
17966 (+ left-fringe left-margin (- (1)))
17967 (+ left-fringe left-margin (-1))
17971 #define NUMVAL(X) \
17972 ((INTEGERP (X) || FLOATP (X)) \
17977 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
)
17986 #define OK_PIXELS(val) ((*res = (val)), 1)
17988 if (SYMBOLP (prop
))
17990 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
17992 char *unit
= SDATA (SYMBOL_NAME (prop
));
17994 if (unit
[0] == 'i' && unit
[1] == 'n')
17996 else if (unit
[0] == 'm' && unit
[1] == 'm')
17998 else if (unit
[0] == 'c' && unit
[1] == 'm')
18005 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18006 || (CONSP (Vdisplay_pixels_per_inch
)
18008 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18009 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18011 return OK_PIXELS (ppi
/ pixels
);
18017 if (EQ (prop
, Qheight
))
18018 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
18019 if (EQ (prop
, Qwidth
))
18020 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
18021 if (EQ (prop
, Qleft_fringe
))
18022 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18023 if (EQ (prop
, Qright_fringe
))
18024 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18025 if (EQ (prop
, Qleft_margin
))
18026 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18027 if (EQ (prop
, Qright_margin
))
18028 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18029 if (EQ (prop
, Qscroll_bar
))
18030 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18032 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18035 if (INTEGERP (prop
) || FLOATP (prop
))
18037 int base_unit
= (width_p
18038 ? FRAME_COLUMN_WIDTH (it
->f
)
18039 : FRAME_LINE_HEIGHT (it
->f
));
18040 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18045 Lisp_Object car
= XCAR (prop
);
18046 Lisp_Object cdr
= XCDR (prop
);
18050 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18056 while (CONSP (cdr
))
18058 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
), font
, width_p
))
18061 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18066 if (EQ (car
, Qminus
))
18068 return OK_PIXELS (pixels
);
18071 if (EQ (car
, Qleft_fringe
))
18072 return OK_PIXELS ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18074 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
18076 if (EQ (car
, Qright_fringe
))
18077 return OK_PIXELS ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18079 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18081 if (EQ (car
, Qscroll_bar
))
18082 return OK_PIXELS ((WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18083 == EQ (cdr
, Qleft
))
18084 ? WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
)
18087 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18090 if (INTEGERP (car
) || FLOATP (car
))
18093 pixels
= XFLOATINT (car
);
18095 return OK_PIXELS (pixels
);
18096 if (calc_pixel_width_or_height (&fact
, it
, cdr
, font
, width_p
))
18097 return OK_PIXELS (pixels
* fact
);
18107 /* Produce a stretch glyph for iterator IT. IT->object is the value
18108 of the glyph property displayed. The value must be a list
18109 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
18112 1. `:width WIDTH' specifies that the space should be WIDTH *
18113 canonical char width wide. WIDTH may be an integer or floating
18116 2. `:relative-width FACTOR' specifies that the width of the stretch
18117 should be computed from the width of the first character having the
18118 `glyph' property, and should be FACTOR times that width.
18120 3. `:align-to HPOS' specifies that the space should be wide enough
18121 to reach HPOS, a value in canonical character units.
18123 Exactly one of the above pairs must be present.
18125 4. `:height HEIGHT' specifies that the height of the stretch produced
18126 should be HEIGHT, measured in canonical character units.
18128 5. `:relative-height FACTOR' specifies that the height of the
18129 stretch should be FACTOR times the height of the characters having
18130 the glyph property.
18132 Either none or exactly one of 4 or 5 must be present.
18134 6. `:ascent ASCENT' specifies that ASCENT percent of the height
18135 of the stretch should be used for the ascent of the stretch.
18136 ASCENT must be in the range 0 <= ASCENT <= 100. */
18139 produce_stretch_glyph (it
)
18142 /* (space :width WIDTH :height HEIGHT ...) */
18143 Lisp_Object prop
, plist
;
18144 int width
= 0, height
= 0;
18145 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
18148 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18149 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
18151 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18153 /* List should start with `space'. */
18154 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
18155 plist
= XCDR (it
->object
);
18157 /* Compute the width of the stretch. */
18158 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
18159 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1))
18161 /* Absolute width `:width WIDTH' specified and valid. */
18162 zero_width_ok_p
= 1;
18165 else if (prop
= Fplist_get (plist
, QCrelative_width
),
18168 /* Relative width `:relative-width FACTOR' specified and valid.
18169 Compute the width of the characters having the `glyph'
18172 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
18175 if (it
->multibyte_p
)
18177 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
18178 - IT_BYTEPOS (*it
));
18179 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
18182 it2
.c
= *p
, it2
.len
= 1;
18184 it2
.glyph_row
= NULL
;
18185 it2
.what
= IT_CHARACTER
;
18186 x_produce_glyphs (&it2
);
18187 width
= NUMVAL (prop
) * it2
.pixel_width
;
18189 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
18190 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1))
18192 width
= max (0, (int)tem
- it
->current_x
);
18193 zero_width_ok_p
= 1;
18196 /* Nothing specified -> width defaults to canonical char width. */
18197 width
= FRAME_COLUMN_WIDTH (it
->f
);
18199 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
18202 /* Compute height. */
18203 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
18204 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0))
18207 zero_height_ok_p
= 1;
18209 else if (prop
= Fplist_get (plist
, QCrelative_height
),
18211 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
18213 height
= FONT_HEIGHT (font
);
18215 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
18218 /* Compute percentage of height used for ascent. If
18219 `:ascent ASCENT' is present and valid, use that. Otherwise,
18220 derive the ascent from the font in use. */
18221 if (prop
= Fplist_get (plist
, QCascent
),
18222 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
18223 ascent
= height
* NUMVAL (prop
) / 100.0;
18224 else if (!NILP (prop
)
18225 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0))
18226 ascent
= min (max (0, (int)tem
), height
);
18228 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
18230 if (width
> 0 && height
> 0 && it
->glyph_row
)
18232 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
18233 if (!STRINGP (object
))
18234 object
= it
->w
->buffer
;
18235 append_stretch_glyph (it
, object
, width
, height
, ascent
);
18238 it
->pixel_width
= width
;
18239 it
->ascent
= it
->phys_ascent
= ascent
;
18240 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
18241 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
18243 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
18245 if (face
->box_line_width
> 0)
18247 it
->ascent
+= face
->box_line_width
;
18248 it
->descent
+= face
->box_line_width
;
18251 if (it
->start_of_box_run_p
)
18252 it
->pixel_width
+= abs (face
->box_line_width
);
18253 if (it
->end_of_box_run_p
)
18254 it
->pixel_width
+= abs (face
->box_line_width
);
18257 take_vertical_position_into_account (it
);
18261 Produce glyphs/get display metrics for the display element IT is
18262 loaded with. See the description of struct display_iterator in
18263 dispextern.h for an overview of struct display_iterator. */
18266 x_produce_glyphs (it
)
18269 it
->glyph_not_available_p
= 0;
18271 if (it
->what
== IT_CHARACTER
)
18275 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18277 int font_not_found_p
;
18278 struct font_info
*font_info
;
18279 int boff
; /* baseline offset */
18280 /* We may change it->multibyte_p upon unibyte<->multibyte
18281 conversion. So, save the current value now and restore it
18284 Note: It seems that we don't have to record multibyte_p in
18285 struct glyph because the character code itself tells if or
18286 not the character is multibyte. Thus, in the future, we must
18287 consider eliminating the field `multibyte_p' in the struct
18289 int saved_multibyte_p
= it
->multibyte_p
;
18291 /* Maybe translate single-byte characters to multibyte, or the
18293 it
->char_to_display
= it
->c
;
18294 if (!ASCII_BYTE_P (it
->c
))
18296 if (unibyte_display_via_language_environment
18297 && SINGLE_BYTE_CHAR_P (it
->c
)
18299 || !NILP (Vnonascii_translation_table
)))
18301 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
18302 it
->multibyte_p
= 1;
18303 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18304 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18306 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
18307 && !it
->multibyte_p
)
18309 it
->multibyte_p
= 1;
18310 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18311 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18315 /* Get font to use. Encode IT->char_to_display. */
18316 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
18317 &char2b
, it
->multibyte_p
, 0);
18320 /* When no suitable font found, use the default font. */
18321 font_not_found_p
= font
== NULL
;
18322 if (font_not_found_p
)
18324 font
= FRAME_FONT (it
->f
);
18325 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18330 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18331 boff
= font_info
->baseline_offset
;
18332 if (font_info
->vertical_centering
)
18333 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18336 if (it
->char_to_display
>= ' '
18337 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
18339 /* Either unibyte or ASCII. */
18344 pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
18345 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
18346 it
->ascent
= FONT_BASE (font
) + boff
;
18347 it
->descent
= FONT_DESCENT (font
) - boff
;
18351 it
->phys_ascent
= pcm
->ascent
+ boff
;
18352 it
->phys_descent
= pcm
->descent
- boff
;
18353 it
->pixel_width
= pcm
->width
;
18357 it
->glyph_not_available_p
= 1;
18358 it
->phys_ascent
= FONT_BASE (font
) + boff
;
18359 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18360 it
->pixel_width
= FONT_WIDTH (font
);
18363 /* If this is a space inside a region of text with
18364 `space-width' property, change its width. */
18365 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
18367 it
->pixel_width
*= XFLOATINT (it
->space_width
);
18369 /* If face has a box, add the box thickness to the character
18370 height. If character has a box line to the left and/or
18371 right, add the box line width to the character's width. */
18372 if (face
->box
!= FACE_NO_BOX
)
18374 int thick
= face
->box_line_width
;
18378 it
->ascent
+= thick
;
18379 it
->descent
+= thick
;
18384 if (it
->start_of_box_run_p
)
18385 it
->pixel_width
+= thick
;
18386 if (it
->end_of_box_run_p
)
18387 it
->pixel_width
+= thick
;
18390 /* If face has an overline, add the height of the overline
18391 (1 pixel) and a 1 pixel margin to the character height. */
18392 if (face
->overline_p
)
18395 take_vertical_position_into_account (it
);
18397 /* If we have to actually produce glyphs, do it. */
18402 /* Translate a space with a `space-width' property
18403 into a stretch glyph. */
18404 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
18405 / FONT_HEIGHT (font
));
18406 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
18407 it
->ascent
+ it
->descent
, ascent
);
18412 /* If characters with lbearing or rbearing are displayed
18413 in this line, record that fact in a flag of the
18414 glyph row. This is used to optimize X output code. */
18415 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
18416 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
18419 else if (it
->char_to_display
== '\n')
18421 /* A newline has no width but we need the height of the line. */
18422 it
->pixel_width
= 0;
18424 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
18425 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18427 if (face
->box
!= FACE_NO_BOX
18428 && face
->box_line_width
> 0)
18430 it
->ascent
+= face
->box_line_width
;
18431 it
->descent
+= face
->box_line_width
;
18434 else if (it
->char_to_display
== '\t')
18436 int tab_width
= it
->tab_width
* FRAME_COLUMN_WIDTH (it
->f
);
18437 int x
= it
->current_x
+ it
->continuation_lines_width
;
18438 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
18440 /* If the distance from the current position to the next tab
18441 stop is less than a canonical character width, use the
18442 tab stop after that. */
18443 if (next_tab_x
- x
< FRAME_COLUMN_WIDTH (it
->f
))
18444 next_tab_x
+= tab_width
;
18446 it
->pixel_width
= next_tab_x
- x
;
18448 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
18449 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18453 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
18454 it
->ascent
+ it
->descent
, it
->ascent
);
18459 /* A multi-byte character. Assume that the display width of the
18460 character is the width of the character multiplied by the
18461 width of the font. */
18463 /* If we found a font, this font should give us the right
18464 metrics. If we didn't find a font, use the frame's
18465 default font and calculate the width of the character
18466 from the charset width; this is what old redisplay code
18469 pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
18470 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
18472 if (font_not_found_p
|| !pcm
)
18474 int charset
= CHAR_CHARSET (it
->char_to_display
);
18476 it
->glyph_not_available_p
= 1;
18477 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
18478 * CHARSET_WIDTH (charset
));
18479 it
->phys_ascent
= FONT_BASE (font
) + boff
;
18480 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18484 it
->pixel_width
= pcm
->width
;
18485 it
->phys_ascent
= pcm
->ascent
+ boff
;
18486 it
->phys_descent
= pcm
->descent
- boff
;
18488 && (pcm
->lbearing
< 0
18489 || pcm
->rbearing
> pcm
->width
))
18490 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
18493 it
->ascent
= FONT_BASE (font
) + boff
;
18494 it
->descent
= FONT_DESCENT (font
) - boff
;
18495 if (face
->box
!= FACE_NO_BOX
)
18497 int thick
= face
->box_line_width
;
18501 it
->ascent
+= thick
;
18502 it
->descent
+= thick
;
18507 if (it
->start_of_box_run_p
)
18508 it
->pixel_width
+= thick
;
18509 if (it
->end_of_box_run_p
)
18510 it
->pixel_width
+= thick
;
18513 /* If face has an overline, add the height of the overline
18514 (1 pixel) and a 1 pixel margin to the character height. */
18515 if (face
->overline_p
)
18518 take_vertical_position_into_account (it
);
18523 it
->multibyte_p
= saved_multibyte_p
;
18525 else if (it
->what
== IT_COMPOSITION
)
18527 /* Note: A composition is represented as one glyph in the
18528 glyph matrix. There are no padding glyphs. */
18531 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18533 int font_not_found_p
;
18534 struct font_info
*font_info
;
18535 int boff
; /* baseline offset */
18536 struct composition
*cmp
= composition_table
[it
->cmp_id
];
18538 /* Maybe translate single-byte characters to multibyte. */
18539 it
->char_to_display
= it
->c
;
18540 if (unibyte_display_via_language_environment
18541 && SINGLE_BYTE_CHAR_P (it
->c
)
18544 && !NILP (Vnonascii_translation_table
))))
18546 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
18549 /* Get face and font to use. Encode IT->char_to_display. */
18550 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18551 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18552 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
18553 &char2b
, it
->multibyte_p
, 0);
18556 /* When no suitable font found, use the default font. */
18557 font_not_found_p
= font
== NULL
;
18558 if (font_not_found_p
)
18560 font
= FRAME_FONT (it
->f
);
18561 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18566 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18567 boff
= font_info
->baseline_offset
;
18568 if (font_info
->vertical_centering
)
18569 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18572 /* There are no padding glyphs, so there is only one glyph to
18573 produce for the composition. Important is that pixel_width,
18574 ascent and descent are the values of what is drawn by
18575 draw_glyphs (i.e. the values of the overall glyphs composed). */
18578 /* If we have not yet calculated pixel size data of glyphs of
18579 the composition for the current face font, calculate them
18580 now. Theoretically, we have to check all fonts for the
18581 glyphs, but that requires much time and memory space. So,
18582 here we check only the font of the first glyph. This leads
18583 to incorrect display very rarely, and C-l (recenter) can
18584 correct the display anyway. */
18585 if (cmp
->font
!= (void *) font
)
18587 /* Ascent and descent of the font of the first character of
18588 this composition (adjusted by baseline offset). Ascent
18589 and descent of overall glyphs should not be less than
18590 them respectively. */
18591 int font_ascent
= FONT_BASE (font
) + boff
;
18592 int font_descent
= FONT_DESCENT (font
) - boff
;
18593 /* Bounding box of the overall glyphs. */
18594 int leftmost
, rightmost
, lowest
, highest
;
18595 int i
, width
, ascent
, descent
;
18597 cmp
->font
= (void *) font
;
18599 /* Initialize the bounding box. */
18601 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
18602 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
18604 width
= pcm
->width
;
18605 ascent
= pcm
->ascent
;
18606 descent
= pcm
->descent
;
18610 width
= FONT_WIDTH (font
);
18611 ascent
= FONT_BASE (font
);
18612 descent
= FONT_DESCENT (font
);
18616 lowest
= - descent
+ boff
;
18617 highest
= ascent
+ boff
;
18621 && font_info
->default_ascent
18622 && CHAR_TABLE_P (Vuse_default_ascent
)
18623 && !NILP (Faref (Vuse_default_ascent
,
18624 make_number (it
->char_to_display
))))
18625 highest
= font_info
->default_ascent
+ boff
;
18627 /* Draw the first glyph at the normal position. It may be
18628 shifted to right later if some other glyphs are drawn at
18630 cmp
->offsets
[0] = 0;
18631 cmp
->offsets
[1] = boff
;
18633 /* Set cmp->offsets for the remaining glyphs. */
18634 for (i
= 1; i
< cmp
->glyph_len
; i
++)
18636 int left
, right
, btm
, top
;
18637 int ch
= COMPOSITION_GLYPH (cmp
, i
);
18638 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
18640 face
= FACE_FROM_ID (it
->f
, face_id
);
18641 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
18642 &char2b
, it
->multibyte_p
, 0);
18646 font
= FRAME_FONT (it
->f
);
18647 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18653 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18654 boff
= font_info
->baseline_offset
;
18655 if (font_info
->vertical_centering
)
18656 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18660 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
18661 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
18663 width
= pcm
->width
;
18664 ascent
= pcm
->ascent
;
18665 descent
= pcm
->descent
;
18669 width
= FONT_WIDTH (font
);
18674 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
18676 /* Relative composition with or without
18677 alternate chars. */
18678 left
= (leftmost
+ rightmost
- width
) / 2;
18679 btm
= - descent
+ boff
;
18680 if (font_info
&& font_info
->relative_compose
18681 && (! CHAR_TABLE_P (Vignore_relative_composition
)
18682 || NILP (Faref (Vignore_relative_composition
,
18683 make_number (ch
)))))
18686 if (- descent
>= font_info
->relative_compose
)
18687 /* One extra pixel between two glyphs. */
18689 else if (ascent
<= 0)
18690 /* One extra pixel between two glyphs. */
18691 btm
= lowest
- 1 - ascent
- descent
;
18696 /* A composition rule is specified by an integer
18697 value that encodes global and new reference
18698 points (GREF and NREF). GREF and NREF are
18699 specified by numbers as below:
18701 0---1---2 -- ascent
18705 9--10--11 -- center
18707 ---3---4---5--- baseline
18709 6---7---8 -- descent
18711 int rule
= COMPOSITION_RULE (cmp
, i
);
18712 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
18714 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
18715 grefx
= gref
% 3, nrefx
= nref
% 3;
18716 grefy
= gref
/ 3, nrefy
= nref
/ 3;
18719 + grefx
* (rightmost
- leftmost
) / 2
18720 - nrefx
* width
/ 2);
18721 btm
= ((grefy
== 0 ? highest
18723 : grefy
== 2 ? lowest
18724 : (highest
+ lowest
) / 2)
18725 - (nrefy
== 0 ? ascent
+ descent
18726 : nrefy
== 1 ? descent
- boff
18728 : (ascent
+ descent
) / 2));
18731 cmp
->offsets
[i
* 2] = left
;
18732 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
18734 /* Update the bounding box of the overall glyphs. */
18735 right
= left
+ width
;
18736 top
= btm
+ descent
+ ascent
;
18737 if (left
< leftmost
)
18739 if (right
> rightmost
)
18747 /* If there are glyphs whose x-offsets are negative,
18748 shift all glyphs to the right and make all x-offsets
18752 for (i
= 0; i
< cmp
->glyph_len
; i
++)
18753 cmp
->offsets
[i
* 2] -= leftmost
;
18754 rightmost
-= leftmost
;
18757 cmp
->pixel_width
= rightmost
;
18758 cmp
->ascent
= highest
;
18759 cmp
->descent
= - lowest
;
18760 if (cmp
->ascent
< font_ascent
)
18761 cmp
->ascent
= font_ascent
;
18762 if (cmp
->descent
< font_descent
)
18763 cmp
->descent
= font_descent
;
18766 it
->pixel_width
= cmp
->pixel_width
;
18767 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
18768 it
->descent
= it
->phys_descent
= cmp
->descent
;
18770 if (face
->box
!= FACE_NO_BOX
)
18772 int thick
= face
->box_line_width
;
18776 it
->ascent
+= thick
;
18777 it
->descent
+= thick
;
18782 if (it
->start_of_box_run_p
)
18783 it
->pixel_width
+= thick
;
18784 if (it
->end_of_box_run_p
)
18785 it
->pixel_width
+= thick
;
18788 /* If face has an overline, add the height of the overline
18789 (1 pixel) and a 1 pixel margin to the character height. */
18790 if (face
->overline_p
)
18793 take_vertical_position_into_account (it
);
18796 append_composite_glyph (it
);
18798 else if (it
->what
== IT_IMAGE
)
18799 produce_image_glyph (it
);
18800 else if (it
->what
== IT_STRETCH
)
18801 produce_stretch_glyph (it
);
18803 /* Accumulate dimensions. Note: can't assume that it->descent > 0
18804 because this isn't true for images with `:ascent 100'. */
18805 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
18806 if (it
->area
== TEXT_AREA
)
18807 it
->current_x
+= it
->pixel_width
;
18809 it
->descent
+= it
->extra_line_spacing
;
18811 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
18812 it
->max_descent
= max (it
->max_descent
, it
->descent
);
18813 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
18814 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
18818 Output LEN glyphs starting at START at the nominal cursor position.
18819 Advance the nominal cursor over the text. The global variable
18820 updated_window contains the window being updated, updated_row is
18821 the glyph row being updated, and updated_area is the area of that
18822 row being updated. */
18825 x_write_glyphs (start
, len
)
18826 struct glyph
*start
;
18831 xassert (updated_window
&& updated_row
);
18834 /* Write glyphs. */
18836 hpos
= start
- updated_row
->glyphs
[updated_area
];
18837 x
= draw_glyphs (updated_window
, output_cursor
.x
,
18838 updated_row
, updated_area
,
18840 DRAW_NORMAL_TEXT
, 0);
18842 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
18843 if (updated_area
== TEXT_AREA
18844 && updated_window
->phys_cursor_on_p
18845 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
18846 && updated_window
->phys_cursor
.hpos
>= hpos
18847 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
18848 updated_window
->phys_cursor_on_p
= 0;
18852 /* Advance the output cursor. */
18853 output_cursor
.hpos
+= len
;
18854 output_cursor
.x
= x
;
18859 Insert LEN glyphs from START at the nominal cursor position. */
18862 x_insert_glyphs (start
, len
)
18863 struct glyph
*start
;
18868 int line_height
, shift_by_width
, shifted_region_width
;
18869 struct glyph_row
*row
;
18870 struct glyph
*glyph
;
18871 int frame_x
, frame_y
, hpos
;
18873 xassert (updated_window
&& updated_row
);
18875 w
= updated_window
;
18876 f
= XFRAME (WINDOW_FRAME (w
));
18878 /* Get the height of the line we are in. */
18880 line_height
= row
->height
;
18882 /* Get the width of the glyphs to insert. */
18883 shift_by_width
= 0;
18884 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
18885 shift_by_width
+= glyph
->pixel_width
;
18887 /* Get the width of the region to shift right. */
18888 shifted_region_width
= (window_box_width (w
, updated_area
)
18893 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
18894 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
18896 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
18897 line_height
, shift_by_width
);
18899 /* Write the glyphs. */
18900 hpos
= start
- row
->glyphs
[updated_area
];
18901 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
18903 DRAW_NORMAL_TEXT
, 0);
18905 /* Advance the output cursor. */
18906 output_cursor
.hpos
+= len
;
18907 output_cursor
.x
+= shift_by_width
;
18913 Erase the current text line from the nominal cursor position
18914 (inclusive) to pixel column TO_X (exclusive). The idea is that
18915 everything from TO_X onward is already erased.
18917 TO_X is a pixel position relative to updated_area of
18918 updated_window. TO_X == -1 means clear to the end of this area. */
18921 x_clear_end_of_line (to_x
)
18925 struct window
*w
= updated_window
;
18926 int max_x
, min_y
, max_y
;
18927 int from_x
, from_y
, to_y
;
18929 xassert (updated_window
&& updated_row
);
18930 f
= XFRAME (w
->frame
);
18932 if (updated_row
->full_width_p
)
18933 max_x
= WINDOW_TOTAL_WIDTH (w
);
18935 max_x
= window_box_width (w
, updated_area
);
18936 max_y
= window_text_bottom_y (w
);
18938 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
18939 of window. For TO_X > 0, truncate to end of drawing area. */
18945 to_x
= min (to_x
, max_x
);
18947 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
18949 /* Notice if the cursor will be cleared by this operation. */
18950 if (!updated_row
->full_width_p
)
18951 notice_overwritten_cursor (w
, updated_area
,
18952 output_cursor
.x
, -1,
18954 MATRIX_ROW_BOTTOM_Y (updated_row
));
18956 from_x
= output_cursor
.x
;
18958 /* Translate to frame coordinates. */
18959 if (updated_row
->full_width_p
)
18961 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
18962 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
18966 int area_left
= window_box_left (w
, updated_area
);
18967 from_x
+= area_left
;
18971 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
18972 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
18973 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
18975 /* Prevent inadvertently clearing to end of the X window. */
18976 if (to_x
> from_x
&& to_y
> from_y
)
18979 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
18980 to_x
- from_x
, to_y
- from_y
);
18985 #endif /* HAVE_WINDOW_SYSTEM */
18989 /***********************************************************************
18991 ***********************************************************************/
18993 /* Value is the internal representation of the specified cursor type
18994 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
18995 of the bar cursor. */
18997 static enum text_cursor_kinds
18998 get_specified_cursor_type (arg
, width
)
19002 enum text_cursor_kinds type
;
19007 if (EQ (arg
, Qbox
))
19008 return FILLED_BOX_CURSOR
;
19010 if (EQ (arg
, Qhollow
))
19011 return HOLLOW_BOX_CURSOR
;
19013 if (EQ (arg
, Qbar
))
19020 && EQ (XCAR (arg
), Qbar
)
19021 && INTEGERP (XCDR (arg
))
19022 && XINT (XCDR (arg
)) >= 0)
19024 *width
= XINT (XCDR (arg
));
19028 if (EQ (arg
, Qhbar
))
19031 return HBAR_CURSOR
;
19035 && EQ (XCAR (arg
), Qhbar
)
19036 && INTEGERP (XCDR (arg
))
19037 && XINT (XCDR (arg
)) >= 0)
19039 *width
= XINT (XCDR (arg
));
19040 return HBAR_CURSOR
;
19043 /* Treat anything unknown as "hollow box cursor".
19044 It was bad to signal an error; people have trouble fixing
19045 .Xdefaults with Emacs, when it has something bad in it. */
19046 type
= HOLLOW_BOX_CURSOR
;
19051 /* Set the default cursor types for specified frame. */
19053 set_frame_cursor_types (f
, arg
)
19060 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
19061 FRAME_CURSOR_WIDTH (f
) = width
;
19063 /* By default, set up the blink-off state depending on the on-state. */
19065 tem
= Fassoc (arg
, Vblink_cursor_alist
);
19068 FRAME_BLINK_OFF_CURSOR (f
)
19069 = get_specified_cursor_type (XCDR (tem
), &width
);
19070 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
19073 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
19077 /* Return the cursor we want to be displayed in window W. Return
19078 width of bar/hbar cursor through WIDTH arg. Return with
19079 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
19080 (i.e. if the `system caret' should track this cursor).
19082 In a mini-buffer window, we want the cursor only to appear if we
19083 are reading input from this window. For the selected window, we
19084 want the cursor type given by the frame parameter or buffer local
19085 setting of cursor-type. If explicitly marked off, draw no cursor.
19086 In all other cases, we want a hollow box cursor. */
19088 static enum text_cursor_kinds
19089 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
19091 struct glyph
*glyph
;
19093 int *active_cursor
;
19095 struct frame
*f
= XFRAME (w
->frame
);
19096 struct buffer
*b
= XBUFFER (w
->buffer
);
19097 int cursor_type
= DEFAULT_CURSOR
;
19098 Lisp_Object alt_cursor
;
19099 int non_selected
= 0;
19101 *active_cursor
= 1;
19104 if (cursor_in_echo_area
19105 && FRAME_HAS_MINIBUF_P (f
)
19106 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
19108 if (w
== XWINDOW (echo_area_window
))
19110 *width
= FRAME_CURSOR_WIDTH (f
);
19111 return FRAME_DESIRED_CURSOR (f
);
19114 *active_cursor
= 0;
19118 /* Nonselected window or nonselected frame. */
19119 else if (w
!= XWINDOW (f
->selected_window
)
19120 #ifdef HAVE_WINDOW_SYSTEM
19121 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
19125 *active_cursor
= 0;
19127 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
19133 /* Never display a cursor in a window in which cursor-type is nil. */
19134 if (NILP (b
->cursor_type
))
19137 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
19140 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
19141 return get_specified_cursor_type (alt_cursor
, width
);
19144 /* Get the normal cursor type for this window. */
19145 if (EQ (b
->cursor_type
, Qt
))
19147 cursor_type
= FRAME_DESIRED_CURSOR (f
);
19148 *width
= FRAME_CURSOR_WIDTH (f
);
19151 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
19153 /* Use normal cursor if not blinked off. */
19154 if (!w
->cursor_off_p
)
19156 if (glyph
->type
== IMAGE_GLYPH
) {
19157 if (cursor_type
== FILLED_BOX_CURSOR
)
19158 cursor_type
= HOLLOW_BOX_CURSOR
;
19160 return cursor_type
;
19163 /* Cursor is blinked off, so determine how to "toggle" it. */
19165 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
19166 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
19167 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
19169 /* Then see if frame has specified a specific blink off cursor type. */
19170 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
19172 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
19173 return FRAME_BLINK_OFF_CURSOR (f
);
19177 /* Some people liked having a permanently visible blinking cursor,
19178 while others had very strong opinions against it. So it was
19179 decided to remove it. KFS 2003-09-03 */
19181 /* Finally perform built-in cursor blinking:
19182 filled box <-> hollow box
19183 wide [h]bar <-> narrow [h]bar
19184 narrow [h]bar <-> no cursor
19185 other type <-> no cursor */
19187 if (cursor_type
== FILLED_BOX_CURSOR
)
19188 return HOLLOW_BOX_CURSOR
;
19190 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
19193 return cursor_type
;
19201 #ifdef HAVE_WINDOW_SYSTEM
19203 /* Notice when the text cursor of window W has been completely
19204 overwritten by a drawing operation that outputs glyphs in AREA
19205 starting at X0 and ending at X1 in the line starting at Y0 and
19206 ending at Y1. X coordinates are area-relative. X1 < 0 means all
19207 the rest of the line after X0 has been written. Y coordinates
19208 are window-relative. */
19211 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
19213 enum glyph_row_area area
;
19214 int x0
, y0
, x1
, y1
;
19216 if (area
== TEXT_AREA
&& w
->phys_cursor_on_p
)
19218 int cx0
= w
->phys_cursor
.x
;
19219 int cx1
= cx0
+ w
->phys_cursor_width
;
19220 int cy0
= w
->phys_cursor
.y
;
19221 int cy1
= cy0
+ w
->phys_cursor_height
;
19223 if (x0
<= cx0
&& (x1
< 0 || x1
>= cx1
))
19225 /* The cursor image will be completely removed from the
19226 screen if the output area intersects the cursor area in
19227 y-direction. When we draw in [y0 y1[, and some part of
19228 the cursor is at y < y0, that part must have been drawn
19229 before. When scrolling, the cursor is erased before
19230 actually scrolling, so we don't come here. When not
19231 scrolling, the rows above the old cursor row must have
19232 changed, and in this case these rows must have written
19233 over the cursor image.
19235 Likewise if part of the cursor is below y1, with the
19236 exception of the cursor being in the first blank row at
19237 the buffer and window end because update_text_area
19238 doesn't draw that row. (Except when it does, but
19239 that's handled in update_text_area.) */
19241 if (((y0
>= cy0
&& y0
< cy1
) || (y1
> cy0
&& y1
< cy1
))
19242 && w
->current_matrix
->rows
[w
->phys_cursor
.vpos
].displays_text_p
)
19243 w
->phys_cursor_on_p
= 0;
19248 #endif /* HAVE_WINDOW_SYSTEM */
19251 /************************************************************************
19253 ************************************************************************/
19255 #ifdef HAVE_WINDOW_SYSTEM
19258 Fix the display of area AREA of overlapping row ROW in window W. */
19261 x_fix_overlapping_area (w
, row
, area
)
19263 struct glyph_row
*row
;
19264 enum glyph_row_area area
;
19271 for (i
= 0; i
< row
->used
[area
];)
19273 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
19275 int start
= i
, start_x
= x
;
19279 x
+= row
->glyphs
[area
][i
].pixel_width
;
19282 while (i
< row
->used
[area
]
19283 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
19285 draw_glyphs (w
, start_x
, row
, area
,
19287 DRAW_NORMAL_TEXT
, 1);
19291 x
+= row
->glyphs
[area
][i
].pixel_width
;
19301 Draw the cursor glyph of window W in glyph row ROW. See the
19302 comment of draw_glyphs for the meaning of HL. */
19305 draw_phys_cursor_glyph (w
, row
, hl
)
19307 struct glyph_row
*row
;
19308 enum draw_glyphs_face hl
;
19310 /* If cursor hpos is out of bounds, don't draw garbage. This can
19311 happen in mini-buffer windows when switching between echo area
19312 glyphs and mini-buffer. */
19313 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
19315 int on_p
= w
->phys_cursor_on_p
;
19317 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
19318 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
19320 w
->phys_cursor_on_p
= on_p
;
19322 if (hl
== DRAW_CURSOR
)
19323 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
19324 /* When we erase the cursor, and ROW is overlapped by other
19325 rows, make sure that these overlapping parts of other rows
19327 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
19329 if (row
> w
->current_matrix
->rows
19330 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
19331 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
19333 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
19334 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
19335 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
19342 Erase the image of a cursor of window W from the screen. */
19345 erase_phys_cursor (w
)
19348 struct frame
*f
= XFRAME (w
->frame
);
19349 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
19350 int hpos
= w
->phys_cursor
.hpos
;
19351 int vpos
= w
->phys_cursor
.vpos
;
19352 int mouse_face_here_p
= 0;
19353 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
19354 struct glyph_row
*cursor_row
;
19355 struct glyph
*cursor_glyph
;
19356 enum draw_glyphs_face hl
;
19358 /* No cursor displayed or row invalidated => nothing to do on the
19360 if (w
->phys_cursor_type
== NO_CURSOR
)
19361 goto mark_cursor_off
;
19363 /* VPOS >= active_glyphs->nrows means that window has been resized.
19364 Don't bother to erase the cursor. */
19365 if (vpos
>= active_glyphs
->nrows
)
19366 goto mark_cursor_off
;
19368 /* If row containing cursor is marked invalid, there is nothing we
19370 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
19371 if (!cursor_row
->enabled_p
)
19372 goto mark_cursor_off
;
19374 /* If row is completely invisible, don't attempt to delete a cursor which
19375 isn't there. This can happen if cursor is at top of a window, and
19376 we switch to a buffer with a header line in that window. */
19377 if (cursor_row
->visible_height
<= 0)
19378 goto mark_cursor_off
;
19380 /* This can happen when the new row is shorter than the old one.
19381 In this case, either draw_glyphs or clear_end_of_line
19382 should have cleared the cursor. Note that we wouldn't be
19383 able to erase the cursor in this case because we don't have a
19384 cursor glyph at hand. */
19385 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
19386 goto mark_cursor_off
;
19388 /* If the cursor is in the mouse face area, redisplay that when
19389 we clear the cursor. */
19390 if (! NILP (dpyinfo
->mouse_face_window
)
19391 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
19392 && (vpos
> dpyinfo
->mouse_face_beg_row
19393 || (vpos
== dpyinfo
->mouse_face_beg_row
19394 && hpos
>= dpyinfo
->mouse_face_beg_col
))
19395 && (vpos
< dpyinfo
->mouse_face_end_row
19396 || (vpos
== dpyinfo
->mouse_face_end_row
19397 && hpos
< dpyinfo
->mouse_face_end_col
))
19398 /* Don't redraw the cursor's spot in mouse face if it is at the
19399 end of a line (on a newline). The cursor appears there, but
19400 mouse highlighting does not. */
19401 && cursor_row
->used
[TEXT_AREA
] > hpos
)
19402 mouse_face_here_p
= 1;
19404 /* Maybe clear the display under the cursor. */
19405 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
19408 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
19410 cursor_glyph
= get_phys_cursor_glyph (w
);
19411 if (cursor_glyph
== NULL
)
19412 goto mark_cursor_off
;
19414 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
19415 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
19417 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
,
19418 cursor_glyph
->pixel_width
, cursor_row
->visible_height
);
19421 /* Erase the cursor by redrawing the character underneath it. */
19422 if (mouse_face_here_p
)
19423 hl
= DRAW_MOUSE_FACE
;
19425 hl
= DRAW_NORMAL_TEXT
;
19426 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
19429 w
->phys_cursor_on_p
= 0;
19430 w
->phys_cursor_type
= NO_CURSOR
;
19435 Display or clear cursor of window W. If ON is zero, clear the
19436 cursor. If it is non-zero, display the cursor. If ON is nonzero,
19437 where to put the cursor is specified by HPOS, VPOS, X and Y. */
19440 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
19442 int on
, hpos
, vpos
, x
, y
;
19444 struct frame
*f
= XFRAME (w
->frame
);
19445 int new_cursor_type
;
19446 int new_cursor_width
;
19448 struct glyph_matrix
*current_glyphs
;
19449 struct glyph_row
*glyph_row
;
19450 struct glyph
*glyph
;
19452 /* This is pointless on invisible frames, and dangerous on garbaged
19453 windows and frames; in the latter case, the frame or window may
19454 be in the midst of changing its size, and x and y may be off the
19456 if (! FRAME_VISIBLE_P (f
)
19457 || FRAME_GARBAGED_P (f
)
19458 || vpos
>= w
->current_matrix
->nrows
19459 || hpos
>= w
->current_matrix
->matrix_w
)
19462 /* If cursor is off and we want it off, return quickly. */
19463 if (!on
&& !w
->phys_cursor_on_p
)
19466 current_glyphs
= w
->current_matrix
;
19467 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
19468 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
19470 /* If cursor row is not enabled, we don't really know where to
19471 display the cursor. */
19472 if (!glyph_row
->enabled_p
)
19474 w
->phys_cursor_on_p
= 0;
19478 xassert (interrupt_input_blocked
);
19480 /* Set new_cursor_type to the cursor we want to be displayed. */
19481 new_cursor_type
= get_window_cursor_type (w
, glyph
,
19482 &new_cursor_width
, &active_cursor
);
19484 /* If cursor is currently being shown and we don't want it to be or
19485 it is in the wrong place, or the cursor type is not what we want,
19487 if (w
->phys_cursor_on_p
19489 || w
->phys_cursor
.x
!= x
19490 || w
->phys_cursor
.y
!= y
19491 || new_cursor_type
!= w
->phys_cursor_type
19492 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
19493 && new_cursor_width
!= w
->phys_cursor_width
)))
19494 erase_phys_cursor (w
);
19496 /* Don't check phys_cursor_on_p here because that flag is only set
19497 to zero in some cases where we know that the cursor has been
19498 completely erased, to avoid the extra work of erasing the cursor
19499 twice. In other words, phys_cursor_on_p can be 1 and the cursor
19500 still not be visible, or it has only been partly erased. */
19503 w
->phys_cursor_ascent
= glyph_row
->ascent
;
19504 w
->phys_cursor_height
= glyph_row
->height
;
19506 /* Set phys_cursor_.* before x_draw_.* is called because some
19507 of them may need the information. */
19508 w
->phys_cursor
.x
= x
;
19509 w
->phys_cursor
.y
= glyph_row
->y
;
19510 w
->phys_cursor
.hpos
= hpos
;
19511 w
->phys_cursor
.vpos
= vpos
;
19514 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
19515 new_cursor_type
, new_cursor_width
,
19516 on
, active_cursor
);
19520 /* Switch the display of W's cursor on or off, according to the value
19524 update_window_cursor (w
, on
)
19528 /* Don't update cursor in windows whose frame is in the process
19529 of being deleted. */
19530 if (w
->current_matrix
)
19533 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
19534 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
19540 /* Call update_window_cursor with parameter ON_P on all leaf windows
19541 in the window tree rooted at W. */
19544 update_cursor_in_window_tree (w
, on_p
)
19550 if (!NILP (w
->hchild
))
19551 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
19552 else if (!NILP (w
->vchild
))
19553 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
19555 update_window_cursor (w
, on_p
);
19557 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
19563 Display the cursor on window W, or clear it, according to ON_P.
19564 Don't change the cursor's position. */
19567 x_update_cursor (f
, on_p
)
19571 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
19576 Clear the cursor of window W to background color, and mark the
19577 cursor as not shown. This is used when the text where the cursor
19578 is is about to be rewritten. */
19584 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
19585 update_window_cursor (w
, 0);
19590 Display the active region described by mouse_face_* according to DRAW. */
19593 show_mouse_face (dpyinfo
, draw
)
19594 Display_Info
*dpyinfo
;
19595 enum draw_glyphs_face draw
;
19597 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
19598 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19600 if (/* If window is in the process of being destroyed, don't bother
19602 w
->current_matrix
!= NULL
19603 /* Don't update mouse highlight if hidden */
19604 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
19605 /* Recognize when we are called to operate on rows that don't exist
19606 anymore. This can happen when a window is split. */
19607 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
19609 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
19610 struct glyph_row
*row
, *first
, *last
;
19612 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
19613 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
19615 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
19617 int start_hpos
, end_hpos
, start_x
;
19619 /* For all but the first row, the highlight starts at column 0. */
19622 start_hpos
= dpyinfo
->mouse_face_beg_col
;
19623 start_x
= dpyinfo
->mouse_face_beg_x
;
19632 end_hpos
= dpyinfo
->mouse_face_end_col
;
19634 end_hpos
= row
->used
[TEXT_AREA
];
19636 if (end_hpos
> start_hpos
)
19638 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
19639 start_hpos
, end_hpos
,
19643 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
19647 /* When we've written over the cursor, arrange for it to
19648 be displayed again. */
19649 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
19652 display_and_set_cursor (w
, 1,
19653 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
19654 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
19659 /* Change the mouse cursor. */
19660 if (draw
== DRAW_NORMAL_TEXT
)
19661 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
19662 else if (draw
== DRAW_MOUSE_FACE
)
19663 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
19665 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
19669 Clear out the mouse-highlighted active region.
19670 Redraw it un-highlighted first. Value is non-zero if mouse
19671 face was actually drawn unhighlighted. */
19674 clear_mouse_face (dpyinfo
)
19675 Display_Info
*dpyinfo
;
19679 if (!NILP (dpyinfo
->mouse_face_window
))
19681 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
19685 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
19686 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
19687 dpyinfo
->mouse_face_window
= Qnil
;
19688 dpyinfo
->mouse_face_overlay
= Qnil
;
19694 Non-zero if physical cursor of window W is within mouse face. */
19697 cursor_in_mouse_face_p (w
)
19700 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
19701 int in_mouse_face
= 0;
19703 if (WINDOWP (dpyinfo
->mouse_face_window
)
19704 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
19706 int hpos
= w
->phys_cursor
.hpos
;
19707 int vpos
= w
->phys_cursor
.vpos
;
19709 if (vpos
>= dpyinfo
->mouse_face_beg_row
19710 && vpos
<= dpyinfo
->mouse_face_end_row
19711 && (vpos
> dpyinfo
->mouse_face_beg_row
19712 || hpos
>= dpyinfo
->mouse_face_beg_col
)
19713 && (vpos
< dpyinfo
->mouse_face_end_row
19714 || hpos
< dpyinfo
->mouse_face_end_col
19715 || dpyinfo
->mouse_face_past_end
))
19719 return in_mouse_face
;
19725 /* Find the glyph matrix position of buffer position CHARPOS in window
19726 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
19727 current glyphs must be up to date. If CHARPOS is above window
19728 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
19729 of last line in W. In the row containing CHARPOS, stop before glyphs
19730 having STOP as object. */
19732 #if 1 /* This is a version of fast_find_position that's more correct
19733 in the presence of hscrolling, for example. I didn't install
19734 it right away because the problem fixed is minor, it failed
19735 in 20.x as well, and I think it's too risky to install
19736 so near the release of 21.1. 2001-09-25 gerd. */
19739 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
19742 int *hpos
, *vpos
, *x
, *y
;
19745 struct glyph_row
*row
, *first
;
19746 struct glyph
*glyph
, *end
;
19749 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
19750 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
19753 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
19755 *x
= *y
= *hpos
= *vpos
= 0;
19760 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
19767 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
19769 glyph
= row
->glyphs
[TEXT_AREA
];
19770 end
= glyph
+ row
->used
[TEXT_AREA
];
19772 /* Skip over glyphs not having an object at the start of the row.
19773 These are special glyphs like truncation marks on terminal
19775 if (row
->displays_text_p
)
19777 && INTEGERP (glyph
->object
)
19778 && !EQ (stop
, glyph
->object
)
19779 && glyph
->charpos
< 0)
19781 *x
+= glyph
->pixel_width
;
19786 && !INTEGERP (glyph
->object
)
19787 && !EQ (stop
, glyph
->object
)
19788 && (!BUFFERP (glyph
->object
)
19789 || glyph
->charpos
< charpos
))
19791 *x
+= glyph
->pixel_width
;
19795 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
19802 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
19805 int *hpos
, *vpos
, *x
, *y
;
19810 int maybe_next_line_p
= 0;
19811 int line_start_position
;
19812 int yb
= window_text_bottom_y (w
);
19813 struct glyph_row
*row
, *best_row
;
19814 int row_vpos
, best_row_vpos
;
19817 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
19818 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
19820 while (row
->y
< yb
)
19822 if (row
->used
[TEXT_AREA
])
19823 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
19825 line_start_position
= 0;
19827 if (line_start_position
> pos
)
19829 /* If the position sought is the end of the buffer,
19830 don't include the blank lines at the bottom of the window. */
19831 else if (line_start_position
== pos
19832 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
19834 maybe_next_line_p
= 1;
19837 else if (line_start_position
> 0)
19840 best_row_vpos
= row_vpos
;
19843 if (row
->y
+ row
->height
>= yb
)
19850 /* Find the right column within BEST_ROW. */
19852 current_x
= best_row
->x
;
19853 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
19855 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
19856 int charpos
= glyph
->charpos
;
19858 if (BUFFERP (glyph
->object
))
19860 if (charpos
== pos
)
19863 *vpos
= best_row_vpos
;
19868 else if (charpos
> pos
)
19871 else if (EQ (glyph
->object
, stop
))
19876 current_x
+= glyph
->pixel_width
;
19879 /* If we're looking for the end of the buffer,
19880 and we didn't find it in the line we scanned,
19881 use the start of the following line. */
19882 if (maybe_next_line_p
)
19887 current_x
= best_row
->x
;
19890 *vpos
= best_row_vpos
;
19891 *hpos
= lastcol
+ 1;
19900 /* Find the position of the glyph for position POS in OBJECT in
19901 window W's current matrix, and return in *X, *Y the pixel
19902 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
19904 RIGHT_P non-zero means return the position of the right edge of the
19905 glyph, RIGHT_P zero means return the left edge position.
19907 If no glyph for POS exists in the matrix, return the position of
19908 the glyph with the next smaller position that is in the matrix, if
19909 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
19910 exists in the matrix, return the position of the glyph with the
19911 next larger position in OBJECT.
19913 Value is non-zero if a glyph was found. */
19916 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
19919 Lisp_Object object
;
19920 int *hpos
, *vpos
, *x
, *y
;
19923 int yb
= window_text_bottom_y (w
);
19924 struct glyph_row
*r
;
19925 struct glyph
*best_glyph
= NULL
;
19926 struct glyph_row
*best_row
= NULL
;
19929 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
19930 r
->enabled_p
&& r
->y
< yb
;
19933 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
19934 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
19937 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
19938 if (EQ (g
->object
, object
))
19940 if (g
->charpos
== pos
)
19947 else if (best_glyph
== NULL
19948 || ((abs (g
->charpos
- pos
)
19949 < abs (best_glyph
->charpos
- pos
))
19952 : g
->charpos
> pos
)))
19966 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
19970 *x
+= best_glyph
->pixel_width
;
19975 *vpos
= best_row
- w
->current_matrix
->rows
;
19978 return best_glyph
!= NULL
;
19982 /* See if position X, Y is within a hot-spot of an image. */
19985 on_hot_spot_p (hot_spot
, x
, y
)
19986 Lisp_Object hot_spot
;
19989 if (!CONSP (hot_spot
))
19992 if (EQ (XCAR (hot_spot
), Qrect
))
19994 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
19995 Lisp_Object rect
= XCDR (hot_spot
);
19999 if (!CONSP (XCAR (rect
)))
20001 if (!CONSP (XCDR (rect
)))
20003 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
20005 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
20007 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
20009 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
20013 else if (EQ (XCAR (hot_spot
), Qcircle
))
20015 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
20016 Lisp_Object circ
= XCDR (hot_spot
);
20017 Lisp_Object lr
, lx0
, ly0
;
20019 && CONSP (XCAR (circ
))
20020 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
20021 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
20022 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
20024 double r
= XFLOATINT (lr
);
20025 double dx
= XINT (lx0
) - x
;
20026 double dy
= XINT (ly0
) - y
;
20027 return (dx
* dx
+ dy
* dy
<= r
* r
);
20030 else if (EQ (XCAR (hot_spot
), Qpoly
))
20032 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
20033 if (VECTORP (XCDR (hot_spot
)))
20035 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
20036 Lisp_Object
*poly
= v
->contents
;
20040 Lisp_Object lx
, ly
;
20043 /* Need an even number of coordinates, and at least 3 edges. */
20044 if (n
< 6 || n
& 1)
20047 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
20048 If count is odd, we are inside polygon. Pixels on edges
20049 may or may not be included depending on actual geometry of the
20051 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
20052 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
20054 x0
= XINT (lx
), y0
= XINT (ly
);
20055 for (i
= 0; i
< n
; i
+= 2)
20057 int x1
= x0
, y1
= y0
;
20058 if ((lx
= poly
[i
], !INTEGERP (lx
))
20059 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
20061 x0
= XINT (lx
), y0
= XINT (ly
);
20063 /* Does this segment cross the X line? */
20071 if (y
> y0
&& y
> y1
)
20073 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
20084 find_hot_spot (map
, x
, y
)
20088 while (CONSP (map
))
20090 if (CONSP (XCAR (map
))
20091 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
20099 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
20101 doc
: /* Lookup in image map MAP coordinates X and Y.
20102 An image map is an alist where each element has the format (AREA ID PLIST).
20103 An AREA is specified as either a rectangle, a circle, or a polygon:
20104 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
20105 pixel coordinates of the upper left and bottom right corners.
20106 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
20107 and the radius of the circle; r may be a float or integer.
20108 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
20109 vector describes one corner in the polygon.
20110 Returns the alist element for the first matching AREA in MAP. */)
20120 wrong_type_argument (Qintegerp
, x
);
20122 wrong_type_argument (Qintegerp
, y
);
20124 return find_hot_spot (map
, XINT (x
), XINT (y
));
20128 /* Display frame CURSOR, optionally using shape defined by POINTER. */
20130 define_frame_cursor1 (f
, cursor
, pointer
)
20133 Lisp_Object pointer
;
20135 if (!NILP (pointer
))
20137 if (EQ (pointer
, Qarrow
))
20138 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20139 else if (EQ (pointer
, Qhand
))
20140 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
20141 else if (EQ (pointer
, Qtext
))
20142 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
20143 else if (EQ (pointer
, intern ("hdrag")))
20144 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
20145 #ifdef HAVE_X_WINDOWS
20146 else if (EQ (pointer
, intern ("vdrag")))
20147 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
20149 else if (EQ (pointer
, intern ("hourglass")))
20150 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
20151 else if (EQ (pointer
, Qmodeline
))
20152 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
20154 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20157 #ifndef HAVE_CARBON
20158 if (cursor
!= No_Cursor
)
20160 if (bcmp (&cursor
, &No_Cursor
, sizeof (Cursor
)))
20162 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
20165 /* Take proper action when mouse has moved to the mode or header line
20166 or marginal area AREA of window W, x-position X and y-position Y.
20167 X is relative to the start of the text display area of W, so the
20168 width of bitmap areas and scroll bars must be subtracted to get a
20169 position relative to the start of the mode line. */
20172 note_mode_line_or_margin_highlight (w
, x
, y
, area
)
20175 enum window_part area
;
20177 struct frame
*f
= XFRAME (w
->frame
);
20178 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20179 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20180 Lisp_Object pointer
= Qnil
;
20181 int charpos
, dx
, dy
, width
, height
;
20182 Lisp_Object string
, object
= Qnil
;
20183 Lisp_Object pos
, help
, image
;
20185 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
20186 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
20187 &object
, &dx
, &dy
, &width
, &height
);
20190 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
20191 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
20192 &object
, &dx
, &dy
, &width
, &height
);
20197 if (IMAGEP (object
))
20199 Lisp_Object image_map
, hotspot
;
20200 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
20202 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
20204 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
20206 Lisp_Object area_id
, plist
;
20208 area_id
= XCAR (hotspot
);
20209 /* Could check AREA_ID to see if we enter/leave this hot-spot.
20210 If so, we could look for mouse-enter, mouse-leave
20211 properties in PLIST (and do something...). */
20212 if ((plist
= XCDR (hotspot
), CONSP (plist
)))
20214 pointer
= Fplist_get (plist
, Qpointer
);
20215 if (NILP (pointer
))
20217 help
= Fplist_get (plist
, Qhelp_echo
);
20220 help_echo_string
= help
;
20221 /* Is this correct? ++kfs */
20222 XSETWINDOW (help_echo_window
, w
);
20223 help_echo_object
= w
->buffer
;
20224 help_echo_pos
= charpos
;
20227 if (NILP (pointer
))
20228 pointer
= Fplist_get (XCDR (object
), QCpointer
);
20232 if (STRINGP (string
))
20234 pos
= make_number (charpos
);
20235 /* If we're on a string with `help-echo' text property, arrange
20236 for the help to be displayed. This is done by setting the
20237 global variable help_echo_string to the help string. */
20238 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
20241 help_echo_string
= help
;
20242 XSETWINDOW (help_echo_window
, w
);
20243 help_echo_object
= string
;
20244 help_echo_pos
= charpos
;
20247 if (NILP (pointer
))
20248 pointer
= Fget_text_property (pos
, Qpointer
, string
);
20250 /* Change the mouse pointer according to what is under X/Y. */
20251 if (NILP (pointer
) && area
== ON_MODE_LINE
)
20254 map
= Fget_text_property (pos
, Qlocal_map
, string
);
20255 if (!KEYMAPP (map
))
20256 map
= Fget_text_property (pos
, Qkeymap
, string
);
20257 if (!KEYMAPP (map
))
20258 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
20262 define_frame_cursor1 (f
, cursor
, pointer
);
20267 Take proper action when the mouse has moved to position X, Y on
20268 frame F as regards highlighting characters that have mouse-face
20269 properties. Also de-highlighting chars where the mouse was before.
20270 X and Y can be negative or out of range. */
20273 note_mouse_highlight (f
, x
, y
)
20277 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20278 enum window_part part
;
20279 Lisp_Object window
;
20281 Cursor cursor
= No_Cursor
;
20282 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
20285 /* When a menu is active, don't highlight because this looks odd. */
20286 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
20287 if (popup_activated ())
20291 if (NILP (Vmouse_highlight
)
20292 || !f
->glyphs_initialized_p
)
20295 dpyinfo
->mouse_face_mouse_x
= x
;
20296 dpyinfo
->mouse_face_mouse_y
= y
;
20297 dpyinfo
->mouse_face_mouse_frame
= f
;
20299 if (dpyinfo
->mouse_face_defer
)
20302 if (gc_in_progress
)
20304 dpyinfo
->mouse_face_deferred_gc
= 1;
20308 /* Which window is that in? */
20309 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
20311 /* If we were displaying active text in another window, clear that. */
20312 if (! EQ (window
, dpyinfo
->mouse_face_window
))
20313 clear_mouse_face (dpyinfo
);
20315 /* Not on a window -> return. */
20316 if (!WINDOWP (window
))
20319 /* Reset help_echo_string. It will get recomputed below. */
20320 help_echo_string
= Qnil
;
20322 /* Convert to window-relative pixel coordinates. */
20323 w
= XWINDOW (window
);
20324 frame_to_window_pixel_xy (w
, &x
, &y
);
20326 /* Handle tool-bar window differently since it doesn't display a
20328 if (EQ (window
, f
->tool_bar_window
))
20330 note_tool_bar_highlight (f
, x
, y
);
20334 /* Mouse is on the mode, header line or margin? */
20335 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
20336 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
20338 note_mode_line_or_margin_highlight (w
, x
, y
, part
);
20342 if (part
== ON_VERTICAL_BORDER
)
20343 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
20344 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
)
20345 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20347 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
20349 /* Are we in a window whose display is up to date?
20350 And verify the buffer's text has not changed. */
20351 b
= XBUFFER (w
->buffer
);
20352 if (part
== ON_TEXT
20353 && EQ (w
->window_end_valid
, w
->buffer
)
20354 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
20355 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
20357 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
20358 struct glyph
*glyph
;
20359 Lisp_Object object
;
20360 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
20361 Lisp_Object
*overlay_vec
= NULL
;
20362 int len
, noverlays
;
20363 struct buffer
*obuf
;
20364 int obegv
, ozv
, same_region
;
20366 /* Find the glyph under X/Y. */
20367 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
20369 /* Look for :pointer property on image. */
20370 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
20372 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
20373 if (img
!= NULL
&& IMAGEP (img
->spec
))
20375 Lisp_Object image_map
, hotspot
;
20376 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
20378 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
20380 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
20382 Lisp_Object area_id
, plist
;
20384 area_id
= XCAR (hotspot
);
20385 /* Could check AREA_ID to see if we enter/leave this hot-spot.
20386 If so, we could look for mouse-enter, mouse-leave
20387 properties in PLIST (and do something...). */
20388 if ((plist
= XCDR (hotspot
), CONSP (plist
)))
20390 pointer
= Fplist_get (plist
, Qpointer
);
20391 if (NILP (pointer
))
20393 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
20394 if (!NILP (help_echo_string
))
20396 help_echo_window
= window
;
20397 help_echo_object
= glyph
->object
;
20398 help_echo_pos
= glyph
->charpos
;
20402 if (NILP (pointer
))
20403 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
20407 /* Clear mouse face if X/Y not over text. */
20409 || area
!= TEXT_AREA
20410 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
20412 if (clear_mouse_face (dpyinfo
))
20413 cursor
= No_Cursor
;
20414 if (NILP (pointer
))
20416 if (area
!= TEXT_AREA
)
20417 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20419 pointer
= Vvoid_text_area_pointer
;
20424 pos
= glyph
->charpos
;
20425 object
= glyph
->object
;
20426 if (!STRINGP (object
) && !BUFFERP (object
))
20429 /* If we get an out-of-range value, return now; avoid an error. */
20430 if (BUFFERP (object
) && pos
> BUF_Z (b
))
20433 /* Make the window's buffer temporarily current for
20434 overlays_at and compute_char_face. */
20435 obuf
= current_buffer
;
20436 current_buffer
= b
;
20442 /* Is this char mouse-active or does it have help-echo? */
20443 position
= make_number (pos
);
20445 if (BUFFERP (object
))
20447 /* Put all the overlays we want in a vector in overlay_vec.
20448 Store the length in len. If there are more than 10, make
20449 enough space for all, and try again. */
20451 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
20452 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
20453 if (noverlays
> len
)
20456 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
20457 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
20460 /* Sort overlays into increasing priority order. */
20461 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
20466 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
20467 && vpos
>= dpyinfo
->mouse_face_beg_row
20468 && vpos
<= dpyinfo
->mouse_face_end_row
20469 && (vpos
> dpyinfo
->mouse_face_beg_row
20470 || hpos
>= dpyinfo
->mouse_face_beg_col
)
20471 && (vpos
< dpyinfo
->mouse_face_end_row
20472 || hpos
< dpyinfo
->mouse_face_end_col
20473 || dpyinfo
->mouse_face_past_end
));
20476 cursor
= No_Cursor
;
20478 /* Check mouse-face highlighting. */
20480 /* If there exists an overlay with mouse-face overlapping
20481 the one we are currently highlighting, we have to
20482 check if we enter the overlapping overlay, and then
20483 highlight only that. */
20484 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
20485 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
20487 /* Find the highest priority overlay that has a mouse-face
20490 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
20492 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
20493 if (!NILP (mouse_face
))
20494 overlay
= overlay_vec
[i
];
20497 /* If we're actually highlighting the same overlay as
20498 before, there's no need to do that again. */
20499 if (!NILP (overlay
)
20500 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
20501 goto check_help_echo
;
20503 dpyinfo
->mouse_face_overlay
= overlay
;
20505 /* Clear the display of the old active region, if any. */
20506 if (clear_mouse_face (dpyinfo
))
20507 cursor
= No_Cursor
;
20509 /* If no overlay applies, get a text property. */
20510 if (NILP (overlay
))
20511 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
20513 /* Handle the overlay case. */
20514 if (!NILP (overlay
))
20516 /* Find the range of text around this char that
20517 should be active. */
20518 Lisp_Object before
, after
;
20521 before
= Foverlay_start (overlay
);
20522 after
= Foverlay_end (overlay
);
20523 /* Record this as the current active region. */
20524 fast_find_position (w
, XFASTINT (before
),
20525 &dpyinfo
->mouse_face_beg_col
,
20526 &dpyinfo
->mouse_face_beg_row
,
20527 &dpyinfo
->mouse_face_beg_x
,
20528 &dpyinfo
->mouse_face_beg_y
, Qnil
);
20530 dpyinfo
->mouse_face_past_end
20531 = !fast_find_position (w
, XFASTINT (after
),
20532 &dpyinfo
->mouse_face_end_col
,
20533 &dpyinfo
->mouse_face_end_row
,
20534 &dpyinfo
->mouse_face_end_x
,
20535 &dpyinfo
->mouse_face_end_y
, Qnil
);
20536 dpyinfo
->mouse_face_window
= window
;
20538 dpyinfo
->mouse_face_face_id
20539 = face_at_buffer_position (w
, pos
, 0, 0,
20541 !dpyinfo
->mouse_face_hidden
);
20543 /* Display it as active. */
20544 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
20545 cursor
= No_Cursor
;
20547 /* Handle the text property case. */
20548 else if (!NILP (mouse_face
) && BUFFERP (object
))
20550 /* Find the range of text around this char that
20551 should be active. */
20552 Lisp_Object before
, after
, beginning
, end
;
20555 beginning
= Fmarker_position (w
->start
);
20556 end
= make_number (BUF_Z (XBUFFER (object
))
20557 - XFASTINT (w
->window_end_pos
));
20559 = Fprevious_single_property_change (make_number (pos
+ 1),
20561 object
, beginning
);
20563 = Fnext_single_property_change (position
, Qmouse_face
,
20566 /* Record this as the current active region. */
20567 fast_find_position (w
, XFASTINT (before
),
20568 &dpyinfo
->mouse_face_beg_col
,
20569 &dpyinfo
->mouse_face_beg_row
,
20570 &dpyinfo
->mouse_face_beg_x
,
20571 &dpyinfo
->mouse_face_beg_y
, Qnil
);
20572 dpyinfo
->mouse_face_past_end
20573 = !fast_find_position (w
, XFASTINT (after
),
20574 &dpyinfo
->mouse_face_end_col
,
20575 &dpyinfo
->mouse_face_end_row
,
20576 &dpyinfo
->mouse_face_end_x
,
20577 &dpyinfo
->mouse_face_end_y
, Qnil
);
20578 dpyinfo
->mouse_face_window
= window
;
20580 if (BUFFERP (object
))
20581 dpyinfo
->mouse_face_face_id
20582 = face_at_buffer_position (w
, pos
, 0, 0,
20584 !dpyinfo
->mouse_face_hidden
);
20586 /* Display it as active. */
20587 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
20588 cursor
= No_Cursor
;
20590 else if (!NILP (mouse_face
) && STRINGP (object
))
20595 b
= Fprevious_single_property_change (make_number (pos
+ 1),
20598 e
= Fnext_single_property_change (position
, Qmouse_face
,
20601 b
= make_number (0);
20603 e
= make_number (SCHARS (object
) - 1);
20604 fast_find_string_pos (w
, XINT (b
), object
,
20605 &dpyinfo
->mouse_face_beg_col
,
20606 &dpyinfo
->mouse_face_beg_row
,
20607 &dpyinfo
->mouse_face_beg_x
,
20608 &dpyinfo
->mouse_face_beg_y
, 0);
20609 fast_find_string_pos (w
, XINT (e
), object
,
20610 &dpyinfo
->mouse_face_end_col
,
20611 &dpyinfo
->mouse_face_end_row
,
20612 &dpyinfo
->mouse_face_end_x
,
20613 &dpyinfo
->mouse_face_end_y
, 1);
20614 dpyinfo
->mouse_face_past_end
= 0;
20615 dpyinfo
->mouse_face_window
= window
;
20616 dpyinfo
->mouse_face_face_id
20617 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
20618 glyph
->face_id
, 1);
20619 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
20620 cursor
= No_Cursor
;
20622 else if (STRINGP (object
) && NILP (mouse_face
))
20624 /* A string which doesn't have mouse-face, but
20625 the text ``under'' it might have. */
20626 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
20627 int start
= MATRIX_ROW_START_CHARPOS (r
);
20629 pos
= string_buffer_position (w
, object
, start
);
20631 mouse_face
= get_char_property_and_overlay (make_number (pos
),
20635 if (!NILP (mouse_face
) && !NILP (overlay
))
20637 Lisp_Object before
= Foverlay_start (overlay
);
20638 Lisp_Object after
= Foverlay_end (overlay
);
20641 /* Note that we might not be able to find position
20642 BEFORE in the glyph matrix if the overlay is
20643 entirely covered by a `display' property. In
20644 this case, we overshoot. So let's stop in
20645 the glyph matrix before glyphs for OBJECT. */
20646 fast_find_position (w
, XFASTINT (before
),
20647 &dpyinfo
->mouse_face_beg_col
,
20648 &dpyinfo
->mouse_face_beg_row
,
20649 &dpyinfo
->mouse_face_beg_x
,
20650 &dpyinfo
->mouse_face_beg_y
,
20653 dpyinfo
->mouse_face_past_end
20654 = !fast_find_position (w
, XFASTINT (after
),
20655 &dpyinfo
->mouse_face_end_col
,
20656 &dpyinfo
->mouse_face_end_row
,
20657 &dpyinfo
->mouse_face_end_x
,
20658 &dpyinfo
->mouse_face_end_y
,
20660 dpyinfo
->mouse_face_window
= window
;
20661 dpyinfo
->mouse_face_face_id
20662 = face_at_buffer_position (w
, pos
, 0, 0,
20664 !dpyinfo
->mouse_face_hidden
);
20666 /* Display it as active. */
20667 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
20668 cursor
= No_Cursor
;
20675 /* Look for a `help-echo' property. */
20676 if (NILP (help_echo_string
)) {
20677 Lisp_Object help
, overlay
;
20679 /* Check overlays first. */
20680 help
= overlay
= Qnil
;
20681 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
20683 overlay
= overlay_vec
[i
];
20684 help
= Foverlay_get (overlay
, Qhelp_echo
);
20689 help_echo_string
= help
;
20690 help_echo_window
= window
;
20691 help_echo_object
= overlay
;
20692 help_echo_pos
= pos
;
20696 Lisp_Object object
= glyph
->object
;
20697 int charpos
= glyph
->charpos
;
20699 /* Try text properties. */
20700 if (STRINGP (object
)
20702 && charpos
< SCHARS (object
))
20704 help
= Fget_text_property (make_number (charpos
),
20705 Qhelp_echo
, object
);
20708 /* If the string itself doesn't specify a help-echo,
20709 see if the buffer text ``under'' it does. */
20710 struct glyph_row
*r
20711 = MATRIX_ROW (w
->current_matrix
, vpos
);
20712 int start
= MATRIX_ROW_START_CHARPOS (r
);
20713 int pos
= string_buffer_position (w
, object
, start
);
20716 help
= Fget_char_property (make_number (pos
),
20717 Qhelp_echo
, w
->buffer
);
20721 object
= w
->buffer
;
20726 else if (BUFFERP (object
)
20729 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
20734 help_echo_string
= help
;
20735 help_echo_window
= window
;
20736 help_echo_object
= object
;
20737 help_echo_pos
= charpos
;
20742 /* Look for a `pointer' property. */
20743 if (NILP (pointer
))
20745 /* Check overlays first. */
20746 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
20747 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
20749 if (NILP (pointer
))
20751 Lisp_Object object
= glyph
->object
;
20752 int charpos
= glyph
->charpos
;
20754 /* Try text properties. */
20755 if (STRINGP (object
)
20757 && charpos
< SCHARS (object
))
20759 pointer
= Fget_text_property (make_number (charpos
),
20761 if (NILP (pointer
))
20763 /* If the string itself doesn't specify a pointer,
20764 see if the buffer text ``under'' it does. */
20765 struct glyph_row
*r
20766 = MATRIX_ROW (w
->current_matrix
, vpos
);
20767 int start
= MATRIX_ROW_START_CHARPOS (r
);
20768 int pos
= string_buffer_position (w
, object
, start
);
20770 pointer
= Fget_char_property (make_number (pos
),
20771 Qpointer
, w
->buffer
);
20774 else if (BUFFERP (object
)
20777 pointer
= Fget_text_property (make_number (charpos
),
20784 current_buffer
= obuf
;
20789 define_frame_cursor1 (f
, cursor
, pointer
);
20794 Clear any mouse-face on window W. This function is part of the
20795 redisplay interface, and is called from try_window_id and similar
20796 functions to ensure the mouse-highlight is off. */
20799 x_clear_window_mouse_face (w
)
20802 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
20803 Lisp_Object window
;
20806 XSETWINDOW (window
, w
);
20807 if (EQ (window
, dpyinfo
->mouse_face_window
))
20808 clear_mouse_face (dpyinfo
);
20814 Just discard the mouse face information for frame F, if any.
20815 This is used when the size of F is changed. */
20818 cancel_mouse_face (f
)
20821 Lisp_Object window
;
20822 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20824 window
= dpyinfo
->mouse_face_window
;
20825 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
20827 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
20828 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
20829 dpyinfo
->mouse_face_window
= Qnil
;
20834 #endif /* HAVE_WINDOW_SYSTEM */
20837 /***********************************************************************
20839 ***********************************************************************/
20841 #ifdef HAVE_WINDOW_SYSTEM
20843 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
20844 which intersects rectangle R. R is in window-relative coordinates. */
20847 expose_area (w
, row
, r
, area
)
20849 struct glyph_row
*row
;
20851 enum glyph_row_area area
;
20853 struct glyph
*first
= row
->glyphs
[area
];
20854 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
20855 struct glyph
*last
;
20856 int first_x
, start_x
, x
;
20858 if (area
== TEXT_AREA
&& row
->fill_line_p
)
20859 /* If row extends face to end of line write the whole line. */
20860 draw_glyphs (w
, 0, row
, area
,
20861 0, row
->used
[area
],
20862 DRAW_NORMAL_TEXT
, 0);
20865 /* Set START_X to the window-relative start position for drawing glyphs of
20866 AREA. The first glyph of the text area can be partially visible.
20867 The first glyphs of other areas cannot. */
20868 start_x
= window_box_left_offset (w
, area
);
20870 if (area
== TEXT_AREA
)
20873 /* Find the first glyph that must be redrawn. */
20875 && x
+ first
->pixel_width
< r
->x
)
20877 x
+= first
->pixel_width
;
20881 /* Find the last one. */
20885 && x
< r
->x
+ r
->width
)
20887 x
+= last
->pixel_width
;
20893 draw_glyphs (w
, first_x
- start_x
, row
, area
,
20894 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
20895 DRAW_NORMAL_TEXT
, 0);
20900 /* Redraw the parts of the glyph row ROW on window W intersecting
20901 rectangle R. R is in window-relative coordinates. Value is
20902 non-zero if mouse-face was overwritten. */
20905 expose_line (w
, row
, r
)
20907 struct glyph_row
*row
;
20910 xassert (row
->enabled_p
);
20912 if (row
->mode_line_p
|| w
->pseudo_window_p
)
20913 draw_glyphs (w
, 0, row
, TEXT_AREA
,
20914 0, row
->used
[TEXT_AREA
],
20915 DRAW_NORMAL_TEXT
, 0);
20918 if (row
->used
[LEFT_MARGIN_AREA
])
20919 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
20920 if (row
->used
[TEXT_AREA
])
20921 expose_area (w
, row
, r
, TEXT_AREA
);
20922 if (row
->used
[RIGHT_MARGIN_AREA
])
20923 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
20924 draw_row_fringe_bitmaps (w
, row
);
20927 return row
->mouse_face_p
;
20931 /* Redraw those parts of glyphs rows during expose event handling that
20932 overlap other rows. Redrawing of an exposed line writes over parts
20933 of lines overlapping that exposed line; this function fixes that.
20935 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
20936 row in W's current matrix that is exposed and overlaps other rows.
20937 LAST_OVERLAPPING_ROW is the last such row. */
20940 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
20942 struct glyph_row
*first_overlapping_row
;
20943 struct glyph_row
*last_overlapping_row
;
20945 struct glyph_row
*row
;
20947 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
20948 if (row
->overlapping_p
)
20950 xassert (row
->enabled_p
&& !row
->mode_line_p
);
20952 if (row
->used
[LEFT_MARGIN_AREA
])
20953 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
20955 if (row
->used
[TEXT_AREA
])
20956 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
20958 if (row
->used
[RIGHT_MARGIN_AREA
])
20959 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
20964 /* Return non-zero if W's cursor intersects rectangle R. */
20967 phys_cursor_in_rect_p (w
, r
)
20971 XRectangle cr
, result
;
20972 struct glyph
*cursor_glyph
;
20974 cursor_glyph
= get_phys_cursor_glyph (w
);
20977 /* r is relative to W's box, but w->phys_cursor.x is relative
20978 to left edge of W's TEXT area. Adjust it. */
20979 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
20980 cr
.y
= w
->phys_cursor
.y
;
20981 cr
.width
= cursor_glyph
->pixel_width
;
20982 cr
.height
= w
->phys_cursor_height
;
20983 /* ++KFS: W32 version used W32-specific IntersectRect here, but
20984 I assume the effect is the same -- and this is portable. */
20985 return x_intersect_rectangles (&cr
, r
, &result
);
20993 Draw a vertical window border to the right of window W if W doesn't
20994 have vertical scroll bars. */
20997 x_draw_vertical_border (w
)
21000 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21002 /* We could do better, if we knew what type of scroll-bar the adjacent
21003 windows (on either side) have... But we don't :-(
21004 However, I think this works ok. ++KFS 2003-04-25 */
21006 /* Redraw borders between horizontally adjacent windows. Don't
21007 do it for frames with vertical scroll bars because either the
21008 right scroll bar of a window, or the left scroll bar of its
21009 neighbor will suffice as a border. */
21010 if (!WINDOW_RIGHTMOST_P (w
)
21011 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
21013 int x0
, x1
, y0
, y1
;
21015 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21018 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
21020 else if (!WINDOW_LEFTMOST_P (w
)
21021 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
21023 int x0
, x1
, y0
, y1
;
21025 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21028 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
21033 /* Redraw the part of window W intersection rectangle FR. Pixel
21034 coordinates in FR are frame-relative. Call this function with
21035 input blocked. Value is non-zero if the exposure overwrites
21039 expose_window (w
, fr
)
21043 struct frame
*f
= XFRAME (w
->frame
);
21045 int mouse_face_overwritten_p
= 0;
21047 /* If window is not yet fully initialized, do nothing. This can
21048 happen when toolkit scroll bars are used and a window is split.
21049 Reconfiguring the scroll bar will generate an expose for a newly
21051 if (w
->current_matrix
== NULL
)
21054 /* When we're currently updating the window, display and current
21055 matrix usually don't agree. Arrange for a thorough display
21057 if (w
== updated_window
)
21059 SET_FRAME_GARBAGED (f
);
21063 /* Frame-relative pixel rectangle of W. */
21064 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
21065 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
21066 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
21067 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
21069 if (x_intersect_rectangles (fr
, &wr
, &r
))
21071 int yb
= window_text_bottom_y (w
);
21072 struct glyph_row
*row
;
21073 int cursor_cleared_p
;
21074 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
21076 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
21077 r
.x
, r
.y
, r
.width
, r
.height
));
21079 /* Convert to window coordinates. */
21080 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
21081 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
21083 /* Turn off the cursor. */
21084 if (!w
->pseudo_window_p
21085 && phys_cursor_in_rect_p (w
, &r
))
21087 x_clear_cursor (w
);
21088 cursor_cleared_p
= 1;
21091 cursor_cleared_p
= 0;
21093 /* Update lines intersecting rectangle R. */
21094 first_overlapping_row
= last_overlapping_row
= NULL
;
21095 for (row
= w
->current_matrix
->rows
;
21100 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
21102 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
21103 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
21104 || (r
.y
>= y0
&& r
.y
< y1
)
21105 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
21107 if (row
->overlapping_p
)
21109 if (first_overlapping_row
== NULL
)
21110 first_overlapping_row
= row
;
21111 last_overlapping_row
= row
;
21114 if (expose_line (w
, row
, &r
))
21115 mouse_face_overwritten_p
= 1;
21122 /* Display the mode line if there is one. */
21123 if (WINDOW_WANTS_MODELINE_P (w
)
21124 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
21126 && row
->y
< r
.y
+ r
.height
)
21128 if (expose_line (w
, row
, &r
))
21129 mouse_face_overwritten_p
= 1;
21132 if (!w
->pseudo_window_p
)
21134 /* Fix the display of overlapping rows. */
21135 if (first_overlapping_row
)
21136 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
21138 /* Draw border between windows. */
21139 x_draw_vertical_border (w
);
21141 /* Turn the cursor on again. */
21142 if (cursor_cleared_p
)
21143 update_window_cursor (w
, 1);
21148 /* Display scroll bar for this window. */
21149 if (!NILP (w
->vertical_scroll_bar
))
21152 If this doesn't work here (maybe some header files are missing),
21153 make a function in macterm.c and call it to do the job! */
21155 = SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (w
->vertical_scroll_bar
));
21161 return mouse_face_overwritten_p
;
21166 /* Redraw (parts) of all windows in the window tree rooted at W that
21167 intersect R. R contains frame pixel coordinates. Value is
21168 non-zero if the exposure overwrites mouse-face. */
21171 expose_window_tree (w
, r
)
21175 struct frame
*f
= XFRAME (w
->frame
);
21176 int mouse_face_overwritten_p
= 0;
21178 while (w
&& !FRAME_GARBAGED_P (f
))
21180 if (!NILP (w
->hchild
))
21181 mouse_face_overwritten_p
21182 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
21183 else if (!NILP (w
->vchild
))
21184 mouse_face_overwritten_p
21185 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
21187 mouse_face_overwritten_p
|= expose_window (w
, r
);
21189 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
21192 return mouse_face_overwritten_p
;
21197 Redisplay an exposed area of frame F. X and Y are the upper-left
21198 corner of the exposed rectangle. W and H are width and height of
21199 the exposed area. All are pixel values. W or H zero means redraw
21200 the entire frame. */
21203 expose_frame (f
, x
, y
, w
, h
)
21208 int mouse_face_overwritten_p
= 0;
21210 TRACE ((stderr
, "expose_frame "));
21212 /* No need to redraw if frame will be redrawn soon. */
21213 if (FRAME_GARBAGED_P (f
))
21215 TRACE ((stderr
, " garbaged\n"));
21220 /* MAC_TODO: this is a kludge, but if scroll bars are not activated
21221 or deactivated here, for unknown reasons, activated scroll bars
21222 are shown in deactivated frames in some instances. */
21223 if (f
== FRAME_MAC_DISPLAY_INFO (f
)->x_focus_frame
)
21224 activate_scroll_bars (f
);
21226 deactivate_scroll_bars (f
);
21229 /* If basic faces haven't been realized yet, there is no point in
21230 trying to redraw anything. This can happen when we get an expose
21231 event while Emacs is starting, e.g. by moving another window. */
21232 if (FRAME_FACE_CACHE (f
) == NULL
21233 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
21235 TRACE ((stderr
, " no faces\n"));
21239 if (w
== 0 || h
== 0)
21242 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
21243 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
21253 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
21254 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
21256 if (WINDOWP (f
->tool_bar_window
))
21257 mouse_face_overwritten_p
21258 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
21260 #ifdef HAVE_X_WINDOWS
21262 #ifndef USE_X_TOOLKIT
21263 if (WINDOWP (f
->menu_bar_window
))
21264 mouse_face_overwritten_p
21265 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
21266 #endif /* not USE_X_TOOLKIT */
21270 /* Some window managers support a focus-follows-mouse style with
21271 delayed raising of frames. Imagine a partially obscured frame,
21272 and moving the mouse into partially obscured mouse-face on that
21273 frame. The visible part of the mouse-face will be highlighted,
21274 then the WM raises the obscured frame. With at least one WM, KDE
21275 2.1, Emacs is not getting any event for the raising of the frame
21276 (even tried with SubstructureRedirectMask), only Expose events.
21277 These expose events will draw text normally, i.e. not
21278 highlighted. Which means we must redo the highlight here.
21279 Subsume it under ``we love X''. --gerd 2001-08-15 */
21280 /* Included in Windows version because Windows most likely does not
21281 do the right thing if any third party tool offers
21282 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
21283 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
21285 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21286 if (f
== dpyinfo
->mouse_face_mouse_frame
)
21288 int x
= dpyinfo
->mouse_face_mouse_x
;
21289 int y
= dpyinfo
->mouse_face_mouse_y
;
21290 clear_mouse_face (dpyinfo
);
21291 note_mouse_highlight (f
, x
, y
);
21298 Determine the intersection of two rectangles R1 and R2. Return
21299 the intersection in *RESULT. Value is non-zero if RESULT is not
21303 x_intersect_rectangles (r1
, r2
, result
)
21304 XRectangle
*r1
, *r2
, *result
;
21306 XRectangle
*left
, *right
;
21307 XRectangle
*upper
, *lower
;
21308 int intersection_p
= 0;
21310 /* Rearrange so that R1 is the left-most rectangle. */
21312 left
= r1
, right
= r2
;
21314 left
= r2
, right
= r1
;
21316 /* X0 of the intersection is right.x0, if this is inside R1,
21317 otherwise there is no intersection. */
21318 if (right
->x
<= left
->x
+ left
->width
)
21320 result
->x
= right
->x
;
21322 /* The right end of the intersection is the minimum of the
21323 the right ends of left and right. */
21324 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
21327 /* Same game for Y. */
21329 upper
= r1
, lower
= r2
;
21331 upper
= r2
, lower
= r1
;
21333 /* The upper end of the intersection is lower.y0, if this is inside
21334 of upper. Otherwise, there is no intersection. */
21335 if (lower
->y
<= upper
->y
+ upper
->height
)
21337 result
->y
= lower
->y
;
21339 /* The lower end of the intersection is the minimum of the lower
21340 ends of upper and lower. */
21341 result
->height
= (min (lower
->y
+ lower
->height
,
21342 upper
->y
+ upper
->height
)
21344 intersection_p
= 1;
21348 return intersection_p
;
21351 #endif /* HAVE_WINDOW_SYSTEM */
21354 /***********************************************************************
21356 ***********************************************************************/
21361 Vwith_echo_area_save_vector
= Qnil
;
21362 staticpro (&Vwith_echo_area_save_vector
);
21364 Vmessage_stack
= Qnil
;
21365 staticpro (&Vmessage_stack
);
21367 Qinhibit_redisplay
= intern ("inhibit-redisplay");
21368 staticpro (&Qinhibit_redisplay
);
21370 message_dolog_marker1
= Fmake_marker ();
21371 staticpro (&message_dolog_marker1
);
21372 message_dolog_marker2
= Fmake_marker ();
21373 staticpro (&message_dolog_marker2
);
21374 message_dolog_marker3
= Fmake_marker ();
21375 staticpro (&message_dolog_marker3
);
21378 defsubr (&Sdump_frame_glyph_matrix
);
21379 defsubr (&Sdump_glyph_matrix
);
21380 defsubr (&Sdump_glyph_row
);
21381 defsubr (&Sdump_tool_bar_row
);
21382 defsubr (&Strace_redisplay
);
21383 defsubr (&Strace_to_stderr
);
21385 #ifdef HAVE_WINDOW_SYSTEM
21386 defsubr (&Stool_bar_lines_needed
);
21387 defsubr (&Slookup_image_map
);
21389 defsubr (&Sformat_mode_line
);
21391 staticpro (&Qmenu_bar_update_hook
);
21392 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
21394 staticpro (&Qoverriding_terminal_local_map
);
21395 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
21397 staticpro (&Qoverriding_local_map
);
21398 Qoverriding_local_map
= intern ("overriding-local-map");
21400 staticpro (&Qwindow_scroll_functions
);
21401 Qwindow_scroll_functions
= intern ("window-scroll-functions");
21403 staticpro (&Qredisplay_end_trigger_functions
);
21404 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
21406 staticpro (&Qinhibit_point_motion_hooks
);
21407 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
21409 QCdata
= intern (":data");
21410 staticpro (&QCdata
);
21411 Qdisplay
= intern ("display");
21412 staticpro (&Qdisplay
);
21413 Qspace_width
= intern ("space-width");
21414 staticpro (&Qspace_width
);
21415 Qraise
= intern ("raise");
21416 staticpro (&Qraise
);
21417 Qspace
= intern ("space");
21418 staticpro (&Qspace
);
21419 Qmargin
= intern ("margin");
21420 staticpro (&Qmargin
);
21421 Qpointer
= intern ("pointer");
21422 staticpro (&Qpointer
);
21423 Qleft_margin
= intern ("left-margin");
21424 staticpro (&Qleft_margin
);
21425 Qright_margin
= intern ("right-margin");
21426 staticpro (&Qright_margin
);
21427 QCalign_to
= intern (":align-to");
21428 staticpro (&QCalign_to
);
21429 QCrelative_width
= intern (":relative-width");
21430 staticpro (&QCrelative_width
);
21431 QCrelative_height
= intern (":relative-height");
21432 staticpro (&QCrelative_height
);
21433 QCeval
= intern (":eval");
21434 staticpro (&QCeval
);
21435 QCpropertize
= intern (":propertize");
21436 staticpro (&QCpropertize
);
21437 QCfile
= intern (":file");
21438 staticpro (&QCfile
);
21439 Qfontified
= intern ("fontified");
21440 staticpro (&Qfontified
);
21441 Qfontification_functions
= intern ("fontification-functions");
21442 staticpro (&Qfontification_functions
);
21443 Qtrailing_whitespace
= intern ("trailing-whitespace");
21444 staticpro (&Qtrailing_whitespace
);
21445 Qimage
= intern ("image");
21446 staticpro (&Qimage
);
21447 QCmap
= intern (":map");
21448 staticpro (&QCmap
);
21449 QCpointer
= intern (":pointer");
21450 staticpro (&QCpointer
);
21451 Qrect
= intern ("rect");
21452 staticpro (&Qrect
);
21453 Qcircle
= intern ("circle");
21454 staticpro (&Qcircle
);
21455 Qpoly
= intern ("poly");
21456 staticpro (&Qpoly
);
21457 Qmessage_truncate_lines
= intern ("message-truncate-lines");
21458 staticpro (&Qmessage_truncate_lines
);
21459 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
21460 staticpro (&Qcursor_in_non_selected_windows
);
21461 Qgrow_only
= intern ("grow-only");
21462 staticpro (&Qgrow_only
);
21463 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
21464 staticpro (&Qinhibit_menubar_update
);
21465 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
21466 staticpro (&Qinhibit_eval_during_redisplay
);
21467 Qposition
= intern ("position");
21468 staticpro (&Qposition
);
21469 Qbuffer_position
= intern ("buffer-position");
21470 staticpro (&Qbuffer_position
);
21471 Qobject
= intern ("object");
21472 staticpro (&Qobject
);
21473 Qbar
= intern ("bar");
21475 Qhbar
= intern ("hbar");
21476 staticpro (&Qhbar
);
21477 Qbox
= intern ("box");
21479 Qhollow
= intern ("hollow");
21480 staticpro (&Qhollow
);
21481 Qhand
= intern ("hand");
21482 staticpro (&Qhand
);
21483 Qarrow
= intern ("arrow");
21484 staticpro (&Qarrow
);
21485 Qtext
= intern ("text");
21486 staticpro (&Qtext
);
21487 Qrisky_local_variable
= intern ("risky-local-variable");
21488 staticpro (&Qrisky_local_variable
);
21489 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
21490 staticpro (&Qinhibit_free_realized_faces
);
21492 list_of_error
= Fcons (intern ("error"), Qnil
);
21493 staticpro (&list_of_error
);
21495 last_arrow_position
= Qnil
;
21496 last_arrow_string
= Qnil
;
21497 staticpro (&last_arrow_position
);
21498 staticpro (&last_arrow_string
);
21500 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
21501 staticpro (&echo_buffer
[0]);
21502 staticpro (&echo_buffer
[1]);
21504 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
21505 staticpro (&echo_area_buffer
[0]);
21506 staticpro (&echo_area_buffer
[1]);
21508 Vmessages_buffer_name
= build_string ("*Messages*");
21509 staticpro (&Vmessages_buffer_name
);
21511 mode_line_proptrans_alist
= Qnil
;
21512 staticpro (&mode_line_proptrans_alist
);
21514 mode_line_string_list
= Qnil
;
21515 staticpro (&mode_line_string_list
);
21517 help_echo_string
= Qnil
;
21518 staticpro (&help_echo_string
);
21519 help_echo_object
= Qnil
;
21520 staticpro (&help_echo_object
);
21521 help_echo_window
= Qnil
;
21522 staticpro (&help_echo_window
);
21523 previous_help_echo_string
= Qnil
;
21524 staticpro (&previous_help_echo_string
);
21525 help_echo_pos
= -1;
21527 #ifdef HAVE_WINDOW_SYSTEM
21528 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
21529 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
21530 For example, if a block cursor is over a tab, it will be drawn as
21531 wide as that tab on the display. */);
21532 x_stretch_cursor_p
= 0;
21535 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
21536 doc
: /* Non-nil means highlight trailing whitespace.
21537 The face used for trailing whitespace is `trailing-whitespace'. */);
21538 Vshow_trailing_whitespace
= Qnil
;
21540 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
21541 doc
: /* The pointer shape to show in void text areas.
21542 Nil means to show the text pointer. Other options are `arrow', `text',
21543 `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
21544 Vvoid_text_area_pointer
= Qarrow
;
21546 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
21547 doc
: /* Non-nil means don't actually do any redisplay.
21548 This is used for internal purposes. */);
21549 Vinhibit_redisplay
= Qnil
;
21551 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
21552 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
21553 Vglobal_mode_string
= Qnil
;
21555 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
21556 doc
: /* Marker for where to display an arrow on top of the buffer text.
21557 This must be the beginning of a line in order to work.
21558 See also `overlay-arrow-string'. */);
21559 Voverlay_arrow_position
= Qnil
;
21561 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
21562 doc
: /* String to display as an arrow. See also `overlay-arrow-position'. */);
21563 Voverlay_arrow_string
= Qnil
;
21565 DEFVAR_INT ("scroll-step", &scroll_step
,
21566 doc
: /* *The number of lines to try scrolling a window by when point moves out.
21567 If that fails to bring point back on frame, point is centered instead.
21568 If this is zero, point is always centered after it moves off frame.
21569 If you want scrolling to always be a line at a time, you should set
21570 `scroll-conservatively' to a large value rather than set this to 1. */);
21572 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
21573 doc
: /* *Scroll up to this many lines, to bring point back on screen.
21574 A value of zero means to scroll the text to center point vertically
21575 in the window. */);
21576 scroll_conservatively
= 0;
21578 DEFVAR_INT ("scroll-margin", &scroll_margin
,
21579 doc
: /* *Number of lines of margin at the top and bottom of a window.
21580 Recenter the window whenever point gets within this many lines
21581 of the top or bottom of the window. */);
21584 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
21585 doc
: /* Pixels per inch on current display.
21586 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
21587 Vdisplay_pixels_per_inch
= make_float (72.0);
21590 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
21593 DEFVAR_BOOL ("truncate-partial-width-windows",
21594 &truncate_partial_width_windows
,
21595 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
21596 truncate_partial_width_windows
= 1;
21598 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
21599 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
21600 Any other value means to use the appropriate face, `mode-line',
21601 `header-line', or `menu' respectively. */);
21602 mode_line_inverse_video
= 1;
21604 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
21605 doc
: /* *Maximum buffer size for which line number should be displayed.
21606 If the buffer is bigger than this, the line number does not appear
21607 in the mode line. A value of nil means no limit. */);
21608 Vline_number_display_limit
= Qnil
;
21610 DEFVAR_INT ("line-number-display-limit-width",
21611 &line_number_display_limit_width
,
21612 doc
: /* *Maximum line width (in characters) for line number display.
21613 If the average length of the lines near point is bigger than this, then the
21614 line number may be omitted from the mode line. */);
21615 line_number_display_limit_width
= 200;
21617 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
21618 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
21619 highlight_nonselected_windows
= 0;
21621 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
21622 doc
: /* Non-nil if more than one frame is visible on this display.
21623 Minibuffer-only frames don't count, but iconified frames do.
21624 This variable is not guaranteed to be accurate except while processing
21625 `frame-title-format' and `icon-title-format'. */);
21627 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
21628 doc
: /* Template for displaying the title bar of visible frames.
21629 \(Assuming the window manager supports this feature.)
21630 This variable has the same structure as `mode-line-format' (which see),
21631 and is used only on frames for which no explicit name has been set
21632 \(see `modify-frame-parameters'). */);
21634 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
21635 doc
: /* Template for displaying the title bar of an iconified frame.
21636 \(Assuming the window manager supports this feature.)
21637 This variable has the same structure as `mode-line-format' (which see),
21638 and is used only on frames for which no explicit name has been set
21639 \(see `modify-frame-parameters'). */);
21641 = Vframe_title_format
21642 = Fcons (intern ("multiple-frames"),
21643 Fcons (build_string ("%b"),
21644 Fcons (Fcons (empty_string
,
21645 Fcons (intern ("invocation-name"),
21646 Fcons (build_string ("@"),
21647 Fcons (intern ("system-name"),
21651 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
21652 doc
: /* Maximum number of lines to keep in the message log buffer.
21653 If nil, disable message logging. If t, log messages but don't truncate
21654 the buffer when it becomes large. */);
21655 Vmessage_log_max
= make_number (50);
21657 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
21658 doc
: /* Functions called before redisplay, if window sizes have changed.
21659 The value should be a list of functions that take one argument.
21660 Just before redisplay, for each frame, if any of its windows have changed
21661 size since the last redisplay, or have been split or deleted,
21662 all the functions in the list are called, with the frame as argument. */);
21663 Vwindow_size_change_functions
= Qnil
;
21665 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
21666 doc
: /* List of Functions to call before redisplaying a window with scrolling.
21667 Each function is called with two arguments, the window
21668 and its new display-start position. Note that the value of `window-end'
21669 is not valid when these functions are called. */);
21670 Vwindow_scroll_functions
= Qnil
;
21672 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
21673 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
21674 mouse_autoselect_window
= 0;
21676 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
21677 doc
: /* *Non-nil means automatically resize tool-bars.
21678 This increases a tool-bar's height if not all tool-bar items are visible.
21679 It decreases a tool-bar's height when it would display blank lines
21681 auto_resize_tool_bars_p
= 1;
21683 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
21684 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
21685 auto_raise_tool_bar_buttons_p
= 1;
21687 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
21688 doc
: /* *Margin around tool-bar buttons in pixels.
21689 If an integer, use that for both horizontal and vertical margins.
21690 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
21691 HORZ specifying the horizontal margin, and VERT specifying the
21692 vertical margin. */);
21693 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
21695 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
21696 doc
: /* *Relief thickness of tool-bar buttons. */);
21697 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
21699 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
21700 doc
: /* List of functions to call to fontify regions of text.
21701 Each function is called with one argument POS. Functions must
21702 fontify a region starting at POS in the current buffer, and give
21703 fontified regions the property `fontified'. */);
21704 Vfontification_functions
= Qnil
;
21705 Fmake_variable_buffer_local (Qfontification_functions
);
21707 DEFVAR_BOOL ("unibyte-display-via-language-environment",
21708 &unibyte_display_via_language_environment
,
21709 doc
: /* *Non-nil means display unibyte text according to language environment.
21710 Specifically this means that unibyte non-ASCII characters
21711 are displayed by converting them to the equivalent multibyte characters
21712 according to the current language environment. As a result, they are
21713 displayed according to the current fontset. */);
21714 unibyte_display_via_language_environment
= 0;
21716 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
21717 doc
: /* *Maximum height for resizing mini-windows.
21718 If a float, it specifies a fraction of the mini-window frame's height.
21719 If an integer, it specifies a number of lines. */);
21720 Vmax_mini_window_height
= make_float (0.25);
21722 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
21723 doc
: /* *How to resize mini-windows.
21724 A value of nil means don't automatically resize mini-windows.
21725 A value of t means resize them to fit the text displayed in them.
21726 A value of `grow-only', the default, means let mini-windows grow
21727 only, until their display becomes empty, at which point the windows
21728 go back to their normal size. */);
21729 Vresize_mini_windows
= Qgrow_only
;
21731 DEFVAR_LISP ("cursor-in-non-selected-windows",
21732 &Vcursor_in_non_selected_windows
,
21733 doc
: /* *Cursor type to display in non-selected windows.
21734 t means to use hollow box cursor. See `cursor-type' for other values. */);
21735 Vcursor_in_non_selected_windows
= Qt
;
21737 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
21738 doc
: /* Alist specifying how to blink the cursor off.
21739 Each element has the form (ON-STATE . OFF-STATE). Whenever the
21740 `cursor-type' frame-parameter or variable equals ON-STATE,
21741 comparing using `equal', Emacs uses OFF-STATE to specify
21742 how to blink it off. */);
21743 Vblink_cursor_alist
= Qnil
;
21745 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
21746 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
21747 automatic_hscrolling_p
= 1;
21749 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
21750 doc
: /* *How many columns away from the window edge point is allowed to get
21751 before automatic hscrolling will horizontally scroll the window. */);
21752 hscroll_margin
= 5;
21754 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
21755 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
21756 When point is less than `automatic-hscroll-margin' columns from the window
21757 edge, automatic hscrolling will scroll the window by the amount of columns
21758 determined by this variable. If its value is a positive integer, scroll that
21759 many columns. If it's a positive floating-point number, it specifies the
21760 fraction of the window's width to scroll. If it's nil or zero, point will be
21761 centered horizontally after the scroll. Any other value, including negative
21762 numbers, are treated as if the value were zero.
21764 Automatic hscrolling always moves point outside the scroll margin, so if
21765 point was more than scroll step columns inside the margin, the window will
21766 scroll more than the value given by the scroll step.
21768 Note that the lower bound for automatic hscrolling specified by `scroll-left'
21769 and `scroll-right' overrides this variable's effect. */);
21770 Vhscroll_step
= make_number (0);
21772 DEFVAR_LISP ("image-types", &Vimage_types
,
21773 doc
: /* List of supported image types.
21774 Each element of the list is a symbol for a supported image type. */);
21775 Vimage_types
= Qnil
;
21777 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
21778 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
21779 Bind this around calls to `message' to let it take effect. */);
21780 message_truncate_lines
= 0;
21782 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
21783 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
21784 Can be used to update submenus whose contents should vary. */);
21785 Vmenu_bar_update_hook
= Qnil
;
21787 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
21788 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
21789 inhibit_menubar_update
= 0;
21791 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
21792 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
21793 inhibit_eval_during_redisplay
= 0;
21795 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
21796 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
21797 inhibit_free_realized_faces
= 0;
21800 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
21801 doc
: /* Inhibit try_window_id display optimization. */);
21802 inhibit_try_window_id
= 0;
21804 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
21805 doc
: /* Inhibit try_window_reusing display optimization. */);
21806 inhibit_try_window_reusing
= 0;
21808 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
21809 doc
: /* Inhibit try_cursor_movement display optimization. */);
21810 inhibit_try_cursor_movement
= 0;
21811 #endif /* GLYPH_DEBUG */
21815 /* Initialize this module when Emacs starts. */
21820 Lisp_Object root_window
;
21821 struct window
*mini_w
;
21823 current_header_line_height
= current_mode_line_height
= -1;
21825 CHARPOS (this_line_start_pos
) = 0;
21827 mini_w
= XWINDOW (minibuf_window
);
21828 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
21830 if (!noninteractive
)
21832 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
21835 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
21836 set_window_height (root_window
,
21837 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
21839 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
21840 set_window_height (minibuf_window
, 1, 0);
21842 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
21843 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
21845 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
21846 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
21847 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
21849 /* The default ellipsis glyphs `...'. */
21850 for (i
= 0; i
< 3; ++i
)
21851 default_invis_vector
[i
] = make_number ('.');
21855 /* Allocate the buffer for frame titles.
21856 Also used for `format-mode-line'. */
21858 frame_title_buf
= (char *) xmalloc (size
);
21859 frame_title_buf_end
= frame_title_buf
+ size
;
21860 frame_title_ptr
= NULL
;
21863 help_echo_showing_p
= 0;
21867 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
21868 (do not change this comment) */