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 (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 /* coding-system (not including end-of-line format) */
16681 /* coding-system (including end-of-line type) */
16683 int eol_flag
= (c
== 'Z');
16684 char *p
= decode_mode_spec_buf
;
16686 if (! FRAME_WINDOW_P (f
))
16688 /* No need to mention EOL here--the terminal never needs
16689 to do EOL conversion. */
16690 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
16691 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
16693 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
16696 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
16697 #ifdef subprocesses
16698 obj
= Fget_buffer_process (Fcurrent_buffer ());
16699 if (PROCESSP (obj
))
16701 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
16703 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
16706 #endif /* subprocesses */
16709 return decode_mode_spec_buf
;
16715 *multibyte
= STRING_MULTIBYTE (obj
);
16716 return (char *) SDATA (obj
);
16723 /* Count up to COUNT lines starting from START / START_BYTE.
16724 But don't go beyond LIMIT_BYTE.
16725 Return the number of lines thus found (always nonnegative).
16727 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
16730 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
16731 int start
, start_byte
, limit_byte
, count
;
16734 register unsigned char *cursor
;
16735 unsigned char *base
;
16737 register int ceiling
;
16738 register unsigned char *ceiling_addr
;
16739 int orig_count
= count
;
16741 /* If we are not in selective display mode,
16742 check only for newlines. */
16743 int selective_display
= (!NILP (current_buffer
->selective_display
)
16744 && !INTEGERP (current_buffer
->selective_display
));
16748 while (start_byte
< limit_byte
)
16750 ceiling
= BUFFER_CEILING_OF (start_byte
);
16751 ceiling
= min (limit_byte
- 1, ceiling
);
16752 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
16753 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
16756 if (selective_display
)
16757 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
16760 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
16763 if (cursor
!= ceiling_addr
)
16767 start_byte
+= cursor
- base
+ 1;
16768 *byte_pos_ptr
= start_byte
;
16772 if (++cursor
== ceiling_addr
)
16778 start_byte
+= cursor
- base
;
16783 while (start_byte
> limit_byte
)
16785 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
16786 ceiling
= max (limit_byte
, ceiling
);
16787 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
16788 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
16791 if (selective_display
)
16792 while (--cursor
!= ceiling_addr
16793 && *cursor
!= '\n' && *cursor
!= 015)
16796 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
16799 if (cursor
!= ceiling_addr
)
16803 start_byte
+= cursor
- base
+ 1;
16804 *byte_pos_ptr
= start_byte
;
16805 /* When scanning backwards, we should
16806 not count the newline posterior to which we stop. */
16807 return - orig_count
- 1;
16813 /* Here we add 1 to compensate for the last decrement
16814 of CURSOR, which took it past the valid range. */
16815 start_byte
+= cursor
- base
+ 1;
16819 *byte_pos_ptr
= limit_byte
;
16822 return - orig_count
+ count
;
16823 return orig_count
- count
;
16829 /***********************************************************************
16831 ***********************************************************************/
16833 /* Display a NUL-terminated string, starting with index START.
16835 If STRING is non-null, display that C string. Otherwise, the Lisp
16836 string LISP_STRING is displayed.
16838 If FACE_STRING is not nil, FACE_STRING_POS is a position in
16839 FACE_STRING. Display STRING or LISP_STRING with the face at
16840 FACE_STRING_POS in FACE_STRING:
16842 Display the string in the environment given by IT, but use the
16843 standard display table, temporarily.
16845 FIELD_WIDTH is the minimum number of output glyphs to produce.
16846 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16847 with spaces. If STRING has more characters, more than FIELD_WIDTH
16848 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
16850 PRECISION is the maximum number of characters to output from
16851 STRING. PRECISION < 0 means don't truncate the string.
16853 This is roughly equivalent to printf format specifiers:
16855 FIELD_WIDTH PRECISION PRINTF
16856 ----------------------------------------
16862 MULTIBYTE zero means do not display multibyte chars, > 0 means do
16863 display them, and < 0 means obey the current buffer's value of
16864 enable_multibyte_characters.
16866 Value is the number of glyphs produced. */
16869 display_string (string
, lisp_string
, face_string
, face_string_pos
,
16870 start
, it
, field_width
, precision
, max_x
, multibyte
)
16871 unsigned char *string
;
16872 Lisp_Object lisp_string
;
16873 Lisp_Object face_string
;
16874 int face_string_pos
;
16877 int field_width
, precision
, max_x
;
16880 int hpos_at_start
= it
->hpos
;
16881 int saved_face_id
= it
->face_id
;
16882 struct glyph_row
*row
= it
->glyph_row
;
16884 /* Initialize the iterator IT for iteration over STRING beginning
16885 with index START. */
16886 reseat_to_string (it
, string
, lisp_string
, start
,
16887 precision
, field_width
, multibyte
);
16889 /* If displaying STRING, set up the face of the iterator
16890 from LISP_STRING, if that's given. */
16891 if (STRINGP (face_string
))
16897 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
16898 0, it
->region_beg_charpos
,
16899 it
->region_end_charpos
,
16900 &endptr
, it
->base_face_id
, 0);
16901 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16902 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
16905 /* Set max_x to the maximum allowed X position. Don't let it go
16906 beyond the right edge of the window. */
16908 max_x
= it
->last_visible_x
;
16910 max_x
= min (max_x
, it
->last_visible_x
);
16912 /* Skip over display elements that are not visible. because IT->w is
16914 if (it
->current_x
< it
->first_visible_x
)
16915 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
16916 MOVE_TO_POS
| MOVE_TO_X
);
16918 row
->ascent
= it
->max_ascent
;
16919 row
->height
= it
->max_ascent
+ it
->max_descent
;
16920 row
->phys_ascent
= it
->max_phys_ascent
;
16921 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16923 /* This condition is for the case that we are called with current_x
16924 past last_visible_x. */
16925 while (it
->current_x
< max_x
)
16927 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
16929 /* Get the next display element. */
16930 if (!get_next_display_element (it
))
16933 /* Produce glyphs. */
16934 x_before
= it
->current_x
;
16935 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16936 PRODUCE_GLYPHS (it
);
16938 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
16941 while (i
< nglyphs
)
16943 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16945 if (!it
->truncate_lines_p
16946 && x
+ glyph
->pixel_width
> max_x
)
16948 /* End of continued line or max_x reached. */
16949 if (CHAR_GLYPH_PADDING_P (*glyph
))
16951 /* A wide character is unbreakable. */
16952 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16953 it
->current_x
= x_before
;
16957 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16962 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
16964 /* Glyph is at least partially visible. */
16966 if (x
< it
->first_visible_x
)
16967 it
->glyph_row
->x
= x
- it
->first_visible_x
;
16971 /* Glyph is off the left margin of the display area.
16972 Should not happen. */
16976 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16977 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16978 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16979 row
->phys_height
= max (row
->phys_height
,
16980 it
->max_phys_ascent
+ it
->max_phys_descent
);
16981 x
+= glyph
->pixel_width
;
16985 /* Stop if max_x reached. */
16989 /* Stop at line ends. */
16990 if (ITERATOR_AT_END_OF_LINE_P (it
))
16992 it
->continuation_lines_width
= 0;
16996 set_iterator_to_next (it
, 1);
16998 /* Stop if truncating at the right edge. */
16999 if (it
->truncate_lines_p
17000 && it
->current_x
>= it
->last_visible_x
)
17002 /* Add truncation mark, but don't do it if the line is
17003 truncated at a padding space. */
17004 if (IT_CHARPOS (*it
) < it
->string_nchars
)
17006 if (!FRAME_WINDOW_P (it
->f
))
17010 if (it
->current_x
> it
->last_visible_x
)
17012 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17013 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17015 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17017 row
->used
[TEXT_AREA
] = i
;
17018 produce_special_glyphs (it
, IT_TRUNCATION
);
17021 produce_special_glyphs (it
, IT_TRUNCATION
);
17023 it
->glyph_row
->truncated_on_right_p
= 1;
17029 /* Maybe insert a truncation at the left. */
17030 if (it
->first_visible_x
17031 && IT_CHARPOS (*it
) > 0)
17033 if (!FRAME_WINDOW_P (it
->f
))
17034 insert_left_trunc_glyphs (it
);
17035 it
->glyph_row
->truncated_on_left_p
= 1;
17038 it
->face_id
= saved_face_id
;
17040 /* Value is number of columns displayed. */
17041 return it
->hpos
- hpos_at_start
;
17046 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
17047 appears as an element of LIST or as the car of an element of LIST.
17048 If PROPVAL is a list, compare each element against LIST in that
17049 way, and return 1/2 if any element of PROPVAL is found in LIST.
17050 Otherwise return 0. This function cannot quit.
17051 The return value is 2 if the text is invisible but with an ellipsis
17052 and 1 if it's invisible and without an ellipsis. */
17055 invisible_p (propval
, list
)
17056 register Lisp_Object propval
;
17059 register Lisp_Object tail
, proptail
;
17061 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17063 register Lisp_Object tem
;
17065 if (EQ (propval
, tem
))
17067 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
17068 return NILP (XCDR (tem
)) ? 1 : 2;
17071 if (CONSP (propval
))
17073 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
17075 Lisp_Object propelt
;
17076 propelt
= XCAR (proptail
);
17077 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17079 register Lisp_Object tem
;
17081 if (EQ (propelt
, tem
))
17083 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
17084 return NILP (XCDR (tem
)) ? 1 : 2;
17093 /***********************************************************************
17095 ***********************************************************************/
17097 #ifdef HAVE_WINDOW_SYSTEM
17102 dump_glyph_string (s
)
17103 struct glyph_string
*s
;
17105 fprintf (stderr
, "glyph string\n");
17106 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
17107 s
->x
, s
->y
, s
->width
, s
->height
);
17108 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
17109 fprintf (stderr
, " hl = %d\n", s
->hl
);
17110 fprintf (stderr
, " left overhang = %d, right = %d\n",
17111 s
->left_overhang
, s
->right_overhang
);
17112 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
17113 fprintf (stderr
, " extends to end of line = %d\n",
17114 s
->extends_to_end_of_line_p
);
17115 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
17116 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
17119 #endif /* GLYPH_DEBUG */
17121 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
17122 of XChar2b structures for S; it can't be allocated in
17123 init_glyph_string because it must be allocated via `alloca'. W
17124 is the window on which S is drawn. ROW and AREA are the glyph row
17125 and area within the row from which S is constructed. START is the
17126 index of the first glyph structure covered by S. HL is a
17127 face-override for drawing S. */
17130 #define OPTIONAL_HDC(hdc) hdc,
17131 #define DECLARE_HDC(hdc) HDC hdc;
17132 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
17133 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
17136 #ifndef OPTIONAL_HDC
17137 #define OPTIONAL_HDC(hdc)
17138 #define DECLARE_HDC(hdc)
17139 #define ALLOCATE_HDC(hdc, f)
17140 #define RELEASE_HDC(hdc, f)
17144 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
17145 struct glyph_string
*s
;
17149 struct glyph_row
*row
;
17150 enum glyph_row_area area
;
17152 enum draw_glyphs_face hl
;
17154 bzero (s
, sizeof *s
);
17156 s
->f
= XFRAME (w
->frame
);
17160 s
->display
= FRAME_X_DISPLAY (s
->f
);
17161 s
->window
= FRAME_X_WINDOW (s
->f
);
17162 s
->char2b
= char2b
;
17166 s
->first_glyph
= row
->glyphs
[area
] + start
;
17167 s
->height
= row
->height
;
17168 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
17170 /* Display the internal border below the tool-bar window. */
17171 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
17172 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
17174 s
->ybase
= s
->y
+ row
->ascent
;
17178 /* Append the list of glyph strings with head H and tail T to the list
17179 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
17182 append_glyph_string_lists (head
, tail
, h
, t
)
17183 struct glyph_string
**head
, **tail
;
17184 struct glyph_string
*h
, *t
;
17198 /* Prepend the list of glyph strings with head H and tail T to the
17199 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
17203 prepend_glyph_string_lists (head
, tail
, h
, t
)
17204 struct glyph_string
**head
, **tail
;
17205 struct glyph_string
*h
, *t
;
17219 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
17220 Set *HEAD and *TAIL to the resulting list. */
17223 append_glyph_string (head
, tail
, s
)
17224 struct glyph_string
**head
, **tail
;
17225 struct glyph_string
*s
;
17227 s
->next
= s
->prev
= NULL
;
17228 append_glyph_string_lists (head
, tail
, s
, s
);
17232 /* Get face and two-byte form of character glyph GLYPH on frame F.
17233 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
17234 a pointer to a realized face that is ready for display. */
17236 static INLINE
struct face
*
17237 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
17239 struct glyph
*glyph
;
17245 xassert (glyph
->type
== CHAR_GLYPH
);
17246 face
= FACE_FROM_ID (f
, glyph
->face_id
);
17251 if (!glyph
->multibyte_p
)
17253 /* Unibyte case. We don't have to encode, but we have to make
17254 sure to use a face suitable for unibyte. */
17255 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17257 else if (glyph
->u
.ch
< 128
17258 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
17260 /* Case of ASCII in a face known to fit ASCII. */
17261 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17265 int c1
, c2
, charset
;
17267 /* Split characters into bytes. If c2 is -1 afterwards, C is
17268 really a one-byte character so that byte1 is zero. */
17269 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
17271 STORE_XCHAR2B (char2b
, c1
, c2
);
17273 STORE_XCHAR2B (char2b
, 0, c1
);
17275 /* Maybe encode the character in *CHAR2B. */
17276 if (charset
!= CHARSET_ASCII
)
17278 struct font_info
*font_info
17279 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17282 = FRAME_RIF (f
)->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
17286 /* Make sure X resources of the face are allocated. */
17287 xassert (face
!= NULL
);
17288 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17293 /* Fill glyph string S with composition components specified by S->cmp.
17295 FACES is an array of faces for all components of this composition.
17296 S->gidx is the index of the first component for S.
17297 OVERLAPS_P non-zero means S should draw the foreground only, and
17298 use its physical height for clipping.
17300 Value is the index of a component not in S. */
17303 fill_composite_glyph_string (s
, faces
, overlaps_p
)
17304 struct glyph_string
*s
;
17305 struct face
**faces
;
17312 s
->for_overlaps_p
= overlaps_p
;
17314 s
->face
= faces
[s
->gidx
];
17315 s
->font
= s
->face
->font
;
17316 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17318 /* For all glyphs of this composition, starting at the offset
17319 S->gidx, until we reach the end of the definition or encounter a
17320 glyph that requires the different face, add it to S. */
17322 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
17325 /* All glyph strings for the same composition has the same width,
17326 i.e. the width set for the first component of the composition. */
17328 s
->width
= s
->first_glyph
->pixel_width
;
17330 /* If the specified font could not be loaded, use the frame's
17331 default font, but record the fact that we couldn't load it in
17332 the glyph string so that we can draw rectangles for the
17333 characters of the glyph string. */
17334 if (s
->font
== NULL
)
17336 s
->font_not_found_p
= 1;
17337 s
->font
= FRAME_FONT (s
->f
);
17340 /* Adjust base line for subscript/superscript text. */
17341 s
->ybase
+= s
->first_glyph
->voffset
;
17343 xassert (s
->face
&& s
->face
->gc
);
17345 /* This glyph string must always be drawn with 16-bit functions. */
17348 return s
->gidx
+ s
->nchars
;
17352 /* Fill glyph string S from a sequence of character glyphs.
17354 FACE_ID is the face id of the string. START is the index of the
17355 first glyph to consider, END is the index of the last + 1.
17356 OVERLAPS_P non-zero means S should draw the foreground only, and
17357 use its physical height for clipping.
17359 Value is the index of the first glyph not in S. */
17362 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
17363 struct glyph_string
*s
;
17365 int start
, end
, overlaps_p
;
17367 struct glyph
*glyph
, *last
;
17369 int glyph_not_available_p
;
17371 xassert (s
->f
== XFRAME (s
->w
->frame
));
17372 xassert (s
->nchars
== 0);
17373 xassert (start
>= 0 && end
> start
);
17375 s
->for_overlaps_p
= overlaps_p
,
17376 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17377 last
= s
->row
->glyphs
[s
->area
] + end
;
17378 voffset
= glyph
->voffset
;
17380 glyph_not_available_p
= glyph
->glyph_not_available_p
;
17382 while (glyph
< last
17383 && glyph
->type
== CHAR_GLYPH
17384 && glyph
->voffset
== voffset
17385 /* Same face id implies same font, nowadays. */
17386 && glyph
->face_id
== face_id
17387 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
17391 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
17392 s
->char2b
+ s
->nchars
,
17394 s
->two_byte_p
= two_byte_p
;
17396 xassert (s
->nchars
<= end
- start
);
17397 s
->width
+= glyph
->pixel_width
;
17401 s
->font
= s
->face
->font
;
17402 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17404 /* If the specified font could not be loaded, use the frame's font,
17405 but record the fact that we couldn't load it in
17406 S->font_not_found_p so that we can draw rectangles for the
17407 characters of the glyph string. */
17408 if (s
->font
== NULL
|| glyph_not_available_p
)
17410 s
->font_not_found_p
= 1;
17411 s
->font
= FRAME_FONT (s
->f
);
17414 /* Adjust base line for subscript/superscript text. */
17415 s
->ybase
+= voffset
;
17417 xassert (s
->face
&& s
->face
->gc
);
17418 return glyph
- s
->row
->glyphs
[s
->area
];
17422 /* Fill glyph string S from image glyph S->first_glyph. */
17425 fill_image_glyph_string (s
)
17426 struct glyph_string
*s
;
17428 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
17429 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
17431 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
17432 s
->font
= s
->face
->font
;
17433 s
->width
= s
->first_glyph
->pixel_width
;
17435 /* Adjust base line for subscript/superscript text. */
17436 s
->ybase
+= s
->first_glyph
->voffset
;
17440 /* Fill glyph string S from a sequence of stretch glyphs.
17442 ROW is the glyph row in which the glyphs are found, AREA is the
17443 area within the row. START is the index of the first glyph to
17444 consider, END is the index of the last + 1.
17446 Value is the index of the first glyph not in S. */
17449 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
17450 struct glyph_string
*s
;
17451 struct glyph_row
*row
;
17452 enum glyph_row_area area
;
17455 struct glyph
*glyph
, *last
;
17456 int voffset
, face_id
;
17458 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
17460 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17461 last
= s
->row
->glyphs
[s
->area
] + end
;
17462 face_id
= glyph
->face_id
;
17463 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
17464 s
->font
= s
->face
->font
;
17465 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17466 s
->width
= glyph
->pixel_width
;
17467 voffset
= glyph
->voffset
;
17471 && glyph
->type
== STRETCH_GLYPH
17472 && glyph
->voffset
== voffset
17473 && glyph
->face_id
== face_id
);
17475 s
->width
+= glyph
->pixel_width
;
17477 /* Adjust base line for subscript/superscript text. */
17478 s
->ybase
+= voffset
;
17480 /* The case that face->gc == 0 is handled when drawing the glyph
17481 string by calling PREPARE_FACE_FOR_DISPLAY. */
17483 return glyph
- s
->row
->glyphs
[s
->area
];
17488 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
17489 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
17490 assumed to be zero. */
17493 x_get_glyph_overhangs (glyph
, f
, left
, right
)
17494 struct glyph
*glyph
;
17498 *left
= *right
= 0;
17500 if (glyph
->type
== CHAR_GLYPH
)
17504 struct font_info
*font_info
;
17508 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
17510 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17511 if (font
/* ++KFS: Should this be font_info ? */
17512 && (pcm
= FRAME_RIF (f
)->per_char_metric (font
, &char2b
, glyph
->font_type
)))
17514 if (pcm
->rbearing
> pcm
->width
)
17515 *right
= pcm
->rbearing
- pcm
->width
;
17516 if (pcm
->lbearing
< 0)
17517 *left
= -pcm
->lbearing
;
17523 /* Return the index of the first glyph preceding glyph string S that
17524 is overwritten by S because of S's left overhang. Value is -1
17525 if no glyphs are overwritten. */
17528 left_overwritten (s
)
17529 struct glyph_string
*s
;
17533 if (s
->left_overhang
)
17536 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17537 int first
= s
->first_glyph
- glyphs
;
17539 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
17540 x
-= glyphs
[i
].pixel_width
;
17551 /* Return the index of the first glyph preceding glyph string S that
17552 is overwriting S because of its right overhang. Value is -1 if no
17553 glyph in front of S overwrites S. */
17556 left_overwriting (s
)
17557 struct glyph_string
*s
;
17560 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17561 int first
= s
->first_glyph
- glyphs
;
17565 for (i
= first
- 1; i
>= 0; --i
)
17568 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17571 x
-= glyphs
[i
].pixel_width
;
17578 /* Return the index of the last glyph following glyph string S that is
17579 not overwritten by S because of S's right overhang. Value is -1 if
17580 no such glyph is found. */
17583 right_overwritten (s
)
17584 struct glyph_string
*s
;
17588 if (s
->right_overhang
)
17591 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17592 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17593 int end
= s
->row
->used
[s
->area
];
17595 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
17596 x
+= glyphs
[i
].pixel_width
;
17605 /* Return the index of the last glyph following glyph string S that
17606 overwrites S because of its left overhang. Value is negative
17607 if no such glyph is found. */
17610 right_overwriting (s
)
17611 struct glyph_string
*s
;
17614 int end
= s
->row
->used
[s
->area
];
17615 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17616 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17620 for (i
= first
; i
< end
; ++i
)
17623 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17626 x
+= glyphs
[i
].pixel_width
;
17633 /* Get face and two-byte form of character C in face FACE_ID on frame
17634 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
17635 means we want to display multibyte text. DISPLAY_P non-zero means
17636 make sure that X resources for the face returned are allocated.
17637 Value is a pointer to a realized face that is ready for display if
17638 DISPLAY_P is non-zero. */
17640 static INLINE
struct face
*
17641 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
17645 int multibyte_p
, display_p
;
17647 struct face
*face
= FACE_FROM_ID (f
, face_id
);
17651 /* Unibyte case. We don't have to encode, but we have to make
17652 sure to use a face suitable for unibyte. */
17653 STORE_XCHAR2B (char2b
, 0, c
);
17654 face_id
= FACE_FOR_CHAR (f
, face
, c
);
17655 face
= FACE_FROM_ID (f
, face_id
);
17657 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
17659 /* Case of ASCII in a face known to fit ASCII. */
17660 STORE_XCHAR2B (char2b
, 0, c
);
17664 int c1
, c2
, charset
;
17666 /* Split characters into bytes. If c2 is -1 afterwards, C is
17667 really a one-byte character so that byte1 is zero. */
17668 SPLIT_CHAR (c
, charset
, c1
, c2
);
17670 STORE_XCHAR2B (char2b
, c1
, c2
);
17672 STORE_XCHAR2B (char2b
, 0, c1
);
17674 /* Maybe encode the character in *CHAR2B. */
17675 if (face
->font
!= NULL
)
17677 struct font_info
*font_info
17678 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17680 FRAME_RIF (f
)->encode_char (c
, char2b
, font_info
, 0);
17684 /* Make sure X resources of the face are allocated. */
17685 #ifdef HAVE_X_WINDOWS
17689 xassert (face
!= NULL
);
17690 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17697 /* Set background width of glyph string S. START is the index of the
17698 first glyph following S. LAST_X is the right-most x-position + 1
17699 in the drawing area. */
17702 set_glyph_string_background_width (s
, start
, last_x
)
17703 struct glyph_string
*s
;
17707 /* If the face of this glyph string has to be drawn to the end of
17708 the drawing area, set S->extends_to_end_of_line_p. */
17709 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
17711 if (start
== s
->row
->used
[s
->area
]
17712 && s
->area
== TEXT_AREA
17713 && ((s
->hl
== DRAW_NORMAL_TEXT
17714 && (s
->row
->fill_line_p
17715 || s
->face
->background
!= default_face
->background
17716 || s
->face
->stipple
!= default_face
->stipple
17717 || s
->row
->mouse_face_p
))
17718 || s
->hl
== DRAW_MOUSE_FACE
17719 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
17720 && s
->row
->fill_line_p
)))
17721 s
->extends_to_end_of_line_p
= 1;
17723 /* If S extends its face to the end of the line, set its
17724 background_width to the distance to the right edge of the drawing
17726 if (s
->extends_to_end_of_line_p
)
17727 s
->background_width
= last_x
- s
->x
+ 1;
17729 s
->background_width
= s
->width
;
17733 /* Compute overhangs and x-positions for glyph string S and its
17734 predecessors, or successors. X is the starting x-position for S.
17735 BACKWARD_P non-zero means process predecessors. */
17738 compute_overhangs_and_x (s
, x
, backward_p
)
17739 struct glyph_string
*s
;
17747 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
17748 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
17758 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
17759 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
17769 /* The following macros are only called from draw_glyphs below.
17770 They reference the following parameters of that function directly:
17771 `w', `row', `area', and `overlap_p'
17772 as well as the following local variables:
17773 `s', `f', and `hdc' (in W32) */
17776 /* On W32, silently add local `hdc' variable to argument list of
17777 init_glyph_string. */
17778 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17779 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
17781 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17782 init_glyph_string (s, char2b, w, row, area, start, hl)
17785 /* Add a glyph string for a stretch glyph to the list of strings
17786 between HEAD and TAIL. START is the index of the stretch glyph in
17787 row area AREA of glyph row ROW. END is the index of the last glyph
17788 in that glyph row area. X is the current output position assigned
17789 to the new glyph string constructed. HL overrides that face of the
17790 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17791 is the right-most x-position of the drawing area. */
17793 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
17794 and below -- keep them on one line. */
17795 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17798 s = (struct glyph_string *) alloca (sizeof *s); \
17799 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17800 START = fill_stretch_glyph_string (s, row, area, START, END); \
17801 append_glyph_string (&HEAD, &TAIL, s); \
17807 /* Add a glyph string for an image glyph to the list of strings
17808 between HEAD and TAIL. START is the index of the image glyph in
17809 row area AREA of glyph row ROW. END is the index of the last glyph
17810 in that glyph row area. X is the current output position assigned
17811 to the new glyph string constructed. HL overrides that face of the
17812 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17813 is the right-most x-position of the drawing area. */
17815 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17818 s = (struct glyph_string *) alloca (sizeof *s); \
17819 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17820 fill_image_glyph_string (s); \
17821 append_glyph_string (&HEAD, &TAIL, s); \
17828 /* Add a glyph string for a sequence of character glyphs to the list
17829 of strings between HEAD and TAIL. START is the index of the first
17830 glyph in row area AREA of glyph row ROW that is part of the new
17831 glyph string. END is the index of the last glyph in that glyph row
17832 area. X is the current output position assigned to the new glyph
17833 string constructed. HL overrides that face of the glyph; e.g. it
17834 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
17835 right-most x-position of the drawing area. */
17837 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
17843 c = (row)->glyphs[area][START].u.ch; \
17844 face_id = (row)->glyphs[area][START].face_id; \
17846 s = (struct glyph_string *) alloca (sizeof *s); \
17847 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
17848 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
17849 append_glyph_string (&HEAD, &TAIL, s); \
17851 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
17856 /* Add a glyph string for a composite sequence to the list of strings
17857 between HEAD and TAIL. START is the index of the first glyph in
17858 row area AREA of glyph row ROW that is part of the new glyph
17859 string. END is the index of the last glyph in that glyph row area.
17860 X is the current output position assigned to the new glyph string
17861 constructed. HL overrides that face of the glyph; e.g. it is
17862 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
17863 x-position of the drawing area. */
17865 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17867 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
17868 int face_id = (row)->glyphs[area][START].face_id; \
17869 struct face *base_face = FACE_FROM_ID (f, face_id); \
17870 struct composition *cmp = composition_table[cmp_id]; \
17871 int glyph_len = cmp->glyph_len; \
17873 struct face **faces; \
17874 struct glyph_string *first_s = NULL; \
17877 base_face = base_face->ascii_face; \
17878 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
17879 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
17880 /* At first, fill in `char2b' and `faces'. */ \
17881 for (n = 0; n < glyph_len; n++) \
17883 int c = COMPOSITION_GLYPH (cmp, n); \
17884 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
17885 faces[n] = FACE_FROM_ID (f, this_face_id); \
17886 get_char_face_and_encoding (f, c, this_face_id, \
17887 char2b + n, 1, 1); \
17890 /* Make glyph_strings for each glyph sequence that is drawable by \
17891 the same face, and append them to HEAD/TAIL. */ \
17892 for (n = 0; n < cmp->glyph_len;) \
17894 s = (struct glyph_string *) alloca (sizeof *s); \
17895 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
17896 append_glyph_string (&(HEAD), &(TAIL), s); \
17904 n = fill_composite_glyph_string (s, faces, overlaps_p); \
17912 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
17913 of AREA of glyph row ROW on window W between indices START and END.
17914 HL overrides the face for drawing glyph strings, e.g. it is
17915 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
17916 x-positions of the drawing area.
17918 This is an ugly monster macro construct because we must use alloca
17919 to allocate glyph strings (because draw_glyphs can be called
17920 asynchronously). */
17922 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
17925 HEAD = TAIL = NULL; \
17926 while (START < END) \
17928 struct glyph *first_glyph = (row)->glyphs[area] + START; \
17929 switch (first_glyph->type) \
17932 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
17936 case COMPOSITE_GLYPH: \
17937 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
17941 case STRETCH_GLYPH: \
17942 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
17946 case IMAGE_GLYPH: \
17947 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
17955 set_glyph_string_background_width (s, START, LAST_X); \
17962 /* Draw glyphs between START and END in AREA of ROW on window W,
17963 starting at x-position X. X is relative to AREA in W. HL is a
17964 face-override with the following meaning:
17966 DRAW_NORMAL_TEXT draw normally
17967 DRAW_CURSOR draw in cursor face
17968 DRAW_MOUSE_FACE draw in mouse face.
17969 DRAW_INVERSE_VIDEO draw in mode line face
17970 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
17971 DRAW_IMAGE_RAISED draw an image with a raised relief around it
17973 If OVERLAPS_P is non-zero, draw only the foreground of characters
17974 and clip to the physical height of ROW.
17976 Value is the x-position reached, relative to AREA of W. */
17979 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
17982 struct glyph_row
*row
;
17983 enum glyph_row_area area
;
17985 enum draw_glyphs_face hl
;
17988 struct glyph_string
*head
, *tail
;
17989 struct glyph_string
*s
;
17990 int last_x
, area_width
;
17993 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17996 ALLOCATE_HDC (hdc
, f
);
17998 /* Let's rather be paranoid than getting a SEGV. */
17999 end
= min (end
, row
->used
[area
]);
18000 start
= max (0, start
);
18001 start
= min (end
, start
);
18003 /* Translate X to frame coordinates. Set last_x to the right
18004 end of the drawing area. */
18005 if (row
->full_width_p
)
18007 /* X is relative to the left edge of W, without scroll bars
18009 x
+= WINDOW_LEFT_EDGE_X (w
);
18010 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
18014 int area_left
= window_box_left (w
, area
);
18016 area_width
= window_box_width (w
, area
);
18017 last_x
= area_left
+ area_width
;
18020 /* Build a doubly-linked list of glyph_string structures between
18021 head and tail from what we have to draw. Note that the macro
18022 BUILD_GLYPH_STRINGS will modify its start parameter. That's
18023 the reason we use a separate variable `i'. */
18025 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
18027 x_reached
= tail
->x
+ tail
->background_width
;
18031 /* If there are any glyphs with lbearing < 0 or rbearing > width in
18032 the row, redraw some glyphs in front or following the glyph
18033 strings built above. */
18034 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
18037 struct glyph_string
*h
, *t
;
18039 /* Compute overhangs for all glyph strings. */
18040 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
18041 for (s
= head
; s
; s
= s
->next
)
18042 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
18044 /* Prepend glyph strings for glyphs in front of the first glyph
18045 string that are overwritten because of the first glyph
18046 string's left overhang. The background of all strings
18047 prepended must be drawn because the first glyph string
18049 i
= left_overwritten (head
);
18053 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
18054 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18056 compute_overhangs_and_x (t
, head
->x
, 1);
18057 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18060 /* Prepend glyph strings for glyphs in front of the first glyph
18061 string that overwrite that glyph string because of their
18062 right overhang. For these strings, only the foreground must
18063 be drawn, because it draws over the glyph string at `head'.
18064 The background must not be drawn because this would overwrite
18065 right overhangs of preceding glyphs for which no glyph
18067 i
= left_overwriting (head
);
18070 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
18071 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18072 for (s
= h
; s
; s
= s
->next
)
18073 s
->background_filled_p
= 1;
18074 compute_overhangs_and_x (t
, head
->x
, 1);
18075 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18078 /* Append glyphs strings for glyphs following the last glyph
18079 string tail that are overwritten by tail. The background of
18080 these strings has to be drawn because tail's foreground draws
18082 i
= right_overwritten (tail
);
18085 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18086 DRAW_NORMAL_TEXT
, x
, last_x
);
18087 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18088 append_glyph_string_lists (&head
, &tail
, h
, t
);
18091 /* Append glyph strings for glyphs following the last glyph
18092 string tail that overwrite tail. The foreground of such
18093 glyphs has to be drawn because it writes into the background
18094 of tail. The background must not be drawn because it could
18095 paint over the foreground of following glyphs. */
18096 i
= right_overwriting (tail
);
18099 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18100 DRAW_NORMAL_TEXT
, x
, last_x
);
18101 for (s
= h
; s
; s
= s
->next
)
18102 s
->background_filled_p
= 1;
18103 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18104 append_glyph_string_lists (&head
, &tail
, h
, t
);
18108 /* Draw all strings. */
18109 for (s
= head
; s
; s
= s
->next
)
18110 FRAME_RIF (f
)->draw_glyph_string (s
);
18112 if (area
== TEXT_AREA
18113 && !row
->full_width_p
18114 /* When drawing overlapping rows, only the glyph strings'
18115 foreground is drawn, which doesn't erase a cursor
18119 int x0
= head
? head
->x
: x
;
18120 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
18122 int text_left
= window_box_left (w
, TEXT_AREA
);
18126 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
18127 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
18130 /* Value is the x-position up to which drawn, relative to AREA of W.
18131 This doesn't include parts drawn because of overhangs. */
18132 if (row
->full_width_p
)
18133 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
18135 x_reached
-= window_box_left (w
, area
);
18137 RELEASE_HDC (hdc
, f
);
18143 /* Store one glyph for IT->char_to_display in IT->glyph_row.
18144 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18150 struct glyph
*glyph
;
18151 enum glyph_row_area area
= it
->area
;
18153 xassert (it
->glyph_row
);
18154 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
18156 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18157 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18159 glyph
->charpos
= CHARPOS (it
->position
);
18160 glyph
->object
= it
->object
;
18161 glyph
->pixel_width
= it
->pixel_width
;
18162 glyph
->ascent
= it
->ascent
;
18163 glyph
->descent
= it
->descent
;
18164 glyph
->voffset
= it
->voffset
;
18165 glyph
->type
= CHAR_GLYPH
;
18166 glyph
->multibyte_p
= it
->multibyte_p
;
18167 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18168 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18169 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18170 || it
->phys_descent
> it
->descent
);
18171 glyph
->padding_p
= 0;
18172 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
18173 glyph
->face_id
= it
->face_id
;
18174 glyph
->u
.ch
= it
->char_to_display
;
18175 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18176 ++it
->glyph_row
->used
[area
];
18180 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
18181 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18184 append_composite_glyph (it
)
18187 struct glyph
*glyph
;
18188 enum glyph_row_area area
= it
->area
;
18190 xassert (it
->glyph_row
);
18192 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18193 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18195 glyph
->charpos
= CHARPOS (it
->position
);
18196 glyph
->object
= it
->object
;
18197 glyph
->pixel_width
= it
->pixel_width
;
18198 glyph
->ascent
= it
->ascent
;
18199 glyph
->descent
= it
->descent
;
18200 glyph
->voffset
= it
->voffset
;
18201 glyph
->type
= COMPOSITE_GLYPH
;
18202 glyph
->multibyte_p
= it
->multibyte_p
;
18203 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18204 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18205 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18206 || it
->phys_descent
> it
->descent
);
18207 glyph
->padding_p
= 0;
18208 glyph
->glyph_not_available_p
= 0;
18209 glyph
->face_id
= it
->face_id
;
18210 glyph
->u
.cmp_id
= it
->cmp_id
;
18211 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18212 ++it
->glyph_row
->used
[area
];
18217 /* Change IT->ascent and IT->height according to the setting of
18221 take_vertical_position_into_account (it
)
18226 if (it
->voffset
< 0)
18227 /* Increase the ascent so that we can display the text higher
18229 it
->ascent
+= abs (it
->voffset
);
18231 /* Increase the descent so that we can display the text lower
18233 it
->descent
+= it
->voffset
;
18238 /* Produce glyphs/get display metrics for the image IT is loaded with.
18239 See the description of struct display_iterator in dispextern.h for
18240 an overview of struct display_iterator. */
18243 produce_image_glyph (it
)
18248 int face_ascent
, glyph_ascent
;
18250 xassert (it
->what
== IT_IMAGE
);
18252 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18253 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
18256 /* Make sure X resources of the face and image are loaded. */
18257 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18258 prepare_image_for_display (it
->f
, img
);
18260 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
);
18261 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
18262 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
18264 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
18265 face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
18266 if (face_ascent
> it
->ascent
)
18267 it
->ascent
= it
->phys_ascent
= face_ascent
;
18271 if (face
->box
!= FACE_NO_BOX
)
18273 if (face
->box_line_width
> 0)
18275 it
->ascent
+= face
->box_line_width
;
18276 it
->descent
+= face
->box_line_width
;
18279 if (it
->start_of_box_run_p
)
18280 it
->pixel_width
+= abs (face
->box_line_width
);
18281 if (it
->end_of_box_run_p
)
18282 it
->pixel_width
+= abs (face
->box_line_width
);
18285 take_vertical_position_into_account (it
);
18289 struct glyph
*glyph
;
18290 enum glyph_row_area area
= it
->area
;
18292 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18293 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18295 glyph
->charpos
= CHARPOS (it
->position
);
18296 glyph
->object
= it
->object
;
18297 glyph
->pixel_width
= it
->pixel_width
;
18298 glyph
->ascent
= glyph_ascent
;
18299 glyph
->descent
= it
->descent
;
18300 glyph
->voffset
= it
->voffset
;
18301 glyph
->type
= IMAGE_GLYPH
;
18302 glyph
->multibyte_p
= it
->multibyte_p
;
18303 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18304 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18305 glyph
->overlaps_vertically_p
= 0;
18306 glyph
->padding_p
= 0;
18307 glyph
->glyph_not_available_p
= 0;
18308 glyph
->face_id
= it
->face_id
;
18309 glyph
->u
.img_id
= img
->id
;
18310 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18311 ++it
->glyph_row
->used
[area
];
18317 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
18318 of the glyph, WIDTH and HEIGHT are the width and height of the
18319 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
18322 append_stretch_glyph (it
, object
, width
, height
, ascent
)
18324 Lisp_Object object
;
18328 struct glyph
*glyph
;
18329 enum glyph_row_area area
= it
->area
;
18331 xassert (ascent
>= 0 && ascent
<= height
);
18333 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18334 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18336 glyph
->charpos
= CHARPOS (it
->position
);
18337 glyph
->object
= object
;
18338 glyph
->pixel_width
= width
;
18339 glyph
->ascent
= ascent
;
18340 glyph
->descent
= height
- ascent
;
18341 glyph
->voffset
= it
->voffset
;
18342 glyph
->type
= STRETCH_GLYPH
;
18343 glyph
->multibyte_p
= it
->multibyte_p
;
18344 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18345 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18346 glyph
->overlaps_vertically_p
= 0;
18347 glyph
->padding_p
= 0;
18348 glyph
->glyph_not_available_p
= 0;
18349 glyph
->face_id
= it
->face_id
;
18350 glyph
->u
.stretch
.ascent
= ascent
;
18351 glyph
->u
.stretch
.height
= height
;
18352 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18353 ++it
->glyph_row
->used
[area
];
18358 /* Calculate a width or height in pixels from a specification using
18359 the following elements:
18362 NUM - a (fractional) multiple of the default font width/height
18363 (NUM) - specifies exactly NUM pixels
18364 UNIT - a fixed number of pixels, see below.
18365 ELEMENT - size of a display element in pixels, see below.
18366 (NUM . SPEC) - equals NUM * SPEC
18367 (+ SPEC SPEC ...) - add pixel values
18368 (- SPEC SPEC ...) - subtract pixel values
18369 (- SPEC) - negate pixel value
18372 INT or FLOAT - a number constant
18373 SYMBOL - use symbol's (buffer local) variable binding.
18376 in - pixels per inch *)
18377 mm - pixels per 1/1000 meter *)
18378 cm - pixels per 1/100 meter *)
18379 width - width of current font in pixels.
18380 height - height of current font in pixels.
18382 *) using the ratio(s) defined in display-pixels-per-inch.
18386 left-fringe - left fringe width in pixels
18387 (left-fringe . nil) - left fringe width if inside margins, else 0
18388 (left-fringe . t) - left fringe width if outside margins, else 0
18390 right-fringe - right fringe width in pixels
18391 (right-fringe . nil) - right fringe width if inside margins, else 0
18392 (right-fringe . t) - right fringe width if outside margins, else 0
18394 left-margin - left margin width in pixels
18395 right-margin - right margin width in pixels
18397 scroll-bar - scroll-bar area width in pixels
18398 (scroll-bar . left) - scroll-bar width if on left, else 0
18399 (scroll-bar . right) - scroll-bar width if on right, else 0
18403 Pixels corresponding to 5 inches:
18406 Total width of non-text areas on left side of window:
18407 (+ left-fringe left-margin (scroll-bar . left))
18409 Total width of fringes if inside display margins:
18410 (+ (left-fringe) (right-fringe))
18412 Width of left margin minus width of 1 character in the default font:
18415 Width of left margin minus width of 2 characters in the current font:
18416 (- left-margin (2 . width))
18418 Width of left fringe plus left margin minus one pixel:
18419 (- (+ left-fringe left-margin) (1))
18420 (+ left-fringe left-margin (- (1)))
18421 (+ left-fringe left-margin (-1))
18425 #define NUMVAL(X) \
18426 ((INTEGERP (X) || FLOATP (X)) \
18431 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
)
18440 #define OK_PIXELS(val) ((*res = (val)), 1)
18442 if (SYMBOLP (prop
))
18444 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18446 char *unit
= SDATA (SYMBOL_NAME (prop
));
18448 if (unit
[0] == 'i' && unit
[1] == 'n')
18450 else if (unit
[0] == 'm' && unit
[1] == 'm')
18452 else if (unit
[0] == 'c' && unit
[1] == 'm')
18459 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18460 || (CONSP (Vdisplay_pixels_per_inch
)
18462 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18463 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18465 return OK_PIXELS (ppi
/ pixels
);
18471 if (EQ (prop
, Qheight
))
18472 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
18473 if (EQ (prop
, Qwidth
))
18474 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
18475 if (EQ (prop
, Qleft_fringe
))
18476 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18477 if (EQ (prop
, Qright_fringe
))
18478 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18479 if (EQ (prop
, Qleft_margin
))
18480 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18481 if (EQ (prop
, Qright_margin
))
18482 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18483 if (EQ (prop
, Qscroll_bar
))
18484 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18486 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18489 if (INTEGERP (prop
) || FLOATP (prop
))
18491 int base_unit
= (width_p
18492 ? FRAME_COLUMN_WIDTH (it
->f
)
18493 : FRAME_LINE_HEIGHT (it
->f
));
18494 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18499 Lisp_Object car
= XCAR (prop
);
18500 Lisp_Object cdr
= XCDR (prop
);
18504 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18510 while (CONSP (cdr
))
18512 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
), font
, width_p
))
18515 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18520 if (EQ (car
, Qminus
))
18522 return OK_PIXELS (pixels
);
18525 if (EQ (car
, Qleft_fringe
))
18526 return OK_PIXELS ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18528 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
18530 if (EQ (car
, Qright_fringe
))
18531 return OK_PIXELS ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18533 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18535 if (EQ (car
, Qscroll_bar
))
18536 return OK_PIXELS ((WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18537 == EQ (cdr
, Qleft
))
18538 ? WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
)
18541 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18544 if (INTEGERP (car
) || FLOATP (car
))
18547 pixels
= XFLOATINT (car
);
18549 return OK_PIXELS (pixels
);
18550 if (calc_pixel_width_or_height (&fact
, it
, cdr
, font
, width_p
))
18551 return OK_PIXELS (pixels
* fact
);
18561 /* Produce a stretch glyph for iterator IT. IT->object is the value
18562 of the glyph property displayed. The value must be a list
18563 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
18566 1. `:width WIDTH' specifies that the space should be WIDTH *
18567 canonical char width wide. WIDTH may be an integer or floating
18570 2. `:relative-width FACTOR' specifies that the width of the stretch
18571 should be computed from the width of the first character having the
18572 `glyph' property, and should be FACTOR times that width.
18574 3. `:align-to HPOS' specifies that the space should be wide enough
18575 to reach HPOS, a value in canonical character units.
18577 Exactly one of the above pairs must be present.
18579 4. `:height HEIGHT' specifies that the height of the stretch produced
18580 should be HEIGHT, measured in canonical character units.
18582 5. `:relative-height FACTOR' specifies that the height of the
18583 stretch should be FACTOR times the height of the characters having
18584 the glyph property.
18586 Either none or exactly one of 4 or 5 must be present.
18588 6. `:ascent ASCENT' specifies that ASCENT percent of the height
18589 of the stretch should be used for the ascent of the stretch.
18590 ASCENT must be in the range 0 <= ASCENT <= 100. */
18593 produce_stretch_glyph (it
)
18596 /* (space :width WIDTH :height HEIGHT ...) */
18597 Lisp_Object prop
, plist
;
18598 int width
= 0, height
= 0;
18599 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
18602 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18603 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
18605 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18607 /* List should start with `space'. */
18608 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
18609 plist
= XCDR (it
->object
);
18611 /* Compute the width of the stretch. */
18612 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
18613 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1))
18615 /* Absolute width `:width WIDTH' specified and valid. */
18616 zero_width_ok_p
= 1;
18619 else if (prop
= Fplist_get (plist
, QCrelative_width
),
18622 /* Relative width `:relative-width FACTOR' specified and valid.
18623 Compute the width of the characters having the `glyph'
18626 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
18629 if (it
->multibyte_p
)
18631 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
18632 - IT_BYTEPOS (*it
));
18633 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
18636 it2
.c
= *p
, it2
.len
= 1;
18638 it2
.glyph_row
= NULL
;
18639 it2
.what
= IT_CHARACTER
;
18640 x_produce_glyphs (&it2
);
18641 width
= NUMVAL (prop
) * it2
.pixel_width
;
18643 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
18644 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1))
18646 width
= max (0, (int)tem
- it
->current_x
);
18647 zero_width_ok_p
= 1;
18650 /* Nothing specified -> width defaults to canonical char width. */
18651 width
= FRAME_COLUMN_WIDTH (it
->f
);
18653 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
18656 /* Compute height. */
18657 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
18658 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0))
18661 zero_height_ok_p
= 1;
18663 else if (prop
= Fplist_get (plist
, QCrelative_height
),
18665 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
18667 height
= FONT_HEIGHT (font
);
18669 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
18672 /* Compute percentage of height used for ascent. If
18673 `:ascent ASCENT' is present and valid, use that. Otherwise,
18674 derive the ascent from the font in use. */
18675 if (prop
= Fplist_get (plist
, QCascent
),
18676 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
18677 ascent
= height
* NUMVAL (prop
) / 100.0;
18678 else if (!NILP (prop
)
18679 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0))
18680 ascent
= min (max (0, (int)tem
), height
);
18682 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
18684 if (width
> 0 && height
> 0 && it
->glyph_row
)
18686 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
18687 if (!STRINGP (object
))
18688 object
= it
->w
->buffer
;
18689 append_stretch_glyph (it
, object
, width
, height
, ascent
);
18692 it
->pixel_width
= width
;
18693 it
->ascent
= it
->phys_ascent
= ascent
;
18694 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
18695 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
18697 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
18699 if (face
->box_line_width
> 0)
18701 it
->ascent
+= face
->box_line_width
;
18702 it
->descent
+= face
->box_line_width
;
18705 if (it
->start_of_box_run_p
)
18706 it
->pixel_width
+= abs (face
->box_line_width
);
18707 if (it
->end_of_box_run_p
)
18708 it
->pixel_width
+= abs (face
->box_line_width
);
18711 take_vertical_position_into_account (it
);
18715 Produce glyphs/get display metrics for the display element IT is
18716 loaded with. See the description of struct display_iterator in
18717 dispextern.h for an overview of struct display_iterator. */
18720 x_produce_glyphs (it
)
18723 it
->glyph_not_available_p
= 0;
18725 if (it
->what
== IT_CHARACTER
)
18729 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18731 int font_not_found_p
;
18732 struct font_info
*font_info
;
18733 int boff
; /* baseline offset */
18734 /* We may change it->multibyte_p upon unibyte<->multibyte
18735 conversion. So, save the current value now and restore it
18738 Note: It seems that we don't have to record multibyte_p in
18739 struct glyph because the character code itself tells if or
18740 not the character is multibyte. Thus, in the future, we must
18741 consider eliminating the field `multibyte_p' in the struct
18743 int saved_multibyte_p
= it
->multibyte_p
;
18745 /* Maybe translate single-byte characters to multibyte, or the
18747 it
->char_to_display
= it
->c
;
18748 if (!ASCII_BYTE_P (it
->c
))
18750 if (unibyte_display_via_language_environment
18751 && SINGLE_BYTE_CHAR_P (it
->c
)
18753 || !NILP (Vnonascii_translation_table
)))
18755 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
18756 it
->multibyte_p
= 1;
18757 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18758 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18760 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
18761 && !it
->multibyte_p
)
18763 it
->multibyte_p
= 1;
18764 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18765 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18769 /* Get font to use. Encode IT->char_to_display. */
18770 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
18771 &char2b
, it
->multibyte_p
, 0);
18774 /* When no suitable font found, use the default font. */
18775 font_not_found_p
= font
== NULL
;
18776 if (font_not_found_p
)
18778 font
= FRAME_FONT (it
->f
);
18779 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18784 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18785 boff
= font_info
->baseline_offset
;
18786 if (font_info
->vertical_centering
)
18787 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18790 if (it
->char_to_display
>= ' '
18791 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
18793 /* Either unibyte or ASCII. */
18798 pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
18799 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
18800 it
->ascent
= FONT_BASE (font
) + boff
;
18801 it
->descent
= FONT_DESCENT (font
) - boff
;
18805 it
->phys_ascent
= pcm
->ascent
+ boff
;
18806 it
->phys_descent
= pcm
->descent
- boff
;
18807 it
->pixel_width
= pcm
->width
;
18811 it
->glyph_not_available_p
= 1;
18812 it
->phys_ascent
= FONT_BASE (font
) + boff
;
18813 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18814 it
->pixel_width
= FONT_WIDTH (font
);
18817 /* If this is a space inside a region of text with
18818 `space-width' property, change its width. */
18819 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
18821 it
->pixel_width
*= XFLOATINT (it
->space_width
);
18823 /* If face has a box, add the box thickness to the character
18824 height. If character has a box line to the left and/or
18825 right, add the box line width to the character's width. */
18826 if (face
->box
!= FACE_NO_BOX
)
18828 int thick
= face
->box_line_width
;
18832 it
->ascent
+= thick
;
18833 it
->descent
+= thick
;
18838 if (it
->start_of_box_run_p
)
18839 it
->pixel_width
+= thick
;
18840 if (it
->end_of_box_run_p
)
18841 it
->pixel_width
+= thick
;
18844 /* If face has an overline, add the height of the overline
18845 (1 pixel) and a 1 pixel margin to the character height. */
18846 if (face
->overline_p
)
18849 take_vertical_position_into_account (it
);
18851 /* If we have to actually produce glyphs, do it. */
18856 /* Translate a space with a `space-width' property
18857 into a stretch glyph. */
18858 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
18859 / FONT_HEIGHT (font
));
18860 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
18861 it
->ascent
+ it
->descent
, ascent
);
18866 /* If characters with lbearing or rbearing are displayed
18867 in this line, record that fact in a flag of the
18868 glyph row. This is used to optimize X output code. */
18869 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
18870 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
18873 else if (it
->char_to_display
== '\n')
18875 /* A newline has no width but we need the height of the line. */
18876 it
->pixel_width
= 0;
18878 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
18879 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18881 if (face
->box
!= FACE_NO_BOX
18882 && face
->box_line_width
> 0)
18884 it
->ascent
+= face
->box_line_width
;
18885 it
->descent
+= face
->box_line_width
;
18888 else if (it
->char_to_display
== '\t')
18890 int tab_width
= it
->tab_width
* FRAME_COLUMN_WIDTH (it
->f
);
18891 int x
= it
->current_x
+ it
->continuation_lines_width
;
18892 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
18894 /* If the distance from the current position to the next tab
18895 stop is less than a canonical character width, use the
18896 tab stop after that. */
18897 if (next_tab_x
- x
< FRAME_COLUMN_WIDTH (it
->f
))
18898 next_tab_x
+= tab_width
;
18900 it
->pixel_width
= next_tab_x
- x
;
18902 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
18903 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18907 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
18908 it
->ascent
+ it
->descent
, it
->ascent
);
18913 /* A multi-byte character. Assume that the display width of the
18914 character is the width of the character multiplied by the
18915 width of the font. */
18917 /* If we found a font, this font should give us the right
18918 metrics. If we didn't find a font, use the frame's
18919 default font and calculate the width of the character
18920 from the charset width; this is what old redisplay code
18923 pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
18924 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
18926 if (font_not_found_p
|| !pcm
)
18928 int charset
= CHAR_CHARSET (it
->char_to_display
);
18930 it
->glyph_not_available_p
= 1;
18931 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
18932 * CHARSET_WIDTH (charset
));
18933 it
->phys_ascent
= FONT_BASE (font
) + boff
;
18934 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18938 it
->pixel_width
= pcm
->width
;
18939 it
->phys_ascent
= pcm
->ascent
+ boff
;
18940 it
->phys_descent
= pcm
->descent
- boff
;
18942 && (pcm
->lbearing
< 0
18943 || pcm
->rbearing
> pcm
->width
))
18944 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
18947 it
->ascent
= FONT_BASE (font
) + boff
;
18948 it
->descent
= FONT_DESCENT (font
) - boff
;
18949 if (face
->box
!= FACE_NO_BOX
)
18951 int thick
= face
->box_line_width
;
18955 it
->ascent
+= thick
;
18956 it
->descent
+= thick
;
18961 if (it
->start_of_box_run_p
)
18962 it
->pixel_width
+= thick
;
18963 if (it
->end_of_box_run_p
)
18964 it
->pixel_width
+= thick
;
18967 /* If face has an overline, add the height of the overline
18968 (1 pixel) and a 1 pixel margin to the character height. */
18969 if (face
->overline_p
)
18972 take_vertical_position_into_account (it
);
18977 it
->multibyte_p
= saved_multibyte_p
;
18979 else if (it
->what
== IT_COMPOSITION
)
18981 /* Note: A composition is represented as one glyph in the
18982 glyph matrix. There are no padding glyphs. */
18985 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18987 int font_not_found_p
;
18988 struct font_info
*font_info
;
18989 int boff
; /* baseline offset */
18990 struct composition
*cmp
= composition_table
[it
->cmp_id
];
18992 /* Maybe translate single-byte characters to multibyte. */
18993 it
->char_to_display
= it
->c
;
18994 if (unibyte_display_via_language_environment
18995 && SINGLE_BYTE_CHAR_P (it
->c
)
18998 && !NILP (Vnonascii_translation_table
))))
19000 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19003 /* Get face and font to use. Encode IT->char_to_display. */
19004 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19005 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19006 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19007 &char2b
, it
->multibyte_p
, 0);
19010 /* When no suitable font found, use the default font. */
19011 font_not_found_p
= font
== NULL
;
19012 if (font_not_found_p
)
19014 font
= FRAME_FONT (it
->f
);
19015 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19020 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19021 boff
= font_info
->baseline_offset
;
19022 if (font_info
->vertical_centering
)
19023 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19026 /* There are no padding glyphs, so there is only one glyph to
19027 produce for the composition. Important is that pixel_width,
19028 ascent and descent are the values of what is drawn by
19029 draw_glyphs (i.e. the values of the overall glyphs composed). */
19032 /* If we have not yet calculated pixel size data of glyphs of
19033 the composition for the current face font, calculate them
19034 now. Theoretically, we have to check all fonts for the
19035 glyphs, but that requires much time and memory space. So,
19036 here we check only the font of the first glyph. This leads
19037 to incorrect display very rarely, and C-l (recenter) can
19038 correct the display anyway. */
19039 if (cmp
->font
!= (void *) font
)
19041 /* Ascent and descent of the font of the first character of
19042 this composition (adjusted by baseline offset). Ascent
19043 and descent of overall glyphs should not be less than
19044 them respectively. */
19045 int font_ascent
= FONT_BASE (font
) + boff
;
19046 int font_descent
= FONT_DESCENT (font
) - boff
;
19047 /* Bounding box of the overall glyphs. */
19048 int leftmost
, rightmost
, lowest
, highest
;
19049 int i
, width
, ascent
, descent
;
19051 cmp
->font
= (void *) font
;
19053 /* Initialize the bounding box. */
19055 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
19056 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
19058 width
= pcm
->width
;
19059 ascent
= pcm
->ascent
;
19060 descent
= pcm
->descent
;
19064 width
= FONT_WIDTH (font
);
19065 ascent
= FONT_BASE (font
);
19066 descent
= FONT_DESCENT (font
);
19070 lowest
= - descent
+ boff
;
19071 highest
= ascent
+ boff
;
19075 && font_info
->default_ascent
19076 && CHAR_TABLE_P (Vuse_default_ascent
)
19077 && !NILP (Faref (Vuse_default_ascent
,
19078 make_number (it
->char_to_display
))))
19079 highest
= font_info
->default_ascent
+ boff
;
19081 /* Draw the first glyph at the normal position. It may be
19082 shifted to right later if some other glyphs are drawn at
19084 cmp
->offsets
[0] = 0;
19085 cmp
->offsets
[1] = boff
;
19087 /* Set cmp->offsets for the remaining glyphs. */
19088 for (i
= 1; i
< cmp
->glyph_len
; i
++)
19090 int left
, right
, btm
, top
;
19091 int ch
= COMPOSITION_GLYPH (cmp
, i
);
19092 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
19094 face
= FACE_FROM_ID (it
->f
, face_id
);
19095 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
19096 &char2b
, it
->multibyte_p
, 0);
19100 font
= FRAME_FONT (it
->f
);
19101 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19107 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19108 boff
= font_info
->baseline_offset
;
19109 if (font_info
->vertical_centering
)
19110 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19114 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
19115 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
19117 width
= pcm
->width
;
19118 ascent
= pcm
->ascent
;
19119 descent
= pcm
->descent
;
19123 width
= FONT_WIDTH (font
);
19128 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
19130 /* Relative composition with or without
19131 alternate chars. */
19132 left
= (leftmost
+ rightmost
- width
) / 2;
19133 btm
= - descent
+ boff
;
19134 if (font_info
&& font_info
->relative_compose
19135 && (! CHAR_TABLE_P (Vignore_relative_composition
)
19136 || NILP (Faref (Vignore_relative_composition
,
19137 make_number (ch
)))))
19140 if (- descent
>= font_info
->relative_compose
)
19141 /* One extra pixel between two glyphs. */
19143 else if (ascent
<= 0)
19144 /* One extra pixel between two glyphs. */
19145 btm
= lowest
- 1 - ascent
- descent
;
19150 /* A composition rule is specified by an integer
19151 value that encodes global and new reference
19152 points (GREF and NREF). GREF and NREF are
19153 specified by numbers as below:
19155 0---1---2 -- ascent
19159 9--10--11 -- center
19161 ---3---4---5--- baseline
19163 6---7---8 -- descent
19165 int rule
= COMPOSITION_RULE (cmp
, i
);
19166 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
19168 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
19169 grefx
= gref
% 3, nrefx
= nref
% 3;
19170 grefy
= gref
/ 3, nrefy
= nref
/ 3;
19173 + grefx
* (rightmost
- leftmost
) / 2
19174 - nrefx
* width
/ 2);
19175 btm
= ((grefy
== 0 ? highest
19177 : grefy
== 2 ? lowest
19178 : (highest
+ lowest
) / 2)
19179 - (nrefy
== 0 ? ascent
+ descent
19180 : nrefy
== 1 ? descent
- boff
19182 : (ascent
+ descent
) / 2));
19185 cmp
->offsets
[i
* 2] = left
;
19186 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
19188 /* Update the bounding box of the overall glyphs. */
19189 right
= left
+ width
;
19190 top
= btm
+ descent
+ ascent
;
19191 if (left
< leftmost
)
19193 if (right
> rightmost
)
19201 /* If there are glyphs whose x-offsets are negative,
19202 shift all glyphs to the right and make all x-offsets
19206 for (i
= 0; i
< cmp
->glyph_len
; i
++)
19207 cmp
->offsets
[i
* 2] -= leftmost
;
19208 rightmost
-= leftmost
;
19211 cmp
->pixel_width
= rightmost
;
19212 cmp
->ascent
= highest
;
19213 cmp
->descent
= - lowest
;
19214 if (cmp
->ascent
< font_ascent
)
19215 cmp
->ascent
= font_ascent
;
19216 if (cmp
->descent
< font_descent
)
19217 cmp
->descent
= font_descent
;
19220 it
->pixel_width
= cmp
->pixel_width
;
19221 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
19222 it
->descent
= it
->phys_descent
= cmp
->descent
;
19224 if (face
->box
!= FACE_NO_BOX
)
19226 int thick
= face
->box_line_width
;
19230 it
->ascent
+= thick
;
19231 it
->descent
+= thick
;
19236 if (it
->start_of_box_run_p
)
19237 it
->pixel_width
+= thick
;
19238 if (it
->end_of_box_run_p
)
19239 it
->pixel_width
+= thick
;
19242 /* If face has an overline, add the height of the overline
19243 (1 pixel) and a 1 pixel margin to the character height. */
19244 if (face
->overline_p
)
19247 take_vertical_position_into_account (it
);
19250 append_composite_glyph (it
);
19252 else if (it
->what
== IT_IMAGE
)
19253 produce_image_glyph (it
);
19254 else if (it
->what
== IT_STRETCH
)
19255 produce_stretch_glyph (it
);
19257 /* Accumulate dimensions. Note: can't assume that it->descent > 0
19258 because this isn't true for images with `:ascent 100'. */
19259 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
19260 if (it
->area
== TEXT_AREA
)
19261 it
->current_x
+= it
->pixel_width
;
19263 it
->descent
+= it
->extra_line_spacing
;
19265 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
19266 it
->max_descent
= max (it
->max_descent
, it
->descent
);
19267 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
19268 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
19272 Output LEN glyphs starting at START at the nominal cursor position.
19273 Advance the nominal cursor over the text. The global variable
19274 updated_window contains the window being updated, updated_row is
19275 the glyph row being updated, and updated_area is the area of that
19276 row being updated. */
19279 x_write_glyphs (start
, len
)
19280 struct glyph
*start
;
19285 xassert (updated_window
&& updated_row
);
19288 /* Write glyphs. */
19290 hpos
= start
- updated_row
->glyphs
[updated_area
];
19291 x
= draw_glyphs (updated_window
, output_cursor
.x
,
19292 updated_row
, updated_area
,
19294 DRAW_NORMAL_TEXT
, 0);
19296 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
19297 if (updated_area
== TEXT_AREA
19298 && updated_window
->phys_cursor_on_p
19299 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
19300 && updated_window
->phys_cursor
.hpos
>= hpos
19301 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
19302 updated_window
->phys_cursor_on_p
= 0;
19306 /* Advance the output cursor. */
19307 output_cursor
.hpos
+= len
;
19308 output_cursor
.x
= x
;
19313 Insert LEN glyphs from START at the nominal cursor position. */
19316 x_insert_glyphs (start
, len
)
19317 struct glyph
*start
;
19322 int line_height
, shift_by_width
, shifted_region_width
;
19323 struct glyph_row
*row
;
19324 struct glyph
*glyph
;
19325 int frame_x
, frame_y
, hpos
;
19327 xassert (updated_window
&& updated_row
);
19329 w
= updated_window
;
19330 f
= XFRAME (WINDOW_FRAME (w
));
19332 /* Get the height of the line we are in. */
19334 line_height
= row
->height
;
19336 /* Get the width of the glyphs to insert. */
19337 shift_by_width
= 0;
19338 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
19339 shift_by_width
+= glyph
->pixel_width
;
19341 /* Get the width of the region to shift right. */
19342 shifted_region_width
= (window_box_width (w
, updated_area
)
19347 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
19348 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
19350 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
19351 line_height
, shift_by_width
);
19353 /* Write the glyphs. */
19354 hpos
= start
- row
->glyphs
[updated_area
];
19355 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
19357 DRAW_NORMAL_TEXT
, 0);
19359 /* Advance the output cursor. */
19360 output_cursor
.hpos
+= len
;
19361 output_cursor
.x
+= shift_by_width
;
19367 Erase the current text line from the nominal cursor position
19368 (inclusive) to pixel column TO_X (exclusive). The idea is that
19369 everything from TO_X onward is already erased.
19371 TO_X is a pixel position relative to updated_area of
19372 updated_window. TO_X == -1 means clear to the end of this area. */
19375 x_clear_end_of_line (to_x
)
19379 struct window
*w
= updated_window
;
19380 int max_x
, min_y
, max_y
;
19381 int from_x
, from_y
, to_y
;
19383 xassert (updated_window
&& updated_row
);
19384 f
= XFRAME (w
->frame
);
19386 if (updated_row
->full_width_p
)
19387 max_x
= WINDOW_TOTAL_WIDTH (w
);
19389 max_x
= window_box_width (w
, updated_area
);
19390 max_y
= window_text_bottom_y (w
);
19392 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
19393 of window. For TO_X > 0, truncate to end of drawing area. */
19399 to_x
= min (to_x
, max_x
);
19401 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
19403 /* Notice if the cursor will be cleared by this operation. */
19404 if (!updated_row
->full_width_p
)
19405 notice_overwritten_cursor (w
, updated_area
,
19406 output_cursor
.x
, -1,
19408 MATRIX_ROW_BOTTOM_Y (updated_row
));
19410 from_x
= output_cursor
.x
;
19412 /* Translate to frame coordinates. */
19413 if (updated_row
->full_width_p
)
19415 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
19416 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
19420 int area_left
= window_box_left (w
, updated_area
);
19421 from_x
+= area_left
;
19425 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
19426 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
19427 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
19429 /* Prevent inadvertently clearing to end of the X window. */
19430 if (to_x
> from_x
&& to_y
> from_y
)
19433 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
19434 to_x
- from_x
, to_y
- from_y
);
19439 #endif /* HAVE_WINDOW_SYSTEM */
19443 /***********************************************************************
19445 ***********************************************************************/
19447 /* Value is the internal representation of the specified cursor type
19448 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
19449 of the bar cursor. */
19451 static enum text_cursor_kinds
19452 get_specified_cursor_type (arg
, width
)
19456 enum text_cursor_kinds type
;
19461 if (EQ (arg
, Qbox
))
19462 return FILLED_BOX_CURSOR
;
19464 if (EQ (arg
, Qhollow
))
19465 return HOLLOW_BOX_CURSOR
;
19467 if (EQ (arg
, Qbar
))
19474 && EQ (XCAR (arg
), Qbar
)
19475 && INTEGERP (XCDR (arg
))
19476 && XINT (XCDR (arg
)) >= 0)
19478 *width
= XINT (XCDR (arg
));
19482 if (EQ (arg
, Qhbar
))
19485 return HBAR_CURSOR
;
19489 && EQ (XCAR (arg
), Qhbar
)
19490 && INTEGERP (XCDR (arg
))
19491 && XINT (XCDR (arg
)) >= 0)
19493 *width
= XINT (XCDR (arg
));
19494 return HBAR_CURSOR
;
19497 /* Treat anything unknown as "hollow box cursor".
19498 It was bad to signal an error; people have trouble fixing
19499 .Xdefaults with Emacs, when it has something bad in it. */
19500 type
= HOLLOW_BOX_CURSOR
;
19505 /* Set the default cursor types for specified frame. */
19507 set_frame_cursor_types (f
, arg
)
19514 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
19515 FRAME_CURSOR_WIDTH (f
) = width
;
19517 /* By default, set up the blink-off state depending on the on-state. */
19519 tem
= Fassoc (arg
, Vblink_cursor_alist
);
19522 FRAME_BLINK_OFF_CURSOR (f
)
19523 = get_specified_cursor_type (XCDR (tem
), &width
);
19524 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
19527 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
19531 /* Return the cursor we want to be displayed in window W. Return
19532 width of bar/hbar cursor through WIDTH arg. Return with
19533 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
19534 (i.e. if the `system caret' should track this cursor).
19536 In a mini-buffer window, we want the cursor only to appear if we
19537 are reading input from this window. For the selected window, we
19538 want the cursor type given by the frame parameter or buffer local
19539 setting of cursor-type. If explicitly marked off, draw no cursor.
19540 In all other cases, we want a hollow box cursor. */
19542 static enum text_cursor_kinds
19543 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
19545 struct glyph
*glyph
;
19547 int *active_cursor
;
19549 struct frame
*f
= XFRAME (w
->frame
);
19550 struct buffer
*b
= XBUFFER (w
->buffer
);
19551 int cursor_type
= DEFAULT_CURSOR
;
19552 Lisp_Object alt_cursor
;
19553 int non_selected
= 0;
19555 *active_cursor
= 1;
19558 if (cursor_in_echo_area
19559 && FRAME_HAS_MINIBUF_P (f
)
19560 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
19562 if (w
== XWINDOW (echo_area_window
))
19564 *width
= FRAME_CURSOR_WIDTH (f
);
19565 return FRAME_DESIRED_CURSOR (f
);
19568 *active_cursor
= 0;
19572 /* Nonselected window or nonselected frame. */
19573 else if (w
!= XWINDOW (f
->selected_window
)
19574 #ifdef HAVE_WINDOW_SYSTEM
19575 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
19579 *active_cursor
= 0;
19581 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
19587 /* Never display a cursor in a window in which cursor-type is nil. */
19588 if (NILP (b
->cursor_type
))
19591 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
19594 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
19595 return get_specified_cursor_type (alt_cursor
, width
);
19598 /* Get the normal cursor type for this window. */
19599 if (EQ (b
->cursor_type
, Qt
))
19601 cursor_type
= FRAME_DESIRED_CURSOR (f
);
19602 *width
= FRAME_CURSOR_WIDTH (f
);
19605 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
19607 /* Use normal cursor if not blinked off. */
19608 if (!w
->cursor_off_p
)
19610 if (glyph
->type
== IMAGE_GLYPH
) {
19611 if (cursor_type
== FILLED_BOX_CURSOR
)
19612 cursor_type
= HOLLOW_BOX_CURSOR
;
19614 return cursor_type
;
19617 /* Cursor is blinked off, so determine how to "toggle" it. */
19619 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
19620 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
19621 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
19623 /* Then see if frame has specified a specific blink off cursor type. */
19624 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
19626 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
19627 return FRAME_BLINK_OFF_CURSOR (f
);
19631 /* Some people liked having a permanently visible blinking cursor,
19632 while others had very strong opinions against it. So it was
19633 decided to remove it. KFS 2003-09-03 */
19635 /* Finally perform built-in cursor blinking:
19636 filled box <-> hollow box
19637 wide [h]bar <-> narrow [h]bar
19638 narrow [h]bar <-> no cursor
19639 other type <-> no cursor */
19641 if (cursor_type
== FILLED_BOX_CURSOR
)
19642 return HOLLOW_BOX_CURSOR
;
19644 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
19647 return cursor_type
;
19655 #ifdef HAVE_WINDOW_SYSTEM
19657 /* Notice when the text cursor of window W has been completely
19658 overwritten by a drawing operation that outputs glyphs in AREA
19659 starting at X0 and ending at X1 in the line starting at Y0 and
19660 ending at Y1. X coordinates are area-relative. X1 < 0 means all
19661 the rest of the line after X0 has been written. Y coordinates
19662 are window-relative. */
19665 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
19667 enum glyph_row_area area
;
19668 int x0
, y0
, x1
, y1
;
19670 int cx0
, cx1
, cy0
, cy1
;
19671 struct glyph_row
*row
;
19673 if (!w
->phys_cursor_on_p
)
19675 if (area
!= TEXT_AREA
)
19678 row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
;
19679 if (!row
->displays_text_p
)
19682 if (row
->cursor_in_fringe_p
)
19684 row
->cursor_in_fringe_p
= 0;
19685 draw_fringe_bitmap (w
, row
, 0);
19686 w
->phys_cursor_on_p
= 0;
19690 cx0
= w
->phys_cursor
.x
;
19691 cx1
= cx0
+ w
->phys_cursor_width
;
19692 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
19695 /* The cursor image will be completely removed from the
19696 screen if the output area intersects the cursor area in
19697 y-direction. When we draw in [y0 y1[, and some part of
19698 the cursor is at y < y0, that part must have been drawn
19699 before. When scrolling, the cursor is erased before
19700 actually scrolling, so we don't come here. When not
19701 scrolling, the rows above the old cursor row must have
19702 changed, and in this case these rows must have written
19703 over the cursor image.
19705 Likewise if part of the cursor is below y1, with the
19706 exception of the cursor being in the first blank row at
19707 the buffer and window end because update_text_area
19708 doesn't draw that row. (Except when it does, but
19709 that's handled in update_text_area.) */
19711 cy0
= w
->phys_cursor
.y
;
19712 cy1
= cy0
+ w
->phys_cursor_height
;
19713 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
19716 w
->phys_cursor_on_p
= 0;
19719 #endif /* HAVE_WINDOW_SYSTEM */
19722 /************************************************************************
19724 ************************************************************************/
19726 #ifdef HAVE_WINDOW_SYSTEM
19729 Fix the display of area AREA of overlapping row ROW in window W. */
19732 x_fix_overlapping_area (w
, row
, area
)
19734 struct glyph_row
*row
;
19735 enum glyph_row_area area
;
19742 for (i
= 0; i
< row
->used
[area
];)
19744 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
19746 int start
= i
, start_x
= x
;
19750 x
+= row
->glyphs
[area
][i
].pixel_width
;
19753 while (i
< row
->used
[area
]
19754 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
19756 draw_glyphs (w
, start_x
, row
, area
,
19758 DRAW_NORMAL_TEXT
, 1);
19762 x
+= row
->glyphs
[area
][i
].pixel_width
;
19772 Draw the cursor glyph of window W in glyph row ROW. See the
19773 comment of draw_glyphs for the meaning of HL. */
19776 draw_phys_cursor_glyph (w
, row
, hl
)
19778 struct glyph_row
*row
;
19779 enum draw_glyphs_face hl
;
19781 /* If cursor hpos is out of bounds, don't draw garbage. This can
19782 happen in mini-buffer windows when switching between echo area
19783 glyphs and mini-buffer. */
19784 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
19786 int on_p
= w
->phys_cursor_on_p
;
19788 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
19789 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
19791 w
->phys_cursor_on_p
= on_p
;
19793 if (hl
== DRAW_CURSOR
)
19794 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
19795 /* When we erase the cursor, and ROW is overlapped by other
19796 rows, make sure that these overlapping parts of other rows
19798 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
19800 if (row
> w
->current_matrix
->rows
19801 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
19802 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
19804 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
19805 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
19806 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
19813 Erase the image of a cursor of window W from the screen. */
19816 erase_phys_cursor (w
)
19819 struct frame
*f
= XFRAME (w
->frame
);
19820 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
19821 int hpos
= w
->phys_cursor
.hpos
;
19822 int vpos
= w
->phys_cursor
.vpos
;
19823 int mouse_face_here_p
= 0;
19824 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
19825 struct glyph_row
*cursor_row
;
19826 struct glyph
*cursor_glyph
;
19827 enum draw_glyphs_face hl
;
19829 /* No cursor displayed or row invalidated => nothing to do on the
19831 if (w
->phys_cursor_type
== NO_CURSOR
)
19832 goto mark_cursor_off
;
19834 /* VPOS >= active_glyphs->nrows means that window has been resized.
19835 Don't bother to erase the cursor. */
19836 if (vpos
>= active_glyphs
->nrows
)
19837 goto mark_cursor_off
;
19839 /* If row containing cursor is marked invalid, there is nothing we
19841 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
19842 if (!cursor_row
->enabled_p
)
19843 goto mark_cursor_off
;
19845 /* If row is completely invisible, don't attempt to delete a cursor which
19846 isn't there. This can happen if cursor is at top of a window, and
19847 we switch to a buffer with a header line in that window. */
19848 if (cursor_row
->visible_height
<= 0)
19849 goto mark_cursor_off
;
19851 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
19852 if (cursor_row
->cursor_in_fringe_p
)
19854 cursor_row
->cursor_in_fringe_p
= 0;
19855 draw_fringe_bitmap (w
, cursor_row
, 0);
19856 goto mark_cursor_off
;
19859 /* This can happen when the new row is shorter than the old one.
19860 In this case, either draw_glyphs or clear_end_of_line
19861 should have cleared the cursor. Note that we wouldn't be
19862 able to erase the cursor in this case because we don't have a
19863 cursor glyph at hand. */
19864 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
19865 goto mark_cursor_off
;
19867 /* If the cursor is in the mouse face area, redisplay that when
19868 we clear the cursor. */
19869 if (! NILP (dpyinfo
->mouse_face_window
)
19870 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
19871 && (vpos
> dpyinfo
->mouse_face_beg_row
19872 || (vpos
== dpyinfo
->mouse_face_beg_row
19873 && hpos
>= dpyinfo
->mouse_face_beg_col
))
19874 && (vpos
< dpyinfo
->mouse_face_end_row
19875 || (vpos
== dpyinfo
->mouse_face_end_row
19876 && hpos
< dpyinfo
->mouse_face_end_col
))
19877 /* Don't redraw the cursor's spot in mouse face if it is at the
19878 end of a line (on a newline). The cursor appears there, but
19879 mouse highlighting does not. */
19880 && cursor_row
->used
[TEXT_AREA
] > hpos
)
19881 mouse_face_here_p
= 1;
19883 /* Maybe clear the display under the cursor. */
19884 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
19887 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
19889 cursor_glyph
= get_phys_cursor_glyph (w
);
19890 if (cursor_glyph
== NULL
)
19891 goto mark_cursor_off
;
19893 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
19894 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
19896 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
,
19897 cursor_glyph
->pixel_width
, cursor_row
->visible_height
);
19900 /* Erase the cursor by redrawing the character underneath it. */
19901 if (mouse_face_here_p
)
19902 hl
= DRAW_MOUSE_FACE
;
19904 hl
= DRAW_NORMAL_TEXT
;
19905 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
19908 w
->phys_cursor_on_p
= 0;
19909 w
->phys_cursor_type
= NO_CURSOR
;
19914 Display or clear cursor of window W. If ON is zero, clear the
19915 cursor. If it is non-zero, display the cursor. If ON is nonzero,
19916 where to put the cursor is specified by HPOS, VPOS, X and Y. */
19919 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
19921 int on
, hpos
, vpos
, x
, y
;
19923 struct frame
*f
= XFRAME (w
->frame
);
19924 int new_cursor_type
;
19925 int new_cursor_width
;
19927 struct glyph_matrix
*current_glyphs
;
19928 struct glyph_row
*glyph_row
;
19929 struct glyph
*glyph
;
19931 /* This is pointless on invisible frames, and dangerous on garbaged
19932 windows and frames; in the latter case, the frame or window may
19933 be in the midst of changing its size, and x and y may be off the
19935 if (! FRAME_VISIBLE_P (f
)
19936 || FRAME_GARBAGED_P (f
)
19937 || vpos
>= w
->current_matrix
->nrows
19938 || hpos
>= w
->current_matrix
->matrix_w
)
19941 /* If cursor is off and we want it off, return quickly. */
19942 if (!on
&& !w
->phys_cursor_on_p
)
19945 current_glyphs
= w
->current_matrix
;
19946 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
19947 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
19949 /* If cursor row is not enabled, we don't really know where to
19950 display the cursor. */
19951 if (!glyph_row
->enabled_p
)
19953 w
->phys_cursor_on_p
= 0;
19957 xassert (interrupt_input_blocked
);
19959 /* Set new_cursor_type to the cursor we want to be displayed. */
19960 new_cursor_type
= get_window_cursor_type (w
, glyph
,
19961 &new_cursor_width
, &active_cursor
);
19963 /* If cursor is currently being shown and we don't want it to be or
19964 it is in the wrong place, or the cursor type is not what we want,
19966 if (w
->phys_cursor_on_p
19968 || w
->phys_cursor
.x
!= x
19969 || w
->phys_cursor
.y
!= y
19970 || new_cursor_type
!= w
->phys_cursor_type
19971 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
19972 && new_cursor_width
!= w
->phys_cursor_width
)))
19973 erase_phys_cursor (w
);
19975 /* Don't check phys_cursor_on_p here because that flag is only set
19976 to zero in some cases where we know that the cursor has been
19977 completely erased, to avoid the extra work of erasing the cursor
19978 twice. In other words, phys_cursor_on_p can be 1 and the cursor
19979 still not be visible, or it has only been partly erased. */
19982 w
->phys_cursor_ascent
= glyph_row
->ascent
;
19983 w
->phys_cursor_height
= glyph_row
->height
;
19985 /* Set phys_cursor_.* before x_draw_.* is called because some
19986 of them may need the information. */
19987 w
->phys_cursor
.x
= x
;
19988 w
->phys_cursor
.y
= glyph_row
->y
;
19989 w
->phys_cursor
.hpos
= hpos
;
19990 w
->phys_cursor
.vpos
= vpos
;
19993 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
19994 new_cursor_type
, new_cursor_width
,
19995 on
, active_cursor
);
19999 /* Switch the display of W's cursor on or off, according to the value
20003 update_window_cursor (w
, on
)
20007 /* Don't update cursor in windows whose frame is in the process
20008 of being deleted. */
20009 if (w
->current_matrix
)
20012 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20013 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20019 /* Call update_window_cursor with parameter ON_P on all leaf windows
20020 in the window tree rooted at W. */
20023 update_cursor_in_window_tree (w
, on_p
)
20029 if (!NILP (w
->hchild
))
20030 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
20031 else if (!NILP (w
->vchild
))
20032 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
20034 update_window_cursor (w
, on_p
);
20036 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
20042 Display the cursor on window W, or clear it, according to ON_P.
20043 Don't change the cursor's position. */
20046 x_update_cursor (f
, on_p
)
20050 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
20055 Clear the cursor of window W to background color, and mark the
20056 cursor as not shown. This is used when the text where the cursor
20057 is is about to be rewritten. */
20063 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
20064 update_window_cursor (w
, 0);
20069 Display the active region described by mouse_face_* according to DRAW. */
20072 show_mouse_face (dpyinfo
, draw
)
20073 Display_Info
*dpyinfo
;
20074 enum draw_glyphs_face draw
;
20076 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
20077 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20079 if (/* If window is in the process of being destroyed, don't bother
20081 w
->current_matrix
!= NULL
20082 /* Don't update mouse highlight if hidden */
20083 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
20084 /* Recognize when we are called to operate on rows that don't exist
20085 anymore. This can happen when a window is split. */
20086 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
20088 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
20089 struct glyph_row
*row
, *first
, *last
;
20091 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20092 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20094 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
20096 int start_hpos
, end_hpos
, start_x
;
20098 /* For all but the first row, the highlight starts at column 0. */
20101 start_hpos
= dpyinfo
->mouse_face_beg_col
;
20102 start_x
= dpyinfo
->mouse_face_beg_x
;
20111 end_hpos
= dpyinfo
->mouse_face_end_col
;
20113 end_hpos
= row
->used
[TEXT_AREA
];
20115 if (end_hpos
> start_hpos
)
20117 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
20118 start_hpos
, end_hpos
,
20122 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
20126 /* When we've written over the cursor, arrange for it to
20127 be displayed again. */
20128 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
20131 display_and_set_cursor (w
, 1,
20132 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20133 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20138 /* Change the mouse cursor. */
20139 if (draw
== DRAW_NORMAL_TEXT
)
20140 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
20141 else if (draw
== DRAW_MOUSE_FACE
)
20142 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
20144 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
20148 Clear out the mouse-highlighted active region.
20149 Redraw it un-highlighted first. Value is non-zero if mouse
20150 face was actually drawn unhighlighted. */
20153 clear_mouse_face (dpyinfo
)
20154 Display_Info
*dpyinfo
;
20158 if (!NILP (dpyinfo
->mouse_face_window
))
20160 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
20164 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
20165 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
20166 dpyinfo
->mouse_face_window
= Qnil
;
20167 dpyinfo
->mouse_face_overlay
= Qnil
;
20173 Non-zero if physical cursor of window W is within mouse face. */
20176 cursor_in_mouse_face_p (w
)
20179 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
20180 int in_mouse_face
= 0;
20182 if (WINDOWP (dpyinfo
->mouse_face_window
)
20183 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
20185 int hpos
= w
->phys_cursor
.hpos
;
20186 int vpos
= w
->phys_cursor
.vpos
;
20188 if (vpos
>= dpyinfo
->mouse_face_beg_row
20189 && vpos
<= dpyinfo
->mouse_face_end_row
20190 && (vpos
> dpyinfo
->mouse_face_beg_row
20191 || hpos
>= dpyinfo
->mouse_face_beg_col
)
20192 && (vpos
< dpyinfo
->mouse_face_end_row
20193 || hpos
< dpyinfo
->mouse_face_end_col
20194 || dpyinfo
->mouse_face_past_end
))
20198 return in_mouse_face
;
20204 /* Find the glyph matrix position of buffer position CHARPOS in window
20205 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
20206 current glyphs must be up to date. If CHARPOS is above window
20207 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
20208 of last line in W. In the row containing CHARPOS, stop before glyphs
20209 having STOP as object. */
20211 #if 1 /* This is a version of fast_find_position that's more correct
20212 in the presence of hscrolling, for example. I didn't install
20213 it right away because the problem fixed is minor, it failed
20214 in 20.x as well, and I think it's too risky to install
20215 so near the release of 21.1. 2001-09-25 gerd. */
20218 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
20221 int *hpos
, *vpos
, *x
, *y
;
20224 struct glyph_row
*row
, *first
;
20225 struct glyph
*glyph
, *end
;
20228 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20229 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
20232 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
20234 *x
= *y
= *hpos
= *vpos
= 0;
20239 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
20246 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
20248 glyph
= row
->glyphs
[TEXT_AREA
];
20249 end
= glyph
+ row
->used
[TEXT_AREA
];
20251 /* Skip over glyphs not having an object at the start of the row.
20252 These are special glyphs like truncation marks on terminal
20254 if (row
->displays_text_p
)
20256 && INTEGERP (glyph
->object
)
20257 && !EQ (stop
, glyph
->object
)
20258 && glyph
->charpos
< 0)
20260 *x
+= glyph
->pixel_width
;
20265 && !INTEGERP (glyph
->object
)
20266 && !EQ (stop
, glyph
->object
)
20267 && (!BUFFERP (glyph
->object
)
20268 || glyph
->charpos
< charpos
))
20270 *x
+= glyph
->pixel_width
;
20274 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
20281 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
20284 int *hpos
, *vpos
, *x
, *y
;
20289 int maybe_next_line_p
= 0;
20290 int line_start_position
;
20291 int yb
= window_text_bottom_y (w
);
20292 struct glyph_row
*row
, *best_row
;
20293 int row_vpos
, best_row_vpos
;
20296 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20297 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
20299 while (row
->y
< yb
)
20301 if (row
->used
[TEXT_AREA
])
20302 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
20304 line_start_position
= 0;
20306 if (line_start_position
> pos
)
20308 /* If the position sought is the end of the buffer,
20309 don't include the blank lines at the bottom of the window. */
20310 else if (line_start_position
== pos
20311 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
20313 maybe_next_line_p
= 1;
20316 else if (line_start_position
> 0)
20319 best_row_vpos
= row_vpos
;
20322 if (row
->y
+ row
->height
>= yb
)
20329 /* Find the right column within BEST_ROW. */
20331 current_x
= best_row
->x
;
20332 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
20334 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
20335 int charpos
= glyph
->charpos
;
20337 if (BUFFERP (glyph
->object
))
20339 if (charpos
== pos
)
20342 *vpos
= best_row_vpos
;
20347 else if (charpos
> pos
)
20350 else if (EQ (glyph
->object
, stop
))
20355 current_x
+= glyph
->pixel_width
;
20358 /* If we're looking for the end of the buffer,
20359 and we didn't find it in the line we scanned,
20360 use the start of the following line. */
20361 if (maybe_next_line_p
)
20366 current_x
= best_row
->x
;
20369 *vpos
= best_row_vpos
;
20370 *hpos
= lastcol
+ 1;
20379 /* Find the position of the glyph for position POS in OBJECT in
20380 window W's current matrix, and return in *X, *Y the pixel
20381 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
20383 RIGHT_P non-zero means return the position of the right edge of the
20384 glyph, RIGHT_P zero means return the left edge position.
20386 If no glyph for POS exists in the matrix, return the position of
20387 the glyph with the next smaller position that is in the matrix, if
20388 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
20389 exists in the matrix, return the position of the glyph with the
20390 next larger position in OBJECT.
20392 Value is non-zero if a glyph was found. */
20395 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
20398 Lisp_Object object
;
20399 int *hpos
, *vpos
, *x
, *y
;
20402 int yb
= window_text_bottom_y (w
);
20403 struct glyph_row
*r
;
20404 struct glyph
*best_glyph
= NULL
;
20405 struct glyph_row
*best_row
= NULL
;
20408 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20409 r
->enabled_p
&& r
->y
< yb
;
20412 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
20413 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
20416 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
20417 if (EQ (g
->object
, object
))
20419 if (g
->charpos
== pos
)
20426 else if (best_glyph
== NULL
20427 || ((abs (g
->charpos
- pos
)
20428 < abs (best_glyph
->charpos
- pos
))
20431 : g
->charpos
> pos
)))
20445 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
20449 *x
+= best_glyph
->pixel_width
;
20454 *vpos
= best_row
- w
->current_matrix
->rows
;
20457 return best_glyph
!= NULL
;
20461 /* See if position X, Y is within a hot-spot of an image. */
20464 on_hot_spot_p (hot_spot
, x
, y
)
20465 Lisp_Object hot_spot
;
20468 if (!CONSP (hot_spot
))
20471 if (EQ (XCAR (hot_spot
), Qrect
))
20473 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
20474 Lisp_Object rect
= XCDR (hot_spot
);
20478 if (!CONSP (XCAR (rect
)))
20480 if (!CONSP (XCDR (rect
)))
20482 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
20484 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
20486 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
20488 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
20492 else if (EQ (XCAR (hot_spot
), Qcircle
))
20494 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
20495 Lisp_Object circ
= XCDR (hot_spot
);
20496 Lisp_Object lr
, lx0
, ly0
;
20498 && CONSP (XCAR (circ
))
20499 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
20500 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
20501 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
20503 double r
= XFLOATINT (lr
);
20504 double dx
= XINT (lx0
) - x
;
20505 double dy
= XINT (ly0
) - y
;
20506 return (dx
* dx
+ dy
* dy
<= r
* r
);
20509 else if (EQ (XCAR (hot_spot
), Qpoly
))
20511 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
20512 if (VECTORP (XCDR (hot_spot
)))
20514 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
20515 Lisp_Object
*poly
= v
->contents
;
20519 Lisp_Object lx
, ly
;
20522 /* Need an even number of coordinates, and at least 3 edges. */
20523 if (n
< 6 || n
& 1)
20526 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
20527 If count is odd, we are inside polygon. Pixels on edges
20528 may or may not be included depending on actual geometry of the
20530 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
20531 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
20533 x0
= XINT (lx
), y0
= XINT (ly
);
20534 for (i
= 0; i
< n
; i
+= 2)
20536 int x1
= x0
, y1
= y0
;
20537 if ((lx
= poly
[i
], !INTEGERP (lx
))
20538 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
20540 x0
= XINT (lx
), y0
= XINT (ly
);
20542 /* Does this segment cross the X line? */
20550 if (y
> y0
&& y
> y1
)
20552 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
20563 find_hot_spot (map
, x
, y
)
20567 while (CONSP (map
))
20569 if (CONSP (XCAR (map
))
20570 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
20578 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
20580 doc
: /* Lookup in image map MAP coordinates X and Y.
20581 An image map is an alist where each element has the format (AREA ID PLIST).
20582 An AREA is specified as either a rectangle, a circle, or a polygon:
20583 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
20584 pixel coordinates of the upper left and bottom right corners.
20585 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
20586 and the radius of the circle; r may be a float or integer.
20587 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
20588 vector describes one corner in the polygon.
20589 Returns the alist element for the first matching AREA in MAP. */)
20599 wrong_type_argument (Qintegerp
, x
);
20601 wrong_type_argument (Qintegerp
, y
);
20603 return find_hot_spot (map
, XINT (x
), XINT (y
));
20607 /* Display frame CURSOR, optionally using shape defined by POINTER. */
20609 define_frame_cursor1 (f
, cursor
, pointer
)
20612 Lisp_Object pointer
;
20614 if (!NILP (pointer
))
20616 if (EQ (pointer
, Qarrow
))
20617 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20618 else if (EQ (pointer
, Qhand
))
20619 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
20620 else if (EQ (pointer
, Qtext
))
20621 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
20622 else if (EQ (pointer
, intern ("hdrag")))
20623 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
20624 #ifdef HAVE_X_WINDOWS
20625 else if (EQ (pointer
, intern ("vdrag")))
20626 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
20628 else if (EQ (pointer
, intern ("hourglass")))
20629 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
20630 else if (EQ (pointer
, Qmodeline
))
20631 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
20633 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20636 #ifndef HAVE_CARBON
20637 if (cursor
!= No_Cursor
)
20639 if (bcmp (&cursor
, &No_Cursor
, sizeof (Cursor
)))
20641 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
20644 /* Take proper action when mouse has moved to the mode or header line
20645 or marginal area AREA of window W, x-position X and y-position Y.
20646 X is relative to the start of the text display area of W, so the
20647 width of bitmap areas and scroll bars must be subtracted to get a
20648 position relative to the start of the mode line. */
20651 note_mode_line_or_margin_highlight (w
, x
, y
, area
)
20654 enum window_part area
;
20656 struct frame
*f
= XFRAME (w
->frame
);
20657 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20658 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20659 Lisp_Object pointer
= Qnil
;
20660 int charpos
, dx
, dy
, width
, height
;
20661 Lisp_Object string
, object
= Qnil
;
20662 Lisp_Object pos
, help
, image
;
20664 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
20665 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
20666 &object
, &dx
, &dy
, &width
, &height
);
20669 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
20670 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
20671 &object
, &dx
, &dy
, &width
, &height
);
20676 if (IMAGEP (object
))
20678 Lisp_Object image_map
, hotspot
;
20679 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
20681 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
20683 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
20685 Lisp_Object area_id
, plist
;
20687 area_id
= XCAR (hotspot
);
20688 /* Could check AREA_ID to see if we enter/leave this hot-spot.
20689 If so, we could look for mouse-enter, mouse-leave
20690 properties in PLIST (and do something...). */
20691 if ((plist
= XCDR (hotspot
), CONSP (plist
)))
20693 pointer
= Fplist_get (plist
, Qpointer
);
20694 if (NILP (pointer
))
20696 help
= Fplist_get (plist
, Qhelp_echo
);
20699 help_echo_string
= help
;
20700 /* Is this correct? ++kfs */
20701 XSETWINDOW (help_echo_window
, w
);
20702 help_echo_object
= w
->buffer
;
20703 help_echo_pos
= charpos
;
20706 if (NILP (pointer
))
20707 pointer
= Fplist_get (XCDR (object
), QCpointer
);
20711 if (STRINGP (string
))
20713 pos
= make_number (charpos
);
20714 /* If we're on a string with `help-echo' text property, arrange
20715 for the help to be displayed. This is done by setting the
20716 global variable help_echo_string to the help string. */
20717 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
20720 help_echo_string
= help
;
20721 XSETWINDOW (help_echo_window
, w
);
20722 help_echo_object
= string
;
20723 help_echo_pos
= charpos
;
20726 if (NILP (pointer
))
20727 pointer
= Fget_text_property (pos
, Qpointer
, string
);
20729 /* Change the mouse pointer according to what is under X/Y. */
20730 if (NILP (pointer
) && area
== ON_MODE_LINE
)
20733 map
= Fget_text_property (pos
, Qlocal_map
, string
);
20734 if (!KEYMAPP (map
))
20735 map
= Fget_text_property (pos
, Qkeymap
, string
);
20736 if (!KEYMAPP (map
))
20737 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
20741 define_frame_cursor1 (f
, cursor
, pointer
);
20746 Take proper action when the mouse has moved to position X, Y on
20747 frame F as regards highlighting characters that have mouse-face
20748 properties. Also de-highlighting chars where the mouse was before.
20749 X and Y can be negative or out of range. */
20752 note_mouse_highlight (f
, x
, y
)
20756 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20757 enum window_part part
;
20758 Lisp_Object window
;
20760 Cursor cursor
= No_Cursor
;
20761 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
20764 /* When a menu is active, don't highlight because this looks odd. */
20765 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
20766 if (popup_activated ())
20770 if (NILP (Vmouse_highlight
)
20771 || !f
->glyphs_initialized_p
)
20774 dpyinfo
->mouse_face_mouse_x
= x
;
20775 dpyinfo
->mouse_face_mouse_y
= y
;
20776 dpyinfo
->mouse_face_mouse_frame
= f
;
20778 if (dpyinfo
->mouse_face_defer
)
20781 if (gc_in_progress
)
20783 dpyinfo
->mouse_face_deferred_gc
= 1;
20787 /* Which window is that in? */
20788 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
20790 /* If we were displaying active text in another window, clear that. */
20791 if (! EQ (window
, dpyinfo
->mouse_face_window
))
20792 clear_mouse_face (dpyinfo
);
20794 /* Not on a window -> return. */
20795 if (!WINDOWP (window
))
20798 /* Reset help_echo_string. It will get recomputed below. */
20799 help_echo_string
= Qnil
;
20801 /* Convert to window-relative pixel coordinates. */
20802 w
= XWINDOW (window
);
20803 frame_to_window_pixel_xy (w
, &x
, &y
);
20805 /* Handle tool-bar window differently since it doesn't display a
20807 if (EQ (window
, f
->tool_bar_window
))
20809 note_tool_bar_highlight (f
, x
, y
);
20813 /* Mouse is on the mode, header line or margin? */
20814 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
20815 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
20817 note_mode_line_or_margin_highlight (w
, x
, y
, part
);
20821 if (part
== ON_VERTICAL_BORDER
)
20822 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
20823 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
)
20824 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20826 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
20828 /* Are we in a window whose display is up to date?
20829 And verify the buffer's text has not changed. */
20830 b
= XBUFFER (w
->buffer
);
20831 if (part
== ON_TEXT
20832 && EQ (w
->window_end_valid
, w
->buffer
)
20833 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
20834 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
20836 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
20837 struct glyph
*glyph
;
20838 Lisp_Object object
;
20839 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
20840 Lisp_Object
*overlay_vec
= NULL
;
20841 int len
, noverlays
;
20842 struct buffer
*obuf
;
20843 int obegv
, ozv
, same_region
;
20845 /* Find the glyph under X/Y. */
20846 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
20848 /* Look for :pointer property on image. */
20849 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
20851 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
20852 if (img
!= NULL
&& IMAGEP (img
->spec
))
20854 Lisp_Object image_map
, hotspot
;
20855 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
20857 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
20859 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
20861 Lisp_Object area_id
, plist
;
20863 area_id
= XCAR (hotspot
);
20864 /* Could check AREA_ID to see if we enter/leave this hot-spot.
20865 If so, we could look for mouse-enter, mouse-leave
20866 properties in PLIST (and do something...). */
20867 if ((plist
= XCDR (hotspot
), CONSP (plist
)))
20869 pointer
= Fplist_get (plist
, Qpointer
);
20870 if (NILP (pointer
))
20872 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
20873 if (!NILP (help_echo_string
))
20875 help_echo_window
= window
;
20876 help_echo_object
= glyph
->object
;
20877 help_echo_pos
= glyph
->charpos
;
20881 if (NILP (pointer
))
20882 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
20886 /* Clear mouse face if X/Y not over text. */
20888 || area
!= TEXT_AREA
20889 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
20891 if (clear_mouse_face (dpyinfo
))
20892 cursor
= No_Cursor
;
20893 if (NILP (pointer
))
20895 if (area
!= TEXT_AREA
)
20896 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20898 pointer
= Vvoid_text_area_pointer
;
20903 pos
= glyph
->charpos
;
20904 object
= glyph
->object
;
20905 if (!STRINGP (object
) && !BUFFERP (object
))
20908 /* If we get an out-of-range value, return now; avoid an error. */
20909 if (BUFFERP (object
) && pos
> BUF_Z (b
))
20912 /* Make the window's buffer temporarily current for
20913 overlays_at and compute_char_face. */
20914 obuf
= current_buffer
;
20915 current_buffer
= b
;
20921 /* Is this char mouse-active or does it have help-echo? */
20922 position
= make_number (pos
);
20924 if (BUFFERP (object
))
20926 /* Put all the overlays we want in a vector in overlay_vec.
20927 Store the length in len. If there are more than 10, make
20928 enough space for all, and try again. */
20930 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
20931 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
20932 if (noverlays
> len
)
20935 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
20936 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
20939 /* Sort overlays into increasing priority order. */
20940 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
20945 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
20946 && vpos
>= dpyinfo
->mouse_face_beg_row
20947 && vpos
<= dpyinfo
->mouse_face_end_row
20948 && (vpos
> dpyinfo
->mouse_face_beg_row
20949 || hpos
>= dpyinfo
->mouse_face_beg_col
)
20950 && (vpos
< dpyinfo
->mouse_face_end_row
20951 || hpos
< dpyinfo
->mouse_face_end_col
20952 || dpyinfo
->mouse_face_past_end
));
20955 cursor
= No_Cursor
;
20957 /* Check mouse-face highlighting. */
20959 /* If there exists an overlay with mouse-face overlapping
20960 the one we are currently highlighting, we have to
20961 check if we enter the overlapping overlay, and then
20962 highlight only that. */
20963 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
20964 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
20966 /* Find the highest priority overlay that has a mouse-face
20969 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
20971 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
20972 if (!NILP (mouse_face
))
20973 overlay
= overlay_vec
[i
];
20976 /* If we're actually highlighting the same overlay as
20977 before, there's no need to do that again. */
20978 if (!NILP (overlay
)
20979 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
20980 goto check_help_echo
;
20982 dpyinfo
->mouse_face_overlay
= overlay
;
20984 /* Clear the display of the old active region, if any. */
20985 if (clear_mouse_face (dpyinfo
))
20986 cursor
= No_Cursor
;
20988 /* If no overlay applies, get a text property. */
20989 if (NILP (overlay
))
20990 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
20992 /* Handle the overlay case. */
20993 if (!NILP (overlay
))
20995 /* Find the range of text around this char that
20996 should be active. */
20997 Lisp_Object before
, after
;
21000 before
= Foverlay_start (overlay
);
21001 after
= Foverlay_end (overlay
);
21002 /* Record this as the current active region. */
21003 fast_find_position (w
, XFASTINT (before
),
21004 &dpyinfo
->mouse_face_beg_col
,
21005 &dpyinfo
->mouse_face_beg_row
,
21006 &dpyinfo
->mouse_face_beg_x
,
21007 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21009 dpyinfo
->mouse_face_past_end
21010 = !fast_find_position (w
, XFASTINT (after
),
21011 &dpyinfo
->mouse_face_end_col
,
21012 &dpyinfo
->mouse_face_end_row
,
21013 &dpyinfo
->mouse_face_end_x
,
21014 &dpyinfo
->mouse_face_end_y
, Qnil
);
21015 dpyinfo
->mouse_face_window
= window
;
21017 dpyinfo
->mouse_face_face_id
21018 = face_at_buffer_position (w
, pos
, 0, 0,
21020 !dpyinfo
->mouse_face_hidden
);
21022 /* Display it as active. */
21023 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21024 cursor
= No_Cursor
;
21026 /* Handle the text property case. */
21027 else if (!NILP (mouse_face
) && BUFFERP (object
))
21029 /* Find the range of text around this char that
21030 should be active. */
21031 Lisp_Object before
, after
, beginning
, end
;
21034 beginning
= Fmarker_position (w
->start
);
21035 end
= make_number (BUF_Z (XBUFFER (object
))
21036 - XFASTINT (w
->window_end_pos
));
21038 = Fprevious_single_property_change (make_number (pos
+ 1),
21040 object
, beginning
);
21042 = Fnext_single_property_change (position
, Qmouse_face
,
21045 /* Record this as the current active region. */
21046 fast_find_position (w
, XFASTINT (before
),
21047 &dpyinfo
->mouse_face_beg_col
,
21048 &dpyinfo
->mouse_face_beg_row
,
21049 &dpyinfo
->mouse_face_beg_x
,
21050 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21051 dpyinfo
->mouse_face_past_end
21052 = !fast_find_position (w
, XFASTINT (after
),
21053 &dpyinfo
->mouse_face_end_col
,
21054 &dpyinfo
->mouse_face_end_row
,
21055 &dpyinfo
->mouse_face_end_x
,
21056 &dpyinfo
->mouse_face_end_y
, Qnil
);
21057 dpyinfo
->mouse_face_window
= window
;
21059 if (BUFFERP (object
))
21060 dpyinfo
->mouse_face_face_id
21061 = face_at_buffer_position (w
, pos
, 0, 0,
21063 !dpyinfo
->mouse_face_hidden
);
21065 /* Display it as active. */
21066 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21067 cursor
= No_Cursor
;
21069 else if (!NILP (mouse_face
) && STRINGP (object
))
21074 b
= Fprevious_single_property_change (make_number (pos
+ 1),
21077 e
= Fnext_single_property_change (position
, Qmouse_face
,
21080 b
= make_number (0);
21082 e
= make_number (SCHARS (object
) - 1);
21083 fast_find_string_pos (w
, XINT (b
), object
,
21084 &dpyinfo
->mouse_face_beg_col
,
21085 &dpyinfo
->mouse_face_beg_row
,
21086 &dpyinfo
->mouse_face_beg_x
,
21087 &dpyinfo
->mouse_face_beg_y
, 0);
21088 fast_find_string_pos (w
, XINT (e
), object
,
21089 &dpyinfo
->mouse_face_end_col
,
21090 &dpyinfo
->mouse_face_end_row
,
21091 &dpyinfo
->mouse_face_end_x
,
21092 &dpyinfo
->mouse_face_end_y
, 1);
21093 dpyinfo
->mouse_face_past_end
= 0;
21094 dpyinfo
->mouse_face_window
= window
;
21095 dpyinfo
->mouse_face_face_id
21096 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
21097 glyph
->face_id
, 1);
21098 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21099 cursor
= No_Cursor
;
21101 else if (STRINGP (object
) && NILP (mouse_face
))
21103 /* A string which doesn't have mouse-face, but
21104 the text ``under'' it might have. */
21105 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
21106 int start
= MATRIX_ROW_START_CHARPOS (r
);
21108 pos
= string_buffer_position (w
, object
, start
);
21110 mouse_face
= get_char_property_and_overlay (make_number (pos
),
21114 if (!NILP (mouse_face
) && !NILP (overlay
))
21116 Lisp_Object before
= Foverlay_start (overlay
);
21117 Lisp_Object after
= Foverlay_end (overlay
);
21120 /* Note that we might not be able to find position
21121 BEFORE in the glyph matrix if the overlay is
21122 entirely covered by a `display' property. In
21123 this case, we overshoot. So let's stop in
21124 the glyph matrix before glyphs for OBJECT. */
21125 fast_find_position (w
, XFASTINT (before
),
21126 &dpyinfo
->mouse_face_beg_col
,
21127 &dpyinfo
->mouse_face_beg_row
,
21128 &dpyinfo
->mouse_face_beg_x
,
21129 &dpyinfo
->mouse_face_beg_y
,
21132 dpyinfo
->mouse_face_past_end
21133 = !fast_find_position (w
, XFASTINT (after
),
21134 &dpyinfo
->mouse_face_end_col
,
21135 &dpyinfo
->mouse_face_end_row
,
21136 &dpyinfo
->mouse_face_end_x
,
21137 &dpyinfo
->mouse_face_end_y
,
21139 dpyinfo
->mouse_face_window
= window
;
21140 dpyinfo
->mouse_face_face_id
21141 = face_at_buffer_position (w
, pos
, 0, 0,
21143 !dpyinfo
->mouse_face_hidden
);
21145 /* Display it as active. */
21146 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21147 cursor
= No_Cursor
;
21154 /* Look for a `help-echo' property. */
21155 if (NILP (help_echo_string
)) {
21156 Lisp_Object help
, overlay
;
21158 /* Check overlays first. */
21159 help
= overlay
= Qnil
;
21160 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
21162 overlay
= overlay_vec
[i
];
21163 help
= Foverlay_get (overlay
, Qhelp_echo
);
21168 help_echo_string
= help
;
21169 help_echo_window
= window
;
21170 help_echo_object
= overlay
;
21171 help_echo_pos
= pos
;
21175 Lisp_Object object
= glyph
->object
;
21176 int charpos
= glyph
->charpos
;
21178 /* Try text properties. */
21179 if (STRINGP (object
)
21181 && charpos
< SCHARS (object
))
21183 help
= Fget_text_property (make_number (charpos
),
21184 Qhelp_echo
, object
);
21187 /* If the string itself doesn't specify a help-echo,
21188 see if the buffer text ``under'' it does. */
21189 struct glyph_row
*r
21190 = MATRIX_ROW (w
->current_matrix
, vpos
);
21191 int start
= MATRIX_ROW_START_CHARPOS (r
);
21192 int pos
= string_buffer_position (w
, object
, start
);
21195 help
= Fget_char_property (make_number (pos
),
21196 Qhelp_echo
, w
->buffer
);
21200 object
= w
->buffer
;
21205 else if (BUFFERP (object
)
21208 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
21213 help_echo_string
= help
;
21214 help_echo_window
= window
;
21215 help_echo_object
= object
;
21216 help_echo_pos
= charpos
;
21221 /* Look for a `pointer' property. */
21222 if (NILP (pointer
))
21224 /* Check overlays first. */
21225 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
21226 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
21228 if (NILP (pointer
))
21230 Lisp_Object object
= glyph
->object
;
21231 int charpos
= glyph
->charpos
;
21233 /* Try text properties. */
21234 if (STRINGP (object
)
21236 && charpos
< SCHARS (object
))
21238 pointer
= Fget_text_property (make_number (charpos
),
21240 if (NILP (pointer
))
21242 /* If the string itself doesn't specify a pointer,
21243 see if the buffer text ``under'' it does. */
21244 struct glyph_row
*r
21245 = MATRIX_ROW (w
->current_matrix
, vpos
);
21246 int start
= MATRIX_ROW_START_CHARPOS (r
);
21247 int pos
= string_buffer_position (w
, object
, start
);
21249 pointer
= Fget_char_property (make_number (pos
),
21250 Qpointer
, w
->buffer
);
21253 else if (BUFFERP (object
)
21256 pointer
= Fget_text_property (make_number (charpos
),
21263 current_buffer
= obuf
;
21268 define_frame_cursor1 (f
, cursor
, pointer
);
21273 Clear any mouse-face on window W. This function is part of the
21274 redisplay interface, and is called from try_window_id and similar
21275 functions to ensure the mouse-highlight is off. */
21278 x_clear_window_mouse_face (w
)
21281 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21282 Lisp_Object window
;
21285 XSETWINDOW (window
, w
);
21286 if (EQ (window
, dpyinfo
->mouse_face_window
))
21287 clear_mouse_face (dpyinfo
);
21293 Just discard the mouse face information for frame F, if any.
21294 This is used when the size of F is changed. */
21297 cancel_mouse_face (f
)
21300 Lisp_Object window
;
21301 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21303 window
= dpyinfo
->mouse_face_window
;
21304 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
21306 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21307 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21308 dpyinfo
->mouse_face_window
= Qnil
;
21313 #endif /* HAVE_WINDOW_SYSTEM */
21316 /***********************************************************************
21318 ***********************************************************************/
21320 #ifdef HAVE_WINDOW_SYSTEM
21322 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
21323 which intersects rectangle R. R is in window-relative coordinates. */
21326 expose_area (w
, row
, r
, area
)
21328 struct glyph_row
*row
;
21330 enum glyph_row_area area
;
21332 struct glyph
*first
= row
->glyphs
[area
];
21333 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
21334 struct glyph
*last
;
21335 int first_x
, start_x
, x
;
21337 if (area
== TEXT_AREA
&& row
->fill_line_p
)
21338 /* If row extends face to end of line write the whole line. */
21339 draw_glyphs (w
, 0, row
, area
,
21340 0, row
->used
[area
],
21341 DRAW_NORMAL_TEXT
, 0);
21344 /* Set START_X to the window-relative start position for drawing glyphs of
21345 AREA. The first glyph of the text area can be partially visible.
21346 The first glyphs of other areas cannot. */
21347 start_x
= window_box_left_offset (w
, area
);
21349 if (area
== TEXT_AREA
)
21352 /* Find the first glyph that must be redrawn. */
21354 && x
+ first
->pixel_width
< r
->x
)
21356 x
+= first
->pixel_width
;
21360 /* Find the last one. */
21364 && x
< r
->x
+ r
->width
)
21366 x
+= last
->pixel_width
;
21372 draw_glyphs (w
, first_x
- start_x
, row
, area
,
21373 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
21374 DRAW_NORMAL_TEXT
, 0);
21379 /* Redraw the parts of the glyph row ROW on window W intersecting
21380 rectangle R. R is in window-relative coordinates. Value is
21381 non-zero if mouse-face was overwritten. */
21384 expose_line (w
, row
, r
)
21386 struct glyph_row
*row
;
21389 xassert (row
->enabled_p
);
21391 if (row
->mode_line_p
|| w
->pseudo_window_p
)
21392 draw_glyphs (w
, 0, row
, TEXT_AREA
,
21393 0, row
->used
[TEXT_AREA
],
21394 DRAW_NORMAL_TEXT
, 0);
21397 if (row
->used
[LEFT_MARGIN_AREA
])
21398 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
21399 if (row
->used
[TEXT_AREA
])
21400 expose_area (w
, row
, r
, TEXT_AREA
);
21401 if (row
->used
[RIGHT_MARGIN_AREA
])
21402 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
21403 draw_row_fringe_bitmaps (w
, row
);
21406 return row
->mouse_face_p
;
21410 /* Redraw those parts of glyphs rows during expose event handling that
21411 overlap other rows. Redrawing of an exposed line writes over parts
21412 of lines overlapping that exposed line; this function fixes that.
21414 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
21415 row in W's current matrix that is exposed and overlaps other rows.
21416 LAST_OVERLAPPING_ROW is the last such row. */
21419 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
21421 struct glyph_row
*first_overlapping_row
;
21422 struct glyph_row
*last_overlapping_row
;
21424 struct glyph_row
*row
;
21426 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
21427 if (row
->overlapping_p
)
21429 xassert (row
->enabled_p
&& !row
->mode_line_p
);
21431 if (row
->used
[LEFT_MARGIN_AREA
])
21432 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
21434 if (row
->used
[TEXT_AREA
])
21435 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
21437 if (row
->used
[RIGHT_MARGIN_AREA
])
21438 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
21443 /* Return non-zero if W's cursor intersects rectangle R. */
21446 phys_cursor_in_rect_p (w
, r
)
21450 XRectangle cr
, result
;
21451 struct glyph
*cursor_glyph
;
21453 cursor_glyph
= get_phys_cursor_glyph (w
);
21456 /* r is relative to W's box, but w->phys_cursor.x is relative
21457 to left edge of W's TEXT area. Adjust it. */
21458 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
21459 cr
.y
= w
->phys_cursor
.y
;
21460 cr
.width
= cursor_glyph
->pixel_width
;
21461 cr
.height
= w
->phys_cursor_height
;
21462 /* ++KFS: W32 version used W32-specific IntersectRect here, but
21463 I assume the effect is the same -- and this is portable. */
21464 return x_intersect_rectangles (&cr
, r
, &result
);
21472 Draw a vertical window border to the right of window W if W doesn't
21473 have vertical scroll bars. */
21476 x_draw_vertical_border (w
)
21479 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21481 /* We could do better, if we knew what type of scroll-bar the adjacent
21482 windows (on either side) have... But we don't :-(
21483 However, I think this works ok. ++KFS 2003-04-25 */
21485 /* Redraw borders between horizontally adjacent windows. Don't
21486 do it for frames with vertical scroll bars because either the
21487 right scroll bar of a window, or the left scroll bar of its
21488 neighbor will suffice as a border. */
21489 if (!WINDOW_RIGHTMOST_P (w
)
21490 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
21492 int x0
, x1
, y0
, y1
;
21494 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21497 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
21499 else if (!WINDOW_LEFTMOST_P (w
)
21500 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
21502 int x0
, x1
, y0
, y1
;
21504 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21507 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
21512 /* Redraw the part of window W intersection rectangle FR. Pixel
21513 coordinates in FR are frame-relative. Call this function with
21514 input blocked. Value is non-zero if the exposure overwrites
21518 expose_window (w
, fr
)
21522 struct frame
*f
= XFRAME (w
->frame
);
21524 int mouse_face_overwritten_p
= 0;
21526 /* If window is not yet fully initialized, do nothing. This can
21527 happen when toolkit scroll bars are used and a window is split.
21528 Reconfiguring the scroll bar will generate an expose for a newly
21530 if (w
->current_matrix
== NULL
)
21533 /* When we're currently updating the window, display and current
21534 matrix usually don't agree. Arrange for a thorough display
21536 if (w
== updated_window
)
21538 SET_FRAME_GARBAGED (f
);
21542 /* Frame-relative pixel rectangle of W. */
21543 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
21544 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
21545 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
21546 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
21548 if (x_intersect_rectangles (fr
, &wr
, &r
))
21550 int yb
= window_text_bottom_y (w
);
21551 struct glyph_row
*row
;
21552 int cursor_cleared_p
;
21553 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
21555 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
21556 r
.x
, r
.y
, r
.width
, r
.height
));
21558 /* Convert to window coordinates. */
21559 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
21560 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
21562 /* Turn off the cursor. */
21563 if (!w
->pseudo_window_p
21564 && phys_cursor_in_rect_p (w
, &r
))
21566 x_clear_cursor (w
);
21567 cursor_cleared_p
= 1;
21570 cursor_cleared_p
= 0;
21572 /* Update lines intersecting rectangle R. */
21573 first_overlapping_row
= last_overlapping_row
= NULL
;
21574 for (row
= w
->current_matrix
->rows
;
21579 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
21581 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
21582 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
21583 || (r
.y
>= y0
&& r
.y
< y1
)
21584 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
21586 if (row
->overlapping_p
)
21588 if (first_overlapping_row
== NULL
)
21589 first_overlapping_row
= row
;
21590 last_overlapping_row
= row
;
21593 if (expose_line (w
, row
, &r
))
21594 mouse_face_overwritten_p
= 1;
21601 /* Display the mode line if there is one. */
21602 if (WINDOW_WANTS_MODELINE_P (w
)
21603 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
21605 && row
->y
< r
.y
+ r
.height
)
21607 if (expose_line (w
, row
, &r
))
21608 mouse_face_overwritten_p
= 1;
21611 if (!w
->pseudo_window_p
)
21613 /* Fix the display of overlapping rows. */
21614 if (first_overlapping_row
)
21615 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
21617 /* Draw border between windows. */
21618 x_draw_vertical_border (w
);
21620 /* Turn the cursor on again. */
21621 if (cursor_cleared_p
)
21622 update_window_cursor (w
, 1);
21627 /* Display scroll bar for this window. */
21628 if (!NILP (w
->vertical_scroll_bar
))
21631 If this doesn't work here (maybe some header files are missing),
21632 make a function in macterm.c and call it to do the job! */
21634 = SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (w
->vertical_scroll_bar
));
21640 return mouse_face_overwritten_p
;
21645 /* Redraw (parts) of all windows in the window tree rooted at W that
21646 intersect R. R contains frame pixel coordinates. Value is
21647 non-zero if the exposure overwrites mouse-face. */
21650 expose_window_tree (w
, r
)
21654 struct frame
*f
= XFRAME (w
->frame
);
21655 int mouse_face_overwritten_p
= 0;
21657 while (w
&& !FRAME_GARBAGED_P (f
))
21659 if (!NILP (w
->hchild
))
21660 mouse_face_overwritten_p
21661 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
21662 else if (!NILP (w
->vchild
))
21663 mouse_face_overwritten_p
21664 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
21666 mouse_face_overwritten_p
|= expose_window (w
, r
);
21668 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
21671 return mouse_face_overwritten_p
;
21676 Redisplay an exposed area of frame F. X and Y are the upper-left
21677 corner of the exposed rectangle. W and H are width and height of
21678 the exposed area. All are pixel values. W or H zero means redraw
21679 the entire frame. */
21682 expose_frame (f
, x
, y
, w
, h
)
21687 int mouse_face_overwritten_p
= 0;
21689 TRACE ((stderr
, "expose_frame "));
21691 /* No need to redraw if frame will be redrawn soon. */
21692 if (FRAME_GARBAGED_P (f
))
21694 TRACE ((stderr
, " garbaged\n"));
21699 /* MAC_TODO: this is a kludge, but if scroll bars are not activated
21700 or deactivated here, for unknown reasons, activated scroll bars
21701 are shown in deactivated frames in some instances. */
21702 if (f
== FRAME_MAC_DISPLAY_INFO (f
)->x_focus_frame
)
21703 activate_scroll_bars (f
);
21705 deactivate_scroll_bars (f
);
21708 /* If basic faces haven't been realized yet, there is no point in
21709 trying to redraw anything. This can happen when we get an expose
21710 event while Emacs is starting, e.g. by moving another window. */
21711 if (FRAME_FACE_CACHE (f
) == NULL
21712 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
21714 TRACE ((stderr
, " no faces\n"));
21718 if (w
== 0 || h
== 0)
21721 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
21722 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
21732 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
21733 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
21735 if (WINDOWP (f
->tool_bar_window
))
21736 mouse_face_overwritten_p
21737 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
21739 #ifdef HAVE_X_WINDOWS
21741 #ifndef USE_X_TOOLKIT
21742 if (WINDOWP (f
->menu_bar_window
))
21743 mouse_face_overwritten_p
21744 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
21745 #endif /* not USE_X_TOOLKIT */
21749 /* Some window managers support a focus-follows-mouse style with
21750 delayed raising of frames. Imagine a partially obscured frame,
21751 and moving the mouse into partially obscured mouse-face on that
21752 frame. The visible part of the mouse-face will be highlighted,
21753 then the WM raises the obscured frame. With at least one WM, KDE
21754 2.1, Emacs is not getting any event for the raising of the frame
21755 (even tried with SubstructureRedirectMask), only Expose events.
21756 These expose events will draw text normally, i.e. not
21757 highlighted. Which means we must redo the highlight here.
21758 Subsume it under ``we love X''. --gerd 2001-08-15 */
21759 /* Included in Windows version because Windows most likely does not
21760 do the right thing if any third party tool offers
21761 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
21762 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
21764 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21765 if (f
== dpyinfo
->mouse_face_mouse_frame
)
21767 int x
= dpyinfo
->mouse_face_mouse_x
;
21768 int y
= dpyinfo
->mouse_face_mouse_y
;
21769 clear_mouse_face (dpyinfo
);
21770 note_mouse_highlight (f
, x
, y
);
21777 Determine the intersection of two rectangles R1 and R2. Return
21778 the intersection in *RESULT. Value is non-zero if RESULT is not
21782 x_intersect_rectangles (r1
, r2
, result
)
21783 XRectangle
*r1
, *r2
, *result
;
21785 XRectangle
*left
, *right
;
21786 XRectangle
*upper
, *lower
;
21787 int intersection_p
= 0;
21789 /* Rearrange so that R1 is the left-most rectangle. */
21791 left
= r1
, right
= r2
;
21793 left
= r2
, right
= r1
;
21795 /* X0 of the intersection is right.x0, if this is inside R1,
21796 otherwise there is no intersection. */
21797 if (right
->x
<= left
->x
+ left
->width
)
21799 result
->x
= right
->x
;
21801 /* The right end of the intersection is the minimum of the
21802 the right ends of left and right. */
21803 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
21806 /* Same game for Y. */
21808 upper
= r1
, lower
= r2
;
21810 upper
= r2
, lower
= r1
;
21812 /* The upper end of the intersection is lower.y0, if this is inside
21813 of upper. Otherwise, there is no intersection. */
21814 if (lower
->y
<= upper
->y
+ upper
->height
)
21816 result
->y
= lower
->y
;
21818 /* The lower end of the intersection is the minimum of the lower
21819 ends of upper and lower. */
21820 result
->height
= (min (lower
->y
+ lower
->height
,
21821 upper
->y
+ upper
->height
)
21823 intersection_p
= 1;
21827 return intersection_p
;
21830 #endif /* HAVE_WINDOW_SYSTEM */
21833 /***********************************************************************
21835 ***********************************************************************/
21840 Vwith_echo_area_save_vector
= Qnil
;
21841 staticpro (&Vwith_echo_area_save_vector
);
21843 Vmessage_stack
= Qnil
;
21844 staticpro (&Vmessage_stack
);
21846 Qinhibit_redisplay
= intern ("inhibit-redisplay");
21847 staticpro (&Qinhibit_redisplay
);
21849 message_dolog_marker1
= Fmake_marker ();
21850 staticpro (&message_dolog_marker1
);
21851 message_dolog_marker2
= Fmake_marker ();
21852 staticpro (&message_dolog_marker2
);
21853 message_dolog_marker3
= Fmake_marker ();
21854 staticpro (&message_dolog_marker3
);
21857 defsubr (&Sdump_frame_glyph_matrix
);
21858 defsubr (&Sdump_glyph_matrix
);
21859 defsubr (&Sdump_glyph_row
);
21860 defsubr (&Sdump_tool_bar_row
);
21861 defsubr (&Strace_redisplay
);
21862 defsubr (&Strace_to_stderr
);
21864 #ifdef HAVE_WINDOW_SYSTEM
21865 defsubr (&Stool_bar_lines_needed
);
21866 defsubr (&Slookup_image_map
);
21868 defsubr (&Sformat_mode_line
);
21870 staticpro (&Qmenu_bar_update_hook
);
21871 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
21873 staticpro (&Qoverriding_terminal_local_map
);
21874 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
21876 staticpro (&Qoverriding_local_map
);
21877 Qoverriding_local_map
= intern ("overriding-local-map");
21879 staticpro (&Qwindow_scroll_functions
);
21880 Qwindow_scroll_functions
= intern ("window-scroll-functions");
21882 staticpro (&Qredisplay_end_trigger_functions
);
21883 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
21885 staticpro (&Qinhibit_point_motion_hooks
);
21886 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
21888 QCdata
= intern (":data");
21889 staticpro (&QCdata
);
21890 Qdisplay
= intern ("display");
21891 staticpro (&Qdisplay
);
21892 Qspace_width
= intern ("space-width");
21893 staticpro (&Qspace_width
);
21894 Qraise
= intern ("raise");
21895 staticpro (&Qraise
);
21896 Qspace
= intern ("space");
21897 staticpro (&Qspace
);
21898 Qmargin
= intern ("margin");
21899 staticpro (&Qmargin
);
21900 Qpointer
= intern ("pointer");
21901 staticpro (&Qpointer
);
21902 Qleft_margin
= intern ("left-margin");
21903 staticpro (&Qleft_margin
);
21904 Qright_margin
= intern ("right-margin");
21905 staticpro (&Qright_margin
);
21906 QCalign_to
= intern (":align-to");
21907 staticpro (&QCalign_to
);
21908 QCrelative_width
= intern (":relative-width");
21909 staticpro (&QCrelative_width
);
21910 QCrelative_height
= intern (":relative-height");
21911 staticpro (&QCrelative_height
);
21912 QCeval
= intern (":eval");
21913 staticpro (&QCeval
);
21914 QCpropertize
= intern (":propertize");
21915 staticpro (&QCpropertize
);
21916 QCfile
= intern (":file");
21917 staticpro (&QCfile
);
21918 Qfontified
= intern ("fontified");
21919 staticpro (&Qfontified
);
21920 Qfontification_functions
= intern ("fontification-functions");
21921 staticpro (&Qfontification_functions
);
21922 Qtrailing_whitespace
= intern ("trailing-whitespace");
21923 staticpro (&Qtrailing_whitespace
);
21924 Qimage
= intern ("image");
21925 staticpro (&Qimage
);
21926 QCmap
= intern (":map");
21927 staticpro (&QCmap
);
21928 QCpointer
= intern (":pointer");
21929 staticpro (&QCpointer
);
21930 Qrect
= intern ("rect");
21931 staticpro (&Qrect
);
21932 Qcircle
= intern ("circle");
21933 staticpro (&Qcircle
);
21934 Qpoly
= intern ("poly");
21935 staticpro (&Qpoly
);
21936 Qmessage_truncate_lines
= intern ("message-truncate-lines");
21937 staticpro (&Qmessage_truncate_lines
);
21938 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
21939 staticpro (&Qcursor_in_non_selected_windows
);
21940 Qgrow_only
= intern ("grow-only");
21941 staticpro (&Qgrow_only
);
21942 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
21943 staticpro (&Qinhibit_menubar_update
);
21944 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
21945 staticpro (&Qinhibit_eval_during_redisplay
);
21946 Qposition
= intern ("position");
21947 staticpro (&Qposition
);
21948 Qbuffer_position
= intern ("buffer-position");
21949 staticpro (&Qbuffer_position
);
21950 Qobject
= intern ("object");
21951 staticpro (&Qobject
);
21952 Qbar
= intern ("bar");
21954 Qhbar
= intern ("hbar");
21955 staticpro (&Qhbar
);
21956 Qbox
= intern ("box");
21958 Qhollow
= intern ("hollow");
21959 staticpro (&Qhollow
);
21960 Qhand
= intern ("hand");
21961 staticpro (&Qhand
);
21962 Qarrow
= intern ("arrow");
21963 staticpro (&Qarrow
);
21964 Qtext
= intern ("text");
21965 staticpro (&Qtext
);
21966 Qrisky_local_variable
= intern ("risky-local-variable");
21967 staticpro (&Qrisky_local_variable
);
21968 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
21969 staticpro (&Qinhibit_free_realized_faces
);
21971 list_of_error
= Fcons (intern ("error"), Qnil
);
21972 staticpro (&list_of_error
);
21974 last_arrow_position
= Qnil
;
21975 last_arrow_string
= Qnil
;
21976 staticpro (&last_arrow_position
);
21977 staticpro (&last_arrow_string
);
21979 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
21980 staticpro (&echo_buffer
[0]);
21981 staticpro (&echo_buffer
[1]);
21983 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
21984 staticpro (&echo_area_buffer
[0]);
21985 staticpro (&echo_area_buffer
[1]);
21987 Vmessages_buffer_name
= build_string ("*Messages*");
21988 staticpro (&Vmessages_buffer_name
);
21990 mode_line_proptrans_alist
= Qnil
;
21991 staticpro (&mode_line_proptrans_alist
);
21993 mode_line_string_list
= Qnil
;
21994 staticpro (&mode_line_string_list
);
21996 help_echo_string
= Qnil
;
21997 staticpro (&help_echo_string
);
21998 help_echo_object
= Qnil
;
21999 staticpro (&help_echo_object
);
22000 help_echo_window
= Qnil
;
22001 staticpro (&help_echo_window
);
22002 previous_help_echo_string
= Qnil
;
22003 staticpro (&previous_help_echo_string
);
22004 help_echo_pos
= -1;
22006 #ifdef HAVE_WINDOW_SYSTEM
22007 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
22008 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
22009 For example, if a block cursor is over a tab, it will be drawn as
22010 wide as that tab on the display. */);
22011 x_stretch_cursor_p
= 0;
22014 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
22015 doc
: /* *Non-nil means highlight trailing whitespace.
22016 The face used for trailing whitespace is `trailing-whitespace'. */);
22017 Vshow_trailing_whitespace
= Qnil
;
22019 #ifdef HAVE_WINDOW_SYSTEM
22020 DEFVAR_LISP ("overflow-newline-into-fringe", &Voverflow_newline_into_fringe
,
22021 doc
: /* *Non-nil means that newline may flow into the right fringe.
22022 This means that display lines which are exactly as wide as the window
22023 (not counting the final newline) will only occupy one screen line, by
22024 showing (or hiding) the final newline in the right fringe; when point
22025 is at the final newline, the cursor is shown in the right fringe.
22026 If nil, also continue lines which are exactly as wide as the window. */);
22027 Voverflow_newline_into_fringe
= Qt
;
22030 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
22031 doc
: /* *The pointer shape to show in void text areas.
22032 Nil means to show the text pointer. Other options are `arrow', `text',
22033 `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
22034 Vvoid_text_area_pointer
= Qarrow
;
22036 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
22037 doc
: /* Non-nil means don't actually do any redisplay.
22038 This is used for internal purposes. */);
22039 Vinhibit_redisplay
= Qnil
;
22041 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
22042 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
22043 Vglobal_mode_string
= Qnil
;
22045 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
22046 doc
: /* Marker for where to display an arrow on top of the buffer text.
22047 This must be the beginning of a line in order to work.
22048 See also `overlay-arrow-string'. */);
22049 Voverlay_arrow_position
= Qnil
;
22051 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
22052 doc
: /* String to display as an arrow. See also `overlay-arrow-position'. */);
22053 Voverlay_arrow_string
= Qnil
;
22055 DEFVAR_INT ("scroll-step", &scroll_step
,
22056 doc
: /* *The number of lines to try scrolling a window by when point moves out.
22057 If that fails to bring point back on frame, point is centered instead.
22058 If this is zero, point is always centered after it moves off frame.
22059 If you want scrolling to always be a line at a time, you should set
22060 `scroll-conservatively' to a large value rather than set this to 1. */);
22062 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
22063 doc
: /* *Scroll up to this many lines, to bring point back on screen.
22064 A value of zero means to scroll the text to center point vertically
22065 in the window. */);
22066 scroll_conservatively
= 0;
22068 DEFVAR_INT ("scroll-margin", &scroll_margin
,
22069 doc
: /* *Number of lines of margin at the top and bottom of a window.
22070 Recenter the window whenever point gets within this many lines
22071 of the top or bottom of the window. */);
22074 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
22075 doc
: /* Pixels per inch on current display.
22076 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
22077 Vdisplay_pixels_per_inch
= make_float (72.0);
22080 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
22083 DEFVAR_BOOL ("truncate-partial-width-windows",
22084 &truncate_partial_width_windows
,
22085 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
22086 truncate_partial_width_windows
= 1;
22088 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
22089 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
22090 Any other value means to use the appropriate face, `mode-line',
22091 `header-line', or `menu' respectively. */);
22092 mode_line_inverse_video
= 1;
22094 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
22095 doc
: /* *Maximum buffer size for which line number should be displayed.
22096 If the buffer is bigger than this, the line number does not appear
22097 in the mode line. A value of nil means no limit. */);
22098 Vline_number_display_limit
= Qnil
;
22100 DEFVAR_INT ("line-number-display-limit-width",
22101 &line_number_display_limit_width
,
22102 doc
: /* *Maximum line width (in characters) for line number display.
22103 If the average length of the lines near point is bigger than this, then the
22104 line number may be omitted from the mode line. */);
22105 line_number_display_limit_width
= 200;
22107 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
22108 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
22109 highlight_nonselected_windows
= 0;
22111 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
22112 doc
: /* Non-nil if more than one frame is visible on this display.
22113 Minibuffer-only frames don't count, but iconified frames do.
22114 This variable is not guaranteed to be accurate except while processing
22115 `frame-title-format' and `icon-title-format'. */);
22117 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
22118 doc
: /* Template for displaying the title bar of visible frames.
22119 \(Assuming the window manager supports this feature.)
22120 This variable has the same structure as `mode-line-format' (which see),
22121 and is used only on frames for which no explicit name has been set
22122 \(see `modify-frame-parameters'). */);
22124 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
22125 doc
: /* Template for displaying the title bar of an iconified frame.
22126 \(Assuming the window manager supports this feature.)
22127 This variable has the same structure as `mode-line-format' (which see),
22128 and is used only on frames for which no explicit name has been set
22129 \(see `modify-frame-parameters'). */);
22131 = Vframe_title_format
22132 = Fcons (intern ("multiple-frames"),
22133 Fcons (build_string ("%b"),
22134 Fcons (Fcons (empty_string
,
22135 Fcons (intern ("invocation-name"),
22136 Fcons (build_string ("@"),
22137 Fcons (intern ("system-name"),
22141 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
22142 doc
: /* Maximum number of lines to keep in the message log buffer.
22143 If nil, disable message logging. If t, log messages but don't truncate
22144 the buffer when it becomes large. */);
22145 Vmessage_log_max
= make_number (50);
22147 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
22148 doc
: /* Functions called before redisplay, if window sizes have changed.
22149 The value should be a list of functions that take one argument.
22150 Just before redisplay, for each frame, if any of its windows have changed
22151 size since the last redisplay, or have been split or deleted,
22152 all the functions in the list are called, with the frame as argument. */);
22153 Vwindow_size_change_functions
= Qnil
;
22155 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
22156 doc
: /* List of Functions to call before redisplaying a window with scrolling.
22157 Each function is called with two arguments, the window
22158 and its new display-start position. Note that the value of `window-end'
22159 is not valid when these functions are called. */);
22160 Vwindow_scroll_functions
= Qnil
;
22162 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
22163 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
22164 mouse_autoselect_window
= 0;
22166 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
22167 doc
: /* *Non-nil means automatically resize tool-bars.
22168 This increases a tool-bar's height if not all tool-bar items are visible.
22169 It decreases a tool-bar's height when it would display blank lines
22171 auto_resize_tool_bars_p
= 1;
22173 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
22174 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
22175 auto_raise_tool_bar_buttons_p
= 1;
22177 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
22178 doc
: /* *Margin around tool-bar buttons in pixels.
22179 If an integer, use that for both horizontal and vertical margins.
22180 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
22181 HORZ specifying the horizontal margin, and VERT specifying the
22182 vertical margin. */);
22183 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
22185 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
22186 doc
: /* *Relief thickness of tool-bar buttons. */);
22187 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
22189 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
22190 doc
: /* List of functions to call to fontify regions of text.
22191 Each function is called with one argument POS. Functions must
22192 fontify a region starting at POS in the current buffer, and give
22193 fontified regions the property `fontified'. */);
22194 Vfontification_functions
= Qnil
;
22195 Fmake_variable_buffer_local (Qfontification_functions
);
22197 DEFVAR_BOOL ("unibyte-display-via-language-environment",
22198 &unibyte_display_via_language_environment
,
22199 doc
: /* *Non-nil means display unibyte text according to language environment.
22200 Specifically this means that unibyte non-ASCII characters
22201 are displayed by converting them to the equivalent multibyte characters
22202 according to the current language environment. As a result, they are
22203 displayed according to the current fontset. */);
22204 unibyte_display_via_language_environment
= 0;
22206 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
22207 doc
: /* *Maximum height for resizing mini-windows.
22208 If a float, it specifies a fraction of the mini-window frame's height.
22209 If an integer, it specifies a number of lines. */);
22210 Vmax_mini_window_height
= make_float (0.25);
22212 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
22213 doc
: /* *How to resize mini-windows.
22214 A value of nil means don't automatically resize mini-windows.
22215 A value of t means resize them to fit the text displayed in them.
22216 A value of `grow-only', the default, means let mini-windows grow
22217 only, until their display becomes empty, at which point the windows
22218 go back to their normal size. */);
22219 Vresize_mini_windows
= Qgrow_only
;
22221 DEFVAR_LISP ("cursor-in-non-selected-windows",
22222 &Vcursor_in_non_selected_windows
,
22223 doc
: /* *Cursor type to display in non-selected windows.
22224 t means to use hollow box cursor. See `cursor-type' for other values. */);
22225 Vcursor_in_non_selected_windows
= Qt
;
22227 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
22228 doc
: /* Alist specifying how to blink the cursor off.
22229 Each element has the form (ON-STATE . OFF-STATE). Whenever the
22230 `cursor-type' frame-parameter or variable equals ON-STATE,
22231 comparing using `equal', Emacs uses OFF-STATE to specify
22232 how to blink it off. */);
22233 Vblink_cursor_alist
= Qnil
;
22235 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
22236 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
22237 automatic_hscrolling_p
= 1;
22239 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
22240 doc
: /* *How many columns away from the window edge point is allowed to get
22241 before automatic hscrolling will horizontally scroll the window. */);
22242 hscroll_margin
= 5;
22244 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
22245 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
22246 When point is less than `automatic-hscroll-margin' columns from the window
22247 edge, automatic hscrolling will scroll the window by the amount of columns
22248 determined by this variable. If its value is a positive integer, scroll that
22249 many columns. If it's a positive floating-point number, it specifies the
22250 fraction of the window's width to scroll. If it's nil or zero, point will be
22251 centered horizontally after the scroll. Any other value, including negative
22252 numbers, are treated as if the value were zero.
22254 Automatic hscrolling always moves point outside the scroll margin, so if
22255 point was more than scroll step columns inside the margin, the window will
22256 scroll more than the value given by the scroll step.
22258 Note that the lower bound for automatic hscrolling specified by `scroll-left'
22259 and `scroll-right' overrides this variable's effect. */);
22260 Vhscroll_step
= make_number (0);
22262 DEFVAR_LISP ("image-types", &Vimage_types
,
22263 doc
: /* List of supported image types.
22264 Each element of the list is a symbol for a supported image type. */);
22265 Vimage_types
= Qnil
;
22267 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
22268 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
22269 Bind this around calls to `message' to let it take effect. */);
22270 message_truncate_lines
= 0;
22272 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
22273 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
22274 Can be used to update submenus whose contents should vary. */);
22275 Vmenu_bar_update_hook
= Qnil
;
22277 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
22278 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
22279 inhibit_menubar_update
= 0;
22281 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
22282 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
22283 inhibit_eval_during_redisplay
= 0;
22285 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
22286 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
22287 inhibit_free_realized_faces
= 0;
22290 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
22291 doc
: /* Inhibit try_window_id display optimization. */);
22292 inhibit_try_window_id
= 0;
22294 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
22295 doc
: /* Inhibit try_window_reusing display optimization. */);
22296 inhibit_try_window_reusing
= 0;
22298 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
22299 doc
: /* Inhibit try_cursor_movement display optimization. */);
22300 inhibit_try_cursor_movement
= 0;
22301 #endif /* GLYPH_DEBUG */
22305 /* Initialize this module when Emacs starts. */
22310 Lisp_Object root_window
;
22311 struct window
*mini_w
;
22313 current_header_line_height
= current_mode_line_height
= -1;
22315 CHARPOS (this_line_start_pos
) = 0;
22317 mini_w
= XWINDOW (minibuf_window
);
22318 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
22320 if (!noninteractive
)
22322 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
22325 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
22326 set_window_height (root_window
,
22327 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
22329 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
22330 set_window_height (minibuf_window
, 1, 0);
22332 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
22333 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
22335 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
22336 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
22337 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
22339 /* The default ellipsis glyphs `...'. */
22340 for (i
= 0; i
< 3; ++i
)
22341 default_invis_vector
[i
] = make_number ('.');
22345 /* Allocate the buffer for frame titles.
22346 Also used for `format-mode-line'. */
22348 frame_title_buf
= (char *) xmalloc (size
);
22349 frame_title_buf_end
= frame_title_buf
+ size
;
22350 frame_title_ptr
= NULL
;
22353 help_echo_showing_p
= 0;
22357 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
22358 (do not change this comment) */