1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985,86,87,88,93,94,95,97,98,99,2000,01,02,03,04
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay do? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking an iterator structure (struct it)
126 Iteration over things to be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator.
128 Calls to get_next_display_element fill the iterator structure with
129 relevant information about the next thing to display. Calls to
130 set_iterator_to_next move the iterator to the next thing.
132 Besides this, an iterator also contains information about the
133 display environment in which glyphs for display elements are to be
134 produced. It has fields for the width and height of the display,
135 the information whether long lines are truncated or continued, a
136 current X and Y position, and lots of other stuff you can better
139 Glyphs in a desired matrix are normally constructed in a loop
140 calling get_next_display_element and then produce_glyphs. The call
141 to produce_glyphs will fill the iterator structure with pixel
142 information about the element being displayed and at the same time
143 produce glyphs for it. If the display element fits on the line
144 being displayed, set_iterator_to_next is called next, otherwise the
145 glyphs produced are discarded.
150 That just couldn't be all, could it? What about terminal types not
151 supporting operations on sub-windows of the screen? To update the
152 display on such a terminal, window-based glyph matrices are not
153 well suited. To be able to reuse part of the display (scrolling
154 lines up and down), we must instead have a view of the whole
155 screen. This is what `frame matrices' are for. They are a trick.
157 Frames on terminals like above have a glyph pool. Windows on such
158 a frame sub-allocate their glyph memory from their frame's glyph
159 pool. The frame itself is given its own glyph matrices. By
160 coincidence---or maybe something else---rows in window glyph
161 matrices are slices of corresponding rows in frame matrices. Thus
162 writing to window matrices implicitly updates a frame matrix which
163 provides us with the view of the whole screen that we originally
164 wanted to have without having to move many bytes around. To be
165 honest, there is a little bit more done, but not much more. If you
166 plan to extend that code, take a look at dispnew.c. The function
167 build_frame_matrix is a good starting point. */
173 #include "keyboard.h"
176 #include "termchar.h"
177 #include "dispextern.h"
181 #include "commands.h"
185 #include "termhooks.h"
186 #include "intervals.h"
189 #include "region-cache.h"
191 #include "blockinput.h"
193 #ifdef HAVE_X_WINDOWS
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 #ifdef HAVE_WINDOW_SYSTEM
314 /* Non-nil means that newline may flow into the right fringe. */
316 Lisp_Object Voverflow_newline_into_fringe
;
317 #endif /* HAVE_WINDOW_SYSTEM */
319 /* Test if overflow newline into fringe. Called with iterator IT
320 at or past right window margin, and with IT->current_x set. */
322 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
323 (!NILP (Voverflow_newline_into_fringe) \
324 && FRAME_WINDOW_P (it->f) \
325 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
326 && it->current_x == it->last_visible_x)
328 /* Non-nil means show the text cursor in void text areas
329 i.e. in blank areas after eol and eob. This used to be
330 the default in 21.3. */
332 Lisp_Object Vvoid_text_area_pointer
;
334 /* Name of the face used to highlight trailing whitespace. */
336 Lisp_Object Qtrailing_whitespace
;
338 /* The symbol `image' which is the car of the lists used to represent
343 /* The image map types. */
344 Lisp_Object QCmap
, QCpointer
;
345 Lisp_Object Qrect
, Qcircle
, Qpoly
;
347 /* Non-zero means print newline to stdout before next mini-buffer
350 int noninteractive_need_newline
;
352 /* Non-zero means print newline to message log before next message. */
354 static int message_log_need_newline
;
356 /* Three markers that message_dolog uses.
357 It could allocate them itself, but that causes trouble
358 in handling memory-full errors. */
359 static Lisp_Object message_dolog_marker1
;
360 static Lisp_Object message_dolog_marker2
;
361 static Lisp_Object message_dolog_marker3
;
363 /* The buffer position of the first character appearing entirely or
364 partially on the line of the selected window which contains the
365 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
366 redisplay optimization in redisplay_internal. */
368 static struct text_pos this_line_start_pos
;
370 /* Number of characters past the end of the line above, including the
371 terminating newline. */
373 static struct text_pos this_line_end_pos
;
375 /* The vertical positions and the height of this line. */
377 static int this_line_vpos
;
378 static int this_line_y
;
379 static int this_line_pixel_height
;
381 /* X position at which this display line starts. Usually zero;
382 negative if first character is partially visible. */
384 static int this_line_start_x
;
386 /* Buffer that this_line_.* variables are referring to. */
388 static struct buffer
*this_line_buffer
;
390 /* Nonzero means truncate lines in all windows less wide than the
393 int truncate_partial_width_windows
;
395 /* A flag to control how to display unibyte 8-bit character. */
397 int unibyte_display_via_language_environment
;
399 /* Nonzero means we have more than one non-mini-buffer-only frame.
400 Not guaranteed to be accurate except while parsing
401 frame-title-format. */
405 Lisp_Object Vglobal_mode_string
;
407 /* Marker for where to display an arrow on top of the buffer text. */
409 Lisp_Object Voverlay_arrow_position
;
411 /* String to display for the arrow. Only used on terminal frames. */
413 Lisp_Object Voverlay_arrow_string
;
415 /* Values of those variables at last redisplay. However, if
416 Voverlay_arrow_position is a marker, last_arrow_position is its
417 numerical position. */
419 static Lisp_Object last_arrow_position
, last_arrow_string
;
421 /* Like mode-line-format, but for the title bar on a visible frame. */
423 Lisp_Object Vframe_title_format
;
425 /* Like mode-line-format, but for the title bar on an iconified frame. */
427 Lisp_Object Vicon_title_format
;
429 /* List of functions to call when a window's size changes. These
430 functions get one arg, a frame on which one or more windows' sizes
433 static Lisp_Object Vwindow_size_change_functions
;
435 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
437 /* Nonzero if overlay arrow has been displayed once in this window. */
439 static int overlay_arrow_seen
;
441 /* Nonzero means highlight the region even in nonselected windows. */
443 int highlight_nonselected_windows
;
445 /* If cursor motion alone moves point off frame, try scrolling this
446 many lines up or down if that will bring it back. */
448 static EMACS_INT scroll_step
;
450 /* Nonzero means scroll just far enough to bring point back on the
451 screen, when appropriate. */
453 static EMACS_INT scroll_conservatively
;
455 /* Recenter the window whenever point gets within this many lines of
456 the top or bottom of the window. This value is translated into a
457 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
458 that there is really a fixed pixel height scroll margin. */
460 EMACS_INT scroll_margin
;
462 /* Number of windows showing the buffer of the selected window (or
463 another buffer with the same base buffer). keyboard.c refers to
468 /* Vector containing glyphs for an ellipsis `...'. */
470 static Lisp_Object default_invis_vector
[3];
472 /* Zero means display the mode-line/header-line/menu-bar in the default face
473 (this slightly odd definition is for compatibility with previous versions
474 of emacs), non-zero means display them using their respective faces.
476 This variable is deprecated. */
478 int mode_line_inverse_video
;
480 /* Prompt to display in front of the mini-buffer contents. */
482 Lisp_Object minibuf_prompt
;
484 /* Width of current mini-buffer prompt. Only set after display_line
485 of the line that contains the prompt. */
487 int minibuf_prompt_width
;
489 /* This is the window where the echo area message was displayed. It
490 is always a mini-buffer window, but it may not be the same window
491 currently active as a mini-buffer. */
493 Lisp_Object echo_area_window
;
495 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
496 pushes the current message and the value of
497 message_enable_multibyte on the stack, the function restore_message
498 pops the stack and displays MESSAGE again. */
500 Lisp_Object Vmessage_stack
;
502 /* Nonzero means multibyte characters were enabled when the echo area
503 message was specified. */
505 int message_enable_multibyte
;
507 /* Nonzero if we should redraw the mode lines on the next redisplay. */
509 int update_mode_lines
;
511 /* Nonzero if window sizes or contents have changed since last
512 redisplay that finished. */
514 int windows_or_buffers_changed
;
516 /* Nonzero means a frame's cursor type has been changed. */
518 int cursor_type_changed
;
520 /* Nonzero after display_mode_line if %l was used and it displayed a
523 int line_number_displayed
;
525 /* Maximum buffer size for which to display line numbers. */
527 Lisp_Object Vline_number_display_limit
;
529 /* Line width to consider when repositioning for line number display. */
531 static EMACS_INT line_number_display_limit_width
;
533 /* Number of lines to keep in the message log buffer. t means
534 infinite. nil means don't log at all. */
536 Lisp_Object Vmessage_log_max
;
538 /* The name of the *Messages* buffer, a string. */
540 static Lisp_Object Vmessages_buffer_name
;
542 /* Current, index 0, and last displayed echo area message. Either
543 buffers from echo_buffers, or nil to indicate no message. */
545 Lisp_Object echo_area_buffer
[2];
547 /* The buffers referenced from echo_area_buffer. */
549 static Lisp_Object echo_buffer
[2];
551 /* A vector saved used in with_area_buffer to reduce consing. */
553 static Lisp_Object Vwith_echo_area_save_vector
;
555 /* Non-zero means display_echo_area should display the last echo area
556 message again. Set by redisplay_preserve_echo_area. */
558 static int display_last_displayed_message_p
;
560 /* Nonzero if echo area is being used by print; zero if being used by
563 int message_buf_print
;
565 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
567 Lisp_Object Qinhibit_menubar_update
;
568 int inhibit_menubar_update
;
570 /* Maximum height for resizing mini-windows. Either a float
571 specifying a fraction of the available height, or an integer
572 specifying a number of lines. */
574 Lisp_Object Vmax_mini_window_height
;
576 /* Non-zero means messages should be displayed with truncated
577 lines instead of being continued. */
579 int message_truncate_lines
;
580 Lisp_Object Qmessage_truncate_lines
;
582 /* Set to 1 in clear_message to make redisplay_internal aware
583 of an emptied echo area. */
585 static int message_cleared_p
;
587 /* Non-zero means we want a hollow cursor in windows that are not
588 selected. Zero means there's no cursor in such windows. */
590 Lisp_Object Vcursor_in_non_selected_windows
;
591 Lisp_Object Qcursor_in_non_selected_windows
;
593 /* How to blink the default frame cursor off. */
594 Lisp_Object Vblink_cursor_alist
;
596 /* A scratch glyph row with contents used for generating truncation
597 glyphs. Also used in direct_output_for_insert. */
599 #define MAX_SCRATCH_GLYPHS 100
600 struct glyph_row scratch_glyph_row
;
601 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
603 /* Ascent and height of the last line processed by move_it_to. */
605 static int last_max_ascent
, last_height
;
607 /* Non-zero if there's a help-echo in the echo area. */
609 int help_echo_showing_p
;
611 /* If >= 0, computed, exact values of mode-line and header-line height
612 to use in the macros CURRENT_MODE_LINE_HEIGHT and
613 CURRENT_HEADER_LINE_HEIGHT. */
615 int current_mode_line_height
, current_header_line_height
;
617 /* The maximum distance to look ahead for text properties. Values
618 that are too small let us call compute_char_face and similar
619 functions too often which is expensive. Values that are too large
620 let us call compute_char_face and alike too often because we
621 might not be interested in text properties that far away. */
623 #define TEXT_PROP_DISTANCE_LIMIT 100
627 /* Variables to turn off display optimizations from Lisp. */
629 int inhibit_try_window_id
, inhibit_try_window_reusing
;
630 int inhibit_try_cursor_movement
;
632 /* Non-zero means print traces of redisplay if compiled with
635 int trace_redisplay_p
;
637 #endif /* GLYPH_DEBUG */
639 #ifdef DEBUG_TRACE_MOVE
640 /* Non-zero means trace with TRACE_MOVE to stderr. */
643 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
645 #define TRACE_MOVE(x) (void) 0
648 /* Non-zero means automatically scroll windows horizontally to make
651 int automatic_hscrolling_p
;
653 /* How close to the margin can point get before the window is scrolled
655 EMACS_INT hscroll_margin
;
657 /* How much to scroll horizontally when point is inside the above margin. */
658 Lisp_Object Vhscroll_step
;
660 /* A list of symbols, one for each supported image type. */
662 Lisp_Object Vimage_types
;
664 /* The variable `resize-mini-windows'. If nil, don't resize
665 mini-windows. If t, always resize them to fit the text they
666 display. If `grow-only', let mini-windows grow only until they
669 Lisp_Object Vresize_mini_windows
;
671 /* Buffer being redisplayed -- for redisplay_window_error. */
673 struct buffer
*displayed_buffer
;
675 /* Value returned from text property handlers (see below). */
680 HANDLED_RECOMPUTE_PROPS
,
681 HANDLED_OVERLAY_STRING_CONSUMED
,
685 /* A description of text properties that redisplay is interested
690 /* The name of the property. */
693 /* A unique index for the property. */
696 /* A handler function called to set up iterator IT from the property
697 at IT's current position. Value is used to steer handle_stop. */
698 enum prop_handled (*handler
) P_ ((struct it
*it
));
701 static enum prop_handled handle_face_prop
P_ ((struct it
*));
702 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
703 static enum prop_handled handle_display_prop
P_ ((struct it
*));
704 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
705 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
706 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
708 /* Properties handled by iterators. */
710 static struct props it_props
[] =
712 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
713 /* Handle `face' before `display' because some sub-properties of
714 `display' need to know the face. */
715 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
716 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
717 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
718 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
722 /* Value is the position described by X. If X is a marker, value is
723 the marker_position of X. Otherwise, value is X. */
725 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
727 /* Enumeration returned by some move_it_.* functions internally. */
731 /* Not used. Undefined value. */
734 /* Move ended at the requested buffer position or ZV. */
735 MOVE_POS_MATCH_OR_ZV
,
737 /* Move ended at the requested X pixel position. */
740 /* Move within a line ended at the end of a line that must be
744 /* Move within a line ended at the end of a line that would
745 be displayed truncated. */
748 /* Move within a line ended at a line end. */
752 /* This counter is used to clear the face cache every once in a while
753 in redisplay_internal. It is incremented for each redisplay.
754 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
757 #define CLEAR_FACE_CACHE_COUNT 500
758 static int clear_face_cache_count
;
760 /* Non-zero while redisplay_internal is in progress. */
764 /* Non-zero means don't free realized faces. Bound while freeing
765 realized faces is dangerous because glyph matrices might still
768 int inhibit_free_realized_faces
;
769 Lisp_Object Qinhibit_free_realized_faces
;
771 /* If a string, XTread_socket generates an event to display that string.
772 (The display is done in read_char.) */
774 Lisp_Object help_echo_string
;
775 Lisp_Object help_echo_window
;
776 Lisp_Object help_echo_object
;
779 /* Temporary variable for XTread_socket. */
781 Lisp_Object previous_help_echo_string
;
785 /* Function prototypes. */
787 static void setup_for_ellipsis
P_ ((struct it
*));
788 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
789 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
790 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
791 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
792 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
793 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
796 static int invisible_text_between_p
P_ ((struct it
*, int, int));
799 static int next_element_from_ellipsis
P_ ((struct it
*));
800 static void pint2str
P_ ((char *, int, int));
801 static void pint2hrstr
P_ ((char *, int, int));
802 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
804 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
805 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
806 static void store_frame_title_char
P_ ((char));
807 static int store_frame_title
P_ ((const unsigned char *, int, int));
808 static void x_consider_frame_title
P_ ((Lisp_Object
));
809 static void handle_stop
P_ ((struct it
*));
810 static int tool_bar_lines_needed
P_ ((struct frame
*));
811 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
812 static void ensure_echo_area_buffers
P_ ((void));
813 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
814 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
815 static int with_echo_area_buffer
P_ ((struct window
*, int,
816 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
817 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
818 static void clear_garbaged_frames
P_ ((void));
819 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
820 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
821 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
822 static int display_echo_area
P_ ((struct window
*));
823 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
824 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
825 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
826 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
827 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
829 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
830 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
831 static void insert_left_trunc_glyphs
P_ ((struct it
*));
832 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
833 static void extend_face_to_end_of_line
P_ ((struct it
*));
834 static int append_space
P_ ((struct it
*, int));
835 static int make_cursor_line_fully_visible
P_ ((struct window
*));
836 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
837 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
838 static int trailing_whitespace_p
P_ ((int));
839 static int message_log_check_duplicate
P_ ((int, int, int, int));
840 static void push_it
P_ ((struct it
*));
841 static void pop_it
P_ ((struct it
*));
842 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
843 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
844 static void redisplay_internal
P_ ((int));
845 static int echo_area_display
P_ ((int));
846 static void redisplay_windows
P_ ((Lisp_Object
));
847 static void redisplay_window
P_ ((Lisp_Object
, int));
848 static Lisp_Object
redisplay_window_error ();
849 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
850 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
851 static void update_menu_bar
P_ ((struct frame
*, int));
852 static int try_window_reusing_current_matrix
P_ ((struct window
*));
853 static int try_window_id
P_ ((struct window
*));
854 static int display_line
P_ ((struct it
*));
855 static int display_mode_lines
P_ ((struct window
*));
856 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
857 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
858 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
859 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
860 static void display_menu_bar
P_ ((struct window
*));
861 static int display_count_lines
P_ ((int, int, int, int, int *));
862 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
863 int, int, struct it
*, int, int, int, int));
864 static void compute_line_metrics
P_ ((struct it
*));
865 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
866 static int get_overlay_strings
P_ ((struct it
*, int));
867 static void next_overlay_string
P_ ((struct it
*));
868 static void reseat
P_ ((struct it
*, struct text_pos
, int));
869 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
870 static void back_to_previous_visible_line_start
P_ ((struct it
*));
871 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
872 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
873 static int next_element_from_display_vector
P_ ((struct it
*));
874 static int next_element_from_string
P_ ((struct it
*));
875 static int next_element_from_c_string
P_ ((struct it
*));
876 static int next_element_from_buffer
P_ ((struct it
*));
877 static int next_element_from_composition
P_ ((struct it
*));
878 static int next_element_from_image
P_ ((struct it
*));
879 static int next_element_from_stretch
P_ ((struct it
*));
880 static void load_overlay_strings
P_ ((struct it
*, int));
881 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
882 struct display_pos
*));
883 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
884 Lisp_Object
, int, int, int, int));
885 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
887 void move_it_vertically_backward
P_ ((struct it
*, int));
888 static void init_to_row_start
P_ ((struct it
*, struct window
*,
889 struct glyph_row
*));
890 static int init_to_row_end
P_ ((struct it
*, struct window
*,
891 struct glyph_row
*));
892 static void back_to_previous_line_start
P_ ((struct it
*));
893 static int forward_to_next_line_start
P_ ((struct it
*, int *));
894 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
896 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
897 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
898 static int number_of_chars
P_ ((unsigned char *, int));
899 static void compute_stop_pos
P_ ((struct it
*));
900 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
902 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
903 static int next_overlay_change
P_ ((int));
904 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
905 Lisp_Object
, struct text_pos
*,
907 static int underlying_face_id
P_ ((struct it
*));
908 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
911 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
912 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
914 #ifdef HAVE_WINDOW_SYSTEM
916 static void update_tool_bar
P_ ((struct frame
*, int));
917 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
918 static int redisplay_tool_bar
P_ ((struct frame
*));
919 static void display_tool_bar_line
P_ ((struct it
*));
920 static void notice_overwritten_cursor
P_ ((struct window
*,
922 int, int, int, int));
926 #endif /* HAVE_WINDOW_SYSTEM */
929 /***********************************************************************
930 Window display dimensions
931 ***********************************************************************/
933 /* Return the bottom boundary y-position for text lines in window W.
934 This is the first y position at which a line cannot start.
935 It is relative to the top of the window.
937 This is the height of W minus the height of a mode line, if any. */
940 window_text_bottom_y (w
)
943 int height
= WINDOW_TOTAL_HEIGHT (w
);
945 if (WINDOW_WANTS_MODELINE_P (w
))
946 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
950 /* Return the pixel width of display area AREA of window W. AREA < 0
951 means return the total width of W, not including fringes to
952 the left and right of the window. */
955 window_box_width (w
, area
)
959 int cols
= XFASTINT (w
->total_cols
);
962 if (!w
->pseudo_window_p
)
964 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
966 if (area
== TEXT_AREA
)
968 if (INTEGERP (w
->left_margin_cols
))
969 cols
-= XFASTINT (w
->left_margin_cols
);
970 if (INTEGERP (w
->right_margin_cols
))
971 cols
-= XFASTINT (w
->right_margin_cols
);
972 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
974 else if (area
== LEFT_MARGIN_AREA
)
976 cols
= (INTEGERP (w
->left_margin_cols
)
977 ? XFASTINT (w
->left_margin_cols
) : 0);
980 else if (area
== RIGHT_MARGIN_AREA
)
982 cols
= (INTEGERP (w
->right_margin_cols
)
983 ? XFASTINT (w
->right_margin_cols
) : 0);
988 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
992 /* Return the pixel height of the display area of window W, not
993 including mode lines of W, if any. */
996 window_box_height (w
)
999 struct frame
*f
= XFRAME (w
->frame
);
1000 int height
= WINDOW_TOTAL_HEIGHT (w
);
1002 xassert (height
>= 0);
1004 /* Note: the code below that determines the mode-line/header-line
1005 height is essentially the same as that contained in the macro
1006 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1007 the appropriate glyph row has its `mode_line_p' flag set,
1008 and if it doesn't, uses estimate_mode_line_height instead. */
1010 if (WINDOW_WANTS_MODELINE_P (w
))
1012 struct glyph_row
*ml_row
1013 = (w
->current_matrix
&& w
->current_matrix
->rows
1014 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1016 if (ml_row
&& ml_row
->mode_line_p
)
1017 height
-= ml_row
->height
;
1019 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1022 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1024 struct glyph_row
*hl_row
1025 = (w
->current_matrix
&& w
->current_matrix
->rows
1026 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1028 if (hl_row
&& hl_row
->mode_line_p
)
1029 height
-= hl_row
->height
;
1031 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1034 /* With a very small font and a mode-line that's taller than
1035 default, we might end up with a negative height. */
1036 return max (0, height
);
1039 /* Return the window-relative coordinate of the left edge of display
1040 area AREA of window W. AREA < 0 means return the left edge of the
1041 whole window, to the right of the left fringe of W. */
1044 window_box_left_offset (w
, area
)
1050 if (w
->pseudo_window_p
)
1053 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1055 if (area
== TEXT_AREA
)
1056 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1057 + window_box_width (w
, LEFT_MARGIN_AREA
));
1058 else if (area
== RIGHT_MARGIN_AREA
)
1059 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1060 + window_box_width (w
, LEFT_MARGIN_AREA
)
1061 + window_box_width (w
, TEXT_AREA
)
1062 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1064 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1065 else if (area
== LEFT_MARGIN_AREA
1066 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1067 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1073 /* Return the window-relative coordinate of the right edge of display
1074 area AREA of window W. AREA < 0 means return the left edge of the
1075 whole window, to the left of the right fringe of W. */
1078 window_box_right_offset (w
, area
)
1082 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1085 /* Return the frame-relative coordinate of the left edge of display
1086 area AREA of window W. AREA < 0 means return the left edge of the
1087 whole window, to the right of the left fringe of W. */
1090 window_box_left (w
, area
)
1094 struct frame
*f
= XFRAME (w
->frame
);
1097 if (w
->pseudo_window_p
)
1098 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1100 x
= (WINDOW_LEFT_EDGE_X (w
)
1101 + window_box_left_offset (w
, area
));
1107 /* Return the frame-relative coordinate of the right edge of display
1108 area AREA of window W. AREA < 0 means return the left edge of the
1109 whole window, to the left of the right fringe of W. */
1112 window_box_right (w
, area
)
1116 return window_box_left (w
, area
) + window_box_width (w
, area
);
1119 /* Get the bounding box of the display area AREA of window W, without
1120 mode lines, in frame-relative coordinates. AREA < 0 means the
1121 whole window, not including the left and right fringes of
1122 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1123 coordinates of the upper-left corner of the box. Return in
1124 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1127 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1130 int *box_x
, *box_y
, *box_width
, *box_height
;
1133 *box_width
= window_box_width (w
, area
);
1135 *box_height
= window_box_height (w
);
1137 *box_x
= window_box_left (w
, area
);
1140 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1141 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1142 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1147 /* Get the bounding box of the display area AREA of window W, without
1148 mode lines. AREA < 0 means the whole window, not including the
1149 left and right fringe of the window. Return in *TOP_LEFT_X
1150 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1151 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1152 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1156 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1157 bottom_right_x
, bottom_right_y
)
1160 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1162 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1164 *bottom_right_x
+= *top_left_x
;
1165 *bottom_right_y
+= *top_left_y
;
1170 /***********************************************************************
1172 ***********************************************************************/
1174 /* Return the bottom y-position of the line the iterator IT is in.
1175 This can modify IT's settings. */
1181 int line_height
= it
->max_ascent
+ it
->max_descent
;
1182 int line_top_y
= it
->current_y
;
1184 if (line_height
== 0)
1187 line_height
= last_height
;
1188 else if (IT_CHARPOS (*it
) < ZV
)
1190 move_it_by_lines (it
, 1, 1);
1191 line_height
= (it
->max_ascent
|| it
->max_descent
1192 ? it
->max_ascent
+ it
->max_descent
1197 struct glyph_row
*row
= it
->glyph_row
;
1199 /* Use the default character height. */
1200 it
->glyph_row
= NULL
;
1201 it
->what
= IT_CHARACTER
;
1204 PRODUCE_GLYPHS (it
);
1205 line_height
= it
->ascent
+ it
->descent
;
1206 it
->glyph_row
= row
;
1210 return line_top_y
+ line_height
;
1214 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1215 1 if POS is visible and the line containing POS is fully visible.
1216 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1217 and header-lines heights. */
1220 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
1222 int charpos
, *fully
, exact_mode_line_heights_p
;
1225 struct text_pos top
;
1227 struct buffer
*old_buffer
= NULL
;
1229 if (XBUFFER (w
->buffer
) != current_buffer
)
1231 old_buffer
= current_buffer
;
1232 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1235 *fully
= visible_p
= 0;
1236 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1238 /* Compute exact mode line heights, if requested. */
1239 if (exact_mode_line_heights_p
)
1241 if (WINDOW_WANTS_MODELINE_P (w
))
1242 current_mode_line_height
1243 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1244 current_buffer
->mode_line_format
);
1246 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1247 current_header_line_height
1248 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1249 current_buffer
->header_line_format
);
1252 start_display (&it
, w
, top
);
1253 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1254 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1256 /* Note that we may overshoot because of invisible text. */
1257 if (IT_CHARPOS (it
) >= charpos
)
1259 int top_y
= it
.current_y
;
1260 int bottom_y
= line_bottom_y (&it
);
1261 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1263 if (top_y
< window_top_y
)
1264 visible_p
= bottom_y
> window_top_y
;
1265 else if (top_y
< it
.last_visible_y
)
1268 *fully
= bottom_y
<= it
.last_visible_y
;
1271 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1273 move_it_by_lines (&it
, 1, 0);
1274 if (charpos
< IT_CHARPOS (it
))
1282 set_buffer_internal_1 (old_buffer
);
1284 current_header_line_height
= current_mode_line_height
= -1;
1289 /* Return the next character from STR which is MAXLEN bytes long.
1290 Return in *LEN the length of the character. This is like
1291 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1292 we find one, we return a `?', but with the length of the invalid
1296 string_char_and_length (str
, maxlen
, len
)
1297 const unsigned char *str
;
1302 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1303 if (!CHAR_VALID_P (c
, 1))
1304 /* We may not change the length here because other places in Emacs
1305 don't use this function, i.e. they silently accept invalid
1314 /* Given a position POS containing a valid character and byte position
1315 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1317 static struct text_pos
1318 string_pos_nchars_ahead (pos
, string
, nchars
)
1319 struct text_pos pos
;
1323 xassert (STRINGP (string
) && nchars
>= 0);
1325 if (STRING_MULTIBYTE (string
))
1327 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1328 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1333 string_char_and_length (p
, rest
, &len
);
1334 p
+= len
, rest
-= len
;
1335 xassert (rest
>= 0);
1337 BYTEPOS (pos
) += len
;
1341 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1347 /* Value is the text position, i.e. character and byte position,
1348 for character position CHARPOS in STRING. */
1350 static INLINE
struct text_pos
1351 string_pos (charpos
, string
)
1355 struct text_pos pos
;
1356 xassert (STRINGP (string
));
1357 xassert (charpos
>= 0);
1358 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1363 /* Value is a text position, i.e. character and byte position, for
1364 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1365 means recognize multibyte characters. */
1367 static struct text_pos
1368 c_string_pos (charpos
, s
, multibyte_p
)
1373 struct text_pos pos
;
1375 xassert (s
!= NULL
);
1376 xassert (charpos
>= 0);
1380 int rest
= strlen (s
), len
;
1382 SET_TEXT_POS (pos
, 0, 0);
1385 string_char_and_length (s
, rest
, &len
);
1386 s
+= len
, rest
-= len
;
1387 xassert (rest
>= 0);
1389 BYTEPOS (pos
) += len
;
1393 SET_TEXT_POS (pos
, charpos
, charpos
);
1399 /* Value is the number of characters in C string S. MULTIBYTE_P
1400 non-zero means recognize multibyte characters. */
1403 number_of_chars (s
, multibyte_p
)
1411 int rest
= strlen (s
), len
;
1412 unsigned char *p
= (unsigned char *) s
;
1414 for (nchars
= 0; rest
> 0; ++nchars
)
1416 string_char_and_length (p
, rest
, &len
);
1417 rest
-= len
, p
+= len
;
1421 nchars
= strlen (s
);
1427 /* Compute byte position NEWPOS->bytepos corresponding to
1428 NEWPOS->charpos. POS is a known position in string STRING.
1429 NEWPOS->charpos must be >= POS.charpos. */
1432 compute_string_pos (newpos
, pos
, string
)
1433 struct text_pos
*newpos
, pos
;
1436 xassert (STRINGP (string
));
1437 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1439 if (STRING_MULTIBYTE (string
))
1440 *newpos
= string_pos_nchars_ahead (pos
, string
,
1441 CHARPOS (*newpos
) - CHARPOS (pos
));
1443 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1447 Return an estimation of the pixel height of mode or top lines on
1448 frame F. FACE_ID specifies what line's height to estimate. */
1451 estimate_mode_line_height (f
, face_id
)
1453 enum face_id face_id
;
1455 #ifdef HAVE_WINDOW_SYSTEM
1456 if (FRAME_WINDOW_P (f
))
1458 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1460 /* This function is called so early when Emacs starts that the face
1461 cache and mode line face are not yet initialized. */
1462 if (FRAME_FACE_CACHE (f
))
1464 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1468 height
= FONT_HEIGHT (face
->font
);
1469 if (face
->box_line_width
> 0)
1470 height
+= 2 * face
->box_line_width
;
1481 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1482 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1483 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1484 not force the value into range. */
1487 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1489 register int pix_x
, pix_y
;
1491 NativeRectangle
*bounds
;
1495 #ifdef HAVE_WINDOW_SYSTEM
1496 if (FRAME_WINDOW_P (f
))
1498 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1499 even for negative values. */
1501 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1503 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1505 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1506 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1509 STORE_NATIVE_RECT (*bounds
,
1510 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1511 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1512 FRAME_COLUMN_WIDTH (f
) - 1,
1513 FRAME_LINE_HEIGHT (f
) - 1);
1519 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1520 pix_x
= FRAME_TOTAL_COLS (f
);
1524 else if (pix_y
> FRAME_LINES (f
))
1525 pix_y
= FRAME_LINES (f
);
1535 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1536 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1537 can't tell the positions because W's display is not up to date,
1541 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1544 int *frame_x
, *frame_y
;
1546 #ifdef HAVE_WINDOW_SYSTEM
1547 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1551 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1552 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1554 if (display_completed
)
1556 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1557 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1558 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1564 hpos
+= glyph
->pixel_width
;
1568 /* If first glyph is partially visible, its first visible position is still 0. */
1580 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1581 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1592 #ifdef HAVE_WINDOW_SYSTEM
1594 /* Find the glyph under window-relative coordinates X/Y in window W.
1595 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1596 strings. Return in *HPOS and *VPOS the row and column number of
1597 the glyph found. Return in *AREA the glyph area containing X.
1598 Value is a pointer to the glyph found or null if X/Y is not on
1599 text, or we can't tell because W's current matrix is not up to
1602 static struct glyph
*
1603 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1606 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1608 struct glyph
*glyph
, *end
;
1609 struct glyph_row
*row
= NULL
;
1612 /* Find row containing Y. Give up if some row is not enabled. */
1613 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1615 row
= MATRIX_ROW (w
->current_matrix
, i
);
1616 if (!row
->enabled_p
)
1618 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1625 /* Give up if Y is not in the window. */
1626 if (i
== w
->current_matrix
->nrows
)
1629 /* Get the glyph area containing X. */
1630 if (w
->pseudo_window_p
)
1637 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1639 *area
= LEFT_MARGIN_AREA
;
1640 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1642 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1645 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1649 *area
= RIGHT_MARGIN_AREA
;
1650 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1654 /* Find glyph containing X. */
1655 glyph
= row
->glyphs
[*area
];
1656 end
= glyph
+ row
->used
[*area
];
1658 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1660 x
-= glyph
->pixel_width
;
1670 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1673 *hpos
= glyph
- row
->glyphs
[*area
];
1679 Convert frame-relative x/y to coordinates relative to window W.
1680 Takes pseudo-windows into account. */
1683 frame_to_window_pixel_xy (w
, x
, y
)
1687 if (w
->pseudo_window_p
)
1689 /* A pseudo-window is always full-width, and starts at the
1690 left edge of the frame, plus a frame border. */
1691 struct frame
*f
= XFRAME (w
->frame
);
1692 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1693 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1697 *x
-= WINDOW_LEFT_EDGE_X (w
);
1698 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1703 Return in *R the clipping rectangle for glyph string S. */
1706 get_glyph_string_clip_rect (s
, nr
)
1707 struct glyph_string
*s
;
1708 NativeRectangle
*nr
;
1712 if (s
->row
->full_width_p
)
1714 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1715 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1716 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1718 /* Unless displaying a mode or menu bar line, which are always
1719 fully visible, clip to the visible part of the row. */
1720 if (s
->w
->pseudo_window_p
)
1721 r
.height
= s
->row
->visible_height
;
1723 r
.height
= s
->height
;
1727 /* This is a text line that may be partially visible. */
1728 r
.x
= window_box_left (s
->w
, s
->area
);
1729 r
.width
= window_box_width (s
->w
, s
->area
);
1730 r
.height
= s
->row
->visible_height
;
1733 /* If S draws overlapping rows, it's sufficient to use the top and
1734 bottom of the window for clipping because this glyph string
1735 intentionally draws over other lines. */
1736 if (s
->for_overlaps_p
)
1738 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1739 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1743 /* Don't use S->y for clipping because it doesn't take partially
1744 visible lines into account. For example, it can be negative for
1745 partially visible lines at the top of a window. */
1746 if (!s
->row
->full_width_p
1747 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1748 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1750 r
.y
= max (0, s
->row
->y
);
1752 /* If drawing a tool-bar window, draw it over the internal border
1753 at the top of the window. */
1754 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1755 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1758 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1760 /* If drawing the cursor, don't let glyph draw outside its
1761 advertised boundaries. Cleartype does this under some circumstances. */
1762 if (s
->hl
== DRAW_CURSOR
)
1764 struct glyph
*glyph
= s
->first_glyph
;
1769 r
.width
-= s
->x
- r
.x
;
1772 r
.width
= min (r
.width
, glyph
->pixel_width
);
1774 /* Don't draw cursor glyph taller than our actual glyph. */
1775 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1776 if (height
< r
.height
)
1778 r
.y
= s
->ybase
+ glyph
->descent
- height
;
1783 #ifdef CONVERT_FROM_XRECT
1784 CONVERT_FROM_XRECT (r
, *nr
);
1790 #endif /* HAVE_WINDOW_SYSTEM */
1793 /***********************************************************************
1794 Lisp form evaluation
1795 ***********************************************************************/
1797 /* Error handler for safe_eval and safe_call. */
1800 safe_eval_handler (arg
)
1803 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1808 /* Evaluate SEXPR and return the result, or nil if something went
1809 wrong. Prevent redisplay during the evaluation. */
1817 if (inhibit_eval_during_redisplay
)
1821 int count
= SPECPDL_INDEX ();
1822 struct gcpro gcpro1
;
1825 specbind (Qinhibit_redisplay
, Qt
);
1826 /* Use Qt to ensure debugger does not run,
1827 so there is no possibility of wanting to redisplay. */
1828 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1831 val
= unbind_to (count
, val
);
1838 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1839 Return the result, or nil if something went wrong. Prevent
1840 redisplay during the evaluation. */
1843 safe_call (nargs
, args
)
1849 if (inhibit_eval_during_redisplay
)
1853 int count
= SPECPDL_INDEX ();
1854 struct gcpro gcpro1
;
1857 gcpro1
.nvars
= nargs
;
1858 specbind (Qinhibit_redisplay
, Qt
);
1859 /* Use Qt to ensure debugger does not run,
1860 so there is no possibility of wanting to redisplay. */
1861 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
1864 val
= unbind_to (count
, val
);
1871 /* Call function FN with one argument ARG.
1872 Return the result, or nil if something went wrong. */
1875 safe_call1 (fn
, arg
)
1876 Lisp_Object fn
, arg
;
1878 Lisp_Object args
[2];
1881 return safe_call (2, args
);
1886 /***********************************************************************
1888 ***********************************************************************/
1892 /* Define CHECK_IT to perform sanity checks on iterators.
1893 This is for debugging. It is too slow to do unconditionally. */
1899 if (it
->method
== next_element_from_string
)
1901 xassert (STRINGP (it
->string
));
1902 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1904 else if (it
->method
== next_element_from_buffer
)
1906 /* Check that character and byte positions agree. */
1907 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1911 xassert (it
->current
.dpvec_index
>= 0);
1913 xassert (it
->current
.dpvec_index
< 0);
1916 #define CHECK_IT(IT) check_it ((IT))
1920 #define CHECK_IT(IT) (void) 0
1927 /* Check that the window end of window W is what we expect it
1928 to be---the last row in the current matrix displaying text. */
1931 check_window_end (w
)
1934 if (!MINI_WINDOW_P (w
)
1935 && !NILP (w
->window_end_valid
))
1937 struct glyph_row
*row
;
1938 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1939 XFASTINT (w
->window_end_vpos
)),
1941 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1942 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1946 #define CHECK_WINDOW_END(W) check_window_end ((W))
1948 #else /* not GLYPH_DEBUG */
1950 #define CHECK_WINDOW_END(W) (void) 0
1952 #endif /* not GLYPH_DEBUG */
1956 /***********************************************************************
1957 Iterator initialization
1958 ***********************************************************************/
1960 /* Initialize IT for displaying current_buffer in window W, starting
1961 at character position CHARPOS. CHARPOS < 0 means that no buffer
1962 position is specified which is useful when the iterator is assigned
1963 a position later. BYTEPOS is the byte position corresponding to
1964 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
1966 If ROW is not null, calls to produce_glyphs with IT as parameter
1967 will produce glyphs in that row.
1969 BASE_FACE_ID is the id of a base face to use. It must be one of
1970 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
1971 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
1972 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
1974 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
1975 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
1976 will be initialized to use the corresponding mode line glyph row of
1977 the desired matrix of W. */
1980 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1983 int charpos
, bytepos
;
1984 struct glyph_row
*row
;
1985 enum face_id base_face_id
;
1987 int highlight_region_p
;
1989 /* Some precondition checks. */
1990 xassert (w
!= NULL
&& it
!= NULL
);
1991 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
1994 /* If face attributes have been changed since the last redisplay,
1995 free realized faces now because they depend on face definitions
1996 that might have changed. Don't free faces while there might be
1997 desired matrices pending which reference these faces. */
1998 if (face_change_count
&& !inhibit_free_realized_faces
)
2000 face_change_count
= 0;
2001 free_all_realized_faces (Qnil
);
2004 /* Use one of the mode line rows of W's desired matrix if
2008 if (base_face_id
== MODE_LINE_FACE_ID
2009 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2010 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2011 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2012 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2016 bzero (it
, sizeof *it
);
2017 it
->current
.overlay_string_index
= -1;
2018 it
->current
.dpvec_index
= -1;
2019 it
->base_face_id
= base_face_id
;
2021 /* The window in which we iterate over current_buffer: */
2022 XSETWINDOW (it
->window
, w
);
2024 it
->f
= XFRAME (w
->frame
);
2026 /* Extra space between lines (on window systems only). */
2027 if (base_face_id
== DEFAULT_FACE_ID
2028 && FRAME_WINDOW_P (it
->f
))
2030 if (NATNUMP (current_buffer
->extra_line_spacing
))
2031 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2032 else if (it
->f
->extra_line_spacing
> 0)
2033 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2036 /* If realized faces have been removed, e.g. because of face
2037 attribute changes of named faces, recompute them. When running
2038 in batch mode, the face cache of the initial frame is null. If
2039 we happen to get called, make a dummy face cache. */
2040 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2041 init_frame_faces (it
->f
);
2042 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2043 recompute_basic_faces (it
->f
);
2045 /* Current value of the `space-width', and 'height' properties. */
2046 it
->space_width
= Qnil
;
2047 it
->font_height
= Qnil
;
2049 /* Are control characters displayed as `^C'? */
2050 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2052 /* -1 means everything between a CR and the following line end
2053 is invisible. >0 means lines indented more than this value are
2055 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2056 ? XFASTINT (current_buffer
->selective_display
)
2057 : (!NILP (current_buffer
->selective_display
)
2059 it
->selective_display_ellipsis_p
2060 = !NILP (current_buffer
->selective_display_ellipses
);
2062 /* Display table to use. */
2063 it
->dp
= window_display_table (w
);
2065 /* Are multibyte characters enabled in current_buffer? */
2066 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2068 /* Non-zero if we should highlight the region. */
2070 = (!NILP (Vtransient_mark_mode
)
2071 && !NILP (current_buffer
->mark_active
)
2072 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2074 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2075 start and end of a visible region in window IT->w. Set both to
2076 -1 to indicate no region. */
2077 if (highlight_region_p
2078 /* Maybe highlight only in selected window. */
2079 && (/* Either show region everywhere. */
2080 highlight_nonselected_windows
2081 /* Or show region in the selected window. */
2082 || w
== XWINDOW (selected_window
)
2083 /* Or show the region if we are in the mini-buffer and W is
2084 the window the mini-buffer refers to. */
2085 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2086 && WINDOWP (minibuf_selected_window
)
2087 && w
== XWINDOW (minibuf_selected_window
))))
2089 int charpos
= marker_position (current_buffer
->mark
);
2090 it
->region_beg_charpos
= min (PT
, charpos
);
2091 it
->region_end_charpos
= max (PT
, charpos
);
2094 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2096 /* Get the position at which the redisplay_end_trigger hook should
2097 be run, if it is to be run at all. */
2098 if (MARKERP (w
->redisplay_end_trigger
)
2099 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2100 it
->redisplay_end_trigger_charpos
2101 = marker_position (w
->redisplay_end_trigger
);
2102 else if (INTEGERP (w
->redisplay_end_trigger
))
2103 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2105 /* Correct bogus values of tab_width. */
2106 it
->tab_width
= XINT (current_buffer
->tab_width
);
2107 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2110 /* Are lines in the display truncated? */
2111 it
->truncate_lines_p
2112 = (base_face_id
!= DEFAULT_FACE_ID
2113 || XINT (it
->w
->hscroll
)
2114 || (truncate_partial_width_windows
2115 && !WINDOW_FULL_WIDTH_P (it
->w
))
2116 || !NILP (current_buffer
->truncate_lines
));
2118 /* Get dimensions of truncation and continuation glyphs. These are
2119 displayed as fringe bitmaps under X, so we don't need them for such
2121 if (!FRAME_WINDOW_P (it
->f
))
2123 if (it
->truncate_lines_p
)
2125 /* We will need the truncation glyph. */
2126 xassert (it
->glyph_row
== NULL
);
2127 produce_special_glyphs (it
, IT_TRUNCATION
);
2128 it
->truncation_pixel_width
= it
->pixel_width
;
2132 /* We will need the continuation glyph. */
2133 xassert (it
->glyph_row
== NULL
);
2134 produce_special_glyphs (it
, IT_CONTINUATION
);
2135 it
->continuation_pixel_width
= it
->pixel_width
;
2138 /* Reset these values to zero because the produce_special_glyphs
2139 above has changed them. */
2140 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2141 it
->phys_ascent
= it
->phys_descent
= 0;
2144 /* Set this after getting the dimensions of truncation and
2145 continuation glyphs, so that we don't produce glyphs when calling
2146 produce_special_glyphs, above. */
2147 it
->glyph_row
= row
;
2148 it
->area
= TEXT_AREA
;
2150 /* Get the dimensions of the display area. The display area
2151 consists of the visible window area plus a horizontally scrolled
2152 part to the left of the window. All x-values are relative to the
2153 start of this total display area. */
2154 if (base_face_id
!= DEFAULT_FACE_ID
)
2156 /* Mode lines, menu bar in terminal frames. */
2157 it
->first_visible_x
= 0;
2158 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2163 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2164 it
->last_visible_x
= (it
->first_visible_x
2165 + window_box_width (w
, TEXT_AREA
));
2167 /* If we truncate lines, leave room for the truncator glyph(s) at
2168 the right margin. Otherwise, leave room for the continuation
2169 glyph(s). Truncation and continuation glyphs are not inserted
2170 for window-based redisplay. */
2171 if (!FRAME_WINDOW_P (it
->f
))
2173 if (it
->truncate_lines_p
)
2174 it
->last_visible_x
-= it
->truncation_pixel_width
;
2176 it
->last_visible_x
-= it
->continuation_pixel_width
;
2179 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2180 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2183 /* Leave room for a border glyph. */
2184 if (!FRAME_WINDOW_P (it
->f
)
2185 && !WINDOW_RIGHTMOST_P (it
->w
))
2186 it
->last_visible_x
-= 1;
2188 it
->last_visible_y
= window_text_bottom_y (w
);
2190 /* For mode lines and alike, arrange for the first glyph having a
2191 left box line if the face specifies a box. */
2192 if (base_face_id
!= DEFAULT_FACE_ID
)
2196 it
->face_id
= base_face_id
;
2198 /* If we have a boxed mode line, make the first character appear
2199 with a left box line. */
2200 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2201 if (face
->box
!= FACE_NO_BOX
)
2202 it
->start_of_box_run_p
= 1;
2205 /* If a buffer position was specified, set the iterator there,
2206 getting overlays and face properties from that position. */
2207 if (charpos
>= BUF_BEG (current_buffer
))
2209 it
->end_charpos
= ZV
;
2211 IT_CHARPOS (*it
) = charpos
;
2213 /* Compute byte position if not specified. */
2214 if (bytepos
< charpos
)
2215 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2217 IT_BYTEPOS (*it
) = bytepos
;
2219 it
->start
= it
->current
;
2221 /* Compute faces etc. */
2222 reseat (it
, it
->current
.pos
, 1);
2229 /* Initialize IT for the display of window W with window start POS. */
2232 start_display (it
, w
, pos
)
2235 struct text_pos pos
;
2237 struct glyph_row
*row
;
2238 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2240 row
= w
->desired_matrix
->rows
+ first_vpos
;
2241 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2242 it
->first_vpos
= first_vpos
;
2244 if (!it
->truncate_lines_p
)
2246 int start_at_line_beg_p
;
2247 int first_y
= it
->current_y
;
2249 /* If window start is not at a line start, skip forward to POS to
2250 get the correct continuation lines width. */
2251 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2252 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2253 if (!start_at_line_beg_p
)
2257 reseat_at_previous_visible_line_start (it
);
2258 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2260 new_x
= it
->current_x
+ it
->pixel_width
;
2262 /* If lines are continued, this line may end in the middle
2263 of a multi-glyph character (e.g. a control character
2264 displayed as \003, or in the middle of an overlay
2265 string). In this case move_it_to above will not have
2266 taken us to the start of the continuation line but to the
2267 end of the continued line. */
2268 if (it
->current_x
> 0
2269 && !it
->truncate_lines_p
/* Lines are continued. */
2270 && (/* And glyph doesn't fit on the line. */
2271 new_x
> it
->last_visible_x
2272 /* Or it fits exactly and we're on a window
2274 || (new_x
== it
->last_visible_x
2275 && FRAME_WINDOW_P (it
->f
))))
2277 if (it
->current
.dpvec_index
>= 0
2278 || it
->current
.overlay_string_index
>= 0)
2280 set_iterator_to_next (it
, 1);
2281 move_it_in_display_line_to (it
, -1, -1, 0);
2284 it
->continuation_lines_width
+= it
->current_x
;
2287 /* We're starting a new display line, not affected by the
2288 height of the continued line, so clear the appropriate
2289 fields in the iterator structure. */
2290 it
->max_ascent
= it
->max_descent
= 0;
2291 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2293 it
->current_y
= first_y
;
2295 it
->current_x
= it
->hpos
= 0;
2299 #if 0 /* Don't assert the following because start_display is sometimes
2300 called intentionally with a window start that is not at a
2301 line start. Please leave this code in as a comment. */
2303 /* Window start should be on a line start, now. */
2304 xassert (it
->continuation_lines_width
2305 || IT_CHARPOS (it
) == BEGV
2306 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2311 /* Return 1 if POS is a position in ellipses displayed for invisible
2312 text. W is the window we display, for text property lookup. */
2315 in_ellipses_for_invisible_text_p (pos
, w
)
2316 struct display_pos
*pos
;
2319 Lisp_Object prop
, window
;
2321 int charpos
= CHARPOS (pos
->pos
);
2323 /* If POS specifies a position in a display vector, this might
2324 be for an ellipsis displayed for invisible text. We won't
2325 get the iterator set up for delivering that ellipsis unless
2326 we make sure that it gets aware of the invisible text. */
2327 if (pos
->dpvec_index
>= 0
2328 && pos
->overlay_string_index
< 0
2329 && CHARPOS (pos
->string_pos
) < 0
2331 && (XSETWINDOW (window
, w
),
2332 prop
= Fget_char_property (make_number (charpos
),
2333 Qinvisible
, window
),
2334 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2336 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2338 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2345 /* Initialize IT for stepping through current_buffer in window W,
2346 starting at position POS that includes overlay string and display
2347 vector/ control character translation position information. Value
2348 is zero if there are overlay strings with newlines at POS. */
2351 init_from_display_pos (it
, w
, pos
)
2354 struct display_pos
*pos
;
2356 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2357 int i
, overlay_strings_with_newlines
= 0;
2359 /* If POS specifies a position in a display vector, this might
2360 be for an ellipsis displayed for invisible text. We won't
2361 get the iterator set up for delivering that ellipsis unless
2362 we make sure that it gets aware of the invisible text. */
2363 if (in_ellipses_for_invisible_text_p (pos
, w
))
2369 /* Keep in mind: the call to reseat in init_iterator skips invisible
2370 text, so we might end up at a position different from POS. This
2371 is only a problem when POS is a row start after a newline and an
2372 overlay starts there with an after-string, and the overlay has an
2373 invisible property. Since we don't skip invisible text in
2374 display_line and elsewhere immediately after consuming the
2375 newline before the row start, such a POS will not be in a string,
2376 but the call to init_iterator below will move us to the
2378 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2380 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
2382 const char *s
= SDATA (it
->overlay_strings
[i
]);
2383 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2385 while (s
< e
&& *s
!= '\n')
2390 overlay_strings_with_newlines
= 1;
2395 /* If position is within an overlay string, set up IT to the right
2397 if (pos
->overlay_string_index
>= 0)
2401 /* If the first overlay string happens to have a `display'
2402 property for an image, the iterator will be set up for that
2403 image, and we have to undo that setup first before we can
2404 correct the overlay string index. */
2405 if (it
->method
== next_element_from_image
)
2408 /* We already have the first chunk of overlay strings in
2409 IT->overlay_strings. Load more until the one for
2410 pos->overlay_string_index is in IT->overlay_strings. */
2411 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2413 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2414 it
->current
.overlay_string_index
= 0;
2417 load_overlay_strings (it
, 0);
2418 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2422 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2423 relative_index
= (it
->current
.overlay_string_index
2424 % OVERLAY_STRING_CHUNK_SIZE
);
2425 it
->string
= it
->overlay_strings
[relative_index
];
2426 xassert (STRINGP (it
->string
));
2427 it
->current
.string_pos
= pos
->string_pos
;
2428 it
->method
= next_element_from_string
;
2431 #if 0 /* This is bogus because POS not having an overlay string
2432 position does not mean it's after the string. Example: A
2433 line starting with a before-string and initialization of IT
2434 to the previous row's end position. */
2435 else if (it
->current
.overlay_string_index
>= 0)
2437 /* If POS says we're already after an overlay string ending at
2438 POS, make sure to pop the iterator because it will be in
2439 front of that overlay string. When POS is ZV, we've thereby
2440 also ``processed'' overlay strings at ZV. */
2443 it
->current
.overlay_string_index
= -1;
2444 it
->method
= next_element_from_buffer
;
2445 if (CHARPOS (pos
->pos
) == ZV
)
2446 it
->overlay_strings_at_end_processed_p
= 1;
2450 if (CHARPOS (pos
->string_pos
) >= 0)
2452 /* Recorded position is not in an overlay string, but in another
2453 string. This can only be a string from a `display' property.
2454 IT should already be filled with that string. */
2455 it
->current
.string_pos
= pos
->string_pos
;
2456 xassert (STRINGP (it
->string
));
2459 /* Restore position in display vector translations, control
2460 character translations or ellipses. */
2461 if (pos
->dpvec_index
>= 0)
2463 if (it
->dpvec
== NULL
)
2464 get_next_display_element (it
);
2465 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2466 it
->current
.dpvec_index
= pos
->dpvec_index
;
2470 return !overlay_strings_with_newlines
;
2474 /* Initialize IT for stepping through current_buffer in window W
2475 starting at ROW->start. */
2478 init_to_row_start (it
, w
, row
)
2481 struct glyph_row
*row
;
2483 init_from_display_pos (it
, w
, &row
->start
);
2484 it
->start
= row
->start
;
2485 it
->continuation_lines_width
= row
->continuation_lines_width
;
2490 /* Initialize IT for stepping through current_buffer in window W
2491 starting in the line following ROW, i.e. starting at ROW->end.
2492 Value is zero if there are overlay strings with newlines at ROW's
2496 init_to_row_end (it
, w
, row
)
2499 struct glyph_row
*row
;
2503 if (init_from_display_pos (it
, w
, &row
->end
))
2505 if (row
->continued_p
)
2506 it
->continuation_lines_width
2507 = row
->continuation_lines_width
+ row
->pixel_width
;
2518 /***********************************************************************
2520 ***********************************************************************/
2522 /* Called when IT reaches IT->stop_charpos. Handle text property and
2523 overlay changes. Set IT->stop_charpos to the next position where
2530 enum prop_handled handled
;
2531 int handle_overlay_change_p
= 1;
2535 it
->current
.dpvec_index
= -1;
2539 handled
= HANDLED_NORMALLY
;
2541 /* Call text property handlers. */
2542 for (p
= it_props
; p
->handler
; ++p
)
2544 handled
= p
->handler (it
);
2546 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2548 else if (handled
== HANDLED_RETURN
)
2550 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2551 handle_overlay_change_p
= 0;
2554 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2556 /* Don't check for overlay strings below when set to deliver
2557 characters from a display vector. */
2558 if (it
->method
== next_element_from_display_vector
)
2559 handle_overlay_change_p
= 0;
2561 /* Handle overlay changes. */
2562 if (handle_overlay_change_p
)
2563 handled
= handle_overlay_change (it
);
2565 /* Determine where to stop next. */
2566 if (handled
== HANDLED_NORMALLY
)
2567 compute_stop_pos (it
);
2570 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2574 /* Compute IT->stop_charpos from text property and overlay change
2575 information for IT's current position. */
2578 compute_stop_pos (it
)
2581 register INTERVAL iv
, next_iv
;
2582 Lisp_Object object
, limit
, position
;
2584 /* If nowhere else, stop at the end. */
2585 it
->stop_charpos
= it
->end_charpos
;
2587 if (STRINGP (it
->string
))
2589 /* Strings are usually short, so don't limit the search for
2591 object
= it
->string
;
2593 position
= make_number (IT_STRING_CHARPOS (*it
));
2599 /* If next overlay change is in front of the current stop pos
2600 (which is IT->end_charpos), stop there. Note: value of
2601 next_overlay_change is point-max if no overlay change
2603 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2604 if (charpos
< it
->stop_charpos
)
2605 it
->stop_charpos
= charpos
;
2607 /* If showing the region, we have to stop at the region
2608 start or end because the face might change there. */
2609 if (it
->region_beg_charpos
> 0)
2611 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2612 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2613 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2614 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2617 /* Set up variables for computing the stop position from text
2618 property changes. */
2619 XSETBUFFER (object
, current_buffer
);
2620 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2621 position
= make_number (IT_CHARPOS (*it
));
2625 /* Get the interval containing IT's position. Value is a null
2626 interval if there isn't such an interval. */
2627 iv
= validate_interval_range (object
, &position
, &position
, 0);
2628 if (!NULL_INTERVAL_P (iv
))
2630 Lisp_Object values_here
[LAST_PROP_IDX
];
2633 /* Get properties here. */
2634 for (p
= it_props
; p
->handler
; ++p
)
2635 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2637 /* Look for an interval following iv that has different
2639 for (next_iv
= next_interval (iv
);
2640 (!NULL_INTERVAL_P (next_iv
)
2642 || XFASTINT (limit
) > next_iv
->position
));
2643 next_iv
= next_interval (next_iv
))
2645 for (p
= it_props
; p
->handler
; ++p
)
2647 Lisp_Object new_value
;
2649 new_value
= textget (next_iv
->plist
, *p
->name
);
2650 if (!EQ (values_here
[p
->idx
], new_value
))
2658 if (!NULL_INTERVAL_P (next_iv
))
2660 if (INTEGERP (limit
)
2661 && next_iv
->position
>= XFASTINT (limit
))
2662 /* No text property change up to limit. */
2663 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2665 /* Text properties change in next_iv. */
2666 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2670 xassert (STRINGP (it
->string
)
2671 || (it
->stop_charpos
>= BEGV
2672 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2676 /* Return the position of the next overlay change after POS in
2677 current_buffer. Value is point-max if no overlay change
2678 follows. This is like `next-overlay-change' but doesn't use
2682 next_overlay_change (pos
)
2687 Lisp_Object
*overlays
;
2691 /* Get all overlays at the given position. */
2693 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2694 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2695 if (noverlays
> len
)
2698 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2699 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2702 /* If any of these overlays ends before endpos,
2703 use its ending point instead. */
2704 for (i
= 0; i
< noverlays
; ++i
)
2709 oend
= OVERLAY_END (overlays
[i
]);
2710 oendpos
= OVERLAY_POSITION (oend
);
2711 endpos
= min (endpos
, oendpos
);
2719 /***********************************************************************
2721 ***********************************************************************/
2723 /* Handle changes in the `fontified' property of the current buffer by
2724 calling hook functions from Qfontification_functions to fontify
2727 static enum prop_handled
2728 handle_fontified_prop (it
)
2731 Lisp_Object prop
, pos
;
2732 enum prop_handled handled
= HANDLED_NORMALLY
;
2734 /* Get the value of the `fontified' property at IT's current buffer
2735 position. (The `fontified' property doesn't have a special
2736 meaning in strings.) If the value is nil, call functions from
2737 Qfontification_functions. */
2738 if (!STRINGP (it
->string
)
2740 && !NILP (Vfontification_functions
)
2741 && !NILP (Vrun_hooks
)
2742 && (pos
= make_number (IT_CHARPOS (*it
)),
2743 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2746 int count
= SPECPDL_INDEX ();
2749 val
= Vfontification_functions
;
2750 specbind (Qfontification_functions
, Qnil
);
2752 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2753 safe_call1 (val
, pos
);
2756 Lisp_Object globals
, fn
;
2757 struct gcpro gcpro1
, gcpro2
;
2760 GCPRO2 (val
, globals
);
2762 for (; CONSP (val
); val
= XCDR (val
))
2768 /* A value of t indicates this hook has a local
2769 binding; it means to run the global binding too.
2770 In a global value, t should not occur. If it
2771 does, we must ignore it to avoid an endless
2773 for (globals
= Fdefault_value (Qfontification_functions
);
2775 globals
= XCDR (globals
))
2777 fn
= XCAR (globals
);
2779 safe_call1 (fn
, pos
);
2783 safe_call1 (fn
, pos
);
2789 unbind_to (count
, Qnil
);
2791 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2792 something. This avoids an endless loop if they failed to
2793 fontify the text for which reason ever. */
2794 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2795 handled
= HANDLED_RECOMPUTE_PROPS
;
2803 /***********************************************************************
2805 ***********************************************************************/
2807 /* Set up iterator IT from face properties at its current position.
2808 Called from handle_stop. */
2810 static enum prop_handled
2811 handle_face_prop (it
)
2814 int new_face_id
, next_stop
;
2816 if (!STRINGP (it
->string
))
2819 = face_at_buffer_position (it
->w
,
2821 it
->region_beg_charpos
,
2822 it
->region_end_charpos
,
2825 + TEXT_PROP_DISTANCE_LIMIT
),
2828 /* Is this a start of a run of characters with box face?
2829 Caveat: this can be called for a freshly initialized
2830 iterator; face_id is -1 in this case. We know that the new
2831 face will not change until limit, i.e. if the new face has a
2832 box, all characters up to limit will have one. But, as
2833 usual, we don't know whether limit is really the end. */
2834 if (new_face_id
!= it
->face_id
)
2836 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2838 /* If new face has a box but old face has not, this is
2839 the start of a run of characters with box, i.e. it has
2840 a shadow on the left side. The value of face_id of the
2841 iterator will be -1 if this is the initial call that gets
2842 the face. In this case, we have to look in front of IT's
2843 position and see whether there is a face != new_face_id. */
2844 it
->start_of_box_run_p
2845 = (new_face
->box
!= FACE_NO_BOX
2846 && (it
->face_id
>= 0
2847 || IT_CHARPOS (*it
) == BEG
2848 || new_face_id
!= face_before_it_pos (it
)));
2849 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2854 int base_face_id
, bufpos
;
2856 if (it
->current
.overlay_string_index
>= 0)
2857 bufpos
= IT_CHARPOS (*it
);
2861 /* For strings from a buffer, i.e. overlay strings or strings
2862 from a `display' property, use the face at IT's current
2863 buffer position as the base face to merge with, so that
2864 overlay strings appear in the same face as surrounding
2865 text, unless they specify their own faces. */
2866 base_face_id
= underlying_face_id (it
);
2868 new_face_id
= face_at_string_position (it
->w
,
2870 IT_STRING_CHARPOS (*it
),
2872 it
->region_beg_charpos
,
2873 it
->region_end_charpos
,
2877 #if 0 /* This shouldn't be neccessary. Let's check it. */
2878 /* If IT is used to display a mode line we would really like to
2879 use the mode line face instead of the frame's default face. */
2880 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2881 && new_face_id
== DEFAULT_FACE_ID
)
2882 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
2885 /* Is this a start of a run of characters with box? Caveat:
2886 this can be called for a freshly allocated iterator; face_id
2887 is -1 is this case. We know that the new face will not
2888 change until the next check pos, i.e. if the new face has a
2889 box, all characters up to that position will have a
2890 box. But, as usual, we don't know whether that position
2891 is really the end. */
2892 if (new_face_id
!= it
->face_id
)
2894 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2895 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2897 /* If new face has a box but old face hasn't, this is the
2898 start of a run of characters with box, i.e. it has a
2899 shadow on the left side. */
2900 it
->start_of_box_run_p
2901 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2902 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2906 it
->face_id
= new_face_id
;
2907 return HANDLED_NORMALLY
;
2911 /* Return the ID of the face ``underlying'' IT's current position,
2912 which is in a string. If the iterator is associated with a
2913 buffer, return the face at IT's current buffer position.
2914 Otherwise, use the iterator's base_face_id. */
2917 underlying_face_id (it
)
2920 int face_id
= it
->base_face_id
, i
;
2922 xassert (STRINGP (it
->string
));
2924 for (i
= it
->sp
- 1; i
>= 0; --i
)
2925 if (NILP (it
->stack
[i
].string
))
2926 face_id
= it
->stack
[i
].face_id
;
2932 /* Compute the face one character before or after the current position
2933 of IT. BEFORE_P non-zero means get the face in front of IT's
2934 position. Value is the id of the face. */
2937 face_before_or_after_it_pos (it
, before_p
)
2942 int next_check_charpos
;
2943 struct text_pos pos
;
2945 xassert (it
->s
== NULL
);
2947 if (STRINGP (it
->string
))
2949 int bufpos
, base_face_id
;
2951 /* No face change past the end of the string (for the case
2952 we are padding with spaces). No face change before the
2954 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
2955 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2958 /* Set pos to the position before or after IT's current position. */
2960 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2962 /* For composition, we must check the character after the
2964 pos
= (it
->what
== IT_COMPOSITION
2965 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2966 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2968 if (it
->current
.overlay_string_index
>= 0)
2969 bufpos
= IT_CHARPOS (*it
);
2973 base_face_id
= underlying_face_id (it
);
2975 /* Get the face for ASCII, or unibyte. */
2976 face_id
= face_at_string_position (it
->w
,
2980 it
->region_beg_charpos
,
2981 it
->region_end_charpos
,
2982 &next_check_charpos
,
2985 /* Correct the face for charsets different from ASCII. Do it
2986 for the multibyte case only. The face returned above is
2987 suitable for unibyte text if IT->string is unibyte. */
2988 if (STRING_MULTIBYTE (it
->string
))
2990 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
2991 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
2993 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2995 c
= string_char_and_length (p
, rest
, &len
);
2996 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3001 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3002 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3005 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3006 pos
= it
->current
.pos
;
3009 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3012 if (it
->what
== IT_COMPOSITION
)
3013 /* For composition, we must check the position after the
3015 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3017 INC_TEXT_POS (pos
, it
->multibyte_p
);
3020 /* Determine face for CHARSET_ASCII, or unibyte. */
3021 face_id
= face_at_buffer_position (it
->w
,
3023 it
->region_beg_charpos
,
3024 it
->region_end_charpos
,
3025 &next_check_charpos
,
3028 /* Correct the face for charsets different from ASCII. Do it
3029 for the multibyte case only. The face returned above is
3030 suitable for unibyte text if current_buffer is unibyte. */
3031 if (it
->multibyte_p
)
3033 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3034 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3035 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3044 /***********************************************************************
3046 ***********************************************************************/
3048 /* Set up iterator IT from invisible properties at its current
3049 position. Called from handle_stop. */
3051 static enum prop_handled
3052 handle_invisible_prop (it
)
3055 enum prop_handled handled
= HANDLED_NORMALLY
;
3057 if (STRINGP (it
->string
))
3059 extern Lisp_Object Qinvisible
;
3060 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3062 /* Get the value of the invisible text property at the
3063 current position. Value will be nil if there is no such
3065 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3066 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3069 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3071 handled
= HANDLED_RECOMPUTE_PROPS
;
3073 /* Get the position at which the next change of the
3074 invisible text property can be found in IT->string.
3075 Value will be nil if the property value is the same for
3076 all the rest of IT->string. */
3077 XSETINT (limit
, SCHARS (it
->string
));
3078 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3081 /* Text at current position is invisible. The next
3082 change in the property is at position end_charpos.
3083 Move IT's current position to that position. */
3084 if (INTEGERP (end_charpos
)
3085 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3087 struct text_pos old
;
3088 old
= it
->current
.string_pos
;
3089 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3090 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3094 /* The rest of the string is invisible. If this is an
3095 overlay string, proceed with the next overlay string
3096 or whatever comes and return a character from there. */
3097 if (it
->current
.overlay_string_index
>= 0)
3099 next_overlay_string (it
);
3100 /* Don't check for overlay strings when we just
3101 finished processing them. */
3102 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3106 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3107 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3114 int invis_p
, newpos
, next_stop
, start_charpos
;
3115 Lisp_Object pos
, prop
, overlay
;
3117 /* First of all, is there invisible text at this position? */
3118 start_charpos
= IT_CHARPOS (*it
);
3119 pos
= make_number (IT_CHARPOS (*it
));
3120 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3122 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3124 /* If we are on invisible text, skip over it. */
3125 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3127 /* Record whether we have to display an ellipsis for the
3129 int display_ellipsis_p
= invis_p
== 2;
3131 handled
= HANDLED_RECOMPUTE_PROPS
;
3133 /* Loop skipping over invisible text. The loop is left at
3134 ZV or with IT on the first char being visible again. */
3137 /* Try to skip some invisible text. Return value is the
3138 position reached which can be equal to IT's position
3139 if there is nothing invisible here. This skips both
3140 over invisible text properties and overlays with
3141 invisible property. */
3142 newpos
= skip_invisible (IT_CHARPOS (*it
),
3143 &next_stop
, ZV
, it
->window
);
3145 /* If we skipped nothing at all we weren't at invisible
3146 text in the first place. If everything to the end of
3147 the buffer was skipped, end the loop. */
3148 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3152 /* We skipped some characters but not necessarily
3153 all there are. Check if we ended up on visible
3154 text. Fget_char_property returns the property of
3155 the char before the given position, i.e. if we
3156 get invis_p = 0, this means that the char at
3157 newpos is visible. */
3158 pos
= make_number (newpos
);
3159 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3160 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3163 /* If we ended up on invisible text, proceed to
3164 skip starting with next_stop. */
3166 IT_CHARPOS (*it
) = next_stop
;
3170 /* The position newpos is now either ZV or on visible text. */
3171 IT_CHARPOS (*it
) = newpos
;
3172 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3174 /* If there are before-strings at the start of invisible
3175 text, and the text is invisible because of a text
3176 property, arrange to show before-strings because 20.x did
3177 it that way. (If the text is invisible because of an
3178 overlay property instead of a text property, this is
3179 already handled in the overlay code.) */
3181 && get_overlay_strings (it
, start_charpos
))
3183 handled
= HANDLED_RECOMPUTE_PROPS
;
3184 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3186 else if (display_ellipsis_p
)
3187 setup_for_ellipsis (it
);
3195 /* Make iterator IT return `...' next. */
3198 setup_for_ellipsis (it
)
3202 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3204 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3205 it
->dpvec
= v
->contents
;
3206 it
->dpend
= v
->contents
+ v
->size
;
3210 /* Default `...'. */
3211 it
->dpvec
= default_invis_vector
;
3212 it
->dpend
= default_invis_vector
+ 3;
3215 /* The ellipsis display does not replace the display of the
3216 character at the new position. Indicate this by setting
3217 IT->dpvec_char_len to zero. */
3218 it
->dpvec_char_len
= 0;
3220 it
->current
.dpvec_index
= 0;
3221 it
->method
= next_element_from_display_vector
;
3226 /***********************************************************************
3228 ***********************************************************************/
3230 /* Set up iterator IT from `display' property at its current position.
3231 Called from handle_stop. */
3233 static enum prop_handled
3234 handle_display_prop (it
)
3237 Lisp_Object prop
, object
;
3238 struct text_pos
*position
;
3239 int display_replaced_p
= 0;
3241 if (STRINGP (it
->string
))
3243 object
= it
->string
;
3244 position
= &it
->current
.string_pos
;
3248 object
= it
->w
->buffer
;
3249 position
= &it
->current
.pos
;
3252 /* Reset those iterator values set from display property values. */
3253 it
->font_height
= Qnil
;
3254 it
->space_width
= Qnil
;
3257 /* We don't support recursive `display' properties, i.e. string
3258 values that have a string `display' property, that have a string
3259 `display' property etc. */
3260 if (!it
->string_from_display_prop_p
)
3261 it
->area
= TEXT_AREA
;
3263 prop
= Fget_char_property (make_number (position
->charpos
),
3266 return HANDLED_NORMALLY
;
3269 /* Simple properties. */
3270 && !EQ (XCAR (prop
), Qimage
)
3271 && !EQ (XCAR (prop
), Qspace
)
3272 && !EQ (XCAR (prop
), Qwhen
)
3273 && !EQ (XCAR (prop
), Qspace_width
)
3274 && !EQ (XCAR (prop
), Qheight
)
3275 && !EQ (XCAR (prop
), Qraise
)
3276 /* Marginal area specifications. */
3277 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3278 && !NILP (XCAR (prop
)))
3280 for (; CONSP (prop
); prop
= XCDR (prop
))
3282 if (handle_single_display_prop (it
, XCAR (prop
), object
,
3283 position
, display_replaced_p
))
3284 display_replaced_p
= 1;
3287 else if (VECTORP (prop
))
3290 for (i
= 0; i
< ASIZE (prop
); ++i
)
3291 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
3292 position
, display_replaced_p
))
3293 display_replaced_p
= 1;
3297 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
3298 display_replaced_p
= 1;
3301 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3305 /* Value is the position of the end of the `display' property starting
3306 at START_POS in OBJECT. */
3308 static struct text_pos
3309 display_prop_end (it
, object
, start_pos
)
3312 struct text_pos start_pos
;
3315 struct text_pos end_pos
;
3317 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3318 Qdisplay
, object
, Qnil
);
3319 CHARPOS (end_pos
) = XFASTINT (end
);
3320 if (STRINGP (object
))
3321 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3323 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3329 /* Set up IT from a single `display' sub-property value PROP. OBJECT
3330 is the object in which the `display' property was found. *POSITION
3331 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3332 means that we previously saw a display sub-property which already
3333 replaced text display with something else, for example an image;
3334 ignore such properties after the first one has been processed.
3336 If PROP is a `space' or `image' sub-property, set *POSITION to the
3337 end position of the `display' property.
3339 Value is non-zero if something was found which replaces the display
3340 of buffer or string text. */
3343 handle_single_display_prop (it
, prop
, object
, position
,
3344 display_replaced_before_p
)
3348 struct text_pos
*position
;
3349 int display_replaced_before_p
;
3352 int replaces_text_display_p
= 0;
3355 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
3356 evaluated. If the result is nil, VALUE is ignored. */
3358 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3367 if (!NILP (form
) && !EQ (form
, Qt
))
3369 int count
= SPECPDL_INDEX ();
3370 struct gcpro gcpro1
;
3372 /* Bind `object' to the object having the `display' property, a
3373 buffer or string. Bind `position' to the position in the
3374 object where the property was found, and `buffer-position'
3375 to the current position in the buffer. */
3376 specbind (Qobject
, object
);
3377 specbind (Qposition
, make_number (CHARPOS (*position
)));
3378 specbind (Qbuffer_position
,
3379 make_number (STRINGP (object
)
3380 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3382 form
= safe_eval (form
);
3384 unbind_to (count
, Qnil
);
3391 && EQ (XCAR (prop
), Qheight
)
3392 && CONSP (XCDR (prop
)))
3394 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3397 /* `(height HEIGHT)'. */
3398 it
->font_height
= XCAR (XCDR (prop
));
3399 if (!NILP (it
->font_height
))
3401 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3402 int new_height
= -1;
3404 if (CONSP (it
->font_height
)
3405 && (EQ (XCAR (it
->font_height
), Qplus
)
3406 || EQ (XCAR (it
->font_height
), Qminus
))
3407 && CONSP (XCDR (it
->font_height
))
3408 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3410 /* `(+ N)' or `(- N)' where N is an integer. */
3411 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3412 if (EQ (XCAR (it
->font_height
), Qplus
))
3414 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3416 else if (FUNCTIONP (it
->font_height
))
3418 /* Call function with current height as argument.
3419 Value is the new height. */
3421 height
= safe_call1 (it
->font_height
,
3422 face
->lface
[LFACE_HEIGHT_INDEX
]);
3423 if (NUMBERP (height
))
3424 new_height
= XFLOATINT (height
);
3426 else if (NUMBERP (it
->font_height
))
3428 /* Value is a multiple of the canonical char height. */
3431 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3432 new_height
= (XFLOATINT (it
->font_height
)
3433 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3437 /* Evaluate IT->font_height with `height' bound to the
3438 current specified height to get the new height. */
3440 int count
= SPECPDL_INDEX ();
3442 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3443 value
= safe_eval (it
->font_height
);
3444 unbind_to (count
, Qnil
);
3446 if (NUMBERP (value
))
3447 new_height
= XFLOATINT (value
);
3451 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3454 else if (CONSP (prop
)
3455 && EQ (XCAR (prop
), Qspace_width
)
3456 && CONSP (XCDR (prop
)))
3458 /* `(space_width WIDTH)'. */
3459 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3462 value
= XCAR (XCDR (prop
));
3463 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3464 it
->space_width
= value
;
3466 else if (CONSP (prop
)
3467 && EQ (XCAR (prop
), Qraise
)
3468 && CONSP (XCDR (prop
)))
3470 /* `(raise FACTOR)'. */
3471 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3474 #ifdef HAVE_WINDOW_SYSTEM
3475 value
= XCAR (XCDR (prop
));
3476 if (NUMBERP (value
))
3478 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3479 it
->voffset
= - (XFLOATINT (value
)
3480 * (FONT_HEIGHT (face
->font
)));
3482 #endif /* HAVE_WINDOW_SYSTEM */
3484 else if (!it
->string_from_display_prop_p
)
3486 /* `((margin left-margin) VALUE)' or `((margin right-margin)
3487 VALUE) or `((margin nil) VALUE)' or VALUE. */
3488 Lisp_Object location
, value
;
3489 struct text_pos start_pos
;
3492 /* Characters having this form of property are not displayed, so
3493 we have to find the end of the property. */
3494 start_pos
= *position
;
3495 *position
= display_prop_end (it
, object
, start_pos
);
3498 /* Let's stop at the new position and assume that all
3499 text properties change there. */
3500 it
->stop_charpos
= position
->charpos
;
3502 location
= Qunbound
;
3503 if (CONSP (prop
) && CONSP (XCAR (prop
)))
3507 value
= XCDR (prop
);
3509 value
= XCAR (value
);
3512 if (EQ (XCAR (tem
), Qmargin
)
3513 && (tem
= XCDR (tem
),
3514 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3516 || EQ (tem
, Qleft_margin
)
3517 || EQ (tem
, Qright_margin
))))
3521 if (EQ (location
, Qunbound
))
3527 #ifdef HAVE_WINDOW_SYSTEM
3528 if (FRAME_TERMCAP_P (it
->f
))
3529 valid_p
= STRINGP (value
);
3531 valid_p
= (STRINGP (value
)
3532 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3533 || valid_image_p (value
));
3534 #else /* not HAVE_WINDOW_SYSTEM */
3535 valid_p
= STRINGP (value
);
3536 #endif /* not HAVE_WINDOW_SYSTEM */
3538 if ((EQ (location
, Qleft_margin
)
3539 || EQ (location
, Qright_margin
)
3542 && !display_replaced_before_p
)
3544 replaces_text_display_p
= 1;
3546 /* Save current settings of IT so that we can restore them
3547 when we are finished with the glyph property value. */
3550 if (NILP (location
))
3551 it
->area
= TEXT_AREA
;
3552 else if (EQ (location
, Qleft_margin
))
3553 it
->area
= LEFT_MARGIN_AREA
;
3555 it
->area
= RIGHT_MARGIN_AREA
;
3557 if (STRINGP (value
))
3560 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3561 it
->current
.overlay_string_index
= -1;
3562 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3563 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3564 it
->method
= next_element_from_string
;
3565 it
->stop_charpos
= 0;
3566 it
->string_from_display_prop_p
= 1;
3567 /* Say that we haven't consumed the characters with
3568 `display' property yet. The call to pop_it in
3569 set_iterator_to_next will clean this up. */
3570 *position
= start_pos
;
3572 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3574 it
->method
= next_element_from_stretch
;
3576 it
->current
.pos
= it
->position
= start_pos
;
3578 #ifdef HAVE_WINDOW_SYSTEM
3581 it
->what
= IT_IMAGE
;
3582 it
->image_id
= lookup_image (it
->f
, value
);
3583 it
->position
= start_pos
;
3584 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3585 it
->method
= next_element_from_image
;
3587 /* Say that we haven't consumed the characters with
3588 `display' property yet. The call to pop_it in
3589 set_iterator_to_next will clean this up. */
3590 *position
= start_pos
;
3592 #endif /* HAVE_WINDOW_SYSTEM */
3595 /* Invalid property or property not supported. Restore
3596 the position to what it was before. */
3597 *position
= start_pos
;
3600 return replaces_text_display_p
;
3604 /* Check if PROP is a display sub-property value whose text should be
3605 treated as intangible. */
3608 single_display_prop_intangible_p (prop
)
3611 /* Skip over `when FORM'. */
3612 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3626 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3627 we don't need to treat text as intangible. */
3628 if (EQ (XCAR (prop
), Qmargin
))
3636 || EQ (XCAR (prop
), Qleft_margin
)
3637 || EQ (XCAR (prop
), Qright_margin
))
3641 return (CONSP (prop
)
3642 && (EQ (XCAR (prop
), Qimage
)
3643 || EQ (XCAR (prop
), Qspace
)));
3647 /* Check if PROP is a display property value whose text should be
3648 treated as intangible. */
3651 display_prop_intangible_p (prop
)
3655 && CONSP (XCAR (prop
))
3656 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3658 /* A list of sub-properties. */
3659 while (CONSP (prop
))
3661 if (single_display_prop_intangible_p (XCAR (prop
)))
3666 else if (VECTORP (prop
))
3668 /* A vector of sub-properties. */
3670 for (i
= 0; i
< ASIZE (prop
); ++i
)
3671 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3675 return single_display_prop_intangible_p (prop
);
3681 /* Return 1 if PROP is a display sub-property value containing STRING. */
3684 single_display_prop_string_p (prop
, string
)
3685 Lisp_Object prop
, string
;
3687 if (EQ (string
, prop
))
3690 /* Skip over `when FORM'. */
3691 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3700 /* Skip over `margin LOCATION'. */
3701 if (EQ (XCAR (prop
), Qmargin
))
3712 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3716 /* Return 1 if STRING appears in the `display' property PROP. */
3719 display_prop_string_p (prop
, string
)
3720 Lisp_Object prop
, string
;
3723 && CONSP (XCAR (prop
))
3724 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3726 /* A list of sub-properties. */
3727 while (CONSP (prop
))
3729 if (single_display_prop_string_p (XCAR (prop
), string
))
3734 else if (VECTORP (prop
))
3736 /* A vector of sub-properties. */
3738 for (i
= 0; i
< ASIZE (prop
); ++i
)
3739 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3743 return single_display_prop_string_p (prop
, string
);
3749 /* Determine from which buffer position in W's buffer STRING comes
3750 from. AROUND_CHARPOS is an approximate position where it could
3751 be from. Value is the buffer position or 0 if it couldn't be
3754 W's buffer must be current.
3756 This function is necessary because we don't record buffer positions
3757 in glyphs generated from strings (to keep struct glyph small).
3758 This function may only use code that doesn't eval because it is
3759 called asynchronously from note_mouse_highlight. */
3762 string_buffer_position (w
, string
, around_charpos
)
3767 Lisp_Object limit
, prop
, pos
;
3768 const int MAX_DISTANCE
= 1000;
3771 pos
= make_number (around_charpos
);
3772 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3773 while (!found
&& !EQ (pos
, limit
))
3775 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3776 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3779 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3784 pos
= make_number (around_charpos
);
3785 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3786 while (!found
&& !EQ (pos
, limit
))
3788 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3789 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3792 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3797 return found
? XINT (pos
) : 0;
3802 /***********************************************************************
3803 `composition' property
3804 ***********************************************************************/
3806 /* Set up iterator IT from `composition' property at its current
3807 position. Called from handle_stop. */
3809 static enum prop_handled
3810 handle_composition_prop (it
)
3813 Lisp_Object prop
, string
;
3814 int pos
, pos_byte
, end
;
3815 enum prop_handled handled
= HANDLED_NORMALLY
;
3817 if (STRINGP (it
->string
))
3819 pos
= IT_STRING_CHARPOS (*it
);
3820 pos_byte
= IT_STRING_BYTEPOS (*it
);
3821 string
= it
->string
;
3825 pos
= IT_CHARPOS (*it
);
3826 pos_byte
= IT_BYTEPOS (*it
);
3830 /* If there's a valid composition and point is not inside of the
3831 composition (in the case that the composition is from the current
3832 buffer), draw a glyph composed from the composition components. */
3833 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3834 && COMPOSITION_VALID_P (pos
, end
, prop
)
3835 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3837 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3841 it
->method
= next_element_from_composition
;
3843 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3844 /* For a terminal, draw only the first character of the
3846 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3847 it
->len
= (STRINGP (it
->string
)
3848 ? string_char_to_byte (it
->string
, end
)
3849 : CHAR_TO_BYTE (end
)) - pos_byte
;
3850 it
->stop_charpos
= end
;
3851 handled
= HANDLED_RETURN
;
3860 /***********************************************************************
3862 ***********************************************************************/
3864 /* The following structure is used to record overlay strings for
3865 later sorting in load_overlay_strings. */
3867 struct overlay_entry
3869 Lisp_Object overlay
;
3876 /* Set up iterator IT from overlay strings at its current position.
3877 Called from handle_stop. */
3879 static enum prop_handled
3880 handle_overlay_change (it
)
3883 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
3884 return HANDLED_RECOMPUTE_PROPS
;
3886 return HANDLED_NORMALLY
;
3890 /* Set up the next overlay string for delivery by IT, if there is an
3891 overlay string to deliver. Called by set_iterator_to_next when the
3892 end of the current overlay string is reached. If there are more
3893 overlay strings to display, IT->string and
3894 IT->current.overlay_string_index are set appropriately here.
3895 Otherwise IT->string is set to nil. */
3898 next_overlay_string (it
)
3901 ++it
->current
.overlay_string_index
;
3902 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3904 /* No more overlay strings. Restore IT's settings to what
3905 they were before overlay strings were processed, and
3906 continue to deliver from current_buffer. */
3907 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
3910 xassert (it
->stop_charpos
>= BEGV
3911 && it
->stop_charpos
<= it
->end_charpos
);
3913 it
->current
.overlay_string_index
= -1;
3914 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3915 it
->n_overlay_strings
= 0;
3916 it
->method
= next_element_from_buffer
;
3918 /* If we're at the end of the buffer, record that we have
3919 processed the overlay strings there already, so that
3920 next_element_from_buffer doesn't try it again. */
3921 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3922 it
->overlay_strings_at_end_processed_p
= 1;
3924 /* If we have to display `...' for invisible text, set
3925 the iterator up for that. */
3926 if (display_ellipsis_p
)
3927 setup_for_ellipsis (it
);
3931 /* There are more overlay strings to process. If
3932 IT->current.overlay_string_index has advanced to a position
3933 where we must load IT->overlay_strings with more strings, do
3935 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3937 if (it
->current
.overlay_string_index
&& i
== 0)
3938 load_overlay_strings (it
, 0);
3940 /* Initialize IT to deliver display elements from the overlay
3942 it
->string
= it
->overlay_strings
[i
];
3943 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3944 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3945 it
->method
= next_element_from_string
;
3946 it
->stop_charpos
= 0;
3953 /* Compare two overlay_entry structures E1 and E2. Used as a
3954 comparison function for qsort in load_overlay_strings. Overlay
3955 strings for the same position are sorted so that
3957 1. All after-strings come in front of before-strings, except
3958 when they come from the same overlay.
3960 2. Within after-strings, strings are sorted so that overlay strings
3961 from overlays with higher priorities come first.
3963 2. Within before-strings, strings are sorted so that overlay
3964 strings from overlays with higher priorities come last.
3966 Value is analogous to strcmp. */
3970 compare_overlay_entries (e1
, e2
)
3973 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3974 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3977 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3979 /* Let after-strings appear in front of before-strings if
3980 they come from different overlays. */
3981 if (EQ (entry1
->overlay
, entry2
->overlay
))
3982 result
= entry1
->after_string_p
? 1 : -1;
3984 result
= entry1
->after_string_p
? -1 : 1;
3986 else if (entry1
->after_string_p
)
3987 /* After-strings sorted in order of decreasing priority. */
3988 result
= entry2
->priority
- entry1
->priority
;
3990 /* Before-strings sorted in order of increasing priority. */
3991 result
= entry1
->priority
- entry2
->priority
;
3997 /* Load the vector IT->overlay_strings with overlay strings from IT's
3998 current buffer position, or from CHARPOS if that is > 0. Set
3999 IT->n_overlays to the total number of overlay strings found.
4001 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4002 a time. On entry into load_overlay_strings,
4003 IT->current.overlay_string_index gives the number of overlay
4004 strings that have already been loaded by previous calls to this
4007 IT->add_overlay_start contains an additional overlay start
4008 position to consider for taking overlay strings from, if non-zero.
4009 This position comes into play when the overlay has an `invisible'
4010 property, and both before and after-strings. When we've skipped to
4011 the end of the overlay, because of its `invisible' property, we
4012 nevertheless want its before-string to appear.
4013 IT->add_overlay_start will contain the overlay start position
4016 Overlay strings are sorted so that after-string strings come in
4017 front of before-string strings. Within before and after-strings,
4018 strings are sorted by overlay priority. See also function
4019 compare_overlay_entries. */
4022 load_overlay_strings (it
, charpos
)
4026 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4027 Lisp_Object overlay
, window
, str
, invisible
;
4028 struct Lisp_Overlay
*ov
;
4031 int n
= 0, i
, j
, invis_p
;
4032 struct overlay_entry
*entries
4033 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4036 charpos
= IT_CHARPOS (*it
);
4038 /* Append the overlay string STRING of overlay OVERLAY to vector
4039 `entries' which has size `size' and currently contains `n'
4040 elements. AFTER_P non-zero means STRING is an after-string of
4042 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4045 Lisp_Object priority; \
4049 int new_size = 2 * size; \
4050 struct overlay_entry *old = entries; \
4052 (struct overlay_entry *) alloca (new_size \
4053 * sizeof *entries); \
4054 bcopy (old, entries, size * sizeof *entries); \
4058 entries[n].string = (STRING); \
4059 entries[n].overlay = (OVERLAY); \
4060 priority = Foverlay_get ((OVERLAY), Qpriority); \
4061 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4062 entries[n].after_string_p = (AFTER_P); \
4067 /* Process overlay before the overlay center. */
4068 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4070 XSETMISC (overlay
, ov
);
4071 xassert (OVERLAYP (overlay
));
4072 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4073 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4078 /* Skip this overlay if it doesn't start or end at IT's current
4080 if (end
!= charpos
&& start
!= charpos
)
4083 /* Skip this overlay if it doesn't apply to IT->w. */
4084 window
= Foverlay_get (overlay
, Qwindow
);
4085 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4088 /* If the text ``under'' the overlay is invisible, both before-
4089 and after-strings from this overlay are visible; start and
4090 end position are indistinguishable. */
4091 invisible
= Foverlay_get (overlay
, Qinvisible
);
4092 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4094 /* If overlay has a non-empty before-string, record it. */
4095 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4096 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4098 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4100 /* If overlay has a non-empty after-string, record it. */
4101 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4102 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4104 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4107 /* Process overlays after the overlay center. */
4108 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4110 XSETMISC (overlay
, ov
);
4111 xassert (OVERLAYP (overlay
));
4112 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4113 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4115 if (start
> charpos
)
4118 /* Skip this overlay if it doesn't start or end at IT's current
4120 if (end
!= charpos
&& start
!= charpos
)
4123 /* Skip this overlay if it doesn't apply to IT->w. */
4124 window
= Foverlay_get (overlay
, Qwindow
);
4125 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4128 /* If the text ``under'' the overlay is invisible, it has a zero
4129 dimension, and both before- and after-strings apply. */
4130 invisible
= Foverlay_get (overlay
, Qinvisible
);
4131 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4133 /* If overlay has a non-empty before-string, record it. */
4134 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4135 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4137 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4139 /* If overlay has a non-empty after-string, record it. */
4140 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4141 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4143 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4146 #undef RECORD_OVERLAY_STRING
4150 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4152 /* Record the total number of strings to process. */
4153 it
->n_overlay_strings
= n
;
4155 /* IT->current.overlay_string_index is the number of overlay strings
4156 that have already been consumed by IT. Copy some of the
4157 remaining overlay strings to IT->overlay_strings. */
4159 j
= it
->current
.overlay_string_index
;
4160 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4161 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4167 /* Get the first chunk of overlay strings at IT's current buffer
4168 position, or at CHARPOS if that is > 0. Value is non-zero if at
4169 least one overlay string was found. */
4172 get_overlay_strings (it
, charpos
)
4176 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4177 process. This fills IT->overlay_strings with strings, and sets
4178 IT->n_overlay_strings to the total number of strings to process.
4179 IT->pos.overlay_string_index has to be set temporarily to zero
4180 because load_overlay_strings needs this; it must be set to -1
4181 when no overlay strings are found because a zero value would
4182 indicate a position in the first overlay string. */
4183 it
->current
.overlay_string_index
= 0;
4184 load_overlay_strings (it
, charpos
);
4186 /* If we found overlay strings, set up IT to deliver display
4187 elements from the first one. Otherwise set up IT to deliver
4188 from current_buffer. */
4189 if (it
->n_overlay_strings
)
4191 /* Make sure we know settings in current_buffer, so that we can
4192 restore meaningful values when we're done with the overlay
4194 compute_stop_pos (it
);
4195 xassert (it
->face_id
>= 0);
4197 /* Save IT's settings. They are restored after all overlay
4198 strings have been processed. */
4199 xassert (it
->sp
== 0);
4202 /* Set up IT to deliver display elements from the first overlay
4204 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4205 it
->string
= it
->overlay_strings
[0];
4206 it
->stop_charpos
= 0;
4207 xassert (STRINGP (it
->string
));
4208 it
->end_charpos
= SCHARS (it
->string
);
4209 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4210 it
->method
= next_element_from_string
;
4215 it
->current
.overlay_string_index
= -1;
4216 it
->method
= next_element_from_buffer
;
4221 /* Value is non-zero if we found at least one overlay string. */
4222 return STRINGP (it
->string
);
4227 /***********************************************************************
4228 Saving and restoring state
4229 ***********************************************************************/
4231 /* Save current settings of IT on IT->stack. Called, for example,
4232 before setting up IT for an overlay string, to be able to restore
4233 IT's settings to what they were after the overlay string has been
4240 struct iterator_stack_entry
*p
;
4242 xassert (it
->sp
< 2);
4243 p
= it
->stack
+ it
->sp
;
4245 p
->stop_charpos
= it
->stop_charpos
;
4246 xassert (it
->face_id
>= 0);
4247 p
->face_id
= it
->face_id
;
4248 p
->string
= it
->string
;
4249 p
->pos
= it
->current
;
4250 p
->end_charpos
= it
->end_charpos
;
4251 p
->string_nchars
= it
->string_nchars
;
4253 p
->multibyte_p
= it
->multibyte_p
;
4254 p
->space_width
= it
->space_width
;
4255 p
->font_height
= it
->font_height
;
4256 p
->voffset
= it
->voffset
;
4257 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4258 p
->display_ellipsis_p
= 0;
4263 /* Restore IT's settings from IT->stack. Called, for example, when no
4264 more overlay strings must be processed, and we return to delivering
4265 display elements from a buffer, or when the end of a string from a
4266 `display' property is reached and we return to delivering display
4267 elements from an overlay string, or from a buffer. */
4273 struct iterator_stack_entry
*p
;
4275 xassert (it
->sp
> 0);
4277 p
= it
->stack
+ it
->sp
;
4278 it
->stop_charpos
= p
->stop_charpos
;
4279 it
->face_id
= p
->face_id
;
4280 it
->string
= p
->string
;
4281 it
->current
= p
->pos
;
4282 it
->end_charpos
= p
->end_charpos
;
4283 it
->string_nchars
= p
->string_nchars
;
4285 it
->multibyte_p
= p
->multibyte_p
;
4286 it
->space_width
= p
->space_width
;
4287 it
->font_height
= p
->font_height
;
4288 it
->voffset
= p
->voffset
;
4289 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4294 /***********************************************************************
4296 ***********************************************************************/
4298 /* Set IT's current position to the previous line start. */
4301 back_to_previous_line_start (it
)
4304 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4305 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4309 /* Move IT to the next line start.
4311 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4312 we skipped over part of the text (as opposed to moving the iterator
4313 continuously over the text). Otherwise, don't change the value
4316 Newlines may come from buffer text, overlay strings, or strings
4317 displayed via the `display' property. That's the reason we can't
4318 simply use find_next_newline_no_quit.
4320 Note that this function may not skip over invisible text that is so
4321 because of text properties and immediately follows a newline. If
4322 it would, function reseat_at_next_visible_line_start, when called
4323 from set_iterator_to_next, would effectively make invisible
4324 characters following a newline part of the wrong glyph row, which
4325 leads to wrong cursor motion. */
4328 forward_to_next_line_start (it
, skipped_p
)
4332 int old_selective
, newline_found_p
, n
;
4333 const int MAX_NEWLINE_DISTANCE
= 500;
4335 /* If already on a newline, just consume it to avoid unintended
4336 skipping over invisible text below. */
4337 if (it
->what
== IT_CHARACTER
4339 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4341 set_iterator_to_next (it
, 0);
4346 /* Don't handle selective display in the following. It's (a)
4347 unnecessary because it's done by the caller, and (b) leads to an
4348 infinite recursion because next_element_from_ellipsis indirectly
4349 calls this function. */
4350 old_selective
= it
->selective
;
4353 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4354 from buffer text. */
4355 for (n
= newline_found_p
= 0;
4356 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4357 n
+= STRINGP (it
->string
) ? 0 : 1)
4359 if (!get_next_display_element (it
))
4361 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4362 set_iterator_to_next (it
, 0);
4365 /* If we didn't find a newline near enough, see if we can use a
4367 if (!newline_found_p
)
4369 int start
= IT_CHARPOS (*it
);
4370 int limit
= find_next_newline_no_quit (start
, 1);
4373 xassert (!STRINGP (it
->string
));
4375 /* If there isn't any `display' property in sight, and no
4376 overlays, we can just use the position of the newline in
4378 if (it
->stop_charpos
>= limit
4379 || ((pos
= Fnext_single_property_change (make_number (start
),
4381 Qnil
, make_number (limit
)),
4383 && next_overlay_change (start
) == ZV
))
4385 IT_CHARPOS (*it
) = limit
;
4386 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4387 *skipped_p
= newline_found_p
= 1;
4391 while (get_next_display_element (it
)
4392 && !newline_found_p
)
4394 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4395 set_iterator_to_next (it
, 0);
4400 it
->selective
= old_selective
;
4401 return newline_found_p
;
4405 /* Set IT's current position to the previous visible line start. Skip
4406 invisible text that is so either due to text properties or due to
4407 selective display. Caution: this does not change IT->current_x and
4411 back_to_previous_visible_line_start (it
)
4416 /* Go back one newline if not on BEGV already. */
4417 if (IT_CHARPOS (*it
) > BEGV
)
4418 back_to_previous_line_start (it
);
4420 /* Move over lines that are invisible because of selective display
4421 or text properties. */
4422 while (IT_CHARPOS (*it
) > BEGV
4427 /* If selective > 0, then lines indented more than that values
4429 if (it
->selective
> 0
4430 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4431 (double) it
->selective
)) /* iftc */
4437 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
4438 Qinvisible
, it
->window
);
4439 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4443 /* Back one more newline if the current one is invisible. */
4445 back_to_previous_line_start (it
);
4448 xassert (IT_CHARPOS (*it
) >= BEGV
);
4449 xassert (IT_CHARPOS (*it
) == BEGV
4450 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4455 /* Reseat iterator IT at the previous visible line start. Skip
4456 invisible text that is so either due to text properties or due to
4457 selective display. At the end, update IT's overlay information,
4458 face information etc. */
4461 reseat_at_previous_visible_line_start (it
)
4464 back_to_previous_visible_line_start (it
);
4465 reseat (it
, it
->current
.pos
, 1);
4470 /* Reseat iterator IT on the next visible line start in the current
4471 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4472 preceding the line start. Skip over invisible text that is so
4473 because of selective display. Compute faces, overlays etc at the
4474 new position. Note that this function does not skip over text that
4475 is invisible because of text properties. */
4478 reseat_at_next_visible_line_start (it
, on_newline_p
)
4482 int newline_found_p
, skipped_p
= 0;
4484 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4486 /* Skip over lines that are invisible because they are indented
4487 more than the value of IT->selective. */
4488 if (it
->selective
> 0)
4489 while (IT_CHARPOS (*it
) < ZV
4490 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4491 (double) it
->selective
)) /* iftc */
4493 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4494 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4497 /* Position on the newline if that's what's requested. */
4498 if (on_newline_p
&& newline_found_p
)
4500 if (STRINGP (it
->string
))
4502 if (IT_STRING_CHARPOS (*it
) > 0)
4504 --IT_STRING_CHARPOS (*it
);
4505 --IT_STRING_BYTEPOS (*it
);
4508 else if (IT_CHARPOS (*it
) > BEGV
)
4512 reseat (it
, it
->current
.pos
, 0);
4516 reseat (it
, it
->current
.pos
, 0);
4523 /***********************************************************************
4524 Changing an iterator's position
4525 ***********************************************************************/
4527 /* Change IT's current position to POS in current_buffer. If FORCE_P
4528 is non-zero, always check for text properties at the new position.
4529 Otherwise, text properties are only looked up if POS >=
4530 IT->check_charpos of a property. */
4533 reseat (it
, pos
, force_p
)
4535 struct text_pos pos
;
4538 int original_pos
= IT_CHARPOS (*it
);
4540 reseat_1 (it
, pos
, 0);
4542 /* Determine where to check text properties. Avoid doing it
4543 where possible because text property lookup is very expensive. */
4545 || CHARPOS (pos
) > it
->stop_charpos
4546 || CHARPOS (pos
) < original_pos
)
4553 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4554 IT->stop_pos to POS, also. */
4557 reseat_1 (it
, pos
, set_stop_p
)
4559 struct text_pos pos
;
4562 /* Don't call this function when scanning a C string. */
4563 xassert (it
->s
== NULL
);
4565 /* POS must be a reasonable value. */
4566 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4568 it
->current
.pos
= it
->position
= pos
;
4569 XSETBUFFER (it
->object
, current_buffer
);
4570 it
->end_charpos
= ZV
;
4572 it
->current
.dpvec_index
= -1;
4573 it
->current
.overlay_string_index
= -1;
4574 IT_STRING_CHARPOS (*it
) = -1;
4575 IT_STRING_BYTEPOS (*it
) = -1;
4577 it
->method
= next_element_from_buffer
;
4578 /* RMS: I added this to fix a bug in move_it_vertically_backward
4579 where it->area continued to relate to the starting point
4580 for the backward motion. Bug report from
4581 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
4582 However, I am not sure whether reseat still does the right thing
4583 in general after this change. */
4584 it
->area
= TEXT_AREA
;
4585 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4587 it
->face_before_selective_p
= 0;
4590 it
->stop_charpos
= CHARPOS (pos
);
4594 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4595 If S is non-null, it is a C string to iterate over. Otherwise,
4596 STRING gives a Lisp string to iterate over.
4598 If PRECISION > 0, don't return more then PRECISION number of
4599 characters from the string.
4601 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4602 characters have been returned. FIELD_WIDTH < 0 means an infinite
4605 MULTIBYTE = 0 means disable processing of multibyte characters,
4606 MULTIBYTE > 0 means enable it,
4607 MULTIBYTE < 0 means use IT->multibyte_p.
4609 IT must be initialized via a prior call to init_iterator before
4610 calling this function. */
4613 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4618 int precision
, field_width
, multibyte
;
4620 /* No region in strings. */
4621 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4623 /* No text property checks performed by default, but see below. */
4624 it
->stop_charpos
= -1;
4626 /* Set iterator position and end position. */
4627 bzero (&it
->current
, sizeof it
->current
);
4628 it
->current
.overlay_string_index
= -1;
4629 it
->current
.dpvec_index
= -1;
4630 xassert (charpos
>= 0);
4632 /* If STRING is specified, use its multibyteness, otherwise use the
4633 setting of MULTIBYTE, if specified. */
4635 it
->multibyte_p
= multibyte
> 0;
4639 xassert (STRINGP (string
));
4640 it
->string
= string
;
4642 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4643 it
->method
= next_element_from_string
;
4644 it
->current
.string_pos
= string_pos (charpos
, string
);
4651 /* Note that we use IT->current.pos, not it->current.string_pos,
4652 for displaying C strings. */
4653 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4654 if (it
->multibyte_p
)
4656 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4657 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4661 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4662 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4665 it
->method
= next_element_from_c_string
;
4668 /* PRECISION > 0 means don't return more than PRECISION characters
4670 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4671 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4673 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4674 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4675 FIELD_WIDTH < 0 means infinite field width. This is useful for
4676 padding with `-' at the end of a mode line. */
4677 if (field_width
< 0)
4678 field_width
= INFINITY
;
4679 if (field_width
> it
->end_charpos
- charpos
)
4680 it
->end_charpos
= charpos
+ field_width
;
4682 /* Use the standard display table for displaying strings. */
4683 if (DISP_TABLE_P (Vstandard_display_table
))
4684 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4686 it
->stop_charpos
= charpos
;
4692 /***********************************************************************
4694 ***********************************************************************/
4696 /* Load IT's display element fields with information about the next
4697 display element from the current position of IT. Value is zero if
4698 end of buffer (or C string) is reached. */
4701 get_next_display_element (it
)
4704 /* Non-zero means that we found a display element. Zero means that
4705 we hit the end of what we iterate over. Performance note: the
4706 function pointer `method' used here turns out to be faster than
4707 using a sequence of if-statements. */
4708 int success_p
= (*it
->method
) (it
);
4710 if (it
->what
== IT_CHARACTER
)
4712 /* Map via display table or translate control characters.
4713 IT->c, IT->len etc. have been set to the next character by
4714 the function call above. If we have a display table, and it
4715 contains an entry for IT->c, translate it. Don't do this if
4716 IT->c itself comes from a display table, otherwise we could
4717 end up in an infinite recursion. (An alternative could be to
4718 count the recursion depth of this function and signal an
4719 error when a certain maximum depth is reached.) Is it worth
4721 if (success_p
&& it
->dpvec
== NULL
)
4726 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4729 struct Lisp_Vector
*v
= XVECTOR (dv
);
4731 /* Return the first character from the display table
4732 entry, if not empty. If empty, don't display the
4733 current character. */
4736 it
->dpvec_char_len
= it
->len
;
4737 it
->dpvec
= v
->contents
;
4738 it
->dpend
= v
->contents
+ v
->size
;
4739 it
->current
.dpvec_index
= 0;
4740 it
->method
= next_element_from_display_vector
;
4741 success_p
= get_next_display_element (it
);
4745 set_iterator_to_next (it
, 0);
4746 success_p
= get_next_display_element (it
);
4750 /* Translate control characters into `\003' or `^C' form.
4751 Control characters coming from a display table entry are
4752 currently not translated because we use IT->dpvec to hold
4753 the translation. This could easily be changed but I
4754 don't believe that it is worth doing.
4756 If it->multibyte_p is nonzero, eight-bit characters and
4757 non-printable multibyte characters are also translated to
4760 If it->multibyte_p is zero, eight-bit characters that
4761 don't have corresponding multibyte char code are also
4762 translated to octal form. */
4763 else if ((it
->c
< ' '
4764 && (it
->area
!= TEXT_AREA
4765 || (it
->c
!= '\n' && it
->c
!= '\t')))
4769 || !CHAR_PRINTABLE_P (it
->c
))
4771 && it
->c
== unibyte_char_to_multibyte (it
->c
))))
4773 /* IT->c is a control character which must be displayed
4774 either as '\003' or as `^C' where the '\\' and '^'
4775 can be defined in the display table. Fill
4776 IT->ctl_chars with glyphs for what we have to
4777 display. Then, set IT->dpvec to these glyphs. */
4780 if (it
->c
< 128 && it
->ctl_arrow_p
)
4782 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4784 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4785 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4786 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4788 g
= FAST_MAKE_GLYPH ('^', 0);
4789 XSETINT (it
->ctl_chars
[0], g
);
4791 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4792 XSETINT (it
->ctl_chars
[1], g
);
4794 /* Set up IT->dpvec and return first character from it. */
4795 it
->dpvec_char_len
= it
->len
;
4796 it
->dpvec
= it
->ctl_chars
;
4797 it
->dpend
= it
->dpvec
+ 2;
4798 it
->current
.dpvec_index
= 0;
4799 it
->method
= next_element_from_display_vector
;
4800 get_next_display_element (it
);
4804 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4809 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4811 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4812 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4813 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4815 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4817 if (SINGLE_BYTE_CHAR_P (it
->c
))
4818 str
[0] = it
->c
, len
= 1;
4821 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4824 /* It's an invalid character, which
4825 shouldn't happen actually, but due to
4826 bugs it may happen. Let's print the char
4827 as is, there's not much meaningful we can
4830 str
[1] = it
->c
>> 8;
4831 str
[2] = it
->c
>> 16;
4832 str
[3] = it
->c
>> 24;
4837 for (i
= 0; i
< len
; i
++)
4839 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4840 /* Insert three more glyphs into IT->ctl_chars for
4841 the octal display of the character. */
4842 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4843 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4844 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4845 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4846 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4847 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4850 /* Set up IT->dpvec and return the first character
4852 it
->dpvec_char_len
= it
->len
;
4853 it
->dpvec
= it
->ctl_chars
;
4854 it
->dpend
= it
->dpvec
+ len
* 4;
4855 it
->current
.dpvec_index
= 0;
4856 it
->method
= next_element_from_display_vector
;
4857 get_next_display_element (it
);
4862 /* Adjust face id for a multibyte character. There are no
4863 multibyte character in unibyte text. */
4866 && FRAME_WINDOW_P (it
->f
))
4868 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4869 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4873 /* Is this character the last one of a run of characters with
4874 box? If yes, set IT->end_of_box_run_p to 1. */
4881 it
->end_of_box_run_p
4882 = ((face_id
= face_after_it_pos (it
),
4883 face_id
!= it
->face_id
)
4884 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4885 face
->box
== FACE_NO_BOX
));
4888 /* Value is 0 if end of buffer or string reached. */
4893 /* Move IT to the next display element.
4895 RESEAT_P non-zero means if called on a newline in buffer text,
4896 skip to the next visible line start.
4898 Functions get_next_display_element and set_iterator_to_next are
4899 separate because I find this arrangement easier to handle than a
4900 get_next_display_element function that also increments IT's
4901 position. The way it is we can first look at an iterator's current
4902 display element, decide whether it fits on a line, and if it does,
4903 increment the iterator position. The other way around we probably
4904 would either need a flag indicating whether the iterator has to be
4905 incremented the next time, or we would have to implement a
4906 decrement position function which would not be easy to write. */
4909 set_iterator_to_next (it
, reseat_p
)
4913 /* Reset flags indicating start and end of a sequence of characters
4914 with box. Reset them at the start of this function because
4915 moving the iterator to a new position might set them. */
4916 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4918 if (it
->method
== next_element_from_buffer
)
4920 /* The current display element of IT is a character from
4921 current_buffer. Advance in the buffer, and maybe skip over
4922 invisible lines that are so because of selective display. */
4923 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4924 reseat_at_next_visible_line_start (it
, 0);
4927 xassert (it
->len
!= 0);
4928 IT_BYTEPOS (*it
) += it
->len
;
4929 IT_CHARPOS (*it
) += 1;
4930 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4933 else if (it
->method
== next_element_from_composition
)
4935 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4936 if (STRINGP (it
->string
))
4938 IT_STRING_BYTEPOS (*it
) += it
->len
;
4939 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4940 it
->method
= next_element_from_string
;
4941 goto consider_string_end
;
4945 IT_BYTEPOS (*it
) += it
->len
;
4946 IT_CHARPOS (*it
) += it
->cmp_len
;
4947 it
->method
= next_element_from_buffer
;
4950 else if (it
->method
== next_element_from_c_string
)
4952 /* Current display element of IT is from a C string. */
4953 IT_BYTEPOS (*it
) += it
->len
;
4954 IT_CHARPOS (*it
) += 1;
4956 else if (it
->method
== next_element_from_display_vector
)
4958 /* Current display element of IT is from a display table entry.
4959 Advance in the display table definition. Reset it to null if
4960 end reached, and continue with characters from buffers/
4962 ++it
->current
.dpvec_index
;
4964 /* Restore face of the iterator to what they were before the
4965 display vector entry (these entries may contain faces). */
4966 it
->face_id
= it
->saved_face_id
;
4968 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4971 it
->method
= next_element_from_c_string
;
4972 else if (STRINGP (it
->string
))
4973 it
->method
= next_element_from_string
;
4975 it
->method
= next_element_from_buffer
;
4978 it
->current
.dpvec_index
= -1;
4980 /* Skip over characters which were displayed via IT->dpvec. */
4981 if (it
->dpvec_char_len
< 0)
4982 reseat_at_next_visible_line_start (it
, 1);
4983 else if (it
->dpvec_char_len
> 0)
4985 it
->len
= it
->dpvec_char_len
;
4986 set_iterator_to_next (it
, reseat_p
);
4990 else if (it
->method
== next_element_from_string
)
4992 /* Current display element is a character from a Lisp string. */
4993 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4994 IT_STRING_BYTEPOS (*it
) += it
->len
;
4995 IT_STRING_CHARPOS (*it
) += 1;
4997 consider_string_end
:
4999 if (it
->current
.overlay_string_index
>= 0)
5001 /* IT->string is an overlay string. Advance to the
5002 next, if there is one. */
5003 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5004 next_overlay_string (it
);
5008 /* IT->string is not an overlay string. If we reached
5009 its end, and there is something on IT->stack, proceed
5010 with what is on the stack. This can be either another
5011 string, this time an overlay string, or a buffer. */
5012 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5016 if (!STRINGP (it
->string
))
5017 it
->method
= next_element_from_buffer
;
5019 goto consider_string_end
;
5023 else if (it
->method
== next_element_from_image
5024 || it
->method
== next_element_from_stretch
)
5026 /* The position etc with which we have to proceed are on
5027 the stack. The position may be at the end of a string,
5028 if the `display' property takes up the whole string. */
5031 if (STRINGP (it
->string
))
5033 it
->method
= next_element_from_string
;
5034 goto consider_string_end
;
5037 it
->method
= next_element_from_buffer
;
5040 /* There are no other methods defined, so this should be a bug. */
5043 xassert (it
->method
!= next_element_from_string
5044 || (STRINGP (it
->string
)
5045 && IT_STRING_CHARPOS (*it
) >= 0));
5049 /* Load IT's display element fields with information about the next
5050 display element which comes from a display table entry or from the
5051 result of translating a control character to one of the forms `^C'
5052 or `\003'. IT->dpvec holds the glyphs to return as characters. */
5055 next_element_from_display_vector (it
)
5059 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5061 /* Remember the current face id in case glyphs specify faces.
5062 IT's face is restored in set_iterator_to_next. */
5063 it
->saved_face_id
= it
->face_id
;
5065 if (INTEGERP (*it
->dpvec
)
5066 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5071 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5072 it
->c
= FAST_GLYPH_CHAR (g
);
5073 it
->len
= CHAR_BYTES (it
->c
);
5075 /* The entry may contain a face id to use. Such a face id is
5076 the id of a Lisp face, not a realized face. A face id of
5077 zero means no face is specified. */
5078 lface_id
= FAST_GLYPH_FACE (g
);
5081 /* The function returns -1 if lface_id is invalid. */
5082 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
5084 it
->face_id
= face_id
;
5088 /* Display table entry is invalid. Return a space. */
5089 it
->c
= ' ', it
->len
= 1;
5091 /* Don't change position and object of the iterator here. They are
5092 still the values of the character that had this display table
5093 entry or was translated, and that's what we want. */
5094 it
->what
= IT_CHARACTER
;
5099 /* Load IT with the next display element from Lisp string IT->string.
5100 IT->current.string_pos is the current position within the string.
5101 If IT->current.overlay_string_index >= 0, the Lisp string is an
5105 next_element_from_string (it
)
5108 struct text_pos position
;
5110 xassert (STRINGP (it
->string
));
5111 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5112 position
= it
->current
.string_pos
;
5114 /* Time to check for invisible text? */
5115 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5116 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5120 /* Since a handler may have changed IT->method, we must
5122 return get_next_display_element (it
);
5125 if (it
->current
.overlay_string_index
>= 0)
5127 /* Get the next character from an overlay string. In overlay
5128 strings, There is no field width or padding with spaces to
5130 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5135 else if (STRING_MULTIBYTE (it
->string
))
5137 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5138 const unsigned char *s
= (SDATA (it
->string
)
5139 + IT_STRING_BYTEPOS (*it
));
5140 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5144 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5150 /* Get the next character from a Lisp string that is not an
5151 overlay string. Such strings come from the mode line, for
5152 example. We may have to pad with spaces, or truncate the
5153 string. See also next_element_from_c_string. */
5154 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5159 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5161 /* Pad with spaces. */
5162 it
->c
= ' ', it
->len
= 1;
5163 CHARPOS (position
) = BYTEPOS (position
) = -1;
5165 else if (STRING_MULTIBYTE (it
->string
))
5167 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5168 const unsigned char *s
= (SDATA (it
->string
)
5169 + IT_STRING_BYTEPOS (*it
));
5170 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5174 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5179 /* Record what we have and where it came from. Note that we store a
5180 buffer position in IT->position although it could arguably be a
5182 it
->what
= IT_CHARACTER
;
5183 it
->object
= it
->string
;
5184 it
->position
= position
;
5189 /* Load IT with next display element from C string IT->s.
5190 IT->string_nchars is the maximum number of characters to return
5191 from the string. IT->end_charpos may be greater than
5192 IT->string_nchars when this function is called, in which case we
5193 may have to return padding spaces. Value is zero if end of string
5194 reached, including padding spaces. */
5197 next_element_from_c_string (it
)
5203 it
->what
= IT_CHARACTER
;
5204 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5207 /* IT's position can be greater IT->string_nchars in case a field
5208 width or precision has been specified when the iterator was
5210 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5212 /* End of the game. */
5216 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5218 /* Pad with spaces. */
5219 it
->c
= ' ', it
->len
= 1;
5220 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5222 else if (it
->multibyte_p
)
5224 /* Implementation note: The calls to strlen apparently aren't a
5225 performance problem because there is no noticeable performance
5226 difference between Emacs running in unibyte or multibyte mode. */
5227 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5228 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5232 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5238 /* Set up IT to return characters from an ellipsis, if appropriate.
5239 The definition of the ellipsis glyphs may come from a display table
5240 entry. This function Fills IT with the first glyph from the
5241 ellipsis if an ellipsis is to be displayed. */
5244 next_element_from_ellipsis (it
)
5247 if (it
->selective_display_ellipsis_p
)
5249 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
5251 /* Use the display table definition for `...'. Invalid glyphs
5252 will be handled by the method returning elements from dpvec. */
5253 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
5254 it
->dpvec_char_len
= it
->len
;
5255 it
->dpvec
= v
->contents
;
5256 it
->dpend
= v
->contents
+ v
->size
;
5257 it
->current
.dpvec_index
= 0;
5258 it
->method
= next_element_from_display_vector
;
5262 /* Use default `...' which is stored in default_invis_vector. */
5263 it
->dpvec_char_len
= it
->len
;
5264 it
->dpvec
= default_invis_vector
;
5265 it
->dpend
= default_invis_vector
+ 3;
5266 it
->current
.dpvec_index
= 0;
5267 it
->method
= next_element_from_display_vector
;
5272 /* The face at the current position may be different from the
5273 face we find after the invisible text. Remember what it
5274 was in IT->saved_face_id, and signal that it's there by
5275 setting face_before_selective_p. */
5276 it
->saved_face_id
= it
->face_id
;
5277 it
->method
= next_element_from_buffer
;
5278 reseat_at_next_visible_line_start (it
, 1);
5279 it
->face_before_selective_p
= 1;
5282 return get_next_display_element (it
);
5286 /* Deliver an image display element. The iterator IT is already
5287 filled with image information (done in handle_display_prop). Value
5292 next_element_from_image (it
)
5295 it
->what
= IT_IMAGE
;
5300 /* Fill iterator IT with next display element from a stretch glyph
5301 property. IT->object is the value of the text property. Value is
5305 next_element_from_stretch (it
)
5308 it
->what
= IT_STRETCH
;
5313 /* Load IT with the next display element from current_buffer. Value
5314 is zero if end of buffer reached. IT->stop_charpos is the next
5315 position at which to stop and check for text properties or buffer
5319 next_element_from_buffer (it
)
5324 /* Check this assumption, otherwise, we would never enter the
5325 if-statement, below. */
5326 xassert (IT_CHARPOS (*it
) >= BEGV
5327 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
5329 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
5331 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5333 int overlay_strings_follow_p
;
5335 /* End of the game, except when overlay strings follow that
5336 haven't been returned yet. */
5337 if (it
->overlay_strings_at_end_processed_p
)
5338 overlay_strings_follow_p
= 0;
5341 it
->overlay_strings_at_end_processed_p
= 1;
5342 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
5345 if (overlay_strings_follow_p
)
5346 success_p
= get_next_display_element (it
);
5350 it
->position
= it
->current
.pos
;
5357 return get_next_display_element (it
);
5362 /* No face changes, overlays etc. in sight, so just return a
5363 character from current_buffer. */
5366 /* Maybe run the redisplay end trigger hook. Performance note:
5367 This doesn't seem to cost measurable time. */
5368 if (it
->redisplay_end_trigger_charpos
5370 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
5371 run_redisplay_end_trigger_hook (it
);
5373 /* Get the next character, maybe multibyte. */
5374 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
5375 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
5377 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
5378 - IT_BYTEPOS (*it
));
5379 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
5382 it
->c
= *p
, it
->len
= 1;
5384 /* Record what we have and where it came from. */
5385 it
->what
= IT_CHARACTER
;;
5386 it
->object
= it
->w
->buffer
;
5387 it
->position
= it
->current
.pos
;
5389 /* Normally we return the character found above, except when we
5390 really want to return an ellipsis for selective display. */
5395 /* A value of selective > 0 means hide lines indented more
5396 than that number of columns. */
5397 if (it
->selective
> 0
5398 && IT_CHARPOS (*it
) + 1 < ZV
5399 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
5400 IT_BYTEPOS (*it
) + 1,
5401 (double) it
->selective
)) /* iftc */
5403 success_p
= next_element_from_ellipsis (it
);
5404 it
->dpvec_char_len
= -1;
5407 else if (it
->c
== '\r' && it
->selective
== -1)
5409 /* A value of selective == -1 means that everything from the
5410 CR to the end of the line is invisible, with maybe an
5411 ellipsis displayed for it. */
5412 success_p
= next_element_from_ellipsis (it
);
5413 it
->dpvec_char_len
= -1;
5418 /* Value is zero if end of buffer reached. */
5419 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
5424 /* Run the redisplay end trigger hook for IT. */
5427 run_redisplay_end_trigger_hook (it
)
5430 Lisp_Object args
[3];
5432 /* IT->glyph_row should be non-null, i.e. we should be actually
5433 displaying something, or otherwise we should not run the hook. */
5434 xassert (it
->glyph_row
);
5436 /* Set up hook arguments. */
5437 args
[0] = Qredisplay_end_trigger_functions
;
5438 args
[1] = it
->window
;
5439 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
5440 it
->redisplay_end_trigger_charpos
= 0;
5442 /* Since we are *trying* to run these functions, don't try to run
5443 them again, even if they get an error. */
5444 it
->w
->redisplay_end_trigger
= Qnil
;
5445 Frun_hook_with_args (3, args
);
5447 /* Notice if it changed the face of the character we are on. */
5448 handle_face_prop (it
);
5452 /* Deliver a composition display element. The iterator IT is already
5453 filled with composition information (done in
5454 handle_composition_prop). Value is always 1. */
5457 next_element_from_composition (it
)
5460 it
->what
= IT_COMPOSITION
;
5461 it
->position
= (STRINGP (it
->string
)
5462 ? it
->current
.string_pos
5469 /***********************************************************************
5470 Moving an iterator without producing glyphs
5471 ***********************************************************************/
5473 /* Move iterator IT to a specified buffer or X position within one
5474 line on the display without producing glyphs.
5476 OP should be a bit mask including some or all of these bits:
5477 MOVE_TO_X: Stop on reaching x-position TO_X.
5478 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5479 Regardless of OP's value, stop in reaching the end of the display line.
5481 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5482 This means, in particular, that TO_X includes window's horizontal
5485 The return value has several possible values that
5486 say what condition caused the scan to stop:
5488 MOVE_POS_MATCH_OR_ZV
5489 - when TO_POS or ZV was reached.
5492 -when TO_X was reached before TO_POS or ZV were reached.
5495 - when we reached the end of the display area and the line must
5499 - when we reached the end of the display area and the line is
5503 - when we stopped at a line end, i.e. a newline or a CR and selective
5506 static enum move_it_result
5507 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5509 int to_charpos
, to_x
, op
;
5511 enum move_it_result result
= MOVE_UNDEFINED
;
5512 struct glyph_row
*saved_glyph_row
;
5514 /* Don't produce glyphs in produce_glyphs. */
5515 saved_glyph_row
= it
->glyph_row
;
5516 it
->glyph_row
= NULL
;
5520 int x
, i
, ascent
= 0, descent
= 0;
5522 /* Stop when ZV or TO_CHARPOS reached. */
5523 if (!get_next_display_element (it
)
5524 || ((op
& MOVE_TO_POS
) != 0
5525 && BUFFERP (it
->object
)
5526 && IT_CHARPOS (*it
) >= to_charpos
))
5528 result
= MOVE_POS_MATCH_OR_ZV
;
5532 /* The call to produce_glyphs will get the metrics of the
5533 display element IT is loaded with. We record in x the
5534 x-position before this display element in case it does not
5538 /* Remember the line height so far in case the next element doesn't
5540 if (!it
->truncate_lines_p
)
5542 ascent
= it
->max_ascent
;
5543 descent
= it
->max_descent
;
5546 PRODUCE_GLYPHS (it
);
5548 if (it
->area
!= TEXT_AREA
)
5550 set_iterator_to_next (it
, 1);
5554 /* The number of glyphs we get back in IT->nglyphs will normally
5555 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5556 character on a terminal frame, or (iii) a line end. For the
5557 second case, IT->nglyphs - 1 padding glyphs will be present
5558 (on X frames, there is only one glyph produced for a
5559 composite character.
5561 The behavior implemented below means, for continuation lines,
5562 that as many spaces of a TAB as fit on the current line are
5563 displayed there. For terminal frames, as many glyphs of a
5564 multi-glyph character are displayed in the current line, too.
5565 This is what the old redisplay code did, and we keep it that
5566 way. Under X, the whole shape of a complex character must
5567 fit on the line or it will be completely displayed in the
5570 Note that both for tabs and padding glyphs, all glyphs have
5574 /* More than one glyph or glyph doesn't fit on line. All
5575 glyphs have the same width. */
5576 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5579 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5581 new_x
= x
+ single_glyph_width
;
5583 /* We want to leave anything reaching TO_X to the caller. */
5584 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5587 result
= MOVE_X_REACHED
;
5590 else if (/* Lines are continued. */
5591 !it
->truncate_lines_p
5592 && (/* And glyph doesn't fit on the line. */
5593 new_x
> it
->last_visible_x
5594 /* Or it fits exactly and we're on a window
5596 || (new_x
== it
->last_visible_x
5597 && FRAME_WINDOW_P (it
->f
))))
5599 if (/* IT->hpos == 0 means the very first glyph
5600 doesn't fit on the line, e.g. a wide image. */
5602 || (new_x
== it
->last_visible_x
5603 && FRAME_WINDOW_P (it
->f
)))
5606 it
->current_x
= new_x
;
5607 if (i
== it
->nglyphs
- 1)
5609 set_iterator_to_next (it
, 1);
5610 #ifdef HAVE_WINDOW_SYSTEM
5611 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
5613 get_next_display_element (it
);
5614 if (ITERATOR_AT_END_OF_LINE_P (it
))
5616 result
= MOVE_NEWLINE_OR_CR
;
5620 #endif /* HAVE_WINDOW_SYSTEM */
5626 it
->max_ascent
= ascent
;
5627 it
->max_descent
= descent
;
5630 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5632 result
= MOVE_LINE_CONTINUED
;
5635 else if (new_x
> it
->first_visible_x
)
5637 /* Glyph is visible. Increment number of glyphs that
5638 would be displayed. */
5643 /* Glyph is completely off the left margin of the display
5644 area. Nothing to do. */
5648 if (result
!= MOVE_UNDEFINED
)
5651 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5653 /* Stop when TO_X specified and reached. This check is
5654 necessary here because of lines consisting of a line end,
5655 only. The line end will not produce any glyphs and we
5656 would never get MOVE_X_REACHED. */
5657 xassert (it
->nglyphs
== 0);
5658 result
= MOVE_X_REACHED
;
5662 /* Is this a line end? If yes, we're done. */
5663 if (ITERATOR_AT_END_OF_LINE_P (it
))
5665 result
= MOVE_NEWLINE_OR_CR
;
5669 /* The current display element has been consumed. Advance
5671 set_iterator_to_next (it
, 1);
5673 /* Stop if lines are truncated and IT's current x-position is
5674 past the right edge of the window now. */
5675 if (it
->truncate_lines_p
5676 && it
->current_x
>= it
->last_visible_x
)
5678 #ifdef HAVE_WINDOW_SYSTEM
5679 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
5681 get_next_display_element (it
);
5682 if (ITERATOR_AT_END_OF_LINE_P (it
))
5684 result
= MOVE_NEWLINE_OR_CR
;
5688 #endif /* HAVE_WINDOW_SYSTEM */
5689 result
= MOVE_LINE_TRUNCATED
;
5694 /* Restore the iterator settings altered at the beginning of this
5696 it
->glyph_row
= saved_glyph_row
;
5701 /* Move IT forward until it satisfies one or more of the criteria in
5702 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
5704 OP is a bit-mask that specifies where to stop, and in particular,
5705 which of those four position arguments makes a difference. See the
5706 description of enum move_operation_enum.
5708 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5709 screen line, this function will set IT to the next position >
5713 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5715 int to_charpos
, to_x
, to_y
, to_vpos
;
5718 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5724 if (op
& MOVE_TO_VPOS
)
5726 /* If no TO_CHARPOS and no TO_X specified, stop at the
5727 start of the line TO_VPOS. */
5728 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5730 if (it
->vpos
== to_vpos
)
5736 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5740 /* TO_VPOS >= 0 means stop at TO_X in the line at
5741 TO_VPOS, or at TO_POS, whichever comes first. */
5742 if (it
->vpos
== to_vpos
)
5748 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5750 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5755 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5757 /* We have reached TO_X but not in the line we want. */
5758 skip
= move_it_in_display_line_to (it
, to_charpos
,
5760 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5768 else if (op
& MOVE_TO_Y
)
5770 struct it it_backup
;
5772 /* TO_Y specified means stop at TO_X in the line containing
5773 TO_Y---or at TO_CHARPOS if this is reached first. The
5774 problem is that we can't really tell whether the line
5775 contains TO_Y before we have completely scanned it, and
5776 this may skip past TO_X. What we do is to first scan to
5779 If TO_X is not specified, use a TO_X of zero. The reason
5780 is to make the outcome of this function more predictable.
5781 If we didn't use TO_X == 0, we would stop at the end of
5782 the line which is probably not what a caller would expect
5784 skip
= move_it_in_display_line_to (it
, to_charpos
,
5788 | (op
& MOVE_TO_POS
)));
5790 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5791 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5797 /* If TO_X was reached, we would like to know whether TO_Y
5798 is in the line. This can only be said if we know the
5799 total line height which requires us to scan the rest of
5801 if (skip
== MOVE_X_REACHED
)
5804 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5805 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5807 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5810 /* Now, decide whether TO_Y is in this line. */
5811 line_height
= it
->max_ascent
+ it
->max_descent
;
5812 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5814 if (to_y
>= it
->current_y
5815 && to_y
< it
->current_y
+ line_height
)
5817 if (skip
== MOVE_X_REACHED
)
5818 /* If TO_Y is in this line and TO_X was reached above,
5819 we scanned too far. We have to restore IT's settings
5820 to the ones before skipping. */
5824 else if (skip
== MOVE_X_REACHED
)
5827 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5835 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5839 case MOVE_POS_MATCH_OR_ZV
:
5843 case MOVE_NEWLINE_OR_CR
:
5844 set_iterator_to_next (it
, 1);
5845 it
->continuation_lines_width
= 0;
5848 case MOVE_LINE_TRUNCATED
:
5849 it
->continuation_lines_width
= 0;
5850 reseat_at_next_visible_line_start (it
, 0);
5851 if ((op
& MOVE_TO_POS
) != 0
5852 && IT_CHARPOS (*it
) > to_charpos
)
5859 case MOVE_LINE_CONTINUED
:
5860 it
->continuation_lines_width
+= it
->current_x
;
5867 /* Reset/increment for the next run. */
5868 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5869 it
->current_x
= it
->hpos
= 0;
5870 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5872 last_height
= it
->max_ascent
+ it
->max_descent
;
5873 last_max_ascent
= it
->max_ascent
;
5874 it
->max_ascent
= it
->max_descent
= 0;
5879 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5883 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5885 If DY > 0, move IT backward at least that many pixels. DY = 0
5886 means move IT backward to the preceding line start or BEGV. This
5887 function may move over more than DY pixels if IT->current_y - DY
5888 ends up in the middle of a line; in this case IT->current_y will be
5889 set to the top of the line moved to. */
5892 move_it_vertically_backward (it
, dy
)
5898 int start_pos
= IT_CHARPOS (*it
);
5902 /* Estimate how many newlines we must move back. */
5903 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
5905 /* Set the iterator's position that many lines back. */
5906 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5907 back_to_previous_visible_line_start (it
);
5909 /* Reseat the iterator here. When moving backward, we don't want
5910 reseat to skip forward over invisible text, set up the iterator
5911 to deliver from overlay strings at the new position etc. So,
5912 use reseat_1 here. */
5913 reseat_1 (it
, it
->current
.pos
, 1);
5915 /* We are now surely at a line start. */
5916 it
->current_x
= it
->hpos
= 0;
5917 it
->continuation_lines_width
= 0;
5919 /* Move forward and see what y-distance we moved. First move to the
5920 start of the next line so that we get its height. We need this
5921 height to be able to tell whether we reached the specified
5924 it2
.max_ascent
= it2
.max_descent
= 0;
5925 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5926 MOVE_TO_POS
| MOVE_TO_VPOS
);
5927 xassert (IT_CHARPOS (*it
) >= BEGV
);
5930 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5931 xassert (IT_CHARPOS (*it
) >= BEGV
);
5932 /* H is the actual vertical distance from the position in *IT
5933 and the starting position. */
5934 h
= it2
.current_y
- it
->current_y
;
5935 /* NLINES is the distance in number of lines. */
5936 nlines
= it2
.vpos
- it
->vpos
;
5938 /* Correct IT's y and vpos position
5939 so that they are relative to the starting point. */
5945 /* DY == 0 means move to the start of the screen line. The
5946 value of nlines is > 0 if continuation lines were involved. */
5948 move_it_by_lines (it
, nlines
, 1);
5949 xassert (IT_CHARPOS (*it
) <= start_pos
);
5953 /* The y-position we try to reach, relative to *IT.
5954 Note that H has been subtracted in front of the if-statement. */
5955 int target_y
= it
->current_y
+ h
- dy
;
5956 int y0
= it3
.current_y
;
5957 int y1
= line_bottom_y (&it3
);
5958 int line_height
= y1
- y0
;
5960 /* If we did not reach target_y, try to move further backward if
5961 we can. If we moved too far backward, try to move forward. */
5962 if (target_y
< it
->current_y
5963 /* This is heuristic. In a window that's 3 lines high, with
5964 a line height of 13 pixels each, recentering with point
5965 on the bottom line will try to move -39/2 = 19 pixels
5966 backward. Try to avoid moving into the first line. */
5967 && it
->current_y
- target_y
> line_height
/ 3 * 2
5968 && IT_CHARPOS (*it
) > BEGV
)
5970 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
5971 target_y
- it
->current_y
));
5972 move_it_vertically (it
, target_y
- it
->current_y
);
5973 xassert (IT_CHARPOS (*it
) >= BEGV
);
5975 else if (target_y
>= it
->current_y
+ line_height
5976 && IT_CHARPOS (*it
) < ZV
)
5978 /* Should move forward by at least one line, maybe more.
5980 Note: Calling move_it_by_lines can be expensive on
5981 terminal frames, where compute_motion is used (via
5982 vmotion) to do the job, when there are very long lines
5983 and truncate-lines is nil. That's the reason for
5984 treating terminal frames specially here. */
5986 if (!FRAME_WINDOW_P (it
->f
))
5987 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
5992 move_it_by_lines (it
, 1, 1);
5994 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
5997 xassert (IT_CHARPOS (*it
) >= BEGV
);
6003 /* Move IT by a specified amount of pixel lines DY. DY negative means
6004 move backwards. DY = 0 means move to start of screen line. At the
6005 end, IT will be on the start of a screen line. */
6008 move_it_vertically (it
, dy
)
6013 move_it_vertically_backward (it
, -dy
);
6016 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6017 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6018 MOVE_TO_POS
| MOVE_TO_Y
);
6019 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6021 /* If buffer ends in ZV without a newline, move to the start of
6022 the line to satisfy the post-condition. */
6023 if (IT_CHARPOS (*it
) == ZV
6024 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6025 move_it_by_lines (it
, 0, 0);
6030 /* Move iterator IT past the end of the text line it is in. */
6033 move_it_past_eol (it
)
6036 enum move_it_result rc
;
6038 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6039 if (rc
== MOVE_NEWLINE_OR_CR
)
6040 set_iterator_to_next (it
, 0);
6044 #if 0 /* Currently not used. */
6046 /* Return non-zero if some text between buffer positions START_CHARPOS
6047 and END_CHARPOS is invisible. IT->window is the window for text
6051 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6053 int start_charpos
, end_charpos
;
6055 Lisp_Object prop
, limit
;
6056 int invisible_found_p
;
6058 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6060 /* Is text at START invisible? */
6061 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6063 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6064 invisible_found_p
= 1;
6067 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6069 make_number (end_charpos
));
6070 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6073 return invisible_found_p
;
6079 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6080 negative means move up. DVPOS == 0 means move to the start of the
6081 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6082 NEED_Y_P is zero, IT->current_y will be left unchanged.
6084 Further optimization ideas: If we would know that IT->f doesn't use
6085 a face with proportional font, we could be faster for
6086 truncate-lines nil. */
6089 move_it_by_lines (it
, dvpos
, need_y_p
)
6091 int dvpos
, need_y_p
;
6093 struct position pos
;
6095 if (!FRAME_WINDOW_P (it
->f
))
6097 struct text_pos textpos
;
6099 /* We can use vmotion on frames without proportional fonts. */
6100 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6101 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6102 reseat (it
, textpos
, 1);
6103 it
->vpos
+= pos
.vpos
;
6104 it
->current_y
+= pos
.vpos
;
6106 else if (dvpos
== 0)
6108 /* DVPOS == 0 means move to the start of the screen line. */
6109 move_it_vertically_backward (it
, 0);
6110 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6113 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6117 int start_charpos
, i
;
6119 /* Start at the beginning of the screen line containing IT's
6121 move_it_vertically_backward (it
, 0);
6123 /* Go back -DVPOS visible lines and reseat the iterator there. */
6124 start_charpos
= IT_CHARPOS (*it
);
6125 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
6126 back_to_previous_visible_line_start (it
);
6127 reseat (it
, it
->current
.pos
, 1);
6128 it
->current_x
= it
->hpos
= 0;
6130 /* Above call may have moved too far if continuation lines
6131 are involved. Scan forward and see if it did. */
6133 it2
.vpos
= it2
.current_y
= 0;
6134 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6135 it
->vpos
-= it2
.vpos
;
6136 it
->current_y
-= it2
.current_y
;
6137 it
->current_x
= it
->hpos
= 0;
6139 /* If we moved too far, move IT some lines forward. */
6140 if (it2
.vpos
> -dvpos
)
6142 int delta
= it2
.vpos
+ dvpos
;
6143 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6148 /* Return 1 if IT points into the middle of a display vector. */
6151 in_display_vector_p (it
)
6154 return (it
->method
== next_element_from_display_vector
6155 && it
->current
.dpvec_index
> 0
6156 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6160 /***********************************************************************
6162 ***********************************************************************/
6165 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6169 add_to_log (format
, arg1
, arg2
)
6171 Lisp_Object arg1
, arg2
;
6173 Lisp_Object args
[3];
6174 Lisp_Object msg
, fmt
;
6177 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6179 /* Do nothing if called asynchronously. Inserting text into
6180 a buffer may call after-change-functions and alike and
6181 that would means running Lisp asynchronously. */
6182 if (handling_signal
)
6186 GCPRO4 (fmt
, msg
, arg1
, arg2
);
6188 args
[0] = fmt
= build_string (format
);
6191 msg
= Fformat (3, args
);
6193 len
= SBYTES (msg
) + 1;
6194 buffer
= (char *) alloca (len
);
6195 bcopy (SDATA (msg
), buffer
, len
);
6197 message_dolog (buffer
, len
- 1, 1, 0);
6202 /* Output a newline in the *Messages* buffer if "needs" one. */
6205 message_log_maybe_newline ()
6207 if (message_log_need_newline
)
6208 message_dolog ("", 0, 1, 0);
6212 /* Add a string M of length NBYTES to the message log, optionally
6213 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
6214 nonzero, means interpret the contents of M as multibyte. This
6215 function calls low-level routines in order to bypass text property
6216 hooks, etc. which might not be safe to run. */
6219 message_dolog (m
, nbytes
, nlflag
, multibyte
)
6221 int nbytes
, nlflag
, multibyte
;
6223 if (!NILP (Vmemory_full
))
6226 if (!NILP (Vmessage_log_max
))
6228 struct buffer
*oldbuf
;
6229 Lisp_Object oldpoint
, oldbegv
, oldzv
;
6230 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6231 int point_at_end
= 0;
6233 Lisp_Object old_deactivate_mark
, tem
;
6234 struct gcpro gcpro1
;
6236 old_deactivate_mark
= Vdeactivate_mark
;
6237 oldbuf
= current_buffer
;
6238 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
6239 current_buffer
->undo_list
= Qt
;
6241 oldpoint
= message_dolog_marker1
;
6242 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
6243 oldbegv
= message_dolog_marker2
;
6244 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
6245 oldzv
= message_dolog_marker3
;
6246 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
6247 GCPRO1 (old_deactivate_mark
);
6255 BEGV_BYTE
= BEG_BYTE
;
6258 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6260 /* Insert the string--maybe converting multibyte to single byte
6261 or vice versa, so that all the text fits the buffer. */
6263 && NILP (current_buffer
->enable_multibyte_characters
))
6265 int i
, c
, char_bytes
;
6266 unsigned char work
[1];
6268 /* Convert a multibyte string to single-byte
6269 for the *Message* buffer. */
6270 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
6272 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
6273 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6275 : multibyte_char_to_unibyte (c
, Qnil
));
6276 insert_1_both (work
, 1, 1, 1, 0, 0);
6279 else if (! multibyte
6280 && ! NILP (current_buffer
->enable_multibyte_characters
))
6282 int i
, c
, char_bytes
;
6283 unsigned char *msg
= (unsigned char *) m
;
6284 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6285 /* Convert a single-byte string to multibyte
6286 for the *Message* buffer. */
6287 for (i
= 0; i
< nbytes
; i
++)
6289 c
= unibyte_char_to_multibyte (msg
[i
]);
6290 char_bytes
= CHAR_STRING (c
, str
);
6291 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
6295 insert_1 (m
, nbytes
, 1, 0, 0);
6299 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
6300 insert_1 ("\n", 1, 1, 0, 0);
6302 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6304 this_bol_byte
= PT_BYTE
;
6306 /* See if this line duplicates the previous one.
6307 If so, combine duplicates. */
6310 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6312 prev_bol_byte
= PT_BYTE
;
6314 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
6315 this_bol
, this_bol_byte
);
6318 del_range_both (prev_bol
, prev_bol_byte
,
6319 this_bol
, this_bol_byte
, 0);
6325 /* If you change this format, don't forget to also
6326 change message_log_check_duplicate. */
6327 sprintf (dupstr
, " [%d times]", dup
);
6328 duplen
= strlen (dupstr
);
6329 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
6330 insert_1 (dupstr
, duplen
, 1, 0, 1);
6335 /* If we have more than the desired maximum number of lines
6336 in the *Messages* buffer now, delete the oldest ones.
6337 This is safe because we don't have undo in this buffer. */
6339 if (NATNUMP (Vmessage_log_max
))
6341 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
6342 -XFASTINT (Vmessage_log_max
) - 1, 0);
6343 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
6346 BEGV
= XMARKER (oldbegv
)->charpos
;
6347 BEGV_BYTE
= marker_byte_position (oldbegv
);
6356 ZV
= XMARKER (oldzv
)->charpos
;
6357 ZV_BYTE
= marker_byte_position (oldzv
);
6361 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6363 /* We can't do Fgoto_char (oldpoint) because it will run some
6365 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
6366 XMARKER (oldpoint
)->bytepos
);
6369 unchain_marker (XMARKER (oldpoint
));
6370 unchain_marker (XMARKER (oldbegv
));
6371 unchain_marker (XMARKER (oldzv
));
6373 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
6374 set_buffer_internal (oldbuf
);
6376 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6377 message_log_need_newline
= !nlflag
;
6378 Vdeactivate_mark
= old_deactivate_mark
;
6383 /* We are at the end of the buffer after just having inserted a newline.
6384 (Note: We depend on the fact we won't be crossing the gap.)
6385 Check to see if the most recent message looks a lot like the previous one.
6386 Return 0 if different, 1 if the new one should just replace it, or a
6387 value N > 1 if we should also append " [N times]". */
6390 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
6391 int prev_bol
, this_bol
;
6392 int prev_bol_byte
, this_bol_byte
;
6395 int len
= Z_BYTE
- 1 - this_bol_byte
;
6397 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
6398 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
6400 for (i
= 0; i
< len
; i
++)
6402 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
6410 if (*p1
++ == ' ' && *p1
++ == '[')
6413 while (*p1
>= '0' && *p1
<= '9')
6414 n
= n
* 10 + *p1
++ - '0';
6415 if (strncmp (p1
, " times]\n", 8) == 0)
6422 /* Display an echo area message M with a specified length of NBYTES
6423 bytes. The string may include null characters. If M is 0, clear
6424 out any existing message, and let the mini-buffer text show
6427 The buffer M must continue to exist until after the echo area gets
6428 cleared or some other message gets displayed there. This means do
6429 not pass text that is stored in a Lisp string; do not pass text in
6430 a buffer that was alloca'd. */
6433 message2 (m
, nbytes
, multibyte
)
6438 /* First flush out any partial line written with print. */
6439 message_log_maybe_newline ();
6441 message_dolog (m
, nbytes
, 1, multibyte
);
6442 message2_nolog (m
, nbytes
, multibyte
);
6446 /* The non-logging counterpart of message2. */
6449 message2_nolog (m
, nbytes
, multibyte
)
6451 int nbytes
, multibyte
;
6453 struct frame
*sf
= SELECTED_FRAME ();
6454 message_enable_multibyte
= multibyte
;
6458 if (noninteractive_need_newline
)
6459 putc ('\n', stderr
);
6460 noninteractive_need_newline
= 0;
6462 fwrite (m
, nbytes
, 1, stderr
);
6463 if (cursor_in_echo_area
== 0)
6464 fprintf (stderr
, "\n");
6467 /* A null message buffer means that the frame hasn't really been
6468 initialized yet. Error messages get reported properly by
6469 cmd_error, so this must be just an informative message; toss it. */
6470 else if (INTERACTIVE
6471 && sf
->glyphs_initialized_p
6472 && FRAME_MESSAGE_BUF (sf
))
6474 Lisp_Object mini_window
;
6477 /* Get the frame containing the mini-buffer
6478 that the selected frame is using. */
6479 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6480 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6482 FRAME_SAMPLE_VISIBILITY (f
);
6483 if (FRAME_VISIBLE_P (sf
)
6484 && ! FRAME_VISIBLE_P (f
))
6485 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
6489 set_message (m
, Qnil
, nbytes
, multibyte
);
6490 if (minibuffer_auto_raise
)
6491 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6494 clear_message (1, 1);
6496 do_pending_window_change (0);
6497 echo_area_display (1);
6498 do_pending_window_change (0);
6499 if (FRAME_DISPLAY (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6500 (*FRAME_DISPLAY (f
)->frame_up_to_date_hook
) (f
);
6505 /* Display an echo area message M with a specified length of NBYTES
6506 bytes. The string may include null characters. If M is not a
6507 string, clear out any existing message, and let the mini-buffer
6508 text show through. */
6511 message3 (m
, nbytes
, multibyte
)
6516 struct gcpro gcpro1
;
6520 /* First flush out any partial line written with print. */
6521 message_log_maybe_newline ();
6523 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
6524 message3_nolog (m
, nbytes
, multibyte
);
6530 /* The non-logging version of message3. */
6533 message3_nolog (m
, nbytes
, multibyte
)
6535 int nbytes
, multibyte
;
6537 struct frame
*sf
= SELECTED_FRAME ();
6538 message_enable_multibyte
= multibyte
;
6542 if (noninteractive_need_newline
)
6543 putc ('\n', stderr
);
6544 noninteractive_need_newline
= 0;
6546 fwrite (SDATA (m
), nbytes
, 1, stderr
);
6547 if (cursor_in_echo_area
== 0)
6548 fprintf (stderr
, "\n");
6551 /* A null message buffer means that the frame hasn't really been
6552 initialized yet. Error messages get reported properly by
6553 cmd_error, so this must be just an informative message; toss it. */
6554 else if (INTERACTIVE
6555 && sf
->glyphs_initialized_p
6556 && FRAME_MESSAGE_BUF (sf
))
6558 Lisp_Object mini_window
;
6562 /* Get the frame containing the mini-buffer
6563 that the selected frame is using. */
6564 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6565 frame
= XWINDOW (mini_window
)->frame
;
6568 FRAME_SAMPLE_VISIBILITY (f
);
6569 if (FRAME_VISIBLE_P (sf
)
6570 && !FRAME_VISIBLE_P (f
))
6571 Fmake_frame_visible (frame
);
6573 if (STRINGP (m
) && SCHARS (m
) > 0)
6575 set_message (NULL
, m
, nbytes
, multibyte
);
6576 if (minibuffer_auto_raise
)
6577 Fraise_frame (frame
);
6580 clear_message (1, 1);
6582 do_pending_window_change (0);
6583 echo_area_display (1);
6584 do_pending_window_change (0);
6585 if (FRAME_DISPLAY (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6586 (*FRAME_DISPLAY (f
)->frame_up_to_date_hook
) (f
);
6591 /* Display a null-terminated echo area message M. If M is 0, clear
6592 out any existing message, and let the mini-buffer text show through.
6594 The buffer M must continue to exist until after the echo area gets
6595 cleared or some other message gets displayed there. Do not pass
6596 text that is stored in a Lisp string. Do not pass text in a buffer
6597 that was alloca'd. */
6603 message2 (m
, (m
? strlen (m
) : 0), 0);
6607 /* The non-logging counterpart of message1. */
6613 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6616 /* Display a message M which contains a single %s
6617 which gets replaced with STRING. */
6620 message_with_string (m
, string
, log
)
6625 CHECK_STRING (string
);
6631 if (noninteractive_need_newline
)
6632 putc ('\n', stderr
);
6633 noninteractive_need_newline
= 0;
6634 fprintf (stderr
, m
, SDATA (string
));
6635 if (cursor_in_echo_area
== 0)
6636 fprintf (stderr
, "\n");
6640 else if (INTERACTIVE
)
6642 /* The frame whose minibuffer we're going to display the message on.
6643 It may be larger than the selected frame, so we need
6644 to use its buffer, not the selected frame's buffer. */
6645 Lisp_Object mini_window
;
6646 struct frame
*f
, *sf
= SELECTED_FRAME ();
6648 /* Get the frame containing the minibuffer
6649 that the selected frame is using. */
6650 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6651 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6653 /* A null message buffer means that the frame hasn't really been
6654 initialized yet. Error messages get reported properly by
6655 cmd_error, so this must be just an informative message; toss it. */
6656 if (FRAME_MESSAGE_BUF (f
))
6658 Lisp_Object args
[2], message
;
6659 struct gcpro gcpro1
, gcpro2
;
6661 args
[0] = build_string (m
);
6662 args
[1] = message
= string
;
6663 GCPRO2 (args
[0], message
);
6666 message
= Fformat (2, args
);
6669 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6671 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6675 /* Print should start at the beginning of the message
6676 buffer next time. */
6677 message_buf_print
= 0;
6683 /* Dump an informative message to the minibuf. If M is 0, clear out
6684 any existing message, and let the mini-buffer text show through. */
6688 message (m
, a1
, a2
, a3
)
6690 EMACS_INT a1
, a2
, a3
;
6696 if (noninteractive_need_newline
)
6697 putc ('\n', stderr
);
6698 noninteractive_need_newline
= 0;
6699 fprintf (stderr
, m
, a1
, a2
, a3
);
6700 if (cursor_in_echo_area
== 0)
6701 fprintf (stderr
, "\n");
6705 else if (INTERACTIVE
)
6707 /* The frame whose mini-buffer we're going to display the message
6708 on. It may be larger than the selected frame, so we need to
6709 use its buffer, not the selected frame's buffer. */
6710 Lisp_Object mini_window
;
6711 struct frame
*f
, *sf
= SELECTED_FRAME ();
6713 /* Get the frame containing the mini-buffer
6714 that the selected frame is using. */
6715 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6716 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6718 /* A null message buffer means that the frame hasn't really been
6719 initialized yet. Error messages get reported properly by
6720 cmd_error, so this must be just an informative message; toss
6722 if (FRAME_MESSAGE_BUF (f
))
6733 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6734 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6736 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6737 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6739 #endif /* NO_ARG_ARRAY */
6741 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6746 /* Print should start at the beginning of the message
6747 buffer next time. */
6748 message_buf_print
= 0;
6754 /* The non-logging version of message. */
6757 message_nolog (m
, a1
, a2
, a3
)
6759 EMACS_INT a1
, a2
, a3
;
6761 Lisp_Object old_log_max
;
6762 old_log_max
= Vmessage_log_max
;
6763 Vmessage_log_max
= Qnil
;
6764 message (m
, a1
, a2
, a3
);
6765 Vmessage_log_max
= old_log_max
;
6769 /* Display the current message in the current mini-buffer. This is
6770 only called from error handlers in process.c, and is not time
6776 if (!NILP (echo_area_buffer
[0]))
6779 string
= Fcurrent_message ();
6780 message3 (string
, SBYTES (string
),
6781 !NILP (current_buffer
->enable_multibyte_characters
));
6786 /* Make sure echo area buffers in `echo_buffers' are live.
6787 If they aren't, make new ones. */
6790 ensure_echo_area_buffers ()
6794 for (i
= 0; i
< 2; ++i
)
6795 if (!BUFFERP (echo_buffer
[i
])
6796 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6799 Lisp_Object old_buffer
;
6802 old_buffer
= echo_buffer
[i
];
6803 sprintf (name
, " *Echo Area %d*", i
);
6804 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6805 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6807 for (j
= 0; j
< 2; ++j
)
6808 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6809 echo_area_buffer
[j
] = echo_buffer
[i
];
6814 /* Call FN with args A1..A4 with either the current or last displayed
6815 echo_area_buffer as current buffer.
6817 WHICH zero means use the current message buffer
6818 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6819 from echo_buffer[] and clear it.
6821 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6822 suitable buffer from echo_buffer[] and clear it.
6824 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6825 that the current message becomes the last displayed one, make
6826 choose a suitable buffer for echo_area_buffer[0], and clear it.
6828 Value is what FN returns. */
6831 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6834 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6840 int this_one
, the_other
, clear_buffer_p
, rc
;
6841 int count
= SPECPDL_INDEX ();
6843 /* If buffers aren't live, make new ones. */
6844 ensure_echo_area_buffers ();
6849 this_one
= 0, the_other
= 1;
6851 this_one
= 1, the_other
= 0;
6854 this_one
= 0, the_other
= 1;
6857 /* We need a fresh one in case the current echo buffer equals
6858 the one containing the last displayed echo area message. */
6859 if (!NILP (echo_area_buffer
[this_one
])
6860 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6861 echo_area_buffer
[this_one
] = Qnil
;
6864 /* Choose a suitable buffer from echo_buffer[] is we don't
6866 if (NILP (echo_area_buffer
[this_one
]))
6868 echo_area_buffer
[this_one
]
6869 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6870 ? echo_buffer
[the_other
]
6871 : echo_buffer
[this_one
]);
6875 buffer
= echo_area_buffer
[this_one
];
6877 /* Don't get confused by reusing the buffer used for echoing
6878 for a different purpose. */
6879 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
6882 record_unwind_protect (unwind_with_echo_area_buffer
,
6883 with_echo_area_buffer_unwind_data (w
));
6885 /* Make the echo area buffer current. Note that for display
6886 purposes, it is not necessary that the displayed window's buffer
6887 == current_buffer, except for text property lookup. So, let's
6888 only set that buffer temporarily here without doing a full
6889 Fset_window_buffer. We must also change w->pointm, though,
6890 because otherwise an assertions in unshow_buffer fails, and Emacs
6892 set_buffer_internal_1 (XBUFFER (buffer
));
6896 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6899 current_buffer
->undo_list
= Qt
;
6900 current_buffer
->read_only
= Qnil
;
6901 specbind (Qinhibit_read_only
, Qt
);
6902 specbind (Qinhibit_modification_hooks
, Qt
);
6904 if (clear_buffer_p
&& Z
> BEG
)
6907 xassert (BEGV
>= BEG
);
6908 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6910 rc
= fn (a1
, a2
, a3
, a4
);
6912 xassert (BEGV
>= BEG
);
6913 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6915 unbind_to (count
, Qnil
);
6920 /* Save state that should be preserved around the call to the function
6921 FN called in with_echo_area_buffer. */
6924 with_echo_area_buffer_unwind_data (w
)
6930 /* Reduce consing by keeping one vector in
6931 Vwith_echo_area_save_vector. */
6932 vector
= Vwith_echo_area_save_vector
;
6933 Vwith_echo_area_save_vector
= Qnil
;
6936 vector
= Fmake_vector (make_number (7), Qnil
);
6938 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6939 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6940 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6944 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6945 AREF (vector
, i
) = w
->buffer
; ++i
;
6946 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6947 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6952 for (; i
< end
; ++i
)
6953 AREF (vector
, i
) = Qnil
;
6956 xassert (i
== ASIZE (vector
));
6961 /* Restore global state from VECTOR which was created by
6962 with_echo_area_buffer_unwind_data. */
6965 unwind_with_echo_area_buffer (vector
)
6968 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6969 Vdeactivate_mark
= AREF (vector
, 1);
6970 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6972 if (WINDOWP (AREF (vector
, 3)))
6975 Lisp_Object buffer
, charpos
, bytepos
;
6977 w
= XWINDOW (AREF (vector
, 3));
6978 buffer
= AREF (vector
, 4);
6979 charpos
= AREF (vector
, 5);
6980 bytepos
= AREF (vector
, 6);
6983 set_marker_both (w
->pointm
, buffer
,
6984 XFASTINT (charpos
), XFASTINT (bytepos
));
6987 Vwith_echo_area_save_vector
= vector
;
6992 /* Set up the echo area for use by print functions. MULTIBYTE_P
6993 non-zero means we will print multibyte. */
6996 setup_echo_area_for_printing (multibyte_p
)
6999 /* If we can't find an echo area any more, exit. */
7000 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7003 ensure_echo_area_buffers ();
7005 if (!message_buf_print
)
7007 /* A message has been output since the last time we printed.
7008 Choose a fresh echo area buffer. */
7009 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7010 echo_area_buffer
[0] = echo_buffer
[1];
7012 echo_area_buffer
[0] = echo_buffer
[0];
7014 /* Switch to that buffer and clear it. */
7015 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7016 current_buffer
->truncate_lines
= Qnil
;
7020 int count
= SPECPDL_INDEX ();
7021 specbind (Qinhibit_read_only
, Qt
);
7022 /* Note that undo recording is always disabled. */
7024 unbind_to (count
, Qnil
);
7026 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7028 /* Set up the buffer for the multibyteness we need. */
7030 != !NILP (current_buffer
->enable_multibyte_characters
))
7031 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7033 /* Raise the frame containing the echo area. */
7034 if (minibuffer_auto_raise
)
7036 struct frame
*sf
= SELECTED_FRAME ();
7037 Lisp_Object mini_window
;
7038 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7039 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7042 message_log_maybe_newline ();
7043 message_buf_print
= 1;
7047 if (NILP (echo_area_buffer
[0]))
7049 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7050 echo_area_buffer
[0] = echo_buffer
[1];
7052 echo_area_buffer
[0] = echo_buffer
[0];
7055 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7057 /* Someone switched buffers between print requests. */
7058 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7059 current_buffer
->truncate_lines
= Qnil
;
7065 /* Display an echo area message in window W. Value is non-zero if W's
7066 height is changed. If display_last_displayed_message_p is
7067 non-zero, display the message that was last displayed, otherwise
7068 display the current message. */
7071 display_echo_area (w
)
7074 int i
, no_message_p
, window_height_changed_p
, count
;
7076 /* Temporarily disable garbage collections while displaying the echo
7077 area. This is done because a GC can print a message itself.
7078 That message would modify the echo area buffer's contents while a
7079 redisplay of the buffer is going on, and seriously confuse
7081 count
= inhibit_garbage_collection ();
7083 /* If there is no message, we must call display_echo_area_1
7084 nevertheless because it resizes the window. But we will have to
7085 reset the echo_area_buffer in question to nil at the end because
7086 with_echo_area_buffer will sets it to an empty buffer. */
7087 i
= display_last_displayed_message_p
? 1 : 0;
7088 no_message_p
= NILP (echo_area_buffer
[i
]);
7090 window_height_changed_p
7091 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7092 display_echo_area_1
,
7093 (EMACS_INT
) w
, Qnil
, 0, 0);
7096 echo_area_buffer
[i
] = Qnil
;
7098 unbind_to (count
, Qnil
);
7099 return window_height_changed_p
;
7103 /* Helper for display_echo_area. Display the current buffer which
7104 contains the current echo area message in window W, a mini-window,
7105 a pointer to which is passed in A1. A2..A4 are currently not used.
7106 Change the height of W so that all of the message is displayed.
7107 Value is non-zero if height of W was changed. */
7110 display_echo_area_1 (a1
, a2
, a3
, a4
)
7115 struct window
*w
= (struct window
*) a1
;
7117 struct text_pos start
;
7118 int window_height_changed_p
= 0;
7120 /* Do this before displaying, so that we have a large enough glyph
7121 matrix for the display. */
7122 window_height_changed_p
= resize_mini_window (w
, 0);
7125 clear_glyph_matrix (w
->desired_matrix
);
7126 XSETWINDOW (window
, w
);
7127 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
7128 try_window (window
, start
);
7130 return window_height_changed_p
;
7134 /* Resize the echo area window to exactly the size needed for the
7135 currently displayed message, if there is one. If a mini-buffer
7136 is active, don't shrink it. */
7139 resize_echo_area_exactly ()
7141 if (BUFFERP (echo_area_buffer
[0])
7142 && WINDOWP (echo_area_window
))
7144 struct window
*w
= XWINDOW (echo_area_window
);
7146 Lisp_Object resize_exactly
;
7148 if (minibuf_level
== 0)
7149 resize_exactly
= Qt
;
7151 resize_exactly
= Qnil
;
7153 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7154 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7157 ++windows_or_buffers_changed
;
7158 ++update_mode_lines
;
7159 redisplay_internal (0);
7165 /* Callback function for with_echo_area_buffer, when used from
7166 resize_echo_area_exactly. A1 contains a pointer to the window to
7167 resize, EXACTLY non-nil means resize the mini-window exactly to the
7168 size of the text displayed. A3 and A4 are not used. Value is what
7169 resize_mini_window returns. */
7172 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
7174 Lisp_Object exactly
;
7177 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
7181 /* Resize mini-window W to fit the size of its contents. EXACT:P
7182 means size the window exactly to the size needed. Otherwise, it's
7183 only enlarged until W's buffer is empty. Value is non-zero if
7184 the window height has been changed. */
7187 resize_mini_window (w
, exact_p
)
7191 struct frame
*f
= XFRAME (w
->frame
);
7192 int window_height_changed_p
= 0;
7194 xassert (MINI_WINDOW_P (w
));
7196 /* Don't resize windows while redisplaying a window; it would
7197 confuse redisplay functions when the size of the window they are
7198 displaying changes from under them. Such a resizing can happen,
7199 for instance, when which-func prints a long message while
7200 we are running fontification-functions. We're running these
7201 functions with safe_call which binds inhibit-redisplay to t. */
7202 if (!NILP (Vinhibit_redisplay
))
7205 /* Nil means don't try to resize. */
7206 if (NILP (Vresize_mini_windows
)
7207 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
7210 if (!FRAME_MINIBUF_ONLY_P (f
))
7213 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7214 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
7215 int height
, max_height
;
7216 int unit
= FRAME_LINE_HEIGHT (f
);
7217 struct text_pos start
;
7218 struct buffer
*old_current_buffer
= NULL
;
7220 if (current_buffer
!= XBUFFER (w
->buffer
))
7222 old_current_buffer
= current_buffer
;
7223 set_buffer_internal (XBUFFER (w
->buffer
));
7226 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
7228 /* Compute the max. number of lines specified by the user. */
7229 if (FLOATP (Vmax_mini_window_height
))
7230 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
7231 else if (INTEGERP (Vmax_mini_window_height
))
7232 max_height
= XINT (Vmax_mini_window_height
);
7234 max_height
= total_height
/ 4;
7236 /* Correct that max. height if it's bogus. */
7237 max_height
= max (1, max_height
);
7238 max_height
= min (total_height
, max_height
);
7240 /* Find out the height of the text in the window. */
7241 if (it
.truncate_lines_p
)
7246 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
7247 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
7248 height
= it
.current_y
+ last_height
;
7250 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
7251 height
-= it
.extra_line_spacing
;
7252 height
= (height
+ unit
- 1) / unit
;
7255 /* Compute a suitable window start. */
7256 if (height
> max_height
)
7258 height
= max_height
;
7259 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
7260 move_it_vertically_backward (&it
, (height
- 1) * unit
);
7261 start
= it
.current
.pos
;
7264 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
7265 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
7267 if (EQ (Vresize_mini_windows
, Qgrow_only
))
7269 /* Let it grow only, until we display an empty message, in which
7270 case the window shrinks again. */
7271 if (height
> WINDOW_TOTAL_LINES (w
))
7273 int old_height
= WINDOW_TOTAL_LINES (w
);
7274 freeze_window_starts (f
, 1);
7275 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7276 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7278 else if (height
< WINDOW_TOTAL_LINES (w
)
7279 && (exact_p
|| BEGV
== ZV
))
7281 int old_height
= WINDOW_TOTAL_LINES (w
);
7282 freeze_window_starts (f
, 0);
7283 shrink_mini_window (w
);
7284 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7289 /* Always resize to exact size needed. */
7290 if (height
> WINDOW_TOTAL_LINES (w
))
7292 int old_height
= WINDOW_TOTAL_LINES (w
);
7293 freeze_window_starts (f
, 1);
7294 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7295 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7297 else if (height
< WINDOW_TOTAL_LINES (w
))
7299 int old_height
= WINDOW_TOTAL_LINES (w
);
7300 freeze_window_starts (f
, 0);
7301 shrink_mini_window (w
);
7305 freeze_window_starts (f
, 1);
7306 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7309 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7313 if (old_current_buffer
)
7314 set_buffer_internal (old_current_buffer
);
7317 return window_height_changed_p
;
7321 /* Value is the current message, a string, or nil if there is no
7329 if (NILP (echo_area_buffer
[0]))
7333 with_echo_area_buffer (0, 0, current_message_1
,
7334 (EMACS_INT
) &msg
, Qnil
, 0, 0);
7336 echo_area_buffer
[0] = Qnil
;
7344 current_message_1 (a1
, a2
, a3
, a4
)
7349 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
7352 *msg
= make_buffer_string (BEG
, Z
, 1);
7359 /* Push the current message on Vmessage_stack for later restauration
7360 by restore_message. Value is non-zero if the current message isn't
7361 empty. This is a relatively infrequent operation, so it's not
7362 worth optimizing. */
7368 msg
= current_message ();
7369 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
7370 return STRINGP (msg
);
7374 /* Restore message display from the top of Vmessage_stack. */
7381 xassert (CONSP (Vmessage_stack
));
7382 msg
= XCAR (Vmessage_stack
);
7384 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
7386 message3_nolog (msg
, 0, 0);
7390 /* Handler for record_unwind_protect calling pop_message. */
7393 pop_message_unwind (dummy
)
7400 /* Pop the top-most entry off Vmessage_stack. */
7405 xassert (CONSP (Vmessage_stack
));
7406 Vmessage_stack
= XCDR (Vmessage_stack
);
7410 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
7411 exits. If the stack is not empty, we have a missing pop_message
7415 check_message_stack ()
7417 if (!NILP (Vmessage_stack
))
7422 /* Truncate to NCHARS what will be displayed in the echo area the next
7423 time we display it---but don't redisplay it now. */
7426 truncate_echo_area (nchars
)
7430 echo_area_buffer
[0] = Qnil
;
7431 /* A null message buffer means that the frame hasn't really been
7432 initialized yet. Error messages get reported properly by
7433 cmd_error, so this must be just an informative message; toss it. */
7434 else if (!noninteractive
7436 && !NILP (echo_area_buffer
[0]))
7438 struct frame
*sf
= SELECTED_FRAME ();
7439 if (FRAME_MESSAGE_BUF (sf
))
7440 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
7445 /* Helper function for truncate_echo_area. Truncate the current
7446 message to at most NCHARS characters. */
7449 truncate_message_1 (nchars
, a2
, a3
, a4
)
7454 if (BEG
+ nchars
< Z
)
7455 del_range (BEG
+ nchars
, Z
);
7457 echo_area_buffer
[0] = Qnil
;
7462 /* Set the current message to a substring of S or STRING.
7464 If STRING is a Lisp string, set the message to the first NBYTES
7465 bytes from STRING. NBYTES zero means use the whole string. If
7466 STRING is multibyte, the message will be displayed multibyte.
7468 If S is not null, set the message to the first LEN bytes of S. LEN
7469 zero means use the whole string. MULTIBYTE_P non-zero means S is
7470 multibyte. Display the message multibyte in that case. */
7473 set_message (s
, string
, nbytes
, multibyte_p
)
7476 int nbytes
, multibyte_p
;
7478 message_enable_multibyte
7479 = ((s
&& multibyte_p
)
7480 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
7482 with_echo_area_buffer (0, -1, set_message_1
,
7483 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
7484 message_buf_print
= 0;
7485 help_echo_showing_p
= 0;
7489 /* Helper function for set_message. Arguments have the same meaning
7490 as there, with A1 corresponding to S and A2 corresponding to STRING
7491 This function is called with the echo area buffer being
7495 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
7498 EMACS_INT nbytes
, multibyte_p
;
7500 const char *s
= (const char *) a1
;
7501 Lisp_Object string
= a2
;
7505 /* Change multibyteness of the echo buffer appropriately. */
7506 if (message_enable_multibyte
7507 != !NILP (current_buffer
->enable_multibyte_characters
))
7508 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
7510 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
7512 /* Insert new message at BEG. */
7513 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7515 if (STRINGP (string
))
7520 nbytes
= SBYTES (string
);
7521 nchars
= string_byte_to_char (string
, nbytes
);
7523 /* This function takes care of single/multibyte conversion. We
7524 just have to ensure that the echo area buffer has the right
7525 setting of enable_multibyte_characters. */
7526 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7531 nbytes
= strlen (s
);
7533 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
7535 /* Convert from multi-byte to single-byte. */
7537 unsigned char work
[1];
7539 /* Convert a multibyte string to single-byte. */
7540 for (i
= 0; i
< nbytes
; i
+= n
)
7542 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
7543 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7545 : multibyte_char_to_unibyte (c
, Qnil
));
7546 insert_1_both (work
, 1, 1, 1, 0, 0);
7549 else if (!multibyte_p
7550 && !NILP (current_buffer
->enable_multibyte_characters
))
7552 /* Convert from single-byte to multi-byte. */
7554 const unsigned char *msg
= (const unsigned char *) s
;
7555 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7557 /* Convert a single-byte string to multibyte. */
7558 for (i
= 0; i
< nbytes
; i
++)
7560 c
= unibyte_char_to_multibyte (msg
[i
]);
7561 n
= CHAR_STRING (c
, str
);
7562 insert_1_both (str
, 1, n
, 1, 0, 0);
7566 insert_1 (s
, nbytes
, 1, 0, 0);
7573 /* Clear messages. CURRENT_P non-zero means clear the current
7574 message. LAST_DISPLAYED_P non-zero means clear the message
7578 clear_message (current_p
, last_displayed_p
)
7579 int current_p
, last_displayed_p
;
7583 echo_area_buffer
[0] = Qnil
;
7584 message_cleared_p
= 1;
7587 if (last_displayed_p
)
7588 echo_area_buffer
[1] = Qnil
;
7590 message_buf_print
= 0;
7593 /* Clear garbaged frames.
7595 This function is used where the old redisplay called
7596 redraw_garbaged_frames which in turn called redraw_frame which in
7597 turn called clear_frame. The call to clear_frame was a source of
7598 flickering. I believe a clear_frame is not necessary. It should
7599 suffice in the new redisplay to invalidate all current matrices,
7600 and ensure a complete redisplay of all windows. */
7603 clear_garbaged_frames ()
7607 Lisp_Object tail
, frame
;
7608 int changed_count
= 0;
7610 FOR_EACH_FRAME (tail
, frame
)
7612 struct frame
*f
= XFRAME (frame
);
7614 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7617 Fredraw_frame (frame
);
7618 clear_current_matrices (f
);
7627 ++windows_or_buffers_changed
;
7632 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7633 is non-zero update selected_frame. Value is non-zero if the
7634 mini-windows height has been changed. */
7637 echo_area_display (update_frame_p
)
7640 Lisp_Object mini_window
;
7643 int window_height_changed_p
= 0;
7644 struct frame
*sf
= SELECTED_FRAME ();
7646 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7647 w
= XWINDOW (mini_window
);
7648 f
= XFRAME (WINDOW_FRAME (w
));
7650 /* Don't display if frame is invisible or not yet initialized. */
7651 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7654 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7656 #ifdef HAVE_WINDOW_SYSTEM
7657 /* When Emacs starts, selected_frame may be the initial terminal
7658 frame. If we let this through, a message would be displayed on
7660 if (FRAME_TERMCAP_P (XFRAME (selected_frame
))
7661 && FRAME_TTY (XFRAME (selected_frame
))->type
== NULL
)
7663 #endif /* HAVE_WINDOW_SYSTEM */
7666 /* Redraw garbaged frames. */
7668 clear_garbaged_frames ();
7670 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7672 echo_area_window
= mini_window
;
7673 window_height_changed_p
= display_echo_area (w
);
7674 w
->must_be_updated_p
= 1;
7676 /* Update the display, unless called from redisplay_internal.
7677 Also don't update the screen during redisplay itself. The
7678 update will happen at the end of redisplay, and an update
7679 here could cause confusion. */
7680 if (update_frame_p
&& !redisplaying_p
)
7684 /* If the display update has been interrupted by pending
7685 input, update mode lines in the frame. Due to the
7686 pending input, it might have been that redisplay hasn't
7687 been called, so that mode lines above the echo area are
7688 garbaged. This looks odd, so we prevent it here. */
7689 if (!display_completed
)
7690 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7692 if (window_height_changed_p
7693 /* Don't do this if Emacs is shutting down. Redisplay
7694 needs to run hooks. */
7695 && !NILP (Vrun_hooks
))
7697 /* Must update other windows. Likewise as in other
7698 cases, don't let this update be interrupted by
7700 int count
= SPECPDL_INDEX ();
7701 specbind (Qredisplay_dont_pause
, Qt
);
7702 windows_or_buffers_changed
= 1;
7703 redisplay_internal (0);
7704 unbind_to (count
, Qnil
);
7706 else if (FRAME_WINDOW_P (f
) && n
== 0)
7708 /* Window configuration is the same as before.
7709 Can do with a display update of the echo area,
7710 unless we displayed some mode lines. */
7711 update_single_window (w
, 1);
7712 FRAME_RIF (f
)->flush_display (f
);
7715 update_frame (f
, 1, 1);
7717 /* If cursor is in the echo area, make sure that the next
7718 redisplay displays the minibuffer, so that the cursor will
7719 be replaced with what the minibuffer wants. */
7720 if (cursor_in_echo_area
)
7721 ++windows_or_buffers_changed
;
7724 else if (!EQ (mini_window
, selected_window
))
7725 windows_or_buffers_changed
++;
7727 /* Last displayed message is now the current message. */
7728 echo_area_buffer
[1] = echo_area_buffer
[0];
7730 /* Prevent redisplay optimization in redisplay_internal by resetting
7731 this_line_start_pos. This is done because the mini-buffer now
7732 displays the message instead of its buffer text. */
7733 if (EQ (mini_window
, selected_window
))
7734 CHARPOS (this_line_start_pos
) = 0;
7736 return window_height_changed_p
;
7741 /***********************************************************************
7743 ***********************************************************************/
7746 /* The frame title buffering code is also used by Fformat_mode_line.
7747 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
7749 /* A buffer for constructing frame titles in it; allocated from the
7750 heap in init_xdisp and resized as needed in store_frame_title_char. */
7752 static char *frame_title_buf
;
7754 /* The buffer's end, and a current output position in it. */
7756 static char *frame_title_buf_end
;
7757 static char *frame_title_ptr
;
7760 /* Store a single character C for the frame title in frame_title_buf.
7761 Re-allocate frame_title_buf if necessary. */
7765 store_frame_title_char (char c
)
7767 store_frame_title_char (c
)
7771 /* If output position has reached the end of the allocated buffer,
7772 double the buffer's size. */
7773 if (frame_title_ptr
== frame_title_buf_end
)
7775 int len
= frame_title_ptr
- frame_title_buf
;
7776 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7777 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7778 frame_title_buf_end
= frame_title_buf
+ new_size
;
7779 frame_title_ptr
= frame_title_buf
+ len
;
7782 *frame_title_ptr
++ = c
;
7786 /* Store part of a frame title in frame_title_buf, beginning at
7787 frame_title_ptr. STR is the string to store. Do not copy
7788 characters that yield more columns than PRECISION; PRECISION <= 0
7789 means copy the whole string. Pad with spaces until FIELD_WIDTH
7790 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7791 pad. Called from display_mode_element when it is used to build a
7795 store_frame_title (str
, field_width
, precision
)
7796 const unsigned char *str
;
7797 int field_width
, precision
;
7802 /* Copy at most PRECISION chars from STR. */
7803 nbytes
= strlen (str
);
7804 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7806 store_frame_title_char (*str
++);
7808 /* Fill up with spaces until FIELD_WIDTH reached. */
7809 while (field_width
> 0
7812 store_frame_title_char (' ');
7819 #ifdef HAVE_WINDOW_SYSTEM
7821 /* Set the title of FRAME, if it has changed. The title format is
7822 Vicon_title_format if FRAME is iconified, otherwise it is
7823 frame_title_format. */
7826 x_consider_frame_title (frame
)
7829 struct frame
*f
= XFRAME (frame
);
7831 if (FRAME_WINDOW_P (f
)
7832 || FRAME_MINIBUF_ONLY_P (f
)
7833 || f
->explicit_name
)
7835 /* Do we have more than one visible frame on this X display? */
7838 struct buffer
*obuf
;
7842 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7844 Lisp_Object other_frame
= XCAR (tail
);
7845 struct frame
*tf
= XFRAME (other_frame
);
7848 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7849 && !FRAME_MINIBUF_ONLY_P (tf
)
7850 && !EQ (other_frame
, tip_frame
)
7851 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7855 /* Set global variable indicating that multiple frames exist. */
7856 multiple_frames
= CONSP (tail
);
7858 /* Switch to the buffer of selected window of the frame. Set up
7859 frame_title_ptr so that display_mode_element will output into it;
7860 then display the title. */
7861 obuf
= current_buffer
;
7862 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
7863 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7864 frame_title_ptr
= frame_title_buf
;
7865 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7866 NULL
, DEFAULT_FACE_ID
);
7867 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
7868 len
= frame_title_ptr
- frame_title_buf
;
7869 frame_title_ptr
= NULL
;
7870 set_buffer_internal_1 (obuf
);
7872 /* Set the title only if it's changed. This avoids consing in
7873 the common case where it hasn't. (If it turns out that we've
7874 already wasted too much time by walking through the list with
7875 display_mode_element, then we might need to optimize at a
7876 higher level than this.) */
7877 if (! STRINGP (f
->name
)
7878 || SBYTES (f
->name
) != len
7879 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
7880 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7884 #endif /* not HAVE_WINDOW_SYSTEM */
7889 /***********************************************************************
7891 ***********************************************************************/
7894 /* Prepare for redisplay by updating menu-bar item lists when
7895 appropriate. This can call eval. */
7898 prepare_menu_bars ()
7901 struct gcpro gcpro1
, gcpro2
;
7903 Lisp_Object tooltip_frame
;
7905 #ifdef HAVE_WINDOW_SYSTEM
7906 tooltip_frame
= tip_frame
;
7908 tooltip_frame
= Qnil
;
7911 /* Update all frame titles based on their buffer names, etc. We do
7912 this before the menu bars so that the buffer-menu will show the
7913 up-to-date frame titles. */
7914 #ifdef HAVE_WINDOW_SYSTEM
7915 if (windows_or_buffers_changed
|| update_mode_lines
)
7917 Lisp_Object tail
, frame
;
7919 FOR_EACH_FRAME (tail
, frame
)
7922 if (!EQ (frame
, tooltip_frame
)
7923 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7924 x_consider_frame_title (frame
);
7927 #endif /* HAVE_WINDOW_SYSTEM */
7929 /* Update the menu bar item lists, if appropriate. This has to be
7930 done before any actual redisplay or generation of display lines. */
7931 all_windows
= (update_mode_lines
7932 || buffer_shared
> 1
7933 || windows_or_buffers_changed
);
7936 Lisp_Object tail
, frame
;
7937 int count
= SPECPDL_INDEX ();
7939 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7941 FOR_EACH_FRAME (tail
, frame
)
7945 /* Ignore tooltip frame. */
7946 if (EQ (frame
, tooltip_frame
))
7949 /* If a window on this frame changed size, report that to
7950 the user and clear the size-change flag. */
7951 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7953 Lisp_Object functions
;
7955 /* Clear flag first in case we get an error below. */
7956 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7957 functions
= Vwindow_size_change_functions
;
7958 GCPRO2 (tail
, functions
);
7960 while (CONSP (functions
))
7962 call1 (XCAR (functions
), frame
);
7963 functions
= XCDR (functions
);
7969 update_menu_bar (f
, 0);
7970 #ifdef HAVE_WINDOW_SYSTEM
7971 update_tool_bar (f
, 0);
7976 unbind_to (count
, Qnil
);
7980 struct frame
*sf
= SELECTED_FRAME ();
7981 update_menu_bar (sf
, 1);
7982 #ifdef HAVE_WINDOW_SYSTEM
7983 update_tool_bar (sf
, 1);
7987 /* Motif needs this. See comment in xmenu.c. Turn it off when
7988 pending_menu_activation is not defined. */
7989 #ifdef USE_X_TOOLKIT
7990 pending_menu_activation
= 0;
7995 /* Update the menu bar item list for frame F. This has to be done
7996 before we start to fill in any display lines, because it can call
7999 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8002 update_menu_bar (f
, save_match_data
)
8004 int save_match_data
;
8007 register struct window
*w
;
8009 /* If called recursively during a menu update, do nothing. This can
8010 happen when, for instance, an activate-menubar-hook causes a
8012 if (inhibit_menubar_update
)
8015 window
= FRAME_SELECTED_WINDOW (f
);
8016 w
= XWINDOW (window
);
8018 #if 0 /* The if statement below this if statement used to include the
8019 condition !NILP (w->update_mode_line), rather than using
8020 update_mode_lines directly, and this if statement may have
8021 been added to make that condition work. Now the if
8022 statement below matches its comment, this isn't needed. */
8023 if (update_mode_lines
)
8024 w
->update_mode_line
= Qt
;
8027 if (FRAME_WINDOW_P (f
)
8029 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8030 || defined (USE_GTK)
8031 FRAME_EXTERNAL_MENU_BAR (f
)
8033 FRAME_MENU_BAR_LINES (f
) > 0
8035 : FRAME_MENU_BAR_LINES (f
) > 0)
8037 /* If the user has switched buffers or windows, we need to
8038 recompute to reflect the new bindings. But we'll
8039 recompute when update_mode_lines is set too; that means
8040 that people can use force-mode-line-update to request
8041 that the menu bar be recomputed. The adverse effect on
8042 the rest of the redisplay algorithm is about the same as
8043 windows_or_buffers_changed anyway. */
8044 if (windows_or_buffers_changed
8045 /* This used to test w->update_mode_line, but we believe
8046 there is no need to recompute the menu in that case. */
8047 || update_mode_lines
8048 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8049 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8050 != !NILP (w
->last_had_star
))
8051 || ((!NILP (Vtransient_mark_mode
)
8052 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8053 != !NILP (w
->region_showing
)))
8055 struct buffer
*prev
= current_buffer
;
8056 int count
= SPECPDL_INDEX ();
8058 specbind (Qinhibit_menubar_update
, Qt
);
8060 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8061 if (save_match_data
)
8062 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8063 if (NILP (Voverriding_local_map_menu_flag
))
8065 specbind (Qoverriding_terminal_local_map
, Qnil
);
8066 specbind (Qoverriding_local_map
, Qnil
);
8069 /* Run the Lucid hook. */
8070 safe_run_hooks (Qactivate_menubar_hook
);
8072 /* If it has changed current-menubar from previous value,
8073 really recompute the menu-bar from the value. */
8074 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8075 call0 (Qrecompute_lucid_menubar
);
8077 safe_run_hooks (Qmenu_bar_update_hook
);
8078 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
8080 /* Redisplay the menu bar in case we changed it. */
8081 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8082 || defined (USE_GTK)
8083 if (FRAME_WINDOW_P (f
)
8084 #if defined (MAC_OS)
8085 /* All frames on Mac OS share the same menubar. So only the
8086 selected frame should be allowed to set it. */
8087 && f
== SELECTED_FRAME ()
8090 set_frame_menubar (f
, 0, 0);
8092 /* On a terminal screen, the menu bar is an ordinary screen
8093 line, and this makes it get updated. */
8094 w
->update_mode_line
= Qt
;
8095 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8096 /* In the non-toolkit version, the menu bar is an ordinary screen
8097 line, and this makes it get updated. */
8098 w
->update_mode_line
= Qt
;
8099 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8101 unbind_to (count
, Qnil
);
8102 set_buffer_internal_1 (prev
);
8109 /***********************************************************************
8111 ***********************************************************************/
8113 #ifdef HAVE_WINDOW_SYSTEM
8116 Nominal cursor position -- where to draw output.
8117 HPOS and VPOS are window relative glyph matrix coordinates.
8118 X and Y are window relative pixel coordinates. */
8120 struct cursor_pos output_cursor
;
8124 Set the global variable output_cursor to CURSOR. All cursor
8125 positions are relative to updated_window. */
8128 set_output_cursor (cursor
)
8129 struct cursor_pos
*cursor
;
8131 output_cursor
.hpos
= cursor
->hpos
;
8132 output_cursor
.vpos
= cursor
->vpos
;
8133 output_cursor
.x
= cursor
->x
;
8134 output_cursor
.y
= cursor
->y
;
8139 Set a nominal cursor position.
8141 HPOS and VPOS are column/row positions in a window glyph matrix. X
8142 and Y are window text area relative pixel positions.
8144 If this is done during an update, updated_window will contain the
8145 window that is being updated and the position is the future output
8146 cursor position for that window. If updated_window is null, use
8147 selected_window and display the cursor at the given position. */
8150 x_cursor_to (vpos
, hpos
, y
, x
)
8151 int vpos
, hpos
, y
, x
;
8155 /* If updated_window is not set, work on selected_window. */
8159 w
= XWINDOW (selected_window
);
8161 /* Set the output cursor. */
8162 output_cursor
.hpos
= hpos
;
8163 output_cursor
.vpos
= vpos
;
8164 output_cursor
.x
= x
;
8165 output_cursor
.y
= y
;
8167 /* If not called as part of an update, really display the cursor.
8168 This will also set the cursor position of W. */
8169 if (updated_window
== NULL
)
8172 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8173 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
8174 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
8179 #endif /* HAVE_WINDOW_SYSTEM */
8182 /***********************************************************************
8184 ***********************************************************************/
8186 #ifdef HAVE_WINDOW_SYSTEM
8188 /* Where the mouse was last time we reported a mouse event. */
8190 FRAME_PTR last_mouse_frame
;
8192 /* Tool-bar item index of the item on which a mouse button was pressed
8195 int last_tool_bar_item
;
8198 /* Update the tool-bar item list for frame F. This has to be done
8199 before we start to fill in any display lines. Called from
8200 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8201 and restore it here. */
8204 update_tool_bar (f
, save_match_data
)
8206 int save_match_data
;
8209 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
8211 int do_update
= WINDOWP (f
->tool_bar_window
)
8212 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
8220 window
= FRAME_SELECTED_WINDOW (f
);
8221 w
= XWINDOW (window
);
8223 /* If the user has switched buffers or windows, we need to
8224 recompute to reflect the new bindings. But we'll
8225 recompute when update_mode_lines is set too; that means
8226 that people can use force-mode-line-update to request
8227 that the menu bar be recomputed. The adverse effect on
8228 the rest of the redisplay algorithm is about the same as
8229 windows_or_buffers_changed anyway. */
8230 if (windows_or_buffers_changed
8231 || !NILP (w
->update_mode_line
)
8232 || update_mode_lines
8233 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8234 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8235 != !NILP (w
->last_had_star
))
8236 || ((!NILP (Vtransient_mark_mode
)
8237 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8238 != !NILP (w
->region_showing
)))
8240 struct buffer
*prev
= current_buffer
;
8241 int count
= SPECPDL_INDEX ();
8242 Lisp_Object old_tool_bar
;
8243 struct gcpro gcpro1
;
8245 /* Set current_buffer to the buffer of the selected
8246 window of the frame, so that we get the right local
8248 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8250 /* Save match data, if we must. */
8251 if (save_match_data
)
8252 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8254 /* Make sure that we don't accidentally use bogus keymaps. */
8255 if (NILP (Voverriding_local_map_menu_flag
))
8257 specbind (Qoverriding_terminal_local_map
, Qnil
);
8258 specbind (Qoverriding_local_map
, Qnil
);
8261 old_tool_bar
= f
->tool_bar_items
;
8262 GCPRO1 (old_tool_bar
);
8264 /* Build desired tool-bar items from keymaps. */
8267 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
8270 /* Redisplay the tool-bar if we changed it. */
8271 if (! NILP (Fequal (old_tool_bar
, f
->tool_bar_items
)))
8272 w
->update_mode_line
= Qt
;
8276 unbind_to (count
, Qnil
);
8277 set_buffer_internal_1 (prev
);
8283 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8284 F's desired tool-bar contents. F->tool_bar_items must have
8285 been set up previously by calling prepare_menu_bars. */
8288 build_desired_tool_bar_string (f
)
8291 int i
, size
, size_needed
;
8292 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8293 Lisp_Object image
, plist
, props
;
8295 image
= plist
= props
= Qnil
;
8296 GCPRO3 (image
, plist
, props
);
8298 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
8299 Otherwise, make a new string. */
8301 /* The size of the string we might be able to reuse. */
8302 size
= (STRINGP (f
->desired_tool_bar_string
)
8303 ? SCHARS (f
->desired_tool_bar_string
)
8306 /* We need one space in the string for each image. */
8307 size_needed
= f
->n_tool_bar_items
;
8309 /* Reuse f->desired_tool_bar_string, if possible. */
8310 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
8311 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
8315 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
8316 Fremove_text_properties (make_number (0), make_number (size
),
8317 props
, f
->desired_tool_bar_string
);
8320 /* Put a `display' property on the string for the images to display,
8321 put a `menu_item' property on tool-bar items with a value that
8322 is the index of the item in F's tool-bar item vector. */
8323 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
8325 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
8327 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8328 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8329 int hmargin
, vmargin
, relief
, idx
, end
;
8330 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
8332 /* If image is a vector, choose the image according to the
8334 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
8335 if (VECTORP (image
))
8339 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
8340 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
8343 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
8344 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
8346 xassert (ASIZE (image
) >= idx
);
8347 image
= AREF (image
, idx
);
8352 /* Ignore invalid image specifications. */
8353 if (!valid_image_p (image
))
8356 /* Display the tool-bar button pressed, or depressed. */
8357 plist
= Fcopy_sequence (XCDR (image
));
8359 /* Compute margin and relief to draw. */
8360 relief
= (tool_bar_button_relief
>= 0
8361 ? tool_bar_button_relief
8362 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
8363 hmargin
= vmargin
= relief
;
8365 if (INTEGERP (Vtool_bar_button_margin
)
8366 && XINT (Vtool_bar_button_margin
) > 0)
8368 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
8369 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
8371 else if (CONSP (Vtool_bar_button_margin
))
8373 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
8374 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
8375 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
8377 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
8378 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
8379 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
8382 if (auto_raise_tool_bar_buttons_p
)
8384 /* Add a `:relief' property to the image spec if the item is
8388 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
8395 /* If image is selected, display it pressed, i.e. with a
8396 negative relief. If it's not selected, display it with a
8398 plist
= Fplist_put (plist
, QCrelief
,
8400 ? make_number (-relief
)
8401 : make_number (relief
)));
8406 /* Put a margin around the image. */
8407 if (hmargin
|| vmargin
)
8409 if (hmargin
== vmargin
)
8410 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
8412 plist
= Fplist_put (plist
, QCmargin
,
8413 Fcons (make_number (hmargin
),
8414 make_number (vmargin
)));
8417 /* If button is not enabled, and we don't have special images
8418 for the disabled state, make the image appear disabled by
8419 applying an appropriate algorithm to it. */
8420 if (!enabled_p
&& idx
< 0)
8421 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
8423 /* Put a `display' text property on the string for the image to
8424 display. Put a `menu-item' property on the string that gives
8425 the start of this item's properties in the tool-bar items
8427 image
= Fcons (Qimage
, plist
);
8428 props
= list4 (Qdisplay
, image
,
8429 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
8431 /* Let the last image hide all remaining spaces in the tool bar
8432 string. The string can be longer than needed when we reuse a
8434 if (i
+ 1 == f
->n_tool_bar_items
)
8435 end
= SCHARS (f
->desired_tool_bar_string
);
8438 Fadd_text_properties (make_number (i
), make_number (end
),
8439 props
, f
->desired_tool_bar_string
);
8447 /* Display one line of the tool-bar of frame IT->f. */
8450 display_tool_bar_line (it
)
8453 struct glyph_row
*row
= it
->glyph_row
;
8454 int max_x
= it
->last_visible_x
;
8457 prepare_desired_row (row
);
8458 row
->y
= it
->current_y
;
8460 /* Note that this isn't made use of if the face hasn't a box,
8461 so there's no need to check the face here. */
8462 it
->start_of_box_run_p
= 1;
8464 while (it
->current_x
< max_x
)
8466 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
8468 /* Get the next display element. */
8469 if (!get_next_display_element (it
))
8472 /* Produce glyphs. */
8473 x_before
= it
->current_x
;
8474 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
8475 PRODUCE_GLYPHS (it
);
8477 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
8482 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
8484 if (x
+ glyph
->pixel_width
> max_x
)
8486 /* Glyph doesn't fit on line. */
8487 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
8493 x
+= glyph
->pixel_width
;
8497 /* Stop at line ends. */
8498 if (ITERATOR_AT_END_OF_LINE_P (it
))
8501 set_iterator_to_next (it
, 1);
8506 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
8507 extend_face_to_end_of_line (it
);
8508 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
8509 last
->right_box_line_p
= 1;
8510 if (last
== row
->glyphs
[TEXT_AREA
])
8511 last
->left_box_line_p
= 1;
8512 compute_line_metrics (it
);
8514 /* If line is empty, make it occupy the rest of the tool-bar. */
8515 if (!row
->displays_text_p
)
8517 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
8518 row
->ascent
= row
->phys_ascent
= 0;
8521 row
->full_width_p
= 1;
8522 row
->continued_p
= 0;
8523 row
->truncated_on_left_p
= 0;
8524 row
->truncated_on_right_p
= 0;
8526 it
->current_x
= it
->hpos
= 0;
8527 it
->current_y
+= row
->height
;
8533 /* Value is the number of screen lines needed to make all tool-bar
8534 items of frame F visible. */
8537 tool_bar_lines_needed (f
)
8540 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8543 /* Initialize an iterator for iteration over
8544 F->desired_tool_bar_string in the tool-bar window of frame F. */
8545 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8546 it
.first_visible_x
= 0;
8547 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8548 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8550 while (!ITERATOR_AT_END_P (&it
))
8552 it
.glyph_row
= w
->desired_matrix
->rows
;
8553 clear_glyph_row (it
.glyph_row
);
8554 display_tool_bar_line (&it
);
8557 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
8561 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
8563 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
8572 frame
= selected_frame
;
8574 CHECK_FRAME (frame
);
8577 if (WINDOWP (f
->tool_bar_window
)
8578 || (w
= XWINDOW (f
->tool_bar_window
),
8579 WINDOW_TOTAL_LINES (w
) > 0))
8581 update_tool_bar (f
, 1);
8582 if (f
->n_tool_bar_items
)
8584 build_desired_tool_bar_string (f
);
8585 nlines
= tool_bar_lines_needed (f
);
8589 return make_number (nlines
);
8593 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
8594 height should be changed. */
8597 redisplay_tool_bar (f
)
8602 struct glyph_row
*row
;
8603 int change_height_p
= 0;
8606 if (FRAME_EXTERNAL_TOOL_BAR (f
))
8607 update_frame_tool_bar (f
);
8611 /* If frame hasn't a tool-bar window or if it is zero-height, don't
8612 do anything. This means you must start with tool-bar-lines
8613 non-zero to get the auto-sizing effect. Or in other words, you
8614 can turn off tool-bars by specifying tool-bar-lines zero. */
8615 if (!WINDOWP (f
->tool_bar_window
)
8616 || (w
= XWINDOW (f
->tool_bar_window
),
8617 WINDOW_TOTAL_LINES (w
) == 0))
8620 /* Set up an iterator for the tool-bar window. */
8621 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8622 it
.first_visible_x
= 0;
8623 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8626 /* Build a string that represents the contents of the tool-bar. */
8627 build_desired_tool_bar_string (f
);
8628 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8630 /* Display as many lines as needed to display all tool-bar items. */
8631 while (it
.current_y
< it
.last_visible_y
)
8632 display_tool_bar_line (&it
);
8634 /* It doesn't make much sense to try scrolling in the tool-bar
8635 window, so don't do it. */
8636 w
->desired_matrix
->no_scrolling_p
= 1;
8637 w
->must_be_updated_p
= 1;
8639 if (auto_resize_tool_bars_p
)
8643 /* If we couldn't display everything, change the tool-bar's
8645 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
8646 change_height_p
= 1;
8648 /* If there are blank lines at the end, except for a partially
8649 visible blank line at the end that is smaller than
8650 FRAME_LINE_HEIGHT, change the tool-bar's height. */
8651 row
= it
.glyph_row
- 1;
8652 if (!row
->displays_text_p
8653 && row
->height
>= FRAME_LINE_HEIGHT (f
))
8654 change_height_p
= 1;
8656 /* If row displays tool-bar items, but is partially visible,
8657 change the tool-bar's height. */
8658 if (row
->displays_text_p
8659 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
8660 change_height_p
= 1;
8662 /* Resize windows as needed by changing the `tool-bar-lines'
8665 && (nlines
= tool_bar_lines_needed (f
),
8666 nlines
!= WINDOW_TOTAL_LINES (w
)))
8668 extern Lisp_Object Qtool_bar_lines
;
8670 int old_height
= WINDOW_TOTAL_LINES (w
);
8672 XSETFRAME (frame
, f
);
8673 clear_glyph_matrix (w
->desired_matrix
);
8674 Fmodify_frame_parameters (frame
,
8675 Fcons (Fcons (Qtool_bar_lines
,
8676 make_number (nlines
)),
8678 if (WINDOW_TOTAL_LINES (w
) != old_height
)
8679 fonts_changed_p
= 1;
8683 return change_height_p
;
8687 /* Get information about the tool-bar item which is displayed in GLYPH
8688 on frame F. Return in *PROP_IDX the index where tool-bar item
8689 properties start in F->tool_bar_items. Value is zero if
8690 GLYPH doesn't display a tool-bar item. */
8693 tool_bar_item_info (f
, glyph
, prop_idx
)
8695 struct glyph
*glyph
;
8702 /* This function can be called asynchronously, which means we must
8703 exclude any possibility that Fget_text_property signals an
8705 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
8706 charpos
= max (0, charpos
);
8708 /* Get the text property `menu-item' at pos. The value of that
8709 property is the start index of this item's properties in
8710 F->tool_bar_items. */
8711 prop
= Fget_text_property (make_number (charpos
),
8712 Qmenu_item
, f
->current_tool_bar_string
);
8713 if (INTEGERP (prop
))
8715 *prop_idx
= XINT (prop
);
8725 /* Get information about the tool-bar item at position X/Y on frame F.
8726 Return in *GLYPH a pointer to the glyph of the tool-bar item in
8727 the current matrix of the tool-bar window of F, or NULL if not
8728 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
8729 item in F->tool_bar_items. Value is
8731 -1 if X/Y is not on a tool-bar item
8732 0 if X/Y is on the same item that was highlighted before.
8736 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
8739 struct glyph
**glyph
;
8740 int *hpos
, *vpos
, *prop_idx
;
8742 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8743 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8746 /* Find the glyph under X/Y. */
8747 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
8751 /* Get the start of this tool-bar item's properties in
8752 f->tool_bar_items. */
8753 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
8756 /* Is mouse on the highlighted item? */
8757 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
8758 && *vpos
>= dpyinfo
->mouse_face_beg_row
8759 && *vpos
<= dpyinfo
->mouse_face_end_row
8760 && (*vpos
> dpyinfo
->mouse_face_beg_row
8761 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
8762 && (*vpos
< dpyinfo
->mouse_face_end_row
8763 || *hpos
< dpyinfo
->mouse_face_end_col
8764 || dpyinfo
->mouse_face_past_end
))
8772 Handle mouse button event on the tool-bar of frame F, at
8773 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
8774 0 for button release. MODIFIERS is event modifiers for button
8778 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
8781 unsigned int modifiers
;
8783 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8784 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8785 int hpos
, vpos
, prop_idx
;
8786 struct glyph
*glyph
;
8787 Lisp_Object enabled_p
;
8789 /* If not on the highlighted tool-bar item, return. */
8790 frame_to_window_pixel_xy (w
, &x
, &y
);
8791 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
8794 /* If item is disabled, do nothing. */
8795 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
8796 if (NILP (enabled_p
))
8801 /* Show item in pressed state. */
8802 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
8803 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
8804 last_tool_bar_item
= prop_idx
;
8808 Lisp_Object key
, frame
;
8809 struct input_event event
;
8812 /* Show item in released state. */
8813 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
8814 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
8816 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
8818 XSETFRAME (frame
, f
);
8819 event
.kind
= TOOL_BAR_EVENT
;
8820 event
.frame_or_window
= frame
;
8822 kbd_buffer_store_event (&event
);
8824 event
.kind
= TOOL_BAR_EVENT
;
8825 event
.frame_or_window
= frame
;
8827 event
.modifiers
= modifiers
;
8828 kbd_buffer_store_event (&event
);
8829 last_tool_bar_item
= -1;
8834 /* Possibly highlight a tool-bar item on frame F when mouse moves to
8835 tool-bar window-relative coordinates X/Y. Called from
8836 note_mouse_highlight. */
8839 note_tool_bar_highlight (f
, x
, y
)
8843 Lisp_Object window
= f
->tool_bar_window
;
8844 struct window
*w
= XWINDOW (window
);
8845 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8847 struct glyph
*glyph
;
8848 struct glyph_row
*row
;
8850 Lisp_Object enabled_p
;
8852 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
8853 int mouse_down_p
, rc
;
8855 /* Function note_mouse_highlight is called with negative x(y
8856 values when mouse moves outside of the frame. */
8857 if (x
<= 0 || y
<= 0)
8859 clear_mouse_face (dpyinfo
);
8863 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
8866 /* Not on tool-bar item. */
8867 clear_mouse_face (dpyinfo
);
8871 /* On same tool-bar item as before. */
8874 clear_mouse_face (dpyinfo
);
8876 /* Mouse is down, but on different tool-bar item? */
8877 mouse_down_p
= (dpyinfo
->grabbed
8878 && f
== last_mouse_frame
8879 && FRAME_LIVE_P (f
));
8881 && last_tool_bar_item
!= prop_idx
)
8884 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
8885 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
8887 /* If tool-bar item is not enabled, don't highlight it. */
8888 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
8889 if (!NILP (enabled_p
))
8891 /* Compute the x-position of the glyph. In front and past the
8892 image is a space. We include this in the highlighted area. */
8893 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
8894 for (i
= x
= 0; i
< hpos
; ++i
)
8895 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
8897 /* Record this as the current active region. */
8898 dpyinfo
->mouse_face_beg_col
= hpos
;
8899 dpyinfo
->mouse_face_beg_row
= vpos
;
8900 dpyinfo
->mouse_face_beg_x
= x
;
8901 dpyinfo
->mouse_face_beg_y
= row
->y
;
8902 dpyinfo
->mouse_face_past_end
= 0;
8904 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
8905 dpyinfo
->mouse_face_end_row
= vpos
;
8906 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
8907 dpyinfo
->mouse_face_end_y
= row
->y
;
8908 dpyinfo
->mouse_face_window
= window
;
8909 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
8911 /* Display it as active. */
8912 show_mouse_face (dpyinfo
, draw
);
8913 dpyinfo
->mouse_face_image_state
= draw
;
8918 /* Set help_echo_string to a help string to display for this tool-bar item.
8919 XTread_socket does the rest. */
8920 help_echo_object
= help_echo_window
= Qnil
;
8922 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
8923 if (NILP (help_echo_string
))
8924 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
8927 #endif /* HAVE_WINDOW_SYSTEM */
8931 /***********************************************************************
8933 ***********************************************************************/
8935 #ifdef HAVE_WINDOW_SYSTEM
8937 /* Notice that all bitmaps bits are "mirrored". */
8939 /* An arrow like this: `<-'. */
8950 static unsigned char left_bits
[] = {
8951 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
8954 /* Right truncation arrow bitmap `->'. */
8965 static unsigned char right_bits
[] = {
8966 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
8969 /* Up arrow bitmap. */
8980 static unsigned char up_arrow_bits
[] = {
8981 0x18, 0x3c, 0x7e, 0xff, 0x18, 0x18, 0x18, 0x18};
8984 /* Down arrow bitmap. */
8995 static unsigned char down_arrow_bits
[] = {
8996 0x18, 0x18, 0x18, 0x18, 0xff, 0x7e, 0x3c, 0x18};
8998 /* Marker for continued lines. */
9009 static unsigned char continued_bits
[] = {
9010 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
9012 /* Marker for continuation lines. */
9023 static unsigned char continuation_bits
[] = {
9024 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
9026 /* Overlay arrow bitmap. A triangular arrow. */
9037 static unsigned char ov_bits
[] = {
9038 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
9041 /* First line bitmap. An left-up angle. */
9052 static unsigned char first_line_bits
[] = {
9053 0x3f, 0x3f, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00};
9056 /* Last line bitmap. An left-down angle. */
9067 static unsigned char last_line_bits
[] = {
9068 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xfc};
9070 /* Filled box cursor bitmap. A filled box; max 13 pixels high. */
9086 static unsigned char filled_box_cursor_bits
[] = {
9087 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f};
9089 /* Hollow box cursor bitmap. A hollow box; max 13 pixels high. */
9105 static unsigned char hollow_box_cursor_bits
[] = {
9106 0x7f, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x7f};
9108 /* Bar cursor bitmap. A vertical bar; max 13 pixels high. */
9124 static unsigned char bar_cursor_bits
[] = {
9125 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03};
9127 /* HBar cursor bitmap. A horisontal bar; 2 pixels high. */
9132 static unsigned char hbar_cursor_bits
[] = {
9136 /* Bitmap drawn to indicate lines not displaying text if
9137 `indicate-empty-lines' is non-nil. */
9138 static unsigned char zv_bits
[] = {
9139 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
9140 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
9141 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
9142 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
9143 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
9144 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
9145 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
9146 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00};
9148 /* Hollow square bitmap. */
9157 static unsigned char hollow_square_bits
[] = {
9158 0x7e, 0x42, 0x42, 0x42, 0x42, 0x7e};
9161 struct fringe_bitmap fringe_bitmaps
[MAX_FRINGE_BITMAPS
] =
9163 { 0, 0, 0, NULL
/* NO_FRINGE_BITMAP */ },
9164 { 8, sizeof (left_bits
), 0, left_bits
},
9165 { 8, sizeof (right_bits
), 0, right_bits
},
9166 { 8, sizeof (up_arrow_bits
), -1, up_arrow_bits
},
9167 { 8, sizeof (down_arrow_bits
), -2, down_arrow_bits
},
9168 { 8, sizeof (continued_bits
), 0, continued_bits
},
9169 { 8, sizeof (continuation_bits
), 0, continuation_bits
},
9170 { 8, sizeof (ov_bits
), 0, ov_bits
},
9171 { 8, sizeof (first_line_bits
), -1, first_line_bits
},
9172 { 8, sizeof (last_line_bits
), -2, last_line_bits
},
9173 { 8, sizeof (filled_box_cursor_bits
), 0, filled_box_cursor_bits
},
9174 { 8, sizeof (hollow_box_cursor_bits
), 0, hollow_box_cursor_bits
},
9175 { 8, sizeof (bar_cursor_bits
), 0, bar_cursor_bits
},
9176 { 8, sizeof (hbar_cursor_bits
), -2, hbar_cursor_bits
},
9177 { 8, sizeof (zv_bits
), 3, zv_bits
},
9178 { 8, sizeof (hollow_square_bits
), 0, hollow_square_bits
},
9182 /* Draw the bitmap WHICH in one of the left or right fringes of
9183 window W. ROW is the glyph row for which to display the bitmap; it
9184 determines the vertical position at which the bitmap has to be
9186 LEFT_P is 1 for left fringe, 0 for right fringe.
9190 draw_fringe_bitmap (w
, row
, left_p
)
9192 struct glyph_row
*row
;
9195 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9196 struct draw_fringe_bitmap_params p
;
9197 enum fringe_bitmap_type which
;
9201 which
= row
->left_fringe_bitmap
;
9202 else if (!row
->cursor_in_fringe_p
)
9203 which
= row
->right_fringe_bitmap
;
9205 switch (w
->phys_cursor_type
)
9207 case HOLLOW_BOX_CURSOR
:
9208 if (row
->visible_height
>= sizeof(hollow_box_cursor_bits
))
9209 which
= HOLLOW_BOX_CURSOR_BITMAP
;
9211 which
= HOLLOW_SQUARE_BITMAP
;
9213 case FILLED_BOX_CURSOR
:
9214 which
= FILLED_BOX_CURSOR_BITMAP
;
9217 which
= BAR_CURSOR_BITMAP
;
9220 which
= HBAR_CURSOR_BITMAP
;
9224 w
->phys_cursor_on_p
= 0;
9225 row
->cursor_in_fringe_p
= 0;
9226 which
= row
->right_fringe_bitmap
;
9230 period
= fringe_bitmaps
[which
].period
;
9232 /* Convert row to frame coordinates. */
9233 p
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
9236 p
.wd
= fringe_bitmaps
[which
].width
;
9238 p
.h
= fringe_bitmaps
[which
].height
;
9239 p
.dh
= (period
> 0 ? (p
.y
% period
) : 0);
9241 /* Clip bitmap if too high. */
9242 if (p
.h
> row
->height
)
9245 p
.face
= FACE_FROM_ID (f
, FRINGE_FACE_ID
);
9246 PREPARE_FACE_FOR_DISPLAY (f
, p
.face
);
9248 /* Clear left fringe if no bitmap to draw or if bitmap doesn't fill
9253 int wd
= WINDOW_LEFT_FRINGE_WIDTH (w
);
9254 int x
= window_box_left (w
, (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
9259 p
.x
= x
- p
.wd
- (wd
- p
.wd
) / 2;
9261 if (p
.wd
< wd
|| row
->height
> p
.h
)
9263 /* If W has a vertical border to its left, don't draw over it. */
9264 wd
-= ((!WINDOW_LEFTMOST_P (w
)
9265 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
9273 int x
= window_box_right (w
,
9274 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
9277 int wd
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
9280 p
.x
= x
+ (wd
- p
.wd
) / 2;
9281 /* Clear right fringe if no bitmap to draw of if bitmap doesn't fill
9283 if (p
.wd
< wd
|| row
->height
> p
.h
)
9292 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
9294 p
.by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, row
->y
));
9295 p
.ny
= row
->visible_height
;
9298 /* Adjust y to the offset in the row to start drawing the bitmap. */
9300 p
.y
+= (row
->height
- p
.h
) / 2;
9301 else if (period
== -2)
9303 p
.h
= fringe_bitmaps
[which
].height
;
9304 p
.y
+= (row
->visible_height
- p
.h
);
9307 FRAME_RIF (f
)->draw_fringe_bitmap (w
, row
, &p
);
9310 /* Draw fringe bitmaps for glyph row ROW on window W. Call this
9311 function with input blocked. */
9314 draw_row_fringe_bitmaps (w
, row
)
9316 struct glyph_row
*row
;
9318 xassert (interrupt_input_blocked
);
9320 /* If row is completely invisible, because of vscrolling, we
9321 don't have to draw anything. */
9322 if (row
->visible_height
<= 0)
9325 if (WINDOW_LEFT_FRINGE_WIDTH (w
) != 0)
9326 draw_fringe_bitmap (w
, row
, 1);
9328 if (WINDOW_RIGHT_FRINGE_WIDTH (w
) != 0)
9329 draw_fringe_bitmap (w
, row
, 0);
9332 /* Draw the fringes of window W. Only fringes for rows marked for
9333 update in redraw_fringe_bitmaps_p are drawn. */
9336 draw_window_fringes (w
)
9339 struct glyph_row
*row
;
9340 int yb
= window_text_bottom_y (w
);
9341 int nrows
= w
->current_matrix
->nrows
;
9344 if (w
->pseudo_window_p
)
9347 for (y
= 0, rn
= 0, row
= w
->current_matrix
->rows
;
9348 y
< yb
&& rn
< nrows
;
9349 y
+= row
->height
, ++row
, ++rn
)
9351 if (!row
->redraw_fringe_bitmaps_p
)
9353 draw_row_fringe_bitmaps (w
, row
);
9354 row
->redraw_fringe_bitmaps_p
= 0;
9359 /* Compute actual fringe widths for frame F.
9361 If REDRAW is 1, redraw F if the fringe settings was actually
9362 modified and F is visible.
9364 Since the combined left and right fringe must occupy an integral
9365 number of columns, we may need to add some pixels to each fringe.
9366 Typically, we add an equal amount (+/- 1 pixel) to each fringe,
9367 but a negative width value is taken literally (after negating it).
9369 We never make the fringes narrower than specified. It is planned
9370 to make fringe bitmaps customizable and expandable, and at that
9371 time, the user will typically specify the minimum number of pixels
9372 needed for his bitmaps, so we shouldn't select anything less than
9377 compute_fringe_widths (f
, redraw
)
9381 int o_left
= FRAME_LEFT_FRINGE_WIDTH (f
);
9382 int o_right
= FRAME_RIGHT_FRINGE_WIDTH (f
);
9383 int o_cols
= FRAME_FRINGE_COLS (f
);
9385 Lisp_Object left_fringe
= Fassq (Qleft_fringe
, f
->param_alist
);
9386 Lisp_Object right_fringe
= Fassq (Qright_fringe
, f
->param_alist
);
9387 int left_fringe_width
, right_fringe_width
;
9389 if (!NILP (left_fringe
))
9390 left_fringe
= Fcdr (left_fringe
);
9391 if (!NILP (right_fringe
))
9392 right_fringe
= Fcdr (right_fringe
);
9394 left_fringe_width
= ((NILP (left_fringe
) || !INTEGERP (left_fringe
)) ? 8 :
9395 XINT (left_fringe
));
9396 right_fringe_width
= ((NILP (right_fringe
) || !INTEGERP (right_fringe
)) ? 8 :
9397 XINT (right_fringe
));
9399 if (left_fringe_width
|| right_fringe_width
)
9401 int left_wid
= left_fringe_width
>= 0 ? left_fringe_width
: -left_fringe_width
;
9402 int right_wid
= right_fringe_width
>= 0 ? right_fringe_width
: -right_fringe_width
;
9403 int conf_wid
= left_wid
+ right_wid
;
9404 int font_wid
= FRAME_COLUMN_WIDTH (f
);
9405 int cols
= (left_wid
+ right_wid
+ font_wid
-1) / font_wid
;
9406 int real_wid
= cols
* font_wid
;
9407 if (left_wid
&& right_wid
)
9409 if (left_fringe_width
< 0)
9411 /* Left fringe width is fixed, adjust right fringe if necessary */
9412 FRAME_LEFT_FRINGE_WIDTH (f
) = left_wid
;
9413 FRAME_RIGHT_FRINGE_WIDTH (f
) = real_wid
- left_wid
;
9415 else if (right_fringe_width
< 0)
9417 /* Right fringe width is fixed, adjust left fringe if necessary */
9418 FRAME_LEFT_FRINGE_WIDTH (f
) = real_wid
- right_wid
;
9419 FRAME_RIGHT_FRINGE_WIDTH (f
) = right_wid
;
9423 /* Adjust both fringes with an equal amount.
9424 Note that we are doing integer arithmetic here, so don't
9425 lose a pixel if the total width is an odd number. */
9426 int fill
= real_wid
- conf_wid
;
9427 FRAME_LEFT_FRINGE_WIDTH (f
) = left_wid
+ fill
/2;
9428 FRAME_RIGHT_FRINGE_WIDTH (f
) = right_wid
+ fill
- fill
/2;
9431 else if (left_fringe_width
)
9433 FRAME_LEFT_FRINGE_WIDTH (f
) = real_wid
;
9434 FRAME_RIGHT_FRINGE_WIDTH (f
) = 0;
9438 FRAME_LEFT_FRINGE_WIDTH (f
) = 0;
9439 FRAME_RIGHT_FRINGE_WIDTH (f
) = real_wid
;
9441 FRAME_FRINGE_COLS (f
) = cols
;
9445 FRAME_LEFT_FRINGE_WIDTH (f
) = 0;
9446 FRAME_RIGHT_FRINGE_WIDTH (f
) = 0;
9447 FRAME_FRINGE_COLS (f
) = 0;
9450 if (redraw
&& FRAME_VISIBLE_P (f
))
9451 if (o_left
!= FRAME_LEFT_FRINGE_WIDTH (f
) ||
9452 o_right
!= FRAME_RIGHT_FRINGE_WIDTH (f
) ||
9453 o_cols
!= FRAME_FRINGE_COLS (f
))
9457 #endif /* HAVE_WINDOW_SYSTEM */
9461 /************************************************************************
9462 Horizontal scrolling
9463 ************************************************************************/
9465 static int hscroll_window_tree
P_ ((Lisp_Object
));
9466 static int hscroll_windows
P_ ((Lisp_Object
));
9468 /* For all leaf windows in the window tree rooted at WINDOW, set their
9469 hscroll value so that PT is (i) visible in the window, and (ii) so
9470 that it is not within a certain margin at the window's left and
9471 right border. Value is non-zero if any window's hscroll has been
9475 hscroll_window_tree (window
)
9478 int hscrolled_p
= 0;
9479 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9480 int hscroll_step_abs
= 0;
9481 double hscroll_step_rel
= 0;
9483 if (hscroll_relative_p
)
9485 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9486 if (hscroll_step_rel
< 0)
9488 hscroll_relative_p
= 0;
9489 hscroll_step_abs
= 0;
9492 else if (INTEGERP (Vhscroll_step
))
9494 hscroll_step_abs
= XINT (Vhscroll_step
);
9495 if (hscroll_step_abs
< 0)
9496 hscroll_step_abs
= 0;
9499 hscroll_step_abs
= 0;
9501 while (WINDOWP (window
))
9503 struct window
*w
= XWINDOW (window
);
9505 if (WINDOWP (w
->hchild
))
9506 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9507 else if (WINDOWP (w
->vchild
))
9508 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9509 else if (w
->cursor
.vpos
>= 0)
9512 int text_area_width
;
9513 struct glyph_row
*current_cursor_row
9514 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9515 struct glyph_row
*desired_cursor_row
9516 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9517 struct glyph_row
*cursor_row
9518 = (desired_cursor_row
->enabled_p
9519 ? desired_cursor_row
9520 : current_cursor_row
);
9522 text_area_width
= window_box_width (w
, TEXT_AREA
);
9524 /* Scroll when cursor is inside this scroll margin. */
9525 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9527 if ((XFASTINT (w
->hscroll
)
9528 && w
->cursor
.x
<= h_margin
)
9529 || (cursor_row
->enabled_p
9530 && cursor_row
->truncated_on_right_p
9531 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9535 struct buffer
*saved_current_buffer
;
9539 /* Find point in a display of infinite width. */
9540 saved_current_buffer
= current_buffer
;
9541 current_buffer
= XBUFFER (w
->buffer
);
9543 if (w
== XWINDOW (selected_window
))
9544 pt
= BUF_PT (current_buffer
);
9547 pt
= marker_position (w
->pointm
);
9548 pt
= max (BEGV
, pt
);
9552 /* Move iterator to pt starting at cursor_row->start in
9553 a line with infinite width. */
9554 init_to_row_start (&it
, w
, cursor_row
);
9555 it
.last_visible_x
= INFINITY
;
9556 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9557 current_buffer
= saved_current_buffer
;
9559 /* Position cursor in window. */
9560 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9561 hscroll
= max (0, it
.current_x
- text_area_width
/ 2)
9562 / FRAME_COLUMN_WIDTH (it
.f
);
9563 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9565 if (hscroll_relative_p
)
9566 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9569 wanted_x
= text_area_width
9570 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9573 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9577 if (hscroll_relative_p
)
9578 wanted_x
= text_area_width
* hscroll_step_rel
9581 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9584 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9586 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9588 /* Don't call Fset_window_hscroll if value hasn't
9589 changed because it will prevent redisplay
9591 if (XFASTINT (w
->hscroll
) != hscroll
)
9593 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9594 w
->hscroll
= make_number (hscroll
);
9603 /* Value is non-zero if hscroll of any leaf window has been changed. */
9608 /* Set hscroll so that cursor is visible and not inside horizontal
9609 scroll margins for all windows in the tree rooted at WINDOW. See
9610 also hscroll_window_tree above. Value is non-zero if any window's
9611 hscroll has been changed. If it has, desired matrices on the frame
9612 of WINDOW are cleared. */
9615 hscroll_windows (window
)
9620 if (automatic_hscrolling_p
)
9622 hscrolled_p
= hscroll_window_tree (window
);
9624 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9633 /************************************************************************
9635 ************************************************************************/
9637 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9638 to a non-zero value. This is sometimes handy to have in a debugger
9643 /* First and last unchanged row for try_window_id. */
9645 int debug_first_unchanged_at_end_vpos
;
9646 int debug_last_unchanged_at_beg_vpos
;
9648 /* Delta vpos and y. */
9650 int debug_dvpos
, debug_dy
;
9652 /* Delta in characters and bytes for try_window_id. */
9654 int debug_delta
, debug_delta_bytes
;
9656 /* Values of window_end_pos and window_end_vpos at the end of
9659 EMACS_INT debug_end_pos
, debug_end_vpos
;
9661 /* Append a string to W->desired_matrix->method. FMT is a printf
9662 format string. A1...A9 are a supplement for a variable-length
9663 argument list. If trace_redisplay_p is non-zero also printf the
9664 resulting string to stderr. */
9667 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9670 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9673 char *method
= w
->desired_matrix
->method
;
9674 int len
= strlen (method
);
9675 int size
= sizeof w
->desired_matrix
->method
;
9676 int remaining
= size
- len
- 1;
9678 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9679 if (len
&& remaining
)
9685 strncpy (method
+ len
, buffer
, remaining
);
9687 if (trace_redisplay_p
)
9688 fprintf (stderr
, "%p (%s): %s\n",
9690 ((BUFFERP (w
->buffer
)
9691 && STRINGP (XBUFFER (w
->buffer
)->name
))
9692 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9697 #endif /* GLYPH_DEBUG */
9700 /* Value is non-zero if all changes in window W, which displays
9701 current_buffer, are in the text between START and END. START is a
9702 buffer position, END is given as a distance from Z. Used in
9703 redisplay_internal for display optimization. */
9706 text_outside_line_unchanged_p (w
, start
, end
)
9710 int unchanged_p
= 1;
9712 /* If text or overlays have changed, see where. */
9713 if (XFASTINT (w
->last_modified
) < MODIFF
9714 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9716 /* Gap in the line? */
9717 if (GPT
< start
|| Z
- GPT
< end
)
9720 /* Changes start in front of the line, or end after it? */
9722 && (BEG_UNCHANGED
< start
- 1
9723 || END_UNCHANGED
< end
))
9726 /* If selective display, can't optimize if changes start at the
9727 beginning of the line. */
9729 && INTEGERP (current_buffer
->selective_display
)
9730 && XINT (current_buffer
->selective_display
) > 0
9731 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9734 /* If there are overlays at the start or end of the line, these
9735 may have overlay strings with newlines in them. A change at
9736 START, for instance, may actually concern the display of such
9737 overlay strings as well, and they are displayed on different
9738 lines. So, quickly rule out this case. (For the future, it
9739 might be desirable to implement something more telling than
9740 just BEG/END_UNCHANGED.) */
9743 if (BEG
+ BEG_UNCHANGED
== start
9744 && overlay_touches_p (start
))
9746 if (END_UNCHANGED
== end
9747 && overlay_touches_p (Z
- end
))
9756 /* Do a frame update, taking possible shortcuts into account. This is
9757 the main external entry point for redisplay.
9759 If the last redisplay displayed an echo area message and that message
9760 is no longer requested, we clear the echo area or bring back the
9761 mini-buffer if that is in use. */
9766 redisplay_internal (0);
9770 /* Return 1 if point moved out of or into a composition. Otherwise
9771 return 0. PREV_BUF and PREV_PT are the last point buffer and
9772 position. BUF and PT are the current point buffer and position. */
9775 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
9776 struct buffer
*prev_buf
, *buf
;
9783 XSETBUFFER (buffer
, buf
);
9784 /* Check a composition at the last point if point moved within the
9786 if (prev_buf
== buf
)
9789 /* Point didn't move. */
9792 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
9793 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
9794 && COMPOSITION_VALID_P (start
, end
, prop
)
9795 && start
< prev_pt
&& end
> prev_pt
)
9796 /* The last point was within the composition. Return 1 iff
9797 point moved out of the composition. */
9798 return (pt
<= start
|| pt
>= end
);
9801 /* Check a composition at the current point. */
9802 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
9803 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
9804 && COMPOSITION_VALID_P (start
, end
, prop
)
9805 && start
< pt
&& end
> pt
);
9809 /* Reconsider the setting of B->clip_changed which is displayed
9813 reconsider_clip_changes (w
, b
)
9818 && !NILP (w
->window_end_valid
)
9819 && w
->current_matrix
->buffer
== b
9820 && w
->current_matrix
->zv
== BUF_ZV (b
)
9821 && w
->current_matrix
->begv
== BUF_BEGV (b
))
9822 b
->clip_changed
= 0;
9824 /* If display wasn't paused, and W is not a tool bar window, see if
9825 point has been moved into or out of a composition. In that case,
9826 we set b->clip_changed to 1 to force updating the screen. If
9827 b->clip_changed has already been set to 1, we can skip this
9829 if (!b
->clip_changed
9830 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
9834 if (w
== XWINDOW (selected_window
))
9835 pt
= BUF_PT (current_buffer
);
9837 pt
= marker_position (w
->pointm
);
9839 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
9840 || pt
!= XINT (w
->last_point
))
9841 && check_point_in_composition (w
->current_matrix
->buffer
,
9842 XINT (w
->last_point
),
9843 XBUFFER (w
->buffer
), pt
))
9844 b
->clip_changed
= 1;
9849 /* Select FRAME to forward the values of frame-local variables into C
9850 variables so that the redisplay routines can access those values
9854 select_frame_for_redisplay (frame
)
9857 Lisp_Object tail
, sym
, val
;
9858 Lisp_Object old
= selected_frame
;
9860 selected_frame
= frame
;
9862 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9863 if (CONSP (XCAR (tail
))
9864 && (sym
= XCAR (XCAR (tail
)),
9866 && (sym
= indirect_variable (sym
),
9867 val
= SYMBOL_VALUE (sym
),
9868 (BUFFER_LOCAL_VALUEP (val
)
9869 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9870 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9871 Fsymbol_value (sym
);
9873 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9874 if (CONSP (XCAR (tail
))
9875 && (sym
= XCAR (XCAR (tail
)),
9877 && (sym
= indirect_variable (sym
),
9878 val
= SYMBOL_VALUE (sym
),
9879 (BUFFER_LOCAL_VALUEP (val
)
9880 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9881 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9882 Fsymbol_value (sym
);
9886 #define STOP_POLLING \
9887 do { if (! polling_stopped_here) stop_polling (); \
9888 polling_stopped_here = 1; } while (0)
9890 #define RESUME_POLLING \
9891 do { if (polling_stopped_here) start_polling (); \
9892 polling_stopped_here = 0; } while (0)
9895 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
9896 response to any user action; therefore, we should preserve the echo
9897 area. (Actually, our caller does that job.) Perhaps in the future
9898 avoid recentering windows if it is not necessary; currently that
9899 causes some problems. */
9902 redisplay_internal (preserve_echo_area
)
9903 int preserve_echo_area
;
9905 struct window
*w
= XWINDOW (selected_window
);
9906 struct frame
*f
= XFRAME (w
->frame
);
9908 int must_finish
= 0;
9909 struct text_pos tlbufpos
, tlendpos
;
9910 int number_of_visible_frames
;
9912 struct frame
*sf
= SELECTED_FRAME ();
9913 int polling_stopped_here
= 0;
9915 /* Non-zero means redisplay has to consider all windows on all
9916 frames. Zero means, only selected_window is considered. */
9917 int consider_all_windows_p
;
9919 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
9921 /* No redisplay if running in batch mode or frame is not yet fully
9922 initialized, or redisplay is explicitly turned off by setting
9923 Vinhibit_redisplay. */
9925 || !NILP (Vinhibit_redisplay
)
9926 || !f
->glyphs_initialized_p
)
9929 /* The flag redisplay_performed_directly_p is set by
9930 direct_output_for_insert when it already did the whole screen
9931 update necessary. */
9932 if (redisplay_performed_directly_p
)
9934 redisplay_performed_directly_p
= 0;
9935 if (!hscroll_windows (selected_window
))
9939 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
9940 if (popup_activated ())
9944 /* I don't think this happens but let's be paranoid. */
9948 /* Record a function that resets redisplaying_p to its old value
9949 when we leave this function. */
9950 count
= SPECPDL_INDEX ();
9951 record_unwind_protect (unwind_redisplay
,
9952 Fcons (make_number (redisplaying_p
), selected_frame
));
9954 specbind (Qinhibit_free_realized_faces
, Qnil
);
9958 reconsider_clip_changes (w
, current_buffer
);
9960 /* If new fonts have been loaded that make a glyph matrix adjustment
9961 necessary, do it. */
9962 if (fonts_changed_p
)
9964 adjust_glyphs (NULL
);
9965 ++windows_or_buffers_changed
;
9966 fonts_changed_p
= 0;
9969 /* If face_change_count is non-zero, init_iterator will free all
9970 realized faces, which includes the faces referenced from current
9971 matrices. So, we can't reuse current matrices in this case. */
9972 if (face_change_count
)
9973 ++windows_or_buffers_changed
;
9975 if (FRAME_TERMCAP_P (sf
)
9976 && FRAME_TTY (sf
)->previous_terminal_frame
!= sf
)
9978 /* Since frames on a single ASCII terminal share the same
9979 display area, displaying a different frame means redisplay
9981 windows_or_buffers_changed
++;
9982 SET_FRAME_GARBAGED (sf
);
9983 FRAME_TTY (sf
)->previous_terminal_frame
= sf
;
9986 /* Set the visible flags for all frames. Do this before checking
9987 for resized or garbaged frames; they want to know if their frames
9988 are visible. See the comment in frame.h for
9989 FRAME_SAMPLE_VISIBILITY. */
9991 Lisp_Object tail
, frame
;
9993 number_of_visible_frames
= 0;
9995 FOR_EACH_FRAME (tail
, frame
)
9997 struct frame
*f
= XFRAME (frame
);
9999 FRAME_SAMPLE_VISIBILITY (f
);
10000 if (FRAME_VISIBLE_P (f
))
10001 ++number_of_visible_frames
;
10002 clear_desired_matrices (f
);
10007 /* Notice any pending interrupt request to change frame size. */
10008 do_pending_window_change (1);
10010 /* Clear frames marked as garbaged. */
10011 if (frame_garbaged
)
10012 clear_garbaged_frames ();
10014 /* Build menubar and tool-bar items. */
10015 prepare_menu_bars ();
10017 if (windows_or_buffers_changed
)
10018 update_mode_lines
++;
10020 /* Detect case that we need to write or remove a star in the mode line. */
10021 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10023 w
->update_mode_line
= Qt
;
10024 if (buffer_shared
> 1)
10025 update_mode_lines
++;
10028 /* If %c is in the mode line, update it if needed. */
10029 if (!NILP (w
->column_number_displayed
)
10030 /* This alternative quickly identifies a common case
10031 where no change is needed. */
10032 && !(PT
== XFASTINT (w
->last_point
)
10033 && XFASTINT (w
->last_modified
) >= MODIFF
10034 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10035 && (XFASTINT (w
->column_number_displayed
)
10036 != (int) current_column ())) /* iftc */
10037 w
->update_mode_line
= Qt
;
10039 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10041 /* The variable buffer_shared is set in redisplay_window and
10042 indicates that we redisplay a buffer in different windows. See
10044 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10045 || cursor_type_changed
);
10047 /* If specs for an arrow have changed, do thorough redisplay
10048 to ensure we remove any arrow that should no longer exist. */
10049 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
10050 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
10051 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10053 /* Normally the message* functions will have already displayed and
10054 updated the echo area, but the frame may have been trashed, or
10055 the update may have been preempted, so display the echo area
10056 again here. Checking message_cleared_p captures the case that
10057 the echo area should be cleared. */
10058 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10059 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10060 || (message_cleared_p
10061 && minibuf_level
== 0
10062 /* If the mini-window is currently selected, this means the
10063 echo-area doesn't show through. */
10064 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10066 int window_height_changed_p
= echo_area_display (0);
10069 /* If we don't display the current message, don't clear the
10070 message_cleared_p flag, because, if we did, we wouldn't clear
10071 the echo area in the next redisplay which doesn't preserve
10073 if (!display_last_displayed_message_p
)
10074 message_cleared_p
= 0;
10076 if (fonts_changed_p
)
10078 else if (window_height_changed_p
)
10080 consider_all_windows_p
= 1;
10081 ++update_mode_lines
;
10082 ++windows_or_buffers_changed
;
10084 /* If window configuration was changed, frames may have been
10085 marked garbaged. Clear them or we will experience
10086 surprises wrt scrolling. */
10087 if (frame_garbaged
)
10088 clear_garbaged_frames ();
10091 else if (EQ (selected_window
, minibuf_window
)
10092 && (current_buffer
->clip_changed
10093 || XFASTINT (w
->last_modified
) < MODIFF
10094 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10095 && resize_mini_window (w
, 0))
10097 /* Resized active mini-window to fit the size of what it is
10098 showing if its contents might have changed. */
10100 consider_all_windows_p
= 1;
10101 ++windows_or_buffers_changed
;
10102 ++update_mode_lines
;
10104 /* If window configuration was changed, frames may have been
10105 marked garbaged. Clear them or we will experience
10106 surprises wrt scrolling. */
10107 if (frame_garbaged
)
10108 clear_garbaged_frames ();
10112 /* If showing the region, and mark has changed, we must redisplay
10113 the whole window. The assignment to this_line_start_pos prevents
10114 the optimization directly below this if-statement. */
10115 if (((!NILP (Vtransient_mark_mode
)
10116 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10117 != !NILP (w
->region_showing
))
10118 || (!NILP (w
->region_showing
)
10119 && !EQ (w
->region_showing
,
10120 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
10121 CHARPOS (this_line_start_pos
) = 0;
10123 /* Optimize the case that only the line containing the cursor in the
10124 selected window has changed. Variables starting with this_ are
10125 set in display_line and record information about the line
10126 containing the cursor. */
10127 tlbufpos
= this_line_start_pos
;
10128 tlendpos
= this_line_end_pos
;
10129 if (!consider_all_windows_p
10130 && CHARPOS (tlbufpos
) > 0
10131 && NILP (w
->update_mode_line
)
10132 && !current_buffer
->clip_changed
10133 && !current_buffer
->prevent_redisplay_optimizations_p
10134 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
10135 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
10136 /* Make sure recorded data applies to current buffer, etc. */
10137 && this_line_buffer
== current_buffer
10138 && current_buffer
== XBUFFER (w
->buffer
)
10139 && NILP (w
->force_start
)
10140 && NILP (w
->optional_new_start
)
10141 /* Point must be on the line that we have info recorded about. */
10142 && PT
>= CHARPOS (tlbufpos
)
10143 && PT
<= Z
- CHARPOS (tlendpos
)
10144 /* All text outside that line, including its final newline,
10145 must be unchanged */
10146 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
10147 CHARPOS (tlendpos
)))
10149 if (CHARPOS (tlbufpos
) > BEGV
10150 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
10151 && (CHARPOS (tlbufpos
) == ZV
10152 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
10153 /* Former continuation line has disappeared by becoming empty */
10155 else if (XFASTINT (w
->last_modified
) < MODIFF
10156 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
10157 || MINI_WINDOW_P (w
))
10159 /* We have to handle the case of continuation around a
10160 wide-column character (See the comment in indent.c around
10163 For instance, in the following case:
10165 -------- Insert --------
10166 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
10167 J_I_ ==> J_I_ `^^' are cursors.
10171 As we have to redraw the line above, we should goto cancel. */
10174 int line_height_before
= this_line_pixel_height
;
10176 /* Note that start_display will handle the case that the
10177 line starting at tlbufpos is a continuation lines. */
10178 start_display (&it
, w
, tlbufpos
);
10180 /* Implementation note: It this still necessary? */
10181 if (it
.current_x
!= this_line_start_x
)
10184 TRACE ((stderr
, "trying display optimization 1\n"));
10185 w
->cursor
.vpos
= -1;
10186 overlay_arrow_seen
= 0;
10187 it
.vpos
= this_line_vpos
;
10188 it
.current_y
= this_line_y
;
10189 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10190 display_line (&it
);
10192 /* If line contains point, is not continued,
10193 and ends at same distance from eob as before, we win */
10194 if (w
->cursor
.vpos
>= 0
10195 /* Line is not continued, otherwise this_line_start_pos
10196 would have been set to 0 in display_line. */
10197 && CHARPOS (this_line_start_pos
)
10198 /* Line ends as before. */
10199 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10200 /* Line has same height as before. Otherwise other lines
10201 would have to be shifted up or down. */
10202 && this_line_pixel_height
== line_height_before
)
10204 /* If this is not the window's last line, we must adjust
10205 the charstarts of the lines below. */
10206 if (it
.current_y
< it
.last_visible_y
)
10208 struct glyph_row
*row
10209 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10210 int delta
, delta_bytes
;
10212 if (Z
- CHARPOS (tlendpos
) == ZV
)
10214 /* This line ends at end of (accessible part of)
10215 buffer. There is no newline to count. */
10217 - CHARPOS (tlendpos
)
10218 - MATRIX_ROW_START_CHARPOS (row
));
10219 delta_bytes
= (Z_BYTE
10220 - BYTEPOS (tlendpos
)
10221 - MATRIX_ROW_START_BYTEPOS (row
));
10225 /* This line ends in a newline. Must take
10226 account of the newline and the rest of the
10227 text that follows. */
10229 - CHARPOS (tlendpos
)
10230 - MATRIX_ROW_START_CHARPOS (row
));
10231 delta_bytes
= (Z_BYTE
10232 - BYTEPOS (tlendpos
)
10233 - MATRIX_ROW_START_BYTEPOS (row
));
10236 increment_matrix_positions (w
->current_matrix
,
10237 this_line_vpos
+ 1,
10238 w
->current_matrix
->nrows
,
10239 delta
, delta_bytes
);
10242 /* If this row displays text now but previously didn't,
10243 or vice versa, w->window_end_vpos may have to be
10245 if ((it
.glyph_row
- 1)->displays_text_p
)
10247 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10248 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10250 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10251 && this_line_vpos
> 0)
10252 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10253 w
->window_end_valid
= Qnil
;
10255 /* Update hint: No need to try to scroll in update_window. */
10256 w
->desired_matrix
->no_scrolling_p
= 1;
10259 *w
->desired_matrix
->method
= 0;
10260 debug_method_add (w
, "optimization 1");
10262 #ifdef HAVE_WINDOW_SYSTEM
10263 update_window_fringes (w
, 0);
10270 else if (/* Cursor position hasn't changed. */
10271 PT
== XFASTINT (w
->last_point
)
10272 /* Make sure the cursor was last displayed
10273 in this window. Otherwise we have to reposition it. */
10274 && 0 <= w
->cursor
.vpos
10275 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10279 do_pending_window_change (1);
10281 /* We used to always goto end_of_redisplay here, but this
10282 isn't enough if we have a blinking cursor. */
10283 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10284 goto end_of_redisplay
;
10288 /* If highlighting the region, or if the cursor is in the echo area,
10289 then we can't just move the cursor. */
10290 else if (! (!NILP (Vtransient_mark_mode
)
10291 && !NILP (current_buffer
->mark_active
))
10292 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10293 || highlight_nonselected_windows
)
10294 && NILP (w
->region_showing
)
10295 && NILP (Vshow_trailing_whitespace
)
10296 && !cursor_in_echo_area
)
10299 struct glyph_row
*row
;
10301 /* Skip from tlbufpos to PT and see where it is. Note that
10302 PT may be in invisible text. If so, we will end at the
10303 next visible position. */
10304 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10305 NULL
, DEFAULT_FACE_ID
);
10306 it
.current_x
= this_line_start_x
;
10307 it
.current_y
= this_line_y
;
10308 it
.vpos
= this_line_vpos
;
10310 /* The call to move_it_to stops in front of PT, but
10311 moves over before-strings. */
10312 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10314 if (it
.vpos
== this_line_vpos
10315 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10318 xassert (this_line_vpos
== it
.vpos
);
10319 xassert (this_line_y
== it
.current_y
);
10320 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10322 *w
->desired_matrix
->method
= 0;
10323 debug_method_add (w
, "optimization 3");
10332 /* Text changed drastically or point moved off of line. */
10333 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10336 CHARPOS (this_line_start_pos
) = 0;
10337 consider_all_windows_p
|= buffer_shared
> 1;
10338 ++clear_face_cache_count
;
10341 /* Build desired matrices, and update the display. If
10342 consider_all_windows_p is non-zero, do it for all windows on all
10343 frames. Otherwise do it for selected_window, only. */
10345 if (consider_all_windows_p
)
10347 Lisp_Object tail
, frame
;
10348 int i
, n
= 0, size
= 50;
10349 struct frame
**updated
10350 = (struct frame
**) alloca (size
* sizeof *updated
);
10352 /* Clear the face cache eventually. */
10353 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
10355 clear_face_cache (0);
10356 clear_face_cache_count
= 0;
10359 /* Recompute # windows showing selected buffer. This will be
10360 incremented each time such a window is displayed. */
10363 FOR_EACH_FRAME (tail
, frame
)
10365 struct frame
*f
= XFRAME (frame
);
10367 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
10369 if (! EQ (frame
, selected_frame
))
10370 /* Select the frame, for the sake of frame-local
10372 select_frame_for_redisplay (frame
);
10374 #ifdef HAVE_WINDOW_SYSTEM
10375 if (clear_face_cache_count
% 50 == 0
10376 && FRAME_WINDOW_P (f
))
10377 clear_image_cache (f
, 0);
10378 #endif /* HAVE_WINDOW_SYSTEM */
10380 /* Mark all the scroll bars to be removed; we'll redeem
10381 the ones we want when we redisplay their windows. */
10382 if (FRAME_DISPLAY (f
)->condemn_scroll_bars_hook
)
10383 FRAME_DISPLAY (f
)->condemn_scroll_bars_hook (f
);
10385 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10386 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10388 /* Any scroll bars which redisplay_windows should have
10389 nuked should now go away. */
10390 if (FRAME_DISPLAY (f
)->judge_scroll_bars_hook
)
10391 FRAME_DISPLAY (f
)->judge_scroll_bars_hook (f
);
10393 /* If fonts changed, display again. */
10394 /* ??? rms: I suspect it is a mistake to jump all the way
10395 back to retry here. It should just retry this frame. */
10396 if (fonts_changed_p
)
10399 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10401 /* See if we have to hscroll. */
10402 if (hscroll_windows (f
->root_window
))
10405 /* Prevent various kinds of signals during display
10406 update. stdio is not robust about handling
10407 signals, which can cause an apparent I/O
10409 if (interrupt_input
)
10410 unrequest_sigio ();
10413 /* Update the display. */
10414 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10415 pause
|= update_frame (f
, 0, 0);
10416 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10423 int nbytes
= size
* sizeof *updated
;
10424 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
10425 bcopy (updated
, p
, nbytes
);
10436 /* Do the mark_window_display_accurate after all windows have
10437 been redisplayed because this call resets flags in buffers
10438 which are needed for proper redisplay. */
10439 for (i
= 0; i
< n
; ++i
)
10441 struct frame
*f
= updated
[i
];
10442 mark_window_display_accurate (f
->root_window
, 1);
10443 if (FRAME_DISPLAY (f
)->frame_up_to_date_hook
)
10444 FRAME_DISPLAY (f
)->frame_up_to_date_hook (f
);
10448 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10450 Lisp_Object mini_window
;
10451 struct frame
*mini_frame
;
10453 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10454 /* Use list_of_error, not Qerror, so that
10455 we catch only errors and don't run the debugger. */
10456 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10458 redisplay_window_error
);
10460 /* Compare desired and current matrices, perform output. */
10463 /* If fonts changed, display again. */
10464 if (fonts_changed_p
)
10467 /* Prevent various kinds of signals during display update.
10468 stdio is not robust about handling signals,
10469 which can cause an apparent I/O error. */
10470 if (interrupt_input
)
10471 unrequest_sigio ();
10474 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10476 if (hscroll_windows (selected_window
))
10479 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10480 pause
= update_frame (sf
, 0, 0);
10483 /* We may have called echo_area_display at the top of this
10484 function. If the echo area is on another frame, that may
10485 have put text on a frame other than the selected one, so the
10486 above call to update_frame would not have caught it. Catch
10488 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10489 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10491 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10493 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10494 pause
|= update_frame (mini_frame
, 0, 0);
10495 if (!pause
&& hscroll_windows (mini_window
))
10500 /* If display was paused because of pending input, make sure we do a
10501 thorough update the next time. */
10504 /* Prevent the optimization at the beginning of
10505 redisplay_internal that tries a single-line update of the
10506 line containing the cursor in the selected window. */
10507 CHARPOS (this_line_start_pos
) = 0;
10509 /* Let the overlay arrow be updated the next time. */
10510 if (!NILP (last_arrow_position
))
10512 last_arrow_position
= Qt
;
10513 last_arrow_string
= Qt
;
10516 /* If we pause after scrolling, some rows in the current
10517 matrices of some windows are not valid. */
10518 if (!WINDOW_FULL_WIDTH_P (w
)
10519 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10520 update_mode_lines
= 1;
10524 if (!consider_all_windows_p
)
10526 /* This has already been done above if
10527 consider_all_windows_p is set. */
10528 mark_window_display_accurate_1 (w
, 1);
10530 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
10531 last_arrow_string
= Voverlay_arrow_string
;
10533 if (FRAME_DISPLAY (sf
)->frame_up_to_date_hook
!= 0)
10534 FRAME_DISPLAY (sf
)->frame_up_to_date_hook (sf
);
10537 update_mode_lines
= 0;
10538 windows_or_buffers_changed
= 0;
10539 cursor_type_changed
= 0;
10542 /* Start SIGIO interrupts coming again. Having them off during the
10543 code above makes it less likely one will discard output, but not
10544 impossible, since there might be stuff in the system buffer here.
10545 But it is much hairier to try to do anything about that. */
10546 if (interrupt_input
)
10550 /* If a frame has become visible which was not before, redisplay
10551 again, so that we display it. Expose events for such a frame
10552 (which it gets when becoming visible) don't call the parts of
10553 redisplay constructing glyphs, so simply exposing a frame won't
10554 display anything in this case. So, we have to display these
10555 frames here explicitly. */
10558 Lisp_Object tail
, frame
;
10561 FOR_EACH_FRAME (tail
, frame
)
10563 int this_is_visible
= 0;
10565 if (XFRAME (frame
)->visible
)
10566 this_is_visible
= 1;
10567 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10568 if (XFRAME (frame
)->visible
)
10569 this_is_visible
= 1;
10571 if (this_is_visible
)
10575 if (new_count
!= number_of_visible_frames
)
10576 windows_or_buffers_changed
++;
10579 /* Change frame size now if a change is pending. */
10580 do_pending_window_change (1);
10582 /* If we just did a pending size change, or have additional
10583 visible frames, redisplay again. */
10584 if (windows_or_buffers_changed
&& !pause
)
10588 unbind_to (count
, Qnil
);
10593 /* Redisplay, but leave alone any recent echo area message unless
10594 another message has been requested in its place.
10596 This is useful in situations where you need to redisplay but no
10597 user action has occurred, making it inappropriate for the message
10598 area to be cleared. See tracking_off and
10599 wait_reading_process_input for examples of these situations.
10601 FROM_WHERE is an integer saying from where this function was
10602 called. This is useful for debugging. */
10605 redisplay_preserve_echo_area (from_where
)
10608 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10610 if (!NILP (echo_area_buffer
[1]))
10612 /* We have a previously displayed message, but no current
10613 message. Redisplay the previous message. */
10614 display_last_displayed_message_p
= 1;
10615 redisplay_internal (1);
10616 display_last_displayed_message_p
= 0;
10619 redisplay_internal (1);
10623 /* Function registered with record_unwind_protect in
10624 redisplay_internal. Reset redisplaying_p to the value it had
10625 before redisplay_internal was called, and clear
10626 prevent_freeing_realized_faces_p. It also selects the previously
10630 unwind_redisplay (val
)
10633 Lisp_Object old_redisplaying_p
, old_frame
;
10635 old_redisplaying_p
= XCAR (val
);
10636 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10637 old_frame
= XCDR (val
);
10638 if (! EQ (old_frame
, selected_frame
))
10639 select_frame_for_redisplay (old_frame
);
10644 /* Mark the display of window W as accurate or inaccurate. If
10645 ACCURATE_P is non-zero mark display of W as accurate. If
10646 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10647 redisplay_internal is called. */
10650 mark_window_display_accurate_1 (w
, accurate_p
)
10654 if (BUFFERP (w
->buffer
))
10656 struct buffer
*b
= XBUFFER (w
->buffer
);
10659 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
10660 w
->last_overlay_modified
10661 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
10663 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
10667 b
->clip_changed
= 0;
10668 b
->prevent_redisplay_optimizations_p
= 0;
10670 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
10671 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
10672 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
10673 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
10675 w
->current_matrix
->buffer
= b
;
10676 w
->current_matrix
->begv
= BUF_BEGV (b
);
10677 w
->current_matrix
->zv
= BUF_ZV (b
);
10679 w
->last_cursor
= w
->cursor
;
10680 w
->last_cursor_off_p
= w
->cursor_off_p
;
10682 if (w
== XWINDOW (selected_window
))
10683 w
->last_point
= make_number (BUF_PT (b
));
10685 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
10691 w
->window_end_valid
= w
->buffer
;
10692 #if 0 /* This is incorrect with variable-height lines. */
10693 xassert (XINT (w
->window_end_vpos
)
10694 < (WINDOW_TOTAL_LINES (w
)
10695 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
10697 w
->update_mode_line
= Qnil
;
10702 /* Mark the display of windows in the window tree rooted at WINDOW as
10703 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
10704 windows as accurate. If ACCURATE_P is zero, arrange for windows to
10705 be redisplayed the next time redisplay_internal is called. */
10708 mark_window_display_accurate (window
, accurate_p
)
10709 Lisp_Object window
;
10714 for (; !NILP (window
); window
= w
->next
)
10716 w
= XWINDOW (window
);
10717 mark_window_display_accurate_1 (w
, accurate_p
);
10719 if (!NILP (w
->vchild
))
10720 mark_window_display_accurate (w
->vchild
, accurate_p
);
10721 if (!NILP (w
->hchild
))
10722 mark_window_display_accurate (w
->hchild
, accurate_p
);
10727 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
10728 last_arrow_string
= Voverlay_arrow_string
;
10732 /* Force a thorough redisplay the next time by setting
10733 last_arrow_position and last_arrow_string to t, which is
10734 unequal to any useful value of Voverlay_arrow_... */
10735 last_arrow_position
= Qt
;
10736 last_arrow_string
= Qt
;
10741 /* Return value in display table DP (Lisp_Char_Table *) for character
10742 C. Since a display table doesn't have any parent, we don't have to
10743 follow parent. Do not call this function directly but use the
10744 macro DISP_CHAR_VECTOR. */
10747 disp_char_vector (dp
, c
)
10748 struct Lisp_Char_Table
*dp
;
10754 if (SINGLE_BYTE_CHAR_P (c
))
10755 return (dp
->contents
[c
]);
10757 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
10760 else if (code
[2] < 32)
10763 /* Here, the possible range of code[0] (== charset ID) is
10764 128..max_charset. Since the top level char table contains data
10765 for multibyte characters after 256th element, we must increment
10766 code[0] by 128 to get a correct index. */
10768 code
[3] = -1; /* anchor */
10770 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
10772 val
= dp
->contents
[code
[i
]];
10773 if (!SUB_CHAR_TABLE_P (val
))
10774 return (NILP (val
) ? dp
->defalt
: val
);
10777 /* Here, val is a sub char table. We return the default value of
10779 return (dp
->defalt
);
10784 /***********************************************************************
10786 ***********************************************************************/
10788 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
10791 redisplay_windows (window
)
10792 Lisp_Object window
;
10794 while (!NILP (window
))
10796 struct window
*w
= XWINDOW (window
);
10798 if (!NILP (w
->hchild
))
10799 redisplay_windows (w
->hchild
);
10800 else if (!NILP (w
->vchild
))
10801 redisplay_windows (w
->vchild
);
10804 displayed_buffer
= XBUFFER (w
->buffer
);
10805 /* Use list_of_error, not Qerror, so that
10806 we catch only errors and don't run the debugger. */
10807 internal_condition_case_1 (redisplay_window_0
, window
,
10809 redisplay_window_error
);
10817 redisplay_window_error ()
10819 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
10824 redisplay_window_0 (window
)
10825 Lisp_Object window
;
10827 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10828 redisplay_window (window
, 0);
10833 redisplay_window_1 (window
)
10834 Lisp_Object window
;
10836 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10837 redisplay_window (window
, 1);
10842 /* Increment GLYPH until it reaches END or CONDITION fails while
10843 adding (GLYPH)->pixel_width to X. */
10845 #define SKIP_GLYPHS(glyph, end, x, condition) \
10848 (x) += (glyph)->pixel_width; \
10851 while ((glyph) < (end) && (condition))
10854 /* Set cursor position of W. PT is assumed to be displayed in ROW.
10855 DELTA is the number of bytes by which positions recorded in ROW
10856 differ from current buffer positions. */
10859 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
10861 struct glyph_row
*row
;
10862 struct glyph_matrix
*matrix
;
10863 int delta
, delta_bytes
, dy
, dvpos
;
10865 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
10866 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
10867 /* The first glyph that starts a sequence of glyphs from string. */
10868 struct glyph
*string_start
;
10869 /* The X coordinate of string_start. */
10870 int string_start_x
;
10871 /* The last known character position. */
10872 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
10873 /* The last known character position before string_start. */
10874 int string_before_pos
;
10876 int pt_old
= PT
- delta
;
10878 /* Skip over glyphs not having an object at the start of the row.
10879 These are special glyphs like truncation marks on terminal
10881 if (row
->displays_text_p
)
10883 && INTEGERP (glyph
->object
)
10884 && glyph
->charpos
< 0)
10886 x
+= glyph
->pixel_width
;
10890 string_start
= NULL
;
10892 && !INTEGERP (glyph
->object
)
10893 && (!BUFFERP (glyph
->object
)
10894 || (last_pos
= glyph
->charpos
) < pt_old
))
10896 if (! STRINGP (glyph
->object
))
10898 string_start
= NULL
;
10899 x
+= glyph
->pixel_width
;
10904 string_before_pos
= last_pos
;
10905 string_start
= glyph
;
10906 string_start_x
= x
;
10907 /* Skip all glyphs from string. */
10908 SKIP_GLYPHS (glyph
, end
, x
, STRINGP (glyph
->object
));
10913 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
10915 /* We may have skipped over point because the previous glyphs
10916 are from string. As there's no easy way to know the
10917 character position of the current glyph, find the correct
10918 glyph on point by scanning from string_start again. */
10920 Lisp_Object string
;
10923 limit
= make_number (pt_old
+ 1);
10925 glyph
= string_start
;
10926 x
= string_start_x
;
10927 string
= glyph
->object
;
10928 pos
= string_buffer_position (w
, string
, string_before_pos
);
10929 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
10930 because we always put cursor after overlay strings. */
10931 while (pos
== 0 && glyph
< end
)
10933 string
= glyph
->object
;
10934 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10936 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
10939 while (glyph
< end
)
10941 pos
= XINT (Fnext_single_char_property_change
10942 (make_number (pos
), Qdisplay
, Qnil
, limit
));
10945 /* Skip glyphs from the same string. */
10946 string
= glyph
->object
;
10947 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10948 /* Skip glyphs from an overlay. */
10950 && ! string_buffer_position (w
, glyph
->object
, pos
))
10952 string
= glyph
->object
;
10953 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10958 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
10960 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
10961 w
->cursor
.y
= row
->y
+ dy
;
10963 if (w
== XWINDOW (selected_window
))
10965 if (!row
->continued_p
10966 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
10969 this_line_buffer
= XBUFFER (w
->buffer
);
10971 CHARPOS (this_line_start_pos
)
10972 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
10973 BYTEPOS (this_line_start_pos
)
10974 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
10976 CHARPOS (this_line_end_pos
)
10977 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
10978 BYTEPOS (this_line_end_pos
)
10979 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
10981 this_line_y
= w
->cursor
.y
;
10982 this_line_pixel_height
= row
->height
;
10983 this_line_vpos
= w
->cursor
.vpos
;
10984 this_line_start_x
= row
->x
;
10987 CHARPOS (this_line_start_pos
) = 0;
10992 /* Run window scroll functions, if any, for WINDOW with new window
10993 start STARTP. Sets the window start of WINDOW to that position.
10995 We assume that the window's buffer is really current. */
10997 static INLINE
struct text_pos
10998 run_window_scroll_functions (window
, startp
)
10999 Lisp_Object window
;
11000 struct text_pos startp
;
11002 struct window
*w
= XWINDOW (window
);
11003 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
11005 if (current_buffer
!= XBUFFER (w
->buffer
))
11008 if (!NILP (Vwindow_scroll_functions
))
11010 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
11011 make_number (CHARPOS (startp
)));
11012 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11013 /* In case the hook functions switch buffers. */
11014 if (current_buffer
!= XBUFFER (w
->buffer
))
11015 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11022 /* Make sure the line containing the cursor is fully visible.
11023 A value of 1 means there is nothing to be done.
11024 (Either the line is fully visible, or it cannot be made so,
11025 or we cannot tell.)
11026 A value of 0 means the caller should do scrolling
11027 as if point had gone off the screen. */
11030 make_cursor_line_fully_visible (w
)
11033 struct glyph_matrix
*matrix
;
11034 struct glyph_row
*row
;
11037 /* It's not always possible to find the cursor, e.g, when a window
11038 is full of overlay strings. Don't do anything in that case. */
11039 if (w
->cursor
.vpos
< 0)
11042 matrix
= w
->desired_matrix
;
11043 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
11045 /* If the cursor row is not partially visible, there's nothing to do. */
11046 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
11049 /* If the row the cursor is in is taller than the window's height,
11050 it's not clear what to do, so do nothing. */
11051 window_height
= window_box_height (w
);
11052 if (row
->height
>= window_height
)
11058 /* This code used to try to scroll the window just enough to make
11059 the line visible. It returned 0 to say that the caller should
11060 allocate larger glyph matrices. */
11062 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
11064 int dy
= row
->height
- row
->visible_height
;
11067 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11069 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
11071 int dy
= - (row
->height
- row
->visible_height
);
11074 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11077 /* When we change the cursor y-position of the selected window,
11078 change this_line_y as well so that the display optimization for
11079 the cursor line of the selected window in redisplay_internal uses
11080 the correct y-position. */
11081 if (w
== XWINDOW (selected_window
))
11082 this_line_y
= w
->cursor
.y
;
11084 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
11085 redisplay with larger matrices. */
11086 if (matrix
->nrows
< required_matrix_height (w
))
11088 fonts_changed_p
= 1;
11097 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
11098 non-zero means only WINDOW is redisplayed in redisplay_internal.
11099 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
11100 in redisplay_window to bring a partially visible line into view in
11101 the case that only the cursor has moved.
11103 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
11104 last screen line's vertical height extends past the end of the screen.
11108 1 if scrolling succeeded
11110 0 if scrolling didn't find point.
11112 -1 if new fonts have been loaded so that we must interrupt
11113 redisplay, adjust glyph matrices, and try again. */
11119 SCROLLING_NEED_LARGER_MATRICES
11123 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
11124 scroll_step
, temp_scroll_step
, last_line_misfit
)
11125 Lisp_Object window
;
11126 int just_this_one_p
;
11127 EMACS_INT scroll_conservatively
, scroll_step
;
11128 int temp_scroll_step
;
11129 int last_line_misfit
;
11131 struct window
*w
= XWINDOW (window
);
11132 struct frame
*f
= XFRAME (w
->frame
);
11133 struct text_pos scroll_margin_pos
;
11134 struct text_pos pos
;
11135 struct text_pos startp
;
11137 Lisp_Object window_end
;
11138 int this_scroll_margin
;
11142 int amount_to_scroll
= 0;
11143 Lisp_Object aggressive
;
11145 int end_scroll_margin
;
11148 debug_method_add (w
, "try_scrolling");
11151 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11153 /* Compute scroll margin height in pixels. We scroll when point is
11154 within this distance from the top or bottom of the window. */
11155 if (scroll_margin
> 0)
11157 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11158 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11161 this_scroll_margin
= 0;
11163 /* Compute how much we should try to scroll maximally to bring point
11165 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11166 scroll_max
= max (scroll_step
,
11167 max (scroll_conservatively
, temp_scroll_step
));
11168 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11169 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11170 /* We're trying to scroll because of aggressive scrolling
11171 but no scroll_step is set. Choose an arbitrary one. Maybe
11172 there should be a variable for this. */
11176 scroll_max
*= FRAME_LINE_HEIGHT (f
);
11178 /* Decide whether we have to scroll down. Start at the window end
11179 and move this_scroll_margin up to find the position of the scroll
11181 window_end
= Fwindow_end (window
, Qt
);
11185 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
11186 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
11188 end_scroll_margin
= this_scroll_margin
+ !!last_line_misfit
;
11189 if (end_scroll_margin
)
11191 start_display (&it
, w
, scroll_margin_pos
);
11192 move_it_vertically (&it
, - end_scroll_margin
);
11193 scroll_margin_pos
= it
.current
.pos
;
11196 if (PT
>= CHARPOS (scroll_margin_pos
))
11200 /* Point is in the scroll margin at the bottom of the window, or
11201 below. Compute a new window start that makes point visible. */
11203 /* Compute the distance from the scroll margin to PT.
11204 Give up if the distance is greater than scroll_max. */
11205 start_display (&it
, w
, scroll_margin_pos
);
11207 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11208 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11210 /* To make point visible, we have to move the window start
11211 down so that the line the cursor is in is visible, which
11212 means we have to add in the height of the cursor line. */
11213 dy
= line_bottom_y (&it
) - y0
;
11215 if (dy
> scroll_max
)
11216 return SCROLLING_FAILED
;
11218 /* Move the window start down. If scrolling conservatively,
11219 move it just enough down to make point visible. If
11220 scroll_step is set, move it down by scroll_step. */
11221 start_display (&it
, w
, startp
);
11223 if (scroll_conservatively
)
11224 /* Set AMOUNT_TO_SCROLL to at least one line,
11225 and at most scroll_conservatively lines. */
11227 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11228 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11229 else if (scroll_step
|| temp_scroll_step
)
11230 amount_to_scroll
= scroll_max
;
11233 aggressive
= current_buffer
->scroll_up_aggressively
;
11234 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11235 if (NUMBERP (aggressive
))
11236 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
11239 if (amount_to_scroll
<= 0)
11240 return SCROLLING_FAILED
;
11242 /* If moving by amount_to_scroll leaves STARTP unchanged,
11243 move it down one screen line. */
11245 move_it_vertically (&it
, amount_to_scroll
);
11246 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
11247 move_it_by_lines (&it
, 1, 1);
11248 startp
= it
.current
.pos
;
11252 /* See if point is inside the scroll margin at the top of the
11254 scroll_margin_pos
= startp
;
11255 if (this_scroll_margin
)
11257 start_display (&it
, w
, startp
);
11258 move_it_vertically (&it
, this_scroll_margin
);
11259 scroll_margin_pos
= it
.current
.pos
;
11262 if (PT
< CHARPOS (scroll_margin_pos
))
11264 /* Point is in the scroll margin at the top of the window or
11265 above what is displayed in the window. */
11268 /* Compute the vertical distance from PT to the scroll
11269 margin position. Give up if distance is greater than
11271 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
11272 start_display (&it
, w
, pos
);
11274 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11275 it
.last_visible_y
, -1,
11276 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11277 dy
= it
.current_y
- y0
;
11278 if (dy
> scroll_max
)
11279 return SCROLLING_FAILED
;
11281 /* Compute new window start. */
11282 start_display (&it
, w
, startp
);
11284 if (scroll_conservatively
)
11286 max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11287 else if (scroll_step
|| temp_scroll_step
)
11288 amount_to_scroll
= scroll_max
;
11291 aggressive
= current_buffer
->scroll_down_aggressively
;
11292 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11293 if (NUMBERP (aggressive
))
11294 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
11297 if (amount_to_scroll
<= 0)
11298 return SCROLLING_FAILED
;
11300 move_it_vertically (&it
, - amount_to_scroll
);
11301 startp
= it
.current
.pos
;
11305 /* Run window scroll functions. */
11306 startp
= run_window_scroll_functions (window
, startp
);
11308 /* Display the window. Give up if new fonts are loaded, or if point
11310 if (!try_window (window
, startp
))
11311 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11312 else if (w
->cursor
.vpos
< 0)
11314 clear_glyph_matrix (w
->desired_matrix
);
11315 rc
= SCROLLING_FAILED
;
11319 /* Maybe forget recorded base line for line number display. */
11320 if (!just_this_one_p
11321 || current_buffer
->clip_changed
11322 || BEG_UNCHANGED
< CHARPOS (startp
))
11323 w
->base_line_number
= Qnil
;
11325 /* If cursor ends up on a partially visible line,
11326 treat that as being off the bottom of the screen. */
11327 if (! make_cursor_line_fully_visible (w
))
11329 clear_glyph_matrix (w
->desired_matrix
);
11330 last_line_misfit
= 1;
11333 rc
= SCROLLING_SUCCESS
;
11340 /* Compute a suitable window start for window W if display of W starts
11341 on a continuation line. Value is non-zero if a new window start
11344 The new window start will be computed, based on W's width, starting
11345 from the start of the continued line. It is the start of the
11346 screen line with the minimum distance from the old start W->start. */
11349 compute_window_start_on_continuation_line (w
)
11352 struct text_pos pos
, start_pos
;
11353 int window_start_changed_p
= 0;
11355 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
11357 /* If window start is on a continuation line... Window start may be
11358 < BEGV in case there's invisible text at the start of the
11359 buffer (M-x rmail, for example). */
11360 if (CHARPOS (start_pos
) > BEGV
11361 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
11364 struct glyph_row
*row
;
11366 /* Handle the case that the window start is out of range. */
11367 if (CHARPOS (start_pos
) < BEGV
)
11368 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
11369 else if (CHARPOS (start_pos
) > ZV
)
11370 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
11372 /* Find the start of the continued line. This should be fast
11373 because scan_buffer is fast (newline cache). */
11374 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
11375 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
11376 row
, DEFAULT_FACE_ID
);
11377 reseat_at_previous_visible_line_start (&it
);
11379 /* If the line start is "too far" away from the window start,
11380 say it takes too much time to compute a new window start. */
11381 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
11382 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
11384 int min_distance
, distance
;
11386 /* Move forward by display lines to find the new window
11387 start. If window width was enlarged, the new start can
11388 be expected to be > the old start. If window width was
11389 decreased, the new window start will be < the old start.
11390 So, we're looking for the display line start with the
11391 minimum distance from the old window start. */
11392 pos
= it
.current
.pos
;
11393 min_distance
= INFINITY
;
11394 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
11395 distance
< min_distance
)
11397 min_distance
= distance
;
11398 pos
= it
.current
.pos
;
11399 move_it_by_lines (&it
, 1, 0);
11402 /* Set the window start there. */
11403 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
11404 window_start_changed_p
= 1;
11408 return window_start_changed_p
;
11412 /* Try cursor movement in case text has not changed in window WINDOW,
11413 with window start STARTP. Value is
11415 CURSOR_MOVEMENT_SUCCESS if successful
11417 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
11419 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
11420 display. *SCROLL_STEP is set to 1, under certain circumstances, if
11421 we want to scroll as if scroll-step were set to 1. See the code.
11423 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
11424 which case we have to abort this redisplay, and adjust matrices
11429 CURSOR_MOVEMENT_SUCCESS
,
11430 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11431 CURSOR_MOVEMENT_MUST_SCROLL
,
11432 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11436 try_cursor_movement (window
, startp
, scroll_step
)
11437 Lisp_Object window
;
11438 struct text_pos startp
;
11441 struct window
*w
= XWINDOW (window
);
11442 struct frame
*f
= XFRAME (w
->frame
);
11443 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11446 if (inhibit_try_cursor_movement
)
11450 /* Handle case where text has not changed, only point, and it has
11451 not moved off the frame. */
11452 if (/* Point may be in this window. */
11453 PT
>= CHARPOS (startp
)
11454 /* Selective display hasn't changed. */
11455 && !current_buffer
->clip_changed
11456 /* Function force-mode-line-update is used to force a thorough
11457 redisplay. It sets either windows_or_buffers_changed or
11458 update_mode_lines. So don't take a shortcut here for these
11460 && !update_mode_lines
11461 && !windows_or_buffers_changed
11462 && !cursor_type_changed
11463 /* Can't use this case if highlighting a region. When a
11464 region exists, cursor movement has to do more than just
11466 && !(!NILP (Vtransient_mark_mode
)
11467 && !NILP (current_buffer
->mark_active
))
11468 && NILP (w
->region_showing
)
11469 && NILP (Vshow_trailing_whitespace
)
11470 /* Right after splitting windows, last_point may be nil. */
11471 && INTEGERP (w
->last_point
)
11472 /* This code is not used for mini-buffer for the sake of the case
11473 of redisplaying to replace an echo area message; since in
11474 that case the mini-buffer contents per se are usually
11475 unchanged. This code is of no real use in the mini-buffer
11476 since the handling of this_line_start_pos, etc., in redisplay
11477 handles the same cases. */
11478 && !EQ (window
, minibuf_window
)
11479 /* When splitting windows or for new windows, it happens that
11480 redisplay is called with a nil window_end_vpos or one being
11481 larger than the window. This should really be fixed in
11482 window.c. I don't have this on my list, now, so we do
11483 approximately the same as the old redisplay code. --gerd. */
11484 && INTEGERP (w
->window_end_vpos
)
11485 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11486 && (FRAME_WINDOW_P (f
)
11487 || !MARKERP (Voverlay_arrow_position
)
11488 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
11490 int this_scroll_margin
;
11491 struct glyph_row
*row
= NULL
;
11494 debug_method_add (w
, "cursor movement");
11497 /* Scroll if point within this distance from the top or bottom
11498 of the window. This is a pixel value. */
11499 this_scroll_margin
= max (0, scroll_margin
);
11500 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11501 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11503 /* Start with the row the cursor was displayed during the last
11504 not paused redisplay. Give up if that row is not valid. */
11505 if (w
->last_cursor
.vpos
< 0
11506 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11507 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11510 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11511 if (row
->mode_line_p
)
11513 if (!row
->enabled_p
)
11514 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11517 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11520 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11522 if (PT
> XFASTINT (w
->last_point
))
11524 /* Point has moved forward. */
11525 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11526 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11528 xassert (row
->enabled_p
);
11532 /* The end position of a row equals the start position
11533 of the next row. If PT is there, we would rather
11534 display it in the next line. */
11535 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11536 && MATRIX_ROW_END_CHARPOS (row
) == PT
11537 && !cursor_row_p (w
, row
))
11540 /* If within the scroll margin, scroll. Note that
11541 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11542 the next line would be drawn, and that
11543 this_scroll_margin can be zero. */
11544 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11545 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11546 /* Line is completely visible last line in window
11547 and PT is to be set in the next line. */
11548 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11549 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11550 && !row
->ends_at_zv_p
11551 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11554 else if (PT
< XFASTINT (w
->last_point
))
11556 /* Cursor has to be moved backward. Note that PT >=
11557 CHARPOS (startp) because of the outer
11559 while (!row
->mode_line_p
11560 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11561 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11562 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
11563 && (row
->y
> this_scroll_margin
11564 || CHARPOS (startp
) == BEGV
))
11566 xassert (row
->enabled_p
);
11570 /* Consider the following case: Window starts at BEGV,
11571 there is invisible, intangible text at BEGV, so that
11572 display starts at some point START > BEGV. It can
11573 happen that we are called with PT somewhere between
11574 BEGV and START. Try to handle that case. */
11575 if (row
< w
->current_matrix
->rows
11576 || row
->mode_line_p
)
11578 row
= w
->current_matrix
->rows
;
11579 if (row
->mode_line_p
)
11583 /* Due to newlines in overlay strings, we may have to
11584 skip forward over overlay strings. */
11585 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11586 && MATRIX_ROW_END_CHARPOS (row
) == PT
11587 && !cursor_row_p (w
, row
))
11590 /* If within the scroll margin, scroll. */
11591 if (row
->y
< this_scroll_margin
11592 && CHARPOS (startp
) != BEGV
)
11596 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
11597 || PT
> MATRIX_ROW_END_CHARPOS (row
))
11599 /* if PT is not in the glyph row, give up. */
11600 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11602 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
11604 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
11605 && !row
->ends_at_zv_p
11606 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11607 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11608 else if (row
->height
> window_box_height (w
))
11610 /* If we end up in a partially visible line, let's
11611 make it fully visible, except when it's taller
11612 than the window, in which case we can't do much
11615 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11619 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11620 if (!make_cursor_line_fully_visible (w
))
11621 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11623 rc
= CURSOR_MOVEMENT_SUCCESS
;
11627 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11630 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11631 rc
= CURSOR_MOVEMENT_SUCCESS
;
11640 set_vertical_scroll_bar (w
)
11643 int start
, end
, whole
;
11645 /* Calculate the start and end positions for the current window.
11646 At some point, it would be nice to choose between scrollbars
11647 which reflect the whole buffer size, with special markers
11648 indicating narrowing, and scrollbars which reflect only the
11651 Note that mini-buffers sometimes aren't displaying any text. */
11652 if (!MINI_WINDOW_P (w
)
11653 || (w
== XWINDOW (minibuf_window
)
11654 && NILP (echo_area_buffer
[0])))
11656 struct buffer
*buf
= XBUFFER (w
->buffer
);
11657 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
11658 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
11659 /* I don't think this is guaranteed to be right. For the
11660 moment, we'll pretend it is. */
11661 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
11665 if (whole
< (end
- start
))
11666 whole
= end
- start
;
11669 start
= end
= whole
= 0;
11671 /* Indicate what this scroll bar ought to be displaying now. */
11672 if (FRAME_DISPLAY (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
11673 (*FRAME_DISPLAY (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
11674 (w
, end
- start
, whole
, start
);
11677 #ifdef HAVE_WINDOW_SYSTEM
11679 /* Recalculate the bitmaps to show in the fringes of window W.
11680 If FORCE_P is 0, only mark rows with modified bitmaps for update in
11681 redraw_fringe_bitmaps_p; else mark all rows for update. */
11684 update_window_fringes (w
, force_p
)
11688 struct glyph_row
*row
, *cur
= 0;
11689 int yb
= window_text_bottom_y (w
);
11690 int rn
, nrows
= w
->current_matrix
->nrows
;
11695 if (w
->pseudo_window_p
)
11698 if (!MINI_WINDOW_P (w
)
11699 && (ind
= XBUFFER (w
->buffer
)->indicate_buffer_boundaries
, !NILP (ind
)))
11701 int do_eob
= 1, do_bob
= 1;
11703 for (y
= 0, rn
= 0;
11704 y
< yb
&& rn
< nrows
;
11705 y
+= row
->height
, ++rn
)
11707 unsigned indicate_bob_p
, indicate_top_line_p
;
11708 unsigned indicate_eob_p
, indicate_bottom_line_p
;
11710 row
= w
->desired_matrix
->rows
+ rn
;
11711 if (!row
->enabled_p
)
11712 row
= w
->current_matrix
->rows
+ rn
;
11714 indicate_bob_p
= row
->indicate_bob_p
;
11715 indicate_top_line_p
= row
->indicate_top_line_p
;
11716 indicate_eob_p
= row
->indicate_eob_p
;
11717 indicate_bottom_line_p
= row
->indicate_bottom_line_p
;
11719 row
->indicate_bob_p
= row
->indicate_top_line_p
= 0;
11720 row
->indicate_eob_p
= row
->indicate_bottom_line_p
= 0;
11722 if (MATRIX_ROW_START_CHARPOS (row
) <= BUF_BEGV (XBUFFER (w
->buffer
)))
11723 row
->indicate_bob_p
= do_bob
, do_bob
= 0;
11724 else if (EQ (ind
, Qt
)
11725 && (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0) == rn
)
11726 row
->indicate_top_line_p
= 1;
11728 if (MATRIX_ROW_END_CHARPOS (row
) >= BUF_ZV (XBUFFER (w
->buffer
)))
11729 row
->indicate_eob_p
= do_eob
, do_eob
= 0;
11730 else if (EQ (ind
, Qt
)
11731 && y
+ row
->height
>= yb
)
11732 row
->indicate_bottom_line_p
= 1;
11734 if (indicate_bob_p
!= row
->indicate_bob_p
11735 || indicate_top_line_p
!= row
->indicate_top_line_p
11736 || indicate_eob_p
!= row
->indicate_eob_p
11737 || indicate_bottom_line_p
!= row
->indicate_bottom_line_p
)
11738 row
->redraw_fringe_bitmaps_p
= 1;
11742 for (y
= 0, rn
= 0;
11743 y
< yb
&& rn
< nrows
;
11744 y
+= row
->height
, rn
++)
11746 enum fringe_bitmap_type left
, right
;
11748 row
= w
->desired_matrix
->rows
+ rn
;
11749 cur
= w
->current_matrix
->rows
+ rn
;
11750 if (!row
->enabled_p
)
11753 /* Decide which bitmap to draw in the left fringe. */
11754 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
11755 left
= NO_FRINGE_BITMAP
;
11756 else if (row
->overlay_arrow_p
)
11757 left
= OVERLAY_ARROW_BITMAP
;
11758 else if (row
->truncated_on_left_p
)
11759 left
= LEFT_TRUNCATION_BITMAP
;
11760 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
11761 left
= CONTINUATION_LINE_BITMAP
;
11762 else if (row
->indicate_empty_line_p
)
11763 left
= ZV_LINE_BITMAP
;
11764 else if (row
->indicate_bob_p
)
11765 left
= FIRST_LINE_BITMAP
;
11767 left
= NO_FRINGE_BITMAP
;
11769 /* Decide which bitmap to draw in the right fringe. */
11770 if (WINDOW_RIGHT_FRINGE_WIDTH (w
) == 0)
11771 right
= NO_FRINGE_BITMAP
;
11772 else if (row
->truncated_on_right_p
)
11773 right
= RIGHT_TRUNCATION_BITMAP
;
11774 else if (row
->continued_p
)
11775 right
= CONTINUED_LINE_BITMAP
;
11776 else if (row
->indicate_eob_p
)
11777 right
= LAST_LINE_BITMAP
;
11778 else if (row
->indicate_top_line_p
)
11779 right
= UP_ARROW_BITMAP
;
11780 else if (row
->indicate_bottom_line_p
)
11781 right
= DOWN_ARROW_BITMAP
;
11782 else if (row
->indicate_empty_line_p
&& WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
11783 right
= ZV_LINE_BITMAP
;
11785 right
= NO_FRINGE_BITMAP
;
11788 || row
->y
!= cur
->y
11789 || row
->visible_height
!= cur
->visible_height
11790 || left
!= cur
->left_fringe_bitmap
11791 || right
!= cur
->right_fringe_bitmap
11792 || cur
->redraw_fringe_bitmaps_p
)
11794 redraw_p
= row
->redraw_fringe_bitmaps_p
= cur
->redraw_fringe_bitmaps_p
= 1;
11795 cur
->left_fringe_bitmap
= left
;
11796 cur
->right_fringe_bitmap
= right
;
11799 row
->left_fringe_bitmap
= left
;
11800 row
->right_fringe_bitmap
= right
;
11806 #endif /* HAVE_WINDOW_SYSTEM */
11808 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
11809 selected_window is redisplayed.
11811 We can return without actually redisplaying the window if
11812 fonts_changed_p is nonzero. In that case, redisplay_internal will
11816 redisplay_window (window
, just_this_one_p
)
11817 Lisp_Object window
;
11818 int just_this_one_p
;
11820 struct window
*w
= XWINDOW (window
);
11821 struct frame
*f
= XFRAME (w
->frame
);
11822 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11823 struct buffer
*old
= current_buffer
;
11824 struct text_pos lpoint
, opoint
, startp
;
11825 int update_mode_line
;
11828 /* Record it now because it's overwritten. */
11829 int current_matrix_up_to_date_p
= 0;
11830 int used_current_matrix_p
= 0;
11831 /* This is less strict than current_matrix_up_to_date_p.
11832 It indictes that the buffer contents and narrowing are unchanged. */
11833 int buffer_unchanged_p
= 0;
11834 int temp_scroll_step
= 0;
11835 int count
= SPECPDL_INDEX ();
11837 int centering_position
;
11838 int last_line_misfit
= 0;
11840 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11843 /* W must be a leaf window here. */
11844 xassert (!NILP (w
->buffer
));
11846 *w
->desired_matrix
->method
= 0;
11849 specbind (Qinhibit_point_motion_hooks
, Qt
);
11851 reconsider_clip_changes (w
, buffer
);
11853 /* Has the mode line to be updated? */
11854 update_mode_line
= (!NILP (w
->update_mode_line
)
11855 || update_mode_lines
11856 || buffer
->clip_changed
11857 || buffer
->prevent_redisplay_optimizations_p
);
11859 if (MINI_WINDOW_P (w
))
11861 if (w
== XWINDOW (echo_area_window
)
11862 && !NILP (echo_area_buffer
[0]))
11864 if (update_mode_line
)
11865 /* We may have to update a tty frame's menu bar or a
11866 tool-bar. Example `M-x C-h C-h C-g'. */
11867 goto finish_menu_bars
;
11869 /* We've already displayed the echo area glyphs in this window. */
11870 goto finish_scroll_bars
;
11872 else if ((w
!= XWINDOW (minibuf_window
)
11873 || minibuf_level
== 0)
11874 /* When buffer is nonempty, redisplay window normally. */
11875 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
11876 /* Quail displays non-mini buffers in minibuffer window.
11877 In that case, redisplay the window normally. */
11878 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
11880 /* W is a mini-buffer window, but it's not active, so clear
11882 int yb
= window_text_bottom_y (w
);
11883 struct glyph_row
*row
;
11886 for (y
= 0, row
= w
->desired_matrix
->rows
;
11888 y
+= row
->height
, ++row
)
11889 blank_row (w
, row
, y
);
11890 goto finish_scroll_bars
;
11893 clear_glyph_matrix (w
->desired_matrix
);
11896 /* Otherwise set up data on this window; select its buffer and point
11898 /* Really select the buffer, for the sake of buffer-local
11900 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11901 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
11903 current_matrix_up_to_date_p
11904 = (!NILP (w
->window_end_valid
)
11905 && !current_buffer
->clip_changed
11906 && !current_buffer
->prevent_redisplay_optimizations_p
11907 && XFASTINT (w
->last_modified
) >= MODIFF
11908 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11911 = (!NILP (w
->window_end_valid
)
11912 && !current_buffer
->clip_changed
11913 && XFASTINT (w
->last_modified
) >= MODIFF
11914 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11916 /* When windows_or_buffers_changed is non-zero, we can't rely on
11917 the window end being valid, so set it to nil there. */
11918 if (windows_or_buffers_changed
)
11920 /* If window starts on a continuation line, maybe adjust the
11921 window start in case the window's width changed. */
11922 if (XMARKER (w
->start
)->buffer
== current_buffer
)
11923 compute_window_start_on_continuation_line (w
);
11925 w
->window_end_valid
= Qnil
;
11928 /* Some sanity checks. */
11929 CHECK_WINDOW_END (w
);
11930 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
11932 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
11935 /* If %c is in mode line, update it if needed. */
11936 if (!NILP (w
->column_number_displayed
)
11937 /* This alternative quickly identifies a common case
11938 where no change is needed. */
11939 && !(PT
== XFASTINT (w
->last_point
)
11940 && XFASTINT (w
->last_modified
) >= MODIFF
11941 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11942 && (XFASTINT (w
->column_number_displayed
)
11943 != (int) current_column ())) /* iftc */
11944 update_mode_line
= 1;
11946 /* Count number of windows showing the selected buffer. An indirect
11947 buffer counts as its base buffer. */
11948 if (!just_this_one_p
)
11950 struct buffer
*current_base
, *window_base
;
11951 current_base
= current_buffer
;
11952 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11953 if (current_base
->base_buffer
)
11954 current_base
= current_base
->base_buffer
;
11955 if (window_base
->base_buffer
)
11956 window_base
= window_base
->base_buffer
;
11957 if (current_base
== window_base
)
11961 /* Point refers normally to the selected window. For any other
11962 window, set up appropriate value. */
11963 if (!EQ (window
, selected_window
))
11965 int new_pt
= XMARKER (w
->pointm
)->charpos
;
11966 int new_pt_byte
= marker_byte_position (w
->pointm
);
11970 new_pt_byte
= BEGV_BYTE
;
11971 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
11973 else if (new_pt
> (ZV
- 1))
11976 new_pt_byte
= ZV_BYTE
;
11977 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
11980 /* We don't use SET_PT so that the point-motion hooks don't run. */
11981 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
11984 /* If any of the character widths specified in the display table
11985 have changed, invalidate the width run cache. It's true that
11986 this may be a bit late to catch such changes, but the rest of
11987 redisplay goes (non-fatally) haywire when the display table is
11988 changed, so why should we worry about doing any better? */
11989 if (current_buffer
->width_run_cache
)
11991 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
11993 if (! disptab_matches_widthtab (disptab
,
11994 XVECTOR (current_buffer
->width_table
)))
11996 invalidate_region_cache (current_buffer
,
11997 current_buffer
->width_run_cache
,
11999 recompute_width_table (current_buffer
, disptab
);
12003 /* If window-start is screwed up, choose a new one. */
12004 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12007 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12009 /* If someone specified a new starting point but did not insist,
12010 check whether it can be used. */
12011 if (!NILP (w
->optional_new_start
)
12012 && CHARPOS (startp
) >= BEGV
12013 && CHARPOS (startp
) <= ZV
)
12015 w
->optional_new_start
= Qnil
;
12016 start_display (&it
, w
, startp
);
12017 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12018 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12019 if (IT_CHARPOS (it
) == PT
)
12020 w
->force_start
= Qt
;
12021 /* IT may overshoot PT if text at PT is invisible. */
12022 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12023 w
->force_start
= Qt
;
12028 /* Handle case where place to start displaying has been specified,
12029 unless the specified location is outside the accessible range. */
12030 if (!NILP (w
->force_start
)
12031 || w
->frozen_window_start_p
)
12033 /* We set this later on if we have to adjust point. */
12036 w
->force_start
= Qnil
;
12038 w
->window_end_valid
= Qnil
;
12040 /* Forget any recorded base line for line number display. */
12041 if (!buffer_unchanged_p
)
12042 w
->base_line_number
= Qnil
;
12044 /* Redisplay the mode line. Select the buffer properly for that.
12045 Also, run the hook window-scroll-functions
12046 because we have scrolled. */
12047 /* Note, we do this after clearing force_start because
12048 if there's an error, it is better to forget about force_start
12049 than to get into an infinite loop calling the hook functions
12050 and having them get more errors. */
12051 if (!update_mode_line
12052 || ! NILP (Vwindow_scroll_functions
))
12054 update_mode_line
= 1;
12055 w
->update_mode_line
= Qt
;
12056 startp
= run_window_scroll_functions (window
, startp
);
12059 w
->last_modified
= make_number (0);
12060 w
->last_overlay_modified
= make_number (0);
12061 if (CHARPOS (startp
) < BEGV
)
12062 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
12063 else if (CHARPOS (startp
) > ZV
)
12064 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12066 /* Redisplay, then check if cursor has been set during the
12067 redisplay. Give up if new fonts were loaded. */
12068 if (!try_window (window
, startp
))
12070 w
->force_start
= Qt
;
12071 clear_glyph_matrix (w
->desired_matrix
);
12072 goto need_larger_matrices
;
12075 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12077 /* If point does not appear, try to move point so it does
12078 appear. The desired matrix has been built above, so we
12079 can use it here. */
12080 new_vpos
= window_box_height (w
) / 2;
12083 if (!make_cursor_line_fully_visible (w
))
12085 /* Point does appear, but on a line partly visible at end of window.
12086 Move it back to a fully-visible line. */
12087 new_vpos
= window_box_height (w
);
12090 /* If we need to move point for either of the above reasons,
12091 now actually do it. */
12094 struct glyph_row
*row
;
12096 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
12097 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
12100 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
12101 MATRIX_ROW_START_BYTEPOS (row
));
12103 if (w
!= XWINDOW (selected_window
))
12104 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
12105 else if (current_buffer
== old
)
12106 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12108 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
12110 /* If we are highlighting the region, then we just changed
12111 the region, so redisplay to show it. */
12112 if (!NILP (Vtransient_mark_mode
)
12113 && !NILP (current_buffer
->mark_active
))
12115 clear_glyph_matrix (w
->desired_matrix
);
12116 if (!try_window (window
, startp
))
12117 goto need_larger_matrices
;
12122 debug_method_add (w
, "forced window start");
12127 /* Handle case where text has not changed, only point, and it has
12128 not moved off the frame, and we are not retrying after hscroll.
12129 (current_matrix_up_to_date_p is nonzero when retrying.) */
12130 if (current_matrix_up_to_date_p
12131 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
12132 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
12136 case CURSOR_MOVEMENT_SUCCESS
:
12137 used_current_matrix_p
= 1;
12140 #if 0 /* try_cursor_movement never returns this value. */
12141 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
12142 goto need_larger_matrices
;
12145 case CURSOR_MOVEMENT_MUST_SCROLL
:
12146 goto try_to_scroll
;
12152 /* If current starting point was originally the beginning of a line
12153 but no longer is, find a new starting point. */
12154 else if (!NILP (w
->start_at_line_beg
)
12155 && !(CHARPOS (startp
) <= BEGV
12156 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
12159 debug_method_add (w
, "recenter 1");
12164 /* Try scrolling with try_window_id. Value is > 0 if update has
12165 been done, it is -1 if we know that the same window start will
12166 not work. It is 0 if unsuccessful for some other reason. */
12167 else if ((tem
= try_window_id (w
)) != 0)
12170 debug_method_add (w
, "try_window_id %d", tem
);
12173 if (fonts_changed_p
)
12174 goto need_larger_matrices
;
12178 /* Otherwise try_window_id has returned -1 which means that we
12179 don't want the alternative below this comment to execute. */
12181 else if (CHARPOS (startp
) >= BEGV
12182 && CHARPOS (startp
) <= ZV
12183 && PT
>= CHARPOS (startp
)
12184 && (CHARPOS (startp
) < ZV
12185 /* Avoid starting at end of buffer. */
12186 || CHARPOS (startp
) == BEGV
12187 || (XFASTINT (w
->last_modified
) >= MODIFF
12188 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
12191 debug_method_add (w
, "same window start");
12194 /* Try to redisplay starting at same place as before.
12195 If point has not moved off frame, accept the results. */
12196 if (!current_matrix_up_to_date_p
12197 /* Don't use try_window_reusing_current_matrix in this case
12198 because a window scroll function can have changed the
12200 || !NILP (Vwindow_scroll_functions
)
12201 || MINI_WINDOW_P (w
)
12202 || !(used_current_matrix_p
=
12203 try_window_reusing_current_matrix (w
)))
12205 IF_DEBUG (debug_method_add (w
, "1"));
12206 try_window (window
, startp
);
12209 if (fonts_changed_p
)
12210 goto need_larger_matrices
;
12212 if (w
->cursor
.vpos
>= 0)
12214 if (!just_this_one_p
12215 || current_buffer
->clip_changed
12216 || BEG_UNCHANGED
< CHARPOS (startp
))
12217 /* Forget any recorded base line for line number display. */
12218 w
->base_line_number
= Qnil
;
12220 if (!make_cursor_line_fully_visible (w
))
12222 clear_glyph_matrix (w
->desired_matrix
);
12223 last_line_misfit
= 1;
12225 /* Drop through and scroll. */
12230 clear_glyph_matrix (w
->desired_matrix
);
12235 w
->last_modified
= make_number (0);
12236 w
->last_overlay_modified
= make_number (0);
12238 /* Redisplay the mode line. Select the buffer properly for that. */
12239 if (!update_mode_line
)
12241 update_mode_line
= 1;
12242 w
->update_mode_line
= Qt
;
12245 /* Try to scroll by specified few lines. */
12246 if ((scroll_conservatively
12248 || temp_scroll_step
12249 || NUMBERP (current_buffer
->scroll_up_aggressively
)
12250 || NUMBERP (current_buffer
->scroll_down_aggressively
))
12251 && !current_buffer
->clip_changed
12252 && CHARPOS (startp
) >= BEGV
12253 && CHARPOS (startp
) <= ZV
)
12255 /* The function returns -1 if new fonts were loaded, 1 if
12256 successful, 0 if not successful. */
12257 int rc
= try_scrolling (window
, just_this_one_p
,
12258 scroll_conservatively
,
12260 temp_scroll_step
, last_line_misfit
);
12263 case SCROLLING_SUCCESS
:
12266 case SCROLLING_NEED_LARGER_MATRICES
:
12267 goto need_larger_matrices
;
12269 case SCROLLING_FAILED
:
12277 /* Finally, just choose place to start which centers point */
12280 centering_position
= window_box_height (w
) / 2;
12283 /* Jump here with centering_position already set to 0. */
12286 debug_method_add (w
, "recenter");
12289 /* w->vscroll = 0; */
12291 /* Forget any previously recorded base line for line number display. */
12292 if (!buffer_unchanged_p
)
12293 w
->base_line_number
= Qnil
;
12295 /* Move backward half the height of the window. */
12296 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12297 it
.current_y
= it
.last_visible_y
;
12298 move_it_vertically_backward (&it
, centering_position
);
12299 xassert (IT_CHARPOS (it
) >= BEGV
);
12301 /* The function move_it_vertically_backward may move over more
12302 than the specified y-distance. If it->w is small, e.g. a
12303 mini-buffer window, we may end up in front of the window's
12304 display area. Start displaying at the start of the line
12305 containing PT in this case. */
12306 if (it
.current_y
<= 0)
12308 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12309 move_it_vertically (&it
, 0);
12310 xassert (IT_CHARPOS (it
) <= PT
);
12314 it
.current_x
= it
.hpos
= 0;
12316 /* Set startp here explicitly in case that helps avoid an infinite loop
12317 in case the window-scroll-functions functions get errors. */
12318 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
12320 /* Run scroll hooks. */
12321 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
12323 /* Redisplay the window. */
12324 if (!current_matrix_up_to_date_p
12325 || windows_or_buffers_changed
12326 || cursor_type_changed
12327 /* Don't use try_window_reusing_current_matrix in this case
12328 because it can have changed the buffer. */
12329 || !NILP (Vwindow_scroll_functions
)
12330 || !just_this_one_p
12331 || MINI_WINDOW_P (w
)
12332 || !(used_current_matrix_p
=
12333 try_window_reusing_current_matrix (w
)))
12334 try_window (window
, startp
);
12336 /* If new fonts have been loaded (due to fontsets), give up. We
12337 have to start a new redisplay since we need to re-adjust glyph
12339 if (fonts_changed_p
)
12340 goto need_larger_matrices
;
12342 /* If cursor did not appear assume that the middle of the window is
12343 in the first line of the window. Do it again with the next line.
12344 (Imagine a window of height 100, displaying two lines of height
12345 60. Moving back 50 from it->last_visible_y will end in the first
12347 if (w
->cursor
.vpos
< 0)
12349 if (!NILP (w
->window_end_valid
)
12350 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
12352 clear_glyph_matrix (w
->desired_matrix
);
12353 move_it_by_lines (&it
, 1, 0);
12354 try_window (window
, it
.current
.pos
);
12356 else if (PT
< IT_CHARPOS (it
))
12358 clear_glyph_matrix (w
->desired_matrix
);
12359 move_it_by_lines (&it
, -1, 0);
12360 try_window (window
, it
.current
.pos
);
12364 /* Not much we can do about it. */
12368 /* Consider the following case: Window starts at BEGV, there is
12369 invisible, intangible text at BEGV, so that display starts at
12370 some point START > BEGV. It can happen that we are called with
12371 PT somewhere between BEGV and START. Try to handle that case. */
12372 if (w
->cursor
.vpos
< 0)
12374 struct glyph_row
*row
= w
->current_matrix
->rows
;
12375 if (row
->mode_line_p
)
12377 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12380 if (!make_cursor_line_fully_visible (w
))
12382 /* If vscroll is enabled, disable it and try again. */
12386 clear_glyph_matrix (w
->desired_matrix
);
12390 /* If centering point failed to make the whole line visible,
12391 put point at the top instead. That has to make the whole line
12392 visible, if it can be done. */
12393 centering_position
= 0;
12399 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12400 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
12401 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
12404 /* Display the mode line, if we must. */
12405 if ((update_mode_line
12406 /* If window not full width, must redo its mode line
12407 if (a) the window to its side is being redone and
12408 (b) we do a frame-based redisplay. This is a consequence
12409 of how inverted lines are drawn in frame-based redisplay. */
12410 || (!just_this_one_p
12411 && !FRAME_WINDOW_P (f
)
12412 && !WINDOW_FULL_WIDTH_P (w
))
12413 /* Line number to display. */
12414 || INTEGERP (w
->base_line_pos
)
12415 /* Column number is displayed and different from the one displayed. */
12416 || (!NILP (w
->column_number_displayed
)
12417 && (XFASTINT (w
->column_number_displayed
)
12418 != (int) current_column ()))) /* iftc */
12419 /* This means that the window has a mode line. */
12420 && (WINDOW_WANTS_MODELINE_P (w
)
12421 || WINDOW_WANTS_HEADER_LINE_P (w
)))
12423 display_mode_lines (w
);
12425 /* If mode line height has changed, arrange for a thorough
12426 immediate redisplay using the correct mode line height. */
12427 if (WINDOW_WANTS_MODELINE_P (w
)
12428 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12430 fonts_changed_p
= 1;
12431 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12432 = DESIRED_MODE_LINE_HEIGHT (w
);
12435 /* If top line height has changed, arrange for a thorough
12436 immediate redisplay using the correct mode line height. */
12437 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12438 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
12440 fonts_changed_p
= 1;
12441 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
12442 = DESIRED_HEADER_LINE_HEIGHT (w
);
12445 if (fonts_changed_p
)
12446 goto need_larger_matrices
;
12449 if (!line_number_displayed
12450 && !BUFFERP (w
->base_line_pos
))
12452 w
->base_line_pos
= Qnil
;
12453 w
->base_line_number
= Qnil
;
12458 /* When we reach a frame's selected window, redo the frame's menu bar. */
12459 if (update_mode_line
12460 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
12462 int redisplay_menu_p
= 0;
12463 int redisplay_tool_bar_p
= 0;
12465 if (FRAME_WINDOW_P (f
))
12467 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
12468 || defined (USE_GTK)
12469 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
12471 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12475 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12477 if (redisplay_menu_p
)
12478 display_menu_bar (w
);
12480 #ifdef HAVE_WINDOW_SYSTEM
12482 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
12484 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
12485 && (FRAME_TOOL_BAR_LINES (f
) > 0
12486 || auto_resize_tool_bars_p
);
12490 if (redisplay_tool_bar_p
)
12491 redisplay_tool_bar (f
);
12495 #ifdef HAVE_WINDOW_SYSTEM
12496 if (update_window_fringes (w
, 0)
12497 && (used_current_matrix_p
|| overlay_arrow_seen
)
12498 && !w
->pseudo_window_p
)
12502 draw_window_fringes (w
);
12506 #endif /* HAVE_WINDOW_SYSTEM */
12508 /* We go to this label, with fonts_changed_p nonzero,
12509 if it is necessary to try again using larger glyph matrices.
12510 We have to redeem the scroll bar even in this case,
12511 because the loop in redisplay_internal expects that. */
12512 need_larger_matrices
:
12514 finish_scroll_bars
:
12516 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
12518 /* Set the thumb's position and size. */
12519 set_vertical_scroll_bar (w
);
12521 /* Note that we actually used the scroll bar attached to this
12522 window, so it shouldn't be deleted at the end of redisplay. */
12523 if (FRAME_DISPLAY (f
)->redeem_scroll_bar_hook
)
12524 (*FRAME_DISPLAY (f
)->redeem_scroll_bar_hook
) (w
);
12527 /* Restore current_buffer and value of point in it. */
12528 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
12529 set_buffer_internal_1 (old
);
12530 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12532 unbind_to (count
, Qnil
);
12536 /* Build the complete desired matrix of WINDOW with a window start
12537 buffer position POS. Value is non-zero if successful. It is zero
12538 if fonts were loaded during redisplay which makes re-adjusting
12539 glyph matrices necessary. */
12542 try_window (window
, pos
)
12543 Lisp_Object window
;
12544 struct text_pos pos
;
12546 struct window
*w
= XWINDOW (window
);
12548 struct glyph_row
*last_text_row
= NULL
;
12550 /* Make POS the new window start. */
12551 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
12553 /* Mark cursor position as unknown. No overlay arrow seen. */
12554 w
->cursor
.vpos
= -1;
12555 overlay_arrow_seen
= 0;
12557 /* Initialize iterator and info to start at POS. */
12558 start_display (&it
, w
, pos
);
12560 /* Display all lines of W. */
12561 while (it
.current_y
< it
.last_visible_y
)
12563 if (display_line (&it
))
12564 last_text_row
= it
.glyph_row
- 1;
12565 if (fonts_changed_p
)
12569 /* If bottom moved off end of frame, change mode line percentage. */
12570 if (XFASTINT (w
->window_end_pos
) <= 0
12571 && Z
!= IT_CHARPOS (it
))
12572 w
->update_mode_line
= Qt
;
12574 /* Set window_end_pos to the offset of the last character displayed
12575 on the window from the end of current_buffer. Set
12576 window_end_vpos to its row number. */
12579 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
12580 w
->window_end_bytepos
12581 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12583 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12585 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12586 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12587 ->displays_text_p
);
12591 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12592 w
->window_end_pos
= make_number (Z
- ZV
);
12593 w
->window_end_vpos
= make_number (0);
12596 /* But that is not valid info until redisplay finishes. */
12597 w
->window_end_valid
= Qnil
;
12603 /************************************************************************
12604 Window redisplay reusing current matrix when buffer has not changed
12605 ************************************************************************/
12607 /* Try redisplay of window W showing an unchanged buffer with a
12608 different window start than the last time it was displayed by
12609 reusing its current matrix. Value is non-zero if successful.
12610 W->start is the new window start. */
12613 try_window_reusing_current_matrix (w
)
12616 struct frame
*f
= XFRAME (w
->frame
);
12617 struct glyph_row
*row
, *bottom_row
;
12620 struct text_pos start
, new_start
;
12621 int nrows_scrolled
, i
;
12622 struct glyph_row
*last_text_row
;
12623 struct glyph_row
*last_reused_text_row
;
12624 struct glyph_row
*start_row
;
12625 int start_vpos
, min_y
, max_y
;
12628 if (inhibit_try_window_reusing
)
12632 if (/* This function doesn't handle terminal frames. */
12633 !FRAME_WINDOW_P (f
)
12634 /* Don't try to reuse the display if windows have been split
12636 || windows_or_buffers_changed
12637 || cursor_type_changed
)
12640 /* Can't do this if region may have changed. */
12641 if ((!NILP (Vtransient_mark_mode
)
12642 && !NILP (current_buffer
->mark_active
))
12643 || !NILP (w
->region_showing
)
12644 || !NILP (Vshow_trailing_whitespace
))
12647 /* If top-line visibility has changed, give up. */
12648 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12649 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12652 /* Give up if old or new display is scrolled vertically. We could
12653 make this function handle this, but right now it doesn't. */
12654 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12655 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
12658 /* The variable new_start now holds the new window start. The old
12659 start `start' can be determined from the current matrix. */
12660 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
12661 start
= start_row
->start
.pos
;
12662 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12664 /* Clear the desired matrix for the display below. */
12665 clear_glyph_matrix (w
->desired_matrix
);
12667 if (CHARPOS (new_start
) <= CHARPOS (start
))
12671 /* Don't use this method if the display starts with an ellipsis
12672 displayed for invisible text. It's not easy to handle that case
12673 below, and it's certainly not worth the effort since this is
12674 not a frequent case. */
12675 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
12678 IF_DEBUG (debug_method_add (w
, "twu1"));
12680 /* Display up to a row that can be reused. The variable
12681 last_text_row is set to the last row displayed that displays
12682 text. Note that it.vpos == 0 if or if not there is a
12683 header-line; it's not the same as the MATRIX_ROW_VPOS! */
12684 start_display (&it
, w
, new_start
);
12685 first_row_y
= it
.current_y
;
12686 w
->cursor
.vpos
= -1;
12687 last_text_row
= last_reused_text_row
= NULL
;
12689 while (it
.current_y
< it
.last_visible_y
12690 && IT_CHARPOS (it
) < CHARPOS (start
)
12691 && !fonts_changed_p
)
12692 if (display_line (&it
))
12693 last_text_row
= it
.glyph_row
- 1;
12695 /* A value of current_y < last_visible_y means that we stopped
12696 at the previous window start, which in turn means that we
12697 have at least one reusable row. */
12698 if (it
.current_y
< it
.last_visible_y
)
12700 /* IT.vpos always starts from 0; it counts text lines. */
12701 nrows_scrolled
= it
.vpos
;
12703 /* Find PT if not already found in the lines displayed. */
12704 if (w
->cursor
.vpos
< 0)
12706 int dy
= it
.current_y
- first_row_y
;
12708 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12709 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
12711 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
12712 dy
, nrows_scrolled
);
12715 clear_glyph_matrix (w
->desired_matrix
);
12720 /* Scroll the display. Do it before the current matrix is
12721 changed. The problem here is that update has not yet
12722 run, i.e. part of the current matrix is not up to date.
12723 scroll_run_hook will clear the cursor, and use the
12724 current matrix to get the height of the row the cursor is
12726 run
.current_y
= first_row_y
;
12727 run
.desired_y
= it
.current_y
;
12728 run
.height
= it
.last_visible_y
- it
.current_y
;
12730 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
12733 FRAME_RIF (f
)->update_window_begin_hook (w
);
12734 FRAME_RIF (f
)->clear_window_mouse_face (w
);
12735 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
12736 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
12740 /* Shift current matrix down by nrows_scrolled lines. */
12741 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12742 rotate_matrix (w
->current_matrix
,
12744 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12747 /* Disable lines that must be updated. */
12748 for (i
= 0; i
< it
.vpos
; ++i
)
12749 (start_row
+ i
)->enabled_p
= 0;
12751 /* Re-compute Y positions. */
12752 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12753 max_y
= it
.last_visible_y
;
12754 for (row
= start_row
+ nrows_scrolled
;
12758 row
->y
= it
.current_y
;
12759 row
->visible_height
= row
->height
;
12761 if (row
->y
< min_y
)
12762 row
->visible_height
-= min_y
- row
->y
;
12763 if (row
->y
+ row
->height
> max_y
)
12764 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12765 row
->redraw_fringe_bitmaps_p
= 1;
12767 it
.current_y
+= row
->height
;
12769 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12770 last_reused_text_row
= row
;
12771 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
12775 /* Disable lines in the current matrix which are now
12776 below the window. */
12777 for (++row
; row
< bottom_row
; ++row
)
12778 row
->enabled_p
= 0;
12781 /* Update window_end_pos etc.; last_reused_text_row is the last
12782 reused row from the current matrix containing text, if any.
12783 The value of last_text_row is the last displayed line
12784 containing text. */
12785 if (last_reused_text_row
)
12787 w
->window_end_bytepos
12788 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
12790 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
12792 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
12793 w
->current_matrix
));
12795 else if (last_text_row
)
12797 w
->window_end_bytepos
12798 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12800 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12802 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12806 /* This window must be completely empty. */
12807 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12808 w
->window_end_pos
= make_number (Z
- ZV
);
12809 w
->window_end_vpos
= make_number (0);
12811 w
->window_end_valid
= Qnil
;
12813 /* Update hint: don't try scrolling again in update_window. */
12814 w
->desired_matrix
->no_scrolling_p
= 1;
12817 debug_method_add (w
, "try_window_reusing_current_matrix 1");
12821 else if (CHARPOS (new_start
) > CHARPOS (start
))
12823 struct glyph_row
*pt_row
, *row
;
12824 struct glyph_row
*first_reusable_row
;
12825 struct glyph_row
*first_row_to_display
;
12827 int yb
= window_text_bottom_y (w
);
12829 /* Find the row starting at new_start, if there is one. Don't
12830 reuse a partially visible line at the end. */
12831 first_reusable_row
= start_row
;
12832 while (first_reusable_row
->enabled_p
12833 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
12834 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12835 < CHARPOS (new_start
)))
12836 ++first_reusable_row
;
12838 /* Give up if there is no row to reuse. */
12839 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
12840 || !first_reusable_row
->enabled_p
12841 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12842 != CHARPOS (new_start
)))
12845 /* We can reuse fully visible rows beginning with
12846 first_reusable_row to the end of the window. Set
12847 first_row_to_display to the first row that cannot be reused.
12848 Set pt_row to the row containing point, if there is any. */
12850 for (first_row_to_display
= first_reusable_row
;
12851 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
12852 ++first_row_to_display
)
12854 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
12855 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
12856 pt_row
= first_row_to_display
;
12859 /* Start displaying at the start of first_row_to_display. */
12860 xassert (first_row_to_display
->y
< yb
);
12861 init_to_row_start (&it
, w
, first_row_to_display
);
12863 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
12865 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
12867 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
12868 + WINDOW_HEADER_LINE_HEIGHT (w
));
12870 /* Display lines beginning with first_row_to_display in the
12871 desired matrix. Set last_text_row to the last row displayed
12872 that displays text. */
12873 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
12874 if (pt_row
== NULL
)
12875 w
->cursor
.vpos
= -1;
12876 last_text_row
= NULL
;
12877 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
12878 if (display_line (&it
))
12879 last_text_row
= it
.glyph_row
- 1;
12881 /* Give up If point isn't in a row displayed or reused. */
12882 if (w
->cursor
.vpos
< 0)
12884 clear_glyph_matrix (w
->desired_matrix
);
12888 /* If point is in a reused row, adjust y and vpos of the cursor
12892 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
12893 w
->current_matrix
);
12894 w
->cursor
.y
-= first_reusable_row
->y
;
12897 /* Scroll the display. */
12898 run
.current_y
= first_reusable_row
->y
;
12899 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12900 run
.height
= it
.last_visible_y
- run
.current_y
;
12901 dy
= run
.current_y
- run
.desired_y
;
12906 FRAME_RIF (f
)->update_window_begin_hook (w
);
12907 FRAME_RIF (f
)->clear_window_mouse_face (w
);
12908 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
12909 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
12913 /* Adjust Y positions of reused rows. */
12914 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12915 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12916 max_y
= it
.last_visible_y
;
12917 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
12920 row
->visible_height
= row
->height
;
12921 if (row
->y
< min_y
)
12922 row
->visible_height
-= min_y
- row
->y
;
12923 if (row
->y
+ row
->height
> max_y
)
12924 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12925 row
->redraw_fringe_bitmaps_p
= 1;
12928 /* Scroll the current matrix. */
12929 xassert (nrows_scrolled
> 0);
12930 rotate_matrix (w
->current_matrix
,
12932 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12935 /* Disable rows not reused. */
12936 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
12937 row
->enabled_p
= 0;
12939 /* Adjust window end. A null value of last_text_row means that
12940 the window end is in reused rows which in turn means that
12941 only its vpos can have changed. */
12944 w
->window_end_bytepos
12945 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12947 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12949 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12954 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
12957 w
->window_end_valid
= Qnil
;
12958 w
->desired_matrix
->no_scrolling_p
= 1;
12961 debug_method_add (w
, "try_window_reusing_current_matrix 2");
12971 /************************************************************************
12972 Window redisplay reusing current matrix when buffer has changed
12973 ************************************************************************/
12975 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
12976 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
12978 static struct glyph_row
*
12979 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
12980 struct glyph_row
*));
12983 /* Return the last row in MATRIX displaying text. If row START is
12984 non-null, start searching with that row. IT gives the dimensions
12985 of the display. Value is null if matrix is empty; otherwise it is
12986 a pointer to the row found. */
12988 static struct glyph_row
*
12989 find_last_row_displaying_text (matrix
, it
, start
)
12990 struct glyph_matrix
*matrix
;
12992 struct glyph_row
*start
;
12994 struct glyph_row
*row
, *row_found
;
12996 /* Set row_found to the last row in IT->w's current matrix
12997 displaying text. The loop looks funny but think of partially
13000 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
13001 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13003 xassert (row
->enabled_p
);
13005 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
13014 /* Return the last row in the current matrix of W that is not affected
13015 by changes at the start of current_buffer that occurred since W's
13016 current matrix was built. Value is null if no such row exists.
13018 BEG_UNCHANGED us the number of characters unchanged at the start of
13019 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
13020 first changed character in current_buffer. Characters at positions <
13021 BEG + BEG_UNCHANGED are at the same buffer positions as they were
13022 when the current matrix was built. */
13024 static struct glyph_row
*
13025 find_last_unchanged_at_beg_row (w
)
13028 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
13029 struct glyph_row
*row
;
13030 struct glyph_row
*row_found
= NULL
;
13031 int yb
= window_text_bottom_y (w
);
13033 /* Find the last row displaying unchanged text. */
13034 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13035 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13036 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
13038 if (/* If row ends before first_changed_pos, it is unchanged,
13039 except in some case. */
13040 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
13041 /* When row ends in ZV and we write at ZV it is not
13043 && !row
->ends_at_zv_p
13044 /* When first_changed_pos is the end of a continued line,
13045 row is not unchanged because it may be no longer
13047 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
13048 && (row
->continued_p
13049 || row
->exact_window_width_line_p
)))
13052 /* Stop if last visible row. */
13053 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
13063 /* Find the first glyph row in the current matrix of W that is not
13064 affected by changes at the end of current_buffer since the
13065 time W's current matrix was built.
13067 Return in *DELTA the number of chars by which buffer positions in
13068 unchanged text at the end of current_buffer must be adjusted.
13070 Return in *DELTA_BYTES the corresponding number of bytes.
13072 Value is null if no such row exists, i.e. all rows are affected by
13075 static struct glyph_row
*
13076 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
13078 int *delta
, *delta_bytes
;
13080 struct glyph_row
*row
;
13081 struct glyph_row
*row_found
= NULL
;
13083 *delta
= *delta_bytes
= 0;
13085 /* Display must not have been paused, otherwise the current matrix
13086 is not up to date. */
13087 if (NILP (w
->window_end_valid
))
13090 /* A value of window_end_pos >= END_UNCHANGED means that the window
13091 end is in the range of changed text. If so, there is no
13092 unchanged row at the end of W's current matrix. */
13093 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
13096 /* Set row to the last row in W's current matrix displaying text. */
13097 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13099 /* If matrix is entirely empty, no unchanged row exists. */
13100 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13102 /* The value of row is the last glyph row in the matrix having a
13103 meaningful buffer position in it. The end position of row
13104 corresponds to window_end_pos. This allows us to translate
13105 buffer positions in the current matrix to current buffer
13106 positions for characters not in changed text. */
13107 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13108 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13109 int last_unchanged_pos
, last_unchanged_pos_old
;
13110 struct glyph_row
*first_text_row
13111 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13113 *delta
= Z
- Z_old
;
13114 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13116 /* Set last_unchanged_pos to the buffer position of the last
13117 character in the buffer that has not been changed. Z is the
13118 index + 1 of the last character in current_buffer, i.e. by
13119 subtracting END_UNCHANGED we get the index of the last
13120 unchanged character, and we have to add BEG to get its buffer
13122 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
13123 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
13125 /* Search backward from ROW for a row displaying a line that
13126 starts at a minimum position >= last_unchanged_pos_old. */
13127 for (; row
> first_text_row
; --row
)
13129 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13132 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
13137 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
13144 /* Make sure that glyph rows in the current matrix of window W
13145 reference the same glyph memory as corresponding rows in the
13146 frame's frame matrix. This function is called after scrolling W's
13147 current matrix on a terminal frame in try_window_id and
13148 try_window_reusing_current_matrix. */
13151 sync_frame_with_window_matrix_rows (w
)
13154 struct frame
*f
= XFRAME (w
->frame
);
13155 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
13157 /* Preconditions: W must be a leaf window and full-width. Its frame
13158 must have a frame matrix. */
13159 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
13160 xassert (WINDOW_FULL_WIDTH_P (w
));
13161 xassert (!FRAME_WINDOW_P (f
));
13163 /* If W is a full-width window, glyph pointers in W's current matrix
13164 have, by definition, to be the same as glyph pointers in the
13165 corresponding frame matrix. Note that frame matrices have no
13166 marginal areas (see build_frame_matrix). */
13167 window_row
= w
->current_matrix
->rows
;
13168 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
13169 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
13170 while (window_row
< window_row_end
)
13172 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
13173 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
13175 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
13176 frame_row
->glyphs
[TEXT_AREA
] = start
;
13177 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
13178 frame_row
->glyphs
[LAST_AREA
] = end
;
13180 /* Disable frame rows whose corresponding window rows have
13181 been disabled in try_window_id. */
13182 if (!window_row
->enabled_p
)
13183 frame_row
->enabled_p
= 0;
13185 ++window_row
, ++frame_row
;
13190 /* Find the glyph row in window W containing CHARPOS. Consider all
13191 rows between START and END (not inclusive). END null means search
13192 all rows to the end of the display area of W. Value is the row
13193 containing CHARPOS or null. */
13196 row_containing_pos (w
, charpos
, start
, end
, dy
)
13199 struct glyph_row
*start
, *end
;
13202 struct glyph_row
*row
= start
;
13205 /* If we happen to start on a header-line, skip that. */
13206 if (row
->mode_line_p
)
13209 if ((end
&& row
>= end
) || !row
->enabled_p
)
13212 last_y
= window_text_bottom_y (w
) - dy
;
13216 /* Give up if we have gone too far. */
13217 if (end
&& row
>= end
)
13219 /* This formerly returned if they were equal.
13220 I think that both quantities are of a "last plus one" type;
13221 if so, when they are equal, the row is within the screen. -- rms. */
13222 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
13225 /* If it is in this row, return this row. */
13226 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
13227 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
13228 /* The end position of a row equals the start
13229 position of the next row. If CHARPOS is there, we
13230 would rather display it in the next line, except
13231 when this line ends in ZV. */
13232 && !row
->ends_at_zv_p
13233 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13234 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
13241 /* Try to redisplay window W by reusing its existing display. W's
13242 current matrix must be up to date when this function is called,
13243 i.e. window_end_valid must not be nil.
13247 1 if display has been updated
13248 0 if otherwise unsuccessful
13249 -1 if redisplay with same window start is known not to succeed
13251 The following steps are performed:
13253 1. Find the last row in the current matrix of W that is not
13254 affected by changes at the start of current_buffer. If no such row
13257 2. Find the first row in W's current matrix that is not affected by
13258 changes at the end of current_buffer. Maybe there is no such row.
13260 3. Display lines beginning with the row + 1 found in step 1 to the
13261 row found in step 2 or, if step 2 didn't find a row, to the end of
13264 4. If cursor is not known to appear on the window, give up.
13266 5. If display stopped at the row found in step 2, scroll the
13267 display and current matrix as needed.
13269 6. Maybe display some lines at the end of W, if we must. This can
13270 happen under various circumstances, like a partially visible line
13271 becoming fully visible, or because newly displayed lines are displayed
13272 in smaller font sizes.
13274 7. Update W's window end information. */
13280 struct frame
*f
= XFRAME (w
->frame
);
13281 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
13282 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
13283 struct glyph_row
*last_unchanged_at_beg_row
;
13284 struct glyph_row
*first_unchanged_at_end_row
;
13285 struct glyph_row
*row
;
13286 struct glyph_row
*bottom_row
;
13289 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
13290 struct text_pos start_pos
;
13292 int first_unchanged_at_end_vpos
= 0;
13293 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
13294 struct text_pos start
;
13295 int first_changed_charpos
, last_changed_charpos
;
13298 if (inhibit_try_window_id
)
13302 /* This is handy for debugging. */
13304 #define GIVE_UP(X) \
13306 fprintf (stderr, "try_window_id give up %d\n", (X)); \
13310 #define GIVE_UP(X) return 0
13313 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
13315 /* Don't use this for mini-windows because these can show
13316 messages and mini-buffers, and we don't handle that here. */
13317 if (MINI_WINDOW_P (w
))
13320 /* This flag is used to prevent redisplay optimizations. */
13321 if (windows_or_buffers_changed
|| cursor_type_changed
)
13324 /* Verify that narrowing has not changed.
13325 Also verify that we were not told to prevent redisplay optimizations.
13326 It would be nice to further
13327 reduce the number of cases where this prevents try_window_id. */
13328 if (current_buffer
->clip_changed
13329 || current_buffer
->prevent_redisplay_optimizations_p
)
13332 /* Window must either use window-based redisplay or be full width. */
13333 if (!FRAME_WINDOW_P (f
)
13334 && (!FRAME_LINE_INS_DEL_OK (f
)
13335 || !WINDOW_FULL_WIDTH_P (w
)))
13338 /* Give up if point is not known NOT to appear in W. */
13339 if (PT
< CHARPOS (start
))
13342 /* Another way to prevent redisplay optimizations. */
13343 if (XFASTINT (w
->last_modified
) == 0)
13346 /* Verify that window is not hscrolled. */
13347 if (XFASTINT (w
->hscroll
) != 0)
13350 /* Verify that display wasn't paused. */
13351 if (NILP (w
->window_end_valid
))
13354 /* Can't use this if highlighting a region because a cursor movement
13355 will do more than just set the cursor. */
13356 if (!NILP (Vtransient_mark_mode
)
13357 && !NILP (current_buffer
->mark_active
))
13360 /* Likewise if highlighting trailing whitespace. */
13361 if (!NILP (Vshow_trailing_whitespace
))
13364 /* Likewise if showing a region. */
13365 if (!NILP (w
->region_showing
))
13368 /* Can use this if overlay arrow position and or string have changed. */
13369 if (!EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
13370 || !EQ (last_arrow_string
, Voverlay_arrow_string
))
13374 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
13375 only if buffer has really changed. The reason is that the gap is
13376 initially at Z for freshly visited files. The code below would
13377 set end_unchanged to 0 in that case. */
13378 if (MODIFF
> SAVE_MODIFF
13379 /* This seems to happen sometimes after saving a buffer. */
13380 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
13382 if (GPT
- BEG
< BEG_UNCHANGED
)
13383 BEG_UNCHANGED
= GPT
- BEG
;
13384 if (Z
- GPT
< END_UNCHANGED
)
13385 END_UNCHANGED
= Z
- GPT
;
13388 /* The position of the first and last character that has been changed. */
13389 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
13390 last_changed_charpos
= Z
- END_UNCHANGED
;
13392 /* If window starts after a line end, and the last change is in
13393 front of that newline, then changes don't affect the display.
13394 This case happens with stealth-fontification. Note that although
13395 the display is unchanged, glyph positions in the matrix have to
13396 be adjusted, of course. */
13397 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13398 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13399 && ((last_changed_charpos
< CHARPOS (start
)
13400 && CHARPOS (start
) == BEGV
)
13401 || (last_changed_charpos
< CHARPOS (start
) - 1
13402 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
13404 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
13405 struct glyph_row
*r0
;
13407 /* Compute how many chars/bytes have been added to or removed
13408 from the buffer. */
13409 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13410 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13412 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13414 /* Give up if PT is not in the window. Note that it already has
13415 been checked at the start of try_window_id that PT is not in
13416 front of the window start. */
13417 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
13420 /* If window start is unchanged, we can reuse the whole matrix
13421 as is, after adjusting glyph positions. No need to compute
13422 the window end again, since its offset from Z hasn't changed. */
13423 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13424 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
13425 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
13426 /* PT must not be in a partially visible line. */
13427 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
13428 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13430 /* Adjust positions in the glyph matrix. */
13431 if (delta
|| delta_bytes
)
13433 struct glyph_row
*r1
13434 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13435 increment_matrix_positions (w
->current_matrix
,
13436 MATRIX_ROW_VPOS (r0
, current_matrix
),
13437 MATRIX_ROW_VPOS (r1
, current_matrix
),
13438 delta
, delta_bytes
);
13441 /* Set the cursor. */
13442 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13444 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13451 /* Handle the case that changes are all below what is displayed in
13452 the window, and that PT is in the window. This shortcut cannot
13453 be taken if ZV is visible in the window, and text has been added
13454 there that is visible in the window. */
13455 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
13456 /* ZV is not visible in the window, or there are no
13457 changes at ZV, actually. */
13458 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
13459 || first_changed_charpos
== last_changed_charpos
))
13461 struct glyph_row
*r0
;
13463 /* Give up if PT is not in the window. Note that it already has
13464 been checked at the start of try_window_id that PT is not in
13465 front of the window start. */
13466 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
13469 /* If window start is unchanged, we can reuse the whole matrix
13470 as is, without changing glyph positions since no text has
13471 been added/removed in front of the window end. */
13472 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13473 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
13474 /* PT must not be in a partially visible line. */
13475 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
13476 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13478 /* We have to compute the window end anew since text
13479 can have been added/removed after it. */
13481 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13482 w
->window_end_bytepos
13483 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13485 /* Set the cursor. */
13486 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13488 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13495 /* Give up if window start is in the changed area.
13497 The condition used to read
13499 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
13501 but why that was tested escapes me at the moment. */
13502 if (CHARPOS (start
) >= first_changed_charpos
13503 && CHARPOS (start
) <= last_changed_charpos
)
13506 /* Check that window start agrees with the start of the first glyph
13507 row in its current matrix. Check this after we know the window
13508 start is not in changed text, otherwise positions would not be
13510 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13511 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
13514 /* Give up if the window ends in strings. Overlay strings
13515 at the end are difficult to handle, so don't try. */
13516 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
13517 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
13520 /* Compute the position at which we have to start displaying new
13521 lines. Some of the lines at the top of the window might be
13522 reusable because they are not displaying changed text. Find the
13523 last row in W's current matrix not affected by changes at the
13524 start of current_buffer. Value is null if changes start in the
13525 first line of window. */
13526 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
13527 if (last_unchanged_at_beg_row
)
13529 /* Avoid starting to display in the moddle of a character, a TAB
13530 for instance. This is easier than to set up the iterator
13531 exactly, and it's not a frequent case, so the additional
13532 effort wouldn't really pay off. */
13533 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
13534 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
13535 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
13536 --last_unchanged_at_beg_row
;
13538 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
13541 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
13543 start_pos
= it
.current
.pos
;
13545 /* Start displaying new lines in the desired matrix at the same
13546 vpos we would use in the current matrix, i.e. below
13547 last_unchanged_at_beg_row. */
13548 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
13550 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13551 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
13553 xassert (it
.hpos
== 0 && it
.current_x
== 0);
13557 /* There are no reusable lines at the start of the window.
13558 Start displaying in the first text line. */
13559 start_display (&it
, w
, start
);
13560 it
.vpos
= it
.first_vpos
;
13561 start_pos
= it
.current
.pos
;
13564 /* Find the first row that is not affected by changes at the end of
13565 the buffer. Value will be null if there is no unchanged row, in
13566 which case we must redisplay to the end of the window. delta
13567 will be set to the value by which buffer positions beginning with
13568 first_unchanged_at_end_row have to be adjusted due to text
13570 first_unchanged_at_end_row
13571 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
13572 IF_DEBUG (debug_delta
= delta
);
13573 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
13575 /* Set stop_pos to the buffer position up to which we will have to
13576 display new lines. If first_unchanged_at_end_row != NULL, this
13577 is the buffer position of the start of the line displayed in that
13578 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
13579 that we don't stop at a buffer position. */
13581 if (first_unchanged_at_end_row
)
13583 xassert (last_unchanged_at_beg_row
== NULL
13584 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
13586 /* If this is a continuation line, move forward to the next one
13587 that isn't. Changes in lines above affect this line.
13588 Caution: this may move first_unchanged_at_end_row to a row
13589 not displaying text. */
13590 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
13591 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13592 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13593 < it
.last_visible_y
))
13594 ++first_unchanged_at_end_row
;
13596 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13597 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13598 >= it
.last_visible_y
))
13599 first_unchanged_at_end_row
= NULL
;
13602 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13604 first_unchanged_at_end_vpos
13605 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13606 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13609 else if (last_unchanged_at_beg_row
== NULL
)
13615 /* Either there is no unchanged row at the end, or the one we have
13616 now displays text. This is a necessary condition for the window
13617 end pos calculation at the end of this function. */
13618 xassert (first_unchanged_at_end_row
== NULL
13619 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
13621 debug_last_unchanged_at_beg_vpos
13622 = (last_unchanged_at_beg_row
13623 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
13625 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
13627 #endif /* GLYPH_DEBUG != 0 */
13630 /* Display new lines. Set last_text_row to the last new line
13631 displayed which has text on it, i.e. might end up as being the
13632 line where the window_end_vpos is. */
13633 w
->cursor
.vpos
= -1;
13634 last_text_row
= NULL
;
13635 overlay_arrow_seen
= 0;
13636 while (it
.current_y
< it
.last_visible_y
13637 && !fonts_changed_p
13638 && (first_unchanged_at_end_row
== NULL
13639 || IT_CHARPOS (it
) < stop_pos
))
13641 if (display_line (&it
))
13642 last_text_row
= it
.glyph_row
- 1;
13645 if (fonts_changed_p
)
13649 /* Compute differences in buffer positions, y-positions etc. for
13650 lines reused at the bottom of the window. Compute what we can
13652 if (first_unchanged_at_end_row
13653 /* No lines reused because we displayed everything up to the
13654 bottom of the window. */
13655 && it
.current_y
< it
.last_visible_y
)
13658 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
13660 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
13661 run
.current_y
= first_unchanged_at_end_row
->y
;
13662 run
.desired_y
= run
.current_y
+ dy
;
13663 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
13667 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
13668 first_unchanged_at_end_row
= NULL
;
13670 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
13673 /* Find the cursor if not already found. We have to decide whether
13674 PT will appear on this window (it sometimes doesn't, but this is
13675 not a very frequent case.) This decision has to be made before
13676 the current matrix is altered. A value of cursor.vpos < 0 means
13677 that PT is either in one of the lines beginning at
13678 first_unchanged_at_end_row or below the window. Don't care for
13679 lines that might be displayed later at the window end; as
13680 mentioned, this is not a frequent case. */
13681 if (w
->cursor
.vpos
< 0)
13683 /* Cursor in unchanged rows at the top? */
13684 if (PT
< CHARPOS (start_pos
)
13685 && last_unchanged_at_beg_row
)
13687 row
= row_containing_pos (w
, PT
,
13688 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
13689 last_unchanged_at_beg_row
+ 1, 0);
13691 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13694 /* Start from first_unchanged_at_end_row looking for PT. */
13695 else if (first_unchanged_at_end_row
)
13697 row
= row_containing_pos (w
, PT
- delta
,
13698 first_unchanged_at_end_row
, NULL
, 0);
13700 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
13701 delta_bytes
, dy
, dvpos
);
13704 /* Give up if cursor was not found. */
13705 if (w
->cursor
.vpos
< 0)
13707 clear_glyph_matrix (w
->desired_matrix
);
13712 /* Don't let the cursor end in the scroll margins. */
13714 int this_scroll_margin
, cursor_height
;
13716 this_scroll_margin
= max (0, scroll_margin
);
13717 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13718 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13719 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
13721 if ((w
->cursor
.y
< this_scroll_margin
13722 && CHARPOS (start
) > BEGV
)
13723 /* Don't take scroll margin into account at the bottom because
13724 old redisplay didn't do it either. */
13725 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
13727 w
->cursor
.vpos
= -1;
13728 clear_glyph_matrix (w
->desired_matrix
);
13733 /* Scroll the display. Do it before changing the current matrix so
13734 that xterm.c doesn't get confused about where the cursor glyph is
13736 if (dy
&& run
.height
)
13740 if (FRAME_WINDOW_P (f
))
13742 FRAME_RIF (f
)->update_window_begin_hook (w
);
13743 FRAME_RIF (f
)->clear_window_mouse_face (w
);
13744 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
13745 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
13749 /* Terminal frame. In this case, dvpos gives the number of
13750 lines to scroll by; dvpos < 0 means scroll up. */
13751 int first_unchanged_at_end_vpos
13752 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
13753 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
13754 int end
= (WINDOW_TOP_EDGE_LINE (w
)
13755 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
13756 + window_internal_height (w
));
13758 /* Perform the operation on the screen. */
13761 /* Scroll last_unchanged_at_beg_row to the end of the
13762 window down dvpos lines. */
13763 set_terminal_window (end
);
13765 /* On dumb terminals delete dvpos lines at the end
13766 before inserting dvpos empty lines. */
13767 if (!FRAME_SCROLL_REGION_OK (f
))
13768 ins_del_lines (end
- dvpos
, -dvpos
);
13770 /* Insert dvpos empty lines in front of
13771 last_unchanged_at_beg_row. */
13772 ins_del_lines (from
, dvpos
);
13774 else if (dvpos
< 0)
13776 /* Scroll up last_unchanged_at_beg_vpos to the end of
13777 the window to last_unchanged_at_beg_vpos - |dvpos|. */
13778 set_terminal_window (end
);
13780 /* Delete dvpos lines in front of
13781 last_unchanged_at_beg_vpos. ins_del_lines will set
13782 the cursor to the given vpos and emit |dvpos| delete
13784 ins_del_lines (from
+ dvpos
, dvpos
);
13786 /* On a dumb terminal insert dvpos empty lines at the
13788 if (!FRAME_SCROLL_REGION_OK (f
))
13789 ins_del_lines (end
+ dvpos
, -dvpos
);
13792 set_terminal_window (0);
13798 /* Shift reused rows of the current matrix to the right position.
13799 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
13801 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13802 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
13805 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
13806 bottom_vpos
, dvpos
);
13807 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
13810 else if (dvpos
> 0)
13812 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
13813 bottom_vpos
, dvpos
);
13814 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
13815 first_unchanged_at_end_vpos
+ dvpos
, 0);
13818 /* For frame-based redisplay, make sure that current frame and window
13819 matrix are in sync with respect to glyph memory. */
13820 if (!FRAME_WINDOW_P (f
))
13821 sync_frame_with_window_matrix_rows (w
);
13823 /* Adjust buffer positions in reused rows. */
13825 increment_matrix_positions (current_matrix
,
13826 first_unchanged_at_end_vpos
+ dvpos
,
13827 bottom_vpos
, delta
, delta_bytes
);
13829 /* Adjust Y positions. */
13831 shift_glyph_matrix (w
, current_matrix
,
13832 first_unchanged_at_end_vpos
+ dvpos
,
13835 if (first_unchanged_at_end_row
)
13836 first_unchanged_at_end_row
+= dvpos
;
13838 /* If scrolling up, there may be some lines to display at the end of
13840 last_text_row_at_end
= NULL
;
13843 /* Scrolling up can leave for example a partially visible line
13844 at the end of the window to be redisplayed. */
13845 /* Set last_row to the glyph row in the current matrix where the
13846 window end line is found. It has been moved up or down in
13847 the matrix by dvpos. */
13848 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
13849 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
13851 /* If last_row is the window end line, it should display text. */
13852 xassert (last_row
->displays_text_p
);
13854 /* If window end line was partially visible before, begin
13855 displaying at that line. Otherwise begin displaying with the
13856 line following it. */
13857 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
13859 init_to_row_start (&it
, w
, last_row
);
13860 it
.vpos
= last_vpos
;
13861 it
.current_y
= last_row
->y
;
13865 init_to_row_end (&it
, w
, last_row
);
13866 it
.vpos
= 1 + last_vpos
;
13867 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
13871 /* We may start in a continuation line. If so, we have to
13872 get the right continuation_lines_width and current_x. */
13873 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
13874 it
.hpos
= it
.current_x
= 0;
13876 /* Display the rest of the lines at the window end. */
13877 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13878 while (it
.current_y
< it
.last_visible_y
13879 && !fonts_changed_p
)
13881 /* Is it always sure that the display agrees with lines in
13882 the current matrix? I don't think so, so we mark rows
13883 displayed invalid in the current matrix by setting their
13884 enabled_p flag to zero. */
13885 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
13886 if (display_line (&it
))
13887 last_text_row_at_end
= it
.glyph_row
- 1;
13891 /* Update window_end_pos and window_end_vpos. */
13892 if (first_unchanged_at_end_row
13893 && first_unchanged_at_end_row
->y
< it
.last_visible_y
13894 && !last_text_row_at_end
)
13896 /* Window end line if one of the preserved rows from the current
13897 matrix. Set row to the last row displaying text in current
13898 matrix starting at first_unchanged_at_end_row, after
13900 xassert (first_unchanged_at_end_row
->displays_text_p
);
13901 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
13902 first_unchanged_at_end_row
);
13903 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
13905 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13906 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13908 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
13909 xassert (w
->window_end_bytepos
>= 0);
13910 IF_DEBUG (debug_method_add (w
, "A"));
13912 else if (last_text_row_at_end
)
13915 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
13916 w
->window_end_bytepos
13917 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
13919 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
13920 xassert (w
->window_end_bytepos
>= 0);
13921 IF_DEBUG (debug_method_add (w
, "B"));
13923 else if (last_text_row
)
13925 /* We have displayed either to the end of the window or at the
13926 end of the window, i.e. the last row with text is to be found
13927 in the desired matrix. */
13929 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13930 w
->window_end_bytepos
13931 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13933 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
13934 xassert (w
->window_end_bytepos
>= 0);
13936 else if (first_unchanged_at_end_row
== NULL
13937 && last_text_row
== NULL
13938 && last_text_row_at_end
== NULL
)
13940 /* Displayed to end of window, but no line containing text was
13941 displayed. Lines were deleted at the end of the window. */
13942 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
13943 int vpos
= XFASTINT (w
->window_end_vpos
);
13944 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
13945 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
13948 row
== NULL
&& vpos
>= first_vpos
;
13949 --vpos
, --current_row
, --desired_row
)
13951 if (desired_row
->enabled_p
)
13953 if (desired_row
->displays_text_p
)
13956 else if (current_row
->displays_text_p
)
13960 xassert (row
!= NULL
);
13961 w
->window_end_vpos
= make_number (vpos
+ 1);
13962 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13963 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13964 xassert (w
->window_end_bytepos
>= 0);
13965 IF_DEBUG (debug_method_add (w
, "C"));
13970 #if 0 /* This leads to problems, for instance when the cursor is
13971 at ZV, and the cursor line displays no text. */
13972 /* Disable rows below what's displayed in the window. This makes
13973 debugging easier. */
13974 enable_glyph_matrix_rows (current_matrix
,
13975 XFASTINT (w
->window_end_vpos
) + 1,
13979 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
13980 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
13982 /* Record that display has not been completed. */
13983 w
->window_end_valid
= Qnil
;
13984 w
->desired_matrix
->no_scrolling_p
= 1;
13992 /***********************************************************************
13993 More debugging support
13994 ***********************************************************************/
13998 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
13999 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
14000 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
14003 /* Dump the contents of glyph matrix MATRIX on stderr.
14005 GLYPHS 0 means don't show glyph contents.
14006 GLYPHS 1 means show glyphs in short form
14007 GLYPHS > 1 means show glyphs in long form. */
14010 dump_glyph_matrix (matrix
, glyphs
)
14011 struct glyph_matrix
*matrix
;
14015 for (i
= 0; i
< matrix
->nrows
; ++i
)
14016 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
14020 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
14021 the glyph row and area where the glyph comes from. */
14024 dump_glyph (row
, glyph
, area
)
14025 struct glyph_row
*row
;
14026 struct glyph
*glyph
;
14029 if (glyph
->type
== CHAR_GLYPH
)
14032 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14033 glyph
- row
->glyphs
[TEXT_AREA
],
14036 (BUFFERP (glyph
->object
)
14038 : (STRINGP (glyph
->object
)
14041 glyph
->pixel_width
,
14043 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
14047 glyph
->left_box_line_p
,
14048 glyph
->right_box_line_p
);
14050 else if (glyph
->type
== STRETCH_GLYPH
)
14053 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14054 glyph
- row
->glyphs
[TEXT_AREA
],
14057 (BUFFERP (glyph
->object
)
14059 : (STRINGP (glyph
->object
)
14062 glyph
->pixel_width
,
14066 glyph
->left_box_line_p
,
14067 glyph
->right_box_line_p
);
14069 else if (glyph
->type
== IMAGE_GLYPH
)
14072 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14073 glyph
- row
->glyphs
[TEXT_AREA
],
14076 (BUFFERP (glyph
->object
)
14078 : (STRINGP (glyph
->object
)
14081 glyph
->pixel_width
,
14085 glyph
->left_box_line_p
,
14086 glyph
->right_box_line_p
);
14091 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
14092 GLYPHS 0 means don't show glyph contents.
14093 GLYPHS 1 means show glyphs in short form
14094 GLYPHS > 1 means show glyphs in long form. */
14097 dump_glyph_row (row
, vpos
, glyphs
)
14098 struct glyph_row
*row
;
14103 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
14104 fprintf (stderr
, "=======================================================================\n");
14106 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
14107 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
14109 MATRIX_ROW_START_CHARPOS (row
),
14110 MATRIX_ROW_END_CHARPOS (row
),
14111 row
->used
[TEXT_AREA
],
14112 row
->contains_overlapping_glyphs_p
,
14114 row
->truncated_on_left_p
,
14115 row
->truncated_on_right_p
,
14116 row
->overlay_arrow_p
,
14118 MATRIX_ROW_CONTINUATION_LINE_P (row
),
14119 row
->displays_text_p
,
14122 row
->ends_in_middle_of_char_p
,
14123 row
->starts_in_middle_of_char_p
,
14129 row
->visible_height
,
14132 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
14133 row
->end
.overlay_string_index
,
14134 row
->continuation_lines_width
);
14135 fprintf (stderr
, "%9d %5d\n",
14136 CHARPOS (row
->start
.string_pos
),
14137 CHARPOS (row
->end
.string_pos
));
14138 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
14139 row
->end
.dpvec_index
);
14146 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14148 struct glyph
*glyph
= row
->glyphs
[area
];
14149 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
14151 /* Glyph for a line end in text. */
14152 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
14155 if (glyph
< glyph_end
)
14156 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
14158 for (; glyph
< glyph_end
; ++glyph
)
14159 dump_glyph (row
, glyph
, area
);
14162 else if (glyphs
== 1)
14166 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14168 char *s
= (char *) alloca (row
->used
[area
] + 1);
14171 for (i
= 0; i
< row
->used
[area
]; ++i
)
14173 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
14174 if (glyph
->type
== CHAR_GLYPH
14175 && glyph
->u
.ch
< 0x80
14176 && glyph
->u
.ch
>= ' ')
14177 s
[i
] = glyph
->u
.ch
;
14183 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
14189 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
14190 Sdump_glyph_matrix
, 0, 1, "p",
14191 doc
: /* Dump the current matrix of the selected window to stderr.
14192 Shows contents of glyph row structures. With non-nil
14193 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
14194 glyphs in short form, otherwise show glyphs in long form. */)
14196 Lisp_Object glyphs
;
14198 struct window
*w
= XWINDOW (selected_window
);
14199 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14201 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
14202 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
14203 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
14204 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
14205 fprintf (stderr
, "=============================================\n");
14206 dump_glyph_matrix (w
->current_matrix
,
14207 NILP (glyphs
) ? 0 : XINT (glyphs
));
14212 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
14213 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
14216 struct frame
*f
= XFRAME (selected_frame
);
14217 dump_glyph_matrix (f
->current_matrix
, 1);
14222 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
14223 doc
: /* Dump glyph row ROW to stderr.
14224 GLYPH 0 means don't dump glyphs.
14225 GLYPH 1 means dump glyphs in short form.
14226 GLYPH > 1 or omitted means dump glyphs in long form. */)
14228 Lisp_Object row
, glyphs
;
14230 struct glyph_matrix
*matrix
;
14233 CHECK_NUMBER (row
);
14234 matrix
= XWINDOW (selected_window
)->current_matrix
;
14236 if (vpos
>= 0 && vpos
< matrix
->nrows
)
14237 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
14239 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14244 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
14245 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
14246 GLYPH 0 means don't dump glyphs.
14247 GLYPH 1 means dump glyphs in short form.
14248 GLYPH > 1 or omitted means dump glyphs in long form. */)
14250 Lisp_Object row
, glyphs
;
14252 struct frame
*sf
= SELECTED_FRAME ();
14253 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
14256 CHECK_NUMBER (row
);
14258 if (vpos
>= 0 && vpos
< m
->nrows
)
14259 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
14260 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14265 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
14266 doc
: /* Toggle tracing of redisplay.
14267 With ARG, turn tracing on if and only if ARG is positive. */)
14272 trace_redisplay_p
= !trace_redisplay_p
;
14275 arg
= Fprefix_numeric_value (arg
);
14276 trace_redisplay_p
= XINT (arg
) > 0;
14283 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
14284 doc
: /* Like `format', but print result to stderr.
14285 usage: (trace-to-stderr STRING &rest OBJECTS) */)
14290 Lisp_Object s
= Fformat (nargs
, args
);
14291 fprintf (stderr
, "%s", SDATA (s
));
14295 #endif /* GLYPH_DEBUG */
14299 /***********************************************************************
14300 Building Desired Matrix Rows
14301 ***********************************************************************/
14303 /* Return a temporary glyph row holding the glyphs of an overlay
14304 arrow. Only used for non-window-redisplay windows. */
14306 static struct glyph_row
*
14307 get_overlay_arrow_glyph_row (w
)
14310 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14311 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14312 struct buffer
*old
= current_buffer
;
14313 const unsigned char *arrow_string
= SDATA (Voverlay_arrow_string
);
14314 int arrow_len
= SCHARS (Voverlay_arrow_string
);
14315 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
14316 const unsigned char *p
;
14319 int n_glyphs_before
;
14321 set_buffer_temp (buffer
);
14322 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
14323 it
.glyph_row
->used
[TEXT_AREA
] = 0;
14324 SET_TEXT_POS (it
.position
, 0, 0);
14326 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
14328 while (p
< arrow_end
)
14330 Lisp_Object face
, ilisp
;
14332 /* Get the next character. */
14334 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
14336 it
.c
= *p
, it
.len
= 1;
14339 /* Get its face. */
14340 ilisp
= make_number (p
- arrow_string
);
14341 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
14342 it
.face_id
= compute_char_face (f
, it
.c
, face
);
14344 /* Compute its width, get its glyphs. */
14345 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
14346 SET_TEXT_POS (it
.position
, -1, -1);
14347 PRODUCE_GLYPHS (&it
);
14349 /* If this character doesn't fit any more in the line, we have
14350 to remove some glyphs. */
14351 if (it
.current_x
> it
.last_visible_x
)
14353 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14358 set_buffer_temp (old
);
14359 return it
.glyph_row
;
14363 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
14364 glyphs are only inserted for terminal frames since we can't really
14365 win with truncation glyphs when partially visible glyphs are
14366 involved. Which glyphs to insert is determined by
14367 produce_special_glyphs. */
14370 insert_left_trunc_glyphs (it
)
14373 struct it truncate_it
;
14374 struct glyph
*from
, *end
, *to
, *toend
;
14376 xassert (!FRAME_WINDOW_P (it
->f
));
14378 /* Get the truncation glyphs. */
14380 truncate_it
.current_x
= 0;
14381 truncate_it
.face_id
= DEFAULT_FACE_ID
;
14382 truncate_it
.glyph_row
= &scratch_glyph_row
;
14383 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
14384 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
14385 truncate_it
.object
= make_number (0);
14386 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
14388 /* Overwrite glyphs from IT with truncation glyphs. */
14389 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14390 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
14391 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
14392 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
14397 /* There may be padding glyphs left over. Overwrite them too. */
14398 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
14400 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14406 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
14410 /* Compute the pixel height and width of IT->glyph_row.
14412 Most of the time, ascent and height of a display line will be equal
14413 to the max_ascent and max_height values of the display iterator
14414 structure. This is not the case if
14416 1. We hit ZV without displaying anything. In this case, max_ascent
14417 and max_height will be zero.
14419 2. We have some glyphs that don't contribute to the line height.
14420 (The glyph row flag contributes_to_line_height_p is for future
14421 pixmap extensions).
14423 The first case is easily covered by using default values because in
14424 these cases, the line height does not really matter, except that it
14425 must not be zero. */
14428 compute_line_metrics (it
)
14431 struct glyph_row
*row
= it
->glyph_row
;
14434 if (FRAME_WINDOW_P (it
->f
))
14436 int i
, min_y
, max_y
;
14438 /* The line may consist of one space only, that was added to
14439 place the cursor on it. If so, the row's height hasn't been
14441 if (row
->height
== 0)
14443 if (it
->max_ascent
+ it
->max_descent
== 0)
14444 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
14445 row
->ascent
= it
->max_ascent
;
14446 row
->height
= it
->max_ascent
+ it
->max_descent
;
14447 row
->phys_ascent
= it
->max_phys_ascent
;
14448 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14451 /* Compute the width of this line. */
14452 row
->pixel_width
= row
->x
;
14453 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
14454 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
14456 xassert (row
->pixel_width
>= 0);
14457 xassert (row
->ascent
>= 0 && row
->height
> 0);
14459 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
14460 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
14462 /* If first line's physical ascent is larger than its logical
14463 ascent, use the physical ascent, and make the row taller.
14464 This makes accented characters fully visible. */
14465 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
14466 && row
->phys_ascent
> row
->ascent
)
14468 row
->height
+= row
->phys_ascent
- row
->ascent
;
14469 row
->ascent
= row
->phys_ascent
;
14472 /* Compute how much of the line is visible. */
14473 row
->visible_height
= row
->height
;
14475 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
14476 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
14478 if (row
->y
< min_y
)
14479 row
->visible_height
-= min_y
- row
->y
;
14480 if (row
->y
+ row
->height
> max_y
)
14481 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14485 row
->pixel_width
= row
->used
[TEXT_AREA
];
14486 if (row
->continued_p
)
14487 row
->pixel_width
-= it
->continuation_pixel_width
;
14488 else if (row
->truncated_on_right_p
)
14489 row
->pixel_width
-= it
->truncation_pixel_width
;
14490 row
->ascent
= row
->phys_ascent
= 0;
14491 row
->height
= row
->phys_height
= row
->visible_height
= 1;
14494 /* Compute a hash code for this row. */
14496 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14497 for (i
= 0; i
< row
->used
[area
]; ++i
)
14498 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
14499 + row
->glyphs
[area
][i
].u
.val
14500 + row
->glyphs
[area
][i
].face_id
14501 + row
->glyphs
[area
][i
].padding_p
14502 + (row
->glyphs
[area
][i
].type
<< 2));
14504 it
->max_ascent
= it
->max_descent
= 0;
14505 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
14509 /* Append one space to the glyph row of iterator IT if doing a
14510 window-based redisplay. DEFAULT_FACE_P non-zero means let the
14511 space have the default face, otherwise let it have the same face as
14512 IT->face_id. Value is non-zero if a space was added.
14514 This function is called to make sure that there is always one glyph
14515 at the end of a glyph row that the cursor can be set on under
14516 window-systems. (If there weren't such a glyph we would not know
14517 how wide and tall a box cursor should be displayed).
14519 At the same time this space let's a nicely handle clearing to the
14520 end of the line if the row ends in italic text. */
14523 append_space (it
, default_face_p
)
14525 int default_face_p
;
14527 if (FRAME_WINDOW_P (it
->f
))
14529 int n
= it
->glyph_row
->used
[TEXT_AREA
];
14531 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
14532 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
14534 /* Save some values that must not be changed.
14535 Must save IT->c and IT->len because otherwise
14536 ITERATOR_AT_END_P wouldn't work anymore after
14537 append_space has been called. */
14538 enum display_element_type saved_what
= it
->what
;
14539 int saved_c
= it
->c
, saved_len
= it
->len
;
14540 int saved_x
= it
->current_x
;
14541 int saved_face_id
= it
->face_id
;
14542 struct text_pos saved_pos
;
14543 Lisp_Object saved_object
;
14546 saved_object
= it
->object
;
14547 saved_pos
= it
->position
;
14549 it
->what
= IT_CHARACTER
;
14550 bzero (&it
->position
, sizeof it
->position
);
14551 it
->object
= make_number (0);
14555 if (default_face_p
)
14556 it
->face_id
= DEFAULT_FACE_ID
;
14557 else if (it
->face_before_selective_p
)
14558 it
->face_id
= it
->saved_face_id
;
14559 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14560 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
14562 PRODUCE_GLYPHS (it
);
14564 it
->current_x
= saved_x
;
14565 it
->object
= saved_object
;
14566 it
->position
= saved_pos
;
14567 it
->what
= saved_what
;
14568 it
->face_id
= saved_face_id
;
14569 it
->len
= saved_len
;
14579 /* Extend the face of the last glyph in the text area of IT->glyph_row
14580 to the end of the display line. Called from display_line.
14581 If the glyph row is empty, add a space glyph to it so that we
14582 know the face to draw. Set the glyph row flag fill_line_p. */
14585 extend_face_to_end_of_line (it
)
14589 struct frame
*f
= it
->f
;
14591 /* If line is already filled, do nothing. */
14592 if (it
->current_x
>= it
->last_visible_x
)
14595 /* Face extension extends the background and box of IT->face_id
14596 to the end of the line. If the background equals the background
14597 of the frame, we don't have to do anything. */
14598 if (it
->face_before_selective_p
)
14599 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14601 face
= FACE_FROM_ID (f
, it
->face_id
);
14603 if (FRAME_WINDOW_P (f
)
14604 && face
->box
== FACE_NO_BOX
14605 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
14609 /* Set the glyph row flag indicating that the face of the last glyph
14610 in the text area has to be drawn to the end of the text area. */
14611 it
->glyph_row
->fill_line_p
= 1;
14613 /* If current character of IT is not ASCII, make sure we have the
14614 ASCII face. This will be automatically undone the next time
14615 get_next_display_element returns a multibyte character. Note
14616 that the character will always be single byte in unibyte text. */
14617 if (!SINGLE_BYTE_CHAR_P (it
->c
))
14619 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
14622 if (FRAME_WINDOW_P (f
))
14624 /* If the row is empty, add a space with the current face of IT,
14625 so that we know which face to draw. */
14626 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
14628 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
14629 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
14630 it
->glyph_row
->used
[TEXT_AREA
] = 1;
14635 /* Save some values that must not be changed. */
14636 int saved_x
= it
->current_x
;
14637 struct text_pos saved_pos
;
14638 Lisp_Object saved_object
;
14639 enum display_element_type saved_what
= it
->what
;
14640 int saved_face_id
= it
->face_id
;
14642 saved_object
= it
->object
;
14643 saved_pos
= it
->position
;
14645 it
->what
= IT_CHARACTER
;
14646 bzero (&it
->position
, sizeof it
->position
);
14647 it
->object
= make_number (0);
14650 it
->face_id
= face
->id
;
14652 PRODUCE_GLYPHS (it
);
14654 while (it
->current_x
<= it
->last_visible_x
)
14655 PRODUCE_GLYPHS (it
);
14657 /* Don't count these blanks really. It would let us insert a left
14658 truncation glyph below and make us set the cursor on them, maybe. */
14659 it
->current_x
= saved_x
;
14660 it
->object
= saved_object
;
14661 it
->position
= saved_pos
;
14662 it
->what
= saved_what
;
14663 it
->face_id
= saved_face_id
;
14668 /* Value is non-zero if text starting at CHARPOS in current_buffer is
14669 trailing whitespace. */
14672 trailing_whitespace_p (charpos
)
14675 int bytepos
= CHAR_TO_BYTE (charpos
);
14678 while (bytepos
< ZV_BYTE
14679 && (c
= FETCH_CHAR (bytepos
),
14680 c
== ' ' || c
== '\t'))
14683 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
14685 if (bytepos
!= PT_BYTE
)
14692 /* Highlight trailing whitespace, if any, in ROW. */
14695 highlight_trailing_whitespace (f
, row
)
14697 struct glyph_row
*row
;
14699 int used
= row
->used
[TEXT_AREA
];
14703 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
14704 struct glyph
*glyph
= start
+ used
- 1;
14706 /* Skip over glyphs inserted to display the cursor at the
14707 end of a line, for extending the face of the last glyph
14708 to the end of the line on terminals, and for truncation
14709 and continuation glyphs. */
14710 while (glyph
>= start
14711 && glyph
->type
== CHAR_GLYPH
14712 && INTEGERP (glyph
->object
))
14715 /* If last glyph is a space or stretch, and it's trailing
14716 whitespace, set the face of all trailing whitespace glyphs in
14717 IT->glyph_row to `trailing-whitespace'. */
14719 && BUFFERP (glyph
->object
)
14720 && (glyph
->type
== STRETCH_GLYPH
14721 || (glyph
->type
== CHAR_GLYPH
14722 && glyph
->u
.ch
== ' '))
14723 && trailing_whitespace_p (glyph
->charpos
))
14725 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
14727 while (glyph
>= start
14728 && BUFFERP (glyph
->object
)
14729 && (glyph
->type
== STRETCH_GLYPH
14730 || (glyph
->type
== CHAR_GLYPH
14731 && glyph
->u
.ch
== ' ')))
14732 (glyph
--)->face_id
= face_id
;
14738 /* Value is non-zero if glyph row ROW in window W should be
14739 used to hold the cursor. */
14742 cursor_row_p (w
, row
)
14744 struct glyph_row
*row
;
14746 int cursor_row_p
= 1;
14748 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
14750 /* If the row ends with a newline from a string, we don't want
14751 the cursor there (if the row is continued it doesn't end in a
14753 if (CHARPOS (row
->end
.string_pos
) >= 0
14754 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14755 cursor_row_p
= row
->continued_p
;
14757 /* If the row ends at ZV, display the cursor at the end of that
14758 row instead of at the start of the row below. */
14759 else if (row
->ends_at_zv_p
)
14765 return cursor_row_p
;
14769 /* Construct the glyph row IT->glyph_row in the desired matrix of
14770 IT->w from text at the current position of IT. See dispextern.h
14771 for an overview of struct it. Value is non-zero if
14772 IT->glyph_row displays text, as opposed to a line displaying ZV
14779 struct glyph_row
*row
= it
->glyph_row
;
14781 /* We always start displaying at hpos zero even if hscrolled. */
14782 xassert (it
->hpos
== 0 && it
->current_x
== 0);
14784 /* We must not display in a row that's not a text row. */
14785 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
14786 < it
->w
->desired_matrix
->nrows
);
14788 /* Is IT->w showing the region? */
14789 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
14791 /* Clear the result glyph row and enable it. */
14792 prepare_desired_row (row
);
14794 row
->y
= it
->current_y
;
14795 row
->start
= it
->start
;
14796 row
->continuation_lines_width
= it
->continuation_lines_width
;
14797 row
->displays_text_p
= 1;
14798 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
14799 it
->starts_in_middle_of_char_p
= 0;
14801 /* Arrange the overlays nicely for our purposes. Usually, we call
14802 display_line on only one line at a time, in which case this
14803 can't really hurt too much, or we call it on lines which appear
14804 one after another in the buffer, in which case all calls to
14805 recenter_overlay_lists but the first will be pretty cheap. */
14806 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
14808 /* Move over display elements that are not visible because we are
14809 hscrolled. This may stop at an x-position < IT->first_visible_x
14810 if the first glyph is partially visible or if we hit a line end. */
14811 if (it
->current_x
< it
->first_visible_x
)
14812 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
14813 MOVE_TO_POS
| MOVE_TO_X
);
14815 /* Get the initial row height. This is either the height of the
14816 text hscrolled, if there is any, or zero. */
14817 row
->ascent
= it
->max_ascent
;
14818 row
->height
= it
->max_ascent
+ it
->max_descent
;
14819 row
->phys_ascent
= it
->max_phys_ascent
;
14820 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14822 /* Loop generating characters. The loop is left with IT on the next
14823 character to display. */
14826 int n_glyphs_before
, hpos_before
, x_before
;
14828 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
14830 /* Retrieve the next thing to display. Value is zero if end of
14832 if (!get_next_display_element (it
))
14834 /* Maybe add a space at the end of this line that is used to
14835 display the cursor there under X. Set the charpos of the
14836 first glyph of blank lines not corresponding to any text
14838 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
14839 || row
->used
[TEXT_AREA
] == 0)
14841 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
14842 row
->displays_text_p
= 0;
14844 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
14845 && (!MINI_WINDOW_P (it
->w
)
14846 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
14847 row
->indicate_empty_line_p
= 1;
14850 it
->continuation_lines_width
= 0;
14851 row
->ends_at_zv_p
= 1;
14855 /* Now, get the metrics of what we want to display. This also
14856 generates glyphs in `row' (which is IT->glyph_row). */
14857 n_glyphs_before
= row
->used
[TEXT_AREA
];
14860 /* Remember the line height so far in case the next element doesn't
14861 fit on the line. */
14862 if (!it
->truncate_lines_p
)
14864 ascent
= it
->max_ascent
;
14865 descent
= it
->max_descent
;
14866 phys_ascent
= it
->max_phys_ascent
;
14867 phys_descent
= it
->max_phys_descent
;
14870 PRODUCE_GLYPHS (it
);
14872 /* If this display element was in marginal areas, continue with
14874 if (it
->area
!= TEXT_AREA
)
14876 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14877 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14878 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14879 row
->phys_height
= max (row
->phys_height
,
14880 it
->max_phys_ascent
+ it
->max_phys_descent
);
14881 set_iterator_to_next (it
, 1);
14885 /* Does the display element fit on the line? If we truncate
14886 lines, we should draw past the right edge of the window. If
14887 we don't truncate, we want to stop so that we can display the
14888 continuation glyph before the right margin. If lines are
14889 continued, there are two possible strategies for characters
14890 resulting in more than 1 glyph (e.g. tabs): Display as many
14891 glyphs as possible in this line and leave the rest for the
14892 continuation line, or display the whole element in the next
14893 line. Original redisplay did the former, so we do it also. */
14894 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
14895 hpos_before
= it
->hpos
;
14898 if (/* Not a newline. */
14900 /* Glyphs produced fit entirely in the line. */
14901 && it
->current_x
< it
->last_visible_x
)
14903 it
->hpos
+= nglyphs
;
14904 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14905 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14906 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14907 row
->phys_height
= max (row
->phys_height
,
14908 it
->max_phys_ascent
+ it
->max_phys_descent
);
14909 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
14910 row
->x
= x
- it
->first_visible_x
;
14915 struct glyph
*glyph
;
14917 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
14919 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14920 new_x
= x
+ glyph
->pixel_width
;
14922 if (/* Lines are continued. */
14923 !it
->truncate_lines_p
14924 && (/* Glyph doesn't fit on the line. */
14925 new_x
> it
->last_visible_x
14926 /* Or it fits exactly on a window system frame. */
14927 || (new_x
== it
->last_visible_x
14928 && FRAME_WINDOW_P (it
->f
))))
14930 /* End of a continued line. */
14933 || (new_x
== it
->last_visible_x
14934 && FRAME_WINDOW_P (it
->f
)))
14936 /* Current glyph is the only one on the line or
14937 fits exactly on the line. We must continue
14938 the line because we can't draw the cursor
14939 after the glyph. */
14940 row
->continued_p
= 1;
14941 it
->current_x
= new_x
;
14942 it
->continuation_lines_width
+= new_x
;
14944 if (i
== nglyphs
- 1)
14946 set_iterator_to_next (it
, 1);
14947 #ifdef HAVE_WINDOW_SYSTEM
14948 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14950 get_next_display_element (it
);
14951 if (ITERATOR_AT_END_OF_LINE_P (it
))
14953 row
->continued_p
= 0;
14954 row
->exact_window_width_line_p
= 1;
14957 #endif /* HAVE_WINDOW_SYSTEM */
14960 else if (CHAR_GLYPH_PADDING_P (*glyph
)
14961 && !FRAME_WINDOW_P (it
->f
))
14963 /* A padding glyph that doesn't fit on this line.
14964 This means the whole character doesn't fit
14966 row
->used
[TEXT_AREA
] = n_glyphs_before
;
14968 /* Fill the rest of the row with continuation
14969 glyphs like in 20.x. */
14970 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
14971 < row
->glyphs
[1 + TEXT_AREA
])
14972 produce_special_glyphs (it
, IT_CONTINUATION
);
14974 row
->continued_p
= 1;
14975 it
->current_x
= x_before
;
14976 it
->continuation_lines_width
+= x_before
;
14978 /* Restore the height to what it was before the
14979 element not fitting on the line. */
14980 it
->max_ascent
= ascent
;
14981 it
->max_descent
= descent
;
14982 it
->max_phys_ascent
= phys_ascent
;
14983 it
->max_phys_descent
= phys_descent
;
14985 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
14987 /* A TAB that extends past the right edge of the
14988 window. This produces a single glyph on
14989 window system frames. We leave the glyph in
14990 this row and let it fill the row, but don't
14991 consume the TAB. */
14992 it
->continuation_lines_width
+= it
->last_visible_x
;
14993 row
->ends_in_middle_of_char_p
= 1;
14994 row
->continued_p
= 1;
14995 glyph
->pixel_width
= it
->last_visible_x
- x
;
14996 it
->starts_in_middle_of_char_p
= 1;
15000 /* Something other than a TAB that draws past
15001 the right edge of the window. Restore
15002 positions to values before the element. */
15003 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15005 /* Display continuation glyphs. */
15006 if (!FRAME_WINDOW_P (it
->f
))
15007 produce_special_glyphs (it
, IT_CONTINUATION
);
15008 row
->continued_p
= 1;
15010 it
->continuation_lines_width
+= x
;
15012 if (nglyphs
> 1 && i
> 0)
15014 row
->ends_in_middle_of_char_p
= 1;
15015 it
->starts_in_middle_of_char_p
= 1;
15018 /* Restore the height to what it was before the
15019 element not fitting on the line. */
15020 it
->max_ascent
= ascent
;
15021 it
->max_descent
= descent
;
15022 it
->max_phys_ascent
= phys_ascent
;
15023 it
->max_phys_descent
= phys_descent
;
15028 else if (new_x
> it
->first_visible_x
)
15030 /* Increment number of glyphs actually displayed. */
15033 if (x
< it
->first_visible_x
)
15034 /* Glyph is partially visible, i.e. row starts at
15035 negative X position. */
15036 row
->x
= x
- it
->first_visible_x
;
15040 /* Glyph is completely off the left margin of the
15041 window. This should not happen because of the
15042 move_it_in_display_line at the start of this
15043 function, unless the text display area of the
15044 window is empty. */
15045 xassert (it
->first_visible_x
<= it
->last_visible_x
);
15049 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15050 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15051 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15052 row
->phys_height
= max (row
->phys_height
,
15053 it
->max_phys_ascent
+ it
->max_phys_descent
);
15055 /* End of this display line if row is continued. */
15056 if (row
->continued_p
)
15061 /* Is this a line end? If yes, we're also done, after making
15062 sure that a non-default face is extended up to the right
15063 margin of the window. */
15064 if (ITERATOR_AT_END_OF_LINE_P (it
))
15066 int used_before
= row
->used
[TEXT_AREA
];
15068 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
15070 #ifdef HAVE_WINDOW_SYSTEM
15071 /* Add a space at the end of the line that is used to
15072 display the cursor there. */
15073 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15074 append_space (it
, 0);
15075 #endif /* HAVE_WINDOW_SYSTEM */
15077 /* Extend the face to the end of the line. */
15078 extend_face_to_end_of_line (it
);
15080 /* Make sure we have the position. */
15081 if (used_before
== 0)
15082 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
15084 /* Consume the line end. This skips over invisible lines. */
15085 set_iterator_to_next (it
, 1);
15086 it
->continuation_lines_width
= 0;
15090 /* Proceed with next display element. Note that this skips
15091 over lines invisible because of selective display. */
15092 set_iterator_to_next (it
, 1);
15094 /* If we truncate lines, we are done when the last displayed
15095 glyphs reach past the right margin of the window. */
15096 if (it
->truncate_lines_p
15097 && (FRAME_WINDOW_P (it
->f
)
15098 ? (it
->current_x
>= it
->last_visible_x
)
15099 : (it
->current_x
> it
->last_visible_x
)))
15101 /* Maybe add truncation glyphs. */
15102 if (!FRAME_WINDOW_P (it
->f
))
15106 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15107 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15110 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15112 row
->used
[TEXT_AREA
] = i
;
15113 produce_special_glyphs (it
, IT_TRUNCATION
);
15116 #ifdef HAVE_WINDOW_SYSTEM
15119 /* Don't truncate if we can overflow newline into fringe. */
15120 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15122 get_next_display_element (it
);
15123 if (ITERATOR_AT_END_OF_LINE_P (it
))
15125 row
->exact_window_width_line_p
= 1;
15126 goto at_end_of_line
;
15130 #endif /* HAVE_WINDOW_SYSTEM */
15132 row
->truncated_on_right_p
= 1;
15133 it
->continuation_lines_width
= 0;
15134 reseat_at_next_visible_line_start (it
, 0);
15135 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
15136 it
->hpos
= hpos_before
;
15137 it
->current_x
= x_before
;
15142 /* If line is not empty and hscrolled, maybe insert truncation glyphs
15143 at the left window margin. */
15144 if (it
->first_visible_x
15145 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
15147 if (!FRAME_WINDOW_P (it
->f
))
15148 insert_left_trunc_glyphs (it
);
15149 row
->truncated_on_left_p
= 1;
15152 /* If the start of this line is the overlay arrow-position, then
15153 mark this glyph row as the one containing the overlay arrow.
15154 This is clearly a mess with variable size fonts. It would be
15155 better to let it be displayed like cursors under X. */
15156 if (MARKERP (Voverlay_arrow_position
)
15157 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
15158 && (MATRIX_ROW_START_CHARPOS (row
)
15159 == marker_position (Voverlay_arrow_position
))
15160 && STRINGP (Voverlay_arrow_string
)
15161 && ! overlay_arrow_seen
)
15163 /* Overlay arrow in window redisplay is a fringe bitmap. */
15164 if (!FRAME_WINDOW_P (it
->f
))
15166 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
15167 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
15168 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
15169 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
15170 struct glyph
*p2
, *end
;
15172 /* Copy the arrow glyphs. */
15173 while (glyph
< arrow_end
)
15176 /* Throw away padding glyphs. */
15178 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15179 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
15185 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
15189 overlay_arrow_seen
= 1;
15190 row
->overlay_arrow_p
= 1;
15193 /* Compute pixel dimensions of this line. */
15194 compute_line_metrics (it
);
15196 /* Remember the position at which this line ends. */
15197 row
->end
= it
->current
;
15199 /* Maybe set the cursor. */
15200 if (it
->w
->cursor
.vpos
< 0
15201 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
15202 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15203 && cursor_row_p (it
->w
, row
))
15204 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
15206 /* Highlight trailing whitespace. */
15207 if (!NILP (Vshow_trailing_whitespace
))
15208 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
15210 /* Prepare for the next line. This line starts horizontally at (X
15211 HPOS) = (0 0). Vertical positions are incremented. As a
15212 convenience for the caller, IT->glyph_row is set to the next
15214 it
->current_x
= it
->hpos
= 0;
15215 it
->current_y
+= row
->height
;
15218 it
->start
= it
->current
;
15219 return row
->displays_text_p
;
15224 /***********************************************************************
15226 ***********************************************************************/
15228 /* Redisplay the menu bar in the frame for window W.
15230 The menu bar of X frames that don't have X toolkit support is
15231 displayed in a special window W->frame->menu_bar_window.
15233 The menu bar of terminal frames is treated specially as far as
15234 glyph matrices are concerned. Menu bar lines are not part of
15235 windows, so the update is done directly on the frame matrix rows
15236 for the menu bar. */
15239 display_menu_bar (w
)
15242 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15247 /* Don't do all this for graphical frames. */
15249 if (!NILP (Vwindow_system
))
15252 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
15257 if (FRAME_MAC_P (f
))
15261 #ifdef USE_X_TOOLKIT
15262 xassert (!FRAME_WINDOW_P (f
));
15263 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
15264 it
.first_visible_x
= 0;
15265 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15266 #else /* not USE_X_TOOLKIT */
15267 if (FRAME_WINDOW_P (f
))
15269 /* Menu bar lines are displayed in the desired matrix of the
15270 dummy window menu_bar_window. */
15271 struct window
*menu_w
;
15272 xassert (WINDOWP (f
->menu_bar_window
));
15273 menu_w
= XWINDOW (f
->menu_bar_window
);
15274 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
15276 it
.first_visible_x
= 0;
15277 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15281 /* This is a TTY frame, i.e. character hpos/vpos are used as
15283 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
15285 it
.first_visible_x
= 0;
15286 it
.last_visible_x
= FRAME_COLS (f
);
15288 #endif /* not USE_X_TOOLKIT */
15290 if (! mode_line_inverse_video
)
15291 /* Force the menu-bar to be displayed in the default face. */
15292 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15294 /* Clear all rows of the menu bar. */
15295 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
15297 struct glyph_row
*row
= it
.glyph_row
+ i
;
15298 clear_glyph_row (row
);
15299 row
->enabled_p
= 1;
15300 row
->full_width_p
= 1;
15303 /* Display all items of the menu bar. */
15304 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
15305 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
15307 Lisp_Object string
;
15309 /* Stop at nil string. */
15310 string
= AREF (items
, i
+ 1);
15314 /* Remember where item was displayed. */
15315 AREF (items
, i
+ 3) = make_number (it
.hpos
);
15317 /* Display the item, pad with one space. */
15318 if (it
.current_x
< it
.last_visible_x
)
15319 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
15320 SCHARS (string
) + 1, 0, 0, -1);
15323 /* Fill out the line with spaces. */
15324 if (it
.current_x
< it
.last_visible_x
)
15325 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
15327 /* Compute the total height of the lines. */
15328 compute_line_metrics (&it
);
15333 /***********************************************************************
15335 ***********************************************************************/
15337 /* Redisplay mode lines in the window tree whose root is WINDOW. If
15338 FORCE is non-zero, redisplay mode lines unconditionally.
15339 Otherwise, redisplay only mode lines that are garbaged. Value is
15340 the number of windows whose mode lines were redisplayed. */
15343 redisplay_mode_lines (window
, force
)
15344 Lisp_Object window
;
15349 while (!NILP (window
))
15351 struct window
*w
= XWINDOW (window
);
15353 if (WINDOWP (w
->hchild
))
15354 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
15355 else if (WINDOWP (w
->vchild
))
15356 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
15358 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
15359 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
15361 struct text_pos lpoint
;
15362 struct buffer
*old
= current_buffer
;
15364 /* Set the window's buffer for the mode line display. */
15365 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15366 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15368 /* Point refers normally to the selected window. For any
15369 other window, set up appropriate value. */
15370 if (!EQ (window
, selected_window
))
15372 struct text_pos pt
;
15374 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
15375 if (CHARPOS (pt
) < BEGV
)
15376 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15377 else if (CHARPOS (pt
) > (ZV
- 1))
15378 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
15380 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
15383 /* Display mode lines. */
15384 clear_glyph_matrix (w
->desired_matrix
);
15385 if (display_mode_lines (w
))
15388 w
->must_be_updated_p
= 1;
15391 /* Restore old settings. */
15392 set_buffer_internal_1 (old
);
15393 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15403 /* Display the mode and/or top line of window W. Value is the number
15404 of mode lines displayed. */
15407 display_mode_lines (w
)
15410 Lisp_Object old_selected_window
, old_selected_frame
;
15413 old_selected_frame
= selected_frame
;
15414 selected_frame
= w
->frame
;
15415 old_selected_window
= selected_window
;
15416 XSETWINDOW (selected_window
, w
);
15418 /* These will be set while the mode line specs are processed. */
15419 line_number_displayed
= 0;
15420 w
->column_number_displayed
= Qnil
;
15422 if (WINDOW_WANTS_MODELINE_P (w
))
15424 struct window
*sel_w
= XWINDOW (old_selected_window
);
15426 /* Select mode line face based on the real selected window. */
15427 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
15428 current_buffer
->mode_line_format
);
15432 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15434 display_mode_line (w
, HEADER_LINE_FACE_ID
,
15435 current_buffer
->header_line_format
);
15439 selected_frame
= old_selected_frame
;
15440 selected_window
= old_selected_window
;
15445 /* Display mode or top line of window W. FACE_ID specifies which line
15446 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
15447 FORMAT is the mode line format to display. Value is the pixel
15448 height of the mode line displayed. */
15451 display_mode_line (w
, face_id
, format
)
15453 enum face_id face_id
;
15454 Lisp_Object format
;
15459 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15460 prepare_desired_row (it
.glyph_row
);
15462 if (! mode_line_inverse_video
)
15463 /* Force the mode-line to be displayed in the default face. */
15464 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15466 /* Temporarily make frame's keyboard the current kboard so that
15467 kboard-local variables in the mode_line_format will get the right
15469 push_frame_kboard (it
.f
);
15470 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15471 pop_frame_kboard ();
15473 /* Fill up with spaces. */
15474 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
15476 compute_line_metrics (&it
);
15477 it
.glyph_row
->full_width_p
= 1;
15478 it
.glyph_row
->mode_line_p
= 1;
15479 it
.glyph_row
->continued_p
= 0;
15480 it
.glyph_row
->truncated_on_left_p
= 0;
15481 it
.glyph_row
->truncated_on_right_p
= 0;
15483 /* Make a 3D mode-line have a shadow at its right end. */
15484 face
= FACE_FROM_ID (it
.f
, face_id
);
15485 extend_face_to_end_of_line (&it
);
15486 if (face
->box
!= FACE_NO_BOX
)
15488 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
15489 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
15490 last
->right_box_line_p
= 1;
15493 return it
.glyph_row
->height
;
15496 /* Alist that caches the results of :propertize.
15497 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
15498 Lisp_Object mode_line_proptrans_alist
;
15500 /* List of strings making up the mode-line. */
15501 Lisp_Object mode_line_string_list
;
15503 /* Base face property when building propertized mode line string. */
15504 static Lisp_Object mode_line_string_face
;
15505 static Lisp_Object mode_line_string_face_prop
;
15508 /* Contribute ELT to the mode line for window IT->w. How it
15509 translates into text depends on its data type.
15511 IT describes the display environment in which we display, as usual.
15513 DEPTH is the depth in recursion. It is used to prevent
15514 infinite recursion here.
15516 FIELD_WIDTH is the number of characters the display of ELT should
15517 occupy in the mode line, and PRECISION is the maximum number of
15518 characters to display from ELT's representation. See
15519 display_string for details.
15521 Returns the hpos of the end of the text generated by ELT.
15523 PROPS is a property list to add to any string we encounter.
15525 If RISKY is nonzero, remove (disregard) any properties in any string
15526 we encounter, and ignore :eval and :propertize.
15528 If the global variable `frame_title_ptr' is non-NULL, then the output
15529 is passed to `store_frame_title' instead of `display_string'. */
15532 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
15535 int field_width
, precision
;
15536 Lisp_Object elt
, props
;
15539 int n
= 0, field
, prec
;
15544 elt
= build_string ("*too-deep*");
15548 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
15552 /* A string: output it and check for %-constructs within it. */
15554 const unsigned char *this, *lisp_string
;
15556 if (!NILP (props
) || risky
)
15558 Lisp_Object oprops
, aelt
;
15559 oprops
= Ftext_properties_at (make_number (0), elt
);
15561 if (NILP (Fequal (props
, oprops
)) || risky
)
15563 /* If the starting string has properties,
15564 merge the specified ones onto the existing ones. */
15565 if (! NILP (oprops
) && !risky
)
15569 oprops
= Fcopy_sequence (oprops
);
15571 while (CONSP (tem
))
15573 oprops
= Fplist_put (oprops
, XCAR (tem
),
15574 XCAR (XCDR (tem
)));
15575 tem
= XCDR (XCDR (tem
));
15580 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
15581 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
15583 mode_line_proptrans_alist
15584 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
15591 elt
= Fcopy_sequence (elt
);
15592 Fset_text_properties (make_number (0), Flength (elt
),
15594 /* Add this item to mode_line_proptrans_alist. */
15595 mode_line_proptrans_alist
15596 = Fcons (Fcons (elt
, props
),
15597 mode_line_proptrans_alist
);
15598 /* Truncate mode_line_proptrans_alist
15599 to at most 50 elements. */
15600 tem
= Fnthcdr (make_number (50),
15601 mode_line_proptrans_alist
);
15603 XSETCDR (tem
, Qnil
);
15608 this = SDATA (elt
);
15609 lisp_string
= this;
15613 prec
= precision
- n
;
15614 if (frame_title_ptr
)
15615 n
+= store_frame_title (SDATA (elt
), -1, prec
);
15616 else if (!NILP (mode_line_string_list
))
15617 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
15619 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
15620 0, prec
, 0, STRING_MULTIBYTE (elt
));
15625 while ((precision
<= 0 || n
< precision
)
15627 && (frame_title_ptr
15628 || !NILP (mode_line_string_list
)
15629 || it
->current_x
< it
->last_visible_x
))
15631 const unsigned char *last
= this;
15633 /* Advance to end of string or next format specifier. */
15634 while ((c
= *this++) != '\0' && c
!= '%')
15637 if (this - 1 != last
)
15639 /* Output to end of string or up to '%'. Field width
15640 is length of string. Don't output more than
15641 PRECISION allows us. */
15644 prec
= chars_in_text (last
, this - last
);
15645 if (precision
> 0 && prec
> precision
- n
)
15646 prec
= precision
- n
;
15648 if (frame_title_ptr
)
15649 n
+= store_frame_title (last
, 0, prec
);
15650 else if (!NILP (mode_line_string_list
))
15652 int bytepos
= last
- lisp_string
;
15653 int charpos
= string_byte_to_char (elt
, bytepos
);
15654 n
+= store_mode_line_string (NULL
,
15655 Fsubstring (elt
, make_number (charpos
),
15656 make_number (charpos
+ prec
)),
15661 int bytepos
= last
- lisp_string
;
15662 int charpos
= string_byte_to_char (elt
, bytepos
);
15663 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
15665 STRING_MULTIBYTE (elt
));
15668 else /* c == '%' */
15670 const unsigned char *percent_position
= this;
15672 /* Get the specified minimum width. Zero means
15675 while ((c
= *this++) >= '0' && c
<= '9')
15676 field
= field
* 10 + c
- '0';
15678 /* Don't pad beyond the total padding allowed. */
15679 if (field_width
- n
> 0 && field
> field_width
- n
)
15680 field
= field_width
- n
;
15682 /* Note that either PRECISION <= 0 or N < PRECISION. */
15683 prec
= precision
- n
;
15686 n
+= display_mode_element (it
, depth
, field
, prec
,
15687 Vglobal_mode_string
, props
,
15692 int bytepos
, charpos
;
15693 unsigned char *spec
;
15695 bytepos
= percent_position
- lisp_string
;
15696 charpos
= (STRING_MULTIBYTE (elt
)
15697 ? string_byte_to_char (elt
, bytepos
)
15701 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
15703 if (frame_title_ptr
)
15704 n
+= store_frame_title (spec
, field
, prec
);
15705 else if (!NILP (mode_line_string_list
))
15707 int len
= strlen (spec
);
15708 Lisp_Object tem
= make_string (spec
, len
);
15709 props
= Ftext_properties_at (make_number (charpos
), elt
);
15710 /* Should only keep face property in props */
15711 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
15715 int nglyphs_before
, nwritten
;
15717 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
15718 nwritten
= display_string (spec
, Qnil
, elt
,
15723 /* Assign to the glyphs written above the
15724 string where the `%x' came from, position
15728 struct glyph
*glyph
15729 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
15733 for (i
= 0; i
< nwritten
; ++i
)
15735 glyph
[i
].object
= elt
;
15736 glyph
[i
].charpos
= charpos
;
15751 /* A symbol: process the value of the symbol recursively
15752 as if it appeared here directly. Avoid error if symbol void.
15753 Special case: if value of symbol is a string, output the string
15756 register Lisp_Object tem
;
15758 /* If the variable is not marked as risky to set
15759 then its contents are risky to use. */
15760 if (NILP (Fget (elt
, Qrisky_local_variable
)))
15763 tem
= Fboundp (elt
);
15766 tem
= Fsymbol_value (elt
);
15767 /* If value is a string, output that string literally:
15768 don't check for % within it. */
15772 if (!EQ (tem
, elt
))
15774 /* Give up right away for nil or t. */
15784 register Lisp_Object car
, tem
;
15786 /* A cons cell: five distinct cases.
15787 If first element is :eval or :propertize, do something special.
15788 If first element is a string or a cons, process all the elements
15789 and effectively concatenate them.
15790 If first element is a negative number, truncate displaying cdr to
15791 at most that many characters. If positive, pad (with spaces)
15792 to at least that many characters.
15793 If first element is a symbol, process the cadr or caddr recursively
15794 according to whether the symbol's value is non-nil or nil. */
15796 if (EQ (car
, QCeval
))
15798 /* An element of the form (:eval FORM) means evaluate FORM
15799 and use the result as mode line elements. */
15804 if (CONSP (XCDR (elt
)))
15807 spec
= safe_eval (XCAR (XCDR (elt
)));
15808 n
+= display_mode_element (it
, depth
, field_width
- n
,
15809 precision
- n
, spec
, props
,
15813 else if (EQ (car
, QCpropertize
))
15815 /* An element of the form (:propertize ELT PROPS...)
15816 means display ELT but applying properties PROPS. */
15821 if (CONSP (XCDR (elt
)))
15822 n
+= display_mode_element (it
, depth
, field_width
- n
,
15823 precision
- n
, XCAR (XCDR (elt
)),
15824 XCDR (XCDR (elt
)), risky
);
15826 else if (SYMBOLP (car
))
15828 tem
= Fboundp (car
);
15832 /* elt is now the cdr, and we know it is a cons cell.
15833 Use its car if CAR has a non-nil value. */
15836 tem
= Fsymbol_value (car
);
15843 /* Symbol's value is nil (or symbol is unbound)
15844 Get the cddr of the original list
15845 and if possible find the caddr and use that. */
15849 else if (!CONSP (elt
))
15854 else if (INTEGERP (car
))
15856 register int lim
= XINT (car
);
15860 /* Negative int means reduce maximum width. */
15861 if (precision
<= 0)
15864 precision
= min (precision
, -lim
);
15868 /* Padding specified. Don't let it be more than
15869 current maximum. */
15871 lim
= min (precision
, lim
);
15873 /* If that's more padding than already wanted, queue it.
15874 But don't reduce padding already specified even if
15875 that is beyond the current truncation point. */
15876 field_width
= max (lim
, field_width
);
15880 else if (STRINGP (car
) || CONSP (car
))
15882 register int limit
= 50;
15883 /* Limit is to protect against circular lists. */
15886 && (precision
<= 0 || n
< precision
))
15888 n
+= display_mode_element (it
, depth
, field_width
- n
,
15889 precision
- n
, XCAR (elt
),
15899 elt
= build_string ("*invalid*");
15903 /* Pad to FIELD_WIDTH. */
15904 if (field_width
> 0 && n
< field_width
)
15906 if (frame_title_ptr
)
15907 n
+= store_frame_title ("", field_width
- n
, 0);
15908 else if (!NILP (mode_line_string_list
))
15909 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
15911 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
15918 /* Store a mode-line string element in mode_line_string_list.
15920 If STRING is non-null, display that C string. Otherwise, the Lisp
15921 string LISP_STRING is displayed.
15923 FIELD_WIDTH is the minimum number of output glyphs to produce.
15924 If STRING has fewer characters than FIELD_WIDTH, pad to the right
15925 with spaces. FIELD_WIDTH <= 0 means don't pad.
15927 PRECISION is the maximum number of characters to output from
15928 STRING. PRECISION <= 0 means don't truncate the string.
15930 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
15931 properties to the string.
15933 PROPS are the properties to add to the string.
15934 The mode_line_string_face face property is always added to the string.
15937 static int store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
15939 Lisp_Object lisp_string
;
15948 if (string
!= NULL
)
15950 len
= strlen (string
);
15951 if (precision
> 0 && len
> precision
)
15953 lisp_string
= make_string (string
, len
);
15955 props
= mode_line_string_face_prop
;
15956 else if (!NILP (mode_line_string_face
))
15958 Lisp_Object face
= Fplist_get (props
, Qface
);
15959 props
= Fcopy_sequence (props
);
15961 face
= mode_line_string_face
;
15963 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15964 props
= Fplist_put (props
, Qface
, face
);
15966 Fadd_text_properties (make_number (0), make_number (len
),
15967 props
, lisp_string
);
15971 len
= XFASTINT (Flength (lisp_string
));
15972 if (precision
> 0 && len
> precision
)
15975 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
15978 if (!NILP (mode_line_string_face
))
15982 props
= Ftext_properties_at (make_number (0), lisp_string
);
15983 face
= Fplist_get (props
, Qface
);
15985 face
= mode_line_string_face
;
15987 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15988 props
= Fcons (Qface
, Fcons (face
, Qnil
));
15990 lisp_string
= Fcopy_sequence (lisp_string
);
15993 Fadd_text_properties (make_number (0), make_number (len
),
15994 props
, lisp_string
);
15999 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16003 if (field_width
> len
)
16005 field_width
-= len
;
16006 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
16008 Fadd_text_properties (make_number (0), make_number (field_width
),
16009 props
, lisp_string
);
16010 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16018 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
16020 doc
: /* Return the mode-line of selected window as a string.
16021 First optional arg FORMAT specifies a different format string (see
16022 `mode-line-format' for details) to use. If FORMAT is t, return
16023 the buffer's header-line. Second optional arg WINDOW specifies a
16024 different window to use as the context for the formatting.
16025 If third optional arg NO-PROPS is non-nil, string is not propertized. */)
16026 (format
, window
, no_props
)
16027 Lisp_Object format
, window
, no_props
;
16032 struct buffer
*old_buffer
= NULL
;
16033 enum face_id face_id
= DEFAULT_FACE_ID
;
16036 window
= selected_window
;
16037 CHECK_WINDOW (window
);
16038 w
= XWINDOW (window
);
16039 CHECK_BUFFER (w
->buffer
);
16041 if (XBUFFER (w
->buffer
) != current_buffer
)
16043 old_buffer
= current_buffer
;
16044 set_buffer_internal_1 (XBUFFER (w
->buffer
));
16047 if (NILP (format
) || EQ (format
, Qt
))
16049 face_id
= NILP (format
)
16050 ? CURRENT_MODE_LINE_FACE_ID (w
) :
16051 HEADER_LINE_FACE_ID
;
16052 format
= NILP (format
)
16053 ? current_buffer
->mode_line_format
16054 : current_buffer
->header_line_format
;
16057 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16059 if (NILP (no_props
))
16061 mode_line_string_face
=
16062 (face_id
== MODE_LINE_FACE_ID
? Qmode_line
:
16063 face_id
== MODE_LINE_INACTIVE_FACE_ID
? Qmode_line_inactive
:
16064 face_id
== HEADER_LINE_FACE_ID
? Qheader_line
: Qnil
);
16066 mode_line_string_face_prop
=
16067 NILP (mode_line_string_face
) ? Qnil
:
16068 Fcons (Qface
, Fcons (mode_line_string_face
, Qnil
));
16070 /* We need a dummy last element in mode_line_string_list to
16071 indicate we are building the propertized mode-line string.
16072 Using mode_line_string_face_prop here GC protects it. */
16073 mode_line_string_list
=
16074 Fcons (mode_line_string_face_prop
, Qnil
);
16075 frame_title_ptr
= NULL
;
16079 mode_line_string_face_prop
= Qnil
;
16080 mode_line_string_list
= Qnil
;
16081 frame_title_ptr
= frame_title_buf
;
16084 push_frame_kboard (it
.f
);
16085 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16086 pop_frame_kboard ();
16089 set_buffer_internal_1 (old_buffer
);
16091 if (NILP (no_props
))
16094 mode_line_string_list
= Fnreverse (mode_line_string_list
);
16095 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
16096 make_string ("", 0));
16097 mode_line_string_face_prop
= Qnil
;
16098 mode_line_string_list
= Qnil
;
16102 len
= frame_title_ptr
- frame_title_buf
;
16103 if (len
> 0 && frame_title_ptr
[-1] == '-')
16105 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
16106 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
16108 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
16109 if (len
> frame_title_ptr
- frame_title_buf
)
16110 len
= frame_title_ptr
- frame_title_buf
;
16113 frame_title_ptr
= NULL
;
16114 return make_string (frame_title_buf
, len
);
16117 /* Write a null-terminated, right justified decimal representation of
16118 the positive integer D to BUF using a minimal field width WIDTH. */
16121 pint2str (buf
, width
, d
)
16122 register char *buf
;
16123 register int width
;
16126 register char *p
= buf
;
16134 *p
++ = d
% 10 + '0';
16139 for (width
-= (int) (p
- buf
); width
> 0; --width
)
16150 /* Write a null-terminated, right justified decimal and "human
16151 readable" representation of the nonnegative integer D to BUF using
16152 a minimal field width WIDTH. D should be smaller than 999.5e24. */
16154 static const char power_letter
[] =
16168 pint2hrstr (buf
, width
, d
)
16173 /* We aim to represent the nonnegative integer D as
16174 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
16177 /* -1 means: do not use TENTHS. */
16181 /* Length of QUOTIENT.TENTHS as a string. */
16187 if (1000 <= quotient
)
16189 /* Scale to the appropriate EXPONENT. */
16192 remainder
= quotient
% 1000;
16196 while (1000 <= quotient
);
16198 /* Round to nearest and decide whether to use TENTHS or not. */
16201 tenths
= remainder
/ 100;
16202 if (50 <= remainder
% 100)
16208 if (quotient
== 10)
16215 if (500 <= remainder
)
16216 if (quotient
< 999)
16226 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
16227 if (tenths
== -1 && quotient
<= 99)
16234 p
= psuffix
= buf
+ max (width
, length
);
16236 /* Print EXPONENT. */
16238 *psuffix
++ = power_letter
[exponent
];
16241 /* Print TENTHS. */
16244 *--p
= '0' + tenths
;
16248 /* Print QUOTIENT. */
16251 int digit
= quotient
% 10;
16252 *--p
= '0' + digit
;
16254 while ((quotient
/= 10) != 0);
16256 /* Print leading spaces. */
16261 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
16262 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
16263 type of CODING_SYSTEM. Return updated pointer into BUF. */
16265 static unsigned char invalid_eol_type
[] = "(*invalid*)";
16268 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
16269 Lisp_Object coding_system
;
16270 register char *buf
;
16274 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
16275 const unsigned char *eol_str
;
16277 /* The EOL conversion we are using. */
16278 Lisp_Object eoltype
;
16280 val
= Fget (coding_system
, Qcoding_system
);
16283 if (!VECTORP (val
)) /* Not yet decided. */
16288 eoltype
= eol_mnemonic_undecided
;
16289 /* Don't mention EOL conversion if it isn't decided. */
16293 Lisp_Object eolvalue
;
16295 eolvalue
= Fget (coding_system
, Qeol_type
);
16298 *buf
++ = XFASTINT (AREF (val
, 1));
16302 /* The EOL conversion that is normal on this system. */
16304 if (NILP (eolvalue
)) /* Not yet decided. */
16305 eoltype
= eol_mnemonic_undecided
;
16306 else if (VECTORP (eolvalue
)) /* Not yet decided. */
16307 eoltype
= eol_mnemonic_undecided
;
16308 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
16309 eoltype
= (XFASTINT (eolvalue
) == 0
16310 ? eol_mnemonic_unix
16311 : (XFASTINT (eolvalue
) == 1
16312 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
16318 /* Mention the EOL conversion if it is not the usual one. */
16319 if (STRINGP (eoltype
))
16321 eol_str
= SDATA (eoltype
);
16322 eol_str_len
= SBYTES (eoltype
);
16324 else if (INTEGERP (eoltype
)
16325 && CHAR_VALID_P (XINT (eoltype
), 0))
16327 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
16328 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
16333 eol_str
= invalid_eol_type
;
16334 eol_str_len
= sizeof (invalid_eol_type
) - 1;
16336 bcopy (eol_str
, buf
, eol_str_len
);
16337 buf
+= eol_str_len
;
16343 /* Return a string for the output of a mode line %-spec for window W,
16344 generated by character C. PRECISION >= 0 means don't return a
16345 string longer than that value. FIELD_WIDTH > 0 means pad the
16346 string returned with spaces to that value. Return 1 in *MULTIBYTE
16347 if the result is multibyte text. */
16349 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
16352 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
16355 int field_width
, precision
;
16359 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16360 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
16361 struct buffer
*b
= XBUFFER (w
->buffer
);
16369 if (!NILP (b
->read_only
))
16371 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16376 /* This differs from %* only for a modified read-only buffer. */
16377 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16379 if (!NILP (b
->read_only
))
16384 /* This differs from %* in ignoring read-only-ness. */
16385 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16397 if (command_loop_level
> 5)
16399 p
= decode_mode_spec_buf
;
16400 for (i
= 0; i
< command_loop_level
; i
++)
16403 return decode_mode_spec_buf
;
16411 if (command_loop_level
> 5)
16413 p
= decode_mode_spec_buf
;
16414 for (i
= 0; i
< command_loop_level
; i
++)
16417 return decode_mode_spec_buf
;
16424 /* Let lots_of_dashes be a string of infinite length. */
16425 if (!NILP (mode_line_string_list
))
16427 if (field_width
<= 0
16428 || field_width
> sizeof (lots_of_dashes
))
16430 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
16431 decode_mode_spec_buf
[i
] = '-';
16432 decode_mode_spec_buf
[i
] = '\0';
16433 return decode_mode_spec_buf
;
16436 return lots_of_dashes
;
16445 int col
= (int) current_column (); /* iftc */
16446 w
->column_number_displayed
= make_number (col
);
16447 pint2str (decode_mode_spec_buf
, field_width
, col
);
16448 return decode_mode_spec_buf
;
16452 /* %F displays the frame name. */
16453 if (!NILP (f
->title
))
16454 return (char *) SDATA (f
->title
);
16455 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
16456 return (char *) SDATA (f
->name
);
16465 int size
= ZV
- BEGV
;
16466 pint2str (decode_mode_spec_buf
, field_width
, size
);
16467 return decode_mode_spec_buf
;
16472 int size
= ZV
- BEGV
;
16473 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
16474 return decode_mode_spec_buf
;
16479 int startpos
= XMARKER (w
->start
)->charpos
;
16480 int startpos_byte
= marker_byte_position (w
->start
);
16481 int line
, linepos
, linepos_byte
, topline
;
16483 int height
= WINDOW_TOTAL_LINES (w
);
16485 /* If we decided that this buffer isn't suitable for line numbers,
16486 don't forget that too fast. */
16487 if (EQ (w
->base_line_pos
, w
->buffer
))
16489 /* But do forget it, if the window shows a different buffer now. */
16490 else if (BUFFERP (w
->base_line_pos
))
16491 w
->base_line_pos
= Qnil
;
16493 /* If the buffer is very big, don't waste time. */
16494 if (INTEGERP (Vline_number_display_limit
)
16495 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
16497 w
->base_line_pos
= Qnil
;
16498 w
->base_line_number
= Qnil
;
16502 if (!NILP (w
->base_line_number
)
16503 && !NILP (w
->base_line_pos
)
16504 && XFASTINT (w
->base_line_pos
) <= startpos
)
16506 line
= XFASTINT (w
->base_line_number
);
16507 linepos
= XFASTINT (w
->base_line_pos
);
16508 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
16513 linepos
= BUF_BEGV (b
);
16514 linepos_byte
= BUF_BEGV_BYTE (b
);
16517 /* Count lines from base line to window start position. */
16518 nlines
= display_count_lines (linepos
, linepos_byte
,
16522 topline
= nlines
+ line
;
16524 /* Determine a new base line, if the old one is too close
16525 or too far away, or if we did not have one.
16526 "Too close" means it's plausible a scroll-down would
16527 go back past it. */
16528 if (startpos
== BUF_BEGV (b
))
16530 w
->base_line_number
= make_number (topline
);
16531 w
->base_line_pos
= make_number (BUF_BEGV (b
));
16533 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
16534 || linepos
== BUF_BEGV (b
))
16536 int limit
= BUF_BEGV (b
);
16537 int limit_byte
= BUF_BEGV_BYTE (b
);
16539 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
16541 if (startpos
- distance
> limit
)
16543 limit
= startpos
- distance
;
16544 limit_byte
= CHAR_TO_BYTE (limit
);
16547 nlines
= display_count_lines (startpos
, startpos_byte
,
16549 - (height
* 2 + 30),
16551 /* If we couldn't find the lines we wanted within
16552 line_number_display_limit_width chars per line,
16553 give up on line numbers for this window. */
16554 if (position
== limit_byte
&& limit
== startpos
- distance
)
16556 w
->base_line_pos
= w
->buffer
;
16557 w
->base_line_number
= Qnil
;
16561 w
->base_line_number
= make_number (topline
- nlines
);
16562 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
16565 /* Now count lines from the start pos to point. */
16566 nlines
= display_count_lines (startpos
, startpos_byte
,
16567 PT_BYTE
, PT
, &junk
);
16569 /* Record that we did display the line number. */
16570 line_number_displayed
= 1;
16572 /* Make the string to show. */
16573 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
16574 return decode_mode_spec_buf
;
16577 char* p
= decode_mode_spec_buf
;
16578 int pad
= field_width
- 2;
16584 return decode_mode_spec_buf
;
16590 obj
= b
->mode_name
;
16594 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
16600 int pos
= marker_position (w
->start
);
16601 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16603 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
16605 if (pos
<= BUF_BEGV (b
))
16610 else if (pos
<= BUF_BEGV (b
))
16614 if (total
> 1000000)
16615 /* Do it differently for a large value, to avoid overflow. */
16616 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16618 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16619 /* We can't normally display a 3-digit number,
16620 so get us a 2-digit number that is close. */
16623 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16624 return decode_mode_spec_buf
;
16628 /* Display percentage of size above the bottom of the screen. */
16631 int toppos
= marker_position (w
->start
);
16632 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
16633 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16635 if (botpos
>= BUF_ZV (b
))
16637 if (toppos
<= BUF_BEGV (b
))
16644 if (total
> 1000000)
16645 /* Do it differently for a large value, to avoid overflow. */
16646 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16648 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16649 /* We can't normally display a 3-digit number,
16650 so get us a 2-digit number that is close. */
16653 if (toppos
<= BUF_BEGV (b
))
16654 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
16656 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16657 return decode_mode_spec_buf
;
16662 /* status of process */
16663 obj
= Fget_buffer_process (w
->buffer
);
16665 return "no process";
16666 #ifdef subprocesses
16667 obj
= Fsymbol_name (Fprocess_status (obj
));
16671 case 't': /* indicate TEXT or BINARY */
16672 #ifdef MODE_LINE_BINARY_TEXT
16673 return MODE_LINE_BINARY_TEXT (b
);
16679 /* %T is the frame name on a termcap frame, the empty string otherwise. */
16680 if (! FRAME_TERMCAP_P (f
))
16682 if (!NILP (f
->title
))
16683 return (char *) SDATA (f
->title
);
16684 return (char *) SDATA (f
->name
);
16687 /* coding-system (not including end-of-line format) */
16689 /* coding-system (including end-of-line type) */
16691 int eol_flag
= (c
== 'Z');
16692 char *p
= decode_mode_spec_buf
;
16694 if (! FRAME_WINDOW_P (f
))
16696 /* No need to mention EOL here--the terminal never needs
16697 to do EOL conversion. */
16698 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
16699 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
16701 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
16704 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
16705 #ifdef subprocesses
16706 obj
= Fget_buffer_process (Fcurrent_buffer ());
16707 if (PROCESSP (obj
))
16709 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
16711 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
16714 #endif /* subprocesses */
16717 return decode_mode_spec_buf
;
16723 *multibyte
= STRING_MULTIBYTE (obj
);
16724 return (char *) SDATA (obj
);
16731 /* Count up to COUNT lines starting from START / START_BYTE.
16732 But don't go beyond LIMIT_BYTE.
16733 Return the number of lines thus found (always nonnegative).
16735 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
16738 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
16739 int start
, start_byte
, limit_byte
, count
;
16742 register unsigned char *cursor
;
16743 unsigned char *base
;
16745 register int ceiling
;
16746 register unsigned char *ceiling_addr
;
16747 int orig_count
= count
;
16749 /* If we are not in selective display mode,
16750 check only for newlines. */
16751 int selective_display
= (!NILP (current_buffer
->selective_display
)
16752 && !INTEGERP (current_buffer
->selective_display
));
16756 while (start_byte
< limit_byte
)
16758 ceiling
= BUFFER_CEILING_OF (start_byte
);
16759 ceiling
= min (limit_byte
- 1, ceiling
);
16760 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
16761 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
16764 if (selective_display
)
16765 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
16768 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
16771 if (cursor
!= ceiling_addr
)
16775 start_byte
+= cursor
- base
+ 1;
16776 *byte_pos_ptr
= start_byte
;
16780 if (++cursor
== ceiling_addr
)
16786 start_byte
+= cursor
- base
;
16791 while (start_byte
> limit_byte
)
16793 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
16794 ceiling
= max (limit_byte
, ceiling
);
16795 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
16796 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
16799 if (selective_display
)
16800 while (--cursor
!= ceiling_addr
16801 && *cursor
!= '\n' && *cursor
!= 015)
16804 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
16807 if (cursor
!= ceiling_addr
)
16811 start_byte
+= cursor
- base
+ 1;
16812 *byte_pos_ptr
= start_byte
;
16813 /* When scanning backwards, we should
16814 not count the newline posterior to which we stop. */
16815 return - orig_count
- 1;
16821 /* Here we add 1 to compensate for the last decrement
16822 of CURSOR, which took it past the valid range. */
16823 start_byte
+= cursor
- base
+ 1;
16827 *byte_pos_ptr
= limit_byte
;
16830 return - orig_count
+ count
;
16831 return orig_count
- count
;
16837 /***********************************************************************
16839 ***********************************************************************/
16841 /* Display a NUL-terminated string, starting with index START.
16843 If STRING is non-null, display that C string. Otherwise, the Lisp
16844 string LISP_STRING is displayed.
16846 If FACE_STRING is not nil, FACE_STRING_POS is a position in
16847 FACE_STRING. Display STRING or LISP_STRING with the face at
16848 FACE_STRING_POS in FACE_STRING:
16850 Display the string in the environment given by IT, but use the
16851 standard display table, temporarily.
16853 FIELD_WIDTH is the minimum number of output glyphs to produce.
16854 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16855 with spaces. If STRING has more characters, more than FIELD_WIDTH
16856 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
16858 PRECISION is the maximum number of characters to output from
16859 STRING. PRECISION < 0 means don't truncate the string.
16861 This is roughly equivalent to printf format specifiers:
16863 FIELD_WIDTH PRECISION PRINTF
16864 ----------------------------------------
16870 MULTIBYTE zero means do not display multibyte chars, > 0 means do
16871 display them, and < 0 means obey the current buffer's value of
16872 enable_multibyte_characters.
16874 Value is the number of glyphs produced. */
16877 display_string (string
, lisp_string
, face_string
, face_string_pos
,
16878 start
, it
, field_width
, precision
, max_x
, multibyte
)
16879 unsigned char *string
;
16880 Lisp_Object lisp_string
;
16881 Lisp_Object face_string
;
16882 int face_string_pos
;
16885 int field_width
, precision
, max_x
;
16888 int hpos_at_start
= it
->hpos
;
16889 int saved_face_id
= it
->face_id
;
16890 struct glyph_row
*row
= it
->glyph_row
;
16892 /* Initialize the iterator IT for iteration over STRING beginning
16893 with index START. */
16894 reseat_to_string (it
, string
, lisp_string
, start
,
16895 precision
, field_width
, multibyte
);
16897 /* If displaying STRING, set up the face of the iterator
16898 from LISP_STRING, if that's given. */
16899 if (STRINGP (face_string
))
16905 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
16906 0, it
->region_beg_charpos
,
16907 it
->region_end_charpos
,
16908 &endptr
, it
->base_face_id
, 0);
16909 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16910 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
16913 /* Set max_x to the maximum allowed X position. Don't let it go
16914 beyond the right edge of the window. */
16916 max_x
= it
->last_visible_x
;
16918 max_x
= min (max_x
, it
->last_visible_x
);
16920 /* Skip over display elements that are not visible. because IT->w is
16922 if (it
->current_x
< it
->first_visible_x
)
16923 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
16924 MOVE_TO_POS
| MOVE_TO_X
);
16926 row
->ascent
= it
->max_ascent
;
16927 row
->height
= it
->max_ascent
+ it
->max_descent
;
16928 row
->phys_ascent
= it
->max_phys_ascent
;
16929 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16931 /* This condition is for the case that we are called with current_x
16932 past last_visible_x. */
16933 while (it
->current_x
< max_x
)
16935 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
16937 /* Get the next display element. */
16938 if (!get_next_display_element (it
))
16941 /* Produce glyphs. */
16942 x_before
= it
->current_x
;
16943 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16944 PRODUCE_GLYPHS (it
);
16946 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
16949 while (i
< nglyphs
)
16951 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16953 if (!it
->truncate_lines_p
16954 && x
+ glyph
->pixel_width
> max_x
)
16956 /* End of continued line or max_x reached. */
16957 if (CHAR_GLYPH_PADDING_P (*glyph
))
16959 /* A wide character is unbreakable. */
16960 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16961 it
->current_x
= x_before
;
16965 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16970 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
16972 /* Glyph is at least partially visible. */
16974 if (x
< it
->first_visible_x
)
16975 it
->glyph_row
->x
= x
- it
->first_visible_x
;
16979 /* Glyph is off the left margin of the display area.
16980 Should not happen. */
16984 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16985 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16986 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16987 row
->phys_height
= max (row
->phys_height
,
16988 it
->max_phys_ascent
+ it
->max_phys_descent
);
16989 x
+= glyph
->pixel_width
;
16993 /* Stop if max_x reached. */
16997 /* Stop at line ends. */
16998 if (ITERATOR_AT_END_OF_LINE_P (it
))
17000 it
->continuation_lines_width
= 0;
17004 set_iterator_to_next (it
, 1);
17006 /* Stop if truncating at the right edge. */
17007 if (it
->truncate_lines_p
17008 && it
->current_x
>= it
->last_visible_x
)
17010 /* Add truncation mark, but don't do it if the line is
17011 truncated at a padding space. */
17012 if (IT_CHARPOS (*it
) < it
->string_nchars
)
17014 if (!FRAME_WINDOW_P (it
->f
))
17018 if (it
->current_x
> it
->last_visible_x
)
17020 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17021 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17023 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17025 row
->used
[TEXT_AREA
] = i
;
17026 produce_special_glyphs (it
, IT_TRUNCATION
);
17029 produce_special_glyphs (it
, IT_TRUNCATION
);
17031 it
->glyph_row
->truncated_on_right_p
= 1;
17037 /* Maybe insert a truncation at the left. */
17038 if (it
->first_visible_x
17039 && IT_CHARPOS (*it
) > 0)
17041 if (!FRAME_WINDOW_P (it
->f
))
17042 insert_left_trunc_glyphs (it
);
17043 it
->glyph_row
->truncated_on_left_p
= 1;
17046 it
->face_id
= saved_face_id
;
17048 /* Value is number of columns displayed. */
17049 return it
->hpos
- hpos_at_start
;
17054 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
17055 appears as an element of LIST or as the car of an element of LIST.
17056 If PROPVAL is a list, compare each element against LIST in that
17057 way, and return 1/2 if any element of PROPVAL is found in LIST.
17058 Otherwise return 0. This function cannot quit.
17059 The return value is 2 if the text is invisible but with an ellipsis
17060 and 1 if it's invisible and without an ellipsis. */
17063 invisible_p (propval
, list
)
17064 register Lisp_Object propval
;
17067 register Lisp_Object tail
, proptail
;
17069 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17071 register Lisp_Object tem
;
17073 if (EQ (propval
, tem
))
17075 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
17076 return NILP (XCDR (tem
)) ? 1 : 2;
17079 if (CONSP (propval
))
17081 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
17083 Lisp_Object propelt
;
17084 propelt
= XCAR (proptail
);
17085 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17087 register Lisp_Object tem
;
17089 if (EQ (propelt
, tem
))
17091 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
17092 return NILP (XCDR (tem
)) ? 1 : 2;
17101 /***********************************************************************
17103 ***********************************************************************/
17105 #ifdef HAVE_WINDOW_SYSTEM
17110 dump_glyph_string (s
)
17111 struct glyph_string
*s
;
17113 fprintf (stderr
, "glyph string\n");
17114 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
17115 s
->x
, s
->y
, s
->width
, s
->height
);
17116 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
17117 fprintf (stderr
, " hl = %d\n", s
->hl
);
17118 fprintf (stderr
, " left overhang = %d, right = %d\n",
17119 s
->left_overhang
, s
->right_overhang
);
17120 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
17121 fprintf (stderr
, " extends to end of line = %d\n",
17122 s
->extends_to_end_of_line_p
);
17123 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
17124 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
17127 #endif /* GLYPH_DEBUG */
17129 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
17130 of XChar2b structures for S; it can't be allocated in
17131 init_glyph_string because it must be allocated via `alloca'. W
17132 is the window on which S is drawn. ROW and AREA are the glyph row
17133 and area within the row from which S is constructed. START is the
17134 index of the first glyph structure covered by S. HL is a
17135 face-override for drawing S. */
17138 #define OPTIONAL_HDC(hdc) hdc,
17139 #define DECLARE_HDC(hdc) HDC hdc;
17140 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
17141 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
17144 #ifndef OPTIONAL_HDC
17145 #define OPTIONAL_HDC(hdc)
17146 #define DECLARE_HDC(hdc)
17147 #define ALLOCATE_HDC(hdc, f)
17148 #define RELEASE_HDC(hdc, f)
17152 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
17153 struct glyph_string
*s
;
17157 struct glyph_row
*row
;
17158 enum glyph_row_area area
;
17160 enum draw_glyphs_face hl
;
17162 bzero (s
, sizeof *s
);
17164 s
->f
= XFRAME (w
->frame
);
17168 s
->display
= FRAME_X_DISPLAY (s
->f
);
17169 s
->window
= FRAME_X_WINDOW (s
->f
);
17170 s
->char2b
= char2b
;
17174 s
->first_glyph
= row
->glyphs
[area
] + start
;
17175 s
->height
= row
->height
;
17176 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
17178 /* Display the internal border below the tool-bar window. */
17179 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
17180 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
17182 s
->ybase
= s
->y
+ row
->ascent
;
17186 /* Append the list of glyph strings with head H and tail T to the list
17187 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
17190 append_glyph_string_lists (head
, tail
, h
, t
)
17191 struct glyph_string
**head
, **tail
;
17192 struct glyph_string
*h
, *t
;
17206 /* Prepend the list of glyph strings with head H and tail T to the
17207 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
17211 prepend_glyph_string_lists (head
, tail
, h
, t
)
17212 struct glyph_string
**head
, **tail
;
17213 struct glyph_string
*h
, *t
;
17227 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
17228 Set *HEAD and *TAIL to the resulting list. */
17231 append_glyph_string (head
, tail
, s
)
17232 struct glyph_string
**head
, **tail
;
17233 struct glyph_string
*s
;
17235 s
->next
= s
->prev
= NULL
;
17236 append_glyph_string_lists (head
, tail
, s
, s
);
17240 /* Get face and two-byte form of character glyph GLYPH on frame F.
17241 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
17242 a pointer to a realized face that is ready for display. */
17244 static INLINE
struct face
*
17245 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
17247 struct glyph
*glyph
;
17253 xassert (glyph
->type
== CHAR_GLYPH
);
17254 face
= FACE_FROM_ID (f
, glyph
->face_id
);
17259 if (!glyph
->multibyte_p
)
17261 /* Unibyte case. We don't have to encode, but we have to make
17262 sure to use a face suitable for unibyte. */
17263 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17265 else if (glyph
->u
.ch
< 128
17266 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
17268 /* Case of ASCII in a face known to fit ASCII. */
17269 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17273 int c1
, c2
, charset
;
17275 /* Split characters into bytes. If c2 is -1 afterwards, C is
17276 really a one-byte character so that byte1 is zero. */
17277 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
17279 STORE_XCHAR2B (char2b
, c1
, c2
);
17281 STORE_XCHAR2B (char2b
, 0, c1
);
17283 /* Maybe encode the character in *CHAR2B. */
17284 if (charset
!= CHARSET_ASCII
)
17286 struct font_info
*font_info
17287 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17290 = FRAME_RIF (f
)->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
17294 /* Make sure X resources of the face are allocated. */
17295 xassert (face
!= NULL
);
17296 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17301 /* Fill glyph string S with composition components specified by S->cmp.
17303 FACES is an array of faces for all components of this composition.
17304 S->gidx is the index of the first component for S.
17305 OVERLAPS_P non-zero means S should draw the foreground only, and
17306 use its physical height for clipping.
17308 Value is the index of a component not in S. */
17311 fill_composite_glyph_string (s
, faces
, overlaps_p
)
17312 struct glyph_string
*s
;
17313 struct face
**faces
;
17320 s
->for_overlaps_p
= overlaps_p
;
17322 s
->face
= faces
[s
->gidx
];
17323 s
->font
= s
->face
->font
;
17324 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17326 /* For all glyphs of this composition, starting at the offset
17327 S->gidx, until we reach the end of the definition or encounter a
17328 glyph that requires the different face, add it to S. */
17330 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
17333 /* All glyph strings for the same composition has the same width,
17334 i.e. the width set for the first component of the composition. */
17336 s
->width
= s
->first_glyph
->pixel_width
;
17338 /* If the specified font could not be loaded, use the frame's
17339 default font, but record the fact that we couldn't load it in
17340 the glyph string so that we can draw rectangles for the
17341 characters of the glyph string. */
17342 if (s
->font
== NULL
)
17344 s
->font_not_found_p
= 1;
17345 s
->font
= FRAME_FONT (s
->f
);
17348 /* Adjust base line for subscript/superscript text. */
17349 s
->ybase
+= s
->first_glyph
->voffset
;
17351 xassert (s
->face
&& s
->face
->gc
);
17353 /* This glyph string must always be drawn with 16-bit functions. */
17356 return s
->gidx
+ s
->nchars
;
17360 /* Fill glyph string S from a sequence of character glyphs.
17362 FACE_ID is the face id of the string. START is the index of the
17363 first glyph to consider, END is the index of the last + 1.
17364 OVERLAPS_P non-zero means S should draw the foreground only, and
17365 use its physical height for clipping.
17367 Value is the index of the first glyph not in S. */
17370 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
17371 struct glyph_string
*s
;
17373 int start
, end
, overlaps_p
;
17375 struct glyph
*glyph
, *last
;
17377 int glyph_not_available_p
;
17379 xassert (s
->f
== XFRAME (s
->w
->frame
));
17380 xassert (s
->nchars
== 0);
17381 xassert (start
>= 0 && end
> start
);
17383 s
->for_overlaps_p
= overlaps_p
,
17384 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17385 last
= s
->row
->glyphs
[s
->area
] + end
;
17386 voffset
= glyph
->voffset
;
17388 glyph_not_available_p
= glyph
->glyph_not_available_p
;
17390 while (glyph
< last
17391 && glyph
->type
== CHAR_GLYPH
17392 && glyph
->voffset
== voffset
17393 /* Same face id implies same font, nowadays. */
17394 && glyph
->face_id
== face_id
17395 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
17399 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
17400 s
->char2b
+ s
->nchars
,
17402 s
->two_byte_p
= two_byte_p
;
17404 xassert (s
->nchars
<= end
- start
);
17405 s
->width
+= glyph
->pixel_width
;
17409 s
->font
= s
->face
->font
;
17410 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17412 /* If the specified font could not be loaded, use the frame's font,
17413 but record the fact that we couldn't load it in
17414 S->font_not_found_p so that we can draw rectangles for the
17415 characters of the glyph string. */
17416 if (s
->font
== NULL
|| glyph_not_available_p
)
17418 s
->font_not_found_p
= 1;
17419 s
->font
= FRAME_FONT (s
->f
);
17422 /* Adjust base line for subscript/superscript text. */
17423 s
->ybase
+= voffset
;
17425 xassert (s
->face
&& s
->face
->gc
);
17426 return glyph
- s
->row
->glyphs
[s
->area
];
17430 /* Fill glyph string S from image glyph S->first_glyph. */
17433 fill_image_glyph_string (s
)
17434 struct glyph_string
*s
;
17436 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
17437 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
17439 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
17440 s
->font
= s
->face
->font
;
17441 s
->width
= s
->first_glyph
->pixel_width
;
17443 /* Adjust base line for subscript/superscript text. */
17444 s
->ybase
+= s
->first_glyph
->voffset
;
17448 /* Fill glyph string S from a sequence of stretch glyphs.
17450 ROW is the glyph row in which the glyphs are found, AREA is the
17451 area within the row. START is the index of the first glyph to
17452 consider, END is the index of the last + 1.
17454 Value is the index of the first glyph not in S. */
17457 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
17458 struct glyph_string
*s
;
17459 struct glyph_row
*row
;
17460 enum glyph_row_area area
;
17463 struct glyph
*glyph
, *last
;
17464 int voffset
, face_id
;
17466 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
17468 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17469 last
= s
->row
->glyphs
[s
->area
] + end
;
17470 face_id
= glyph
->face_id
;
17471 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
17472 s
->font
= s
->face
->font
;
17473 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17474 s
->width
= glyph
->pixel_width
;
17475 voffset
= glyph
->voffset
;
17479 && glyph
->type
== STRETCH_GLYPH
17480 && glyph
->voffset
== voffset
17481 && glyph
->face_id
== face_id
);
17483 s
->width
+= glyph
->pixel_width
;
17485 /* Adjust base line for subscript/superscript text. */
17486 s
->ybase
+= voffset
;
17488 /* The case that face->gc == 0 is handled when drawing the glyph
17489 string by calling PREPARE_FACE_FOR_DISPLAY. */
17491 return glyph
- s
->row
->glyphs
[s
->area
];
17496 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
17497 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
17498 assumed to be zero. */
17501 x_get_glyph_overhangs (glyph
, f
, left
, right
)
17502 struct glyph
*glyph
;
17506 *left
= *right
= 0;
17508 if (glyph
->type
== CHAR_GLYPH
)
17512 struct font_info
*font_info
;
17516 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
17518 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17519 if (font
/* ++KFS: Should this be font_info ? */
17520 && (pcm
= FRAME_RIF (f
)->per_char_metric (font
, &char2b
, glyph
->font_type
)))
17522 if (pcm
->rbearing
> pcm
->width
)
17523 *right
= pcm
->rbearing
- pcm
->width
;
17524 if (pcm
->lbearing
< 0)
17525 *left
= -pcm
->lbearing
;
17531 /* Return the index of the first glyph preceding glyph string S that
17532 is overwritten by S because of S's left overhang. Value is -1
17533 if no glyphs are overwritten. */
17536 left_overwritten (s
)
17537 struct glyph_string
*s
;
17541 if (s
->left_overhang
)
17544 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17545 int first
= s
->first_glyph
- glyphs
;
17547 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
17548 x
-= glyphs
[i
].pixel_width
;
17559 /* Return the index of the first glyph preceding glyph string S that
17560 is overwriting S because of its right overhang. Value is -1 if no
17561 glyph in front of S overwrites S. */
17564 left_overwriting (s
)
17565 struct glyph_string
*s
;
17568 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17569 int first
= s
->first_glyph
- glyphs
;
17573 for (i
= first
- 1; i
>= 0; --i
)
17576 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17579 x
-= glyphs
[i
].pixel_width
;
17586 /* Return the index of the last glyph following glyph string S that is
17587 not overwritten by S because of S's right overhang. Value is -1 if
17588 no such glyph is found. */
17591 right_overwritten (s
)
17592 struct glyph_string
*s
;
17596 if (s
->right_overhang
)
17599 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17600 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17601 int end
= s
->row
->used
[s
->area
];
17603 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
17604 x
+= glyphs
[i
].pixel_width
;
17613 /* Return the index of the last glyph following glyph string S that
17614 overwrites S because of its left overhang. Value is negative
17615 if no such glyph is found. */
17618 right_overwriting (s
)
17619 struct glyph_string
*s
;
17622 int end
= s
->row
->used
[s
->area
];
17623 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17624 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17628 for (i
= first
; i
< end
; ++i
)
17631 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17634 x
+= glyphs
[i
].pixel_width
;
17641 /* Get face and two-byte form of character C in face FACE_ID on frame
17642 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
17643 means we want to display multibyte text. DISPLAY_P non-zero means
17644 make sure that X resources for the face returned are allocated.
17645 Value is a pointer to a realized face that is ready for display if
17646 DISPLAY_P is non-zero. */
17648 static INLINE
struct face
*
17649 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
17653 int multibyte_p
, display_p
;
17655 struct face
*face
= FACE_FROM_ID (f
, face_id
);
17659 /* Unibyte case. We don't have to encode, but we have to make
17660 sure to use a face suitable for unibyte. */
17661 STORE_XCHAR2B (char2b
, 0, c
);
17662 face_id
= FACE_FOR_CHAR (f
, face
, c
);
17663 face
= FACE_FROM_ID (f
, face_id
);
17665 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
17667 /* Case of ASCII in a face known to fit ASCII. */
17668 STORE_XCHAR2B (char2b
, 0, c
);
17672 int c1
, c2
, charset
;
17674 /* Split characters into bytes. If c2 is -1 afterwards, C is
17675 really a one-byte character so that byte1 is zero. */
17676 SPLIT_CHAR (c
, charset
, c1
, c2
);
17678 STORE_XCHAR2B (char2b
, c1
, c2
);
17680 STORE_XCHAR2B (char2b
, 0, c1
);
17682 /* Maybe encode the character in *CHAR2B. */
17683 if (face
->font
!= NULL
)
17685 struct font_info
*font_info
17686 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17688 FRAME_RIF (f
)->encode_char (c
, char2b
, font_info
, 0);
17692 /* Make sure X resources of the face are allocated. */
17693 #ifdef HAVE_X_WINDOWS
17697 xassert (face
!= NULL
);
17698 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17705 /* Set background width of glyph string S. START is the index of the
17706 first glyph following S. LAST_X is the right-most x-position + 1
17707 in the drawing area. */
17710 set_glyph_string_background_width (s
, start
, last_x
)
17711 struct glyph_string
*s
;
17715 /* If the face of this glyph string has to be drawn to the end of
17716 the drawing area, set S->extends_to_end_of_line_p. */
17717 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
17719 if (start
== s
->row
->used
[s
->area
]
17720 && s
->area
== TEXT_AREA
17721 && ((s
->hl
== DRAW_NORMAL_TEXT
17722 && (s
->row
->fill_line_p
17723 || s
->face
->background
!= default_face
->background
17724 || s
->face
->stipple
!= default_face
->stipple
17725 || s
->row
->mouse_face_p
))
17726 || s
->hl
== DRAW_MOUSE_FACE
17727 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
17728 && s
->row
->fill_line_p
)))
17729 s
->extends_to_end_of_line_p
= 1;
17731 /* If S extends its face to the end of the line, set its
17732 background_width to the distance to the right edge of the drawing
17734 if (s
->extends_to_end_of_line_p
)
17735 s
->background_width
= last_x
- s
->x
+ 1;
17737 s
->background_width
= s
->width
;
17741 /* Compute overhangs and x-positions for glyph string S and its
17742 predecessors, or successors. X is the starting x-position for S.
17743 BACKWARD_P non-zero means process predecessors. */
17746 compute_overhangs_and_x (s
, x
, backward_p
)
17747 struct glyph_string
*s
;
17755 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
17756 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
17766 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
17767 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
17777 /* The following macros are only called from draw_glyphs below.
17778 They reference the following parameters of that function directly:
17779 `w', `row', `area', and `overlap_p'
17780 as well as the following local variables:
17781 `s', `f', and `hdc' (in W32) */
17784 /* On W32, silently add local `hdc' variable to argument list of
17785 init_glyph_string. */
17786 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17787 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
17789 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17790 init_glyph_string (s, char2b, w, row, area, start, hl)
17793 /* Add a glyph string for a stretch glyph to the list of strings
17794 between HEAD and TAIL. START is the index of the stretch glyph in
17795 row area AREA of glyph row ROW. END is the index of the last glyph
17796 in that glyph row area. X is the current output position assigned
17797 to the new glyph string constructed. HL overrides that face of the
17798 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17799 is the right-most x-position of the drawing area. */
17801 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
17802 and below -- keep them on one line. */
17803 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17806 s = (struct glyph_string *) alloca (sizeof *s); \
17807 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17808 START = fill_stretch_glyph_string (s, row, area, START, END); \
17809 append_glyph_string (&HEAD, &TAIL, s); \
17815 /* Add a glyph string for an image glyph to the list of strings
17816 between HEAD and TAIL. START is the index of the image glyph in
17817 row area AREA of glyph row ROW. END is the index of the last glyph
17818 in that glyph row area. X is the current output position assigned
17819 to the new glyph string constructed. HL overrides that face of the
17820 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17821 is the right-most x-position of the drawing area. */
17823 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17826 s = (struct glyph_string *) alloca (sizeof *s); \
17827 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17828 fill_image_glyph_string (s); \
17829 append_glyph_string (&HEAD, &TAIL, s); \
17836 /* Add a glyph string for a sequence of character glyphs to the list
17837 of strings between HEAD and TAIL. START is the index of the first
17838 glyph in row area AREA of glyph row ROW that is part of the new
17839 glyph string. END is the index of the last glyph in that glyph row
17840 area. X is the current output position assigned to the new glyph
17841 string constructed. HL overrides that face of the glyph; e.g. it
17842 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
17843 right-most x-position of the drawing area. */
17845 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
17851 c = (row)->glyphs[area][START].u.ch; \
17852 face_id = (row)->glyphs[area][START].face_id; \
17854 s = (struct glyph_string *) alloca (sizeof *s); \
17855 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
17856 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
17857 append_glyph_string (&HEAD, &TAIL, s); \
17859 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
17864 /* Add a glyph string for a composite sequence to the list of strings
17865 between HEAD and TAIL. START is the index of the first glyph in
17866 row area AREA of glyph row ROW that is part of the new glyph
17867 string. END is the index of the last glyph in that glyph row area.
17868 X is the current output position assigned to the new glyph string
17869 constructed. HL overrides that face of the glyph; e.g. it is
17870 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
17871 x-position of the drawing area. */
17873 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17875 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
17876 int face_id = (row)->glyphs[area][START].face_id; \
17877 struct face *base_face = FACE_FROM_ID (f, face_id); \
17878 struct composition *cmp = composition_table[cmp_id]; \
17879 int glyph_len = cmp->glyph_len; \
17881 struct face **faces; \
17882 struct glyph_string *first_s = NULL; \
17885 base_face = base_face->ascii_face; \
17886 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
17887 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
17888 /* At first, fill in `char2b' and `faces'. */ \
17889 for (n = 0; n < glyph_len; n++) \
17891 int c = COMPOSITION_GLYPH (cmp, n); \
17892 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
17893 faces[n] = FACE_FROM_ID (f, this_face_id); \
17894 get_char_face_and_encoding (f, c, this_face_id, \
17895 char2b + n, 1, 1); \
17898 /* Make glyph_strings for each glyph sequence that is drawable by \
17899 the same face, and append them to HEAD/TAIL. */ \
17900 for (n = 0; n < cmp->glyph_len;) \
17902 s = (struct glyph_string *) alloca (sizeof *s); \
17903 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
17904 append_glyph_string (&(HEAD), &(TAIL), s); \
17912 n = fill_composite_glyph_string (s, faces, overlaps_p); \
17920 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
17921 of AREA of glyph row ROW on window W between indices START and END.
17922 HL overrides the face for drawing glyph strings, e.g. it is
17923 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
17924 x-positions of the drawing area.
17926 This is an ugly monster macro construct because we must use alloca
17927 to allocate glyph strings (because draw_glyphs can be called
17928 asynchronously). */
17930 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
17933 HEAD = TAIL = NULL; \
17934 while (START < END) \
17936 struct glyph *first_glyph = (row)->glyphs[area] + START; \
17937 switch (first_glyph->type) \
17940 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
17944 case COMPOSITE_GLYPH: \
17945 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
17949 case STRETCH_GLYPH: \
17950 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
17954 case IMAGE_GLYPH: \
17955 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
17963 set_glyph_string_background_width (s, START, LAST_X); \
17970 /* Draw glyphs between START and END in AREA of ROW on window W,
17971 starting at x-position X. X is relative to AREA in W. HL is a
17972 face-override with the following meaning:
17974 DRAW_NORMAL_TEXT draw normally
17975 DRAW_CURSOR draw in cursor face
17976 DRAW_MOUSE_FACE draw in mouse face.
17977 DRAW_INVERSE_VIDEO draw in mode line face
17978 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
17979 DRAW_IMAGE_RAISED draw an image with a raised relief around it
17981 If OVERLAPS_P is non-zero, draw only the foreground of characters
17982 and clip to the physical height of ROW.
17984 Value is the x-position reached, relative to AREA of W. */
17987 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
17990 struct glyph_row
*row
;
17991 enum glyph_row_area area
;
17993 enum draw_glyphs_face hl
;
17996 struct glyph_string
*head
, *tail
;
17997 struct glyph_string
*s
;
17998 int last_x
, area_width
;
18001 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18004 ALLOCATE_HDC (hdc
, f
);
18006 /* Let's rather be paranoid than getting a SEGV. */
18007 end
= min (end
, row
->used
[area
]);
18008 start
= max (0, start
);
18009 start
= min (end
, start
);
18011 /* Translate X to frame coordinates. Set last_x to the right
18012 end of the drawing area. */
18013 if (row
->full_width_p
)
18015 /* X is relative to the left edge of W, without scroll bars
18017 x
+= WINDOW_LEFT_EDGE_X (w
);
18018 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
18022 int area_left
= window_box_left (w
, area
);
18024 area_width
= window_box_width (w
, area
);
18025 last_x
= area_left
+ area_width
;
18028 /* Build a doubly-linked list of glyph_string structures between
18029 head and tail from what we have to draw. Note that the macro
18030 BUILD_GLYPH_STRINGS will modify its start parameter. That's
18031 the reason we use a separate variable `i'. */
18033 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
18035 x_reached
= tail
->x
+ tail
->background_width
;
18039 /* If there are any glyphs with lbearing < 0 or rbearing > width in
18040 the row, redraw some glyphs in front or following the glyph
18041 strings built above. */
18042 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
18045 struct glyph_string
*h
, *t
;
18047 /* Compute overhangs for all glyph strings. */
18048 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
18049 for (s
= head
; s
; s
= s
->next
)
18050 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
18052 /* Prepend glyph strings for glyphs in front of the first glyph
18053 string that are overwritten because of the first glyph
18054 string's left overhang. The background of all strings
18055 prepended must be drawn because the first glyph string
18057 i
= left_overwritten (head
);
18061 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
18062 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18064 compute_overhangs_and_x (t
, head
->x
, 1);
18065 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18068 /* Prepend glyph strings for glyphs in front of the first glyph
18069 string that overwrite that glyph string because of their
18070 right overhang. For these strings, only the foreground must
18071 be drawn, because it draws over the glyph string at `head'.
18072 The background must not be drawn because this would overwrite
18073 right overhangs of preceding glyphs for which no glyph
18075 i
= left_overwriting (head
);
18078 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
18079 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18080 for (s
= h
; s
; s
= s
->next
)
18081 s
->background_filled_p
= 1;
18082 compute_overhangs_and_x (t
, head
->x
, 1);
18083 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18086 /* Append glyphs strings for glyphs following the last glyph
18087 string tail that are overwritten by tail. The background of
18088 these strings has to be drawn because tail's foreground draws
18090 i
= right_overwritten (tail
);
18093 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18094 DRAW_NORMAL_TEXT
, x
, last_x
);
18095 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18096 append_glyph_string_lists (&head
, &tail
, h
, t
);
18099 /* Append glyph strings for glyphs following the last glyph
18100 string tail that overwrite tail. The foreground of such
18101 glyphs has to be drawn because it writes into the background
18102 of tail. The background must not be drawn because it could
18103 paint over the foreground of following glyphs. */
18104 i
= right_overwriting (tail
);
18107 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18108 DRAW_NORMAL_TEXT
, x
, last_x
);
18109 for (s
= h
; s
; s
= s
->next
)
18110 s
->background_filled_p
= 1;
18111 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18112 append_glyph_string_lists (&head
, &tail
, h
, t
);
18116 /* Draw all strings. */
18117 for (s
= head
; s
; s
= s
->next
)
18118 FRAME_RIF (f
)->draw_glyph_string (s
);
18120 if (area
== TEXT_AREA
18121 && !row
->full_width_p
18122 /* When drawing overlapping rows, only the glyph strings'
18123 foreground is drawn, which doesn't erase a cursor
18127 int x0
= head
? head
->x
: x
;
18128 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
18130 int text_left
= window_box_left (w
, TEXT_AREA
);
18134 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
18135 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
18138 /* Value is the x-position up to which drawn, relative to AREA of W.
18139 This doesn't include parts drawn because of overhangs. */
18140 if (row
->full_width_p
)
18141 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
18143 x_reached
-= window_box_left (w
, area
);
18145 RELEASE_HDC (hdc
, f
);
18151 /* Store one glyph for IT->char_to_display in IT->glyph_row.
18152 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18158 struct glyph
*glyph
;
18159 enum glyph_row_area area
= it
->area
;
18161 xassert (it
->glyph_row
);
18162 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
18164 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18165 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18167 glyph
->charpos
= CHARPOS (it
->position
);
18168 glyph
->object
= it
->object
;
18169 glyph
->pixel_width
= it
->pixel_width
;
18170 glyph
->ascent
= it
->ascent
;
18171 glyph
->descent
= it
->descent
;
18172 glyph
->voffset
= it
->voffset
;
18173 glyph
->type
= CHAR_GLYPH
;
18174 glyph
->multibyte_p
= it
->multibyte_p
;
18175 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18176 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18177 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18178 || it
->phys_descent
> it
->descent
);
18179 glyph
->padding_p
= 0;
18180 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
18181 glyph
->face_id
= it
->face_id
;
18182 glyph
->u
.ch
= it
->char_to_display
;
18183 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18184 ++it
->glyph_row
->used
[area
];
18188 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
18189 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18192 append_composite_glyph (it
)
18195 struct glyph
*glyph
;
18196 enum glyph_row_area area
= it
->area
;
18198 xassert (it
->glyph_row
);
18200 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18201 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18203 glyph
->charpos
= CHARPOS (it
->position
);
18204 glyph
->object
= it
->object
;
18205 glyph
->pixel_width
= it
->pixel_width
;
18206 glyph
->ascent
= it
->ascent
;
18207 glyph
->descent
= it
->descent
;
18208 glyph
->voffset
= it
->voffset
;
18209 glyph
->type
= COMPOSITE_GLYPH
;
18210 glyph
->multibyte_p
= it
->multibyte_p
;
18211 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18212 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18213 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18214 || it
->phys_descent
> it
->descent
);
18215 glyph
->padding_p
= 0;
18216 glyph
->glyph_not_available_p
= 0;
18217 glyph
->face_id
= it
->face_id
;
18218 glyph
->u
.cmp_id
= it
->cmp_id
;
18219 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18220 ++it
->glyph_row
->used
[area
];
18225 /* Change IT->ascent and IT->height according to the setting of
18229 take_vertical_position_into_account (it
)
18234 if (it
->voffset
< 0)
18235 /* Increase the ascent so that we can display the text higher
18237 it
->ascent
+= abs (it
->voffset
);
18239 /* Increase the descent so that we can display the text lower
18241 it
->descent
+= it
->voffset
;
18246 /* Produce glyphs/get display metrics for the image IT is loaded with.
18247 See the description of struct display_iterator in dispextern.h for
18248 an overview of struct display_iterator. */
18251 produce_image_glyph (it
)
18256 int face_ascent
, glyph_ascent
;
18258 xassert (it
->what
== IT_IMAGE
);
18260 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18261 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
18264 /* Make sure X resources of the face and image are loaded. */
18265 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18266 prepare_image_for_display (it
->f
, img
);
18268 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
);
18269 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
18270 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
18272 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
18273 face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
18274 if (face_ascent
> it
->ascent
)
18275 it
->ascent
= it
->phys_ascent
= face_ascent
;
18279 if (face
->box
!= FACE_NO_BOX
)
18281 if (face
->box_line_width
> 0)
18283 it
->ascent
+= face
->box_line_width
;
18284 it
->descent
+= face
->box_line_width
;
18287 if (it
->start_of_box_run_p
)
18288 it
->pixel_width
+= abs (face
->box_line_width
);
18289 if (it
->end_of_box_run_p
)
18290 it
->pixel_width
+= abs (face
->box_line_width
);
18293 take_vertical_position_into_account (it
);
18297 struct glyph
*glyph
;
18298 enum glyph_row_area area
= it
->area
;
18300 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18301 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18303 glyph
->charpos
= CHARPOS (it
->position
);
18304 glyph
->object
= it
->object
;
18305 glyph
->pixel_width
= it
->pixel_width
;
18306 glyph
->ascent
= glyph_ascent
;
18307 glyph
->descent
= it
->descent
;
18308 glyph
->voffset
= it
->voffset
;
18309 glyph
->type
= IMAGE_GLYPH
;
18310 glyph
->multibyte_p
= it
->multibyte_p
;
18311 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18312 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18313 glyph
->overlaps_vertically_p
= 0;
18314 glyph
->padding_p
= 0;
18315 glyph
->glyph_not_available_p
= 0;
18316 glyph
->face_id
= it
->face_id
;
18317 glyph
->u
.img_id
= img
->id
;
18318 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18319 ++it
->glyph_row
->used
[area
];
18325 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
18326 of the glyph, WIDTH and HEIGHT are the width and height of the
18327 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
18330 append_stretch_glyph (it
, object
, width
, height
, ascent
)
18332 Lisp_Object object
;
18336 struct glyph
*glyph
;
18337 enum glyph_row_area area
= it
->area
;
18339 xassert (ascent
>= 0 && ascent
<= height
);
18341 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18342 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18344 glyph
->charpos
= CHARPOS (it
->position
);
18345 glyph
->object
= object
;
18346 glyph
->pixel_width
= width
;
18347 glyph
->ascent
= ascent
;
18348 glyph
->descent
= height
- ascent
;
18349 glyph
->voffset
= it
->voffset
;
18350 glyph
->type
= STRETCH_GLYPH
;
18351 glyph
->multibyte_p
= it
->multibyte_p
;
18352 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18353 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18354 glyph
->overlaps_vertically_p
= 0;
18355 glyph
->padding_p
= 0;
18356 glyph
->glyph_not_available_p
= 0;
18357 glyph
->face_id
= it
->face_id
;
18358 glyph
->u
.stretch
.ascent
= ascent
;
18359 glyph
->u
.stretch
.height
= height
;
18360 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18361 ++it
->glyph_row
->used
[area
];
18366 /* Calculate a width or height in pixels from a specification using
18367 the following elements:
18370 NUM - a (fractional) multiple of the default font width/height
18371 (NUM) - specifies exactly NUM pixels
18372 UNIT - a fixed number of pixels, see below.
18373 ELEMENT - size of a display element in pixels, see below.
18374 (NUM . SPEC) - equals NUM * SPEC
18375 (+ SPEC SPEC ...) - add pixel values
18376 (- SPEC SPEC ...) - subtract pixel values
18377 (- SPEC) - negate pixel value
18380 INT or FLOAT - a number constant
18381 SYMBOL - use symbol's (buffer local) variable binding.
18384 in - pixels per inch *)
18385 mm - pixels per 1/1000 meter *)
18386 cm - pixels per 1/100 meter *)
18387 width - width of current font in pixels.
18388 height - height of current font in pixels.
18390 *) using the ratio(s) defined in display-pixels-per-inch.
18394 left-fringe - left fringe width in pixels
18395 (left-fringe . nil) - left fringe width if inside margins, else 0
18396 (left-fringe . t) - left fringe width if outside margins, else 0
18398 right-fringe - right fringe width in pixels
18399 (right-fringe . nil) - right fringe width if inside margins, else 0
18400 (right-fringe . t) - right fringe width if outside margins, else 0
18402 left-margin - left margin width in pixels
18403 right-margin - right margin width in pixels
18405 scroll-bar - scroll-bar area width in pixels
18406 (scroll-bar . left) - scroll-bar width if on left, else 0
18407 (scroll-bar . right) - scroll-bar width if on right, else 0
18411 Pixels corresponding to 5 inches:
18414 Total width of non-text areas on left side of window:
18415 (+ left-fringe left-margin (scroll-bar . left))
18417 Total width of fringes if inside display margins:
18418 (+ (left-fringe) (right-fringe))
18420 Width of left margin minus width of 1 character in the default font:
18423 Width of left margin minus width of 2 characters in the current font:
18424 (- left-margin (2 . width))
18426 Width of left fringe plus left margin minus one pixel:
18427 (- (+ left-fringe left-margin) (1))
18428 (+ left-fringe left-margin (- (1)))
18429 (+ left-fringe left-margin (-1))
18433 #define NUMVAL(X) \
18434 ((INTEGERP (X) || FLOATP (X)) \
18439 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
)
18448 #define OK_PIXELS(val) ((*res = (val)), 1)
18450 if (SYMBOLP (prop
))
18452 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18454 char *unit
= SDATA (SYMBOL_NAME (prop
));
18456 if (unit
[0] == 'i' && unit
[1] == 'n')
18458 else if (unit
[0] == 'm' && unit
[1] == 'm')
18460 else if (unit
[0] == 'c' && unit
[1] == 'm')
18467 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18468 || (CONSP (Vdisplay_pixels_per_inch
)
18470 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18471 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18473 return OK_PIXELS (ppi
/ pixels
);
18479 if (EQ (prop
, Qheight
))
18480 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
18481 if (EQ (prop
, Qwidth
))
18482 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
18483 if (EQ (prop
, Qleft_fringe
))
18484 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18485 if (EQ (prop
, Qright_fringe
))
18486 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18487 if (EQ (prop
, Qleft_margin
))
18488 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18489 if (EQ (prop
, Qright_margin
))
18490 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18491 if (EQ (prop
, Qscroll_bar
))
18492 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18494 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18497 if (INTEGERP (prop
) || FLOATP (prop
))
18499 int base_unit
= (width_p
18500 ? FRAME_COLUMN_WIDTH (it
->f
)
18501 : FRAME_LINE_HEIGHT (it
->f
));
18502 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18507 Lisp_Object car
= XCAR (prop
);
18508 Lisp_Object cdr
= XCDR (prop
);
18512 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18518 while (CONSP (cdr
))
18520 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
), font
, width_p
))
18523 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18528 if (EQ (car
, Qminus
))
18530 return OK_PIXELS (pixels
);
18533 if (EQ (car
, Qleft_fringe
))
18534 return OK_PIXELS ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18536 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
18538 if (EQ (car
, Qright_fringe
))
18539 return OK_PIXELS ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18541 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18543 if (EQ (car
, Qscroll_bar
))
18544 return OK_PIXELS ((WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18545 == EQ (cdr
, Qleft
))
18546 ? WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
)
18549 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18552 if (INTEGERP (car
) || FLOATP (car
))
18555 pixels
= XFLOATINT (car
);
18557 return OK_PIXELS (pixels
);
18558 if (calc_pixel_width_or_height (&fact
, it
, cdr
, font
, width_p
))
18559 return OK_PIXELS (pixels
* fact
);
18569 /* Produce a stretch glyph for iterator IT. IT->object is the value
18570 of the glyph property displayed. The value must be a list
18571 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
18574 1. `:width WIDTH' specifies that the space should be WIDTH *
18575 canonical char width wide. WIDTH may be an integer or floating
18578 2. `:relative-width FACTOR' specifies that the width of the stretch
18579 should be computed from the width of the first character having the
18580 `glyph' property, and should be FACTOR times that width.
18582 3. `:align-to HPOS' specifies that the space should be wide enough
18583 to reach HPOS, a value in canonical character units.
18585 Exactly one of the above pairs must be present.
18587 4. `:height HEIGHT' specifies that the height of the stretch produced
18588 should be HEIGHT, measured in canonical character units.
18590 5. `:relative-height FACTOR' specifies that the height of the
18591 stretch should be FACTOR times the height of the characters having
18592 the glyph property.
18594 Either none or exactly one of 4 or 5 must be present.
18596 6. `:ascent ASCENT' specifies that ASCENT percent of the height
18597 of the stretch should be used for the ascent of the stretch.
18598 ASCENT must be in the range 0 <= ASCENT <= 100. */
18601 produce_stretch_glyph (it
)
18604 /* (space :width WIDTH :height HEIGHT ...) */
18605 Lisp_Object prop
, plist
;
18606 int width
= 0, height
= 0;
18607 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
18610 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18611 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
18613 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18615 /* List should start with `space'. */
18616 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
18617 plist
= XCDR (it
->object
);
18619 /* Compute the width of the stretch. */
18620 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
18621 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1))
18623 /* Absolute width `:width WIDTH' specified and valid. */
18624 zero_width_ok_p
= 1;
18627 else if (prop
= Fplist_get (plist
, QCrelative_width
),
18630 /* Relative width `:relative-width FACTOR' specified and valid.
18631 Compute the width of the characters having the `glyph'
18634 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
18637 if (it
->multibyte_p
)
18639 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
18640 - IT_BYTEPOS (*it
));
18641 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
18644 it2
.c
= *p
, it2
.len
= 1;
18646 it2
.glyph_row
= NULL
;
18647 it2
.what
= IT_CHARACTER
;
18648 x_produce_glyphs (&it2
);
18649 width
= NUMVAL (prop
) * it2
.pixel_width
;
18651 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
18652 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1))
18654 width
= max (0, (int)tem
- it
->current_x
);
18655 zero_width_ok_p
= 1;
18658 /* Nothing specified -> width defaults to canonical char width. */
18659 width
= FRAME_COLUMN_WIDTH (it
->f
);
18661 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
18664 /* Compute height. */
18665 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
18666 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0))
18669 zero_height_ok_p
= 1;
18671 else if (prop
= Fplist_get (plist
, QCrelative_height
),
18673 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
18675 height
= FONT_HEIGHT (font
);
18677 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
18680 /* Compute percentage of height used for ascent. If
18681 `:ascent ASCENT' is present and valid, use that. Otherwise,
18682 derive the ascent from the font in use. */
18683 if (prop
= Fplist_get (plist
, QCascent
),
18684 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
18685 ascent
= height
* NUMVAL (prop
) / 100.0;
18686 else if (!NILP (prop
)
18687 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0))
18688 ascent
= min (max (0, (int)tem
), height
);
18690 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
18692 if (width
> 0 && height
> 0 && it
->glyph_row
)
18694 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
18695 if (!STRINGP (object
))
18696 object
= it
->w
->buffer
;
18697 append_stretch_glyph (it
, object
, width
, height
, ascent
);
18700 it
->pixel_width
= width
;
18701 it
->ascent
= it
->phys_ascent
= ascent
;
18702 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
18703 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
18705 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
18707 if (face
->box_line_width
> 0)
18709 it
->ascent
+= face
->box_line_width
;
18710 it
->descent
+= face
->box_line_width
;
18713 if (it
->start_of_box_run_p
)
18714 it
->pixel_width
+= abs (face
->box_line_width
);
18715 if (it
->end_of_box_run_p
)
18716 it
->pixel_width
+= abs (face
->box_line_width
);
18719 take_vertical_position_into_account (it
);
18723 Produce glyphs/get display metrics for the display element IT is
18724 loaded with. See the description of struct display_iterator in
18725 dispextern.h for an overview of struct display_iterator. */
18728 x_produce_glyphs (it
)
18731 it
->glyph_not_available_p
= 0;
18733 if (it
->what
== IT_CHARACTER
)
18737 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18739 int font_not_found_p
;
18740 struct font_info
*font_info
;
18741 int boff
; /* baseline offset */
18742 /* We may change it->multibyte_p upon unibyte<->multibyte
18743 conversion. So, save the current value now and restore it
18746 Note: It seems that we don't have to record multibyte_p in
18747 struct glyph because the character code itself tells if or
18748 not the character is multibyte. Thus, in the future, we must
18749 consider eliminating the field `multibyte_p' in the struct
18751 int saved_multibyte_p
= it
->multibyte_p
;
18753 /* Maybe translate single-byte characters to multibyte, or the
18755 it
->char_to_display
= it
->c
;
18756 if (!ASCII_BYTE_P (it
->c
))
18758 if (unibyte_display_via_language_environment
18759 && SINGLE_BYTE_CHAR_P (it
->c
)
18761 || !NILP (Vnonascii_translation_table
)))
18763 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
18764 it
->multibyte_p
= 1;
18765 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18766 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18768 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
18769 && !it
->multibyte_p
)
18771 it
->multibyte_p
= 1;
18772 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18773 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18777 /* Get font to use. Encode IT->char_to_display. */
18778 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
18779 &char2b
, it
->multibyte_p
, 0);
18782 /* When no suitable font found, use the default font. */
18783 font_not_found_p
= font
== NULL
;
18784 if (font_not_found_p
)
18786 font
= FRAME_FONT (it
->f
);
18787 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18792 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18793 boff
= font_info
->baseline_offset
;
18794 if (font_info
->vertical_centering
)
18795 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18798 if (it
->char_to_display
>= ' '
18799 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
18801 /* Either unibyte or ASCII. */
18806 pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
18807 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
18808 it
->ascent
= FONT_BASE (font
) + boff
;
18809 it
->descent
= FONT_DESCENT (font
) - boff
;
18813 it
->phys_ascent
= pcm
->ascent
+ boff
;
18814 it
->phys_descent
= pcm
->descent
- boff
;
18815 it
->pixel_width
= pcm
->width
;
18819 it
->glyph_not_available_p
= 1;
18820 it
->phys_ascent
= FONT_BASE (font
) + boff
;
18821 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18822 it
->pixel_width
= FONT_WIDTH (font
);
18825 /* If this is a space inside a region of text with
18826 `space-width' property, change its width. */
18827 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
18829 it
->pixel_width
*= XFLOATINT (it
->space_width
);
18831 /* If face has a box, add the box thickness to the character
18832 height. If character has a box line to the left and/or
18833 right, add the box line width to the character's width. */
18834 if (face
->box
!= FACE_NO_BOX
)
18836 int thick
= face
->box_line_width
;
18840 it
->ascent
+= thick
;
18841 it
->descent
+= thick
;
18846 if (it
->start_of_box_run_p
)
18847 it
->pixel_width
+= thick
;
18848 if (it
->end_of_box_run_p
)
18849 it
->pixel_width
+= thick
;
18852 /* If face has an overline, add the height of the overline
18853 (1 pixel) and a 1 pixel margin to the character height. */
18854 if (face
->overline_p
)
18857 take_vertical_position_into_account (it
);
18859 /* If we have to actually produce glyphs, do it. */
18864 /* Translate a space with a `space-width' property
18865 into a stretch glyph. */
18866 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
18867 / FONT_HEIGHT (font
));
18868 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
18869 it
->ascent
+ it
->descent
, ascent
);
18874 /* If characters with lbearing or rbearing are displayed
18875 in this line, record that fact in a flag of the
18876 glyph row. This is used to optimize X output code. */
18877 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
18878 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
18881 else if (it
->char_to_display
== '\n')
18883 /* A newline has no width but we need the height of the line. */
18884 it
->pixel_width
= 0;
18886 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
18887 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18889 if (face
->box
!= FACE_NO_BOX
18890 && face
->box_line_width
> 0)
18892 it
->ascent
+= face
->box_line_width
;
18893 it
->descent
+= face
->box_line_width
;
18896 else if (it
->char_to_display
== '\t')
18898 int tab_width
= it
->tab_width
* FRAME_COLUMN_WIDTH (it
->f
);
18899 int x
= it
->current_x
+ it
->continuation_lines_width
;
18900 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
18902 /* If the distance from the current position to the next tab
18903 stop is less than a canonical character width, use the
18904 tab stop after that. */
18905 if (next_tab_x
- x
< FRAME_COLUMN_WIDTH (it
->f
))
18906 next_tab_x
+= tab_width
;
18908 it
->pixel_width
= next_tab_x
- x
;
18910 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
18911 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18915 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
18916 it
->ascent
+ it
->descent
, it
->ascent
);
18921 /* A multi-byte character. Assume that the display width of the
18922 character is the width of the character multiplied by the
18923 width of the font. */
18925 /* If we found a font, this font should give us the right
18926 metrics. If we didn't find a font, use the frame's
18927 default font and calculate the width of the character
18928 from the charset width; this is what old redisplay code
18931 pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
18932 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
18934 if (font_not_found_p
|| !pcm
)
18936 int charset
= CHAR_CHARSET (it
->char_to_display
);
18938 it
->glyph_not_available_p
= 1;
18939 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
18940 * CHARSET_WIDTH (charset
));
18941 it
->phys_ascent
= FONT_BASE (font
) + boff
;
18942 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18946 it
->pixel_width
= pcm
->width
;
18947 it
->phys_ascent
= pcm
->ascent
+ boff
;
18948 it
->phys_descent
= pcm
->descent
- boff
;
18950 && (pcm
->lbearing
< 0
18951 || pcm
->rbearing
> pcm
->width
))
18952 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
18955 it
->ascent
= FONT_BASE (font
) + boff
;
18956 it
->descent
= FONT_DESCENT (font
) - boff
;
18957 if (face
->box
!= FACE_NO_BOX
)
18959 int thick
= face
->box_line_width
;
18963 it
->ascent
+= thick
;
18964 it
->descent
+= thick
;
18969 if (it
->start_of_box_run_p
)
18970 it
->pixel_width
+= thick
;
18971 if (it
->end_of_box_run_p
)
18972 it
->pixel_width
+= thick
;
18975 /* If face has an overline, add the height of the overline
18976 (1 pixel) and a 1 pixel margin to the character height. */
18977 if (face
->overline_p
)
18980 take_vertical_position_into_account (it
);
18985 it
->multibyte_p
= saved_multibyte_p
;
18987 else if (it
->what
== IT_COMPOSITION
)
18989 /* Note: A composition is represented as one glyph in the
18990 glyph matrix. There are no padding glyphs. */
18993 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18995 int font_not_found_p
;
18996 struct font_info
*font_info
;
18997 int boff
; /* baseline offset */
18998 struct composition
*cmp
= composition_table
[it
->cmp_id
];
19000 /* Maybe translate single-byte characters to multibyte. */
19001 it
->char_to_display
= it
->c
;
19002 if (unibyte_display_via_language_environment
19003 && SINGLE_BYTE_CHAR_P (it
->c
)
19006 && !NILP (Vnonascii_translation_table
))))
19008 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19011 /* Get face and font to use. Encode IT->char_to_display. */
19012 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19013 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19014 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19015 &char2b
, it
->multibyte_p
, 0);
19018 /* When no suitable font found, use the default font. */
19019 font_not_found_p
= font
== NULL
;
19020 if (font_not_found_p
)
19022 font
= FRAME_FONT (it
->f
);
19023 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19028 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19029 boff
= font_info
->baseline_offset
;
19030 if (font_info
->vertical_centering
)
19031 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19034 /* There are no padding glyphs, so there is only one glyph to
19035 produce for the composition. Important is that pixel_width,
19036 ascent and descent are the values of what is drawn by
19037 draw_glyphs (i.e. the values of the overall glyphs composed). */
19040 /* If we have not yet calculated pixel size data of glyphs of
19041 the composition for the current face font, calculate them
19042 now. Theoretically, we have to check all fonts for the
19043 glyphs, but that requires much time and memory space. So,
19044 here we check only the font of the first glyph. This leads
19045 to incorrect display very rarely, and C-l (recenter) can
19046 correct the display anyway. */
19047 if (cmp
->font
!= (void *) font
)
19049 /* Ascent and descent of the font of the first character of
19050 this composition (adjusted by baseline offset). Ascent
19051 and descent of overall glyphs should not be less than
19052 them respectively. */
19053 int font_ascent
= FONT_BASE (font
) + boff
;
19054 int font_descent
= FONT_DESCENT (font
) - boff
;
19055 /* Bounding box of the overall glyphs. */
19056 int leftmost
, rightmost
, lowest
, highest
;
19057 int i
, width
, ascent
, descent
;
19059 cmp
->font
= (void *) font
;
19061 /* Initialize the bounding box. */
19063 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
19064 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
19066 width
= pcm
->width
;
19067 ascent
= pcm
->ascent
;
19068 descent
= pcm
->descent
;
19072 width
= FONT_WIDTH (font
);
19073 ascent
= FONT_BASE (font
);
19074 descent
= FONT_DESCENT (font
);
19078 lowest
= - descent
+ boff
;
19079 highest
= ascent
+ boff
;
19083 && font_info
->default_ascent
19084 && CHAR_TABLE_P (Vuse_default_ascent
)
19085 && !NILP (Faref (Vuse_default_ascent
,
19086 make_number (it
->char_to_display
))))
19087 highest
= font_info
->default_ascent
+ boff
;
19089 /* Draw the first glyph at the normal position. It may be
19090 shifted to right later if some other glyphs are drawn at
19092 cmp
->offsets
[0] = 0;
19093 cmp
->offsets
[1] = boff
;
19095 /* Set cmp->offsets for the remaining glyphs. */
19096 for (i
= 1; i
< cmp
->glyph_len
; i
++)
19098 int left
, right
, btm
, top
;
19099 int ch
= COMPOSITION_GLYPH (cmp
, i
);
19100 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
19102 face
= FACE_FROM_ID (it
->f
, face_id
);
19103 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
19104 &char2b
, it
->multibyte_p
, 0);
19108 font
= FRAME_FONT (it
->f
);
19109 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19115 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19116 boff
= font_info
->baseline_offset
;
19117 if (font_info
->vertical_centering
)
19118 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19122 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
19123 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
19125 width
= pcm
->width
;
19126 ascent
= pcm
->ascent
;
19127 descent
= pcm
->descent
;
19131 width
= FONT_WIDTH (font
);
19136 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
19138 /* Relative composition with or without
19139 alternate chars. */
19140 left
= (leftmost
+ rightmost
- width
) / 2;
19141 btm
= - descent
+ boff
;
19142 if (font_info
&& font_info
->relative_compose
19143 && (! CHAR_TABLE_P (Vignore_relative_composition
)
19144 || NILP (Faref (Vignore_relative_composition
,
19145 make_number (ch
)))))
19148 if (- descent
>= font_info
->relative_compose
)
19149 /* One extra pixel between two glyphs. */
19151 else if (ascent
<= 0)
19152 /* One extra pixel between two glyphs. */
19153 btm
= lowest
- 1 - ascent
- descent
;
19158 /* A composition rule is specified by an integer
19159 value that encodes global and new reference
19160 points (GREF and NREF). GREF and NREF are
19161 specified by numbers as below:
19163 0---1---2 -- ascent
19167 9--10--11 -- center
19169 ---3---4---5--- baseline
19171 6---7---8 -- descent
19173 int rule
= COMPOSITION_RULE (cmp
, i
);
19174 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
19176 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
19177 grefx
= gref
% 3, nrefx
= nref
% 3;
19178 grefy
= gref
/ 3, nrefy
= nref
/ 3;
19181 + grefx
* (rightmost
- leftmost
) / 2
19182 - nrefx
* width
/ 2);
19183 btm
= ((grefy
== 0 ? highest
19185 : grefy
== 2 ? lowest
19186 : (highest
+ lowest
) / 2)
19187 - (nrefy
== 0 ? ascent
+ descent
19188 : nrefy
== 1 ? descent
- boff
19190 : (ascent
+ descent
) / 2));
19193 cmp
->offsets
[i
* 2] = left
;
19194 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
19196 /* Update the bounding box of the overall glyphs. */
19197 right
= left
+ width
;
19198 top
= btm
+ descent
+ ascent
;
19199 if (left
< leftmost
)
19201 if (right
> rightmost
)
19209 /* If there are glyphs whose x-offsets are negative,
19210 shift all glyphs to the right and make all x-offsets
19214 for (i
= 0; i
< cmp
->glyph_len
; i
++)
19215 cmp
->offsets
[i
* 2] -= leftmost
;
19216 rightmost
-= leftmost
;
19219 cmp
->pixel_width
= rightmost
;
19220 cmp
->ascent
= highest
;
19221 cmp
->descent
= - lowest
;
19222 if (cmp
->ascent
< font_ascent
)
19223 cmp
->ascent
= font_ascent
;
19224 if (cmp
->descent
< font_descent
)
19225 cmp
->descent
= font_descent
;
19228 it
->pixel_width
= cmp
->pixel_width
;
19229 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
19230 it
->descent
= it
->phys_descent
= cmp
->descent
;
19232 if (face
->box
!= FACE_NO_BOX
)
19234 int thick
= face
->box_line_width
;
19238 it
->ascent
+= thick
;
19239 it
->descent
+= thick
;
19244 if (it
->start_of_box_run_p
)
19245 it
->pixel_width
+= thick
;
19246 if (it
->end_of_box_run_p
)
19247 it
->pixel_width
+= thick
;
19250 /* If face has an overline, add the height of the overline
19251 (1 pixel) and a 1 pixel margin to the character height. */
19252 if (face
->overline_p
)
19255 take_vertical_position_into_account (it
);
19258 append_composite_glyph (it
);
19260 else if (it
->what
== IT_IMAGE
)
19261 produce_image_glyph (it
);
19262 else if (it
->what
== IT_STRETCH
)
19263 produce_stretch_glyph (it
);
19265 /* Accumulate dimensions. Note: can't assume that it->descent > 0
19266 because this isn't true for images with `:ascent 100'. */
19267 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
19268 if (it
->area
== TEXT_AREA
)
19269 it
->current_x
+= it
->pixel_width
;
19271 it
->descent
+= it
->extra_line_spacing
;
19273 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
19274 it
->max_descent
= max (it
->max_descent
, it
->descent
);
19275 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
19276 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
19280 Output LEN glyphs starting at START at the nominal cursor position.
19281 Advance the nominal cursor over the text. The global variable
19282 updated_window contains the window being updated, updated_row is
19283 the glyph row being updated, and updated_area is the area of that
19284 row being updated. */
19287 x_write_glyphs (start
, len
)
19288 struct glyph
*start
;
19293 xassert (updated_window
&& updated_row
);
19296 /* Write glyphs. */
19298 hpos
= start
- updated_row
->glyphs
[updated_area
];
19299 x
= draw_glyphs (updated_window
, output_cursor
.x
,
19300 updated_row
, updated_area
,
19302 DRAW_NORMAL_TEXT
, 0);
19304 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
19305 if (updated_area
== TEXT_AREA
19306 && updated_window
->phys_cursor_on_p
19307 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
19308 && updated_window
->phys_cursor
.hpos
>= hpos
19309 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
19310 updated_window
->phys_cursor_on_p
= 0;
19314 /* Advance the output cursor. */
19315 output_cursor
.hpos
+= len
;
19316 output_cursor
.x
= x
;
19321 Insert LEN glyphs from START at the nominal cursor position. */
19324 x_insert_glyphs (start
, len
)
19325 struct glyph
*start
;
19330 int line_height
, shift_by_width
, shifted_region_width
;
19331 struct glyph_row
*row
;
19332 struct glyph
*glyph
;
19333 int frame_x
, frame_y
, hpos
;
19335 xassert (updated_window
&& updated_row
);
19337 w
= updated_window
;
19338 f
= XFRAME (WINDOW_FRAME (w
));
19340 /* Get the height of the line we are in. */
19342 line_height
= row
->height
;
19344 /* Get the width of the glyphs to insert. */
19345 shift_by_width
= 0;
19346 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
19347 shift_by_width
+= glyph
->pixel_width
;
19349 /* Get the width of the region to shift right. */
19350 shifted_region_width
= (window_box_width (w
, updated_area
)
19355 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
19356 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
19358 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
19359 line_height
, shift_by_width
);
19361 /* Write the glyphs. */
19362 hpos
= start
- row
->glyphs
[updated_area
];
19363 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
19365 DRAW_NORMAL_TEXT
, 0);
19367 /* Advance the output cursor. */
19368 output_cursor
.hpos
+= len
;
19369 output_cursor
.x
+= shift_by_width
;
19375 Erase the current text line from the nominal cursor position
19376 (inclusive) to pixel column TO_X (exclusive). The idea is that
19377 everything from TO_X onward is already erased.
19379 TO_X is a pixel position relative to updated_area of
19380 updated_window. TO_X == -1 means clear to the end of this area. */
19383 x_clear_end_of_line (to_x
)
19387 struct window
*w
= updated_window
;
19388 int max_x
, min_y
, max_y
;
19389 int from_x
, from_y
, to_y
;
19391 xassert (updated_window
&& updated_row
);
19392 f
= XFRAME (w
->frame
);
19394 if (updated_row
->full_width_p
)
19395 max_x
= WINDOW_TOTAL_WIDTH (w
);
19397 max_x
= window_box_width (w
, updated_area
);
19398 max_y
= window_text_bottom_y (w
);
19400 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
19401 of window. For TO_X > 0, truncate to end of drawing area. */
19407 to_x
= min (to_x
, max_x
);
19409 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
19411 /* Notice if the cursor will be cleared by this operation. */
19412 if (!updated_row
->full_width_p
)
19413 notice_overwritten_cursor (w
, updated_area
,
19414 output_cursor
.x
, -1,
19416 MATRIX_ROW_BOTTOM_Y (updated_row
));
19418 from_x
= output_cursor
.x
;
19420 /* Translate to frame coordinates. */
19421 if (updated_row
->full_width_p
)
19423 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
19424 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
19428 int area_left
= window_box_left (w
, updated_area
);
19429 from_x
+= area_left
;
19433 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
19434 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
19435 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
19437 /* Prevent inadvertently clearing to end of the X window. */
19438 if (to_x
> from_x
&& to_y
> from_y
)
19441 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
19442 to_x
- from_x
, to_y
- from_y
);
19447 #endif /* HAVE_WINDOW_SYSTEM */
19451 /***********************************************************************
19453 ***********************************************************************/
19455 /* Value is the internal representation of the specified cursor type
19456 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
19457 of the bar cursor. */
19459 static enum text_cursor_kinds
19460 get_specified_cursor_type (arg
, width
)
19464 enum text_cursor_kinds type
;
19469 if (EQ (arg
, Qbox
))
19470 return FILLED_BOX_CURSOR
;
19472 if (EQ (arg
, Qhollow
))
19473 return HOLLOW_BOX_CURSOR
;
19475 if (EQ (arg
, Qbar
))
19482 && EQ (XCAR (arg
), Qbar
)
19483 && INTEGERP (XCDR (arg
))
19484 && XINT (XCDR (arg
)) >= 0)
19486 *width
= XINT (XCDR (arg
));
19490 if (EQ (arg
, Qhbar
))
19493 return HBAR_CURSOR
;
19497 && EQ (XCAR (arg
), Qhbar
)
19498 && INTEGERP (XCDR (arg
))
19499 && XINT (XCDR (arg
)) >= 0)
19501 *width
= XINT (XCDR (arg
));
19502 return HBAR_CURSOR
;
19505 /* Treat anything unknown as "hollow box cursor".
19506 It was bad to signal an error; people have trouble fixing
19507 .Xdefaults with Emacs, when it has something bad in it. */
19508 type
= HOLLOW_BOX_CURSOR
;
19513 /* Set the default cursor types for specified frame. */
19515 set_frame_cursor_types (f
, arg
)
19522 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
19523 FRAME_CURSOR_WIDTH (f
) = width
;
19525 /* By default, set up the blink-off state depending on the on-state. */
19527 tem
= Fassoc (arg
, Vblink_cursor_alist
);
19530 FRAME_BLINK_OFF_CURSOR (f
)
19531 = get_specified_cursor_type (XCDR (tem
), &width
);
19532 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
19535 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
19539 /* Return the cursor we want to be displayed in window W. Return
19540 width of bar/hbar cursor through WIDTH arg. Return with
19541 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
19542 (i.e. if the `system caret' should track this cursor).
19544 In a mini-buffer window, we want the cursor only to appear if we
19545 are reading input from this window. For the selected window, we
19546 want the cursor type given by the frame parameter or buffer local
19547 setting of cursor-type. If explicitly marked off, draw no cursor.
19548 In all other cases, we want a hollow box cursor. */
19550 static enum text_cursor_kinds
19551 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
19553 struct glyph
*glyph
;
19555 int *active_cursor
;
19557 struct frame
*f
= XFRAME (w
->frame
);
19558 struct buffer
*b
= XBUFFER (w
->buffer
);
19559 int cursor_type
= DEFAULT_CURSOR
;
19560 Lisp_Object alt_cursor
;
19561 int non_selected
= 0;
19563 *active_cursor
= 1;
19566 if (cursor_in_echo_area
19567 && FRAME_HAS_MINIBUF_P (f
)
19568 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
19570 if (w
== XWINDOW (echo_area_window
))
19572 *width
= FRAME_CURSOR_WIDTH (f
);
19573 return FRAME_DESIRED_CURSOR (f
);
19576 *active_cursor
= 0;
19580 /* Nonselected window or nonselected frame. */
19581 else if (w
!= XWINDOW (f
->selected_window
)
19582 #ifdef HAVE_WINDOW_SYSTEM
19583 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
19587 *active_cursor
= 0;
19589 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
19595 /* Never display a cursor in a window in which cursor-type is nil. */
19596 if (NILP (b
->cursor_type
))
19599 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
19602 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
19603 return get_specified_cursor_type (alt_cursor
, width
);
19606 /* Get the normal cursor type for this window. */
19607 if (EQ (b
->cursor_type
, Qt
))
19609 cursor_type
= FRAME_DESIRED_CURSOR (f
);
19610 *width
= FRAME_CURSOR_WIDTH (f
);
19613 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
19615 /* Use normal cursor if not blinked off. */
19616 if (!w
->cursor_off_p
)
19618 if (glyph
->type
== IMAGE_GLYPH
) {
19619 if (cursor_type
== FILLED_BOX_CURSOR
)
19620 cursor_type
= HOLLOW_BOX_CURSOR
;
19622 return cursor_type
;
19625 /* Cursor is blinked off, so determine how to "toggle" it. */
19627 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
19628 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
19629 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
19631 /* Then see if frame has specified a specific blink off cursor type. */
19632 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
19634 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
19635 return FRAME_BLINK_OFF_CURSOR (f
);
19639 /* Some people liked having a permanently visible blinking cursor,
19640 while others had very strong opinions against it. So it was
19641 decided to remove it. KFS 2003-09-03 */
19643 /* Finally perform built-in cursor blinking:
19644 filled box <-> hollow box
19645 wide [h]bar <-> narrow [h]bar
19646 narrow [h]bar <-> no cursor
19647 other type <-> no cursor */
19649 if (cursor_type
== FILLED_BOX_CURSOR
)
19650 return HOLLOW_BOX_CURSOR
;
19652 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
19655 return cursor_type
;
19663 #ifdef HAVE_WINDOW_SYSTEM
19665 /* Notice when the text cursor of window W has been completely
19666 overwritten by a drawing operation that outputs glyphs in AREA
19667 starting at X0 and ending at X1 in the line starting at Y0 and
19668 ending at Y1. X coordinates are area-relative. X1 < 0 means all
19669 the rest of the line after X0 has been written. Y coordinates
19670 are window-relative. */
19673 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
19675 enum glyph_row_area area
;
19676 int x0
, y0
, x1
, y1
;
19678 int cx0
, cx1
, cy0
, cy1
;
19679 struct glyph_row
*row
;
19681 if (!w
->phys_cursor_on_p
)
19683 if (area
!= TEXT_AREA
)
19686 row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
;
19687 if (!row
->displays_text_p
)
19690 if (row
->cursor_in_fringe_p
)
19692 row
->cursor_in_fringe_p
= 0;
19693 draw_fringe_bitmap (w
, row
, 0);
19694 w
->phys_cursor_on_p
= 0;
19698 cx0
= w
->phys_cursor
.x
;
19699 cx1
= cx0
+ w
->phys_cursor_width
;
19700 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
19703 /* The cursor image will be completely removed from the
19704 screen if the output area intersects the cursor area in
19705 y-direction. When we draw in [y0 y1[, and some part of
19706 the cursor is at y < y0, that part must have been drawn
19707 before. When scrolling, the cursor is erased before
19708 actually scrolling, so we don't come here. When not
19709 scrolling, the rows above the old cursor row must have
19710 changed, and in this case these rows must have written
19711 over the cursor image.
19713 Likewise if part of the cursor is below y1, with the
19714 exception of the cursor being in the first blank row at
19715 the buffer and window end because update_text_area
19716 doesn't draw that row. (Except when it does, but
19717 that's handled in update_text_area.) */
19719 cy0
= w
->phys_cursor
.y
;
19720 cy1
= cy0
+ w
->phys_cursor_height
;
19721 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
19724 w
->phys_cursor_on_p
= 0;
19727 #endif /* HAVE_WINDOW_SYSTEM */
19730 /************************************************************************
19732 ************************************************************************/
19734 #ifdef HAVE_WINDOW_SYSTEM
19737 Fix the display of area AREA of overlapping row ROW in window W. */
19740 x_fix_overlapping_area (w
, row
, area
)
19742 struct glyph_row
*row
;
19743 enum glyph_row_area area
;
19750 for (i
= 0; i
< row
->used
[area
];)
19752 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
19754 int start
= i
, start_x
= x
;
19758 x
+= row
->glyphs
[area
][i
].pixel_width
;
19761 while (i
< row
->used
[area
]
19762 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
19764 draw_glyphs (w
, start_x
, row
, area
,
19766 DRAW_NORMAL_TEXT
, 1);
19770 x
+= row
->glyphs
[area
][i
].pixel_width
;
19780 Draw the cursor glyph of window W in glyph row ROW. See the
19781 comment of draw_glyphs for the meaning of HL. */
19784 draw_phys_cursor_glyph (w
, row
, hl
)
19786 struct glyph_row
*row
;
19787 enum draw_glyphs_face hl
;
19789 /* If cursor hpos is out of bounds, don't draw garbage. This can
19790 happen in mini-buffer windows when switching between echo area
19791 glyphs and mini-buffer. */
19792 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
19794 int on_p
= w
->phys_cursor_on_p
;
19796 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
19797 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
19799 w
->phys_cursor_on_p
= on_p
;
19801 if (hl
== DRAW_CURSOR
)
19802 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
19803 /* When we erase the cursor, and ROW is overlapped by other
19804 rows, make sure that these overlapping parts of other rows
19806 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
19808 if (row
> w
->current_matrix
->rows
19809 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
19810 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
19812 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
19813 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
19814 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
19821 Erase the image of a cursor of window W from the screen. */
19824 erase_phys_cursor (w
)
19827 struct frame
*f
= XFRAME (w
->frame
);
19828 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
19829 int hpos
= w
->phys_cursor
.hpos
;
19830 int vpos
= w
->phys_cursor
.vpos
;
19831 int mouse_face_here_p
= 0;
19832 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
19833 struct glyph_row
*cursor_row
;
19834 struct glyph
*cursor_glyph
;
19835 enum draw_glyphs_face hl
;
19837 /* No cursor displayed or row invalidated => nothing to do on the
19839 if (w
->phys_cursor_type
== NO_CURSOR
)
19840 goto mark_cursor_off
;
19842 /* VPOS >= active_glyphs->nrows means that window has been resized.
19843 Don't bother to erase the cursor. */
19844 if (vpos
>= active_glyphs
->nrows
)
19845 goto mark_cursor_off
;
19847 /* If row containing cursor is marked invalid, there is nothing we
19849 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
19850 if (!cursor_row
->enabled_p
)
19851 goto mark_cursor_off
;
19853 /* If row is completely invisible, don't attempt to delete a cursor which
19854 isn't there. This can happen if cursor is at top of a window, and
19855 we switch to a buffer with a header line in that window. */
19856 if (cursor_row
->visible_height
<= 0)
19857 goto mark_cursor_off
;
19859 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
19860 if (cursor_row
->cursor_in_fringe_p
)
19862 cursor_row
->cursor_in_fringe_p
= 0;
19863 draw_fringe_bitmap (w
, cursor_row
, 0);
19864 goto mark_cursor_off
;
19867 /* This can happen when the new row is shorter than the old one.
19868 In this case, either draw_glyphs or clear_end_of_line
19869 should have cleared the cursor. Note that we wouldn't be
19870 able to erase the cursor in this case because we don't have a
19871 cursor glyph at hand. */
19872 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
19873 goto mark_cursor_off
;
19875 /* If the cursor is in the mouse face area, redisplay that when
19876 we clear the cursor. */
19877 if (! NILP (dpyinfo
->mouse_face_window
)
19878 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
19879 && (vpos
> dpyinfo
->mouse_face_beg_row
19880 || (vpos
== dpyinfo
->mouse_face_beg_row
19881 && hpos
>= dpyinfo
->mouse_face_beg_col
))
19882 && (vpos
< dpyinfo
->mouse_face_end_row
19883 || (vpos
== dpyinfo
->mouse_face_end_row
19884 && hpos
< dpyinfo
->mouse_face_end_col
))
19885 /* Don't redraw the cursor's spot in mouse face if it is at the
19886 end of a line (on a newline). The cursor appears there, but
19887 mouse highlighting does not. */
19888 && cursor_row
->used
[TEXT_AREA
] > hpos
)
19889 mouse_face_here_p
= 1;
19891 /* Maybe clear the display under the cursor. */
19892 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
19895 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
19897 cursor_glyph
= get_phys_cursor_glyph (w
);
19898 if (cursor_glyph
== NULL
)
19899 goto mark_cursor_off
;
19901 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
19902 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
19904 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
,
19905 cursor_glyph
->pixel_width
, cursor_row
->visible_height
);
19908 /* Erase the cursor by redrawing the character underneath it. */
19909 if (mouse_face_here_p
)
19910 hl
= DRAW_MOUSE_FACE
;
19912 hl
= DRAW_NORMAL_TEXT
;
19913 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
19916 w
->phys_cursor_on_p
= 0;
19917 w
->phys_cursor_type
= NO_CURSOR
;
19922 Display or clear cursor of window W. If ON is zero, clear the
19923 cursor. If it is non-zero, display the cursor. If ON is nonzero,
19924 where to put the cursor is specified by HPOS, VPOS, X and Y. */
19927 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
19929 int on
, hpos
, vpos
, x
, y
;
19931 struct frame
*f
= XFRAME (w
->frame
);
19932 int new_cursor_type
;
19933 int new_cursor_width
;
19935 struct glyph_matrix
*current_glyphs
;
19936 struct glyph_row
*glyph_row
;
19937 struct glyph
*glyph
;
19939 /* This is pointless on invisible frames, and dangerous on garbaged
19940 windows and frames; in the latter case, the frame or window may
19941 be in the midst of changing its size, and x and y may be off the
19943 if (! FRAME_VISIBLE_P (f
)
19944 || FRAME_GARBAGED_P (f
)
19945 || vpos
>= w
->current_matrix
->nrows
19946 || hpos
>= w
->current_matrix
->matrix_w
)
19949 /* If cursor is off and we want it off, return quickly. */
19950 if (!on
&& !w
->phys_cursor_on_p
)
19953 current_glyphs
= w
->current_matrix
;
19954 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
19955 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
19957 /* If cursor row is not enabled, we don't really know where to
19958 display the cursor. */
19959 if (!glyph_row
->enabled_p
)
19961 w
->phys_cursor_on_p
= 0;
19965 xassert (interrupt_input_blocked
);
19967 /* Set new_cursor_type to the cursor we want to be displayed. */
19968 new_cursor_type
= get_window_cursor_type (w
, glyph
,
19969 &new_cursor_width
, &active_cursor
);
19971 /* If cursor is currently being shown and we don't want it to be or
19972 it is in the wrong place, or the cursor type is not what we want,
19974 if (w
->phys_cursor_on_p
19976 || w
->phys_cursor
.x
!= x
19977 || w
->phys_cursor
.y
!= y
19978 || new_cursor_type
!= w
->phys_cursor_type
19979 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
19980 && new_cursor_width
!= w
->phys_cursor_width
)))
19981 erase_phys_cursor (w
);
19983 /* Don't check phys_cursor_on_p here because that flag is only set
19984 to zero in some cases where we know that the cursor has been
19985 completely erased, to avoid the extra work of erasing the cursor
19986 twice. In other words, phys_cursor_on_p can be 1 and the cursor
19987 still not be visible, or it has only been partly erased. */
19990 w
->phys_cursor_ascent
= glyph_row
->ascent
;
19991 w
->phys_cursor_height
= glyph_row
->height
;
19993 /* Set phys_cursor_.* before x_draw_.* is called because some
19994 of them may need the information. */
19995 w
->phys_cursor
.x
= x
;
19996 w
->phys_cursor
.y
= glyph_row
->y
;
19997 w
->phys_cursor
.hpos
= hpos
;
19998 w
->phys_cursor
.vpos
= vpos
;
20001 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
20002 new_cursor_type
, new_cursor_width
,
20003 on
, active_cursor
);
20007 /* Switch the display of W's cursor on or off, according to the value
20011 update_window_cursor (w
, on
)
20015 /* Don't update cursor in windows whose frame is in the process
20016 of being deleted. */
20017 if (w
->current_matrix
)
20020 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20021 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20027 /* Call update_window_cursor with parameter ON_P on all leaf windows
20028 in the window tree rooted at W. */
20031 update_cursor_in_window_tree (w
, on_p
)
20037 if (!NILP (w
->hchild
))
20038 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
20039 else if (!NILP (w
->vchild
))
20040 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
20042 update_window_cursor (w
, on_p
);
20044 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
20050 Display the cursor on window W, or clear it, according to ON_P.
20051 Don't change the cursor's position. */
20054 x_update_cursor (f
, on_p
)
20058 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
20063 Clear the cursor of window W to background color, and mark the
20064 cursor as not shown. This is used when the text where the cursor
20065 is is about to be rewritten. */
20071 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
20072 update_window_cursor (w
, 0);
20077 Display the active region described by mouse_face_* according to DRAW. */
20080 show_mouse_face (dpyinfo
, draw
)
20081 Display_Info
*dpyinfo
;
20082 enum draw_glyphs_face draw
;
20084 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
20085 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20087 if (/* If window is in the process of being destroyed, don't bother
20089 w
->current_matrix
!= NULL
20090 /* Don't update mouse highlight if hidden */
20091 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
20092 /* Recognize when we are called to operate on rows that don't exist
20093 anymore. This can happen when a window is split. */
20094 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
20096 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
20097 struct glyph_row
*row
, *first
, *last
;
20099 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20100 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20102 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
20104 int start_hpos
, end_hpos
, start_x
;
20106 /* For all but the first row, the highlight starts at column 0. */
20109 start_hpos
= dpyinfo
->mouse_face_beg_col
;
20110 start_x
= dpyinfo
->mouse_face_beg_x
;
20119 end_hpos
= dpyinfo
->mouse_face_end_col
;
20121 end_hpos
= row
->used
[TEXT_AREA
];
20123 if (end_hpos
> start_hpos
)
20125 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
20126 start_hpos
, end_hpos
,
20130 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
20134 /* When we've written over the cursor, arrange for it to
20135 be displayed again. */
20136 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
20139 display_and_set_cursor (w
, 1,
20140 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20141 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20146 /* Change the mouse cursor. */
20147 if (draw
== DRAW_NORMAL_TEXT
)
20148 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
20149 else if (draw
== DRAW_MOUSE_FACE
)
20150 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
20152 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
20156 Clear out the mouse-highlighted active region.
20157 Redraw it un-highlighted first. Value is non-zero if mouse
20158 face was actually drawn unhighlighted. */
20161 clear_mouse_face (dpyinfo
)
20162 Display_Info
*dpyinfo
;
20166 if (!NILP (dpyinfo
->mouse_face_window
))
20168 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
20172 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
20173 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
20174 dpyinfo
->mouse_face_window
= Qnil
;
20175 dpyinfo
->mouse_face_overlay
= Qnil
;
20181 Non-zero if physical cursor of window W is within mouse face. */
20184 cursor_in_mouse_face_p (w
)
20187 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
20188 int in_mouse_face
= 0;
20190 if (WINDOWP (dpyinfo
->mouse_face_window
)
20191 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
20193 int hpos
= w
->phys_cursor
.hpos
;
20194 int vpos
= w
->phys_cursor
.vpos
;
20196 if (vpos
>= dpyinfo
->mouse_face_beg_row
20197 && vpos
<= dpyinfo
->mouse_face_end_row
20198 && (vpos
> dpyinfo
->mouse_face_beg_row
20199 || hpos
>= dpyinfo
->mouse_face_beg_col
)
20200 && (vpos
< dpyinfo
->mouse_face_end_row
20201 || hpos
< dpyinfo
->mouse_face_end_col
20202 || dpyinfo
->mouse_face_past_end
))
20206 return in_mouse_face
;
20212 /* Find the glyph matrix position of buffer position CHARPOS in window
20213 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
20214 current glyphs must be up to date. If CHARPOS is above window
20215 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
20216 of last line in W. In the row containing CHARPOS, stop before glyphs
20217 having STOP as object. */
20219 #if 1 /* This is a version of fast_find_position that's more correct
20220 in the presence of hscrolling, for example. I didn't install
20221 it right away because the problem fixed is minor, it failed
20222 in 20.x as well, and I think it's too risky to install
20223 so near the release of 21.1. 2001-09-25 gerd. */
20226 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
20229 int *hpos
, *vpos
, *x
, *y
;
20232 struct glyph_row
*row
, *first
;
20233 struct glyph
*glyph
, *end
;
20236 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20237 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
20240 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
20242 *x
= *y
= *hpos
= *vpos
= 0;
20247 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
20254 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
20256 glyph
= row
->glyphs
[TEXT_AREA
];
20257 end
= glyph
+ row
->used
[TEXT_AREA
];
20259 /* Skip over glyphs not having an object at the start of the row.
20260 These are special glyphs like truncation marks on terminal
20262 if (row
->displays_text_p
)
20264 && INTEGERP (glyph
->object
)
20265 && !EQ (stop
, glyph
->object
)
20266 && glyph
->charpos
< 0)
20268 *x
+= glyph
->pixel_width
;
20273 && !INTEGERP (glyph
->object
)
20274 && !EQ (stop
, glyph
->object
)
20275 && (!BUFFERP (glyph
->object
)
20276 || glyph
->charpos
< charpos
))
20278 *x
+= glyph
->pixel_width
;
20282 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
20289 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
20292 int *hpos
, *vpos
, *x
, *y
;
20297 int maybe_next_line_p
= 0;
20298 int line_start_position
;
20299 int yb
= window_text_bottom_y (w
);
20300 struct glyph_row
*row
, *best_row
;
20301 int row_vpos
, best_row_vpos
;
20304 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20305 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
20307 while (row
->y
< yb
)
20309 if (row
->used
[TEXT_AREA
])
20310 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
20312 line_start_position
= 0;
20314 if (line_start_position
> pos
)
20316 /* If the position sought is the end of the buffer,
20317 don't include the blank lines at the bottom of the window. */
20318 else if (line_start_position
== pos
20319 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
20321 maybe_next_line_p
= 1;
20324 else if (line_start_position
> 0)
20327 best_row_vpos
= row_vpos
;
20330 if (row
->y
+ row
->height
>= yb
)
20337 /* Find the right column within BEST_ROW. */
20339 current_x
= best_row
->x
;
20340 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
20342 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
20343 int charpos
= glyph
->charpos
;
20345 if (BUFFERP (glyph
->object
))
20347 if (charpos
== pos
)
20350 *vpos
= best_row_vpos
;
20355 else if (charpos
> pos
)
20358 else if (EQ (glyph
->object
, stop
))
20363 current_x
+= glyph
->pixel_width
;
20366 /* If we're looking for the end of the buffer,
20367 and we didn't find it in the line we scanned,
20368 use the start of the following line. */
20369 if (maybe_next_line_p
)
20374 current_x
= best_row
->x
;
20377 *vpos
= best_row_vpos
;
20378 *hpos
= lastcol
+ 1;
20387 /* Find the position of the glyph for position POS in OBJECT in
20388 window W's current matrix, and return in *X, *Y the pixel
20389 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
20391 RIGHT_P non-zero means return the position of the right edge of the
20392 glyph, RIGHT_P zero means return the left edge position.
20394 If no glyph for POS exists in the matrix, return the position of
20395 the glyph with the next smaller position that is in the matrix, if
20396 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
20397 exists in the matrix, return the position of the glyph with the
20398 next larger position in OBJECT.
20400 Value is non-zero if a glyph was found. */
20403 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
20406 Lisp_Object object
;
20407 int *hpos
, *vpos
, *x
, *y
;
20410 int yb
= window_text_bottom_y (w
);
20411 struct glyph_row
*r
;
20412 struct glyph
*best_glyph
= NULL
;
20413 struct glyph_row
*best_row
= NULL
;
20416 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20417 r
->enabled_p
&& r
->y
< yb
;
20420 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
20421 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
20424 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
20425 if (EQ (g
->object
, object
))
20427 if (g
->charpos
== pos
)
20434 else if (best_glyph
== NULL
20435 || ((abs (g
->charpos
- pos
)
20436 < abs (best_glyph
->charpos
- pos
))
20439 : g
->charpos
> pos
)))
20453 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
20457 *x
+= best_glyph
->pixel_width
;
20462 *vpos
= best_row
- w
->current_matrix
->rows
;
20465 return best_glyph
!= NULL
;
20469 /* See if position X, Y is within a hot-spot of an image. */
20472 on_hot_spot_p (hot_spot
, x
, y
)
20473 Lisp_Object hot_spot
;
20476 if (!CONSP (hot_spot
))
20479 if (EQ (XCAR (hot_spot
), Qrect
))
20481 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
20482 Lisp_Object rect
= XCDR (hot_spot
);
20486 if (!CONSP (XCAR (rect
)))
20488 if (!CONSP (XCDR (rect
)))
20490 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
20492 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
20494 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
20496 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
20500 else if (EQ (XCAR (hot_spot
), Qcircle
))
20502 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
20503 Lisp_Object circ
= XCDR (hot_spot
);
20504 Lisp_Object lr
, lx0
, ly0
;
20506 && CONSP (XCAR (circ
))
20507 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
20508 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
20509 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
20511 double r
= XFLOATINT (lr
);
20512 double dx
= XINT (lx0
) - x
;
20513 double dy
= XINT (ly0
) - y
;
20514 return (dx
* dx
+ dy
* dy
<= r
* r
);
20517 else if (EQ (XCAR (hot_spot
), Qpoly
))
20519 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
20520 if (VECTORP (XCDR (hot_spot
)))
20522 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
20523 Lisp_Object
*poly
= v
->contents
;
20527 Lisp_Object lx
, ly
;
20530 /* Need an even number of coordinates, and at least 3 edges. */
20531 if (n
< 6 || n
& 1)
20534 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
20535 If count is odd, we are inside polygon. Pixels on edges
20536 may or may not be included depending on actual geometry of the
20538 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
20539 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
20541 x0
= XINT (lx
), y0
= XINT (ly
);
20542 for (i
= 0; i
< n
; i
+= 2)
20544 int x1
= x0
, y1
= y0
;
20545 if ((lx
= poly
[i
], !INTEGERP (lx
))
20546 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
20548 x0
= XINT (lx
), y0
= XINT (ly
);
20550 /* Does this segment cross the X line? */
20558 if (y
> y0
&& y
> y1
)
20560 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
20571 find_hot_spot (map
, x
, y
)
20575 while (CONSP (map
))
20577 if (CONSP (XCAR (map
))
20578 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
20586 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
20588 doc
: /* Lookup in image map MAP coordinates X and Y.
20589 An image map is an alist where each element has the format (AREA ID PLIST).
20590 An AREA is specified as either a rectangle, a circle, or a polygon:
20591 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
20592 pixel coordinates of the upper left and bottom right corners.
20593 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
20594 and the radius of the circle; r may be a float or integer.
20595 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
20596 vector describes one corner in the polygon.
20597 Returns the alist element for the first matching AREA in MAP. */)
20607 wrong_type_argument (Qintegerp
, x
);
20609 wrong_type_argument (Qintegerp
, y
);
20611 return find_hot_spot (map
, XINT (x
), XINT (y
));
20615 /* Display frame CURSOR, optionally using shape defined by POINTER. */
20617 define_frame_cursor1 (f
, cursor
, pointer
)
20620 Lisp_Object pointer
;
20622 if (!NILP (pointer
))
20624 if (EQ (pointer
, Qarrow
))
20625 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20626 else if (EQ (pointer
, Qhand
))
20627 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
20628 else if (EQ (pointer
, Qtext
))
20629 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
20630 else if (EQ (pointer
, intern ("hdrag")))
20631 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
20632 #ifdef HAVE_X_WINDOWS
20633 else if (EQ (pointer
, intern ("vdrag")))
20634 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
20636 else if (EQ (pointer
, intern ("hourglass")))
20637 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
20638 else if (EQ (pointer
, Qmodeline
))
20639 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
20641 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20644 #ifndef HAVE_CARBON
20645 if (cursor
!= No_Cursor
)
20647 if (bcmp (&cursor
, &No_Cursor
, sizeof (Cursor
)))
20649 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
20652 /* Take proper action when mouse has moved to the mode or header line
20653 or marginal area AREA of window W, x-position X and y-position Y.
20654 X is relative to the start of the text display area of W, so the
20655 width of bitmap areas and scroll bars must be subtracted to get a
20656 position relative to the start of the mode line. */
20659 note_mode_line_or_margin_highlight (w
, x
, y
, area
)
20662 enum window_part area
;
20664 struct frame
*f
= XFRAME (w
->frame
);
20665 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20666 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20667 Lisp_Object pointer
= Qnil
;
20668 int charpos
, dx
, dy
, width
, height
;
20669 Lisp_Object string
, object
= Qnil
;
20670 Lisp_Object pos
, help
, image
;
20672 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
20673 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
20674 &object
, &dx
, &dy
, &width
, &height
);
20677 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
20678 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
20679 &object
, &dx
, &dy
, &width
, &height
);
20684 if (IMAGEP (object
))
20686 Lisp_Object image_map
, hotspot
;
20687 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
20689 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
20691 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
20693 Lisp_Object area_id
, plist
;
20695 area_id
= XCAR (hotspot
);
20696 /* Could check AREA_ID to see if we enter/leave this hot-spot.
20697 If so, we could look for mouse-enter, mouse-leave
20698 properties in PLIST (and do something...). */
20699 if ((plist
= XCDR (hotspot
), CONSP (plist
)))
20701 pointer
= Fplist_get (plist
, Qpointer
);
20702 if (NILP (pointer
))
20704 help
= Fplist_get (plist
, Qhelp_echo
);
20707 help_echo_string
= help
;
20708 /* Is this correct? ++kfs */
20709 XSETWINDOW (help_echo_window
, w
);
20710 help_echo_object
= w
->buffer
;
20711 help_echo_pos
= charpos
;
20714 if (NILP (pointer
))
20715 pointer
= Fplist_get (XCDR (object
), QCpointer
);
20719 if (STRINGP (string
))
20721 pos
= make_number (charpos
);
20722 /* If we're on a string with `help-echo' text property, arrange
20723 for the help to be displayed. This is done by setting the
20724 global variable help_echo_string to the help string. */
20725 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
20728 help_echo_string
= help
;
20729 XSETWINDOW (help_echo_window
, w
);
20730 help_echo_object
= string
;
20731 help_echo_pos
= charpos
;
20734 if (NILP (pointer
))
20735 pointer
= Fget_text_property (pos
, Qpointer
, string
);
20737 /* Change the mouse pointer according to what is under X/Y. */
20738 if (NILP (pointer
) && area
== ON_MODE_LINE
)
20741 map
= Fget_text_property (pos
, Qlocal_map
, string
);
20742 if (!KEYMAPP (map
))
20743 map
= Fget_text_property (pos
, Qkeymap
, string
);
20744 if (!KEYMAPP (map
))
20745 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
20749 define_frame_cursor1 (f
, cursor
, pointer
);
20754 Take proper action when the mouse has moved to position X, Y on
20755 frame F as regards highlighting characters that have mouse-face
20756 properties. Also de-highlighting chars where the mouse was before.
20757 X and Y can be negative or out of range. */
20760 note_mouse_highlight (f
, x
, y
)
20764 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20765 enum window_part part
;
20766 Lisp_Object window
;
20768 Cursor cursor
= No_Cursor
;
20769 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
20772 /* When a menu is active, don't highlight because this looks odd. */
20773 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
20774 if (popup_activated ())
20778 if (NILP (Vmouse_highlight
)
20779 || !f
->glyphs_initialized_p
)
20782 dpyinfo
->mouse_face_mouse_x
= x
;
20783 dpyinfo
->mouse_face_mouse_y
= y
;
20784 dpyinfo
->mouse_face_mouse_frame
= f
;
20786 if (dpyinfo
->mouse_face_defer
)
20789 if (gc_in_progress
)
20791 dpyinfo
->mouse_face_deferred_gc
= 1;
20795 /* Which window is that in? */
20796 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
20798 /* If we were displaying active text in another window, clear that. */
20799 if (! EQ (window
, dpyinfo
->mouse_face_window
))
20800 clear_mouse_face (dpyinfo
);
20802 /* Not on a window -> return. */
20803 if (!WINDOWP (window
))
20806 /* Reset help_echo_string. It will get recomputed below. */
20807 help_echo_string
= Qnil
;
20809 /* Convert to window-relative pixel coordinates. */
20810 w
= XWINDOW (window
);
20811 frame_to_window_pixel_xy (w
, &x
, &y
);
20813 /* Handle tool-bar window differently since it doesn't display a
20815 if (EQ (window
, f
->tool_bar_window
))
20817 note_tool_bar_highlight (f
, x
, y
);
20821 /* Mouse is on the mode, header line or margin? */
20822 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
20823 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
20825 note_mode_line_or_margin_highlight (w
, x
, y
, part
);
20829 if (part
== ON_VERTICAL_BORDER
)
20830 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
20831 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
)
20832 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20834 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
20836 /* Are we in a window whose display is up to date?
20837 And verify the buffer's text has not changed. */
20838 b
= XBUFFER (w
->buffer
);
20839 if (part
== ON_TEXT
20840 && EQ (w
->window_end_valid
, w
->buffer
)
20841 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
20842 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
20844 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
20845 struct glyph
*glyph
;
20846 Lisp_Object object
;
20847 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
20848 Lisp_Object
*overlay_vec
= NULL
;
20849 int len
, noverlays
;
20850 struct buffer
*obuf
;
20851 int obegv
, ozv
, same_region
;
20853 /* Find the glyph under X/Y. */
20854 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
20856 /* Look for :pointer property on image. */
20857 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
20859 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
20860 if (img
!= NULL
&& IMAGEP (img
->spec
))
20862 Lisp_Object image_map
, hotspot
;
20863 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
20865 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
20867 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
20869 Lisp_Object area_id
, plist
;
20871 area_id
= XCAR (hotspot
);
20872 /* Could check AREA_ID to see if we enter/leave this hot-spot.
20873 If so, we could look for mouse-enter, mouse-leave
20874 properties in PLIST (and do something...). */
20875 if ((plist
= XCDR (hotspot
), CONSP (plist
)))
20877 pointer
= Fplist_get (plist
, Qpointer
);
20878 if (NILP (pointer
))
20880 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
20881 if (!NILP (help_echo_string
))
20883 help_echo_window
= window
;
20884 help_echo_object
= glyph
->object
;
20885 help_echo_pos
= glyph
->charpos
;
20889 if (NILP (pointer
))
20890 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
20894 /* Clear mouse face if X/Y not over text. */
20896 || area
!= TEXT_AREA
20897 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
20899 if (clear_mouse_face (dpyinfo
))
20900 cursor
= No_Cursor
;
20901 if (NILP (pointer
))
20903 if (area
!= TEXT_AREA
)
20904 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20906 pointer
= Vvoid_text_area_pointer
;
20911 pos
= glyph
->charpos
;
20912 object
= glyph
->object
;
20913 if (!STRINGP (object
) && !BUFFERP (object
))
20916 /* If we get an out-of-range value, return now; avoid an error. */
20917 if (BUFFERP (object
) && pos
> BUF_Z (b
))
20920 /* Make the window's buffer temporarily current for
20921 overlays_at and compute_char_face. */
20922 obuf
= current_buffer
;
20923 current_buffer
= b
;
20929 /* Is this char mouse-active or does it have help-echo? */
20930 position
= make_number (pos
);
20932 if (BUFFERP (object
))
20934 /* Put all the overlays we want in a vector in overlay_vec.
20935 Store the length in len. If there are more than 10, make
20936 enough space for all, and try again. */
20938 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
20939 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
20940 if (noverlays
> len
)
20943 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
20944 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
20947 /* Sort overlays into increasing priority order. */
20948 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
20953 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
20954 && vpos
>= dpyinfo
->mouse_face_beg_row
20955 && vpos
<= dpyinfo
->mouse_face_end_row
20956 && (vpos
> dpyinfo
->mouse_face_beg_row
20957 || hpos
>= dpyinfo
->mouse_face_beg_col
)
20958 && (vpos
< dpyinfo
->mouse_face_end_row
20959 || hpos
< dpyinfo
->mouse_face_end_col
20960 || dpyinfo
->mouse_face_past_end
));
20963 cursor
= No_Cursor
;
20965 /* Check mouse-face highlighting. */
20967 /* If there exists an overlay with mouse-face overlapping
20968 the one we are currently highlighting, we have to
20969 check if we enter the overlapping overlay, and then
20970 highlight only that. */
20971 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
20972 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
20974 /* Find the highest priority overlay that has a mouse-face
20977 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
20979 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
20980 if (!NILP (mouse_face
))
20981 overlay
= overlay_vec
[i
];
20984 /* If we're actually highlighting the same overlay as
20985 before, there's no need to do that again. */
20986 if (!NILP (overlay
)
20987 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
20988 goto check_help_echo
;
20990 dpyinfo
->mouse_face_overlay
= overlay
;
20992 /* Clear the display of the old active region, if any. */
20993 if (clear_mouse_face (dpyinfo
))
20994 cursor
= No_Cursor
;
20996 /* If no overlay applies, get a text property. */
20997 if (NILP (overlay
))
20998 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
21000 /* Handle the overlay case. */
21001 if (!NILP (overlay
))
21003 /* Find the range of text around this char that
21004 should be active. */
21005 Lisp_Object before
, after
;
21008 before
= Foverlay_start (overlay
);
21009 after
= Foverlay_end (overlay
);
21010 /* Record this as the current active region. */
21011 fast_find_position (w
, XFASTINT (before
),
21012 &dpyinfo
->mouse_face_beg_col
,
21013 &dpyinfo
->mouse_face_beg_row
,
21014 &dpyinfo
->mouse_face_beg_x
,
21015 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21017 dpyinfo
->mouse_face_past_end
21018 = !fast_find_position (w
, XFASTINT (after
),
21019 &dpyinfo
->mouse_face_end_col
,
21020 &dpyinfo
->mouse_face_end_row
,
21021 &dpyinfo
->mouse_face_end_x
,
21022 &dpyinfo
->mouse_face_end_y
, Qnil
);
21023 dpyinfo
->mouse_face_window
= window
;
21025 dpyinfo
->mouse_face_face_id
21026 = face_at_buffer_position (w
, pos
, 0, 0,
21028 !dpyinfo
->mouse_face_hidden
);
21030 /* Display it as active. */
21031 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21032 cursor
= No_Cursor
;
21034 /* Handle the text property case. */
21035 else if (!NILP (mouse_face
) && BUFFERP (object
))
21037 /* Find the range of text around this char that
21038 should be active. */
21039 Lisp_Object before
, after
, beginning
, end
;
21042 beginning
= Fmarker_position (w
->start
);
21043 end
= make_number (BUF_Z (XBUFFER (object
))
21044 - XFASTINT (w
->window_end_pos
));
21046 = Fprevious_single_property_change (make_number (pos
+ 1),
21048 object
, beginning
);
21050 = Fnext_single_property_change (position
, Qmouse_face
,
21053 /* Record this as the current active region. */
21054 fast_find_position (w
, XFASTINT (before
),
21055 &dpyinfo
->mouse_face_beg_col
,
21056 &dpyinfo
->mouse_face_beg_row
,
21057 &dpyinfo
->mouse_face_beg_x
,
21058 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21059 dpyinfo
->mouse_face_past_end
21060 = !fast_find_position (w
, XFASTINT (after
),
21061 &dpyinfo
->mouse_face_end_col
,
21062 &dpyinfo
->mouse_face_end_row
,
21063 &dpyinfo
->mouse_face_end_x
,
21064 &dpyinfo
->mouse_face_end_y
, Qnil
);
21065 dpyinfo
->mouse_face_window
= window
;
21067 if (BUFFERP (object
))
21068 dpyinfo
->mouse_face_face_id
21069 = face_at_buffer_position (w
, pos
, 0, 0,
21071 !dpyinfo
->mouse_face_hidden
);
21073 /* Display it as active. */
21074 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21075 cursor
= No_Cursor
;
21077 else if (!NILP (mouse_face
) && STRINGP (object
))
21082 b
= Fprevious_single_property_change (make_number (pos
+ 1),
21085 e
= Fnext_single_property_change (position
, Qmouse_face
,
21088 b
= make_number (0);
21090 e
= make_number (SCHARS (object
) - 1);
21091 fast_find_string_pos (w
, XINT (b
), object
,
21092 &dpyinfo
->mouse_face_beg_col
,
21093 &dpyinfo
->mouse_face_beg_row
,
21094 &dpyinfo
->mouse_face_beg_x
,
21095 &dpyinfo
->mouse_face_beg_y
, 0);
21096 fast_find_string_pos (w
, XINT (e
), object
,
21097 &dpyinfo
->mouse_face_end_col
,
21098 &dpyinfo
->mouse_face_end_row
,
21099 &dpyinfo
->mouse_face_end_x
,
21100 &dpyinfo
->mouse_face_end_y
, 1);
21101 dpyinfo
->mouse_face_past_end
= 0;
21102 dpyinfo
->mouse_face_window
= window
;
21103 dpyinfo
->mouse_face_face_id
21104 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
21105 glyph
->face_id
, 1);
21106 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21107 cursor
= No_Cursor
;
21109 else if (STRINGP (object
) && NILP (mouse_face
))
21111 /* A string which doesn't have mouse-face, but
21112 the text ``under'' it might have. */
21113 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
21114 int start
= MATRIX_ROW_START_CHARPOS (r
);
21116 pos
= string_buffer_position (w
, object
, start
);
21118 mouse_face
= get_char_property_and_overlay (make_number (pos
),
21122 if (!NILP (mouse_face
) && !NILP (overlay
))
21124 Lisp_Object before
= Foverlay_start (overlay
);
21125 Lisp_Object after
= Foverlay_end (overlay
);
21128 /* Note that we might not be able to find position
21129 BEFORE in the glyph matrix if the overlay is
21130 entirely covered by a `display' property. In
21131 this case, we overshoot. So let's stop in
21132 the glyph matrix before glyphs for OBJECT. */
21133 fast_find_position (w
, XFASTINT (before
),
21134 &dpyinfo
->mouse_face_beg_col
,
21135 &dpyinfo
->mouse_face_beg_row
,
21136 &dpyinfo
->mouse_face_beg_x
,
21137 &dpyinfo
->mouse_face_beg_y
,
21140 dpyinfo
->mouse_face_past_end
21141 = !fast_find_position (w
, XFASTINT (after
),
21142 &dpyinfo
->mouse_face_end_col
,
21143 &dpyinfo
->mouse_face_end_row
,
21144 &dpyinfo
->mouse_face_end_x
,
21145 &dpyinfo
->mouse_face_end_y
,
21147 dpyinfo
->mouse_face_window
= window
;
21148 dpyinfo
->mouse_face_face_id
21149 = face_at_buffer_position (w
, pos
, 0, 0,
21151 !dpyinfo
->mouse_face_hidden
);
21153 /* Display it as active. */
21154 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21155 cursor
= No_Cursor
;
21162 /* Look for a `help-echo' property. */
21163 if (NILP (help_echo_string
)) {
21164 Lisp_Object help
, overlay
;
21166 /* Check overlays first. */
21167 help
= overlay
= Qnil
;
21168 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
21170 overlay
= overlay_vec
[i
];
21171 help
= Foverlay_get (overlay
, Qhelp_echo
);
21176 help_echo_string
= help
;
21177 help_echo_window
= window
;
21178 help_echo_object
= overlay
;
21179 help_echo_pos
= pos
;
21183 Lisp_Object object
= glyph
->object
;
21184 int charpos
= glyph
->charpos
;
21186 /* Try text properties. */
21187 if (STRINGP (object
)
21189 && charpos
< SCHARS (object
))
21191 help
= Fget_text_property (make_number (charpos
),
21192 Qhelp_echo
, object
);
21195 /* If the string itself doesn't specify a help-echo,
21196 see if the buffer text ``under'' it does. */
21197 struct glyph_row
*r
21198 = MATRIX_ROW (w
->current_matrix
, vpos
);
21199 int start
= MATRIX_ROW_START_CHARPOS (r
);
21200 int pos
= string_buffer_position (w
, object
, start
);
21203 help
= Fget_char_property (make_number (pos
),
21204 Qhelp_echo
, w
->buffer
);
21208 object
= w
->buffer
;
21213 else if (BUFFERP (object
)
21216 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
21221 help_echo_string
= help
;
21222 help_echo_window
= window
;
21223 help_echo_object
= object
;
21224 help_echo_pos
= charpos
;
21229 /* Look for a `pointer' property. */
21230 if (NILP (pointer
))
21232 /* Check overlays first. */
21233 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
21234 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
21236 if (NILP (pointer
))
21238 Lisp_Object object
= glyph
->object
;
21239 int charpos
= glyph
->charpos
;
21241 /* Try text properties. */
21242 if (STRINGP (object
)
21244 && charpos
< SCHARS (object
))
21246 pointer
= Fget_text_property (make_number (charpos
),
21248 if (NILP (pointer
))
21250 /* If the string itself doesn't specify a pointer,
21251 see if the buffer text ``under'' it does. */
21252 struct glyph_row
*r
21253 = MATRIX_ROW (w
->current_matrix
, vpos
);
21254 int start
= MATRIX_ROW_START_CHARPOS (r
);
21255 int pos
= string_buffer_position (w
, object
, start
);
21257 pointer
= Fget_char_property (make_number (pos
),
21258 Qpointer
, w
->buffer
);
21261 else if (BUFFERP (object
)
21264 pointer
= Fget_text_property (make_number (charpos
),
21271 current_buffer
= obuf
;
21276 define_frame_cursor1 (f
, cursor
, pointer
);
21281 Clear any mouse-face on window W. This function is part of the
21282 redisplay interface, and is called from try_window_id and similar
21283 functions to ensure the mouse-highlight is off. */
21286 x_clear_window_mouse_face (w
)
21289 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21290 Lisp_Object window
;
21293 XSETWINDOW (window
, w
);
21294 if (EQ (window
, dpyinfo
->mouse_face_window
))
21295 clear_mouse_face (dpyinfo
);
21301 Just discard the mouse face information for frame F, if any.
21302 This is used when the size of F is changed. */
21305 cancel_mouse_face (f
)
21308 Lisp_Object window
;
21309 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21311 window
= dpyinfo
->mouse_face_window
;
21312 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
21314 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21315 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21316 dpyinfo
->mouse_face_window
= Qnil
;
21321 #endif /* HAVE_WINDOW_SYSTEM */
21324 /***********************************************************************
21326 ***********************************************************************/
21328 #ifdef HAVE_WINDOW_SYSTEM
21330 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
21331 which intersects rectangle R. R is in window-relative coordinates. */
21334 expose_area (w
, row
, r
, area
)
21336 struct glyph_row
*row
;
21338 enum glyph_row_area area
;
21340 struct glyph
*first
= row
->glyphs
[area
];
21341 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
21342 struct glyph
*last
;
21343 int first_x
, start_x
, x
;
21345 if (area
== TEXT_AREA
&& row
->fill_line_p
)
21346 /* If row extends face to end of line write the whole line. */
21347 draw_glyphs (w
, 0, row
, area
,
21348 0, row
->used
[area
],
21349 DRAW_NORMAL_TEXT
, 0);
21352 /* Set START_X to the window-relative start position for drawing glyphs of
21353 AREA. The first glyph of the text area can be partially visible.
21354 The first glyphs of other areas cannot. */
21355 start_x
= window_box_left_offset (w
, area
);
21357 if (area
== TEXT_AREA
)
21360 /* Find the first glyph that must be redrawn. */
21362 && x
+ first
->pixel_width
< r
->x
)
21364 x
+= first
->pixel_width
;
21368 /* Find the last one. */
21372 && x
< r
->x
+ r
->width
)
21374 x
+= last
->pixel_width
;
21380 draw_glyphs (w
, first_x
- start_x
, row
, area
,
21381 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
21382 DRAW_NORMAL_TEXT
, 0);
21387 /* Redraw the parts of the glyph row ROW on window W intersecting
21388 rectangle R. R is in window-relative coordinates. Value is
21389 non-zero if mouse-face was overwritten. */
21392 expose_line (w
, row
, r
)
21394 struct glyph_row
*row
;
21397 xassert (row
->enabled_p
);
21399 if (row
->mode_line_p
|| w
->pseudo_window_p
)
21400 draw_glyphs (w
, 0, row
, TEXT_AREA
,
21401 0, row
->used
[TEXT_AREA
],
21402 DRAW_NORMAL_TEXT
, 0);
21405 if (row
->used
[LEFT_MARGIN_AREA
])
21406 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
21407 if (row
->used
[TEXT_AREA
])
21408 expose_area (w
, row
, r
, TEXT_AREA
);
21409 if (row
->used
[RIGHT_MARGIN_AREA
])
21410 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
21411 draw_row_fringe_bitmaps (w
, row
);
21414 return row
->mouse_face_p
;
21418 /* Redraw those parts of glyphs rows during expose event handling that
21419 overlap other rows. Redrawing of an exposed line writes over parts
21420 of lines overlapping that exposed line; this function fixes that.
21422 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
21423 row in W's current matrix that is exposed and overlaps other rows.
21424 LAST_OVERLAPPING_ROW is the last such row. */
21427 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
21429 struct glyph_row
*first_overlapping_row
;
21430 struct glyph_row
*last_overlapping_row
;
21432 struct glyph_row
*row
;
21434 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
21435 if (row
->overlapping_p
)
21437 xassert (row
->enabled_p
&& !row
->mode_line_p
);
21439 if (row
->used
[LEFT_MARGIN_AREA
])
21440 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
21442 if (row
->used
[TEXT_AREA
])
21443 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
21445 if (row
->used
[RIGHT_MARGIN_AREA
])
21446 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
21451 /* Return non-zero if W's cursor intersects rectangle R. */
21454 phys_cursor_in_rect_p (w
, r
)
21458 XRectangle cr
, result
;
21459 struct glyph
*cursor_glyph
;
21461 cursor_glyph
= get_phys_cursor_glyph (w
);
21464 /* r is relative to W's box, but w->phys_cursor.x is relative
21465 to left edge of W's TEXT area. Adjust it. */
21466 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
21467 cr
.y
= w
->phys_cursor
.y
;
21468 cr
.width
= cursor_glyph
->pixel_width
;
21469 cr
.height
= w
->phys_cursor_height
;
21470 /* ++KFS: W32 version used W32-specific IntersectRect here, but
21471 I assume the effect is the same -- and this is portable. */
21472 return x_intersect_rectangles (&cr
, r
, &result
);
21480 Draw a vertical window border to the right of window W if W doesn't
21481 have vertical scroll bars. */
21484 x_draw_vertical_border (w
)
21487 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21489 /* We could do better, if we knew what type of scroll-bar the adjacent
21490 windows (on either side) have... But we don't :-(
21491 However, I think this works ok. ++KFS 2003-04-25 */
21493 /* Redraw borders between horizontally adjacent windows. Don't
21494 do it for frames with vertical scroll bars because either the
21495 right scroll bar of a window, or the left scroll bar of its
21496 neighbor will suffice as a border. */
21497 if (!WINDOW_RIGHTMOST_P (w
)
21498 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
21500 int x0
, x1
, y0
, y1
;
21502 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21505 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
21507 else if (!WINDOW_LEFTMOST_P (w
)
21508 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
21510 int x0
, x1
, y0
, y1
;
21512 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21515 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
21520 /* Redraw the part of window W intersection rectangle FR. Pixel
21521 coordinates in FR are frame-relative. Call this function with
21522 input blocked. Value is non-zero if the exposure overwrites
21526 expose_window (w
, fr
)
21530 struct frame
*f
= XFRAME (w
->frame
);
21532 int mouse_face_overwritten_p
= 0;
21534 /* If window is not yet fully initialized, do nothing. This can
21535 happen when toolkit scroll bars are used and a window is split.
21536 Reconfiguring the scroll bar will generate an expose for a newly
21538 if (w
->current_matrix
== NULL
)
21541 /* When we're currently updating the window, display and current
21542 matrix usually don't agree. Arrange for a thorough display
21544 if (w
== updated_window
)
21546 SET_FRAME_GARBAGED (f
);
21550 /* Frame-relative pixel rectangle of W. */
21551 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
21552 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
21553 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
21554 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
21556 if (x_intersect_rectangles (fr
, &wr
, &r
))
21558 int yb
= window_text_bottom_y (w
);
21559 struct glyph_row
*row
;
21560 int cursor_cleared_p
;
21561 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
21563 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
21564 r
.x
, r
.y
, r
.width
, r
.height
));
21566 /* Convert to window coordinates. */
21567 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
21568 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
21570 /* Turn off the cursor. */
21571 if (!w
->pseudo_window_p
21572 && phys_cursor_in_rect_p (w
, &r
))
21574 x_clear_cursor (w
);
21575 cursor_cleared_p
= 1;
21578 cursor_cleared_p
= 0;
21580 /* Update lines intersecting rectangle R. */
21581 first_overlapping_row
= last_overlapping_row
= NULL
;
21582 for (row
= w
->current_matrix
->rows
;
21587 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
21589 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
21590 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
21591 || (r
.y
>= y0
&& r
.y
< y1
)
21592 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
21594 if (row
->overlapping_p
)
21596 if (first_overlapping_row
== NULL
)
21597 first_overlapping_row
= row
;
21598 last_overlapping_row
= row
;
21601 if (expose_line (w
, row
, &r
))
21602 mouse_face_overwritten_p
= 1;
21609 /* Display the mode line if there is one. */
21610 if (WINDOW_WANTS_MODELINE_P (w
)
21611 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
21613 && row
->y
< r
.y
+ r
.height
)
21615 if (expose_line (w
, row
, &r
))
21616 mouse_face_overwritten_p
= 1;
21619 if (!w
->pseudo_window_p
)
21621 /* Fix the display of overlapping rows. */
21622 if (first_overlapping_row
)
21623 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
21625 /* Draw border between windows. */
21626 x_draw_vertical_border (w
);
21628 /* Turn the cursor on again. */
21629 if (cursor_cleared_p
)
21630 update_window_cursor (w
, 1);
21635 /* Display scroll bar for this window. */
21636 if (!NILP (w
->vertical_scroll_bar
))
21639 If this doesn't work here (maybe some header files are missing),
21640 make a function in macterm.c and call it to do the job! */
21642 = SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (w
->vertical_scroll_bar
));
21648 return mouse_face_overwritten_p
;
21653 /* Redraw (parts) of all windows in the window tree rooted at W that
21654 intersect R. R contains frame pixel coordinates. Value is
21655 non-zero if the exposure overwrites mouse-face. */
21658 expose_window_tree (w
, r
)
21662 struct frame
*f
= XFRAME (w
->frame
);
21663 int mouse_face_overwritten_p
= 0;
21665 while (w
&& !FRAME_GARBAGED_P (f
))
21667 if (!NILP (w
->hchild
))
21668 mouse_face_overwritten_p
21669 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
21670 else if (!NILP (w
->vchild
))
21671 mouse_face_overwritten_p
21672 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
21674 mouse_face_overwritten_p
|= expose_window (w
, r
);
21676 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
21679 return mouse_face_overwritten_p
;
21684 Redisplay an exposed area of frame F. X and Y are the upper-left
21685 corner of the exposed rectangle. W and H are width and height of
21686 the exposed area. All are pixel values. W or H zero means redraw
21687 the entire frame. */
21690 expose_frame (f
, x
, y
, w
, h
)
21695 int mouse_face_overwritten_p
= 0;
21697 TRACE ((stderr
, "expose_frame "));
21699 /* No need to redraw if frame will be redrawn soon. */
21700 if (FRAME_GARBAGED_P (f
))
21702 TRACE ((stderr
, " garbaged\n"));
21707 /* MAC_TODO: this is a kludge, but if scroll bars are not activated
21708 or deactivated here, for unknown reasons, activated scroll bars
21709 are shown in deactivated frames in some instances. */
21710 if (f
== FRAME_MAC_DISPLAY_INFO (f
)->x_focus_frame
)
21711 activate_scroll_bars (f
);
21713 deactivate_scroll_bars (f
);
21716 /* If basic faces haven't been realized yet, there is no point in
21717 trying to redraw anything. This can happen when we get an expose
21718 event while Emacs is starting, e.g. by moving another window. */
21719 if (FRAME_FACE_CACHE (f
) == NULL
21720 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
21722 TRACE ((stderr
, " no faces\n"));
21726 if (w
== 0 || h
== 0)
21729 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
21730 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
21740 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
21741 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
21743 if (WINDOWP (f
->tool_bar_window
))
21744 mouse_face_overwritten_p
21745 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
21747 #ifdef HAVE_X_WINDOWS
21749 #ifndef USE_X_TOOLKIT
21750 if (WINDOWP (f
->menu_bar_window
))
21751 mouse_face_overwritten_p
21752 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
21753 #endif /* not USE_X_TOOLKIT */
21757 /* Some window managers support a focus-follows-mouse style with
21758 delayed raising of frames. Imagine a partially obscured frame,
21759 and moving the mouse into partially obscured mouse-face on that
21760 frame. The visible part of the mouse-face will be highlighted,
21761 then the WM raises the obscured frame. With at least one WM, KDE
21762 2.1, Emacs is not getting any event for the raising of the frame
21763 (even tried with SubstructureRedirectMask), only Expose events.
21764 These expose events will draw text normally, i.e. not
21765 highlighted. Which means we must redo the highlight here.
21766 Subsume it under ``we love X''. --gerd 2001-08-15 */
21767 /* Included in Windows version because Windows most likely does not
21768 do the right thing if any third party tool offers
21769 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
21770 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
21772 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21773 if (f
== dpyinfo
->mouse_face_mouse_frame
)
21775 int x
= dpyinfo
->mouse_face_mouse_x
;
21776 int y
= dpyinfo
->mouse_face_mouse_y
;
21777 clear_mouse_face (dpyinfo
);
21778 note_mouse_highlight (f
, x
, y
);
21785 Determine the intersection of two rectangles R1 and R2. Return
21786 the intersection in *RESULT. Value is non-zero if RESULT is not
21790 x_intersect_rectangles (r1
, r2
, result
)
21791 XRectangle
*r1
, *r2
, *result
;
21793 XRectangle
*left
, *right
;
21794 XRectangle
*upper
, *lower
;
21795 int intersection_p
= 0;
21797 /* Rearrange so that R1 is the left-most rectangle. */
21799 left
= r1
, right
= r2
;
21801 left
= r2
, right
= r1
;
21803 /* X0 of the intersection is right.x0, if this is inside R1,
21804 otherwise there is no intersection. */
21805 if (right
->x
<= left
->x
+ left
->width
)
21807 result
->x
= right
->x
;
21809 /* The right end of the intersection is the minimum of the
21810 the right ends of left and right. */
21811 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
21814 /* Same game for Y. */
21816 upper
= r1
, lower
= r2
;
21818 upper
= r2
, lower
= r1
;
21820 /* The upper end of the intersection is lower.y0, if this is inside
21821 of upper. Otherwise, there is no intersection. */
21822 if (lower
->y
<= upper
->y
+ upper
->height
)
21824 result
->y
= lower
->y
;
21826 /* The lower end of the intersection is the minimum of the lower
21827 ends of upper and lower. */
21828 result
->height
= (min (lower
->y
+ lower
->height
,
21829 upper
->y
+ upper
->height
)
21831 intersection_p
= 1;
21835 return intersection_p
;
21838 #endif /* HAVE_WINDOW_SYSTEM */
21841 /***********************************************************************
21843 ***********************************************************************/
21848 Vwith_echo_area_save_vector
= Qnil
;
21849 staticpro (&Vwith_echo_area_save_vector
);
21851 Vmessage_stack
= Qnil
;
21852 staticpro (&Vmessage_stack
);
21854 Qinhibit_redisplay
= intern ("inhibit-redisplay");
21855 staticpro (&Qinhibit_redisplay
);
21857 message_dolog_marker1
= Fmake_marker ();
21858 staticpro (&message_dolog_marker1
);
21859 message_dolog_marker2
= Fmake_marker ();
21860 staticpro (&message_dolog_marker2
);
21861 message_dolog_marker3
= Fmake_marker ();
21862 staticpro (&message_dolog_marker3
);
21865 defsubr (&Sdump_frame_glyph_matrix
);
21866 defsubr (&Sdump_glyph_matrix
);
21867 defsubr (&Sdump_glyph_row
);
21868 defsubr (&Sdump_tool_bar_row
);
21869 defsubr (&Strace_redisplay
);
21870 defsubr (&Strace_to_stderr
);
21872 #ifdef HAVE_WINDOW_SYSTEM
21873 defsubr (&Stool_bar_lines_needed
);
21874 defsubr (&Slookup_image_map
);
21876 defsubr (&Sformat_mode_line
);
21878 staticpro (&Qmenu_bar_update_hook
);
21879 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
21881 staticpro (&Qoverriding_terminal_local_map
);
21882 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
21884 staticpro (&Qoverriding_local_map
);
21885 Qoverriding_local_map
= intern ("overriding-local-map");
21887 staticpro (&Qwindow_scroll_functions
);
21888 Qwindow_scroll_functions
= intern ("window-scroll-functions");
21890 staticpro (&Qredisplay_end_trigger_functions
);
21891 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
21893 staticpro (&Qinhibit_point_motion_hooks
);
21894 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
21896 QCdata
= intern (":data");
21897 staticpro (&QCdata
);
21898 Qdisplay
= intern ("display");
21899 staticpro (&Qdisplay
);
21900 Qspace_width
= intern ("space-width");
21901 staticpro (&Qspace_width
);
21902 Qraise
= intern ("raise");
21903 staticpro (&Qraise
);
21904 Qspace
= intern ("space");
21905 staticpro (&Qspace
);
21906 Qmargin
= intern ("margin");
21907 staticpro (&Qmargin
);
21908 Qpointer
= intern ("pointer");
21909 staticpro (&Qpointer
);
21910 Qleft_margin
= intern ("left-margin");
21911 staticpro (&Qleft_margin
);
21912 Qright_margin
= intern ("right-margin");
21913 staticpro (&Qright_margin
);
21914 QCalign_to
= intern (":align-to");
21915 staticpro (&QCalign_to
);
21916 QCrelative_width
= intern (":relative-width");
21917 staticpro (&QCrelative_width
);
21918 QCrelative_height
= intern (":relative-height");
21919 staticpro (&QCrelative_height
);
21920 QCeval
= intern (":eval");
21921 staticpro (&QCeval
);
21922 QCpropertize
= intern (":propertize");
21923 staticpro (&QCpropertize
);
21924 QCfile
= intern (":file");
21925 staticpro (&QCfile
);
21926 Qfontified
= intern ("fontified");
21927 staticpro (&Qfontified
);
21928 Qfontification_functions
= intern ("fontification-functions");
21929 staticpro (&Qfontification_functions
);
21930 Qtrailing_whitespace
= intern ("trailing-whitespace");
21931 staticpro (&Qtrailing_whitespace
);
21932 Qimage
= intern ("image");
21933 staticpro (&Qimage
);
21934 QCmap
= intern (":map");
21935 staticpro (&QCmap
);
21936 QCpointer
= intern (":pointer");
21937 staticpro (&QCpointer
);
21938 Qrect
= intern ("rect");
21939 staticpro (&Qrect
);
21940 Qcircle
= intern ("circle");
21941 staticpro (&Qcircle
);
21942 Qpoly
= intern ("poly");
21943 staticpro (&Qpoly
);
21944 Qmessage_truncate_lines
= intern ("message-truncate-lines");
21945 staticpro (&Qmessage_truncate_lines
);
21946 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
21947 staticpro (&Qcursor_in_non_selected_windows
);
21948 Qgrow_only
= intern ("grow-only");
21949 staticpro (&Qgrow_only
);
21950 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
21951 staticpro (&Qinhibit_menubar_update
);
21952 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
21953 staticpro (&Qinhibit_eval_during_redisplay
);
21954 Qposition
= intern ("position");
21955 staticpro (&Qposition
);
21956 Qbuffer_position
= intern ("buffer-position");
21957 staticpro (&Qbuffer_position
);
21958 Qobject
= intern ("object");
21959 staticpro (&Qobject
);
21960 Qbar
= intern ("bar");
21962 Qhbar
= intern ("hbar");
21963 staticpro (&Qhbar
);
21964 Qbox
= intern ("box");
21966 Qhollow
= intern ("hollow");
21967 staticpro (&Qhollow
);
21968 Qhand
= intern ("hand");
21969 staticpro (&Qhand
);
21970 Qarrow
= intern ("arrow");
21971 staticpro (&Qarrow
);
21972 Qtext
= intern ("text");
21973 staticpro (&Qtext
);
21974 Qrisky_local_variable
= intern ("risky-local-variable");
21975 staticpro (&Qrisky_local_variable
);
21976 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
21977 staticpro (&Qinhibit_free_realized_faces
);
21979 list_of_error
= Fcons (intern ("error"), Qnil
);
21980 staticpro (&list_of_error
);
21982 last_arrow_position
= Qnil
;
21983 last_arrow_string
= Qnil
;
21984 staticpro (&last_arrow_position
);
21985 staticpro (&last_arrow_string
);
21987 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
21988 staticpro (&echo_buffer
[0]);
21989 staticpro (&echo_buffer
[1]);
21991 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
21992 staticpro (&echo_area_buffer
[0]);
21993 staticpro (&echo_area_buffer
[1]);
21995 Vmessages_buffer_name
= build_string ("*Messages*");
21996 staticpro (&Vmessages_buffer_name
);
21998 mode_line_proptrans_alist
= Qnil
;
21999 staticpro (&mode_line_proptrans_alist
);
22001 mode_line_string_list
= Qnil
;
22002 staticpro (&mode_line_string_list
);
22004 help_echo_string
= Qnil
;
22005 staticpro (&help_echo_string
);
22006 help_echo_object
= Qnil
;
22007 staticpro (&help_echo_object
);
22008 help_echo_window
= Qnil
;
22009 staticpro (&help_echo_window
);
22010 previous_help_echo_string
= Qnil
;
22011 staticpro (&previous_help_echo_string
);
22012 help_echo_pos
= -1;
22014 #ifdef HAVE_WINDOW_SYSTEM
22015 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
22016 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
22017 For example, if a block cursor is over a tab, it will be drawn as
22018 wide as that tab on the display. */);
22019 x_stretch_cursor_p
= 0;
22022 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
22023 doc
: /* *Non-nil means highlight trailing whitespace.
22024 The face used for trailing whitespace is `trailing-whitespace'. */);
22025 Vshow_trailing_whitespace
= Qnil
;
22027 #ifdef HAVE_WINDOW_SYSTEM
22028 DEFVAR_LISP ("overflow-newline-into-fringe", &Voverflow_newline_into_fringe
,
22029 doc
: /* *Non-nil means that newline may flow into the right fringe.
22030 This means that display lines which are exactly as wide as the window
22031 (not counting the final newline) will only occupy one screen line, by
22032 showing (or hiding) the final newline in the right fringe; when point
22033 is at the final newline, the cursor is shown in the right fringe.
22034 If nil, also continue lines which are exactly as wide as the window. */);
22035 Voverflow_newline_into_fringe
= Qt
;
22038 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
22039 doc
: /* *The pointer shape to show in void text areas.
22040 Nil means to show the text pointer. Other options are `arrow', `text',
22041 `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
22042 Vvoid_text_area_pointer
= Qarrow
;
22044 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
22045 doc
: /* Non-nil means don't actually do any redisplay.
22046 This is used for internal purposes. */);
22047 Vinhibit_redisplay
= Qnil
;
22049 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
22050 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
22051 Vglobal_mode_string
= Qnil
;
22053 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
22054 doc
: /* Marker for where to display an arrow on top of the buffer text.
22055 This must be the beginning of a line in order to work.
22056 See also `overlay-arrow-string'. */);
22057 Voverlay_arrow_position
= Qnil
;
22059 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
22060 doc
: /* String to display as an arrow. See also `overlay-arrow-position'. */);
22061 Voverlay_arrow_string
= Qnil
;
22063 DEFVAR_INT ("scroll-step", &scroll_step
,
22064 doc
: /* *The number of lines to try scrolling a window by when point moves out.
22065 If that fails to bring point back on frame, point is centered instead.
22066 If this is zero, point is always centered after it moves off frame.
22067 If you want scrolling to always be a line at a time, you should set
22068 `scroll-conservatively' to a large value rather than set this to 1. */);
22070 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
22071 doc
: /* *Scroll up to this many lines, to bring point back on screen.
22072 A value of zero means to scroll the text to center point vertically
22073 in the window. */);
22074 scroll_conservatively
= 0;
22076 DEFVAR_INT ("scroll-margin", &scroll_margin
,
22077 doc
: /* *Number of lines of margin at the top and bottom of a window.
22078 Recenter the window whenever point gets within this many lines
22079 of the top or bottom of the window. */);
22082 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
22083 doc
: /* Pixels per inch on current display.
22084 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
22085 Vdisplay_pixels_per_inch
= make_float (72.0);
22088 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
22091 DEFVAR_BOOL ("truncate-partial-width-windows",
22092 &truncate_partial_width_windows
,
22093 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
22094 truncate_partial_width_windows
= 1;
22096 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
22097 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
22098 Any other value means to use the appropriate face, `mode-line',
22099 `header-line', or `menu' respectively. */);
22100 mode_line_inverse_video
= 1;
22102 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
22103 doc
: /* *Maximum buffer size for which line number should be displayed.
22104 If the buffer is bigger than this, the line number does not appear
22105 in the mode line. A value of nil means no limit. */);
22106 Vline_number_display_limit
= Qnil
;
22108 DEFVAR_INT ("line-number-display-limit-width",
22109 &line_number_display_limit_width
,
22110 doc
: /* *Maximum line width (in characters) for line number display.
22111 If the average length of the lines near point is bigger than this, then the
22112 line number may be omitted from the mode line. */);
22113 line_number_display_limit_width
= 200;
22115 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
22116 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
22117 highlight_nonselected_windows
= 0;
22119 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
22120 doc
: /* Non-nil if more than one frame is visible on this display.
22121 Minibuffer-only frames don't count, but iconified frames do.
22122 This variable is not guaranteed to be accurate except while processing
22123 `frame-title-format' and `icon-title-format'. */);
22125 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
22126 doc
: /* Template for displaying the title bar of visible frames.
22127 \(Assuming the window manager supports this feature.)
22128 This variable has the same structure as `mode-line-format' (which see),
22129 and is used only on frames for which no explicit name has been set
22130 \(see `modify-frame-parameters'). */);
22132 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
22133 doc
: /* Template for displaying the title bar of an iconified frame.
22134 \(Assuming the window manager supports this feature.)
22135 This variable has the same structure as `mode-line-format' (which see),
22136 and is used only on frames for which no explicit name has been set
22137 \(see `modify-frame-parameters'). */);
22139 = Vframe_title_format
22140 = Fcons (intern ("multiple-frames"),
22141 Fcons (build_string ("%b"),
22142 Fcons (Fcons (empty_string
,
22143 Fcons (intern ("invocation-name"),
22144 Fcons (build_string ("@"),
22145 Fcons (intern ("system-name"),
22149 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
22150 doc
: /* Maximum number of lines to keep in the message log buffer.
22151 If nil, disable message logging. If t, log messages but don't truncate
22152 the buffer when it becomes large. */);
22153 Vmessage_log_max
= make_number (50);
22155 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
22156 doc
: /* Functions called before redisplay, if window sizes have changed.
22157 The value should be a list of functions that take one argument.
22158 Just before redisplay, for each frame, if any of its windows have changed
22159 size since the last redisplay, or have been split or deleted,
22160 all the functions in the list are called, with the frame as argument. */);
22161 Vwindow_size_change_functions
= Qnil
;
22163 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
22164 doc
: /* List of Functions to call before redisplaying a window with scrolling.
22165 Each function is called with two arguments, the window
22166 and its new display-start position. Note that the value of `window-end'
22167 is not valid when these functions are called. */);
22168 Vwindow_scroll_functions
= Qnil
;
22170 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
22171 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
22172 mouse_autoselect_window
= 0;
22174 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
22175 doc
: /* *Non-nil means automatically resize tool-bars.
22176 This increases a tool-bar's height if not all tool-bar items are visible.
22177 It decreases a tool-bar's height when it would display blank lines
22179 auto_resize_tool_bars_p
= 1;
22181 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
22182 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
22183 auto_raise_tool_bar_buttons_p
= 1;
22185 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
22186 doc
: /* *Margin around tool-bar buttons in pixels.
22187 If an integer, use that for both horizontal and vertical margins.
22188 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
22189 HORZ specifying the horizontal margin, and VERT specifying the
22190 vertical margin. */);
22191 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
22193 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
22194 doc
: /* *Relief thickness of tool-bar buttons. */);
22195 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
22197 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
22198 doc
: /* List of functions to call to fontify regions of text.
22199 Each function is called with one argument POS. Functions must
22200 fontify a region starting at POS in the current buffer, and give
22201 fontified regions the property `fontified'. */);
22202 Vfontification_functions
= Qnil
;
22203 Fmake_variable_buffer_local (Qfontification_functions
);
22205 DEFVAR_BOOL ("unibyte-display-via-language-environment",
22206 &unibyte_display_via_language_environment
,
22207 doc
: /* *Non-nil means display unibyte text according to language environment.
22208 Specifically this means that unibyte non-ASCII characters
22209 are displayed by converting them to the equivalent multibyte characters
22210 according to the current language environment. As a result, they are
22211 displayed according to the current fontset. */);
22212 unibyte_display_via_language_environment
= 0;
22214 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
22215 doc
: /* *Maximum height for resizing mini-windows.
22216 If a float, it specifies a fraction of the mini-window frame's height.
22217 If an integer, it specifies a number of lines. */);
22218 Vmax_mini_window_height
= make_float (0.25);
22220 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
22221 doc
: /* *How to resize mini-windows.
22222 A value of nil means don't automatically resize mini-windows.
22223 A value of t means resize them to fit the text displayed in them.
22224 A value of `grow-only', the default, means let mini-windows grow
22225 only, until their display becomes empty, at which point the windows
22226 go back to their normal size. */);
22227 Vresize_mini_windows
= Qgrow_only
;
22229 DEFVAR_LISP ("cursor-in-non-selected-windows",
22230 &Vcursor_in_non_selected_windows
,
22231 doc
: /* *Cursor type to display in non-selected windows.
22232 t means to use hollow box cursor. See `cursor-type' for other values. */);
22233 Vcursor_in_non_selected_windows
= Qt
;
22235 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
22236 doc
: /* Alist specifying how to blink the cursor off.
22237 Each element has the form (ON-STATE . OFF-STATE). Whenever the
22238 `cursor-type' frame-parameter or variable equals ON-STATE,
22239 comparing using `equal', Emacs uses OFF-STATE to specify
22240 how to blink it off. */);
22241 Vblink_cursor_alist
= Qnil
;
22243 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
22244 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
22245 automatic_hscrolling_p
= 1;
22247 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
22248 doc
: /* *How many columns away from the window edge point is allowed to get
22249 before automatic hscrolling will horizontally scroll the window. */);
22250 hscroll_margin
= 5;
22252 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
22253 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
22254 When point is less than `automatic-hscroll-margin' columns from the window
22255 edge, automatic hscrolling will scroll the window by the amount of columns
22256 determined by this variable. If its value is a positive integer, scroll that
22257 many columns. If it's a positive floating-point number, it specifies the
22258 fraction of the window's width to scroll. If it's nil or zero, point will be
22259 centered horizontally after the scroll. Any other value, including negative
22260 numbers, are treated as if the value were zero.
22262 Automatic hscrolling always moves point outside the scroll margin, so if
22263 point was more than scroll step columns inside the margin, the window will
22264 scroll more than the value given by the scroll step.
22266 Note that the lower bound for automatic hscrolling specified by `scroll-left'
22267 and `scroll-right' overrides this variable's effect. */);
22268 Vhscroll_step
= make_number (0);
22270 DEFVAR_LISP ("image-types", &Vimage_types
,
22271 doc
: /* List of supported image types.
22272 Each element of the list is a symbol for a supported image type. */);
22273 Vimage_types
= Qnil
;
22275 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
22276 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
22277 Bind this around calls to `message' to let it take effect. */);
22278 message_truncate_lines
= 0;
22280 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
22281 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
22282 Can be used to update submenus whose contents should vary. */);
22283 Vmenu_bar_update_hook
= Qnil
;
22285 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
22286 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
22287 inhibit_menubar_update
= 0;
22289 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
22290 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
22291 inhibit_eval_during_redisplay
= 0;
22293 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
22294 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
22295 inhibit_free_realized_faces
= 0;
22298 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
22299 doc
: /* Inhibit try_window_id display optimization. */);
22300 inhibit_try_window_id
= 0;
22302 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
22303 doc
: /* Inhibit try_window_reusing display optimization. */);
22304 inhibit_try_window_reusing
= 0;
22306 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
22307 doc
: /* Inhibit try_cursor_movement display optimization. */);
22308 inhibit_try_cursor_movement
= 0;
22309 #endif /* GLYPH_DEBUG */
22313 /* Initialize this module when Emacs starts. */
22318 Lisp_Object root_window
;
22319 struct window
*mini_w
;
22321 current_header_line_height
= current_mode_line_height
= -1;
22323 CHARPOS (this_line_start_pos
) = 0;
22325 mini_w
= XWINDOW (minibuf_window
);
22326 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
22328 if (!noninteractive
)
22330 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
22333 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
22334 set_window_height (root_window
,
22335 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
22337 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
22338 set_window_height (minibuf_window
, 1, 0);
22340 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
22341 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
22343 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
22344 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
22345 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
22347 /* The default ellipsis glyphs `...'. */
22348 for (i
= 0; i
< 3; ++i
)
22349 default_invis_vector
[i
] = make_number ('.');
22353 /* Allocate the buffer for frame titles.
22354 Also used for `format-mode-line'. */
22356 frame_title_buf
= (char *) xmalloc (size
);
22357 frame_title_buf_end
= frame_title_buf
+ size
;
22358 frame_title_ptr
= NULL
;
22361 help_echo_showing_p
= 0;
22365 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
22366 (do not change this comment) */