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
;
305 Lisp_Object Qmargin
, Qpointer
;
306 extern Lisp_Object Qheight
;
307 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
308 extern Lisp_Object Qscroll_bar
;
310 /* Non-nil means highlight trailing whitespace. */
312 Lisp_Object Vshow_trailing_whitespace
;
314 #ifdef HAVE_WINDOW_SYSTEM
315 extern Lisp_Object Voverflow_newline_into_fringe
;
317 /* Test if overflow newline into fringe. Called with iterator IT
318 at or past right window margin, and with IT->current_x set. */
320 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
321 (!NILP (Voverflow_newline_into_fringe) \
322 && FRAME_WINDOW_P (it->f) \
323 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
324 && it->current_x == it->last_visible_x)
326 #endif /* HAVE_WINDOW_SYSTEM */
328 /* Non-nil means show the text cursor in void text areas
329 i.e. in blank areas after eol and eob. This used to be
330 the default in 21.3. */
332 Lisp_Object Vvoid_text_area_pointer
;
334 /* Name of the face used to highlight trailing whitespace. */
336 Lisp_Object Qtrailing_whitespace
;
338 /* The symbol `image' which is the car of the lists used to represent
343 /* The image map types. */
344 Lisp_Object QCmap
, QCpointer
;
345 Lisp_Object Qrect
, Qcircle
, Qpoly
;
347 /* Non-zero means print newline to stdout before next mini-buffer
350 int noninteractive_need_newline
;
352 /* Non-zero means print newline to message log before next message. */
354 static int message_log_need_newline
;
356 /* Three markers that message_dolog uses.
357 It could allocate them itself, but that causes trouble
358 in handling memory-full errors. */
359 static Lisp_Object message_dolog_marker1
;
360 static Lisp_Object message_dolog_marker2
;
361 static Lisp_Object message_dolog_marker3
;
363 /* The buffer position of the first character appearing entirely or
364 partially on the line of the selected window which contains the
365 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
366 redisplay optimization in redisplay_internal. */
368 static struct text_pos this_line_start_pos
;
370 /* Number of characters past the end of the line above, including the
371 terminating newline. */
373 static struct text_pos this_line_end_pos
;
375 /* The vertical positions and the height of this line. */
377 static int this_line_vpos
;
378 static int this_line_y
;
379 static int this_line_pixel_height
;
381 /* X position at which this display line starts. Usually zero;
382 negative if first character is partially visible. */
384 static int this_line_start_x
;
386 /* Buffer that this_line_.* variables are referring to. */
388 static struct buffer
*this_line_buffer
;
390 /* Nonzero means truncate lines in all windows less wide than the
393 int truncate_partial_width_windows
;
395 /* A flag to control how to display unibyte 8-bit character. */
397 int unibyte_display_via_language_environment
;
399 /* Nonzero means we have more than one non-mini-buffer-only frame.
400 Not guaranteed to be accurate except while parsing
401 frame-title-format. */
405 Lisp_Object Vglobal_mode_string
;
408 /* List of variables (symbols) which hold markers for overlay arrows.
409 The symbols on this list are examined during redisplay to determine
410 where to display overlay arrows. */
412 Lisp_Object Voverlay_arrow_variable_list
;
414 /* Marker for where to display an arrow on top of the buffer text. */
416 Lisp_Object Voverlay_arrow_position
;
418 /* String to display for the arrow. Only used on terminal frames. */
420 Lisp_Object Voverlay_arrow_string
;
422 /* Values of those variables at last redisplay are stored as
423 properties on `overlay-arrow-position' symbol. However, if
424 Voverlay_arrow_position is a marker, last-arrow-position is its
425 numerical position. */
427 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
429 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
430 properties on a symbol in overlay-arrow-variable-list. */
432 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
434 /* Like mode-line-format, but for the title bar on a visible frame. */
436 Lisp_Object Vframe_title_format
;
438 /* Like mode-line-format, but for the title bar on an iconified frame. */
440 Lisp_Object Vicon_title_format
;
442 /* List of functions to call when a window's size changes. These
443 functions get one arg, a frame on which one or more windows' sizes
446 static Lisp_Object Vwindow_size_change_functions
;
448 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
450 /* Nonzero if overlay arrow has been displayed once in this window. */
452 static int overlay_arrow_seen
;
454 /* Nonzero means highlight the region even in nonselected windows. */
456 int highlight_nonselected_windows
;
458 /* If cursor motion alone moves point off frame, try scrolling this
459 many lines up or down if that will bring it back. */
461 static EMACS_INT scroll_step
;
463 /* Nonzero means scroll just far enough to bring point back on the
464 screen, when appropriate. */
466 static EMACS_INT scroll_conservatively
;
468 /* Recenter the window whenever point gets within this many lines of
469 the top or bottom of the window. This value is translated into a
470 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
471 that there is really a fixed pixel height scroll margin. */
473 EMACS_INT scroll_margin
;
475 /* Number of windows showing the buffer of the selected window (or
476 another buffer with the same base buffer). keyboard.c refers to
481 /* Vector containing glyphs for an ellipsis `...'. */
483 static Lisp_Object default_invis_vector
[3];
485 /* Zero means display the mode-line/header-line/menu-bar in the default face
486 (this slightly odd definition is for compatibility with previous versions
487 of emacs), non-zero means display them using their respective faces.
489 This variable is deprecated. */
491 int mode_line_inverse_video
;
493 /* Prompt to display in front of the mini-buffer contents. */
495 Lisp_Object minibuf_prompt
;
497 /* Width of current mini-buffer prompt. Only set after display_line
498 of the line that contains the prompt. */
500 int minibuf_prompt_width
;
502 /* This is the window where the echo area message was displayed. It
503 is always a mini-buffer window, but it may not be the same window
504 currently active as a mini-buffer. */
506 Lisp_Object echo_area_window
;
508 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
509 pushes the current message and the value of
510 message_enable_multibyte on the stack, the function restore_message
511 pops the stack and displays MESSAGE again. */
513 Lisp_Object Vmessage_stack
;
515 /* Nonzero means multibyte characters were enabled when the echo area
516 message was specified. */
518 int message_enable_multibyte
;
520 /* Nonzero if we should redraw the mode lines on the next redisplay. */
522 int update_mode_lines
;
524 /* Nonzero if window sizes or contents have changed since last
525 redisplay that finished. */
527 int windows_or_buffers_changed
;
529 /* Nonzero means a frame's cursor type has been changed. */
531 int cursor_type_changed
;
533 /* Nonzero after display_mode_line if %l was used and it displayed a
536 int line_number_displayed
;
538 /* Maximum buffer size for which to display line numbers. */
540 Lisp_Object Vline_number_display_limit
;
542 /* Line width to consider when repositioning for line number display. */
544 static EMACS_INT line_number_display_limit_width
;
546 /* Number of lines to keep in the message log buffer. t means
547 infinite. nil means don't log at all. */
549 Lisp_Object Vmessage_log_max
;
551 /* The name of the *Messages* buffer, a string. */
553 static Lisp_Object Vmessages_buffer_name
;
555 /* Current, index 0, and last displayed echo area message. Either
556 buffers from echo_buffers, or nil to indicate no message. */
558 Lisp_Object echo_area_buffer
[2];
560 /* The buffers referenced from echo_area_buffer. */
562 static Lisp_Object echo_buffer
[2];
564 /* A vector saved used in with_area_buffer to reduce consing. */
566 static Lisp_Object Vwith_echo_area_save_vector
;
568 /* Non-zero means display_echo_area should display the last echo area
569 message again. Set by redisplay_preserve_echo_area. */
571 static int display_last_displayed_message_p
;
573 /* Nonzero if echo area is being used by print; zero if being used by
576 int message_buf_print
;
578 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
580 Lisp_Object Qinhibit_menubar_update
;
581 int inhibit_menubar_update
;
583 /* Maximum height for resizing mini-windows. Either a float
584 specifying a fraction of the available height, or an integer
585 specifying a number of lines. */
587 Lisp_Object Vmax_mini_window_height
;
589 /* Non-zero means messages should be displayed with truncated
590 lines instead of being continued. */
592 int message_truncate_lines
;
593 Lisp_Object Qmessage_truncate_lines
;
595 /* Set to 1 in clear_message to make redisplay_internal aware
596 of an emptied echo area. */
598 static int message_cleared_p
;
600 /* Non-zero means we want a hollow cursor in windows that are not
601 selected. Zero means there's no cursor in such windows. */
603 Lisp_Object Vcursor_in_non_selected_windows
;
604 Lisp_Object Qcursor_in_non_selected_windows
;
606 /* How to blink the default frame cursor off. */
607 Lisp_Object Vblink_cursor_alist
;
609 /* A scratch glyph row with contents used for generating truncation
610 glyphs. Also used in direct_output_for_insert. */
612 #define MAX_SCRATCH_GLYPHS 100
613 struct glyph_row scratch_glyph_row
;
614 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
616 /* Ascent and height of the last line processed by move_it_to. */
618 static int last_max_ascent
, last_height
;
620 /* Non-zero if there's a help-echo in the echo area. */
622 int help_echo_showing_p
;
624 /* If >= 0, computed, exact values of mode-line and header-line height
625 to use in the macros CURRENT_MODE_LINE_HEIGHT and
626 CURRENT_HEADER_LINE_HEIGHT. */
628 int current_mode_line_height
, current_header_line_height
;
630 /* The maximum distance to look ahead for text properties. Values
631 that are too small let us call compute_char_face and similar
632 functions too often which is expensive. Values that are too large
633 let us call compute_char_face and alike too often because we
634 might not be interested in text properties that far away. */
636 #define TEXT_PROP_DISTANCE_LIMIT 100
640 /* Variables to turn off display optimizations from Lisp. */
642 int inhibit_try_window_id
, inhibit_try_window_reusing
;
643 int inhibit_try_cursor_movement
;
645 /* Non-zero means print traces of redisplay if compiled with
648 int trace_redisplay_p
;
650 #endif /* GLYPH_DEBUG */
652 #ifdef DEBUG_TRACE_MOVE
653 /* Non-zero means trace with TRACE_MOVE to stderr. */
656 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
658 #define TRACE_MOVE(x) (void) 0
661 /* Non-zero means automatically scroll windows horizontally to make
664 int automatic_hscrolling_p
;
666 /* How close to the margin can point get before the window is scrolled
668 EMACS_INT hscroll_margin
;
670 /* How much to scroll horizontally when point is inside the above margin. */
671 Lisp_Object Vhscroll_step
;
673 /* A list of symbols, one for each supported image type. */
675 Lisp_Object Vimage_types
;
677 /* The variable `resize-mini-windows'. If nil, don't resize
678 mini-windows. If t, always resize them to fit the text they
679 display. If `grow-only', let mini-windows grow only until they
682 Lisp_Object Vresize_mini_windows
;
684 /* Buffer being redisplayed -- for redisplay_window_error. */
686 struct buffer
*displayed_buffer
;
688 /* Value returned from text property handlers (see below). */
693 HANDLED_RECOMPUTE_PROPS
,
694 HANDLED_OVERLAY_STRING_CONSUMED
,
698 /* A description of text properties that redisplay is interested
703 /* The name of the property. */
706 /* A unique index for the property. */
709 /* A handler function called to set up iterator IT from the property
710 at IT's current position. Value is used to steer handle_stop. */
711 enum prop_handled (*handler
) P_ ((struct it
*it
));
714 static enum prop_handled handle_face_prop
P_ ((struct it
*));
715 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
716 static enum prop_handled handle_display_prop
P_ ((struct it
*));
717 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
718 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
719 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
721 /* Properties handled by iterators. */
723 static struct props it_props
[] =
725 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
726 /* Handle `face' before `display' because some sub-properties of
727 `display' need to know the face. */
728 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
729 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
730 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
731 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
735 /* Value is the position described by X. If X is a marker, value is
736 the marker_position of X. Otherwise, value is X. */
738 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
740 /* Enumeration returned by some move_it_.* functions internally. */
744 /* Not used. Undefined value. */
747 /* Move ended at the requested buffer position or ZV. */
748 MOVE_POS_MATCH_OR_ZV
,
750 /* Move ended at the requested X pixel position. */
753 /* Move within a line ended at the end of a line that must be
757 /* Move within a line ended at the end of a line that would
758 be displayed truncated. */
761 /* Move within a line ended at a line end. */
765 /* This counter is used to clear the face cache every once in a while
766 in redisplay_internal. It is incremented for each redisplay.
767 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
770 #define CLEAR_FACE_CACHE_COUNT 500
771 static int clear_face_cache_count
;
773 /* Record the previous terminal frame we displayed. */
775 static struct frame
*previous_terminal_frame
;
777 /* Non-zero while redisplay_internal is in progress. */
781 /* Non-zero means don't free realized faces. Bound while freeing
782 realized faces is dangerous because glyph matrices might still
785 int inhibit_free_realized_faces
;
786 Lisp_Object Qinhibit_free_realized_faces
;
788 /* If a string, XTread_socket generates an event to display that string.
789 (The display is done in read_char.) */
791 Lisp_Object help_echo_string
;
792 Lisp_Object help_echo_window
;
793 Lisp_Object help_echo_object
;
796 /* Temporary variable for XTread_socket. */
798 Lisp_Object previous_help_echo_string
;
802 /* Function prototypes. */
804 static void setup_for_ellipsis
P_ ((struct it
*));
805 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
806 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
807 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
808 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
809 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
810 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
813 static int invisible_text_between_p
P_ ((struct it
*, int, int));
816 static int next_element_from_ellipsis
P_ ((struct it
*));
817 static void pint2str
P_ ((char *, int, int));
818 static void pint2hrstr
P_ ((char *, int, int));
819 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
821 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
822 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
823 static void store_frame_title_char
P_ ((char));
824 static int store_frame_title
P_ ((const unsigned char *, int, int));
825 static void x_consider_frame_title
P_ ((Lisp_Object
));
826 static void handle_stop
P_ ((struct it
*));
827 static int tool_bar_lines_needed
P_ ((struct frame
*));
828 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
829 static void ensure_echo_area_buffers
P_ ((void));
830 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
831 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
832 static int with_echo_area_buffer
P_ ((struct window
*, int,
833 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
834 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
835 static void clear_garbaged_frames
P_ ((void));
836 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
837 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
838 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
839 static int display_echo_area
P_ ((struct window
*));
840 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
841 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
842 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
843 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
844 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
846 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
847 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
848 static void insert_left_trunc_glyphs
P_ ((struct it
*));
849 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
851 static void extend_face_to_end_of_line
P_ ((struct it
*));
852 static int append_space
P_ ((struct it
*, int));
853 static int make_cursor_line_fully_visible
P_ ((struct window
*, int));
854 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
855 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
856 static int trailing_whitespace_p
P_ ((int));
857 static int message_log_check_duplicate
P_ ((int, int, int, int));
858 static void push_it
P_ ((struct it
*));
859 static void pop_it
P_ ((struct it
*));
860 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
861 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
862 static void redisplay_internal
P_ ((int));
863 static int echo_area_display
P_ ((int));
864 static void redisplay_windows
P_ ((Lisp_Object
));
865 static void redisplay_window
P_ ((Lisp_Object
, int));
866 static Lisp_Object
redisplay_window_error ();
867 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
868 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
869 static void update_menu_bar
P_ ((struct frame
*, int));
870 static int try_window_reusing_current_matrix
P_ ((struct window
*));
871 static int try_window_id
P_ ((struct window
*));
872 static int display_line
P_ ((struct it
*));
873 static int display_mode_lines
P_ ((struct window
*));
874 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
875 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
876 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
877 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
878 static void display_menu_bar
P_ ((struct window
*));
879 static int display_count_lines
P_ ((int, int, int, int, int *));
880 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
881 int, int, struct it
*, int, int, int, int));
882 static void compute_line_metrics
P_ ((struct it
*));
883 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
884 static int get_overlay_strings
P_ ((struct it
*, int));
885 static void next_overlay_string
P_ ((struct it
*));
886 static void reseat
P_ ((struct it
*, struct text_pos
, int));
887 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
888 static void back_to_previous_visible_line_start
P_ ((struct it
*));
889 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
890 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
891 static int next_element_from_display_vector
P_ ((struct it
*));
892 static int next_element_from_string
P_ ((struct it
*));
893 static int next_element_from_c_string
P_ ((struct it
*));
894 static int next_element_from_buffer
P_ ((struct it
*));
895 static int next_element_from_composition
P_ ((struct it
*));
896 static int next_element_from_image
P_ ((struct it
*));
897 static int next_element_from_stretch
P_ ((struct it
*));
898 static void load_overlay_strings
P_ ((struct it
*, int));
899 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
900 struct display_pos
*));
901 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
902 Lisp_Object
, int, int, int, int));
903 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
905 void move_it_vertically_backward
P_ ((struct it
*, int));
906 static void init_to_row_start
P_ ((struct it
*, struct window
*,
907 struct glyph_row
*));
908 static int init_to_row_end
P_ ((struct it
*, struct window
*,
909 struct glyph_row
*));
910 static void back_to_previous_line_start
P_ ((struct it
*));
911 static int forward_to_next_line_start
P_ ((struct it
*, int *));
912 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
914 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
915 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
916 static int number_of_chars
P_ ((unsigned char *, int));
917 static void compute_stop_pos
P_ ((struct it
*));
918 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
920 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
921 static int next_overlay_change
P_ ((int));
922 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
923 Lisp_Object
, struct text_pos
*,
925 static int underlying_face_id
P_ ((struct it
*));
926 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
929 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
930 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
932 #ifdef HAVE_WINDOW_SYSTEM
934 static void update_tool_bar
P_ ((struct frame
*, int));
935 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
936 static int redisplay_tool_bar
P_ ((struct frame
*));
937 static void display_tool_bar_line
P_ ((struct it
*));
938 static void notice_overwritten_cursor
P_ ((struct window
*,
940 int, int, int, int));
944 #endif /* HAVE_WINDOW_SYSTEM */
947 /***********************************************************************
948 Window display dimensions
949 ***********************************************************************/
951 /* Return the bottom boundary y-position for text lines in window W.
952 This is the first y position at which a line cannot start.
953 It is relative to the top of the window.
955 This is the height of W minus the height of a mode line, if any. */
958 window_text_bottom_y (w
)
961 int height
= WINDOW_TOTAL_HEIGHT (w
);
963 if (WINDOW_WANTS_MODELINE_P (w
))
964 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
968 /* Return the pixel width of display area AREA of window W. AREA < 0
969 means return the total width of W, not including fringes to
970 the left and right of the window. */
973 window_box_width (w
, area
)
977 int cols
= XFASTINT (w
->total_cols
);
980 if (!w
->pseudo_window_p
)
982 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
984 if (area
== TEXT_AREA
)
986 if (INTEGERP (w
->left_margin_cols
))
987 cols
-= XFASTINT (w
->left_margin_cols
);
988 if (INTEGERP (w
->right_margin_cols
))
989 cols
-= XFASTINT (w
->right_margin_cols
);
990 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
992 else if (area
== LEFT_MARGIN_AREA
)
994 cols
= (INTEGERP (w
->left_margin_cols
)
995 ? XFASTINT (w
->left_margin_cols
) : 0);
998 else if (area
== RIGHT_MARGIN_AREA
)
1000 cols
= (INTEGERP (w
->right_margin_cols
)
1001 ? XFASTINT (w
->right_margin_cols
) : 0);
1006 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1010 /* Return the pixel height of the display area of window W, not
1011 including mode lines of W, if any. */
1014 window_box_height (w
)
1017 struct frame
*f
= XFRAME (w
->frame
);
1018 int height
= WINDOW_TOTAL_HEIGHT (w
);
1020 xassert (height
>= 0);
1022 /* Note: the code below that determines the mode-line/header-line
1023 height is essentially the same as that contained in the macro
1024 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1025 the appropriate glyph row has its `mode_line_p' flag set,
1026 and if it doesn't, uses estimate_mode_line_height instead. */
1028 if (WINDOW_WANTS_MODELINE_P (w
))
1030 struct glyph_row
*ml_row
1031 = (w
->current_matrix
&& w
->current_matrix
->rows
1032 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1034 if (ml_row
&& ml_row
->mode_line_p
)
1035 height
-= ml_row
->height
;
1037 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1040 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1042 struct glyph_row
*hl_row
1043 = (w
->current_matrix
&& w
->current_matrix
->rows
1044 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1046 if (hl_row
&& hl_row
->mode_line_p
)
1047 height
-= hl_row
->height
;
1049 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1052 /* With a very small font and a mode-line that's taller than
1053 default, we might end up with a negative height. */
1054 return max (0, height
);
1057 /* Return the window-relative coordinate of the left edge of display
1058 area AREA of window W. AREA < 0 means return the left edge of the
1059 whole window, to the right of the left fringe of W. */
1062 window_box_left_offset (w
, area
)
1068 if (w
->pseudo_window_p
)
1071 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1073 if (area
== TEXT_AREA
)
1074 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1075 + window_box_width (w
, LEFT_MARGIN_AREA
));
1076 else if (area
== RIGHT_MARGIN_AREA
)
1077 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1078 + window_box_width (w
, LEFT_MARGIN_AREA
)
1079 + window_box_width (w
, TEXT_AREA
)
1080 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1082 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1083 else if (area
== LEFT_MARGIN_AREA
1084 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1085 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1091 /* Return the window-relative coordinate of the right edge of display
1092 area AREA of window W. AREA < 0 means return the left edge of the
1093 whole window, to the left of the right fringe of W. */
1096 window_box_right_offset (w
, area
)
1100 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1103 /* Return the frame-relative coordinate of the left edge of display
1104 area AREA of window W. AREA < 0 means return the left edge of the
1105 whole window, to the right of the left fringe of W. */
1108 window_box_left (w
, area
)
1112 struct frame
*f
= XFRAME (w
->frame
);
1115 if (w
->pseudo_window_p
)
1116 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1118 x
= (WINDOW_LEFT_EDGE_X (w
)
1119 + window_box_left_offset (w
, area
));
1125 /* Return the frame-relative coordinate of the right edge of display
1126 area AREA of window W. AREA < 0 means return the left edge of the
1127 whole window, to the left of the right fringe of W. */
1130 window_box_right (w
, area
)
1134 return window_box_left (w
, area
) + window_box_width (w
, area
);
1137 /* Get the bounding box of the display area AREA of window W, without
1138 mode lines, in frame-relative coordinates. AREA < 0 means the
1139 whole window, not including the left and right fringes of
1140 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1141 coordinates of the upper-left corner of the box. Return in
1142 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1145 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1148 int *box_x
, *box_y
, *box_width
, *box_height
;
1151 *box_width
= window_box_width (w
, area
);
1153 *box_height
= window_box_height (w
);
1155 *box_x
= window_box_left (w
, area
);
1158 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1159 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1160 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1165 /* Get the bounding box of the display area AREA of window W, without
1166 mode lines. AREA < 0 means the whole window, not including the
1167 left and right fringe of the window. Return in *TOP_LEFT_X
1168 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1169 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1170 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1174 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1175 bottom_right_x
, bottom_right_y
)
1178 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1180 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1182 *bottom_right_x
+= *top_left_x
;
1183 *bottom_right_y
+= *top_left_y
;
1188 /***********************************************************************
1190 ***********************************************************************/
1192 /* Return the bottom y-position of the line the iterator IT is in.
1193 This can modify IT's settings. */
1199 int line_height
= it
->max_ascent
+ it
->max_descent
;
1200 int line_top_y
= it
->current_y
;
1202 if (line_height
== 0)
1205 line_height
= last_height
;
1206 else if (IT_CHARPOS (*it
) < ZV
)
1208 move_it_by_lines (it
, 1, 1);
1209 line_height
= (it
->max_ascent
|| it
->max_descent
1210 ? it
->max_ascent
+ it
->max_descent
1215 struct glyph_row
*row
= it
->glyph_row
;
1217 /* Use the default character height. */
1218 it
->glyph_row
= NULL
;
1219 it
->what
= IT_CHARACTER
;
1222 PRODUCE_GLYPHS (it
);
1223 line_height
= it
->ascent
+ it
->descent
;
1224 it
->glyph_row
= row
;
1228 return line_top_y
+ line_height
;
1232 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1233 1 if POS is visible and the line containing POS is fully visible.
1234 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1235 and header-lines heights. */
1238 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
1240 int charpos
, *fully
, exact_mode_line_heights_p
;
1243 struct text_pos top
;
1245 struct buffer
*old_buffer
= NULL
;
1247 if (XBUFFER (w
->buffer
) != current_buffer
)
1249 old_buffer
= current_buffer
;
1250 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1253 *fully
= visible_p
= 0;
1254 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1256 /* Compute exact mode line heights, if requested. */
1257 if (exact_mode_line_heights_p
)
1259 if (WINDOW_WANTS_MODELINE_P (w
))
1260 current_mode_line_height
1261 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1262 current_buffer
->mode_line_format
);
1264 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1265 current_header_line_height
1266 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1267 current_buffer
->header_line_format
);
1270 start_display (&it
, w
, top
);
1271 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1272 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1274 /* Note that we may overshoot because of invisible text. */
1275 if (IT_CHARPOS (it
) >= charpos
)
1277 int top_y
= it
.current_y
;
1278 int bottom_y
= line_bottom_y (&it
);
1279 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1281 if (top_y
< window_top_y
)
1282 visible_p
= bottom_y
> window_top_y
;
1283 else if (top_y
< it
.last_visible_y
)
1286 *fully
= bottom_y
<= it
.last_visible_y
;
1289 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1291 move_it_by_lines (&it
, 1, 0);
1292 if (charpos
< IT_CHARPOS (it
))
1300 set_buffer_internal_1 (old_buffer
);
1302 current_header_line_height
= current_mode_line_height
= -1;
1307 /* Return the next character from STR which is MAXLEN bytes long.
1308 Return in *LEN the length of the character. This is like
1309 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1310 we find one, we return a `?', but with the length of the invalid
1314 string_char_and_length (str
, maxlen
, len
)
1315 const unsigned char *str
;
1320 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1321 if (!CHAR_VALID_P (c
, 1))
1322 /* We may not change the length here because other places in Emacs
1323 don't use this function, i.e. they silently accept invalid
1332 /* Given a position POS containing a valid character and byte position
1333 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1335 static struct text_pos
1336 string_pos_nchars_ahead (pos
, string
, nchars
)
1337 struct text_pos pos
;
1341 xassert (STRINGP (string
) && nchars
>= 0);
1343 if (STRING_MULTIBYTE (string
))
1345 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1346 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1351 string_char_and_length (p
, rest
, &len
);
1352 p
+= len
, rest
-= len
;
1353 xassert (rest
>= 0);
1355 BYTEPOS (pos
) += len
;
1359 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1365 /* Value is the text position, i.e. character and byte position,
1366 for character position CHARPOS in STRING. */
1368 static INLINE
struct text_pos
1369 string_pos (charpos
, string
)
1373 struct text_pos pos
;
1374 xassert (STRINGP (string
));
1375 xassert (charpos
>= 0);
1376 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1381 /* Value is a text position, i.e. character and byte position, for
1382 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1383 means recognize multibyte characters. */
1385 static struct text_pos
1386 c_string_pos (charpos
, s
, multibyte_p
)
1391 struct text_pos pos
;
1393 xassert (s
!= NULL
);
1394 xassert (charpos
>= 0);
1398 int rest
= strlen (s
), len
;
1400 SET_TEXT_POS (pos
, 0, 0);
1403 string_char_and_length (s
, rest
, &len
);
1404 s
+= len
, rest
-= len
;
1405 xassert (rest
>= 0);
1407 BYTEPOS (pos
) += len
;
1411 SET_TEXT_POS (pos
, charpos
, charpos
);
1417 /* Value is the number of characters in C string S. MULTIBYTE_P
1418 non-zero means recognize multibyte characters. */
1421 number_of_chars (s
, multibyte_p
)
1429 int rest
= strlen (s
), len
;
1430 unsigned char *p
= (unsigned char *) s
;
1432 for (nchars
= 0; rest
> 0; ++nchars
)
1434 string_char_and_length (p
, rest
, &len
);
1435 rest
-= len
, p
+= len
;
1439 nchars
= strlen (s
);
1445 /* Compute byte position NEWPOS->bytepos corresponding to
1446 NEWPOS->charpos. POS is a known position in string STRING.
1447 NEWPOS->charpos must be >= POS.charpos. */
1450 compute_string_pos (newpos
, pos
, string
)
1451 struct text_pos
*newpos
, pos
;
1454 xassert (STRINGP (string
));
1455 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1457 if (STRING_MULTIBYTE (string
))
1458 *newpos
= string_pos_nchars_ahead (pos
, string
,
1459 CHARPOS (*newpos
) - CHARPOS (pos
));
1461 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1465 Return an estimation of the pixel height of mode or top lines on
1466 frame F. FACE_ID specifies what line's height to estimate. */
1469 estimate_mode_line_height (f
, face_id
)
1471 enum face_id face_id
;
1473 #ifdef HAVE_WINDOW_SYSTEM
1474 if (FRAME_WINDOW_P (f
))
1476 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1478 /* This function is called so early when Emacs starts that the face
1479 cache and mode line face are not yet initialized. */
1480 if (FRAME_FACE_CACHE (f
))
1482 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1486 height
= FONT_HEIGHT (face
->font
);
1487 if (face
->box_line_width
> 0)
1488 height
+= 2 * face
->box_line_width
;
1499 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1500 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1501 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1502 not force the value into range. */
1505 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1507 register int pix_x
, pix_y
;
1509 NativeRectangle
*bounds
;
1513 #ifdef HAVE_WINDOW_SYSTEM
1514 if (FRAME_WINDOW_P (f
))
1516 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1517 even for negative values. */
1519 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1521 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1523 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1524 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1527 STORE_NATIVE_RECT (*bounds
,
1528 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1529 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1530 FRAME_COLUMN_WIDTH (f
) - 1,
1531 FRAME_LINE_HEIGHT (f
) - 1);
1537 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1538 pix_x
= FRAME_TOTAL_COLS (f
);
1542 else if (pix_y
> FRAME_LINES (f
))
1543 pix_y
= FRAME_LINES (f
);
1553 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1554 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1555 can't tell the positions because W's display is not up to date,
1559 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1562 int *frame_x
, *frame_y
;
1564 #ifdef HAVE_WINDOW_SYSTEM
1565 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1569 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1570 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1572 if (display_completed
)
1574 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1575 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1576 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1582 hpos
+= glyph
->pixel_width
;
1586 /* If first glyph is partially visible, its first visible position is still 0. */
1598 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1599 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1610 #ifdef HAVE_WINDOW_SYSTEM
1612 /* Find the glyph under window-relative coordinates X/Y in window W.
1613 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1614 strings. Return in *HPOS and *VPOS the row and column number of
1615 the glyph found. Return in *AREA the glyph area containing X.
1616 Value is a pointer to the glyph found or null if X/Y is not on
1617 text, or we can't tell because W's current matrix is not up to
1620 static struct glyph
*
1621 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1624 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1626 struct glyph
*glyph
, *end
;
1627 struct glyph_row
*row
= NULL
;
1630 /* Find row containing Y. Give up if some row is not enabled. */
1631 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1633 row
= MATRIX_ROW (w
->current_matrix
, i
);
1634 if (!row
->enabled_p
)
1636 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1643 /* Give up if Y is not in the window. */
1644 if (i
== w
->current_matrix
->nrows
)
1647 /* Get the glyph area containing X. */
1648 if (w
->pseudo_window_p
)
1655 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1657 *area
= LEFT_MARGIN_AREA
;
1658 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1660 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1663 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1667 *area
= RIGHT_MARGIN_AREA
;
1668 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1672 /* Find glyph containing X. */
1673 glyph
= row
->glyphs
[*area
];
1674 end
= glyph
+ row
->used
[*area
];
1676 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1678 x
-= glyph
->pixel_width
;
1688 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1691 *hpos
= glyph
- row
->glyphs
[*area
];
1697 Convert frame-relative x/y to coordinates relative to window W.
1698 Takes pseudo-windows into account. */
1701 frame_to_window_pixel_xy (w
, x
, y
)
1705 if (w
->pseudo_window_p
)
1707 /* A pseudo-window is always full-width, and starts at the
1708 left edge of the frame, plus a frame border. */
1709 struct frame
*f
= XFRAME (w
->frame
);
1710 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1711 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1715 *x
-= WINDOW_LEFT_EDGE_X (w
);
1716 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1721 Return in *R the clipping rectangle for glyph string S. */
1724 get_glyph_string_clip_rect (s
, nr
)
1725 struct glyph_string
*s
;
1726 NativeRectangle
*nr
;
1730 if (s
->row
->full_width_p
)
1732 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1733 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1734 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1736 /* Unless displaying a mode or menu bar line, which are always
1737 fully visible, clip to the visible part of the row. */
1738 if (s
->w
->pseudo_window_p
)
1739 r
.height
= s
->row
->visible_height
;
1741 r
.height
= s
->height
;
1745 /* This is a text line that may be partially visible. */
1746 r
.x
= window_box_left (s
->w
, s
->area
);
1747 r
.width
= window_box_width (s
->w
, s
->area
);
1748 r
.height
= s
->row
->visible_height
;
1751 /* If S draws overlapping rows, it's sufficient to use the top and
1752 bottom of the window for clipping because this glyph string
1753 intentionally draws over other lines. */
1754 if (s
->for_overlaps_p
)
1756 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1757 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1761 /* Don't use S->y for clipping because it doesn't take partially
1762 visible lines into account. For example, it can be negative for
1763 partially visible lines at the top of a window. */
1764 if (!s
->row
->full_width_p
1765 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1766 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1768 r
.y
= max (0, s
->row
->y
);
1770 /* If drawing a tool-bar window, draw it over the internal border
1771 at the top of the window. */
1772 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1773 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1776 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1778 /* If drawing the cursor, don't let glyph draw outside its
1779 advertised boundaries. Cleartype does this under some circumstances. */
1780 if (s
->hl
== DRAW_CURSOR
)
1782 struct glyph
*glyph
= s
->first_glyph
;
1787 r
.width
-= s
->x
- r
.x
;
1790 r
.width
= min (r
.width
, glyph
->pixel_width
);
1792 /* Don't draw cursor glyph taller than our actual glyph. */
1793 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1794 if (height
< r
.height
)
1796 int max_y
= r
.y
+ r
.height
;
1797 r
.y
= min (max_y
, s
->ybase
+ glyph
->descent
- height
);
1798 r
.height
= min (max_y
- r
.y
, height
);
1802 #ifdef CONVERT_FROM_XRECT
1803 CONVERT_FROM_XRECT (r
, *nr
);
1809 #endif /* HAVE_WINDOW_SYSTEM */
1812 /***********************************************************************
1813 Lisp form evaluation
1814 ***********************************************************************/
1816 /* Error handler for safe_eval and safe_call. */
1819 safe_eval_handler (arg
)
1822 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1827 /* Evaluate SEXPR and return the result, or nil if something went
1828 wrong. Prevent redisplay during the evaluation. */
1836 if (inhibit_eval_during_redisplay
)
1840 int count
= SPECPDL_INDEX ();
1841 struct gcpro gcpro1
;
1844 specbind (Qinhibit_redisplay
, Qt
);
1845 /* Use Qt to ensure debugger does not run,
1846 so there is no possibility of wanting to redisplay. */
1847 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1850 val
= unbind_to (count
, val
);
1857 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1858 Return the result, or nil if something went wrong. Prevent
1859 redisplay during the evaluation. */
1862 safe_call (nargs
, args
)
1868 if (inhibit_eval_during_redisplay
)
1872 int count
= SPECPDL_INDEX ();
1873 struct gcpro gcpro1
;
1876 gcpro1
.nvars
= nargs
;
1877 specbind (Qinhibit_redisplay
, Qt
);
1878 /* Use Qt to ensure debugger does not run,
1879 so there is no possibility of wanting to redisplay. */
1880 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
1883 val
= unbind_to (count
, val
);
1890 /* Call function FN with one argument ARG.
1891 Return the result, or nil if something went wrong. */
1894 safe_call1 (fn
, arg
)
1895 Lisp_Object fn
, arg
;
1897 Lisp_Object args
[2];
1900 return safe_call (2, args
);
1905 /***********************************************************************
1907 ***********************************************************************/
1911 /* Define CHECK_IT to perform sanity checks on iterators.
1912 This is for debugging. It is too slow to do unconditionally. */
1918 if (it
->method
== next_element_from_string
)
1920 xassert (STRINGP (it
->string
));
1921 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1925 xassert (IT_STRING_CHARPOS (*it
) < 0);
1926 if (it
->method
== next_element_from_buffer
)
1928 /* Check that character and byte positions agree. */
1929 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1934 xassert (it
->current
.dpvec_index
>= 0);
1936 xassert (it
->current
.dpvec_index
< 0);
1939 #define CHECK_IT(IT) check_it ((IT))
1943 #define CHECK_IT(IT) (void) 0
1950 /* Check that the window end of window W is what we expect it
1951 to be---the last row in the current matrix displaying text. */
1954 check_window_end (w
)
1957 if (!MINI_WINDOW_P (w
)
1958 && !NILP (w
->window_end_valid
))
1960 struct glyph_row
*row
;
1961 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1962 XFASTINT (w
->window_end_vpos
)),
1964 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1965 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1969 #define CHECK_WINDOW_END(W) check_window_end ((W))
1971 #else /* not GLYPH_DEBUG */
1973 #define CHECK_WINDOW_END(W) (void) 0
1975 #endif /* not GLYPH_DEBUG */
1979 /***********************************************************************
1980 Iterator initialization
1981 ***********************************************************************/
1983 /* Initialize IT for displaying current_buffer in window W, starting
1984 at character position CHARPOS. CHARPOS < 0 means that no buffer
1985 position is specified which is useful when the iterator is assigned
1986 a position later. BYTEPOS is the byte position corresponding to
1987 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
1989 If ROW is not null, calls to produce_glyphs with IT as parameter
1990 will produce glyphs in that row.
1992 BASE_FACE_ID is the id of a base face to use. It must be one of
1993 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
1994 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
1995 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
1997 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
1998 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
1999 will be initialized to use the corresponding mode line glyph row of
2000 the desired matrix of W. */
2003 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2006 int charpos
, bytepos
;
2007 struct glyph_row
*row
;
2008 enum face_id base_face_id
;
2010 int highlight_region_p
;
2012 /* Some precondition checks. */
2013 xassert (w
!= NULL
&& it
!= NULL
);
2014 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2017 /* If face attributes have been changed since the last redisplay,
2018 free realized faces now because they depend on face definitions
2019 that might have changed. Don't free faces while there might be
2020 desired matrices pending which reference these faces. */
2021 if (face_change_count
&& !inhibit_free_realized_faces
)
2023 face_change_count
= 0;
2024 free_all_realized_faces (Qnil
);
2027 /* Use one of the mode line rows of W's desired matrix if
2031 if (base_face_id
== MODE_LINE_FACE_ID
2032 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2033 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2034 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2035 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2039 bzero (it
, sizeof *it
);
2040 it
->current
.overlay_string_index
= -1;
2041 it
->current
.dpvec_index
= -1;
2042 it
->base_face_id
= base_face_id
;
2044 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2046 /* The window in which we iterate over current_buffer: */
2047 XSETWINDOW (it
->window
, w
);
2049 it
->f
= XFRAME (w
->frame
);
2051 /* Extra space between lines (on window systems only). */
2052 if (base_face_id
== DEFAULT_FACE_ID
2053 && FRAME_WINDOW_P (it
->f
))
2055 if (NATNUMP (current_buffer
->extra_line_spacing
))
2056 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2057 else if (it
->f
->extra_line_spacing
> 0)
2058 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2061 /* If realized faces have been removed, e.g. because of face
2062 attribute changes of named faces, recompute them. When running
2063 in batch mode, the face cache of Vterminal_frame is null. If
2064 we happen to get called, make a dummy face cache. */
2065 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2066 init_frame_faces (it
->f
);
2067 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2068 recompute_basic_faces (it
->f
);
2070 /* Current value of the `space-width', and 'height' properties. */
2071 it
->space_width
= Qnil
;
2072 it
->font_height
= Qnil
;
2074 /* Are control characters displayed as `^C'? */
2075 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2077 /* -1 means everything between a CR and the following line end
2078 is invisible. >0 means lines indented more than this value are
2080 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2081 ? XFASTINT (current_buffer
->selective_display
)
2082 : (!NILP (current_buffer
->selective_display
)
2084 it
->selective_display_ellipsis_p
2085 = !NILP (current_buffer
->selective_display_ellipses
);
2087 /* Display table to use. */
2088 it
->dp
= window_display_table (w
);
2090 /* Are multibyte characters enabled in current_buffer? */
2091 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2093 /* Non-zero if we should highlight the region. */
2095 = (!NILP (Vtransient_mark_mode
)
2096 && !NILP (current_buffer
->mark_active
)
2097 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2099 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2100 start and end of a visible region in window IT->w. Set both to
2101 -1 to indicate no region. */
2102 if (highlight_region_p
2103 /* Maybe highlight only in selected window. */
2104 && (/* Either show region everywhere. */
2105 highlight_nonselected_windows
2106 /* Or show region in the selected window. */
2107 || w
== XWINDOW (selected_window
)
2108 /* Or show the region if we are in the mini-buffer and W is
2109 the window the mini-buffer refers to. */
2110 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2111 && WINDOWP (minibuf_selected_window
)
2112 && w
== XWINDOW (minibuf_selected_window
))))
2114 int charpos
= marker_position (current_buffer
->mark
);
2115 it
->region_beg_charpos
= min (PT
, charpos
);
2116 it
->region_end_charpos
= max (PT
, charpos
);
2119 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2121 /* Get the position at which the redisplay_end_trigger hook should
2122 be run, if it is to be run at all. */
2123 if (MARKERP (w
->redisplay_end_trigger
)
2124 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2125 it
->redisplay_end_trigger_charpos
2126 = marker_position (w
->redisplay_end_trigger
);
2127 else if (INTEGERP (w
->redisplay_end_trigger
))
2128 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2130 /* Correct bogus values of tab_width. */
2131 it
->tab_width
= XINT (current_buffer
->tab_width
);
2132 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2135 /* Are lines in the display truncated? */
2136 it
->truncate_lines_p
2137 = (base_face_id
!= DEFAULT_FACE_ID
2138 || XINT (it
->w
->hscroll
)
2139 || (truncate_partial_width_windows
2140 && !WINDOW_FULL_WIDTH_P (it
->w
))
2141 || !NILP (current_buffer
->truncate_lines
));
2143 /* Get dimensions of truncation and continuation glyphs. These are
2144 displayed as fringe bitmaps under X, so we don't need them for such
2146 if (!FRAME_WINDOW_P (it
->f
))
2148 if (it
->truncate_lines_p
)
2150 /* We will need the truncation glyph. */
2151 xassert (it
->glyph_row
== NULL
);
2152 produce_special_glyphs (it
, IT_TRUNCATION
);
2153 it
->truncation_pixel_width
= it
->pixel_width
;
2157 /* We will need the continuation glyph. */
2158 xassert (it
->glyph_row
== NULL
);
2159 produce_special_glyphs (it
, IT_CONTINUATION
);
2160 it
->continuation_pixel_width
= it
->pixel_width
;
2163 /* Reset these values to zero because the produce_special_glyphs
2164 above has changed them. */
2165 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2166 it
->phys_ascent
= it
->phys_descent
= 0;
2169 /* Set this after getting the dimensions of truncation and
2170 continuation glyphs, so that we don't produce glyphs when calling
2171 produce_special_glyphs, above. */
2172 it
->glyph_row
= row
;
2173 it
->area
= TEXT_AREA
;
2175 /* Get the dimensions of the display area. The display area
2176 consists of the visible window area plus a horizontally scrolled
2177 part to the left of the window. All x-values are relative to the
2178 start of this total display area. */
2179 if (base_face_id
!= DEFAULT_FACE_ID
)
2181 /* Mode lines, menu bar in terminal frames. */
2182 it
->first_visible_x
= 0;
2183 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2188 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2189 it
->last_visible_x
= (it
->first_visible_x
2190 + window_box_width (w
, TEXT_AREA
));
2192 /* If we truncate lines, leave room for the truncator glyph(s) at
2193 the right margin. Otherwise, leave room for the continuation
2194 glyph(s). Truncation and continuation glyphs are not inserted
2195 for window-based redisplay. */
2196 if (!FRAME_WINDOW_P (it
->f
))
2198 if (it
->truncate_lines_p
)
2199 it
->last_visible_x
-= it
->truncation_pixel_width
;
2201 it
->last_visible_x
-= it
->continuation_pixel_width
;
2204 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2205 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2208 /* Leave room for a border glyph. */
2209 if (!FRAME_WINDOW_P (it
->f
)
2210 && !WINDOW_RIGHTMOST_P (it
->w
))
2211 it
->last_visible_x
-= 1;
2213 it
->last_visible_y
= window_text_bottom_y (w
);
2215 /* For mode lines and alike, arrange for the first glyph having a
2216 left box line if the face specifies a box. */
2217 if (base_face_id
!= DEFAULT_FACE_ID
)
2221 it
->face_id
= base_face_id
;
2223 /* If we have a boxed mode line, make the first character appear
2224 with a left box line. */
2225 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2226 if (face
->box
!= FACE_NO_BOX
)
2227 it
->start_of_box_run_p
= 1;
2230 /* If a buffer position was specified, set the iterator there,
2231 getting overlays and face properties from that position. */
2232 if (charpos
>= BUF_BEG (current_buffer
))
2234 it
->end_charpos
= ZV
;
2236 IT_CHARPOS (*it
) = charpos
;
2238 /* Compute byte position if not specified. */
2239 if (bytepos
< charpos
)
2240 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2242 IT_BYTEPOS (*it
) = bytepos
;
2244 it
->start
= it
->current
;
2246 /* Compute faces etc. */
2247 reseat (it
, it
->current
.pos
, 1);
2254 /* Initialize IT for the display of window W with window start POS. */
2257 start_display (it
, w
, pos
)
2260 struct text_pos pos
;
2262 struct glyph_row
*row
;
2263 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2265 row
= w
->desired_matrix
->rows
+ first_vpos
;
2266 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2267 it
->first_vpos
= first_vpos
;
2269 if (!it
->truncate_lines_p
)
2271 int start_at_line_beg_p
;
2272 int first_y
= it
->current_y
;
2274 /* If window start is not at a line start, skip forward to POS to
2275 get the correct continuation lines width. */
2276 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2277 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2278 if (!start_at_line_beg_p
)
2282 reseat_at_previous_visible_line_start (it
);
2283 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2285 new_x
= it
->current_x
+ it
->pixel_width
;
2287 /* If lines are continued, this line may end in the middle
2288 of a multi-glyph character (e.g. a control character
2289 displayed as \003, or in the middle of an overlay
2290 string). In this case move_it_to above will not have
2291 taken us to the start of the continuation line but to the
2292 end of the continued line. */
2293 if (it
->current_x
> 0
2294 && !it
->truncate_lines_p
/* Lines are continued. */
2295 && (/* And glyph doesn't fit on the line. */
2296 new_x
> it
->last_visible_x
2297 /* Or it fits exactly and we're on a window
2299 || (new_x
== it
->last_visible_x
2300 && FRAME_WINDOW_P (it
->f
))))
2302 if (it
->current
.dpvec_index
>= 0
2303 || it
->current
.overlay_string_index
>= 0)
2305 set_iterator_to_next (it
, 1);
2306 move_it_in_display_line_to (it
, -1, -1, 0);
2309 it
->continuation_lines_width
+= it
->current_x
;
2312 /* We're starting a new display line, not affected by the
2313 height of the continued line, so clear the appropriate
2314 fields in the iterator structure. */
2315 it
->max_ascent
= it
->max_descent
= 0;
2316 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2318 it
->current_y
= first_y
;
2320 it
->current_x
= it
->hpos
= 0;
2324 #if 0 /* Don't assert the following because start_display is sometimes
2325 called intentionally with a window start that is not at a
2326 line start. Please leave this code in as a comment. */
2328 /* Window start should be on a line start, now. */
2329 xassert (it
->continuation_lines_width
2330 || IT_CHARPOS (it
) == BEGV
2331 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2336 /* Return 1 if POS is a position in ellipses displayed for invisible
2337 text. W is the window we display, for text property lookup. */
2340 in_ellipses_for_invisible_text_p (pos
, w
)
2341 struct display_pos
*pos
;
2344 Lisp_Object prop
, window
;
2346 int charpos
= CHARPOS (pos
->pos
);
2348 /* If POS specifies a position in a display vector, this might
2349 be for an ellipsis displayed for invisible text. We won't
2350 get the iterator set up for delivering that ellipsis unless
2351 we make sure that it gets aware of the invisible text. */
2352 if (pos
->dpvec_index
>= 0
2353 && pos
->overlay_string_index
< 0
2354 && CHARPOS (pos
->string_pos
) < 0
2356 && (XSETWINDOW (window
, w
),
2357 prop
= Fget_char_property (make_number (charpos
),
2358 Qinvisible
, window
),
2359 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2361 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2363 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2370 /* Initialize IT for stepping through current_buffer in window W,
2371 starting at position POS that includes overlay string and display
2372 vector/ control character translation position information. Value
2373 is zero if there are overlay strings with newlines at POS. */
2376 init_from_display_pos (it
, w
, pos
)
2379 struct display_pos
*pos
;
2381 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2382 int i
, overlay_strings_with_newlines
= 0;
2384 /* If POS specifies a position in a display vector, this might
2385 be for an ellipsis displayed for invisible text. We won't
2386 get the iterator set up for delivering that ellipsis unless
2387 we make sure that it gets aware of the invisible text. */
2388 if (in_ellipses_for_invisible_text_p (pos
, w
))
2394 /* Keep in mind: the call to reseat in init_iterator skips invisible
2395 text, so we might end up at a position different from POS. This
2396 is only a problem when POS is a row start after a newline and an
2397 overlay starts there with an after-string, and the overlay has an
2398 invisible property. Since we don't skip invisible text in
2399 display_line and elsewhere immediately after consuming the
2400 newline before the row start, such a POS will not be in a string,
2401 but the call to init_iterator below will move us to the
2403 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2405 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
2407 const char *s
= SDATA (it
->overlay_strings
[i
]);
2408 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2410 while (s
< e
&& *s
!= '\n')
2415 overlay_strings_with_newlines
= 1;
2420 /* If position is within an overlay string, set up IT to the right
2422 if (pos
->overlay_string_index
>= 0)
2426 /* If the first overlay string happens to have a `display'
2427 property for an image, the iterator will be set up for that
2428 image, and we have to undo that setup first before we can
2429 correct the overlay string index. */
2430 if (it
->method
== next_element_from_image
)
2433 /* We already have the first chunk of overlay strings in
2434 IT->overlay_strings. Load more until the one for
2435 pos->overlay_string_index is in IT->overlay_strings. */
2436 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2438 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2439 it
->current
.overlay_string_index
= 0;
2442 load_overlay_strings (it
, 0);
2443 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2447 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2448 relative_index
= (it
->current
.overlay_string_index
2449 % OVERLAY_STRING_CHUNK_SIZE
);
2450 it
->string
= it
->overlay_strings
[relative_index
];
2451 xassert (STRINGP (it
->string
));
2452 it
->current
.string_pos
= pos
->string_pos
;
2453 it
->method
= next_element_from_string
;
2456 #if 0 /* This is bogus because POS not having an overlay string
2457 position does not mean it's after the string. Example: A
2458 line starting with a before-string and initialization of IT
2459 to the previous row's end position. */
2460 else if (it
->current
.overlay_string_index
>= 0)
2462 /* If POS says we're already after an overlay string ending at
2463 POS, make sure to pop the iterator because it will be in
2464 front of that overlay string. When POS is ZV, we've thereby
2465 also ``processed'' overlay strings at ZV. */
2468 it
->current
.overlay_string_index
= -1;
2469 it
->method
= next_element_from_buffer
;
2470 if (CHARPOS (pos
->pos
) == ZV
)
2471 it
->overlay_strings_at_end_processed_p
= 1;
2475 if (CHARPOS (pos
->string_pos
) >= 0)
2477 /* Recorded position is not in an overlay string, but in another
2478 string. This can only be a string from a `display' property.
2479 IT should already be filled with that string. */
2480 it
->current
.string_pos
= pos
->string_pos
;
2481 xassert (STRINGP (it
->string
));
2484 /* Restore position in display vector translations, control
2485 character translations or ellipses. */
2486 if (pos
->dpvec_index
>= 0)
2488 if (it
->dpvec
== NULL
)
2489 get_next_display_element (it
);
2490 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2491 it
->current
.dpvec_index
= pos
->dpvec_index
;
2495 return !overlay_strings_with_newlines
;
2499 /* Initialize IT for stepping through current_buffer in window W
2500 starting at ROW->start. */
2503 init_to_row_start (it
, w
, row
)
2506 struct glyph_row
*row
;
2508 init_from_display_pos (it
, w
, &row
->start
);
2509 it
->start
= row
->start
;
2510 it
->continuation_lines_width
= row
->continuation_lines_width
;
2515 /* Initialize IT for stepping through current_buffer in window W
2516 starting in the line following ROW, i.e. starting at ROW->end.
2517 Value is zero if there are overlay strings with newlines at ROW's
2521 init_to_row_end (it
, w
, row
)
2524 struct glyph_row
*row
;
2528 if (init_from_display_pos (it
, w
, &row
->end
))
2530 if (row
->continued_p
)
2531 it
->continuation_lines_width
2532 = row
->continuation_lines_width
+ row
->pixel_width
;
2543 /***********************************************************************
2545 ***********************************************************************/
2547 /* Called when IT reaches IT->stop_charpos. Handle text property and
2548 overlay changes. Set IT->stop_charpos to the next position where
2555 enum prop_handled handled
;
2556 int handle_overlay_change_p
= 1;
2560 it
->current
.dpvec_index
= -1;
2564 handled
= HANDLED_NORMALLY
;
2566 /* Call text property handlers. */
2567 for (p
= it_props
; p
->handler
; ++p
)
2569 handled
= p
->handler (it
);
2571 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2573 else if (handled
== HANDLED_RETURN
)
2575 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2576 handle_overlay_change_p
= 0;
2579 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2581 /* Don't check for overlay strings below when set to deliver
2582 characters from a display vector. */
2583 if (it
->method
== next_element_from_display_vector
)
2584 handle_overlay_change_p
= 0;
2586 /* Handle overlay changes. */
2587 if (handle_overlay_change_p
)
2588 handled
= handle_overlay_change (it
);
2590 /* Determine where to stop next. */
2591 if (handled
== HANDLED_NORMALLY
)
2592 compute_stop_pos (it
);
2595 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2599 /* Compute IT->stop_charpos from text property and overlay change
2600 information for IT's current position. */
2603 compute_stop_pos (it
)
2606 register INTERVAL iv
, next_iv
;
2607 Lisp_Object object
, limit
, position
;
2609 /* If nowhere else, stop at the end. */
2610 it
->stop_charpos
= it
->end_charpos
;
2612 if (STRINGP (it
->string
))
2614 /* Strings are usually short, so don't limit the search for
2616 object
= it
->string
;
2618 position
= make_number (IT_STRING_CHARPOS (*it
));
2624 /* If next overlay change is in front of the current stop pos
2625 (which is IT->end_charpos), stop there. Note: value of
2626 next_overlay_change is point-max if no overlay change
2628 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2629 if (charpos
< it
->stop_charpos
)
2630 it
->stop_charpos
= charpos
;
2632 /* If showing the region, we have to stop at the region
2633 start or end because the face might change there. */
2634 if (it
->region_beg_charpos
> 0)
2636 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2637 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2638 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2639 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2642 /* Set up variables for computing the stop position from text
2643 property changes. */
2644 XSETBUFFER (object
, current_buffer
);
2645 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2646 position
= make_number (IT_CHARPOS (*it
));
2650 /* Get the interval containing IT's position. Value is a null
2651 interval if there isn't such an interval. */
2652 iv
= validate_interval_range (object
, &position
, &position
, 0);
2653 if (!NULL_INTERVAL_P (iv
))
2655 Lisp_Object values_here
[LAST_PROP_IDX
];
2658 /* Get properties here. */
2659 for (p
= it_props
; p
->handler
; ++p
)
2660 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2662 /* Look for an interval following iv that has different
2664 for (next_iv
= next_interval (iv
);
2665 (!NULL_INTERVAL_P (next_iv
)
2667 || XFASTINT (limit
) > next_iv
->position
));
2668 next_iv
= next_interval (next_iv
))
2670 for (p
= it_props
; p
->handler
; ++p
)
2672 Lisp_Object new_value
;
2674 new_value
= textget (next_iv
->plist
, *p
->name
);
2675 if (!EQ (values_here
[p
->idx
], new_value
))
2683 if (!NULL_INTERVAL_P (next_iv
))
2685 if (INTEGERP (limit
)
2686 && next_iv
->position
>= XFASTINT (limit
))
2687 /* No text property change up to limit. */
2688 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2690 /* Text properties change in next_iv. */
2691 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2695 xassert (STRINGP (it
->string
)
2696 || (it
->stop_charpos
>= BEGV
2697 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2701 /* Return the position of the next overlay change after POS in
2702 current_buffer. Value is point-max if no overlay change
2703 follows. This is like `next-overlay-change' but doesn't use
2707 next_overlay_change (pos
)
2712 Lisp_Object
*overlays
;
2716 /* Get all overlays at the given position. */
2718 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2719 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2720 if (noverlays
> len
)
2723 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2724 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2727 /* If any of these overlays ends before endpos,
2728 use its ending point instead. */
2729 for (i
= 0; i
< noverlays
; ++i
)
2734 oend
= OVERLAY_END (overlays
[i
]);
2735 oendpos
= OVERLAY_POSITION (oend
);
2736 endpos
= min (endpos
, oendpos
);
2744 /***********************************************************************
2746 ***********************************************************************/
2748 /* Handle changes in the `fontified' property of the current buffer by
2749 calling hook functions from Qfontification_functions to fontify
2752 static enum prop_handled
2753 handle_fontified_prop (it
)
2756 Lisp_Object prop
, pos
;
2757 enum prop_handled handled
= HANDLED_NORMALLY
;
2759 /* Get the value of the `fontified' property at IT's current buffer
2760 position. (The `fontified' property doesn't have a special
2761 meaning in strings.) If the value is nil, call functions from
2762 Qfontification_functions. */
2763 if (!STRINGP (it
->string
)
2765 && !NILP (Vfontification_functions
)
2766 && !NILP (Vrun_hooks
)
2767 && (pos
= make_number (IT_CHARPOS (*it
)),
2768 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2771 int count
= SPECPDL_INDEX ();
2774 val
= Vfontification_functions
;
2775 specbind (Qfontification_functions
, Qnil
);
2777 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2778 safe_call1 (val
, pos
);
2781 Lisp_Object globals
, fn
;
2782 struct gcpro gcpro1
, gcpro2
;
2785 GCPRO2 (val
, globals
);
2787 for (; CONSP (val
); val
= XCDR (val
))
2793 /* A value of t indicates this hook has a local
2794 binding; it means to run the global binding too.
2795 In a global value, t should not occur. If it
2796 does, we must ignore it to avoid an endless
2798 for (globals
= Fdefault_value (Qfontification_functions
);
2800 globals
= XCDR (globals
))
2802 fn
= XCAR (globals
);
2804 safe_call1 (fn
, pos
);
2808 safe_call1 (fn
, pos
);
2814 unbind_to (count
, Qnil
);
2816 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2817 something. This avoids an endless loop if they failed to
2818 fontify the text for which reason ever. */
2819 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2820 handled
= HANDLED_RECOMPUTE_PROPS
;
2828 /***********************************************************************
2830 ***********************************************************************/
2832 /* Set up iterator IT from face properties at its current position.
2833 Called from handle_stop. */
2835 static enum prop_handled
2836 handle_face_prop (it
)
2839 int new_face_id
, next_stop
;
2841 if (!STRINGP (it
->string
))
2844 = face_at_buffer_position (it
->w
,
2846 it
->region_beg_charpos
,
2847 it
->region_end_charpos
,
2850 + TEXT_PROP_DISTANCE_LIMIT
),
2853 /* Is this a start of a run of characters with box face?
2854 Caveat: this can be called for a freshly initialized
2855 iterator; face_id is -1 in this case. We know that the new
2856 face will not change until limit, i.e. if the new face has a
2857 box, all characters up to limit will have one. But, as
2858 usual, we don't know whether limit is really the end. */
2859 if (new_face_id
!= it
->face_id
)
2861 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2863 /* If new face has a box but old face has not, this is
2864 the start of a run of characters with box, i.e. it has
2865 a shadow on the left side. The value of face_id of the
2866 iterator will be -1 if this is the initial call that gets
2867 the face. In this case, we have to look in front of IT's
2868 position and see whether there is a face != new_face_id. */
2869 it
->start_of_box_run_p
2870 = (new_face
->box
!= FACE_NO_BOX
2871 && (it
->face_id
>= 0
2872 || IT_CHARPOS (*it
) == BEG
2873 || new_face_id
!= face_before_it_pos (it
)));
2874 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2879 int base_face_id
, bufpos
;
2881 if (it
->current
.overlay_string_index
>= 0)
2882 bufpos
= IT_CHARPOS (*it
);
2886 /* For strings from a buffer, i.e. overlay strings or strings
2887 from a `display' property, use the face at IT's current
2888 buffer position as the base face to merge with, so that
2889 overlay strings appear in the same face as surrounding
2890 text, unless they specify their own faces. */
2891 base_face_id
= underlying_face_id (it
);
2893 new_face_id
= face_at_string_position (it
->w
,
2895 IT_STRING_CHARPOS (*it
),
2897 it
->region_beg_charpos
,
2898 it
->region_end_charpos
,
2902 #if 0 /* This shouldn't be neccessary. Let's check it. */
2903 /* If IT is used to display a mode line we would really like to
2904 use the mode line face instead of the frame's default face. */
2905 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2906 && new_face_id
== DEFAULT_FACE_ID
)
2907 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
2910 /* Is this a start of a run of characters with box? Caveat:
2911 this can be called for a freshly allocated iterator; face_id
2912 is -1 is this case. We know that the new face will not
2913 change until the next check pos, i.e. if the new face has a
2914 box, all characters up to that position will have a
2915 box. But, as usual, we don't know whether that position
2916 is really the end. */
2917 if (new_face_id
!= it
->face_id
)
2919 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2920 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2922 /* If new face has a box but old face hasn't, this is the
2923 start of a run of characters with box, i.e. it has a
2924 shadow on the left side. */
2925 it
->start_of_box_run_p
2926 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2927 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2931 it
->face_id
= new_face_id
;
2932 return HANDLED_NORMALLY
;
2936 /* Return the ID of the face ``underlying'' IT's current position,
2937 which is in a string. If the iterator is associated with a
2938 buffer, return the face at IT's current buffer position.
2939 Otherwise, use the iterator's base_face_id. */
2942 underlying_face_id (it
)
2945 int face_id
= it
->base_face_id
, i
;
2947 xassert (STRINGP (it
->string
));
2949 for (i
= it
->sp
- 1; i
>= 0; --i
)
2950 if (NILP (it
->stack
[i
].string
))
2951 face_id
= it
->stack
[i
].face_id
;
2957 /* Compute the face one character before or after the current position
2958 of IT. BEFORE_P non-zero means get the face in front of IT's
2959 position. Value is the id of the face. */
2962 face_before_or_after_it_pos (it
, before_p
)
2967 int next_check_charpos
;
2968 struct text_pos pos
;
2970 xassert (it
->s
== NULL
);
2972 if (STRINGP (it
->string
))
2974 int bufpos
, base_face_id
;
2976 /* No face change past the end of the string (for the case
2977 we are padding with spaces). No face change before the
2979 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
2980 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2983 /* Set pos to the position before or after IT's current position. */
2985 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2987 /* For composition, we must check the character after the
2989 pos
= (it
->what
== IT_COMPOSITION
2990 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2991 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2993 if (it
->current
.overlay_string_index
>= 0)
2994 bufpos
= IT_CHARPOS (*it
);
2998 base_face_id
= underlying_face_id (it
);
3000 /* Get the face for ASCII, or unibyte. */
3001 face_id
= face_at_string_position (it
->w
,
3005 it
->region_beg_charpos
,
3006 it
->region_end_charpos
,
3007 &next_check_charpos
,
3010 /* Correct the face for charsets different from ASCII. Do it
3011 for the multibyte case only. The face returned above is
3012 suitable for unibyte text if IT->string is unibyte. */
3013 if (STRING_MULTIBYTE (it
->string
))
3015 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3016 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3018 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3020 c
= string_char_and_length (p
, rest
, &len
);
3021 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3026 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3027 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3030 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3031 pos
= it
->current
.pos
;
3034 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3037 if (it
->what
== IT_COMPOSITION
)
3038 /* For composition, we must check the position after the
3040 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3042 INC_TEXT_POS (pos
, it
->multibyte_p
);
3045 /* Determine face for CHARSET_ASCII, or unibyte. */
3046 face_id
= face_at_buffer_position (it
->w
,
3048 it
->region_beg_charpos
,
3049 it
->region_end_charpos
,
3050 &next_check_charpos
,
3053 /* Correct the face for charsets different from ASCII. Do it
3054 for the multibyte case only. The face returned above is
3055 suitable for unibyte text if current_buffer is unibyte. */
3056 if (it
->multibyte_p
)
3058 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3059 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3060 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3069 /***********************************************************************
3071 ***********************************************************************/
3073 /* Set up iterator IT from invisible properties at its current
3074 position. Called from handle_stop. */
3076 static enum prop_handled
3077 handle_invisible_prop (it
)
3080 enum prop_handled handled
= HANDLED_NORMALLY
;
3082 if (STRINGP (it
->string
))
3084 extern Lisp_Object Qinvisible
;
3085 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3087 /* Get the value of the invisible text property at the
3088 current position. Value will be nil if there is no such
3090 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3091 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3094 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3096 handled
= HANDLED_RECOMPUTE_PROPS
;
3098 /* Get the position at which the next change of the
3099 invisible text property can be found in IT->string.
3100 Value will be nil if the property value is the same for
3101 all the rest of IT->string. */
3102 XSETINT (limit
, SCHARS (it
->string
));
3103 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3106 /* Text at current position is invisible. The next
3107 change in the property is at position end_charpos.
3108 Move IT's current position to that position. */
3109 if (INTEGERP (end_charpos
)
3110 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3112 struct text_pos old
;
3113 old
= it
->current
.string_pos
;
3114 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3115 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3119 /* The rest of the string is invisible. If this is an
3120 overlay string, proceed with the next overlay string
3121 or whatever comes and return a character from there. */
3122 if (it
->current
.overlay_string_index
>= 0)
3124 next_overlay_string (it
);
3125 /* Don't check for overlay strings when we just
3126 finished processing them. */
3127 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3131 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3132 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3139 int invis_p
, newpos
, next_stop
, start_charpos
;
3140 Lisp_Object pos
, prop
, overlay
;
3142 /* First of all, is there invisible text at this position? */
3143 start_charpos
= IT_CHARPOS (*it
);
3144 pos
= make_number (IT_CHARPOS (*it
));
3145 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3147 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3149 /* If we are on invisible text, skip over it. */
3150 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3152 /* Record whether we have to display an ellipsis for the
3154 int display_ellipsis_p
= invis_p
== 2;
3156 handled
= HANDLED_RECOMPUTE_PROPS
;
3158 /* Loop skipping over invisible text. The loop is left at
3159 ZV or with IT on the first char being visible again. */
3162 /* Try to skip some invisible text. Return value is the
3163 position reached which can be equal to IT's position
3164 if there is nothing invisible here. This skips both
3165 over invisible text properties and overlays with
3166 invisible property. */
3167 newpos
= skip_invisible (IT_CHARPOS (*it
),
3168 &next_stop
, ZV
, it
->window
);
3170 /* If we skipped nothing at all we weren't at invisible
3171 text in the first place. If everything to the end of
3172 the buffer was skipped, end the loop. */
3173 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3177 /* We skipped some characters but not necessarily
3178 all there are. Check if we ended up on visible
3179 text. Fget_char_property returns the property of
3180 the char before the given position, i.e. if we
3181 get invis_p = 0, this means that the char at
3182 newpos is visible. */
3183 pos
= make_number (newpos
);
3184 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3185 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3188 /* If we ended up on invisible text, proceed to
3189 skip starting with next_stop. */
3191 IT_CHARPOS (*it
) = next_stop
;
3195 /* The position newpos is now either ZV or on visible text. */
3196 IT_CHARPOS (*it
) = newpos
;
3197 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3199 /* If there are before-strings at the start of invisible
3200 text, and the text is invisible because of a text
3201 property, arrange to show before-strings because 20.x did
3202 it that way. (If the text is invisible because of an
3203 overlay property instead of a text property, this is
3204 already handled in the overlay code.) */
3206 && get_overlay_strings (it
, start_charpos
))
3208 handled
= HANDLED_RECOMPUTE_PROPS
;
3209 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3211 else if (display_ellipsis_p
)
3212 setup_for_ellipsis (it
);
3220 /* Make iterator IT return `...' next. */
3223 setup_for_ellipsis (it
)
3227 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3229 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3230 it
->dpvec
= v
->contents
;
3231 it
->dpend
= v
->contents
+ v
->size
;
3235 /* Default `...'. */
3236 it
->dpvec
= default_invis_vector
;
3237 it
->dpend
= default_invis_vector
+ 3;
3240 /* The ellipsis display does not replace the display of the
3241 character at the new position. Indicate this by setting
3242 IT->dpvec_char_len to zero. */
3243 it
->dpvec_char_len
= 0;
3245 it
->current
.dpvec_index
= 0;
3246 it
->method
= next_element_from_display_vector
;
3251 /***********************************************************************
3253 ***********************************************************************/
3255 /* Set up iterator IT from `display' property at its current position.
3256 Called from handle_stop. */
3258 static enum prop_handled
3259 handle_display_prop (it
)
3262 Lisp_Object prop
, object
;
3263 struct text_pos
*position
;
3264 int display_replaced_p
= 0;
3266 if (STRINGP (it
->string
))
3268 object
= it
->string
;
3269 position
= &it
->current
.string_pos
;
3273 object
= it
->w
->buffer
;
3274 position
= &it
->current
.pos
;
3277 /* Reset those iterator values set from display property values. */
3278 it
->font_height
= Qnil
;
3279 it
->space_width
= Qnil
;
3282 /* We don't support recursive `display' properties, i.e. string
3283 values that have a string `display' property, that have a string
3284 `display' property etc. */
3285 if (!it
->string_from_display_prop_p
)
3286 it
->area
= TEXT_AREA
;
3288 prop
= Fget_char_property (make_number (position
->charpos
),
3291 return HANDLED_NORMALLY
;
3294 /* Simple properties. */
3295 && !EQ (XCAR (prop
), Qimage
)
3296 && !EQ (XCAR (prop
), Qspace
)
3297 && !EQ (XCAR (prop
), Qwhen
)
3298 && !EQ (XCAR (prop
), Qspace_width
)
3299 && !EQ (XCAR (prop
), Qheight
)
3300 && !EQ (XCAR (prop
), Qraise
)
3301 /* Marginal area specifications. */
3302 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3303 && !EQ (XCAR (prop
), Qleft_fringe
)
3304 && !EQ (XCAR (prop
), Qright_fringe
)
3305 && !NILP (XCAR (prop
)))
3307 for (; CONSP (prop
); prop
= XCDR (prop
))
3309 if (handle_single_display_prop (it
, XCAR (prop
), object
,
3310 position
, display_replaced_p
))
3311 display_replaced_p
= 1;
3314 else if (VECTORP (prop
))
3317 for (i
= 0; i
< ASIZE (prop
); ++i
)
3318 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
3319 position
, display_replaced_p
))
3320 display_replaced_p
= 1;
3324 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
3325 display_replaced_p
= 1;
3328 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3332 /* Value is the position of the end of the `display' property starting
3333 at START_POS in OBJECT. */
3335 static struct text_pos
3336 display_prop_end (it
, object
, start_pos
)
3339 struct text_pos start_pos
;
3342 struct text_pos end_pos
;
3344 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3345 Qdisplay
, object
, Qnil
);
3346 CHARPOS (end_pos
) = XFASTINT (end
);
3347 if (STRINGP (object
))
3348 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3350 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3356 /* Set up IT from a single `display' sub-property value PROP. OBJECT
3357 is the object in which the `display' property was found. *POSITION
3358 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3359 means that we previously saw a display sub-property which already
3360 replaced text display with something else, for example an image;
3361 ignore such properties after the first one has been processed.
3363 If PROP is a `space' or `image' sub-property, set *POSITION to the
3364 end position of the `display' property.
3366 Value is non-zero if something was found which replaces the display
3367 of buffer or string text. */
3370 handle_single_display_prop (it
, prop
, object
, position
,
3371 display_replaced_before_p
)
3375 struct text_pos
*position
;
3376 int display_replaced_before_p
;
3379 int replaces_text_display_p
= 0;
3382 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
3383 evaluated. If the result is nil, VALUE is ignored. */
3385 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3394 if (!NILP (form
) && !EQ (form
, Qt
))
3396 int count
= SPECPDL_INDEX ();
3397 struct gcpro gcpro1
;
3399 /* Bind `object' to the object having the `display' property, a
3400 buffer or string. Bind `position' to the position in the
3401 object where the property was found, and `buffer-position'
3402 to the current position in the buffer. */
3403 specbind (Qobject
, object
);
3404 specbind (Qposition
, make_number (CHARPOS (*position
)));
3405 specbind (Qbuffer_position
,
3406 make_number (STRINGP (object
)
3407 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3409 form
= safe_eval (form
);
3411 unbind_to (count
, Qnil
);
3418 && EQ (XCAR (prop
), Qheight
)
3419 && CONSP (XCDR (prop
)))
3421 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3424 /* `(height HEIGHT)'. */
3425 it
->font_height
= XCAR (XCDR (prop
));
3426 if (!NILP (it
->font_height
))
3428 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3429 int new_height
= -1;
3431 if (CONSP (it
->font_height
)
3432 && (EQ (XCAR (it
->font_height
), Qplus
)
3433 || EQ (XCAR (it
->font_height
), Qminus
))
3434 && CONSP (XCDR (it
->font_height
))
3435 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3437 /* `(+ N)' or `(- N)' where N is an integer. */
3438 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3439 if (EQ (XCAR (it
->font_height
), Qplus
))
3441 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3443 else if (FUNCTIONP (it
->font_height
))
3445 /* Call function with current height as argument.
3446 Value is the new height. */
3448 height
= safe_call1 (it
->font_height
,
3449 face
->lface
[LFACE_HEIGHT_INDEX
]);
3450 if (NUMBERP (height
))
3451 new_height
= XFLOATINT (height
);
3453 else if (NUMBERP (it
->font_height
))
3455 /* Value is a multiple of the canonical char height. */
3458 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3459 new_height
= (XFLOATINT (it
->font_height
)
3460 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3464 /* Evaluate IT->font_height with `height' bound to the
3465 current specified height to get the new height. */
3467 int count
= SPECPDL_INDEX ();
3469 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3470 value
= safe_eval (it
->font_height
);
3471 unbind_to (count
, Qnil
);
3473 if (NUMBERP (value
))
3474 new_height
= XFLOATINT (value
);
3478 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3481 else if (CONSP (prop
)
3482 && EQ (XCAR (prop
), Qspace_width
)
3483 && CONSP (XCDR (prop
)))
3485 /* `(space_width WIDTH)'. */
3486 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3489 value
= XCAR (XCDR (prop
));
3490 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3491 it
->space_width
= value
;
3493 else if (CONSP (prop
)
3494 && EQ (XCAR (prop
), Qraise
)
3495 && CONSP (XCDR (prop
)))
3497 /* `(raise FACTOR)'. */
3498 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3501 #ifdef HAVE_WINDOW_SYSTEM
3502 value
= XCAR (XCDR (prop
));
3503 if (NUMBERP (value
))
3505 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3506 it
->voffset
= - (XFLOATINT (value
)
3507 * (FONT_HEIGHT (face
->font
)));
3509 #endif /* HAVE_WINDOW_SYSTEM */
3511 else if (!it
->string_from_display_prop_p
)
3513 /* `((margin left-margin) VALUE)' or `((margin right-margin)
3514 VALUE) or `((margin nil) VALUE)' or VALUE. */
3515 Lisp_Object location
, value
;
3516 struct text_pos start_pos
;
3519 /* Characters having this form of property are not displayed, so
3520 we have to find the end of the property. */
3521 start_pos
= *position
;
3522 *position
= display_prop_end (it
, object
, start_pos
);
3525 /* Let's stop at the new position and assume that all
3526 text properties change there. */
3527 it
->stop_charpos
= position
->charpos
;
3530 && (EQ (XCAR (prop
), Qleft_fringe
)
3531 || EQ (XCAR (prop
), Qright_fringe
))
3532 && CONSP (XCDR (prop
)))
3534 unsigned face_id
= DEFAULT_FACE_ID
;
3536 /* Save current settings of IT so that we can restore them
3537 when we are finished with the glyph property value. */
3539 /* `(left-fringe BITMAP FACE)'. */
3540 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3543 #ifdef HAVE_WINDOW_SYSTEM
3544 value
= XCAR (XCDR (prop
));
3545 if (!NUMBERP (value
)
3546 || !valid_fringe_bitmap_id_p (XINT (value
)))
3549 if (CONSP (XCDR (XCDR (prop
))))
3551 Lisp_Object face_name
= XCAR (XCDR (XCDR (prop
)));
3553 face_id
= lookup_named_face (it
->f
, face_name
, 'A');
3560 it
->area
= TEXT_AREA
;
3561 it
->what
= IT_IMAGE
;
3562 it
->image_id
= -1; /* no image */
3563 it
->position
= start_pos
;
3564 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3565 it
->method
= next_element_from_image
;
3566 it
->face_id
= face_id
;
3568 /* Say that we haven't consumed the characters with
3569 `display' property yet. The call to pop_it in
3570 set_iterator_to_next will clean this up. */
3571 *position
= start_pos
;
3573 if (EQ (XCAR (prop
), Qleft_fringe
))
3575 it
->left_user_fringe_bitmap
= XINT (value
);
3576 it
->left_user_fringe_face_id
= face_id
;
3580 it
->right_user_fringe_bitmap
= XINT (value
);
3581 it
->right_user_fringe_face_id
= face_id
;
3583 #endif /* HAVE_WINDOW_SYSTEM */
3587 location
= Qunbound
;
3588 if (CONSP (prop
) && CONSP (XCAR (prop
)))
3592 value
= XCDR (prop
);
3594 value
= XCAR (value
);
3597 if (EQ (XCAR (tem
), Qmargin
)
3598 && (tem
= XCDR (tem
),
3599 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3601 || EQ (tem
, Qleft_margin
)
3602 || EQ (tem
, Qright_margin
))))
3606 if (EQ (location
, Qunbound
))
3612 valid_p
= (STRINGP (value
)
3613 #ifdef HAVE_WINDOW_SYSTEM
3614 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
3615 #endif /* not HAVE_WINDOW_SYSTEM */
3616 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
3618 if ((EQ (location
, Qleft_margin
)
3619 || EQ (location
, Qright_margin
)
3622 && !display_replaced_before_p
)
3624 replaces_text_display_p
= 1;
3626 /* Save current settings of IT so that we can restore them
3627 when we are finished with the glyph property value. */
3630 if (NILP (location
))
3631 it
->area
= TEXT_AREA
;
3632 else if (EQ (location
, Qleft_margin
))
3633 it
->area
= LEFT_MARGIN_AREA
;
3635 it
->area
= RIGHT_MARGIN_AREA
;
3637 if (STRINGP (value
))
3640 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3641 it
->current
.overlay_string_index
= -1;
3642 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3643 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3644 it
->method
= next_element_from_string
;
3645 it
->stop_charpos
= 0;
3646 it
->string_from_display_prop_p
= 1;
3647 /* Say that we haven't consumed the characters with
3648 `display' property yet. The call to pop_it in
3649 set_iterator_to_next will clean this up. */
3650 *position
= start_pos
;
3652 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3654 it
->method
= next_element_from_stretch
;
3656 it
->current
.pos
= it
->position
= start_pos
;
3658 #ifdef HAVE_WINDOW_SYSTEM
3661 it
->what
= IT_IMAGE
;
3662 it
->image_id
= lookup_image (it
->f
, value
);
3663 it
->position
= start_pos
;
3664 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3665 it
->method
= next_element_from_image
;
3667 /* Say that we haven't consumed the characters with
3668 `display' property yet. The call to pop_it in
3669 set_iterator_to_next will clean this up. */
3670 *position
= start_pos
;
3672 #endif /* HAVE_WINDOW_SYSTEM */
3675 /* Invalid property or property not supported. Restore
3676 the position to what it was before. */
3677 *position
= start_pos
;
3680 return replaces_text_display_p
;
3684 /* Check if PROP is a display sub-property value whose text should be
3685 treated as intangible. */
3688 single_display_prop_intangible_p (prop
)
3691 /* Skip over `when FORM'. */
3692 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3706 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3707 we don't need to treat text as intangible. */
3708 if (EQ (XCAR (prop
), Qmargin
))
3716 || EQ (XCAR (prop
), Qleft_margin
)
3717 || EQ (XCAR (prop
), Qright_margin
))
3721 return (CONSP (prop
)
3722 && (EQ (XCAR (prop
), Qimage
)
3723 || EQ (XCAR (prop
), Qspace
)));
3727 /* Check if PROP is a display property value whose text should be
3728 treated as intangible. */
3731 display_prop_intangible_p (prop
)
3735 && CONSP (XCAR (prop
))
3736 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3738 /* A list of sub-properties. */
3739 while (CONSP (prop
))
3741 if (single_display_prop_intangible_p (XCAR (prop
)))
3746 else if (VECTORP (prop
))
3748 /* A vector of sub-properties. */
3750 for (i
= 0; i
< ASIZE (prop
); ++i
)
3751 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3755 return single_display_prop_intangible_p (prop
);
3761 /* Return 1 if PROP is a display sub-property value containing STRING. */
3764 single_display_prop_string_p (prop
, string
)
3765 Lisp_Object prop
, string
;
3767 if (EQ (string
, prop
))
3770 /* Skip over `when FORM'. */
3771 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3780 /* Skip over `margin LOCATION'. */
3781 if (EQ (XCAR (prop
), Qmargin
))
3792 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3796 /* Return 1 if STRING appears in the `display' property PROP. */
3799 display_prop_string_p (prop
, string
)
3800 Lisp_Object prop
, string
;
3803 && CONSP (XCAR (prop
))
3804 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3806 /* A list of sub-properties. */
3807 while (CONSP (prop
))
3809 if (single_display_prop_string_p (XCAR (prop
), string
))
3814 else if (VECTORP (prop
))
3816 /* A vector of sub-properties. */
3818 for (i
= 0; i
< ASIZE (prop
); ++i
)
3819 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3823 return single_display_prop_string_p (prop
, string
);
3829 /* Determine from which buffer position in W's buffer STRING comes
3830 from. AROUND_CHARPOS is an approximate position where it could
3831 be from. Value is the buffer position or 0 if it couldn't be
3834 W's buffer must be current.
3836 This function is necessary because we don't record buffer positions
3837 in glyphs generated from strings (to keep struct glyph small).
3838 This function may only use code that doesn't eval because it is
3839 called asynchronously from note_mouse_highlight. */
3842 string_buffer_position (w
, string
, around_charpos
)
3847 Lisp_Object limit
, prop
, pos
;
3848 const int MAX_DISTANCE
= 1000;
3851 pos
= make_number (around_charpos
);
3852 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3853 while (!found
&& !EQ (pos
, limit
))
3855 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3856 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3859 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3864 pos
= make_number (around_charpos
);
3865 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3866 while (!found
&& !EQ (pos
, limit
))
3868 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3869 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3872 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3877 return found
? XINT (pos
) : 0;
3882 /***********************************************************************
3883 `composition' property
3884 ***********************************************************************/
3886 /* Set up iterator IT from `composition' property at its current
3887 position. Called from handle_stop. */
3889 static enum prop_handled
3890 handle_composition_prop (it
)
3893 Lisp_Object prop
, string
;
3894 int pos
, pos_byte
, end
;
3895 enum prop_handled handled
= HANDLED_NORMALLY
;
3897 if (STRINGP (it
->string
))
3899 pos
= IT_STRING_CHARPOS (*it
);
3900 pos_byte
= IT_STRING_BYTEPOS (*it
);
3901 string
= it
->string
;
3905 pos
= IT_CHARPOS (*it
);
3906 pos_byte
= IT_BYTEPOS (*it
);
3910 /* If there's a valid composition and point is not inside of the
3911 composition (in the case that the composition is from the current
3912 buffer), draw a glyph composed from the composition components. */
3913 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3914 && COMPOSITION_VALID_P (pos
, end
, prop
)
3915 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3917 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3921 it
->method
= next_element_from_composition
;
3923 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3924 /* For a terminal, draw only the first character of the
3926 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3927 it
->len
= (STRINGP (it
->string
)
3928 ? string_char_to_byte (it
->string
, end
)
3929 : CHAR_TO_BYTE (end
)) - pos_byte
;
3930 it
->stop_charpos
= end
;
3931 handled
= HANDLED_RETURN
;
3940 /***********************************************************************
3942 ***********************************************************************/
3944 /* The following structure is used to record overlay strings for
3945 later sorting in load_overlay_strings. */
3947 struct overlay_entry
3949 Lisp_Object overlay
;
3956 /* Set up iterator IT from overlay strings at its current position.
3957 Called from handle_stop. */
3959 static enum prop_handled
3960 handle_overlay_change (it
)
3963 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
3964 return HANDLED_RECOMPUTE_PROPS
;
3966 return HANDLED_NORMALLY
;
3970 /* Set up the next overlay string for delivery by IT, if there is an
3971 overlay string to deliver. Called by set_iterator_to_next when the
3972 end of the current overlay string is reached. If there are more
3973 overlay strings to display, IT->string and
3974 IT->current.overlay_string_index are set appropriately here.
3975 Otherwise IT->string is set to nil. */
3978 next_overlay_string (it
)
3981 ++it
->current
.overlay_string_index
;
3982 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3984 /* No more overlay strings. Restore IT's settings to what
3985 they were before overlay strings were processed, and
3986 continue to deliver from current_buffer. */
3987 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
3990 xassert (it
->stop_charpos
>= BEGV
3991 && it
->stop_charpos
<= it
->end_charpos
);
3993 it
->current
.overlay_string_index
= -1;
3994 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3995 it
->n_overlay_strings
= 0;
3996 it
->method
= next_element_from_buffer
;
3998 /* If we're at the end of the buffer, record that we have
3999 processed the overlay strings there already, so that
4000 next_element_from_buffer doesn't try it again. */
4001 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4002 it
->overlay_strings_at_end_processed_p
= 1;
4004 /* If we have to display `...' for invisible text, set
4005 the iterator up for that. */
4006 if (display_ellipsis_p
)
4007 setup_for_ellipsis (it
);
4011 /* There are more overlay strings to process. If
4012 IT->current.overlay_string_index has advanced to a position
4013 where we must load IT->overlay_strings with more strings, do
4015 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4017 if (it
->current
.overlay_string_index
&& i
== 0)
4018 load_overlay_strings (it
, 0);
4020 /* Initialize IT to deliver display elements from the overlay
4022 it
->string
= it
->overlay_strings
[i
];
4023 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4024 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4025 it
->method
= next_element_from_string
;
4026 it
->stop_charpos
= 0;
4033 /* Compare two overlay_entry structures E1 and E2. Used as a
4034 comparison function for qsort in load_overlay_strings. Overlay
4035 strings for the same position are sorted so that
4037 1. All after-strings come in front of before-strings, except
4038 when they come from the same overlay.
4040 2. Within after-strings, strings are sorted so that overlay strings
4041 from overlays with higher priorities come first.
4043 2. Within before-strings, strings are sorted so that overlay
4044 strings from overlays with higher priorities come last.
4046 Value is analogous to strcmp. */
4050 compare_overlay_entries (e1
, e2
)
4053 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4054 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4057 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4059 /* Let after-strings appear in front of before-strings if
4060 they come from different overlays. */
4061 if (EQ (entry1
->overlay
, entry2
->overlay
))
4062 result
= entry1
->after_string_p
? 1 : -1;
4064 result
= entry1
->after_string_p
? -1 : 1;
4066 else if (entry1
->after_string_p
)
4067 /* After-strings sorted in order of decreasing priority. */
4068 result
= entry2
->priority
- entry1
->priority
;
4070 /* Before-strings sorted in order of increasing priority. */
4071 result
= entry1
->priority
- entry2
->priority
;
4077 /* Load the vector IT->overlay_strings with overlay strings from IT's
4078 current buffer position, or from CHARPOS if that is > 0. Set
4079 IT->n_overlays to the total number of overlay strings found.
4081 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4082 a time. On entry into load_overlay_strings,
4083 IT->current.overlay_string_index gives the number of overlay
4084 strings that have already been loaded by previous calls to this
4087 IT->add_overlay_start contains an additional overlay start
4088 position to consider for taking overlay strings from, if non-zero.
4089 This position comes into play when the overlay has an `invisible'
4090 property, and both before and after-strings. When we've skipped to
4091 the end of the overlay, because of its `invisible' property, we
4092 nevertheless want its before-string to appear.
4093 IT->add_overlay_start will contain the overlay start position
4096 Overlay strings are sorted so that after-string strings come in
4097 front of before-string strings. Within before and after-strings,
4098 strings are sorted by overlay priority. See also function
4099 compare_overlay_entries. */
4102 load_overlay_strings (it
, charpos
)
4106 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4107 Lisp_Object overlay
, window
, str
, invisible
;
4108 struct Lisp_Overlay
*ov
;
4111 int n
= 0, i
, j
, invis_p
;
4112 struct overlay_entry
*entries
4113 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4116 charpos
= IT_CHARPOS (*it
);
4118 /* Append the overlay string STRING of overlay OVERLAY to vector
4119 `entries' which has size `size' and currently contains `n'
4120 elements. AFTER_P non-zero means STRING is an after-string of
4122 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4125 Lisp_Object priority; \
4129 int new_size = 2 * size; \
4130 struct overlay_entry *old = entries; \
4132 (struct overlay_entry *) alloca (new_size \
4133 * sizeof *entries); \
4134 bcopy (old, entries, size * sizeof *entries); \
4138 entries[n].string = (STRING); \
4139 entries[n].overlay = (OVERLAY); \
4140 priority = Foverlay_get ((OVERLAY), Qpriority); \
4141 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4142 entries[n].after_string_p = (AFTER_P); \
4147 /* Process overlay before the overlay center. */
4148 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4150 XSETMISC (overlay
, ov
);
4151 xassert (OVERLAYP (overlay
));
4152 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4153 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4158 /* Skip this overlay if it doesn't start or end at IT's current
4160 if (end
!= charpos
&& start
!= charpos
)
4163 /* Skip this overlay if it doesn't apply to IT->w. */
4164 window
= Foverlay_get (overlay
, Qwindow
);
4165 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4168 /* If the text ``under'' the overlay is invisible, both before-
4169 and after-strings from this overlay are visible; start and
4170 end position are indistinguishable. */
4171 invisible
= Foverlay_get (overlay
, Qinvisible
);
4172 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4174 /* If overlay has a non-empty before-string, record it. */
4175 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4176 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4178 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4180 /* If overlay has a non-empty after-string, record it. */
4181 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4182 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4184 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4187 /* Process overlays after the overlay center. */
4188 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4190 XSETMISC (overlay
, ov
);
4191 xassert (OVERLAYP (overlay
));
4192 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4193 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4195 if (start
> charpos
)
4198 /* Skip this overlay if it doesn't start or end at IT's current
4200 if (end
!= charpos
&& start
!= charpos
)
4203 /* Skip this overlay if it doesn't apply to IT->w. */
4204 window
= Foverlay_get (overlay
, Qwindow
);
4205 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4208 /* If the text ``under'' the overlay is invisible, it has a zero
4209 dimension, and both before- and after-strings apply. */
4210 invisible
= Foverlay_get (overlay
, Qinvisible
);
4211 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4213 /* If overlay has a non-empty before-string, record it. */
4214 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4215 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4217 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4219 /* If overlay has a non-empty after-string, record it. */
4220 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4221 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4223 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4226 #undef RECORD_OVERLAY_STRING
4230 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4232 /* Record the total number of strings to process. */
4233 it
->n_overlay_strings
= n
;
4235 /* IT->current.overlay_string_index is the number of overlay strings
4236 that have already been consumed by IT. Copy some of the
4237 remaining overlay strings to IT->overlay_strings. */
4239 j
= it
->current
.overlay_string_index
;
4240 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4241 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4247 /* Get the first chunk of overlay strings at IT's current buffer
4248 position, or at CHARPOS if that is > 0. Value is non-zero if at
4249 least one overlay string was found. */
4252 get_overlay_strings (it
, charpos
)
4256 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4257 process. This fills IT->overlay_strings with strings, and sets
4258 IT->n_overlay_strings to the total number of strings to process.
4259 IT->pos.overlay_string_index has to be set temporarily to zero
4260 because load_overlay_strings needs this; it must be set to -1
4261 when no overlay strings are found because a zero value would
4262 indicate a position in the first overlay string. */
4263 it
->current
.overlay_string_index
= 0;
4264 load_overlay_strings (it
, charpos
);
4266 /* If we found overlay strings, set up IT to deliver display
4267 elements from the first one. Otherwise set up IT to deliver
4268 from current_buffer. */
4269 if (it
->n_overlay_strings
)
4271 /* Make sure we know settings in current_buffer, so that we can
4272 restore meaningful values when we're done with the overlay
4274 compute_stop_pos (it
);
4275 xassert (it
->face_id
>= 0);
4277 /* Save IT's settings. They are restored after all overlay
4278 strings have been processed. */
4279 xassert (it
->sp
== 0);
4282 /* Set up IT to deliver display elements from the first overlay
4284 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4285 it
->string
= it
->overlay_strings
[0];
4286 it
->stop_charpos
= 0;
4287 xassert (STRINGP (it
->string
));
4288 it
->end_charpos
= SCHARS (it
->string
);
4289 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4290 it
->method
= next_element_from_string
;
4295 it
->current
.overlay_string_index
= -1;
4296 it
->method
= next_element_from_buffer
;
4301 /* Value is non-zero if we found at least one overlay string. */
4302 return STRINGP (it
->string
);
4307 /***********************************************************************
4308 Saving and restoring state
4309 ***********************************************************************/
4311 /* Save current settings of IT on IT->stack. Called, for example,
4312 before setting up IT for an overlay string, to be able to restore
4313 IT's settings to what they were after the overlay string has been
4320 struct iterator_stack_entry
*p
;
4322 xassert (it
->sp
< 2);
4323 p
= it
->stack
+ it
->sp
;
4325 p
->stop_charpos
= it
->stop_charpos
;
4326 xassert (it
->face_id
>= 0);
4327 p
->face_id
= it
->face_id
;
4328 p
->string
= it
->string
;
4329 p
->pos
= it
->current
;
4330 p
->end_charpos
= it
->end_charpos
;
4331 p
->string_nchars
= it
->string_nchars
;
4333 p
->multibyte_p
= it
->multibyte_p
;
4334 p
->space_width
= it
->space_width
;
4335 p
->font_height
= it
->font_height
;
4336 p
->voffset
= it
->voffset
;
4337 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4338 p
->display_ellipsis_p
= 0;
4343 /* Restore IT's settings from IT->stack. Called, for example, when no
4344 more overlay strings must be processed, and we return to delivering
4345 display elements from a buffer, or when the end of a string from a
4346 `display' property is reached and we return to delivering display
4347 elements from an overlay string, or from a buffer. */
4353 struct iterator_stack_entry
*p
;
4355 xassert (it
->sp
> 0);
4357 p
= it
->stack
+ it
->sp
;
4358 it
->stop_charpos
= p
->stop_charpos
;
4359 it
->face_id
= p
->face_id
;
4360 it
->string
= p
->string
;
4361 it
->current
= p
->pos
;
4362 it
->end_charpos
= p
->end_charpos
;
4363 it
->string_nchars
= p
->string_nchars
;
4365 it
->multibyte_p
= p
->multibyte_p
;
4366 it
->space_width
= p
->space_width
;
4367 it
->font_height
= p
->font_height
;
4368 it
->voffset
= p
->voffset
;
4369 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4374 /***********************************************************************
4376 ***********************************************************************/
4378 /* Set IT's current position to the previous line start. */
4381 back_to_previous_line_start (it
)
4384 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4385 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4389 /* Move IT to the next line start.
4391 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4392 we skipped over part of the text (as opposed to moving the iterator
4393 continuously over the text). Otherwise, don't change the value
4396 Newlines may come from buffer text, overlay strings, or strings
4397 displayed via the `display' property. That's the reason we can't
4398 simply use find_next_newline_no_quit.
4400 Note that this function may not skip over invisible text that is so
4401 because of text properties and immediately follows a newline. If
4402 it would, function reseat_at_next_visible_line_start, when called
4403 from set_iterator_to_next, would effectively make invisible
4404 characters following a newline part of the wrong glyph row, which
4405 leads to wrong cursor motion. */
4408 forward_to_next_line_start (it
, skipped_p
)
4412 int old_selective
, newline_found_p
, n
;
4413 const int MAX_NEWLINE_DISTANCE
= 500;
4415 /* If already on a newline, just consume it to avoid unintended
4416 skipping over invisible text below. */
4417 if (it
->what
== IT_CHARACTER
4419 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4421 set_iterator_to_next (it
, 0);
4426 /* Don't handle selective display in the following. It's (a)
4427 unnecessary because it's done by the caller, and (b) leads to an
4428 infinite recursion because next_element_from_ellipsis indirectly
4429 calls this function. */
4430 old_selective
= it
->selective
;
4433 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4434 from buffer text. */
4435 for (n
= newline_found_p
= 0;
4436 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4437 n
+= STRINGP (it
->string
) ? 0 : 1)
4439 if (!get_next_display_element (it
))
4441 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4442 set_iterator_to_next (it
, 0);
4445 /* If we didn't find a newline near enough, see if we can use a
4447 if (!newline_found_p
)
4449 int start
= IT_CHARPOS (*it
);
4450 int limit
= find_next_newline_no_quit (start
, 1);
4453 xassert (!STRINGP (it
->string
));
4455 /* If there isn't any `display' property in sight, and no
4456 overlays, we can just use the position of the newline in
4458 if (it
->stop_charpos
>= limit
4459 || ((pos
= Fnext_single_property_change (make_number (start
),
4461 Qnil
, make_number (limit
)),
4463 && next_overlay_change (start
) == ZV
))
4465 IT_CHARPOS (*it
) = limit
;
4466 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4467 *skipped_p
= newline_found_p
= 1;
4471 while (get_next_display_element (it
)
4472 && !newline_found_p
)
4474 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4475 set_iterator_to_next (it
, 0);
4480 it
->selective
= old_selective
;
4481 return newline_found_p
;
4485 /* Set IT's current position to the previous visible line start. Skip
4486 invisible text that is so either due to text properties or due to
4487 selective display. Caution: this does not change IT->current_x and
4491 back_to_previous_visible_line_start (it
)
4496 /* Go back one newline if not on BEGV already. */
4497 if (IT_CHARPOS (*it
) > BEGV
)
4498 back_to_previous_line_start (it
);
4500 /* Move over lines that are invisible because of selective display
4501 or text properties. */
4502 while (IT_CHARPOS (*it
) > BEGV
4507 /* If selective > 0, then lines indented more than that values
4509 if (it
->selective
> 0
4510 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4511 (double) it
->selective
)) /* iftc */
4517 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
4518 Qinvisible
, it
->window
);
4519 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4523 /* Back one more newline if the current one is invisible. */
4525 back_to_previous_line_start (it
);
4528 xassert (IT_CHARPOS (*it
) >= BEGV
);
4529 xassert (IT_CHARPOS (*it
) == BEGV
4530 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4535 /* Reseat iterator IT at the previous visible line start. Skip
4536 invisible text that is so either due to text properties or due to
4537 selective display. At the end, update IT's overlay information,
4538 face information etc. */
4541 reseat_at_previous_visible_line_start (it
)
4544 back_to_previous_visible_line_start (it
);
4545 reseat (it
, it
->current
.pos
, 1);
4550 /* Reseat iterator IT on the next visible line start in the current
4551 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4552 preceding the line start. Skip over invisible text that is so
4553 because of selective display. Compute faces, overlays etc at the
4554 new position. Note that this function does not skip over text that
4555 is invisible because of text properties. */
4558 reseat_at_next_visible_line_start (it
, on_newline_p
)
4562 int newline_found_p
, skipped_p
= 0;
4564 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4566 /* Skip over lines that are invisible because they are indented
4567 more than the value of IT->selective. */
4568 if (it
->selective
> 0)
4569 while (IT_CHARPOS (*it
) < ZV
4570 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4571 (double) it
->selective
)) /* iftc */
4573 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4574 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4577 /* Position on the newline if that's what's requested. */
4578 if (on_newline_p
&& newline_found_p
)
4580 if (STRINGP (it
->string
))
4582 if (IT_STRING_CHARPOS (*it
) > 0)
4584 --IT_STRING_CHARPOS (*it
);
4585 --IT_STRING_BYTEPOS (*it
);
4588 else if (IT_CHARPOS (*it
) > BEGV
)
4592 reseat (it
, it
->current
.pos
, 0);
4596 reseat (it
, it
->current
.pos
, 0);
4603 /***********************************************************************
4604 Changing an iterator's position
4605 ***********************************************************************/
4607 /* Change IT's current position to POS in current_buffer. If FORCE_P
4608 is non-zero, always check for text properties at the new position.
4609 Otherwise, text properties are only looked up if POS >=
4610 IT->check_charpos of a property. */
4613 reseat (it
, pos
, force_p
)
4615 struct text_pos pos
;
4618 int original_pos
= IT_CHARPOS (*it
);
4620 reseat_1 (it
, pos
, 0);
4622 /* Determine where to check text properties. Avoid doing it
4623 where possible because text property lookup is very expensive. */
4625 || CHARPOS (pos
) > it
->stop_charpos
4626 || CHARPOS (pos
) < original_pos
)
4633 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4634 IT->stop_pos to POS, also. */
4637 reseat_1 (it
, pos
, set_stop_p
)
4639 struct text_pos pos
;
4642 /* Don't call this function when scanning a C string. */
4643 xassert (it
->s
== NULL
);
4645 /* POS must be a reasonable value. */
4646 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4648 it
->current
.pos
= it
->position
= pos
;
4649 XSETBUFFER (it
->object
, current_buffer
);
4650 it
->end_charpos
= ZV
;
4652 it
->current
.dpvec_index
= -1;
4653 it
->current
.overlay_string_index
= -1;
4654 IT_STRING_CHARPOS (*it
) = -1;
4655 IT_STRING_BYTEPOS (*it
) = -1;
4657 it
->method
= next_element_from_buffer
;
4658 /* RMS: I added this to fix a bug in move_it_vertically_backward
4659 where it->area continued to relate to the starting point
4660 for the backward motion. Bug report from
4661 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
4662 However, I am not sure whether reseat still does the right thing
4663 in general after this change. */
4664 it
->area
= TEXT_AREA
;
4665 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4667 it
->face_before_selective_p
= 0;
4670 it
->stop_charpos
= CHARPOS (pos
);
4674 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4675 If S is non-null, it is a C string to iterate over. Otherwise,
4676 STRING gives a Lisp string to iterate over.
4678 If PRECISION > 0, don't return more then PRECISION number of
4679 characters from the string.
4681 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4682 characters have been returned. FIELD_WIDTH < 0 means an infinite
4685 MULTIBYTE = 0 means disable processing of multibyte characters,
4686 MULTIBYTE > 0 means enable it,
4687 MULTIBYTE < 0 means use IT->multibyte_p.
4689 IT must be initialized via a prior call to init_iterator before
4690 calling this function. */
4693 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4698 int precision
, field_width
, multibyte
;
4700 /* No region in strings. */
4701 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4703 /* No text property checks performed by default, but see below. */
4704 it
->stop_charpos
= -1;
4706 /* Set iterator position and end position. */
4707 bzero (&it
->current
, sizeof it
->current
);
4708 it
->current
.overlay_string_index
= -1;
4709 it
->current
.dpvec_index
= -1;
4710 xassert (charpos
>= 0);
4712 /* If STRING is specified, use its multibyteness, otherwise use the
4713 setting of MULTIBYTE, if specified. */
4715 it
->multibyte_p
= multibyte
> 0;
4719 xassert (STRINGP (string
));
4720 it
->string
= string
;
4722 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4723 it
->method
= next_element_from_string
;
4724 it
->current
.string_pos
= string_pos (charpos
, string
);
4731 /* Note that we use IT->current.pos, not it->current.string_pos,
4732 for displaying C strings. */
4733 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4734 if (it
->multibyte_p
)
4736 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4737 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4741 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4742 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4745 it
->method
= next_element_from_c_string
;
4748 /* PRECISION > 0 means don't return more than PRECISION characters
4750 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4751 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4753 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4754 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4755 FIELD_WIDTH < 0 means infinite field width. This is useful for
4756 padding with `-' at the end of a mode line. */
4757 if (field_width
< 0)
4758 field_width
= INFINITY
;
4759 if (field_width
> it
->end_charpos
- charpos
)
4760 it
->end_charpos
= charpos
+ field_width
;
4762 /* Use the standard display table for displaying strings. */
4763 if (DISP_TABLE_P (Vstandard_display_table
))
4764 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4766 it
->stop_charpos
= charpos
;
4772 /***********************************************************************
4774 ***********************************************************************/
4776 /* Load IT's display element fields with information about the next
4777 display element from the current position of IT. Value is zero if
4778 end of buffer (or C string) is reached. */
4781 get_next_display_element (it
)
4784 /* Non-zero means that we found a display element. Zero means that
4785 we hit the end of what we iterate over. Performance note: the
4786 function pointer `method' used here turns out to be faster than
4787 using a sequence of if-statements. */
4788 int success_p
= (*it
->method
) (it
);
4790 if (it
->what
== IT_CHARACTER
)
4792 /* Map via display table or translate control characters.
4793 IT->c, IT->len etc. have been set to the next character by
4794 the function call above. If we have a display table, and it
4795 contains an entry for IT->c, translate it. Don't do this if
4796 IT->c itself comes from a display table, otherwise we could
4797 end up in an infinite recursion. (An alternative could be to
4798 count the recursion depth of this function and signal an
4799 error when a certain maximum depth is reached.) Is it worth
4801 if (success_p
&& it
->dpvec
== NULL
)
4806 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4809 struct Lisp_Vector
*v
= XVECTOR (dv
);
4811 /* Return the first character from the display table
4812 entry, if not empty. If empty, don't display the
4813 current character. */
4816 it
->dpvec_char_len
= it
->len
;
4817 it
->dpvec
= v
->contents
;
4818 it
->dpend
= v
->contents
+ v
->size
;
4819 it
->current
.dpvec_index
= 0;
4820 it
->method
= next_element_from_display_vector
;
4821 success_p
= get_next_display_element (it
);
4825 set_iterator_to_next (it
, 0);
4826 success_p
= get_next_display_element (it
);
4830 /* Translate control characters into `\003' or `^C' form.
4831 Control characters coming from a display table entry are
4832 currently not translated because we use IT->dpvec to hold
4833 the translation. This could easily be changed but I
4834 don't believe that it is worth doing.
4836 If it->multibyte_p is nonzero, eight-bit characters and
4837 non-printable multibyte characters are also translated to
4840 If it->multibyte_p is zero, eight-bit characters that
4841 don't have corresponding multibyte char code are also
4842 translated to octal form. */
4843 else if ((it
->c
< ' '
4844 && (it
->area
!= TEXT_AREA
4845 || (it
->c
!= '\n' && it
->c
!= '\t')))
4849 || !CHAR_PRINTABLE_P (it
->c
))
4851 && it
->c
== unibyte_char_to_multibyte (it
->c
))))
4853 /* IT->c is a control character which must be displayed
4854 either as '\003' or as `^C' where the '\\' and '^'
4855 can be defined in the display table. Fill
4856 IT->ctl_chars with glyphs for what we have to
4857 display. Then, set IT->dpvec to these glyphs. */
4860 if (it
->c
< 128 && it
->ctl_arrow_p
)
4862 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4864 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4865 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4866 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4868 g
= FAST_MAKE_GLYPH ('^', 0);
4869 XSETINT (it
->ctl_chars
[0], g
);
4871 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4872 XSETINT (it
->ctl_chars
[1], g
);
4874 /* Set up IT->dpvec and return first character from it. */
4875 it
->dpvec_char_len
= it
->len
;
4876 it
->dpvec
= it
->ctl_chars
;
4877 it
->dpend
= it
->dpvec
+ 2;
4878 it
->current
.dpvec_index
= 0;
4879 it
->method
= next_element_from_display_vector
;
4880 get_next_display_element (it
);
4884 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4889 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4891 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4892 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4893 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4895 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4897 if (SINGLE_BYTE_CHAR_P (it
->c
))
4898 str
[0] = it
->c
, len
= 1;
4901 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4904 /* It's an invalid character, which
4905 shouldn't happen actually, but due to
4906 bugs it may happen. Let's print the char
4907 as is, there's not much meaningful we can
4910 str
[1] = it
->c
>> 8;
4911 str
[2] = it
->c
>> 16;
4912 str
[3] = it
->c
>> 24;
4917 for (i
= 0; i
< len
; i
++)
4919 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4920 /* Insert three more glyphs into IT->ctl_chars for
4921 the octal display of the character. */
4922 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4923 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4924 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4925 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4926 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4927 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4930 /* Set up IT->dpvec and return the first character
4932 it
->dpvec_char_len
= it
->len
;
4933 it
->dpvec
= it
->ctl_chars
;
4934 it
->dpend
= it
->dpvec
+ len
* 4;
4935 it
->current
.dpvec_index
= 0;
4936 it
->method
= next_element_from_display_vector
;
4937 get_next_display_element (it
);
4942 /* Adjust face id for a multibyte character. There are no
4943 multibyte character in unibyte text. */
4946 && FRAME_WINDOW_P (it
->f
))
4948 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4949 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4953 /* Is this character the last one of a run of characters with
4954 box? If yes, set IT->end_of_box_run_p to 1. */
4961 it
->end_of_box_run_p
4962 = ((face_id
= face_after_it_pos (it
),
4963 face_id
!= it
->face_id
)
4964 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4965 face
->box
== FACE_NO_BOX
));
4968 /* Value is 0 if end of buffer or string reached. */
4973 /* Move IT to the next display element.
4975 RESEAT_P non-zero means if called on a newline in buffer text,
4976 skip to the next visible line start.
4978 Functions get_next_display_element and set_iterator_to_next are
4979 separate because I find this arrangement easier to handle than a
4980 get_next_display_element function that also increments IT's
4981 position. The way it is we can first look at an iterator's current
4982 display element, decide whether it fits on a line, and if it does,
4983 increment the iterator position. The other way around we probably
4984 would either need a flag indicating whether the iterator has to be
4985 incremented the next time, or we would have to implement a
4986 decrement position function which would not be easy to write. */
4989 set_iterator_to_next (it
, reseat_p
)
4993 /* Reset flags indicating start and end of a sequence of characters
4994 with box. Reset them at the start of this function because
4995 moving the iterator to a new position might set them. */
4996 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4998 if (it
->method
== next_element_from_buffer
)
5000 /* The current display element of IT is a character from
5001 current_buffer. Advance in the buffer, and maybe skip over
5002 invisible lines that are so because of selective display. */
5003 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5004 reseat_at_next_visible_line_start (it
, 0);
5007 xassert (it
->len
!= 0);
5008 IT_BYTEPOS (*it
) += it
->len
;
5009 IT_CHARPOS (*it
) += 1;
5010 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5013 else if (it
->method
== next_element_from_composition
)
5015 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5016 if (STRINGP (it
->string
))
5018 IT_STRING_BYTEPOS (*it
) += it
->len
;
5019 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5020 it
->method
= next_element_from_string
;
5021 goto consider_string_end
;
5025 IT_BYTEPOS (*it
) += it
->len
;
5026 IT_CHARPOS (*it
) += it
->cmp_len
;
5027 it
->method
= next_element_from_buffer
;
5030 else if (it
->method
== next_element_from_c_string
)
5032 /* Current display element of IT is from a C string. */
5033 IT_BYTEPOS (*it
) += it
->len
;
5034 IT_CHARPOS (*it
) += 1;
5036 else if (it
->method
== next_element_from_display_vector
)
5038 /* Current display element of IT is from a display table entry.
5039 Advance in the display table definition. Reset it to null if
5040 end reached, and continue with characters from buffers/
5042 ++it
->current
.dpvec_index
;
5044 /* Restore face of the iterator to what they were before the
5045 display vector entry (these entries may contain faces). */
5046 it
->face_id
= it
->saved_face_id
;
5048 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5051 it
->method
= next_element_from_c_string
;
5052 else if (STRINGP (it
->string
))
5053 it
->method
= next_element_from_string
;
5055 it
->method
= next_element_from_buffer
;
5058 it
->current
.dpvec_index
= -1;
5060 /* Skip over characters which were displayed via IT->dpvec. */
5061 if (it
->dpvec_char_len
< 0)
5062 reseat_at_next_visible_line_start (it
, 1);
5063 else if (it
->dpvec_char_len
> 0)
5065 it
->len
= it
->dpvec_char_len
;
5066 set_iterator_to_next (it
, reseat_p
);
5070 else if (it
->method
== next_element_from_string
)
5072 /* Current display element is a character from a Lisp string. */
5073 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5074 IT_STRING_BYTEPOS (*it
) += it
->len
;
5075 IT_STRING_CHARPOS (*it
) += 1;
5077 consider_string_end
:
5079 if (it
->current
.overlay_string_index
>= 0)
5081 /* IT->string is an overlay string. Advance to the
5082 next, if there is one. */
5083 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5084 next_overlay_string (it
);
5088 /* IT->string is not an overlay string. If we reached
5089 its end, and there is something on IT->stack, proceed
5090 with what is on the stack. This can be either another
5091 string, this time an overlay string, or a buffer. */
5092 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5096 if (!STRINGP (it
->string
))
5097 it
->method
= next_element_from_buffer
;
5099 goto consider_string_end
;
5103 else if (it
->method
== next_element_from_image
5104 || it
->method
== next_element_from_stretch
)
5106 /* The position etc with which we have to proceed are on
5107 the stack. The position may be at the end of a string,
5108 if the `display' property takes up the whole string. */
5111 if (STRINGP (it
->string
))
5113 it
->method
= next_element_from_string
;
5114 goto consider_string_end
;
5117 it
->method
= next_element_from_buffer
;
5120 /* There are no other methods defined, so this should be a bug. */
5123 xassert (it
->method
!= next_element_from_string
5124 || (STRINGP (it
->string
)
5125 && IT_STRING_CHARPOS (*it
) >= 0));
5129 /* Load IT's display element fields with information about the next
5130 display element which comes from a display table entry or from the
5131 result of translating a control character to one of the forms `^C'
5132 or `\003'. IT->dpvec holds the glyphs to return as characters. */
5135 next_element_from_display_vector (it
)
5139 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5141 /* Remember the current face id in case glyphs specify faces.
5142 IT's face is restored in set_iterator_to_next. */
5143 it
->saved_face_id
= it
->face_id
;
5145 if (INTEGERP (*it
->dpvec
)
5146 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5151 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5152 it
->c
= FAST_GLYPH_CHAR (g
);
5153 it
->len
= CHAR_BYTES (it
->c
);
5155 /* The entry may contain a face id to use. Such a face id is
5156 the id of a Lisp face, not a realized face. A face id of
5157 zero means no face is specified. */
5158 lface_id
= FAST_GLYPH_FACE (g
);
5161 /* The function returns -1 if lface_id is invalid. */
5162 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
5164 it
->face_id
= face_id
;
5168 /* Display table entry is invalid. Return a space. */
5169 it
->c
= ' ', it
->len
= 1;
5171 /* Don't change position and object of the iterator here. They are
5172 still the values of the character that had this display table
5173 entry or was translated, and that's what we want. */
5174 it
->what
= IT_CHARACTER
;
5179 /* Load IT with the next display element from Lisp string IT->string.
5180 IT->current.string_pos is the current position within the string.
5181 If IT->current.overlay_string_index >= 0, the Lisp string is an
5185 next_element_from_string (it
)
5188 struct text_pos position
;
5190 xassert (STRINGP (it
->string
));
5191 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5192 position
= it
->current
.string_pos
;
5194 /* Time to check for invisible text? */
5195 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5196 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5200 /* Since a handler may have changed IT->method, we must
5202 return get_next_display_element (it
);
5205 if (it
->current
.overlay_string_index
>= 0)
5207 /* Get the next character from an overlay string. In overlay
5208 strings, There is no field width or padding with spaces to
5210 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5215 else if (STRING_MULTIBYTE (it
->string
))
5217 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5218 const unsigned char *s
= (SDATA (it
->string
)
5219 + IT_STRING_BYTEPOS (*it
));
5220 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5224 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5230 /* Get the next character from a Lisp string that is not an
5231 overlay string. Such strings come from the mode line, for
5232 example. We may have to pad with spaces, or truncate the
5233 string. See also next_element_from_c_string. */
5234 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5239 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5241 /* Pad with spaces. */
5242 it
->c
= ' ', it
->len
= 1;
5243 CHARPOS (position
) = BYTEPOS (position
) = -1;
5245 else if (STRING_MULTIBYTE (it
->string
))
5247 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5248 const unsigned char *s
= (SDATA (it
->string
)
5249 + IT_STRING_BYTEPOS (*it
));
5250 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5254 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5259 /* Record what we have and where it came from. Note that we store a
5260 buffer position in IT->position although it could arguably be a
5262 it
->what
= IT_CHARACTER
;
5263 it
->object
= it
->string
;
5264 it
->position
= position
;
5269 /* Load IT with next display element from C string IT->s.
5270 IT->string_nchars is the maximum number of characters to return
5271 from the string. IT->end_charpos may be greater than
5272 IT->string_nchars when this function is called, in which case we
5273 may have to return padding spaces. Value is zero if end of string
5274 reached, including padding spaces. */
5277 next_element_from_c_string (it
)
5283 it
->what
= IT_CHARACTER
;
5284 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5287 /* IT's position can be greater IT->string_nchars in case a field
5288 width or precision has been specified when the iterator was
5290 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5292 /* End of the game. */
5296 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5298 /* Pad with spaces. */
5299 it
->c
= ' ', it
->len
= 1;
5300 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5302 else if (it
->multibyte_p
)
5304 /* Implementation note: The calls to strlen apparently aren't a
5305 performance problem because there is no noticeable performance
5306 difference between Emacs running in unibyte or multibyte mode. */
5307 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5308 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5312 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5318 /* Set up IT to return characters from an ellipsis, if appropriate.
5319 The definition of the ellipsis glyphs may come from a display table
5320 entry. This function Fills IT with the first glyph from the
5321 ellipsis if an ellipsis is to be displayed. */
5324 next_element_from_ellipsis (it
)
5327 if (it
->selective_display_ellipsis_p
)
5329 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
5331 /* Use the display table definition for `...'. Invalid glyphs
5332 will be handled by the method returning elements from dpvec. */
5333 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
5334 it
->dpvec_char_len
= it
->len
;
5335 it
->dpvec
= v
->contents
;
5336 it
->dpend
= v
->contents
+ v
->size
;
5337 it
->current
.dpvec_index
= 0;
5338 it
->method
= next_element_from_display_vector
;
5342 /* Use default `...' which is stored in default_invis_vector. */
5343 it
->dpvec_char_len
= it
->len
;
5344 it
->dpvec
= default_invis_vector
;
5345 it
->dpend
= default_invis_vector
+ 3;
5346 it
->current
.dpvec_index
= 0;
5347 it
->method
= next_element_from_display_vector
;
5352 /* The face at the current position may be different from the
5353 face we find after the invisible text. Remember what it
5354 was in IT->saved_face_id, and signal that it's there by
5355 setting face_before_selective_p. */
5356 it
->saved_face_id
= it
->face_id
;
5357 it
->method
= next_element_from_buffer
;
5358 reseat_at_next_visible_line_start (it
, 1);
5359 it
->face_before_selective_p
= 1;
5362 return get_next_display_element (it
);
5366 /* Deliver an image display element. The iterator IT is already
5367 filled with image information (done in handle_display_prop). Value
5372 next_element_from_image (it
)
5375 it
->what
= IT_IMAGE
;
5380 /* Fill iterator IT with next display element from a stretch glyph
5381 property. IT->object is the value of the text property. Value is
5385 next_element_from_stretch (it
)
5388 it
->what
= IT_STRETCH
;
5393 /* Load IT with the next display element from current_buffer. Value
5394 is zero if end of buffer reached. IT->stop_charpos is the next
5395 position at which to stop and check for text properties or buffer
5399 next_element_from_buffer (it
)
5404 /* Check this assumption, otherwise, we would never enter the
5405 if-statement, below. */
5406 xassert (IT_CHARPOS (*it
) >= BEGV
5407 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
5409 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
5411 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5413 int overlay_strings_follow_p
;
5415 /* End of the game, except when overlay strings follow that
5416 haven't been returned yet. */
5417 if (it
->overlay_strings_at_end_processed_p
)
5418 overlay_strings_follow_p
= 0;
5421 it
->overlay_strings_at_end_processed_p
= 1;
5422 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
5425 if (overlay_strings_follow_p
)
5426 success_p
= get_next_display_element (it
);
5430 it
->position
= it
->current
.pos
;
5437 return get_next_display_element (it
);
5442 /* No face changes, overlays etc. in sight, so just return a
5443 character from current_buffer. */
5446 /* Maybe run the redisplay end trigger hook. Performance note:
5447 This doesn't seem to cost measurable time. */
5448 if (it
->redisplay_end_trigger_charpos
5450 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
5451 run_redisplay_end_trigger_hook (it
);
5453 /* Get the next character, maybe multibyte. */
5454 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
5455 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
5457 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
5458 - IT_BYTEPOS (*it
));
5459 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
5462 it
->c
= *p
, it
->len
= 1;
5464 /* Record what we have and where it came from. */
5465 it
->what
= IT_CHARACTER
;;
5466 it
->object
= it
->w
->buffer
;
5467 it
->position
= it
->current
.pos
;
5469 /* Normally we return the character found above, except when we
5470 really want to return an ellipsis for selective display. */
5475 /* A value of selective > 0 means hide lines indented more
5476 than that number of columns. */
5477 if (it
->selective
> 0
5478 && IT_CHARPOS (*it
) + 1 < ZV
5479 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
5480 IT_BYTEPOS (*it
) + 1,
5481 (double) it
->selective
)) /* iftc */
5483 success_p
= next_element_from_ellipsis (it
);
5484 it
->dpvec_char_len
= -1;
5487 else if (it
->c
== '\r' && it
->selective
== -1)
5489 /* A value of selective == -1 means that everything from the
5490 CR to the end of the line is invisible, with maybe an
5491 ellipsis displayed for it. */
5492 success_p
= next_element_from_ellipsis (it
);
5493 it
->dpvec_char_len
= -1;
5498 /* Value is zero if end of buffer reached. */
5499 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
5504 /* Run the redisplay end trigger hook for IT. */
5507 run_redisplay_end_trigger_hook (it
)
5510 Lisp_Object args
[3];
5512 /* IT->glyph_row should be non-null, i.e. we should be actually
5513 displaying something, or otherwise we should not run the hook. */
5514 xassert (it
->glyph_row
);
5516 /* Set up hook arguments. */
5517 args
[0] = Qredisplay_end_trigger_functions
;
5518 args
[1] = it
->window
;
5519 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
5520 it
->redisplay_end_trigger_charpos
= 0;
5522 /* Since we are *trying* to run these functions, don't try to run
5523 them again, even if they get an error. */
5524 it
->w
->redisplay_end_trigger
= Qnil
;
5525 Frun_hook_with_args (3, args
);
5527 /* Notice if it changed the face of the character we are on. */
5528 handle_face_prop (it
);
5532 /* Deliver a composition display element. The iterator IT is already
5533 filled with composition information (done in
5534 handle_composition_prop). Value is always 1. */
5537 next_element_from_composition (it
)
5540 it
->what
= IT_COMPOSITION
;
5541 it
->position
= (STRINGP (it
->string
)
5542 ? it
->current
.string_pos
5549 /***********************************************************************
5550 Moving an iterator without producing glyphs
5551 ***********************************************************************/
5553 /* Move iterator IT to a specified buffer or X position within one
5554 line on the display without producing glyphs.
5556 OP should be a bit mask including some or all of these bits:
5557 MOVE_TO_X: Stop on reaching x-position TO_X.
5558 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5559 Regardless of OP's value, stop in reaching the end of the display line.
5561 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5562 This means, in particular, that TO_X includes window's horizontal
5565 The return value has several possible values that
5566 say what condition caused the scan to stop:
5568 MOVE_POS_MATCH_OR_ZV
5569 - when TO_POS or ZV was reached.
5572 -when TO_X was reached before TO_POS or ZV were reached.
5575 - when we reached the end of the display area and the line must
5579 - when we reached the end of the display area and the line is
5583 - when we stopped at a line end, i.e. a newline or a CR and selective
5586 static enum move_it_result
5587 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5589 int to_charpos
, to_x
, op
;
5591 enum move_it_result result
= MOVE_UNDEFINED
;
5592 struct glyph_row
*saved_glyph_row
;
5594 /* Don't produce glyphs in produce_glyphs. */
5595 saved_glyph_row
= it
->glyph_row
;
5596 it
->glyph_row
= NULL
;
5598 #define BUFFER_POS_REACHED_P() \
5599 ((op & MOVE_TO_POS) != 0 \
5600 && BUFFERP (it->object) \
5601 && IT_CHARPOS (*it) >= to_charpos)
5605 int x
, i
, ascent
= 0, descent
= 0;
5607 /* Stop when ZV or TO_CHARPOS reached. */
5608 if (!get_next_display_element (it
)
5609 || BUFFER_POS_REACHED_P ())
5611 result
= MOVE_POS_MATCH_OR_ZV
;
5615 /* The call to produce_glyphs will get the metrics of the
5616 display element IT is loaded with. We record in x the
5617 x-position before this display element in case it does not
5621 /* Remember the line height so far in case the next element doesn't
5623 if (!it
->truncate_lines_p
)
5625 ascent
= it
->max_ascent
;
5626 descent
= it
->max_descent
;
5629 PRODUCE_GLYPHS (it
);
5631 if (it
->area
!= TEXT_AREA
)
5633 set_iterator_to_next (it
, 1);
5637 /* The number of glyphs we get back in IT->nglyphs will normally
5638 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5639 character on a terminal frame, or (iii) a line end. For the
5640 second case, IT->nglyphs - 1 padding glyphs will be present
5641 (on X frames, there is only one glyph produced for a
5642 composite character.
5644 The behavior implemented below means, for continuation lines,
5645 that as many spaces of a TAB as fit on the current line are
5646 displayed there. For terminal frames, as many glyphs of a
5647 multi-glyph character are displayed in the current line, too.
5648 This is what the old redisplay code did, and we keep it that
5649 way. Under X, the whole shape of a complex character must
5650 fit on the line or it will be completely displayed in the
5653 Note that both for tabs and padding glyphs, all glyphs have
5657 /* More than one glyph or glyph doesn't fit on line. All
5658 glyphs have the same width. */
5659 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5662 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5664 new_x
= x
+ single_glyph_width
;
5666 /* We want to leave anything reaching TO_X to the caller. */
5667 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5670 result
= MOVE_X_REACHED
;
5673 else if (/* Lines are continued. */
5674 !it
->truncate_lines_p
5675 && (/* And glyph doesn't fit on the line. */
5676 new_x
> it
->last_visible_x
5677 /* Or it fits exactly and we're on a window
5679 || (new_x
== it
->last_visible_x
5680 && FRAME_WINDOW_P (it
->f
))))
5682 if (/* IT->hpos == 0 means the very first glyph
5683 doesn't fit on the line, e.g. a wide image. */
5685 || (new_x
== it
->last_visible_x
5686 && FRAME_WINDOW_P (it
->f
)))
5689 it
->current_x
= new_x
;
5690 if (i
== it
->nglyphs
- 1)
5692 set_iterator_to_next (it
, 1);
5693 #ifdef HAVE_WINDOW_SYSTEM
5694 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
5696 if (!get_next_display_element (it
)
5697 || BUFFER_POS_REACHED_P ())
5699 result
= MOVE_POS_MATCH_OR_ZV
;
5702 if (ITERATOR_AT_END_OF_LINE_P (it
))
5704 result
= MOVE_NEWLINE_OR_CR
;
5708 #endif /* HAVE_WINDOW_SYSTEM */
5714 it
->max_ascent
= ascent
;
5715 it
->max_descent
= descent
;
5718 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5720 result
= MOVE_LINE_CONTINUED
;
5723 else if (new_x
> it
->first_visible_x
)
5725 /* Glyph is visible. Increment number of glyphs that
5726 would be displayed. */
5731 /* Glyph is completely off the left margin of the display
5732 area. Nothing to do. */
5736 if (result
!= MOVE_UNDEFINED
)
5739 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5741 /* Stop when TO_X specified and reached. This check is
5742 necessary here because of lines consisting of a line end,
5743 only. The line end will not produce any glyphs and we
5744 would never get MOVE_X_REACHED. */
5745 xassert (it
->nglyphs
== 0);
5746 result
= MOVE_X_REACHED
;
5750 /* Is this a line end? If yes, we're done. */
5751 if (ITERATOR_AT_END_OF_LINE_P (it
))
5753 result
= MOVE_NEWLINE_OR_CR
;
5757 /* The current display element has been consumed. Advance
5759 set_iterator_to_next (it
, 1);
5761 /* Stop if lines are truncated and IT's current x-position is
5762 past the right edge of the window now. */
5763 if (it
->truncate_lines_p
5764 && it
->current_x
>= it
->last_visible_x
)
5766 #ifdef HAVE_WINDOW_SYSTEM
5767 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
5769 if (!get_next_display_element (it
)
5770 || BUFFER_POS_REACHED_P ())
5772 result
= MOVE_POS_MATCH_OR_ZV
;
5775 if (ITERATOR_AT_END_OF_LINE_P (it
))
5777 result
= MOVE_NEWLINE_OR_CR
;
5781 #endif /* HAVE_WINDOW_SYSTEM */
5782 result
= MOVE_LINE_TRUNCATED
;
5787 #undef BUFFER_POS_REACHED_P
5789 /* Restore the iterator settings altered at the beginning of this
5791 it
->glyph_row
= saved_glyph_row
;
5796 /* Move IT forward until it satisfies one or more of the criteria in
5797 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
5799 OP is a bit-mask that specifies where to stop, and in particular,
5800 which of those four position arguments makes a difference. See the
5801 description of enum move_operation_enum.
5803 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5804 screen line, this function will set IT to the next position >
5808 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5810 int to_charpos
, to_x
, to_y
, to_vpos
;
5813 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5819 if (op
& MOVE_TO_VPOS
)
5821 /* If no TO_CHARPOS and no TO_X specified, stop at the
5822 start of the line TO_VPOS. */
5823 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5825 if (it
->vpos
== to_vpos
)
5831 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5835 /* TO_VPOS >= 0 means stop at TO_X in the line at
5836 TO_VPOS, or at TO_POS, whichever comes first. */
5837 if (it
->vpos
== to_vpos
)
5843 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5845 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5850 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5852 /* We have reached TO_X but not in the line we want. */
5853 skip
= move_it_in_display_line_to (it
, to_charpos
,
5855 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5863 else if (op
& MOVE_TO_Y
)
5865 struct it it_backup
;
5867 /* TO_Y specified means stop at TO_X in the line containing
5868 TO_Y---or at TO_CHARPOS if this is reached first. The
5869 problem is that we can't really tell whether the line
5870 contains TO_Y before we have completely scanned it, and
5871 this may skip past TO_X. What we do is to first scan to
5874 If TO_X is not specified, use a TO_X of zero. The reason
5875 is to make the outcome of this function more predictable.
5876 If we didn't use TO_X == 0, we would stop at the end of
5877 the line which is probably not what a caller would expect
5879 skip
= move_it_in_display_line_to (it
, to_charpos
,
5883 | (op
& MOVE_TO_POS
)));
5885 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5886 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5892 /* If TO_X was reached, we would like to know whether TO_Y
5893 is in the line. This can only be said if we know the
5894 total line height which requires us to scan the rest of
5896 if (skip
== MOVE_X_REACHED
)
5899 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5900 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5902 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5905 /* Now, decide whether TO_Y is in this line. */
5906 line_height
= it
->max_ascent
+ it
->max_descent
;
5907 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5909 if (to_y
>= it
->current_y
5910 && to_y
< it
->current_y
+ line_height
)
5912 if (skip
== MOVE_X_REACHED
)
5913 /* If TO_Y is in this line and TO_X was reached above,
5914 we scanned too far. We have to restore IT's settings
5915 to the ones before skipping. */
5919 else if (skip
== MOVE_X_REACHED
)
5922 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5930 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5934 case MOVE_POS_MATCH_OR_ZV
:
5938 case MOVE_NEWLINE_OR_CR
:
5939 set_iterator_to_next (it
, 1);
5940 it
->continuation_lines_width
= 0;
5943 case MOVE_LINE_TRUNCATED
:
5944 it
->continuation_lines_width
= 0;
5945 reseat_at_next_visible_line_start (it
, 0);
5946 if ((op
& MOVE_TO_POS
) != 0
5947 && IT_CHARPOS (*it
) > to_charpos
)
5954 case MOVE_LINE_CONTINUED
:
5955 it
->continuation_lines_width
+= it
->current_x
;
5962 /* Reset/increment for the next run. */
5963 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5964 it
->current_x
= it
->hpos
= 0;
5965 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5967 last_height
= it
->max_ascent
+ it
->max_descent
;
5968 last_max_ascent
= it
->max_ascent
;
5969 it
->max_ascent
= it
->max_descent
= 0;
5974 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5978 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5980 If DY > 0, move IT backward at least that many pixels. DY = 0
5981 means move IT backward to the preceding line start or BEGV. This
5982 function may move over more than DY pixels if IT->current_y - DY
5983 ends up in the middle of a line; in this case IT->current_y will be
5984 set to the top of the line moved to. */
5987 move_it_vertically_backward (it
, dy
)
5993 int start_pos
= IT_CHARPOS (*it
);
5997 /* Estimate how many newlines we must move back. */
5998 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6000 /* Set the iterator's position that many lines back. */
6001 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6002 back_to_previous_visible_line_start (it
);
6004 /* Reseat the iterator here. When moving backward, we don't want
6005 reseat to skip forward over invisible text, set up the iterator
6006 to deliver from overlay strings at the new position etc. So,
6007 use reseat_1 here. */
6008 reseat_1 (it
, it
->current
.pos
, 1);
6010 /* We are now surely at a line start. */
6011 it
->current_x
= it
->hpos
= 0;
6012 it
->continuation_lines_width
= 0;
6014 /* Move forward and see what y-distance we moved. First move to the
6015 start of the next line so that we get its height. We need this
6016 height to be able to tell whether we reached the specified
6019 it2
.max_ascent
= it2
.max_descent
= 0;
6020 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6021 MOVE_TO_POS
| MOVE_TO_VPOS
);
6022 xassert (IT_CHARPOS (*it
) >= BEGV
);
6025 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6026 xassert (IT_CHARPOS (*it
) >= BEGV
);
6027 /* H is the actual vertical distance from the position in *IT
6028 and the starting position. */
6029 h
= it2
.current_y
- it
->current_y
;
6030 /* NLINES is the distance in number of lines. */
6031 nlines
= it2
.vpos
- it
->vpos
;
6033 /* Correct IT's y and vpos position
6034 so that they are relative to the starting point. */
6040 /* DY == 0 means move to the start of the screen line. The
6041 value of nlines is > 0 if continuation lines were involved. */
6043 move_it_by_lines (it
, nlines
, 1);
6044 xassert (IT_CHARPOS (*it
) <= start_pos
);
6048 /* The y-position we try to reach, relative to *IT.
6049 Note that H has been subtracted in front of the if-statement. */
6050 int target_y
= it
->current_y
+ h
- dy
;
6051 int y0
= it3
.current_y
;
6052 int y1
= line_bottom_y (&it3
);
6053 int line_height
= y1
- y0
;
6055 /* If we did not reach target_y, try to move further backward if
6056 we can. If we moved too far backward, try to move forward. */
6057 if (target_y
< it
->current_y
6058 /* This is heuristic. In a window that's 3 lines high, with
6059 a line height of 13 pixels each, recentering with point
6060 on the bottom line will try to move -39/2 = 19 pixels
6061 backward. Try to avoid moving into the first line. */
6062 && it
->current_y
- target_y
> line_height
/ 3 * 2
6063 && IT_CHARPOS (*it
) > BEGV
)
6065 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6066 target_y
- it
->current_y
));
6067 move_it_vertically (it
, target_y
- it
->current_y
);
6068 xassert (IT_CHARPOS (*it
) >= BEGV
);
6070 else if (target_y
>= it
->current_y
+ line_height
6071 && IT_CHARPOS (*it
) < ZV
)
6073 /* Should move forward by at least one line, maybe more.
6075 Note: Calling move_it_by_lines can be expensive on
6076 terminal frames, where compute_motion is used (via
6077 vmotion) to do the job, when there are very long lines
6078 and truncate-lines is nil. That's the reason for
6079 treating terminal frames specially here. */
6081 if (!FRAME_WINDOW_P (it
->f
))
6082 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6087 move_it_by_lines (it
, 1, 1);
6089 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6092 xassert (IT_CHARPOS (*it
) >= BEGV
);
6098 /* Move IT by a specified amount of pixel lines DY. DY negative means
6099 move backwards. DY = 0 means move to start of screen line. At the
6100 end, IT will be on the start of a screen line. */
6103 move_it_vertically (it
, dy
)
6108 move_it_vertically_backward (it
, -dy
);
6111 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6112 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6113 MOVE_TO_POS
| MOVE_TO_Y
);
6114 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6116 /* If buffer ends in ZV without a newline, move to the start of
6117 the line to satisfy the post-condition. */
6118 if (IT_CHARPOS (*it
) == ZV
6119 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6120 move_it_by_lines (it
, 0, 0);
6125 /* Move iterator IT past the end of the text line it is in. */
6128 move_it_past_eol (it
)
6131 enum move_it_result rc
;
6133 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6134 if (rc
== MOVE_NEWLINE_OR_CR
)
6135 set_iterator_to_next (it
, 0);
6139 #if 0 /* Currently not used. */
6141 /* Return non-zero if some text between buffer positions START_CHARPOS
6142 and END_CHARPOS is invisible. IT->window is the window for text
6146 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6148 int start_charpos
, end_charpos
;
6150 Lisp_Object prop
, limit
;
6151 int invisible_found_p
;
6153 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6155 /* Is text at START invisible? */
6156 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6158 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6159 invisible_found_p
= 1;
6162 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6164 make_number (end_charpos
));
6165 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6168 return invisible_found_p
;
6174 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6175 negative means move up. DVPOS == 0 means move to the start of the
6176 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6177 NEED_Y_P is zero, IT->current_y will be left unchanged.
6179 Further optimization ideas: If we would know that IT->f doesn't use
6180 a face with proportional font, we could be faster for
6181 truncate-lines nil. */
6184 move_it_by_lines (it
, dvpos
, need_y_p
)
6186 int dvpos
, need_y_p
;
6188 struct position pos
;
6190 if (!FRAME_WINDOW_P (it
->f
))
6192 struct text_pos textpos
;
6194 /* We can use vmotion on frames without proportional fonts. */
6195 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6196 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6197 reseat (it
, textpos
, 1);
6198 it
->vpos
+= pos
.vpos
;
6199 it
->current_y
+= pos
.vpos
;
6201 else if (dvpos
== 0)
6203 /* DVPOS == 0 means move to the start of the screen line. */
6204 move_it_vertically_backward (it
, 0);
6205 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6208 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6212 int start_charpos
, i
;
6214 /* Start at the beginning of the screen line containing IT's
6216 move_it_vertically_backward (it
, 0);
6218 /* Go back -DVPOS visible lines and reseat the iterator there. */
6219 start_charpos
= IT_CHARPOS (*it
);
6220 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
6221 back_to_previous_visible_line_start (it
);
6222 reseat (it
, it
->current
.pos
, 1);
6223 it
->current_x
= it
->hpos
= 0;
6225 /* Above call may have moved too far if continuation lines
6226 are involved. Scan forward and see if it did. */
6228 it2
.vpos
= it2
.current_y
= 0;
6229 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6230 it
->vpos
-= it2
.vpos
;
6231 it
->current_y
-= it2
.current_y
;
6232 it
->current_x
= it
->hpos
= 0;
6234 /* If we moved too far, move IT some lines forward. */
6235 if (it2
.vpos
> -dvpos
)
6237 int delta
= it2
.vpos
+ dvpos
;
6238 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6243 /* Return 1 if IT points into the middle of a display vector. */
6246 in_display_vector_p (it
)
6249 return (it
->method
== next_element_from_display_vector
6250 && it
->current
.dpvec_index
> 0
6251 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6255 /***********************************************************************
6257 ***********************************************************************/
6260 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6264 add_to_log (format
, arg1
, arg2
)
6266 Lisp_Object arg1
, arg2
;
6268 Lisp_Object args
[3];
6269 Lisp_Object msg
, fmt
;
6272 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6274 /* Do nothing if called asynchronously. Inserting text into
6275 a buffer may call after-change-functions and alike and
6276 that would means running Lisp asynchronously. */
6277 if (handling_signal
)
6281 GCPRO4 (fmt
, msg
, arg1
, arg2
);
6283 args
[0] = fmt
= build_string (format
);
6286 msg
= Fformat (3, args
);
6288 len
= SBYTES (msg
) + 1;
6289 buffer
= (char *) alloca (len
);
6290 bcopy (SDATA (msg
), buffer
, len
);
6292 message_dolog (buffer
, len
- 1, 1, 0);
6297 /* Output a newline in the *Messages* buffer if "needs" one. */
6300 message_log_maybe_newline ()
6302 if (message_log_need_newline
)
6303 message_dolog ("", 0, 1, 0);
6307 /* Add a string M of length NBYTES to the message log, optionally
6308 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
6309 nonzero, means interpret the contents of M as multibyte. This
6310 function calls low-level routines in order to bypass text property
6311 hooks, etc. which might not be safe to run. */
6314 message_dolog (m
, nbytes
, nlflag
, multibyte
)
6316 int nbytes
, nlflag
, multibyte
;
6318 if (!NILP (Vmemory_full
))
6321 if (!NILP (Vmessage_log_max
))
6323 struct buffer
*oldbuf
;
6324 Lisp_Object oldpoint
, oldbegv
, oldzv
;
6325 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6326 int point_at_end
= 0;
6328 Lisp_Object old_deactivate_mark
, tem
;
6329 struct gcpro gcpro1
;
6331 old_deactivate_mark
= Vdeactivate_mark
;
6332 oldbuf
= current_buffer
;
6333 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
6334 current_buffer
->undo_list
= Qt
;
6336 oldpoint
= message_dolog_marker1
;
6337 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
6338 oldbegv
= message_dolog_marker2
;
6339 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
6340 oldzv
= message_dolog_marker3
;
6341 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
6342 GCPRO1 (old_deactivate_mark
);
6350 BEGV_BYTE
= BEG_BYTE
;
6353 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6355 /* Insert the string--maybe converting multibyte to single byte
6356 or vice versa, so that all the text fits the buffer. */
6358 && NILP (current_buffer
->enable_multibyte_characters
))
6360 int i
, c
, char_bytes
;
6361 unsigned char work
[1];
6363 /* Convert a multibyte string to single-byte
6364 for the *Message* buffer. */
6365 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
6367 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
6368 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6370 : multibyte_char_to_unibyte (c
, Qnil
));
6371 insert_1_both (work
, 1, 1, 1, 0, 0);
6374 else if (! multibyte
6375 && ! NILP (current_buffer
->enable_multibyte_characters
))
6377 int i
, c
, char_bytes
;
6378 unsigned char *msg
= (unsigned char *) m
;
6379 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6380 /* Convert a single-byte string to multibyte
6381 for the *Message* buffer. */
6382 for (i
= 0; i
< nbytes
; i
++)
6384 c
= unibyte_char_to_multibyte (msg
[i
]);
6385 char_bytes
= CHAR_STRING (c
, str
);
6386 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
6390 insert_1 (m
, nbytes
, 1, 0, 0);
6394 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
6395 insert_1 ("\n", 1, 1, 0, 0);
6397 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6399 this_bol_byte
= PT_BYTE
;
6401 /* See if this line duplicates the previous one.
6402 If so, combine duplicates. */
6405 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6407 prev_bol_byte
= PT_BYTE
;
6409 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
6410 this_bol
, this_bol_byte
);
6413 del_range_both (prev_bol
, prev_bol_byte
,
6414 this_bol
, this_bol_byte
, 0);
6420 /* If you change this format, don't forget to also
6421 change message_log_check_duplicate. */
6422 sprintf (dupstr
, " [%d times]", dup
);
6423 duplen
= strlen (dupstr
);
6424 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
6425 insert_1 (dupstr
, duplen
, 1, 0, 1);
6430 /* If we have more than the desired maximum number of lines
6431 in the *Messages* buffer now, delete the oldest ones.
6432 This is safe because we don't have undo in this buffer. */
6434 if (NATNUMP (Vmessage_log_max
))
6436 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
6437 -XFASTINT (Vmessage_log_max
) - 1, 0);
6438 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
6441 BEGV
= XMARKER (oldbegv
)->charpos
;
6442 BEGV_BYTE
= marker_byte_position (oldbegv
);
6451 ZV
= XMARKER (oldzv
)->charpos
;
6452 ZV_BYTE
= marker_byte_position (oldzv
);
6456 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6458 /* We can't do Fgoto_char (oldpoint) because it will run some
6460 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
6461 XMARKER (oldpoint
)->bytepos
);
6464 unchain_marker (XMARKER (oldpoint
));
6465 unchain_marker (XMARKER (oldbegv
));
6466 unchain_marker (XMARKER (oldzv
));
6468 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
6469 set_buffer_internal (oldbuf
);
6471 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6472 message_log_need_newline
= !nlflag
;
6473 Vdeactivate_mark
= old_deactivate_mark
;
6478 /* We are at the end of the buffer after just having inserted a newline.
6479 (Note: We depend on the fact we won't be crossing the gap.)
6480 Check to see if the most recent message looks a lot like the previous one.
6481 Return 0 if different, 1 if the new one should just replace it, or a
6482 value N > 1 if we should also append " [N times]". */
6485 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
6486 int prev_bol
, this_bol
;
6487 int prev_bol_byte
, this_bol_byte
;
6490 int len
= Z_BYTE
- 1 - this_bol_byte
;
6492 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
6493 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
6495 for (i
= 0; i
< len
; i
++)
6497 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
6505 if (*p1
++ == ' ' && *p1
++ == '[')
6508 while (*p1
>= '0' && *p1
<= '9')
6509 n
= n
* 10 + *p1
++ - '0';
6510 if (strncmp (p1
, " times]\n", 8) == 0)
6517 /* Display an echo area message M with a specified length of NBYTES
6518 bytes. The string may include null characters. If M is 0, clear
6519 out any existing message, and let the mini-buffer text show
6522 The buffer M must continue to exist until after the echo area gets
6523 cleared or some other message gets displayed there. This means do
6524 not pass text that is stored in a Lisp string; do not pass text in
6525 a buffer that was alloca'd. */
6528 message2 (m
, nbytes
, multibyte
)
6533 /* First flush out any partial line written with print. */
6534 message_log_maybe_newline ();
6536 message_dolog (m
, nbytes
, 1, multibyte
);
6537 message2_nolog (m
, nbytes
, multibyte
);
6541 /* The non-logging counterpart of message2. */
6544 message2_nolog (m
, nbytes
, multibyte
)
6546 int nbytes
, multibyte
;
6548 struct frame
*sf
= SELECTED_FRAME ();
6549 message_enable_multibyte
= multibyte
;
6553 if (noninteractive_need_newline
)
6554 putc ('\n', stderr
);
6555 noninteractive_need_newline
= 0;
6557 fwrite (m
, nbytes
, 1, stderr
);
6558 if (cursor_in_echo_area
== 0)
6559 fprintf (stderr
, "\n");
6562 /* A null message buffer means that the frame hasn't really been
6563 initialized yet. Error messages get reported properly by
6564 cmd_error, so this must be just an informative message; toss it. */
6565 else if (INTERACTIVE
6566 && sf
->glyphs_initialized_p
6567 && FRAME_MESSAGE_BUF (sf
))
6569 Lisp_Object mini_window
;
6572 /* Get the frame containing the mini-buffer
6573 that the selected frame is using. */
6574 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6575 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6577 FRAME_SAMPLE_VISIBILITY (f
);
6578 if (FRAME_VISIBLE_P (sf
)
6579 && ! FRAME_VISIBLE_P (f
))
6580 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
6584 set_message (m
, Qnil
, nbytes
, multibyte
);
6585 if (minibuffer_auto_raise
)
6586 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6589 clear_message (1, 1);
6591 do_pending_window_change (0);
6592 echo_area_display (1);
6593 do_pending_window_change (0);
6594 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6595 (*frame_up_to_date_hook
) (f
);
6600 /* Display an echo area message M with a specified length of NBYTES
6601 bytes. The string may include null characters. If M is not a
6602 string, clear out any existing message, and let the mini-buffer
6603 text show through. */
6606 message3 (m
, nbytes
, multibyte
)
6611 struct gcpro gcpro1
;
6615 /* First flush out any partial line written with print. */
6616 message_log_maybe_newline ();
6618 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
6619 message3_nolog (m
, nbytes
, multibyte
);
6625 /* The non-logging version of message3. */
6628 message3_nolog (m
, nbytes
, multibyte
)
6630 int nbytes
, multibyte
;
6632 struct frame
*sf
= SELECTED_FRAME ();
6633 message_enable_multibyte
= multibyte
;
6637 if (noninteractive_need_newline
)
6638 putc ('\n', stderr
);
6639 noninteractive_need_newline
= 0;
6641 fwrite (SDATA (m
), nbytes
, 1, stderr
);
6642 if (cursor_in_echo_area
== 0)
6643 fprintf (stderr
, "\n");
6646 /* A null message buffer means that the frame hasn't really been
6647 initialized yet. Error messages get reported properly by
6648 cmd_error, so this must be just an informative message; toss it. */
6649 else if (INTERACTIVE
6650 && sf
->glyphs_initialized_p
6651 && FRAME_MESSAGE_BUF (sf
))
6653 Lisp_Object mini_window
;
6657 /* Get the frame containing the mini-buffer
6658 that the selected frame is using. */
6659 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6660 frame
= XWINDOW (mini_window
)->frame
;
6663 FRAME_SAMPLE_VISIBILITY (f
);
6664 if (FRAME_VISIBLE_P (sf
)
6665 && !FRAME_VISIBLE_P (f
))
6666 Fmake_frame_visible (frame
);
6668 if (STRINGP (m
) && SCHARS (m
) > 0)
6670 set_message (NULL
, m
, nbytes
, multibyte
);
6671 if (minibuffer_auto_raise
)
6672 Fraise_frame (frame
);
6675 clear_message (1, 1);
6677 do_pending_window_change (0);
6678 echo_area_display (1);
6679 do_pending_window_change (0);
6680 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6681 (*frame_up_to_date_hook
) (f
);
6686 /* Display a null-terminated echo area message M. If M is 0, clear
6687 out any existing message, and let the mini-buffer text show through.
6689 The buffer M must continue to exist until after the echo area gets
6690 cleared or some other message gets displayed there. Do not pass
6691 text that is stored in a Lisp string. Do not pass text in a buffer
6692 that was alloca'd. */
6698 message2 (m
, (m
? strlen (m
) : 0), 0);
6702 /* The non-logging counterpart of message1. */
6708 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6711 /* Display a message M which contains a single %s
6712 which gets replaced with STRING. */
6715 message_with_string (m
, string
, log
)
6720 CHECK_STRING (string
);
6726 if (noninteractive_need_newline
)
6727 putc ('\n', stderr
);
6728 noninteractive_need_newline
= 0;
6729 fprintf (stderr
, m
, SDATA (string
));
6730 if (cursor_in_echo_area
== 0)
6731 fprintf (stderr
, "\n");
6735 else if (INTERACTIVE
)
6737 /* The frame whose minibuffer we're going to display the message on.
6738 It may be larger than the selected frame, so we need
6739 to use its buffer, not the selected frame's buffer. */
6740 Lisp_Object mini_window
;
6741 struct frame
*f
, *sf
= SELECTED_FRAME ();
6743 /* Get the frame containing the minibuffer
6744 that the selected frame is using. */
6745 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6746 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6748 /* A null message buffer means that the frame hasn't really been
6749 initialized yet. Error messages get reported properly by
6750 cmd_error, so this must be just an informative message; toss it. */
6751 if (FRAME_MESSAGE_BUF (f
))
6753 Lisp_Object args
[2], message
;
6754 struct gcpro gcpro1
, gcpro2
;
6756 args
[0] = build_string (m
);
6757 args
[1] = message
= string
;
6758 GCPRO2 (args
[0], message
);
6761 message
= Fformat (2, args
);
6764 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6766 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6770 /* Print should start at the beginning of the message
6771 buffer next time. */
6772 message_buf_print
= 0;
6778 /* Dump an informative message to the minibuf. If M is 0, clear out
6779 any existing message, and let the mini-buffer text show through. */
6783 message (m
, a1
, a2
, a3
)
6785 EMACS_INT a1
, a2
, a3
;
6791 if (noninteractive_need_newline
)
6792 putc ('\n', stderr
);
6793 noninteractive_need_newline
= 0;
6794 fprintf (stderr
, m
, a1
, a2
, a3
);
6795 if (cursor_in_echo_area
== 0)
6796 fprintf (stderr
, "\n");
6800 else if (INTERACTIVE
)
6802 /* The frame whose mini-buffer we're going to display the message
6803 on. It may be larger than the selected frame, so we need to
6804 use its buffer, not the selected frame's buffer. */
6805 Lisp_Object mini_window
;
6806 struct frame
*f
, *sf
= SELECTED_FRAME ();
6808 /* Get the frame containing the mini-buffer
6809 that the selected frame is using. */
6810 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6811 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6813 /* A null message buffer means that the frame hasn't really been
6814 initialized yet. Error messages get reported properly by
6815 cmd_error, so this must be just an informative message; toss
6817 if (FRAME_MESSAGE_BUF (f
))
6828 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6829 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6831 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6832 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6834 #endif /* NO_ARG_ARRAY */
6836 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6841 /* Print should start at the beginning of the message
6842 buffer next time. */
6843 message_buf_print
= 0;
6849 /* The non-logging version of message. */
6852 message_nolog (m
, a1
, a2
, a3
)
6854 EMACS_INT a1
, a2
, a3
;
6856 Lisp_Object old_log_max
;
6857 old_log_max
= Vmessage_log_max
;
6858 Vmessage_log_max
= Qnil
;
6859 message (m
, a1
, a2
, a3
);
6860 Vmessage_log_max
= old_log_max
;
6864 /* Display the current message in the current mini-buffer. This is
6865 only called from error handlers in process.c, and is not time
6871 if (!NILP (echo_area_buffer
[0]))
6874 string
= Fcurrent_message ();
6875 message3 (string
, SBYTES (string
),
6876 !NILP (current_buffer
->enable_multibyte_characters
));
6881 /* Make sure echo area buffers in `echo_buffers' are live.
6882 If they aren't, make new ones. */
6885 ensure_echo_area_buffers ()
6889 for (i
= 0; i
< 2; ++i
)
6890 if (!BUFFERP (echo_buffer
[i
])
6891 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6894 Lisp_Object old_buffer
;
6897 old_buffer
= echo_buffer
[i
];
6898 sprintf (name
, " *Echo Area %d*", i
);
6899 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6900 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6902 for (j
= 0; j
< 2; ++j
)
6903 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6904 echo_area_buffer
[j
] = echo_buffer
[i
];
6909 /* Call FN with args A1..A4 with either the current or last displayed
6910 echo_area_buffer as current buffer.
6912 WHICH zero means use the current message buffer
6913 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6914 from echo_buffer[] and clear it.
6916 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6917 suitable buffer from echo_buffer[] and clear it.
6919 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6920 that the current message becomes the last displayed one, make
6921 choose a suitable buffer for echo_area_buffer[0], and clear it.
6923 Value is what FN returns. */
6926 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6929 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6935 int this_one
, the_other
, clear_buffer_p
, rc
;
6936 int count
= SPECPDL_INDEX ();
6938 /* If buffers aren't live, make new ones. */
6939 ensure_echo_area_buffers ();
6944 this_one
= 0, the_other
= 1;
6946 this_one
= 1, the_other
= 0;
6949 this_one
= 0, the_other
= 1;
6952 /* We need a fresh one in case the current echo buffer equals
6953 the one containing the last displayed echo area message. */
6954 if (!NILP (echo_area_buffer
[this_one
])
6955 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6956 echo_area_buffer
[this_one
] = Qnil
;
6959 /* Choose a suitable buffer from echo_buffer[] is we don't
6961 if (NILP (echo_area_buffer
[this_one
]))
6963 echo_area_buffer
[this_one
]
6964 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6965 ? echo_buffer
[the_other
]
6966 : echo_buffer
[this_one
]);
6970 buffer
= echo_area_buffer
[this_one
];
6972 /* Don't get confused by reusing the buffer used for echoing
6973 for a different purpose. */
6974 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
6977 record_unwind_protect (unwind_with_echo_area_buffer
,
6978 with_echo_area_buffer_unwind_data (w
));
6980 /* Make the echo area buffer current. Note that for display
6981 purposes, it is not necessary that the displayed window's buffer
6982 == current_buffer, except for text property lookup. So, let's
6983 only set that buffer temporarily here without doing a full
6984 Fset_window_buffer. We must also change w->pointm, though,
6985 because otherwise an assertions in unshow_buffer fails, and Emacs
6987 set_buffer_internal_1 (XBUFFER (buffer
));
6991 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6994 current_buffer
->undo_list
= Qt
;
6995 current_buffer
->read_only
= Qnil
;
6996 specbind (Qinhibit_read_only
, Qt
);
6997 specbind (Qinhibit_modification_hooks
, Qt
);
6999 if (clear_buffer_p
&& Z
> BEG
)
7002 xassert (BEGV
>= BEG
);
7003 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7005 rc
= fn (a1
, a2
, a3
, a4
);
7007 xassert (BEGV
>= BEG
);
7008 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7010 unbind_to (count
, Qnil
);
7015 /* Save state that should be preserved around the call to the function
7016 FN called in with_echo_area_buffer. */
7019 with_echo_area_buffer_unwind_data (w
)
7025 /* Reduce consing by keeping one vector in
7026 Vwith_echo_area_save_vector. */
7027 vector
= Vwith_echo_area_save_vector
;
7028 Vwith_echo_area_save_vector
= Qnil
;
7031 vector
= Fmake_vector (make_number (7), Qnil
);
7033 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7034 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7035 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7039 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7040 AREF (vector
, i
) = w
->buffer
; ++i
;
7041 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7042 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7047 for (; i
< end
; ++i
)
7048 AREF (vector
, i
) = Qnil
;
7051 xassert (i
== ASIZE (vector
));
7056 /* Restore global state from VECTOR which was created by
7057 with_echo_area_buffer_unwind_data. */
7060 unwind_with_echo_area_buffer (vector
)
7063 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7064 Vdeactivate_mark
= AREF (vector
, 1);
7065 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7067 if (WINDOWP (AREF (vector
, 3)))
7070 Lisp_Object buffer
, charpos
, bytepos
;
7072 w
= XWINDOW (AREF (vector
, 3));
7073 buffer
= AREF (vector
, 4);
7074 charpos
= AREF (vector
, 5);
7075 bytepos
= AREF (vector
, 6);
7078 set_marker_both (w
->pointm
, buffer
,
7079 XFASTINT (charpos
), XFASTINT (bytepos
));
7082 Vwith_echo_area_save_vector
= vector
;
7087 /* Set up the echo area for use by print functions. MULTIBYTE_P
7088 non-zero means we will print multibyte. */
7091 setup_echo_area_for_printing (multibyte_p
)
7094 /* If we can't find an echo area any more, exit. */
7095 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7098 ensure_echo_area_buffers ();
7100 if (!message_buf_print
)
7102 /* A message has been output since the last time we printed.
7103 Choose a fresh echo area buffer. */
7104 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7105 echo_area_buffer
[0] = echo_buffer
[1];
7107 echo_area_buffer
[0] = echo_buffer
[0];
7109 /* Switch to that buffer and clear it. */
7110 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7111 current_buffer
->truncate_lines
= Qnil
;
7115 int count
= SPECPDL_INDEX ();
7116 specbind (Qinhibit_read_only
, Qt
);
7117 /* Note that undo recording is always disabled. */
7119 unbind_to (count
, Qnil
);
7121 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7123 /* Set up the buffer for the multibyteness we need. */
7125 != !NILP (current_buffer
->enable_multibyte_characters
))
7126 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7128 /* Raise the frame containing the echo area. */
7129 if (minibuffer_auto_raise
)
7131 struct frame
*sf
= SELECTED_FRAME ();
7132 Lisp_Object mini_window
;
7133 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7134 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7137 message_log_maybe_newline ();
7138 message_buf_print
= 1;
7142 if (NILP (echo_area_buffer
[0]))
7144 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7145 echo_area_buffer
[0] = echo_buffer
[1];
7147 echo_area_buffer
[0] = echo_buffer
[0];
7150 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7152 /* Someone switched buffers between print requests. */
7153 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7154 current_buffer
->truncate_lines
= Qnil
;
7160 /* Display an echo area message in window W. Value is non-zero if W's
7161 height is changed. If display_last_displayed_message_p is
7162 non-zero, display the message that was last displayed, otherwise
7163 display the current message. */
7166 display_echo_area (w
)
7169 int i
, no_message_p
, window_height_changed_p
, count
;
7171 /* Temporarily disable garbage collections while displaying the echo
7172 area. This is done because a GC can print a message itself.
7173 That message would modify the echo area buffer's contents while a
7174 redisplay of the buffer is going on, and seriously confuse
7176 count
= inhibit_garbage_collection ();
7178 /* If there is no message, we must call display_echo_area_1
7179 nevertheless because it resizes the window. But we will have to
7180 reset the echo_area_buffer in question to nil at the end because
7181 with_echo_area_buffer will sets it to an empty buffer. */
7182 i
= display_last_displayed_message_p
? 1 : 0;
7183 no_message_p
= NILP (echo_area_buffer
[i
]);
7185 window_height_changed_p
7186 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7187 display_echo_area_1
,
7188 (EMACS_INT
) w
, Qnil
, 0, 0);
7191 echo_area_buffer
[i
] = Qnil
;
7193 unbind_to (count
, Qnil
);
7194 return window_height_changed_p
;
7198 /* Helper for display_echo_area. Display the current buffer which
7199 contains the current echo area message in window W, a mini-window,
7200 a pointer to which is passed in A1. A2..A4 are currently not used.
7201 Change the height of W so that all of the message is displayed.
7202 Value is non-zero if height of W was changed. */
7205 display_echo_area_1 (a1
, a2
, a3
, a4
)
7210 struct window
*w
= (struct window
*) a1
;
7212 struct text_pos start
;
7213 int window_height_changed_p
= 0;
7215 /* Do this before displaying, so that we have a large enough glyph
7216 matrix for the display. */
7217 window_height_changed_p
= resize_mini_window (w
, 0);
7220 clear_glyph_matrix (w
->desired_matrix
);
7221 XSETWINDOW (window
, w
);
7222 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
7223 try_window (window
, start
);
7225 return window_height_changed_p
;
7229 /* Resize the echo area window to exactly the size needed for the
7230 currently displayed message, if there is one. If a mini-buffer
7231 is active, don't shrink it. */
7234 resize_echo_area_exactly ()
7236 if (BUFFERP (echo_area_buffer
[0])
7237 && WINDOWP (echo_area_window
))
7239 struct window
*w
= XWINDOW (echo_area_window
);
7241 Lisp_Object resize_exactly
;
7243 if (minibuf_level
== 0)
7244 resize_exactly
= Qt
;
7246 resize_exactly
= Qnil
;
7248 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7249 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7252 ++windows_or_buffers_changed
;
7253 ++update_mode_lines
;
7254 redisplay_internal (0);
7260 /* Callback function for with_echo_area_buffer, when used from
7261 resize_echo_area_exactly. A1 contains a pointer to the window to
7262 resize, EXACTLY non-nil means resize the mini-window exactly to the
7263 size of the text displayed. A3 and A4 are not used. Value is what
7264 resize_mini_window returns. */
7267 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
7269 Lisp_Object exactly
;
7272 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
7276 /* Resize mini-window W to fit the size of its contents. EXACT:P
7277 means size the window exactly to the size needed. Otherwise, it's
7278 only enlarged until W's buffer is empty. Value is non-zero if
7279 the window height has been changed. */
7282 resize_mini_window (w
, exact_p
)
7286 struct frame
*f
= XFRAME (w
->frame
);
7287 int window_height_changed_p
= 0;
7289 xassert (MINI_WINDOW_P (w
));
7291 /* Don't resize windows while redisplaying a window; it would
7292 confuse redisplay functions when the size of the window they are
7293 displaying changes from under them. Such a resizing can happen,
7294 for instance, when which-func prints a long message while
7295 we are running fontification-functions. We're running these
7296 functions with safe_call which binds inhibit-redisplay to t. */
7297 if (!NILP (Vinhibit_redisplay
))
7300 /* Nil means don't try to resize. */
7301 if (NILP (Vresize_mini_windows
)
7302 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
7305 if (!FRAME_MINIBUF_ONLY_P (f
))
7308 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7309 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
7310 int height
, max_height
;
7311 int unit
= FRAME_LINE_HEIGHT (f
);
7312 struct text_pos start
;
7313 struct buffer
*old_current_buffer
= NULL
;
7315 if (current_buffer
!= XBUFFER (w
->buffer
))
7317 old_current_buffer
= current_buffer
;
7318 set_buffer_internal (XBUFFER (w
->buffer
));
7321 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
7323 /* Compute the max. number of lines specified by the user. */
7324 if (FLOATP (Vmax_mini_window_height
))
7325 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
7326 else if (INTEGERP (Vmax_mini_window_height
))
7327 max_height
= XINT (Vmax_mini_window_height
);
7329 max_height
= total_height
/ 4;
7331 /* Correct that max. height if it's bogus. */
7332 max_height
= max (1, max_height
);
7333 max_height
= min (total_height
, max_height
);
7335 /* Find out the height of the text in the window. */
7336 if (it
.truncate_lines_p
)
7341 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
7342 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
7343 height
= it
.current_y
+ last_height
;
7345 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
7346 height
-= it
.extra_line_spacing
;
7347 height
= (height
+ unit
- 1) / unit
;
7350 /* Compute a suitable window start. */
7351 if (height
> max_height
)
7353 height
= max_height
;
7354 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
7355 move_it_vertically_backward (&it
, (height
- 1) * unit
);
7356 start
= it
.current
.pos
;
7359 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
7360 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
7362 if (EQ (Vresize_mini_windows
, Qgrow_only
))
7364 /* Let it grow only, until we display an empty message, in which
7365 case the window shrinks again. */
7366 if (height
> WINDOW_TOTAL_LINES (w
))
7368 int old_height
= WINDOW_TOTAL_LINES (w
);
7369 freeze_window_starts (f
, 1);
7370 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7371 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7373 else if (height
< WINDOW_TOTAL_LINES (w
)
7374 && (exact_p
|| BEGV
== ZV
))
7376 int old_height
= WINDOW_TOTAL_LINES (w
);
7377 freeze_window_starts (f
, 0);
7378 shrink_mini_window (w
);
7379 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7384 /* Always resize to exact size needed. */
7385 if (height
> WINDOW_TOTAL_LINES (w
))
7387 int old_height
= WINDOW_TOTAL_LINES (w
);
7388 freeze_window_starts (f
, 1);
7389 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7390 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7392 else if (height
< WINDOW_TOTAL_LINES (w
))
7394 int old_height
= WINDOW_TOTAL_LINES (w
);
7395 freeze_window_starts (f
, 0);
7396 shrink_mini_window (w
);
7400 freeze_window_starts (f
, 1);
7401 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7404 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7408 if (old_current_buffer
)
7409 set_buffer_internal (old_current_buffer
);
7412 return window_height_changed_p
;
7416 /* Value is the current message, a string, or nil if there is no
7424 if (NILP (echo_area_buffer
[0]))
7428 with_echo_area_buffer (0, 0, current_message_1
,
7429 (EMACS_INT
) &msg
, Qnil
, 0, 0);
7431 echo_area_buffer
[0] = Qnil
;
7439 current_message_1 (a1
, a2
, a3
, a4
)
7444 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
7447 *msg
= make_buffer_string (BEG
, Z
, 1);
7454 /* Push the current message on Vmessage_stack for later restauration
7455 by restore_message. Value is non-zero if the current message isn't
7456 empty. This is a relatively infrequent operation, so it's not
7457 worth optimizing. */
7463 msg
= current_message ();
7464 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
7465 return STRINGP (msg
);
7469 /* Restore message display from the top of Vmessage_stack. */
7476 xassert (CONSP (Vmessage_stack
));
7477 msg
= XCAR (Vmessage_stack
);
7479 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
7481 message3_nolog (msg
, 0, 0);
7485 /* Handler for record_unwind_protect calling pop_message. */
7488 pop_message_unwind (dummy
)
7495 /* Pop the top-most entry off Vmessage_stack. */
7500 xassert (CONSP (Vmessage_stack
));
7501 Vmessage_stack
= XCDR (Vmessage_stack
);
7505 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
7506 exits. If the stack is not empty, we have a missing pop_message
7510 check_message_stack ()
7512 if (!NILP (Vmessage_stack
))
7517 /* Truncate to NCHARS what will be displayed in the echo area the next
7518 time we display it---but don't redisplay it now. */
7521 truncate_echo_area (nchars
)
7525 echo_area_buffer
[0] = Qnil
;
7526 /* A null message buffer means that the frame hasn't really been
7527 initialized yet. Error messages get reported properly by
7528 cmd_error, so this must be just an informative message; toss it. */
7529 else if (!noninteractive
7531 && !NILP (echo_area_buffer
[0]))
7533 struct frame
*sf
= SELECTED_FRAME ();
7534 if (FRAME_MESSAGE_BUF (sf
))
7535 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
7540 /* Helper function for truncate_echo_area. Truncate the current
7541 message to at most NCHARS characters. */
7544 truncate_message_1 (nchars
, a2
, a3
, a4
)
7549 if (BEG
+ nchars
< Z
)
7550 del_range (BEG
+ nchars
, Z
);
7552 echo_area_buffer
[0] = Qnil
;
7557 /* Set the current message to a substring of S or STRING.
7559 If STRING is a Lisp string, set the message to the first NBYTES
7560 bytes from STRING. NBYTES zero means use the whole string. If
7561 STRING is multibyte, the message will be displayed multibyte.
7563 If S is not null, set the message to the first LEN bytes of S. LEN
7564 zero means use the whole string. MULTIBYTE_P non-zero means S is
7565 multibyte. Display the message multibyte in that case. */
7568 set_message (s
, string
, nbytes
, multibyte_p
)
7571 int nbytes
, multibyte_p
;
7573 message_enable_multibyte
7574 = ((s
&& multibyte_p
)
7575 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
7577 with_echo_area_buffer (0, -1, set_message_1
,
7578 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
7579 message_buf_print
= 0;
7580 help_echo_showing_p
= 0;
7584 /* Helper function for set_message. Arguments have the same meaning
7585 as there, with A1 corresponding to S and A2 corresponding to STRING
7586 This function is called with the echo area buffer being
7590 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
7593 EMACS_INT nbytes
, multibyte_p
;
7595 const char *s
= (const char *) a1
;
7596 Lisp_Object string
= a2
;
7600 /* Change multibyteness of the echo buffer appropriately. */
7601 if (message_enable_multibyte
7602 != !NILP (current_buffer
->enable_multibyte_characters
))
7603 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
7605 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
7607 /* Insert new message at BEG. */
7608 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7610 if (STRINGP (string
))
7615 nbytes
= SBYTES (string
);
7616 nchars
= string_byte_to_char (string
, nbytes
);
7618 /* This function takes care of single/multibyte conversion. We
7619 just have to ensure that the echo area buffer has the right
7620 setting of enable_multibyte_characters. */
7621 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7626 nbytes
= strlen (s
);
7628 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
7630 /* Convert from multi-byte to single-byte. */
7632 unsigned char work
[1];
7634 /* Convert a multibyte string to single-byte. */
7635 for (i
= 0; i
< nbytes
; i
+= n
)
7637 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
7638 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7640 : multibyte_char_to_unibyte (c
, Qnil
));
7641 insert_1_both (work
, 1, 1, 1, 0, 0);
7644 else if (!multibyte_p
7645 && !NILP (current_buffer
->enable_multibyte_characters
))
7647 /* Convert from single-byte to multi-byte. */
7649 const unsigned char *msg
= (const unsigned char *) s
;
7650 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7652 /* Convert a single-byte string to multibyte. */
7653 for (i
= 0; i
< nbytes
; i
++)
7655 c
= unibyte_char_to_multibyte (msg
[i
]);
7656 n
= CHAR_STRING (c
, str
);
7657 insert_1_both (str
, 1, n
, 1, 0, 0);
7661 insert_1 (s
, nbytes
, 1, 0, 0);
7668 /* Clear messages. CURRENT_P non-zero means clear the current
7669 message. LAST_DISPLAYED_P non-zero means clear the message
7673 clear_message (current_p
, last_displayed_p
)
7674 int current_p
, last_displayed_p
;
7678 echo_area_buffer
[0] = Qnil
;
7679 message_cleared_p
= 1;
7682 if (last_displayed_p
)
7683 echo_area_buffer
[1] = Qnil
;
7685 message_buf_print
= 0;
7688 /* Clear garbaged frames.
7690 This function is used where the old redisplay called
7691 redraw_garbaged_frames which in turn called redraw_frame which in
7692 turn called clear_frame. The call to clear_frame was a source of
7693 flickering. I believe a clear_frame is not necessary. It should
7694 suffice in the new redisplay to invalidate all current matrices,
7695 and ensure a complete redisplay of all windows. */
7698 clear_garbaged_frames ()
7702 Lisp_Object tail
, frame
;
7703 int changed_count
= 0;
7705 FOR_EACH_FRAME (tail
, frame
)
7707 struct frame
*f
= XFRAME (frame
);
7709 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7713 Fredraw_frame (frame
);
7714 f
->force_flush_display_p
= 1;
7716 clear_current_matrices (f
);
7725 ++windows_or_buffers_changed
;
7730 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7731 is non-zero update selected_frame. Value is non-zero if the
7732 mini-windows height has been changed. */
7735 echo_area_display (update_frame_p
)
7738 Lisp_Object mini_window
;
7741 int window_height_changed_p
= 0;
7742 struct frame
*sf
= SELECTED_FRAME ();
7744 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7745 w
= XWINDOW (mini_window
);
7746 f
= XFRAME (WINDOW_FRAME (w
));
7748 /* Don't display if frame is invisible or not yet initialized. */
7749 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7752 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7754 #ifdef HAVE_WINDOW_SYSTEM
7755 /* When Emacs starts, selected_frame may be a visible terminal
7756 frame, even if we run under a window system. If we let this
7757 through, a message would be displayed on the terminal. */
7758 if (EQ (selected_frame
, Vterminal_frame
)
7759 && !NILP (Vwindow_system
))
7761 #endif /* HAVE_WINDOW_SYSTEM */
7764 /* Redraw garbaged frames. */
7766 clear_garbaged_frames ();
7768 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7770 echo_area_window
= mini_window
;
7771 window_height_changed_p
= display_echo_area (w
);
7772 w
->must_be_updated_p
= 1;
7774 /* Update the display, unless called from redisplay_internal.
7775 Also don't update the screen during redisplay itself. The
7776 update will happen at the end of redisplay, and an update
7777 here could cause confusion. */
7778 if (update_frame_p
&& !redisplaying_p
)
7782 /* If the display update has been interrupted by pending
7783 input, update mode lines in the frame. Due to the
7784 pending input, it might have been that redisplay hasn't
7785 been called, so that mode lines above the echo area are
7786 garbaged. This looks odd, so we prevent it here. */
7787 if (!display_completed
)
7788 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7790 if (window_height_changed_p
7791 /* Don't do this if Emacs is shutting down. Redisplay
7792 needs to run hooks. */
7793 && !NILP (Vrun_hooks
))
7795 /* Must update other windows. Likewise as in other
7796 cases, don't let this update be interrupted by
7798 int count
= SPECPDL_INDEX ();
7799 specbind (Qredisplay_dont_pause
, Qt
);
7800 windows_or_buffers_changed
= 1;
7801 redisplay_internal (0);
7802 unbind_to (count
, Qnil
);
7804 else if (FRAME_WINDOW_P (f
) && n
== 0)
7806 /* Window configuration is the same as before.
7807 Can do with a display update of the echo area,
7808 unless we displayed some mode lines. */
7809 update_single_window (w
, 1);
7810 rif
->flush_display (f
);
7813 update_frame (f
, 1, 1);
7815 /* If cursor is in the echo area, make sure that the next
7816 redisplay displays the minibuffer, so that the cursor will
7817 be replaced with what the minibuffer wants. */
7818 if (cursor_in_echo_area
)
7819 ++windows_or_buffers_changed
;
7822 else if (!EQ (mini_window
, selected_window
))
7823 windows_or_buffers_changed
++;
7825 /* Last displayed message is now the current message. */
7826 echo_area_buffer
[1] = echo_area_buffer
[0];
7828 /* Prevent redisplay optimization in redisplay_internal by resetting
7829 this_line_start_pos. This is done because the mini-buffer now
7830 displays the message instead of its buffer text. */
7831 if (EQ (mini_window
, selected_window
))
7832 CHARPOS (this_line_start_pos
) = 0;
7834 return window_height_changed_p
;
7839 /***********************************************************************
7841 ***********************************************************************/
7844 /* The frame title buffering code is also used by Fformat_mode_line.
7845 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
7847 /* A buffer for constructing frame titles in it; allocated from the
7848 heap in init_xdisp and resized as needed in store_frame_title_char. */
7850 static char *frame_title_buf
;
7852 /* The buffer's end, and a current output position in it. */
7854 static char *frame_title_buf_end
;
7855 static char *frame_title_ptr
;
7858 /* Store a single character C for the frame title in frame_title_buf.
7859 Re-allocate frame_title_buf if necessary. */
7863 store_frame_title_char (char c
)
7865 store_frame_title_char (c
)
7869 /* If output position has reached the end of the allocated buffer,
7870 double the buffer's size. */
7871 if (frame_title_ptr
== frame_title_buf_end
)
7873 int len
= frame_title_ptr
- frame_title_buf
;
7874 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7875 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7876 frame_title_buf_end
= frame_title_buf
+ new_size
;
7877 frame_title_ptr
= frame_title_buf
+ len
;
7880 *frame_title_ptr
++ = c
;
7884 /* Store part of a frame title in frame_title_buf, beginning at
7885 frame_title_ptr. STR is the string to store. Do not copy
7886 characters that yield more columns than PRECISION; PRECISION <= 0
7887 means copy the whole string. Pad with spaces until FIELD_WIDTH
7888 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7889 pad. Called from display_mode_element when it is used to build a
7893 store_frame_title (str
, field_width
, precision
)
7894 const unsigned char *str
;
7895 int field_width
, precision
;
7900 /* Copy at most PRECISION chars from STR. */
7901 nbytes
= strlen (str
);
7902 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7904 store_frame_title_char (*str
++);
7906 /* Fill up with spaces until FIELD_WIDTH reached. */
7907 while (field_width
> 0
7910 store_frame_title_char (' ');
7917 #ifdef HAVE_WINDOW_SYSTEM
7919 /* Set the title of FRAME, if it has changed. The title format is
7920 Vicon_title_format if FRAME is iconified, otherwise it is
7921 frame_title_format. */
7924 x_consider_frame_title (frame
)
7927 struct frame
*f
= XFRAME (frame
);
7929 if (FRAME_WINDOW_P (f
)
7930 || FRAME_MINIBUF_ONLY_P (f
)
7931 || f
->explicit_name
)
7933 /* Do we have more than one visible frame on this X display? */
7936 struct buffer
*obuf
;
7940 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7942 Lisp_Object other_frame
= XCAR (tail
);
7943 struct frame
*tf
= XFRAME (other_frame
);
7946 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7947 && !FRAME_MINIBUF_ONLY_P (tf
)
7948 && !EQ (other_frame
, tip_frame
)
7949 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7953 /* Set global variable indicating that multiple frames exist. */
7954 multiple_frames
= CONSP (tail
);
7956 /* Switch to the buffer of selected window of the frame. Set up
7957 frame_title_ptr so that display_mode_element will output into it;
7958 then display the title. */
7959 obuf
= current_buffer
;
7960 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
7961 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7962 frame_title_ptr
= frame_title_buf
;
7963 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7964 NULL
, DEFAULT_FACE_ID
);
7965 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
7966 len
= frame_title_ptr
- frame_title_buf
;
7967 frame_title_ptr
= NULL
;
7968 set_buffer_internal_1 (obuf
);
7970 /* Set the title only if it's changed. This avoids consing in
7971 the common case where it hasn't. (If it turns out that we've
7972 already wasted too much time by walking through the list with
7973 display_mode_element, then we might need to optimize at a
7974 higher level than this.) */
7975 if (! STRINGP (f
->name
)
7976 || SBYTES (f
->name
) != len
7977 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
7978 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7982 #endif /* not HAVE_WINDOW_SYSTEM */
7987 /***********************************************************************
7989 ***********************************************************************/
7992 /* Prepare for redisplay by updating menu-bar item lists when
7993 appropriate. This can call eval. */
7996 prepare_menu_bars ()
7999 struct gcpro gcpro1
, gcpro2
;
8001 Lisp_Object tooltip_frame
;
8003 #ifdef HAVE_WINDOW_SYSTEM
8004 tooltip_frame
= tip_frame
;
8006 tooltip_frame
= Qnil
;
8009 /* Update all frame titles based on their buffer names, etc. We do
8010 this before the menu bars so that the buffer-menu will show the
8011 up-to-date frame titles. */
8012 #ifdef HAVE_WINDOW_SYSTEM
8013 if (windows_or_buffers_changed
|| update_mode_lines
)
8015 Lisp_Object tail
, frame
;
8017 FOR_EACH_FRAME (tail
, frame
)
8020 if (!EQ (frame
, tooltip_frame
)
8021 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8022 x_consider_frame_title (frame
);
8025 #endif /* HAVE_WINDOW_SYSTEM */
8027 /* Update the menu bar item lists, if appropriate. This has to be
8028 done before any actual redisplay or generation of display lines. */
8029 all_windows
= (update_mode_lines
8030 || buffer_shared
> 1
8031 || windows_or_buffers_changed
);
8034 Lisp_Object tail
, frame
;
8035 int count
= SPECPDL_INDEX ();
8037 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8039 FOR_EACH_FRAME (tail
, frame
)
8043 /* Ignore tooltip frame. */
8044 if (EQ (frame
, tooltip_frame
))
8047 /* If a window on this frame changed size, report that to
8048 the user and clear the size-change flag. */
8049 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8051 Lisp_Object functions
;
8053 /* Clear flag first in case we get an error below. */
8054 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8055 functions
= Vwindow_size_change_functions
;
8056 GCPRO2 (tail
, functions
);
8058 while (CONSP (functions
))
8060 call1 (XCAR (functions
), frame
);
8061 functions
= XCDR (functions
);
8067 update_menu_bar (f
, 0);
8068 #ifdef HAVE_WINDOW_SYSTEM
8069 update_tool_bar (f
, 0);
8074 unbind_to (count
, Qnil
);
8078 struct frame
*sf
= SELECTED_FRAME ();
8079 update_menu_bar (sf
, 1);
8080 #ifdef HAVE_WINDOW_SYSTEM
8081 update_tool_bar (sf
, 1);
8085 /* Motif needs this. See comment in xmenu.c. Turn it off when
8086 pending_menu_activation is not defined. */
8087 #ifdef USE_X_TOOLKIT
8088 pending_menu_activation
= 0;
8093 /* Update the menu bar item list for frame F. This has to be done
8094 before we start to fill in any display lines, because it can call
8097 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8100 update_menu_bar (f
, save_match_data
)
8102 int save_match_data
;
8105 register struct window
*w
;
8107 /* If called recursively during a menu update, do nothing. This can
8108 happen when, for instance, an activate-menubar-hook causes a
8110 if (inhibit_menubar_update
)
8113 window
= FRAME_SELECTED_WINDOW (f
);
8114 w
= XWINDOW (window
);
8116 #if 0 /* The if statement below this if statement used to include the
8117 condition !NILP (w->update_mode_line), rather than using
8118 update_mode_lines directly, and this if statement may have
8119 been added to make that condition work. Now the if
8120 statement below matches its comment, this isn't needed. */
8121 if (update_mode_lines
)
8122 w
->update_mode_line
= Qt
;
8125 if (FRAME_WINDOW_P (f
)
8127 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8128 || defined (USE_GTK)
8129 FRAME_EXTERNAL_MENU_BAR (f
)
8131 FRAME_MENU_BAR_LINES (f
) > 0
8133 : FRAME_MENU_BAR_LINES (f
) > 0)
8135 /* If the user has switched buffers or windows, we need to
8136 recompute to reflect the new bindings. But we'll
8137 recompute when update_mode_lines is set too; that means
8138 that people can use force-mode-line-update to request
8139 that the menu bar be recomputed. The adverse effect on
8140 the rest of the redisplay algorithm is about the same as
8141 windows_or_buffers_changed anyway. */
8142 if (windows_or_buffers_changed
8143 /* This used to test w->update_mode_line, but we believe
8144 there is no need to recompute the menu in that case. */
8145 || update_mode_lines
8146 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8147 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8148 != !NILP (w
->last_had_star
))
8149 || ((!NILP (Vtransient_mark_mode
)
8150 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8151 != !NILP (w
->region_showing
)))
8153 struct buffer
*prev
= current_buffer
;
8154 int count
= SPECPDL_INDEX ();
8156 specbind (Qinhibit_menubar_update
, Qt
);
8158 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8159 if (save_match_data
)
8160 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8161 if (NILP (Voverriding_local_map_menu_flag
))
8163 specbind (Qoverriding_terminal_local_map
, Qnil
);
8164 specbind (Qoverriding_local_map
, Qnil
);
8167 /* Run the Lucid hook. */
8168 safe_run_hooks (Qactivate_menubar_hook
);
8170 /* If it has changed current-menubar from previous value,
8171 really recompute the menu-bar from the value. */
8172 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8173 call0 (Qrecompute_lucid_menubar
);
8175 safe_run_hooks (Qmenu_bar_update_hook
);
8176 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
8178 /* Redisplay the menu bar in case we changed it. */
8179 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8180 || defined (USE_GTK)
8181 if (FRAME_WINDOW_P (f
)
8182 #if defined (MAC_OS)
8183 /* All frames on Mac OS share the same menubar. So only the
8184 selected frame should be allowed to set it. */
8185 && f
== SELECTED_FRAME ()
8188 set_frame_menubar (f
, 0, 0);
8190 /* On a terminal screen, the menu bar is an ordinary screen
8191 line, and this makes it get updated. */
8192 w
->update_mode_line
= Qt
;
8193 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8194 /* In the non-toolkit version, the menu bar is an ordinary screen
8195 line, and this makes it get updated. */
8196 w
->update_mode_line
= Qt
;
8197 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8199 unbind_to (count
, Qnil
);
8200 set_buffer_internal_1 (prev
);
8207 /***********************************************************************
8209 ***********************************************************************/
8211 #ifdef HAVE_WINDOW_SYSTEM
8214 Nominal cursor position -- where to draw output.
8215 HPOS and VPOS are window relative glyph matrix coordinates.
8216 X and Y are window relative pixel coordinates. */
8218 struct cursor_pos output_cursor
;
8222 Set the global variable output_cursor to CURSOR. All cursor
8223 positions are relative to updated_window. */
8226 set_output_cursor (cursor
)
8227 struct cursor_pos
*cursor
;
8229 output_cursor
.hpos
= cursor
->hpos
;
8230 output_cursor
.vpos
= cursor
->vpos
;
8231 output_cursor
.x
= cursor
->x
;
8232 output_cursor
.y
= cursor
->y
;
8237 Set a nominal cursor position.
8239 HPOS and VPOS are column/row positions in a window glyph matrix. X
8240 and Y are window text area relative pixel positions.
8242 If this is done during an update, updated_window will contain the
8243 window that is being updated and the position is the future output
8244 cursor position for that window. If updated_window is null, use
8245 selected_window and display the cursor at the given position. */
8248 x_cursor_to (vpos
, hpos
, y
, x
)
8249 int vpos
, hpos
, y
, x
;
8253 /* If updated_window is not set, work on selected_window. */
8257 w
= XWINDOW (selected_window
);
8259 /* Set the output cursor. */
8260 output_cursor
.hpos
= hpos
;
8261 output_cursor
.vpos
= vpos
;
8262 output_cursor
.x
= x
;
8263 output_cursor
.y
= y
;
8265 /* If not called as part of an update, really display the cursor.
8266 This will also set the cursor position of W. */
8267 if (updated_window
== NULL
)
8270 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8271 if (rif
->flush_display_optional
)
8272 rif
->flush_display_optional (SELECTED_FRAME ());
8277 #endif /* HAVE_WINDOW_SYSTEM */
8280 /***********************************************************************
8282 ***********************************************************************/
8284 #ifdef HAVE_WINDOW_SYSTEM
8286 /* Where the mouse was last time we reported a mouse event. */
8288 FRAME_PTR last_mouse_frame
;
8290 /* Tool-bar item index of the item on which a mouse button was pressed
8293 int last_tool_bar_item
;
8296 /* Update the tool-bar item list for frame F. This has to be done
8297 before we start to fill in any display lines. Called from
8298 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8299 and restore it here. */
8302 update_tool_bar (f
, save_match_data
)
8304 int save_match_data
;
8307 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
8309 int do_update
= WINDOWP (f
->tool_bar_window
)
8310 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
8318 window
= FRAME_SELECTED_WINDOW (f
);
8319 w
= XWINDOW (window
);
8321 /* If the user has switched buffers or windows, we need to
8322 recompute to reflect the new bindings. But we'll
8323 recompute when update_mode_lines is set too; that means
8324 that people can use force-mode-line-update to request
8325 that the menu bar be recomputed. The adverse effect on
8326 the rest of the redisplay algorithm is about the same as
8327 windows_or_buffers_changed anyway. */
8328 if (windows_or_buffers_changed
8329 || !NILP (w
->update_mode_line
)
8330 || update_mode_lines
8331 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8332 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8333 != !NILP (w
->last_had_star
))
8334 || ((!NILP (Vtransient_mark_mode
)
8335 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8336 != !NILP (w
->region_showing
)))
8338 struct buffer
*prev
= current_buffer
;
8339 int count
= SPECPDL_INDEX ();
8340 Lisp_Object old_tool_bar
;
8341 struct gcpro gcpro1
;
8343 /* Set current_buffer to the buffer of the selected
8344 window of the frame, so that we get the right local
8346 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8348 /* Save match data, if we must. */
8349 if (save_match_data
)
8350 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8352 /* Make sure that we don't accidentally use bogus keymaps. */
8353 if (NILP (Voverriding_local_map_menu_flag
))
8355 specbind (Qoverriding_terminal_local_map
, Qnil
);
8356 specbind (Qoverriding_local_map
, Qnil
);
8359 old_tool_bar
= f
->tool_bar_items
;
8360 GCPRO1 (old_tool_bar
);
8362 /* Build desired tool-bar items from keymaps. */
8365 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
8368 /* Redisplay the tool-bar if we changed it. */
8369 if (! NILP (Fequal (old_tool_bar
, f
->tool_bar_items
)))
8370 w
->update_mode_line
= Qt
;
8374 unbind_to (count
, Qnil
);
8375 set_buffer_internal_1 (prev
);
8381 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8382 F's desired tool-bar contents. F->tool_bar_items must have
8383 been set up previously by calling prepare_menu_bars. */
8386 build_desired_tool_bar_string (f
)
8389 int i
, size
, size_needed
;
8390 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8391 Lisp_Object image
, plist
, props
;
8393 image
= plist
= props
= Qnil
;
8394 GCPRO3 (image
, plist
, props
);
8396 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
8397 Otherwise, make a new string. */
8399 /* The size of the string we might be able to reuse. */
8400 size
= (STRINGP (f
->desired_tool_bar_string
)
8401 ? SCHARS (f
->desired_tool_bar_string
)
8404 /* We need one space in the string for each image. */
8405 size_needed
= f
->n_tool_bar_items
;
8407 /* Reuse f->desired_tool_bar_string, if possible. */
8408 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
8409 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
8413 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
8414 Fremove_text_properties (make_number (0), make_number (size
),
8415 props
, f
->desired_tool_bar_string
);
8418 /* Put a `display' property on the string for the images to display,
8419 put a `menu_item' property on tool-bar items with a value that
8420 is the index of the item in F's tool-bar item vector. */
8421 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
8423 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
8425 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8426 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8427 int hmargin
, vmargin
, relief
, idx
, end
;
8428 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
8430 /* If image is a vector, choose the image according to the
8432 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
8433 if (VECTORP (image
))
8437 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
8438 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
8441 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
8442 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
8444 xassert (ASIZE (image
) >= idx
);
8445 image
= AREF (image
, idx
);
8450 /* Ignore invalid image specifications. */
8451 if (!valid_image_p (image
))
8454 /* Display the tool-bar button pressed, or depressed. */
8455 plist
= Fcopy_sequence (XCDR (image
));
8457 /* Compute margin and relief to draw. */
8458 relief
= (tool_bar_button_relief
>= 0
8459 ? tool_bar_button_relief
8460 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
8461 hmargin
= vmargin
= relief
;
8463 if (INTEGERP (Vtool_bar_button_margin
)
8464 && XINT (Vtool_bar_button_margin
) > 0)
8466 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
8467 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
8469 else if (CONSP (Vtool_bar_button_margin
))
8471 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
8472 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
8473 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
8475 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
8476 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
8477 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
8480 if (auto_raise_tool_bar_buttons_p
)
8482 /* Add a `:relief' property to the image spec if the item is
8486 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
8493 /* If image is selected, display it pressed, i.e. with a
8494 negative relief. If it's not selected, display it with a
8496 plist
= Fplist_put (plist
, QCrelief
,
8498 ? make_number (-relief
)
8499 : make_number (relief
)));
8504 /* Put a margin around the image. */
8505 if (hmargin
|| vmargin
)
8507 if (hmargin
== vmargin
)
8508 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
8510 plist
= Fplist_put (plist
, QCmargin
,
8511 Fcons (make_number (hmargin
),
8512 make_number (vmargin
)));
8515 /* If button is not enabled, and we don't have special images
8516 for the disabled state, make the image appear disabled by
8517 applying an appropriate algorithm to it. */
8518 if (!enabled_p
&& idx
< 0)
8519 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
8521 /* Put a `display' text property on the string for the image to
8522 display. Put a `menu-item' property on the string that gives
8523 the start of this item's properties in the tool-bar items
8525 image
= Fcons (Qimage
, plist
);
8526 props
= list4 (Qdisplay
, image
,
8527 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
8529 /* Let the last image hide all remaining spaces in the tool bar
8530 string. The string can be longer than needed when we reuse a
8532 if (i
+ 1 == f
->n_tool_bar_items
)
8533 end
= SCHARS (f
->desired_tool_bar_string
);
8536 Fadd_text_properties (make_number (i
), make_number (end
),
8537 props
, f
->desired_tool_bar_string
);
8545 /* Display one line of the tool-bar of frame IT->f. */
8548 display_tool_bar_line (it
)
8551 struct glyph_row
*row
= it
->glyph_row
;
8552 int max_x
= it
->last_visible_x
;
8555 prepare_desired_row (row
);
8556 row
->y
= it
->current_y
;
8558 /* Note that this isn't made use of if the face hasn't a box,
8559 so there's no need to check the face here. */
8560 it
->start_of_box_run_p
= 1;
8562 while (it
->current_x
< max_x
)
8564 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
8566 /* Get the next display element. */
8567 if (!get_next_display_element (it
))
8570 /* Produce glyphs. */
8571 x_before
= it
->current_x
;
8572 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
8573 PRODUCE_GLYPHS (it
);
8575 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
8580 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
8582 if (x
+ glyph
->pixel_width
> max_x
)
8584 /* Glyph doesn't fit on line. */
8585 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
8591 x
+= glyph
->pixel_width
;
8595 /* Stop at line ends. */
8596 if (ITERATOR_AT_END_OF_LINE_P (it
))
8599 set_iterator_to_next (it
, 1);
8604 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
8605 extend_face_to_end_of_line (it
);
8606 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
8607 last
->right_box_line_p
= 1;
8608 if (last
== row
->glyphs
[TEXT_AREA
])
8609 last
->left_box_line_p
= 1;
8610 compute_line_metrics (it
);
8612 /* If line is empty, make it occupy the rest of the tool-bar. */
8613 if (!row
->displays_text_p
)
8615 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
8616 row
->ascent
= row
->phys_ascent
= 0;
8619 row
->full_width_p
= 1;
8620 row
->continued_p
= 0;
8621 row
->truncated_on_left_p
= 0;
8622 row
->truncated_on_right_p
= 0;
8624 it
->current_x
= it
->hpos
= 0;
8625 it
->current_y
+= row
->height
;
8631 /* Value is the number of screen lines needed to make all tool-bar
8632 items of frame F visible. */
8635 tool_bar_lines_needed (f
)
8638 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8641 /* Initialize an iterator for iteration over
8642 F->desired_tool_bar_string in the tool-bar window of frame F. */
8643 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8644 it
.first_visible_x
= 0;
8645 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8646 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8648 while (!ITERATOR_AT_END_P (&it
))
8650 it
.glyph_row
= w
->desired_matrix
->rows
;
8651 clear_glyph_row (it
.glyph_row
);
8652 display_tool_bar_line (&it
);
8655 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
8659 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
8661 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
8670 frame
= selected_frame
;
8672 CHECK_FRAME (frame
);
8675 if (WINDOWP (f
->tool_bar_window
)
8676 || (w
= XWINDOW (f
->tool_bar_window
),
8677 WINDOW_TOTAL_LINES (w
) > 0))
8679 update_tool_bar (f
, 1);
8680 if (f
->n_tool_bar_items
)
8682 build_desired_tool_bar_string (f
);
8683 nlines
= tool_bar_lines_needed (f
);
8687 return make_number (nlines
);
8691 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
8692 height should be changed. */
8695 redisplay_tool_bar (f
)
8700 struct glyph_row
*row
;
8701 int change_height_p
= 0;
8704 if (FRAME_EXTERNAL_TOOL_BAR (f
))
8705 update_frame_tool_bar (f
);
8709 /* If frame hasn't a tool-bar window or if it is zero-height, don't
8710 do anything. This means you must start with tool-bar-lines
8711 non-zero to get the auto-sizing effect. Or in other words, you
8712 can turn off tool-bars by specifying tool-bar-lines zero. */
8713 if (!WINDOWP (f
->tool_bar_window
)
8714 || (w
= XWINDOW (f
->tool_bar_window
),
8715 WINDOW_TOTAL_LINES (w
) == 0))
8718 /* Set up an iterator for the tool-bar window. */
8719 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8720 it
.first_visible_x
= 0;
8721 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8724 /* Build a string that represents the contents of the tool-bar. */
8725 build_desired_tool_bar_string (f
);
8726 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8728 /* Display as many lines as needed to display all tool-bar items. */
8729 while (it
.current_y
< it
.last_visible_y
)
8730 display_tool_bar_line (&it
);
8732 /* It doesn't make much sense to try scrolling in the tool-bar
8733 window, so don't do it. */
8734 w
->desired_matrix
->no_scrolling_p
= 1;
8735 w
->must_be_updated_p
= 1;
8737 if (auto_resize_tool_bars_p
)
8741 /* If we couldn't display everything, change the tool-bar's
8743 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
8744 change_height_p
= 1;
8746 /* If there are blank lines at the end, except for a partially
8747 visible blank line at the end that is smaller than
8748 FRAME_LINE_HEIGHT, change the tool-bar's height. */
8749 row
= it
.glyph_row
- 1;
8750 if (!row
->displays_text_p
8751 && row
->height
>= FRAME_LINE_HEIGHT (f
))
8752 change_height_p
= 1;
8754 /* If row displays tool-bar items, but is partially visible,
8755 change the tool-bar's height. */
8756 if (row
->displays_text_p
8757 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
8758 change_height_p
= 1;
8760 /* Resize windows as needed by changing the `tool-bar-lines'
8763 && (nlines
= tool_bar_lines_needed (f
),
8764 nlines
!= WINDOW_TOTAL_LINES (w
)))
8766 extern Lisp_Object Qtool_bar_lines
;
8768 int old_height
= WINDOW_TOTAL_LINES (w
);
8770 XSETFRAME (frame
, f
);
8771 clear_glyph_matrix (w
->desired_matrix
);
8772 Fmodify_frame_parameters (frame
,
8773 Fcons (Fcons (Qtool_bar_lines
,
8774 make_number (nlines
)),
8776 if (WINDOW_TOTAL_LINES (w
) != old_height
)
8777 fonts_changed_p
= 1;
8781 return change_height_p
;
8785 /* Get information about the tool-bar item which is displayed in GLYPH
8786 on frame F. Return in *PROP_IDX the index where tool-bar item
8787 properties start in F->tool_bar_items. Value is zero if
8788 GLYPH doesn't display a tool-bar item. */
8791 tool_bar_item_info (f
, glyph
, prop_idx
)
8793 struct glyph
*glyph
;
8800 /* This function can be called asynchronously, which means we must
8801 exclude any possibility that Fget_text_property signals an
8803 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
8804 charpos
= max (0, charpos
);
8806 /* Get the text property `menu-item' at pos. The value of that
8807 property is the start index of this item's properties in
8808 F->tool_bar_items. */
8809 prop
= Fget_text_property (make_number (charpos
),
8810 Qmenu_item
, f
->current_tool_bar_string
);
8811 if (INTEGERP (prop
))
8813 *prop_idx
= XINT (prop
);
8823 /* Get information about the tool-bar item at position X/Y on frame F.
8824 Return in *GLYPH a pointer to the glyph of the tool-bar item in
8825 the current matrix of the tool-bar window of F, or NULL if not
8826 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
8827 item in F->tool_bar_items. Value is
8829 -1 if X/Y is not on a tool-bar item
8830 0 if X/Y is on the same item that was highlighted before.
8834 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
8837 struct glyph
**glyph
;
8838 int *hpos
, *vpos
, *prop_idx
;
8840 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8841 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8844 /* Find the glyph under X/Y. */
8845 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
8849 /* Get the start of this tool-bar item's properties in
8850 f->tool_bar_items. */
8851 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
8854 /* Is mouse on the highlighted item? */
8855 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
8856 && *vpos
>= dpyinfo
->mouse_face_beg_row
8857 && *vpos
<= dpyinfo
->mouse_face_end_row
8858 && (*vpos
> dpyinfo
->mouse_face_beg_row
8859 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
8860 && (*vpos
< dpyinfo
->mouse_face_end_row
8861 || *hpos
< dpyinfo
->mouse_face_end_col
8862 || dpyinfo
->mouse_face_past_end
))
8870 Handle mouse button event on the tool-bar of frame F, at
8871 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
8872 0 for button release. MODIFIERS is event modifiers for button
8876 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
8879 unsigned int modifiers
;
8881 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8882 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8883 int hpos
, vpos
, prop_idx
;
8884 struct glyph
*glyph
;
8885 Lisp_Object enabled_p
;
8887 /* If not on the highlighted tool-bar item, return. */
8888 frame_to_window_pixel_xy (w
, &x
, &y
);
8889 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
8892 /* If item is disabled, do nothing. */
8893 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
8894 if (NILP (enabled_p
))
8899 /* Show item in pressed state. */
8900 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
8901 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
8902 last_tool_bar_item
= prop_idx
;
8906 Lisp_Object key
, frame
;
8907 struct input_event event
;
8910 /* Show item in released state. */
8911 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
8912 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
8914 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
8916 XSETFRAME (frame
, f
);
8917 event
.kind
= TOOL_BAR_EVENT
;
8918 event
.frame_or_window
= frame
;
8920 kbd_buffer_store_event (&event
);
8922 event
.kind
= TOOL_BAR_EVENT
;
8923 event
.frame_or_window
= frame
;
8925 event
.modifiers
= modifiers
;
8926 kbd_buffer_store_event (&event
);
8927 last_tool_bar_item
= -1;
8932 /* Possibly highlight a tool-bar item on frame F when mouse moves to
8933 tool-bar window-relative coordinates X/Y. Called from
8934 note_mouse_highlight. */
8937 note_tool_bar_highlight (f
, x
, y
)
8941 Lisp_Object window
= f
->tool_bar_window
;
8942 struct window
*w
= XWINDOW (window
);
8943 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8945 struct glyph
*glyph
;
8946 struct glyph_row
*row
;
8948 Lisp_Object enabled_p
;
8950 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
8951 int mouse_down_p
, rc
;
8953 /* Function note_mouse_highlight is called with negative x(y
8954 values when mouse moves outside of the frame. */
8955 if (x
<= 0 || y
<= 0)
8957 clear_mouse_face (dpyinfo
);
8961 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
8964 /* Not on tool-bar item. */
8965 clear_mouse_face (dpyinfo
);
8969 /* On same tool-bar item as before. */
8972 clear_mouse_face (dpyinfo
);
8974 /* Mouse is down, but on different tool-bar item? */
8975 mouse_down_p
= (dpyinfo
->grabbed
8976 && f
== last_mouse_frame
8977 && FRAME_LIVE_P (f
));
8979 && last_tool_bar_item
!= prop_idx
)
8982 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
8983 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
8985 /* If tool-bar item is not enabled, don't highlight it. */
8986 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
8987 if (!NILP (enabled_p
))
8989 /* Compute the x-position of the glyph. In front and past the
8990 image is a space. We include this in the highlighted area. */
8991 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
8992 for (i
= x
= 0; i
< hpos
; ++i
)
8993 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
8995 /* Record this as the current active region. */
8996 dpyinfo
->mouse_face_beg_col
= hpos
;
8997 dpyinfo
->mouse_face_beg_row
= vpos
;
8998 dpyinfo
->mouse_face_beg_x
= x
;
8999 dpyinfo
->mouse_face_beg_y
= row
->y
;
9000 dpyinfo
->mouse_face_past_end
= 0;
9002 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9003 dpyinfo
->mouse_face_end_row
= vpos
;
9004 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9005 dpyinfo
->mouse_face_end_y
= row
->y
;
9006 dpyinfo
->mouse_face_window
= window
;
9007 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9009 /* Display it as active. */
9010 show_mouse_face (dpyinfo
, draw
);
9011 dpyinfo
->mouse_face_image_state
= draw
;
9016 /* Set help_echo_string to a help string to display for this tool-bar item.
9017 XTread_socket does the rest. */
9018 help_echo_object
= help_echo_window
= Qnil
;
9020 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9021 if (NILP (help_echo_string
))
9022 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9025 #endif /* HAVE_WINDOW_SYSTEM */
9029 /************************************************************************
9030 Horizontal scrolling
9031 ************************************************************************/
9033 static int hscroll_window_tree
P_ ((Lisp_Object
));
9034 static int hscroll_windows
P_ ((Lisp_Object
));
9036 /* For all leaf windows in the window tree rooted at WINDOW, set their
9037 hscroll value so that PT is (i) visible in the window, and (ii) so
9038 that it is not within a certain margin at the window's left and
9039 right border. Value is non-zero if any window's hscroll has been
9043 hscroll_window_tree (window
)
9046 int hscrolled_p
= 0;
9047 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9048 int hscroll_step_abs
= 0;
9049 double hscroll_step_rel
= 0;
9051 if (hscroll_relative_p
)
9053 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9054 if (hscroll_step_rel
< 0)
9056 hscroll_relative_p
= 0;
9057 hscroll_step_abs
= 0;
9060 else if (INTEGERP (Vhscroll_step
))
9062 hscroll_step_abs
= XINT (Vhscroll_step
);
9063 if (hscroll_step_abs
< 0)
9064 hscroll_step_abs
= 0;
9067 hscroll_step_abs
= 0;
9069 while (WINDOWP (window
))
9071 struct window
*w
= XWINDOW (window
);
9073 if (WINDOWP (w
->hchild
))
9074 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9075 else if (WINDOWP (w
->vchild
))
9076 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9077 else if (w
->cursor
.vpos
>= 0)
9080 int text_area_width
;
9081 struct glyph_row
*current_cursor_row
9082 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9083 struct glyph_row
*desired_cursor_row
9084 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9085 struct glyph_row
*cursor_row
9086 = (desired_cursor_row
->enabled_p
9087 ? desired_cursor_row
9088 : current_cursor_row
);
9090 text_area_width
= window_box_width (w
, TEXT_AREA
);
9092 /* Scroll when cursor is inside this scroll margin. */
9093 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9095 if ((XFASTINT (w
->hscroll
)
9096 && w
->cursor
.x
<= h_margin
)
9097 || (cursor_row
->enabled_p
9098 && cursor_row
->truncated_on_right_p
9099 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9103 struct buffer
*saved_current_buffer
;
9107 /* Find point in a display of infinite width. */
9108 saved_current_buffer
= current_buffer
;
9109 current_buffer
= XBUFFER (w
->buffer
);
9111 if (w
== XWINDOW (selected_window
))
9112 pt
= BUF_PT (current_buffer
);
9115 pt
= marker_position (w
->pointm
);
9116 pt
= max (BEGV
, pt
);
9120 /* Move iterator to pt starting at cursor_row->start in
9121 a line with infinite width. */
9122 init_to_row_start (&it
, w
, cursor_row
);
9123 it
.last_visible_x
= INFINITY
;
9124 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9125 current_buffer
= saved_current_buffer
;
9127 /* Position cursor in window. */
9128 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9129 hscroll
= max (0, (it
.current_x
9130 - (ITERATOR_AT_END_OF_LINE_P (&it
)
9131 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
9132 : (text_area_width
/ 2))))
9133 / FRAME_COLUMN_WIDTH (it
.f
);
9134 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9136 if (hscroll_relative_p
)
9137 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9140 wanted_x
= text_area_width
9141 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9144 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9148 if (hscroll_relative_p
)
9149 wanted_x
= text_area_width
* hscroll_step_rel
9152 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9155 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9157 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9159 /* Don't call Fset_window_hscroll if value hasn't
9160 changed because it will prevent redisplay
9162 if (XFASTINT (w
->hscroll
) != hscroll
)
9164 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9165 w
->hscroll
= make_number (hscroll
);
9174 /* Value is non-zero if hscroll of any leaf window has been changed. */
9179 /* Set hscroll so that cursor is visible and not inside horizontal
9180 scroll margins for all windows in the tree rooted at WINDOW. See
9181 also hscroll_window_tree above. Value is non-zero if any window's
9182 hscroll has been changed. If it has, desired matrices on the frame
9183 of WINDOW are cleared. */
9186 hscroll_windows (window
)
9191 if (automatic_hscrolling_p
)
9193 hscrolled_p
= hscroll_window_tree (window
);
9195 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9204 /************************************************************************
9206 ************************************************************************/
9208 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9209 to a non-zero value. This is sometimes handy to have in a debugger
9214 /* First and last unchanged row for try_window_id. */
9216 int debug_first_unchanged_at_end_vpos
;
9217 int debug_last_unchanged_at_beg_vpos
;
9219 /* Delta vpos and y. */
9221 int debug_dvpos
, debug_dy
;
9223 /* Delta in characters and bytes for try_window_id. */
9225 int debug_delta
, debug_delta_bytes
;
9227 /* Values of window_end_pos and window_end_vpos at the end of
9230 EMACS_INT debug_end_pos
, debug_end_vpos
;
9232 /* Append a string to W->desired_matrix->method. FMT is a printf
9233 format string. A1...A9 are a supplement for a variable-length
9234 argument list. If trace_redisplay_p is non-zero also printf the
9235 resulting string to stderr. */
9238 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9241 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9244 char *method
= w
->desired_matrix
->method
;
9245 int len
= strlen (method
);
9246 int size
= sizeof w
->desired_matrix
->method
;
9247 int remaining
= size
- len
- 1;
9249 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9250 if (len
&& remaining
)
9256 strncpy (method
+ len
, buffer
, remaining
);
9258 if (trace_redisplay_p
)
9259 fprintf (stderr
, "%p (%s): %s\n",
9261 ((BUFFERP (w
->buffer
)
9262 && STRINGP (XBUFFER (w
->buffer
)->name
))
9263 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9268 #endif /* GLYPH_DEBUG */
9271 /* Value is non-zero if all changes in window W, which displays
9272 current_buffer, are in the text between START and END. START is a
9273 buffer position, END is given as a distance from Z. Used in
9274 redisplay_internal for display optimization. */
9277 text_outside_line_unchanged_p (w
, start
, end
)
9281 int unchanged_p
= 1;
9283 /* If text or overlays have changed, see where. */
9284 if (XFASTINT (w
->last_modified
) < MODIFF
9285 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9287 /* Gap in the line? */
9288 if (GPT
< start
|| Z
- GPT
< end
)
9291 /* Changes start in front of the line, or end after it? */
9293 && (BEG_UNCHANGED
< start
- 1
9294 || END_UNCHANGED
< end
))
9297 /* If selective display, can't optimize if changes start at the
9298 beginning of the line. */
9300 && INTEGERP (current_buffer
->selective_display
)
9301 && XINT (current_buffer
->selective_display
) > 0
9302 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9305 /* If there are overlays at the start or end of the line, these
9306 may have overlay strings with newlines in them. A change at
9307 START, for instance, may actually concern the display of such
9308 overlay strings as well, and they are displayed on different
9309 lines. So, quickly rule out this case. (For the future, it
9310 might be desirable to implement something more telling than
9311 just BEG/END_UNCHANGED.) */
9314 if (BEG
+ BEG_UNCHANGED
== start
9315 && overlay_touches_p (start
))
9317 if (END_UNCHANGED
== end
9318 && overlay_touches_p (Z
- end
))
9327 /* Do a frame update, taking possible shortcuts into account. This is
9328 the main external entry point for redisplay.
9330 If the last redisplay displayed an echo area message and that message
9331 is no longer requested, we clear the echo area or bring back the
9332 mini-buffer if that is in use. */
9337 redisplay_internal (0);
9342 overlay_arrow_string_or_property (var
, pbitmap
)
9346 Lisp_Object pstr
= Fget (var
, Qoverlay_arrow_string
);
9352 if (bitmap
= Fget (var
, Qoverlay_arrow_bitmap
), INTEGERP (bitmap
))
9353 *pbitmap
= XINT (bitmap
);
9358 return Voverlay_arrow_string
;
9361 /* Return 1 if there are any overlay-arrows in current_buffer. */
9363 overlay_arrow_in_current_buffer_p ()
9367 for (vlist
= Voverlay_arrow_variable_list
;
9369 vlist
= XCDR (vlist
))
9371 Lisp_Object var
= XCAR (vlist
);
9376 val
= find_symbol_value (var
);
9378 && current_buffer
== XMARKER (val
)->buffer
)
9385 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
9389 overlay_arrows_changed_p ()
9393 for (vlist
= Voverlay_arrow_variable_list
;
9395 vlist
= XCDR (vlist
))
9397 Lisp_Object var
= XCAR (vlist
);
9398 Lisp_Object val
, pstr
;
9402 val
= find_symbol_value (var
);
9405 if (! EQ (COERCE_MARKER (val
),
9406 Fget (var
, Qlast_arrow_position
))
9407 || ! (pstr
= overlay_arrow_string_or_property (var
, 0),
9408 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
9414 /* Mark overlay arrows to be updated on next redisplay. */
9417 update_overlay_arrows (up_to_date
)
9422 for (vlist
= Voverlay_arrow_variable_list
;
9424 vlist
= XCDR (vlist
))
9426 Lisp_Object var
= XCAR (vlist
);
9433 Lisp_Object val
= find_symbol_value (var
);
9434 Fput (var
, Qlast_arrow_position
,
9435 COERCE_MARKER (val
));
9436 Fput (var
, Qlast_arrow_string
,
9437 overlay_arrow_string_or_property (var
, 0));
9439 else if (up_to_date
< 0
9440 || !NILP (Fget (var
, Qlast_arrow_position
)))
9442 Fput (var
, Qlast_arrow_position
, Qt
);
9443 Fput (var
, Qlast_arrow_string
, Qt
);
9449 /* Return overlay arrow string at row, or nil. */
9452 overlay_arrow_at_row (f
, row
, pbitmap
)
9454 struct glyph_row
*row
;
9459 for (vlist
= Voverlay_arrow_variable_list
;
9461 vlist
= XCDR (vlist
))
9463 Lisp_Object var
= XCAR (vlist
);
9469 val
= find_symbol_value (var
);
9472 && current_buffer
== XMARKER (val
)->buffer
9473 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
9475 val
= overlay_arrow_string_or_property (var
, pbitmap
);
9476 if (FRAME_WINDOW_P (f
))
9478 else if (STRINGP (val
))
9488 /* Return 1 if point moved out of or into a composition. Otherwise
9489 return 0. PREV_BUF and PREV_PT are the last point buffer and
9490 position. BUF and PT are the current point buffer and position. */
9493 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
9494 struct buffer
*prev_buf
, *buf
;
9501 XSETBUFFER (buffer
, buf
);
9502 /* Check a composition at the last point if point moved within the
9504 if (prev_buf
== buf
)
9507 /* Point didn't move. */
9510 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
9511 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
9512 && COMPOSITION_VALID_P (start
, end
, prop
)
9513 && start
< prev_pt
&& end
> prev_pt
)
9514 /* The last point was within the composition. Return 1 iff
9515 point moved out of the composition. */
9516 return (pt
<= start
|| pt
>= end
);
9519 /* Check a composition at the current point. */
9520 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
9521 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
9522 && COMPOSITION_VALID_P (start
, end
, prop
)
9523 && start
< pt
&& end
> pt
);
9527 /* Reconsider the setting of B->clip_changed which is displayed
9531 reconsider_clip_changes (w
, b
)
9536 && !NILP (w
->window_end_valid
)
9537 && w
->current_matrix
->buffer
== b
9538 && w
->current_matrix
->zv
== BUF_ZV (b
)
9539 && w
->current_matrix
->begv
== BUF_BEGV (b
))
9540 b
->clip_changed
= 0;
9542 /* If display wasn't paused, and W is not a tool bar window, see if
9543 point has been moved into or out of a composition. In that case,
9544 we set b->clip_changed to 1 to force updating the screen. If
9545 b->clip_changed has already been set to 1, we can skip this
9547 if (!b
->clip_changed
9548 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
9552 if (w
== XWINDOW (selected_window
))
9553 pt
= BUF_PT (current_buffer
);
9555 pt
= marker_position (w
->pointm
);
9557 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
9558 || pt
!= XINT (w
->last_point
))
9559 && check_point_in_composition (w
->current_matrix
->buffer
,
9560 XINT (w
->last_point
),
9561 XBUFFER (w
->buffer
), pt
))
9562 b
->clip_changed
= 1;
9567 /* Select FRAME to forward the values of frame-local variables into C
9568 variables so that the redisplay routines can access those values
9572 select_frame_for_redisplay (frame
)
9575 Lisp_Object tail
, sym
, val
;
9576 Lisp_Object old
= selected_frame
;
9578 selected_frame
= frame
;
9580 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9581 if (CONSP (XCAR (tail
))
9582 && (sym
= XCAR (XCAR (tail
)),
9584 && (sym
= indirect_variable (sym
),
9585 val
= SYMBOL_VALUE (sym
),
9586 (BUFFER_LOCAL_VALUEP (val
)
9587 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9588 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9589 Fsymbol_value (sym
);
9591 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9592 if (CONSP (XCAR (tail
))
9593 && (sym
= XCAR (XCAR (tail
)),
9595 && (sym
= indirect_variable (sym
),
9596 val
= SYMBOL_VALUE (sym
),
9597 (BUFFER_LOCAL_VALUEP (val
)
9598 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9599 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9600 Fsymbol_value (sym
);
9604 #define STOP_POLLING \
9605 do { if (! polling_stopped_here) stop_polling (); \
9606 polling_stopped_here = 1; } while (0)
9608 #define RESUME_POLLING \
9609 do { if (polling_stopped_here) start_polling (); \
9610 polling_stopped_here = 0; } while (0)
9613 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
9614 response to any user action; therefore, we should preserve the echo
9615 area. (Actually, our caller does that job.) Perhaps in the future
9616 avoid recentering windows if it is not necessary; currently that
9617 causes some problems. */
9620 redisplay_internal (preserve_echo_area
)
9621 int preserve_echo_area
;
9623 struct window
*w
= XWINDOW (selected_window
);
9624 struct frame
*f
= XFRAME (w
->frame
);
9626 int must_finish
= 0;
9627 struct text_pos tlbufpos
, tlendpos
;
9628 int number_of_visible_frames
;
9630 struct frame
*sf
= SELECTED_FRAME ();
9631 int polling_stopped_here
= 0;
9633 /* Non-zero means redisplay has to consider all windows on all
9634 frames. Zero means, only selected_window is considered. */
9635 int consider_all_windows_p
;
9637 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
9639 /* No redisplay if running in batch mode or frame is not yet fully
9640 initialized, or redisplay is explicitly turned off by setting
9641 Vinhibit_redisplay. */
9643 || !NILP (Vinhibit_redisplay
)
9644 || !f
->glyphs_initialized_p
)
9647 /* The flag redisplay_performed_directly_p is set by
9648 direct_output_for_insert when it already did the whole screen
9649 update necessary. */
9650 if (redisplay_performed_directly_p
)
9652 redisplay_performed_directly_p
= 0;
9653 if (!hscroll_windows (selected_window
))
9657 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
9658 if (popup_activated ())
9662 /* I don't think this happens but let's be paranoid. */
9666 /* Record a function that resets redisplaying_p to its old value
9667 when we leave this function. */
9668 count
= SPECPDL_INDEX ();
9669 record_unwind_protect (unwind_redisplay
,
9670 Fcons (make_number (redisplaying_p
), selected_frame
));
9672 specbind (Qinhibit_free_realized_faces
, Qnil
);
9676 reconsider_clip_changes (w
, current_buffer
);
9678 /* If new fonts have been loaded that make a glyph matrix adjustment
9679 necessary, do it. */
9680 if (fonts_changed_p
)
9682 adjust_glyphs (NULL
);
9683 ++windows_or_buffers_changed
;
9684 fonts_changed_p
= 0;
9687 /* If face_change_count is non-zero, init_iterator will free all
9688 realized faces, which includes the faces referenced from current
9689 matrices. So, we can't reuse current matrices in this case. */
9690 if (face_change_count
)
9691 ++windows_or_buffers_changed
;
9693 if (! FRAME_WINDOW_P (sf
)
9694 && previous_terminal_frame
!= sf
)
9696 /* Since frames on an ASCII terminal share the same display
9697 area, displaying a different frame means redisplay the whole
9699 windows_or_buffers_changed
++;
9700 SET_FRAME_GARBAGED (sf
);
9701 XSETFRAME (Vterminal_frame
, sf
);
9703 previous_terminal_frame
= sf
;
9705 /* Set the visible flags for all frames. Do this before checking
9706 for resized or garbaged frames; they want to know if their frames
9707 are visible. See the comment in frame.h for
9708 FRAME_SAMPLE_VISIBILITY. */
9710 Lisp_Object tail
, frame
;
9712 number_of_visible_frames
= 0;
9714 FOR_EACH_FRAME (tail
, frame
)
9716 struct frame
*f
= XFRAME (frame
);
9718 FRAME_SAMPLE_VISIBILITY (f
);
9719 if (FRAME_VISIBLE_P (f
))
9720 ++number_of_visible_frames
;
9721 clear_desired_matrices (f
);
9725 /* Notice any pending interrupt request to change frame size. */
9726 do_pending_window_change (1);
9728 /* Clear frames marked as garbaged. */
9730 clear_garbaged_frames ();
9732 /* Build menubar and tool-bar items. */
9733 prepare_menu_bars ();
9735 if (windows_or_buffers_changed
)
9736 update_mode_lines
++;
9738 /* Detect case that we need to write or remove a star in the mode line. */
9739 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
9741 w
->update_mode_line
= Qt
;
9742 if (buffer_shared
> 1)
9743 update_mode_lines
++;
9746 /* If %c is in the mode line, update it if needed. */
9747 if (!NILP (w
->column_number_displayed
)
9748 /* This alternative quickly identifies a common case
9749 where no change is needed. */
9750 && !(PT
== XFASTINT (w
->last_point
)
9751 && XFASTINT (w
->last_modified
) >= MODIFF
9752 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9753 && (XFASTINT (w
->column_number_displayed
)
9754 != (int) current_column ())) /* iftc */
9755 w
->update_mode_line
= Qt
;
9757 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
9759 /* The variable buffer_shared is set in redisplay_window and
9760 indicates that we redisplay a buffer in different windows. See
9762 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
9763 || cursor_type_changed
);
9765 /* If specs for an arrow have changed, do thorough redisplay
9766 to ensure we remove any arrow that should no longer exist. */
9767 if (overlay_arrows_changed_p ())
9768 consider_all_windows_p
= windows_or_buffers_changed
= 1;
9770 /* Normally the message* functions will have already displayed and
9771 updated the echo area, but the frame may have been trashed, or
9772 the update may have been preempted, so display the echo area
9773 again here. Checking message_cleared_p captures the case that
9774 the echo area should be cleared. */
9775 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
9776 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
9777 || (message_cleared_p
9778 && minibuf_level
== 0
9779 /* If the mini-window is currently selected, this means the
9780 echo-area doesn't show through. */
9781 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
9783 int window_height_changed_p
= echo_area_display (0);
9786 /* If we don't display the current message, don't clear the
9787 message_cleared_p flag, because, if we did, we wouldn't clear
9788 the echo area in the next redisplay which doesn't preserve
9790 if (!display_last_displayed_message_p
)
9791 message_cleared_p
= 0;
9793 if (fonts_changed_p
)
9795 else if (window_height_changed_p
)
9797 consider_all_windows_p
= 1;
9798 ++update_mode_lines
;
9799 ++windows_or_buffers_changed
;
9801 /* If window configuration was changed, frames may have been
9802 marked garbaged. Clear them or we will experience
9803 surprises wrt scrolling. */
9805 clear_garbaged_frames ();
9808 else if (EQ (selected_window
, minibuf_window
)
9809 && (current_buffer
->clip_changed
9810 || XFASTINT (w
->last_modified
) < MODIFF
9811 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9812 && resize_mini_window (w
, 0))
9814 /* Resized active mini-window to fit the size of what it is
9815 showing if its contents might have changed. */
9817 consider_all_windows_p
= 1;
9818 ++windows_or_buffers_changed
;
9819 ++update_mode_lines
;
9821 /* If window configuration was changed, frames may have been
9822 marked garbaged. Clear them or we will experience
9823 surprises wrt scrolling. */
9825 clear_garbaged_frames ();
9829 /* If showing the region, and mark has changed, we must redisplay
9830 the whole window. The assignment to this_line_start_pos prevents
9831 the optimization directly below this if-statement. */
9832 if (((!NILP (Vtransient_mark_mode
)
9833 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9834 != !NILP (w
->region_showing
))
9835 || (!NILP (w
->region_showing
)
9836 && !EQ (w
->region_showing
,
9837 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
9838 CHARPOS (this_line_start_pos
) = 0;
9840 /* Optimize the case that only the line containing the cursor in the
9841 selected window has changed. Variables starting with this_ are
9842 set in display_line and record information about the line
9843 containing the cursor. */
9844 tlbufpos
= this_line_start_pos
;
9845 tlendpos
= this_line_end_pos
;
9846 if (!consider_all_windows_p
9847 && CHARPOS (tlbufpos
) > 0
9848 && NILP (w
->update_mode_line
)
9849 && !current_buffer
->clip_changed
9850 && !current_buffer
->prevent_redisplay_optimizations_p
9851 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
9852 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
9853 /* Make sure recorded data applies to current buffer, etc. */
9854 && this_line_buffer
== current_buffer
9855 && current_buffer
== XBUFFER (w
->buffer
)
9856 && NILP (w
->force_start
)
9857 && NILP (w
->optional_new_start
)
9858 /* Point must be on the line that we have info recorded about. */
9859 && PT
>= CHARPOS (tlbufpos
)
9860 && PT
<= Z
- CHARPOS (tlendpos
)
9861 /* All text outside that line, including its final newline,
9862 must be unchanged */
9863 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
9864 CHARPOS (tlendpos
)))
9866 if (CHARPOS (tlbufpos
) > BEGV
9867 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
9868 && (CHARPOS (tlbufpos
) == ZV
9869 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
9870 /* Former continuation line has disappeared by becoming empty */
9872 else if (XFASTINT (w
->last_modified
) < MODIFF
9873 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
9874 || MINI_WINDOW_P (w
))
9876 /* We have to handle the case of continuation around a
9877 wide-column character (See the comment in indent.c around
9880 For instance, in the following case:
9882 -------- Insert --------
9883 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
9884 J_I_ ==> J_I_ `^^' are cursors.
9888 As we have to redraw the line above, we should goto cancel. */
9891 int line_height_before
= this_line_pixel_height
;
9893 /* Note that start_display will handle the case that the
9894 line starting at tlbufpos is a continuation lines. */
9895 start_display (&it
, w
, tlbufpos
);
9897 /* Implementation note: It this still necessary? */
9898 if (it
.current_x
!= this_line_start_x
)
9901 TRACE ((stderr
, "trying display optimization 1\n"));
9902 w
->cursor
.vpos
= -1;
9903 overlay_arrow_seen
= 0;
9904 it
.vpos
= this_line_vpos
;
9905 it
.current_y
= this_line_y
;
9906 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
9909 /* If line contains point, is not continued,
9910 and ends at same distance from eob as before, we win */
9911 if (w
->cursor
.vpos
>= 0
9912 /* Line is not continued, otherwise this_line_start_pos
9913 would have been set to 0 in display_line. */
9914 && CHARPOS (this_line_start_pos
)
9915 /* Line ends as before. */
9916 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
9917 /* Line has same height as before. Otherwise other lines
9918 would have to be shifted up or down. */
9919 && this_line_pixel_height
== line_height_before
)
9921 /* If this is not the window's last line, we must adjust
9922 the charstarts of the lines below. */
9923 if (it
.current_y
< it
.last_visible_y
)
9925 struct glyph_row
*row
9926 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
9927 int delta
, delta_bytes
;
9929 if (Z
- CHARPOS (tlendpos
) == ZV
)
9931 /* This line ends at end of (accessible part of)
9932 buffer. There is no newline to count. */
9934 - CHARPOS (tlendpos
)
9935 - MATRIX_ROW_START_CHARPOS (row
));
9936 delta_bytes
= (Z_BYTE
9937 - BYTEPOS (tlendpos
)
9938 - MATRIX_ROW_START_BYTEPOS (row
));
9942 /* This line ends in a newline. Must take
9943 account of the newline and the rest of the
9944 text that follows. */
9946 - CHARPOS (tlendpos
)
9947 - MATRIX_ROW_START_CHARPOS (row
));
9948 delta_bytes
= (Z_BYTE
9949 - BYTEPOS (tlendpos
)
9950 - MATRIX_ROW_START_BYTEPOS (row
));
9953 increment_matrix_positions (w
->current_matrix
,
9955 w
->current_matrix
->nrows
,
9956 delta
, delta_bytes
);
9959 /* If this row displays text now but previously didn't,
9960 or vice versa, w->window_end_vpos may have to be
9962 if ((it
.glyph_row
- 1)->displays_text_p
)
9964 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
9965 XSETINT (w
->window_end_vpos
, this_line_vpos
);
9967 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
9968 && this_line_vpos
> 0)
9969 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
9970 w
->window_end_valid
= Qnil
;
9972 /* Update hint: No need to try to scroll in update_window. */
9973 w
->desired_matrix
->no_scrolling_p
= 1;
9976 *w
->desired_matrix
->method
= 0;
9977 debug_method_add (w
, "optimization 1");
9979 #ifdef HAVE_WINDOW_SYSTEM
9980 update_window_fringes (w
, 0);
9987 else if (/* Cursor position hasn't changed. */
9988 PT
== XFASTINT (w
->last_point
)
9989 /* Make sure the cursor was last displayed
9990 in this window. Otherwise we have to reposition it. */
9991 && 0 <= w
->cursor
.vpos
9992 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
9996 do_pending_window_change (1);
9998 /* We used to always goto end_of_redisplay here, but this
9999 isn't enough if we have a blinking cursor. */
10000 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10001 goto end_of_redisplay
;
10005 /* If highlighting the region, or if the cursor is in the echo area,
10006 then we can't just move the cursor. */
10007 else if (! (!NILP (Vtransient_mark_mode
)
10008 && !NILP (current_buffer
->mark_active
))
10009 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10010 || highlight_nonselected_windows
)
10011 && NILP (w
->region_showing
)
10012 && NILP (Vshow_trailing_whitespace
)
10013 && !cursor_in_echo_area
)
10016 struct glyph_row
*row
;
10018 /* Skip from tlbufpos to PT and see where it is. Note that
10019 PT may be in invisible text. If so, we will end at the
10020 next visible position. */
10021 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10022 NULL
, DEFAULT_FACE_ID
);
10023 it
.current_x
= this_line_start_x
;
10024 it
.current_y
= this_line_y
;
10025 it
.vpos
= this_line_vpos
;
10027 /* The call to move_it_to stops in front of PT, but
10028 moves over before-strings. */
10029 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10031 if (it
.vpos
== this_line_vpos
10032 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10035 xassert (this_line_vpos
== it
.vpos
);
10036 xassert (this_line_y
== it
.current_y
);
10037 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10039 *w
->desired_matrix
->method
= 0;
10040 debug_method_add (w
, "optimization 3");
10049 /* Text changed drastically or point moved off of line. */
10050 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10053 CHARPOS (this_line_start_pos
) = 0;
10054 consider_all_windows_p
|= buffer_shared
> 1;
10055 ++clear_face_cache_count
;
10058 /* Build desired matrices, and update the display. If
10059 consider_all_windows_p is non-zero, do it for all windows on all
10060 frames. Otherwise do it for selected_window, only. */
10062 if (consider_all_windows_p
)
10064 Lisp_Object tail
, frame
;
10065 int i
, n
= 0, size
= 50;
10066 struct frame
**updated
10067 = (struct frame
**) alloca (size
* sizeof *updated
);
10069 /* Clear the face cache eventually. */
10070 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
10072 clear_face_cache (0);
10073 clear_face_cache_count
= 0;
10076 /* Recompute # windows showing selected buffer. This will be
10077 incremented each time such a window is displayed. */
10080 FOR_EACH_FRAME (tail
, frame
)
10082 struct frame
*f
= XFRAME (frame
);
10084 if (FRAME_WINDOW_P (f
) || f
== sf
)
10086 if (! EQ (frame
, selected_frame
))
10087 /* Select the frame, for the sake of frame-local
10089 select_frame_for_redisplay (frame
);
10091 #ifdef HAVE_WINDOW_SYSTEM
10092 if (clear_face_cache_count
% 50 == 0
10093 && FRAME_WINDOW_P (f
))
10094 clear_image_cache (f
, 0);
10095 #endif /* HAVE_WINDOW_SYSTEM */
10097 /* Mark all the scroll bars to be removed; we'll redeem
10098 the ones we want when we redisplay their windows. */
10099 if (condemn_scroll_bars_hook
)
10100 condemn_scroll_bars_hook (f
);
10102 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10103 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10105 /* Any scroll bars which redisplay_windows should have
10106 nuked should now go away. */
10107 if (judge_scroll_bars_hook
)
10108 judge_scroll_bars_hook (f
);
10110 /* If fonts changed, display again. */
10111 /* ??? rms: I suspect it is a mistake to jump all the way
10112 back to retry here. It should just retry this frame. */
10113 if (fonts_changed_p
)
10116 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10118 /* See if we have to hscroll. */
10119 if (hscroll_windows (f
->root_window
))
10122 /* Prevent various kinds of signals during display
10123 update. stdio is not robust about handling
10124 signals, which can cause an apparent I/O
10126 if (interrupt_input
)
10127 unrequest_sigio ();
10130 /* Update the display. */
10131 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10132 pause
|= update_frame (f
, 0, 0);
10133 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10140 int nbytes
= size
* sizeof *updated
;
10141 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
10142 bcopy (updated
, p
, nbytes
);
10153 /* Do the mark_window_display_accurate after all windows have
10154 been redisplayed because this call resets flags in buffers
10155 which are needed for proper redisplay. */
10156 for (i
= 0; i
< n
; ++i
)
10158 struct frame
*f
= updated
[i
];
10159 mark_window_display_accurate (f
->root_window
, 1);
10160 if (frame_up_to_date_hook
)
10161 frame_up_to_date_hook (f
);
10165 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10167 Lisp_Object mini_window
;
10168 struct frame
*mini_frame
;
10170 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10171 /* Use list_of_error, not Qerror, so that
10172 we catch only errors and don't run the debugger. */
10173 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10175 redisplay_window_error
);
10177 /* Compare desired and current matrices, perform output. */
10180 /* If fonts changed, display again. */
10181 if (fonts_changed_p
)
10184 /* Prevent various kinds of signals during display update.
10185 stdio is not robust about handling signals,
10186 which can cause an apparent I/O error. */
10187 if (interrupt_input
)
10188 unrequest_sigio ();
10191 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10193 if (hscroll_windows (selected_window
))
10196 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10197 pause
= update_frame (sf
, 0, 0);
10200 /* We may have called echo_area_display at the top of this
10201 function. If the echo area is on another frame, that may
10202 have put text on a frame other than the selected one, so the
10203 above call to update_frame would not have caught it. Catch
10205 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10206 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10208 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10210 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10211 pause
|= update_frame (mini_frame
, 0, 0);
10212 if (!pause
&& hscroll_windows (mini_window
))
10217 /* If display was paused because of pending input, make sure we do a
10218 thorough update the next time. */
10221 /* Prevent the optimization at the beginning of
10222 redisplay_internal that tries a single-line update of the
10223 line containing the cursor in the selected window. */
10224 CHARPOS (this_line_start_pos
) = 0;
10226 /* Let the overlay arrow be updated the next time. */
10227 update_overlay_arrows (0);
10229 /* If we pause after scrolling, some rows in the current
10230 matrices of some windows are not valid. */
10231 if (!WINDOW_FULL_WIDTH_P (w
)
10232 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10233 update_mode_lines
= 1;
10237 if (!consider_all_windows_p
)
10239 /* This has already been done above if
10240 consider_all_windows_p is set. */
10241 mark_window_display_accurate_1 (w
, 1);
10243 /* Say overlay arrows are up to date. */
10244 update_overlay_arrows (1);
10246 if (frame_up_to_date_hook
!= 0)
10247 frame_up_to_date_hook (sf
);
10250 update_mode_lines
= 0;
10251 windows_or_buffers_changed
= 0;
10252 cursor_type_changed
= 0;
10255 /* Start SIGIO interrupts coming again. Having them off during the
10256 code above makes it less likely one will discard output, but not
10257 impossible, since there might be stuff in the system buffer here.
10258 But it is much hairier to try to do anything about that. */
10259 if (interrupt_input
)
10263 /* If a frame has become visible which was not before, redisplay
10264 again, so that we display it. Expose events for such a frame
10265 (which it gets when becoming visible) don't call the parts of
10266 redisplay constructing glyphs, so simply exposing a frame won't
10267 display anything in this case. So, we have to display these
10268 frames here explicitly. */
10271 Lisp_Object tail
, frame
;
10274 FOR_EACH_FRAME (tail
, frame
)
10276 int this_is_visible
= 0;
10278 if (XFRAME (frame
)->visible
)
10279 this_is_visible
= 1;
10280 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10281 if (XFRAME (frame
)->visible
)
10282 this_is_visible
= 1;
10284 if (this_is_visible
)
10288 if (new_count
!= number_of_visible_frames
)
10289 windows_or_buffers_changed
++;
10292 /* Change frame size now if a change is pending. */
10293 do_pending_window_change (1);
10295 /* If we just did a pending size change, or have additional
10296 visible frames, redisplay again. */
10297 if (windows_or_buffers_changed
&& !pause
)
10301 unbind_to (count
, Qnil
);
10306 /* Redisplay, but leave alone any recent echo area message unless
10307 another message has been requested in its place.
10309 This is useful in situations where you need to redisplay but no
10310 user action has occurred, making it inappropriate for the message
10311 area to be cleared. See tracking_off and
10312 wait_reading_process_input for examples of these situations.
10314 FROM_WHERE is an integer saying from where this function was
10315 called. This is useful for debugging. */
10318 redisplay_preserve_echo_area (from_where
)
10321 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10323 if (!NILP (echo_area_buffer
[1]))
10325 /* We have a previously displayed message, but no current
10326 message. Redisplay the previous message. */
10327 display_last_displayed_message_p
= 1;
10328 redisplay_internal (1);
10329 display_last_displayed_message_p
= 0;
10332 redisplay_internal (1);
10336 /* Function registered with record_unwind_protect in
10337 redisplay_internal. Reset redisplaying_p to the value it had
10338 before redisplay_internal was called, and clear
10339 prevent_freeing_realized_faces_p. It also selects the previously
10343 unwind_redisplay (val
)
10346 Lisp_Object old_redisplaying_p
, old_frame
;
10348 old_redisplaying_p
= XCAR (val
);
10349 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10350 old_frame
= XCDR (val
);
10351 if (! EQ (old_frame
, selected_frame
))
10352 select_frame_for_redisplay (old_frame
);
10357 /* Mark the display of window W as accurate or inaccurate. If
10358 ACCURATE_P is non-zero mark display of W as accurate. If
10359 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10360 redisplay_internal is called. */
10363 mark_window_display_accurate_1 (w
, accurate_p
)
10367 if (BUFFERP (w
->buffer
))
10369 struct buffer
*b
= XBUFFER (w
->buffer
);
10372 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
10373 w
->last_overlay_modified
10374 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
10376 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
10380 b
->clip_changed
= 0;
10381 b
->prevent_redisplay_optimizations_p
= 0;
10383 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
10384 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
10385 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
10386 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
10388 w
->current_matrix
->buffer
= b
;
10389 w
->current_matrix
->begv
= BUF_BEGV (b
);
10390 w
->current_matrix
->zv
= BUF_ZV (b
);
10392 w
->last_cursor
= w
->cursor
;
10393 w
->last_cursor_off_p
= w
->cursor_off_p
;
10395 if (w
== XWINDOW (selected_window
))
10396 w
->last_point
= make_number (BUF_PT (b
));
10398 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
10404 w
->window_end_valid
= w
->buffer
;
10405 #if 0 /* This is incorrect with variable-height lines. */
10406 xassert (XINT (w
->window_end_vpos
)
10407 < (WINDOW_TOTAL_LINES (w
)
10408 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
10410 w
->update_mode_line
= Qnil
;
10415 /* Mark the display of windows in the window tree rooted at WINDOW as
10416 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
10417 windows as accurate. If ACCURATE_P is zero, arrange for windows to
10418 be redisplayed the next time redisplay_internal is called. */
10421 mark_window_display_accurate (window
, accurate_p
)
10422 Lisp_Object window
;
10427 for (; !NILP (window
); window
= w
->next
)
10429 w
= XWINDOW (window
);
10430 mark_window_display_accurate_1 (w
, accurate_p
);
10432 if (!NILP (w
->vchild
))
10433 mark_window_display_accurate (w
->vchild
, accurate_p
);
10434 if (!NILP (w
->hchild
))
10435 mark_window_display_accurate (w
->hchild
, accurate_p
);
10440 update_overlay_arrows (1);
10444 /* Force a thorough redisplay the next time by setting
10445 last_arrow_position and last_arrow_string to t, which is
10446 unequal to any useful value of Voverlay_arrow_... */
10447 update_overlay_arrows (-1);
10452 /* Return value in display table DP (Lisp_Char_Table *) for character
10453 C. Since a display table doesn't have any parent, we don't have to
10454 follow parent. Do not call this function directly but use the
10455 macro DISP_CHAR_VECTOR. */
10458 disp_char_vector (dp
, c
)
10459 struct Lisp_Char_Table
*dp
;
10465 if (SINGLE_BYTE_CHAR_P (c
))
10466 return (dp
->contents
[c
]);
10468 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
10471 else if (code
[2] < 32)
10474 /* Here, the possible range of code[0] (== charset ID) is
10475 128..max_charset. Since the top level char table contains data
10476 for multibyte characters after 256th element, we must increment
10477 code[0] by 128 to get a correct index. */
10479 code
[3] = -1; /* anchor */
10481 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
10483 val
= dp
->contents
[code
[i
]];
10484 if (!SUB_CHAR_TABLE_P (val
))
10485 return (NILP (val
) ? dp
->defalt
: val
);
10488 /* Here, val is a sub char table. We return the default value of
10490 return (dp
->defalt
);
10495 /***********************************************************************
10497 ***********************************************************************/
10499 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
10502 redisplay_windows (window
)
10503 Lisp_Object window
;
10505 while (!NILP (window
))
10507 struct window
*w
= XWINDOW (window
);
10509 if (!NILP (w
->hchild
))
10510 redisplay_windows (w
->hchild
);
10511 else if (!NILP (w
->vchild
))
10512 redisplay_windows (w
->vchild
);
10515 displayed_buffer
= XBUFFER (w
->buffer
);
10516 /* Use list_of_error, not Qerror, so that
10517 we catch only errors and don't run the debugger. */
10518 internal_condition_case_1 (redisplay_window_0
, window
,
10520 redisplay_window_error
);
10528 redisplay_window_error ()
10530 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
10535 redisplay_window_0 (window
)
10536 Lisp_Object window
;
10538 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10539 redisplay_window (window
, 0);
10544 redisplay_window_1 (window
)
10545 Lisp_Object window
;
10547 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10548 redisplay_window (window
, 1);
10553 /* Increment GLYPH until it reaches END or CONDITION fails while
10554 adding (GLYPH)->pixel_width to X. */
10556 #define SKIP_GLYPHS(glyph, end, x, condition) \
10559 (x) += (glyph)->pixel_width; \
10562 while ((glyph) < (end) && (condition))
10565 /* Set cursor position of W. PT is assumed to be displayed in ROW.
10566 DELTA is the number of bytes by which positions recorded in ROW
10567 differ from current buffer positions. */
10570 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
10572 struct glyph_row
*row
;
10573 struct glyph_matrix
*matrix
;
10574 int delta
, delta_bytes
, dy
, dvpos
;
10576 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
10577 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
10578 /* The first glyph that starts a sequence of glyphs from string. */
10579 struct glyph
*string_start
;
10580 /* The X coordinate of string_start. */
10581 int string_start_x
;
10582 /* The last known character position. */
10583 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
10584 /* The last known character position before string_start. */
10585 int string_before_pos
;
10587 int pt_old
= PT
- delta
;
10589 /* Skip over glyphs not having an object at the start of the row.
10590 These are special glyphs like truncation marks on terminal
10592 if (row
->displays_text_p
)
10594 && INTEGERP (glyph
->object
)
10595 && glyph
->charpos
< 0)
10597 x
+= glyph
->pixel_width
;
10601 string_start
= NULL
;
10603 && !INTEGERP (glyph
->object
)
10604 && (!BUFFERP (glyph
->object
)
10605 || (last_pos
= glyph
->charpos
) < pt_old
))
10607 if (! STRINGP (glyph
->object
))
10609 string_start
= NULL
;
10610 x
+= glyph
->pixel_width
;
10615 string_before_pos
= last_pos
;
10616 string_start
= glyph
;
10617 string_start_x
= x
;
10618 /* Skip all glyphs from string. */
10619 SKIP_GLYPHS (glyph
, end
, x
, STRINGP (glyph
->object
));
10624 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
10626 /* We may have skipped over point because the previous glyphs
10627 are from string. As there's no easy way to know the
10628 character position of the current glyph, find the correct
10629 glyph on point by scanning from string_start again. */
10631 Lisp_Object string
;
10634 limit
= make_number (pt_old
+ 1);
10636 glyph
= string_start
;
10637 x
= string_start_x
;
10638 string
= glyph
->object
;
10639 pos
= string_buffer_position (w
, string
, string_before_pos
);
10640 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
10641 because we always put cursor after overlay strings. */
10642 while (pos
== 0 && glyph
< end
)
10644 string
= glyph
->object
;
10645 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10647 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
10650 while (glyph
< end
)
10652 pos
= XINT (Fnext_single_char_property_change
10653 (make_number (pos
), Qdisplay
, Qnil
, limit
));
10656 /* Skip glyphs from the same string. */
10657 string
= glyph
->object
;
10658 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10659 /* Skip glyphs from an overlay. */
10661 && ! string_buffer_position (w
, glyph
->object
, pos
))
10663 string
= glyph
->object
;
10664 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10669 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
10671 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
10672 w
->cursor
.y
= row
->y
+ dy
;
10674 if (w
== XWINDOW (selected_window
))
10676 if (!row
->continued_p
10677 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
10680 this_line_buffer
= XBUFFER (w
->buffer
);
10682 CHARPOS (this_line_start_pos
)
10683 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
10684 BYTEPOS (this_line_start_pos
)
10685 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
10687 CHARPOS (this_line_end_pos
)
10688 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
10689 BYTEPOS (this_line_end_pos
)
10690 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
10692 this_line_y
= w
->cursor
.y
;
10693 this_line_pixel_height
= row
->height
;
10694 this_line_vpos
= w
->cursor
.vpos
;
10695 this_line_start_x
= row
->x
;
10698 CHARPOS (this_line_start_pos
) = 0;
10703 /* Run window scroll functions, if any, for WINDOW with new window
10704 start STARTP. Sets the window start of WINDOW to that position.
10706 We assume that the window's buffer is really current. */
10708 static INLINE
struct text_pos
10709 run_window_scroll_functions (window
, startp
)
10710 Lisp_Object window
;
10711 struct text_pos startp
;
10713 struct window
*w
= XWINDOW (window
);
10714 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
10716 if (current_buffer
!= XBUFFER (w
->buffer
))
10719 if (!NILP (Vwindow_scroll_functions
))
10721 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
10722 make_number (CHARPOS (startp
)));
10723 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10724 /* In case the hook functions switch buffers. */
10725 if (current_buffer
!= XBUFFER (w
->buffer
))
10726 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10733 /* Make sure the line containing the cursor is fully visible.
10734 A value of 1 means there is nothing to be done.
10735 (Either the line is fully visible, or it cannot be made so,
10736 or we cannot tell.)
10738 If FORCE_P is non-zero, return 0 even if partial visible cursor row
10739 is higher than window.
10741 A value of 0 means the caller should do scrolling
10742 as if point had gone off the screen. */
10745 make_cursor_line_fully_visible (w
, force_p
)
10749 struct glyph_matrix
*matrix
;
10750 struct glyph_row
*row
;
10753 /* It's not always possible to find the cursor, e.g, when a window
10754 is full of overlay strings. Don't do anything in that case. */
10755 if (w
->cursor
.vpos
< 0)
10758 matrix
= w
->desired_matrix
;
10759 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
10761 /* If the cursor row is not partially visible, there's nothing to do. */
10762 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
10768 /* If the row the cursor is in is taller than the window's height,
10769 it's not clear what to do, so do nothing. */
10770 window_height
= window_box_height (w
);
10771 if (row
->height
>= window_height
)
10777 /* This code used to try to scroll the window just enough to make
10778 the line visible. It returned 0 to say that the caller should
10779 allocate larger glyph matrices. */
10781 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
10783 int dy
= row
->height
- row
->visible_height
;
10786 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
10788 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
10790 int dy
= - (row
->height
- row
->visible_height
);
10793 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
10796 /* When we change the cursor y-position of the selected window,
10797 change this_line_y as well so that the display optimization for
10798 the cursor line of the selected window in redisplay_internal uses
10799 the correct y-position. */
10800 if (w
== XWINDOW (selected_window
))
10801 this_line_y
= w
->cursor
.y
;
10803 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
10804 redisplay with larger matrices. */
10805 if (matrix
->nrows
< required_matrix_height (w
))
10807 fonts_changed_p
= 1;
10816 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
10817 non-zero means only WINDOW is redisplayed in redisplay_internal.
10818 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
10819 in redisplay_window to bring a partially visible line into view in
10820 the case that only the cursor has moved.
10822 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
10823 last screen line's vertical height extends past the end of the screen.
10827 1 if scrolling succeeded
10829 0 if scrolling didn't find point.
10831 -1 if new fonts have been loaded so that we must interrupt
10832 redisplay, adjust glyph matrices, and try again. */
10838 SCROLLING_NEED_LARGER_MATRICES
10842 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
10843 scroll_step
, temp_scroll_step
, last_line_misfit
)
10844 Lisp_Object window
;
10845 int just_this_one_p
;
10846 EMACS_INT scroll_conservatively
, scroll_step
;
10847 int temp_scroll_step
;
10848 int last_line_misfit
;
10850 struct window
*w
= XWINDOW (window
);
10851 struct frame
*f
= XFRAME (w
->frame
);
10852 struct text_pos scroll_margin_pos
;
10853 struct text_pos pos
;
10854 struct text_pos startp
;
10856 Lisp_Object window_end
;
10857 int this_scroll_margin
;
10861 int amount_to_scroll
= 0;
10862 Lisp_Object aggressive
;
10864 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
10867 debug_method_add (w
, "try_scrolling");
10870 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10872 /* Compute scroll margin height in pixels. We scroll when point is
10873 within this distance from the top or bottom of the window. */
10874 if (scroll_margin
> 0)
10876 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
10877 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
10880 this_scroll_margin
= 0;
10882 /* Force scroll_conservatively to have a reasonable value so it doesn't
10883 cause an overflow while computing how much to scroll. */
10884 if (scroll_conservatively
)
10885 scroll_conservatively
= min (scroll_conservatively
,
10886 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
10888 /* Compute how much we should try to scroll maximally to bring point
10890 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
10891 scroll_max
= max (scroll_step
,
10892 max (scroll_conservatively
, temp_scroll_step
));
10893 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
10894 || NUMBERP (current_buffer
->scroll_up_aggressively
))
10895 /* We're trying to scroll because of aggressive scrolling
10896 but no scroll_step is set. Choose an arbitrary one. Maybe
10897 there should be a variable for this. */
10901 scroll_max
*= FRAME_LINE_HEIGHT (f
);
10903 /* Decide whether we have to scroll down. Start at the window end
10904 and move this_scroll_margin up to find the position of the scroll
10906 window_end
= Fwindow_end (window
, Qt
);
10910 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
10911 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
10913 if (this_scroll_margin
|| extra_scroll_margin_lines
)
10915 start_display (&it
, w
, scroll_margin_pos
);
10916 if (this_scroll_margin
)
10917 move_it_vertically (&it
, - this_scroll_margin
);
10918 if (extra_scroll_margin_lines
)
10919 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
10920 scroll_margin_pos
= it
.current
.pos
;
10923 if (PT
>= CHARPOS (scroll_margin_pos
))
10927 /* Point is in the scroll margin at the bottom of the window, or
10928 below. Compute a new window start that makes point visible. */
10930 /* Compute the distance from the scroll margin to PT.
10931 Give up if the distance is greater than scroll_max. */
10932 start_display (&it
, w
, scroll_margin_pos
);
10934 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10935 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10937 /* To make point visible, we have to move the window start
10938 down so that the line the cursor is in is visible, which
10939 means we have to add in the height of the cursor line. */
10940 dy
= line_bottom_y (&it
) - y0
;
10942 if (dy
> scroll_max
)
10943 return SCROLLING_FAILED
;
10945 /* Move the window start down. If scrolling conservatively,
10946 move it just enough down to make point visible. If
10947 scroll_step is set, move it down by scroll_step. */
10948 start_display (&it
, w
, startp
);
10950 if (scroll_conservatively
)
10951 /* Set AMOUNT_TO_SCROLL to at least one line,
10952 and at most scroll_conservatively lines. */
10954 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
10955 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
10956 else if (scroll_step
|| temp_scroll_step
)
10957 amount_to_scroll
= scroll_max
;
10960 aggressive
= current_buffer
->scroll_up_aggressively
;
10961 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
10962 if (NUMBERP (aggressive
))
10963 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
10966 if (amount_to_scroll
<= 0)
10967 return SCROLLING_FAILED
;
10969 /* If moving by amount_to_scroll leaves STARTP unchanged,
10970 move it down one screen line. */
10972 move_it_vertically (&it
, amount_to_scroll
);
10973 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
10974 move_it_by_lines (&it
, 1, 1);
10975 startp
= it
.current
.pos
;
10979 /* See if point is inside the scroll margin at the top of the
10981 scroll_margin_pos
= startp
;
10982 if (this_scroll_margin
)
10984 start_display (&it
, w
, startp
);
10985 move_it_vertically (&it
, this_scroll_margin
);
10986 scroll_margin_pos
= it
.current
.pos
;
10989 if (PT
< CHARPOS (scroll_margin_pos
))
10991 /* Point is in the scroll margin at the top of the window or
10992 above what is displayed in the window. */
10995 /* Compute the vertical distance from PT to the scroll
10996 margin position. Give up if distance is greater than
10998 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
10999 start_display (&it
, w
, pos
);
11001 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11002 it
.last_visible_y
, -1,
11003 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11004 dy
= it
.current_y
- y0
;
11005 if (dy
> scroll_max
)
11006 return SCROLLING_FAILED
;
11008 /* Compute new window start. */
11009 start_display (&it
, w
, startp
);
11011 if (scroll_conservatively
)
11013 max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11014 else if (scroll_step
|| temp_scroll_step
)
11015 amount_to_scroll
= scroll_max
;
11018 aggressive
= current_buffer
->scroll_down_aggressively
;
11019 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11020 if (NUMBERP (aggressive
))
11021 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
11024 if (amount_to_scroll
<= 0)
11025 return SCROLLING_FAILED
;
11027 move_it_vertically (&it
, - amount_to_scroll
);
11028 startp
= it
.current
.pos
;
11032 /* Run window scroll functions. */
11033 startp
= run_window_scroll_functions (window
, startp
);
11035 /* Display the window. Give up if new fonts are loaded, or if point
11037 if (!try_window (window
, startp
))
11038 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11039 else if (w
->cursor
.vpos
< 0)
11041 clear_glyph_matrix (w
->desired_matrix
);
11042 rc
= SCROLLING_FAILED
;
11046 /* Maybe forget recorded base line for line number display. */
11047 if (!just_this_one_p
11048 || current_buffer
->clip_changed
11049 || BEG_UNCHANGED
< CHARPOS (startp
))
11050 w
->base_line_number
= Qnil
;
11052 /* If cursor ends up on a partially visible line,
11053 treat that as being off the bottom of the screen. */
11054 if (! make_cursor_line_fully_visible (w
, extra_scroll_margin_lines
<= 1))
11056 clear_glyph_matrix (w
->desired_matrix
);
11057 ++extra_scroll_margin_lines
;
11060 rc
= SCROLLING_SUCCESS
;
11067 /* Compute a suitable window start for window W if display of W starts
11068 on a continuation line. Value is non-zero if a new window start
11071 The new window start will be computed, based on W's width, starting
11072 from the start of the continued line. It is the start of the
11073 screen line with the minimum distance from the old start W->start. */
11076 compute_window_start_on_continuation_line (w
)
11079 struct text_pos pos
, start_pos
;
11080 int window_start_changed_p
= 0;
11082 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
11084 /* If window start is on a continuation line... Window start may be
11085 < BEGV in case there's invisible text at the start of the
11086 buffer (M-x rmail, for example). */
11087 if (CHARPOS (start_pos
) > BEGV
11088 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
11091 struct glyph_row
*row
;
11093 /* Handle the case that the window start is out of range. */
11094 if (CHARPOS (start_pos
) < BEGV
)
11095 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
11096 else if (CHARPOS (start_pos
) > ZV
)
11097 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
11099 /* Find the start of the continued line. This should be fast
11100 because scan_buffer is fast (newline cache). */
11101 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
11102 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
11103 row
, DEFAULT_FACE_ID
);
11104 reseat_at_previous_visible_line_start (&it
);
11106 /* If the line start is "too far" away from the window start,
11107 say it takes too much time to compute a new window start. */
11108 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
11109 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
11111 int min_distance
, distance
;
11113 /* Move forward by display lines to find the new window
11114 start. If window width was enlarged, the new start can
11115 be expected to be > the old start. If window width was
11116 decreased, the new window start will be < the old start.
11117 So, we're looking for the display line start with the
11118 minimum distance from the old window start. */
11119 pos
= it
.current
.pos
;
11120 min_distance
= INFINITY
;
11121 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
11122 distance
< min_distance
)
11124 min_distance
= distance
;
11125 pos
= it
.current
.pos
;
11126 move_it_by_lines (&it
, 1, 0);
11129 /* Set the window start there. */
11130 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
11131 window_start_changed_p
= 1;
11135 return window_start_changed_p
;
11139 /* Try cursor movement in case text has not changed in window WINDOW,
11140 with window start STARTP. Value is
11142 CURSOR_MOVEMENT_SUCCESS if successful
11144 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
11146 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
11147 display. *SCROLL_STEP is set to 1, under certain circumstances, if
11148 we want to scroll as if scroll-step were set to 1. See the code.
11150 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
11151 which case we have to abort this redisplay, and adjust matrices
11156 CURSOR_MOVEMENT_SUCCESS
,
11157 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11158 CURSOR_MOVEMENT_MUST_SCROLL
,
11159 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11163 try_cursor_movement (window
, startp
, scroll_step
)
11164 Lisp_Object window
;
11165 struct text_pos startp
;
11168 struct window
*w
= XWINDOW (window
);
11169 struct frame
*f
= XFRAME (w
->frame
);
11170 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11173 if (inhibit_try_cursor_movement
)
11177 /* Handle case where text has not changed, only point, and it has
11178 not moved off the frame. */
11179 if (/* Point may be in this window. */
11180 PT
>= CHARPOS (startp
)
11181 /* Selective display hasn't changed. */
11182 && !current_buffer
->clip_changed
11183 /* Function force-mode-line-update is used to force a thorough
11184 redisplay. It sets either windows_or_buffers_changed or
11185 update_mode_lines. So don't take a shortcut here for these
11187 && !update_mode_lines
11188 && !windows_or_buffers_changed
11189 && !cursor_type_changed
11190 /* Can't use this case if highlighting a region. When a
11191 region exists, cursor movement has to do more than just
11193 && !(!NILP (Vtransient_mark_mode
)
11194 && !NILP (current_buffer
->mark_active
))
11195 && NILP (w
->region_showing
)
11196 && NILP (Vshow_trailing_whitespace
)
11197 /* Right after splitting windows, last_point may be nil. */
11198 && INTEGERP (w
->last_point
)
11199 /* This code is not used for mini-buffer for the sake of the case
11200 of redisplaying to replace an echo area message; since in
11201 that case the mini-buffer contents per se are usually
11202 unchanged. This code is of no real use in the mini-buffer
11203 since the handling of this_line_start_pos, etc., in redisplay
11204 handles the same cases. */
11205 && !EQ (window
, minibuf_window
)
11206 /* When splitting windows or for new windows, it happens that
11207 redisplay is called with a nil window_end_vpos or one being
11208 larger than the window. This should really be fixed in
11209 window.c. I don't have this on my list, now, so we do
11210 approximately the same as the old redisplay code. --gerd. */
11211 && INTEGERP (w
->window_end_vpos
)
11212 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11213 && (FRAME_WINDOW_P (f
)
11214 || !overlay_arrow_in_current_buffer_p ()))
11216 int this_scroll_margin
;
11217 struct glyph_row
*row
= NULL
;
11220 debug_method_add (w
, "cursor movement");
11223 /* Scroll if point within this distance from the top or bottom
11224 of the window. This is a pixel value. */
11225 this_scroll_margin
= max (0, scroll_margin
);
11226 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11227 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11229 /* Start with the row the cursor was displayed during the last
11230 not paused redisplay. Give up if that row is not valid. */
11231 if (w
->last_cursor
.vpos
< 0
11232 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11233 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11236 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11237 if (row
->mode_line_p
)
11239 if (!row
->enabled_p
)
11240 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11243 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11246 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11248 if (PT
> XFASTINT (w
->last_point
))
11250 /* Point has moved forward. */
11251 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11252 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11254 xassert (row
->enabled_p
);
11258 /* The end position of a row equals the start position
11259 of the next row. If PT is there, we would rather
11260 display it in the next line. */
11261 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11262 && MATRIX_ROW_END_CHARPOS (row
) == PT
11263 && !cursor_row_p (w
, row
))
11266 /* If within the scroll margin, scroll. Note that
11267 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11268 the next line would be drawn, and that
11269 this_scroll_margin can be zero. */
11270 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11271 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11272 /* Line is completely visible last line in window
11273 and PT is to be set in the next line. */
11274 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11275 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11276 && !row
->ends_at_zv_p
11277 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11280 else if (PT
< XFASTINT (w
->last_point
))
11282 /* Cursor has to be moved backward. Note that PT >=
11283 CHARPOS (startp) because of the outer
11285 while (!row
->mode_line_p
11286 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11287 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11288 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
11289 && (row
->y
> this_scroll_margin
11290 || CHARPOS (startp
) == BEGV
))
11292 xassert (row
->enabled_p
);
11296 /* Consider the following case: Window starts at BEGV,
11297 there is invisible, intangible text at BEGV, so that
11298 display starts at some point START > BEGV. It can
11299 happen that we are called with PT somewhere between
11300 BEGV and START. Try to handle that case. */
11301 if (row
< w
->current_matrix
->rows
11302 || row
->mode_line_p
)
11304 row
= w
->current_matrix
->rows
;
11305 if (row
->mode_line_p
)
11309 /* Due to newlines in overlay strings, we may have to
11310 skip forward over overlay strings. */
11311 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11312 && MATRIX_ROW_END_CHARPOS (row
) == PT
11313 && !cursor_row_p (w
, row
))
11316 /* If within the scroll margin, scroll. */
11317 if (row
->y
< this_scroll_margin
11318 && CHARPOS (startp
) != BEGV
)
11322 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
11323 || PT
> MATRIX_ROW_END_CHARPOS (row
))
11325 /* if PT is not in the glyph row, give up. */
11326 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11328 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
11330 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
11331 && !row
->ends_at_zv_p
11332 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11333 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11334 else if (row
->height
> window_box_height (w
))
11336 /* If we end up in a partially visible line, let's
11337 make it fully visible, except when it's taller
11338 than the window, in which case we can't do much
11341 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11345 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11346 if (!make_cursor_line_fully_visible (w
, 0))
11347 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11349 rc
= CURSOR_MOVEMENT_SUCCESS
;
11353 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11356 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11357 rc
= CURSOR_MOVEMENT_SUCCESS
;
11366 set_vertical_scroll_bar (w
)
11369 int start
, end
, whole
;
11371 /* Calculate the start and end positions for the current window.
11372 At some point, it would be nice to choose between scrollbars
11373 which reflect the whole buffer size, with special markers
11374 indicating narrowing, and scrollbars which reflect only the
11377 Note that mini-buffers sometimes aren't displaying any text. */
11378 if (!MINI_WINDOW_P (w
)
11379 || (w
== XWINDOW (minibuf_window
)
11380 && NILP (echo_area_buffer
[0])))
11382 struct buffer
*buf
= XBUFFER (w
->buffer
);
11383 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
11384 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
11385 /* I don't think this is guaranteed to be right. For the
11386 moment, we'll pretend it is. */
11387 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
11391 if (whole
< (end
- start
))
11392 whole
= end
- start
;
11395 start
= end
= whole
= 0;
11397 /* Indicate what this scroll bar ought to be displaying now. */
11398 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
11402 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
11403 selected_window is redisplayed.
11405 We can return without actually redisplaying the window if
11406 fonts_changed_p is nonzero. In that case, redisplay_internal will
11410 redisplay_window (window
, just_this_one_p
)
11411 Lisp_Object window
;
11412 int just_this_one_p
;
11414 struct window
*w
= XWINDOW (window
);
11415 struct frame
*f
= XFRAME (w
->frame
);
11416 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11417 struct buffer
*old
= current_buffer
;
11418 struct text_pos lpoint
, opoint
, startp
;
11419 int update_mode_line
;
11422 /* Record it now because it's overwritten. */
11423 int current_matrix_up_to_date_p
= 0;
11424 int used_current_matrix_p
= 0;
11425 /* This is less strict than current_matrix_up_to_date_p.
11426 It indictes that the buffer contents and narrowing are unchanged. */
11427 int buffer_unchanged_p
= 0;
11428 int temp_scroll_step
= 0;
11429 int count
= SPECPDL_INDEX ();
11431 int centering_position
;
11432 int last_line_misfit
= 0;
11434 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11437 /* W must be a leaf window here. */
11438 xassert (!NILP (w
->buffer
));
11440 *w
->desired_matrix
->method
= 0;
11443 specbind (Qinhibit_point_motion_hooks
, Qt
);
11445 reconsider_clip_changes (w
, buffer
);
11447 /* Has the mode line to be updated? */
11448 update_mode_line
= (!NILP (w
->update_mode_line
)
11449 || update_mode_lines
11450 || buffer
->clip_changed
11451 || buffer
->prevent_redisplay_optimizations_p
);
11453 if (MINI_WINDOW_P (w
))
11455 if (w
== XWINDOW (echo_area_window
)
11456 && !NILP (echo_area_buffer
[0]))
11458 if (update_mode_line
)
11459 /* We may have to update a tty frame's menu bar or a
11460 tool-bar. Example `M-x C-h C-h C-g'. */
11461 goto finish_menu_bars
;
11463 /* We've already displayed the echo area glyphs in this window. */
11464 goto finish_scroll_bars
;
11466 else if ((w
!= XWINDOW (minibuf_window
)
11467 || minibuf_level
== 0)
11468 /* When buffer is nonempty, redisplay window normally. */
11469 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
11470 /* Quail displays non-mini buffers in minibuffer window.
11471 In that case, redisplay the window normally. */
11472 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
11474 /* W is a mini-buffer window, but it's not active, so clear
11476 int yb
= window_text_bottom_y (w
);
11477 struct glyph_row
*row
;
11480 for (y
= 0, row
= w
->desired_matrix
->rows
;
11482 y
+= row
->height
, ++row
)
11483 blank_row (w
, row
, y
);
11484 goto finish_scroll_bars
;
11487 clear_glyph_matrix (w
->desired_matrix
);
11490 /* Otherwise set up data on this window; select its buffer and point
11492 /* Really select the buffer, for the sake of buffer-local
11494 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11495 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
11497 current_matrix_up_to_date_p
11498 = (!NILP (w
->window_end_valid
)
11499 && !current_buffer
->clip_changed
11500 && !current_buffer
->prevent_redisplay_optimizations_p
11501 && XFASTINT (w
->last_modified
) >= MODIFF
11502 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11505 = (!NILP (w
->window_end_valid
)
11506 && !current_buffer
->clip_changed
11507 && XFASTINT (w
->last_modified
) >= MODIFF
11508 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11510 /* When windows_or_buffers_changed is non-zero, we can't rely on
11511 the window end being valid, so set it to nil there. */
11512 if (windows_or_buffers_changed
)
11514 /* If window starts on a continuation line, maybe adjust the
11515 window start in case the window's width changed. */
11516 if (XMARKER (w
->start
)->buffer
== current_buffer
)
11517 compute_window_start_on_continuation_line (w
);
11519 w
->window_end_valid
= Qnil
;
11522 /* Some sanity checks. */
11523 CHECK_WINDOW_END (w
);
11524 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
11526 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
11529 /* If %c is in mode line, update it if needed. */
11530 if (!NILP (w
->column_number_displayed
)
11531 /* This alternative quickly identifies a common case
11532 where no change is needed. */
11533 && !(PT
== XFASTINT (w
->last_point
)
11534 && XFASTINT (w
->last_modified
) >= MODIFF
11535 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11536 && (XFASTINT (w
->column_number_displayed
)
11537 != (int) current_column ())) /* iftc */
11538 update_mode_line
= 1;
11540 /* Count number of windows showing the selected buffer. An indirect
11541 buffer counts as its base buffer. */
11542 if (!just_this_one_p
)
11544 struct buffer
*current_base
, *window_base
;
11545 current_base
= current_buffer
;
11546 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11547 if (current_base
->base_buffer
)
11548 current_base
= current_base
->base_buffer
;
11549 if (window_base
->base_buffer
)
11550 window_base
= window_base
->base_buffer
;
11551 if (current_base
== window_base
)
11555 /* Point refers normally to the selected window. For any other
11556 window, set up appropriate value. */
11557 if (!EQ (window
, selected_window
))
11559 int new_pt
= XMARKER (w
->pointm
)->charpos
;
11560 int new_pt_byte
= marker_byte_position (w
->pointm
);
11564 new_pt_byte
= BEGV_BYTE
;
11565 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
11567 else if (new_pt
> (ZV
- 1))
11570 new_pt_byte
= ZV_BYTE
;
11571 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
11574 /* We don't use SET_PT so that the point-motion hooks don't run. */
11575 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
11578 /* If any of the character widths specified in the display table
11579 have changed, invalidate the width run cache. It's true that
11580 this may be a bit late to catch such changes, but the rest of
11581 redisplay goes (non-fatally) haywire when the display table is
11582 changed, so why should we worry about doing any better? */
11583 if (current_buffer
->width_run_cache
)
11585 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
11587 if (! disptab_matches_widthtab (disptab
,
11588 XVECTOR (current_buffer
->width_table
)))
11590 invalidate_region_cache (current_buffer
,
11591 current_buffer
->width_run_cache
,
11593 recompute_width_table (current_buffer
, disptab
);
11597 /* If window-start is screwed up, choose a new one. */
11598 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
11601 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11603 /* If someone specified a new starting point but did not insist,
11604 check whether it can be used. */
11605 if (!NILP (w
->optional_new_start
)
11606 && CHARPOS (startp
) >= BEGV
11607 && CHARPOS (startp
) <= ZV
)
11609 w
->optional_new_start
= Qnil
;
11610 start_display (&it
, w
, startp
);
11611 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11612 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11613 if (IT_CHARPOS (it
) == PT
)
11614 w
->force_start
= Qt
;
11615 /* IT may overshoot PT if text at PT is invisible. */
11616 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
11617 w
->force_start
= Qt
;
11622 /* Handle case where place to start displaying has been specified,
11623 unless the specified location is outside the accessible range. */
11624 if (!NILP (w
->force_start
)
11625 || w
->frozen_window_start_p
)
11627 /* We set this later on if we have to adjust point. */
11630 w
->force_start
= Qnil
;
11632 w
->window_end_valid
= Qnil
;
11634 /* Forget any recorded base line for line number display. */
11635 if (!buffer_unchanged_p
)
11636 w
->base_line_number
= Qnil
;
11638 /* Redisplay the mode line. Select the buffer properly for that.
11639 Also, run the hook window-scroll-functions
11640 because we have scrolled. */
11641 /* Note, we do this after clearing force_start because
11642 if there's an error, it is better to forget about force_start
11643 than to get into an infinite loop calling the hook functions
11644 and having them get more errors. */
11645 if (!update_mode_line
11646 || ! NILP (Vwindow_scroll_functions
))
11648 update_mode_line
= 1;
11649 w
->update_mode_line
= Qt
;
11650 startp
= run_window_scroll_functions (window
, startp
);
11653 w
->last_modified
= make_number (0);
11654 w
->last_overlay_modified
= make_number (0);
11655 if (CHARPOS (startp
) < BEGV
)
11656 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
11657 else if (CHARPOS (startp
) > ZV
)
11658 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
11660 /* Redisplay, then check if cursor has been set during the
11661 redisplay. Give up if new fonts were loaded. */
11662 if (!try_window (window
, startp
))
11664 w
->force_start
= Qt
;
11665 clear_glyph_matrix (w
->desired_matrix
);
11666 goto need_larger_matrices
;
11669 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
11671 /* If point does not appear, try to move point so it does
11672 appear. The desired matrix has been built above, so we
11673 can use it here. */
11674 new_vpos
= window_box_height (w
) / 2;
11677 if (!make_cursor_line_fully_visible (w
, 0))
11679 /* Point does appear, but on a line partly visible at end of window.
11680 Move it back to a fully-visible line. */
11681 new_vpos
= window_box_height (w
);
11684 /* If we need to move point for either of the above reasons,
11685 now actually do it. */
11688 struct glyph_row
*row
;
11690 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
11691 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
11694 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
11695 MATRIX_ROW_START_BYTEPOS (row
));
11697 if (w
!= XWINDOW (selected_window
))
11698 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
11699 else if (current_buffer
== old
)
11700 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11702 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
11704 /* If we are highlighting the region, then we just changed
11705 the region, so redisplay to show it. */
11706 if (!NILP (Vtransient_mark_mode
)
11707 && !NILP (current_buffer
->mark_active
))
11709 clear_glyph_matrix (w
->desired_matrix
);
11710 if (!try_window (window
, startp
))
11711 goto need_larger_matrices
;
11716 debug_method_add (w
, "forced window start");
11721 /* Handle case where text has not changed, only point, and it has
11722 not moved off the frame, and we are not retrying after hscroll.
11723 (current_matrix_up_to_date_p is nonzero when retrying.) */
11724 if (current_matrix_up_to_date_p
11725 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
11726 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
11730 case CURSOR_MOVEMENT_SUCCESS
:
11731 used_current_matrix_p
= 1;
11734 #if 0 /* try_cursor_movement never returns this value. */
11735 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
11736 goto need_larger_matrices
;
11739 case CURSOR_MOVEMENT_MUST_SCROLL
:
11740 goto try_to_scroll
;
11746 /* If current starting point was originally the beginning of a line
11747 but no longer is, find a new starting point. */
11748 else if (!NILP (w
->start_at_line_beg
)
11749 && !(CHARPOS (startp
) <= BEGV
11750 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
11753 debug_method_add (w
, "recenter 1");
11758 /* Try scrolling with try_window_id. Value is > 0 if update has
11759 been done, it is -1 if we know that the same window start will
11760 not work. It is 0 if unsuccessful for some other reason. */
11761 else if ((tem
= try_window_id (w
)) != 0)
11764 debug_method_add (w
, "try_window_id %d", tem
);
11767 if (fonts_changed_p
)
11768 goto need_larger_matrices
;
11772 /* Otherwise try_window_id has returned -1 which means that we
11773 don't want the alternative below this comment to execute. */
11775 else if (CHARPOS (startp
) >= BEGV
11776 && CHARPOS (startp
) <= ZV
11777 && PT
>= CHARPOS (startp
)
11778 && (CHARPOS (startp
) < ZV
11779 /* Avoid starting at end of buffer. */
11780 || CHARPOS (startp
) == BEGV
11781 || (XFASTINT (w
->last_modified
) >= MODIFF
11782 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
11785 debug_method_add (w
, "same window start");
11788 /* Try to redisplay starting at same place as before.
11789 If point has not moved off frame, accept the results. */
11790 if (!current_matrix_up_to_date_p
11791 /* Don't use try_window_reusing_current_matrix in this case
11792 because a window scroll function can have changed the
11794 || !NILP (Vwindow_scroll_functions
)
11795 || MINI_WINDOW_P (w
)
11796 || !(used_current_matrix_p
=
11797 try_window_reusing_current_matrix (w
)))
11799 IF_DEBUG (debug_method_add (w
, "1"));
11800 try_window (window
, startp
);
11803 if (fonts_changed_p
)
11804 goto need_larger_matrices
;
11806 if (w
->cursor
.vpos
>= 0)
11808 if (!just_this_one_p
11809 || current_buffer
->clip_changed
11810 || BEG_UNCHANGED
< CHARPOS (startp
))
11811 /* Forget any recorded base line for line number display. */
11812 w
->base_line_number
= Qnil
;
11814 if (!make_cursor_line_fully_visible (w
, 1))
11816 clear_glyph_matrix (w
->desired_matrix
);
11817 last_line_misfit
= 1;
11819 /* Drop through and scroll. */
11824 clear_glyph_matrix (w
->desired_matrix
);
11829 w
->last_modified
= make_number (0);
11830 w
->last_overlay_modified
= make_number (0);
11832 /* Redisplay the mode line. Select the buffer properly for that. */
11833 if (!update_mode_line
)
11835 update_mode_line
= 1;
11836 w
->update_mode_line
= Qt
;
11839 /* Try to scroll by specified few lines. */
11840 if ((scroll_conservatively
11842 || temp_scroll_step
11843 || NUMBERP (current_buffer
->scroll_up_aggressively
)
11844 || NUMBERP (current_buffer
->scroll_down_aggressively
))
11845 && !current_buffer
->clip_changed
11846 && CHARPOS (startp
) >= BEGV
11847 && CHARPOS (startp
) <= ZV
)
11849 /* The function returns -1 if new fonts were loaded, 1 if
11850 successful, 0 if not successful. */
11851 int rc
= try_scrolling (window
, just_this_one_p
,
11852 scroll_conservatively
,
11854 temp_scroll_step
, last_line_misfit
);
11857 case SCROLLING_SUCCESS
:
11860 case SCROLLING_NEED_LARGER_MATRICES
:
11861 goto need_larger_matrices
;
11863 case SCROLLING_FAILED
:
11871 /* Finally, just choose place to start which centers point */
11874 centering_position
= window_box_height (w
) / 2;
11877 /* Jump here with centering_position already set to 0. */
11880 debug_method_add (w
, "recenter");
11883 /* w->vscroll = 0; */
11885 /* Forget any previously recorded base line for line number display. */
11886 if (!buffer_unchanged_p
)
11887 w
->base_line_number
= Qnil
;
11889 /* Move backward half the height of the window. */
11890 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
11891 it
.current_y
= it
.last_visible_y
;
11892 move_it_vertically_backward (&it
, centering_position
);
11893 xassert (IT_CHARPOS (it
) >= BEGV
);
11895 /* The function move_it_vertically_backward may move over more
11896 than the specified y-distance. If it->w is small, e.g. a
11897 mini-buffer window, we may end up in front of the window's
11898 display area. Start displaying at the start of the line
11899 containing PT in this case. */
11900 if (it
.current_y
<= 0)
11902 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
11903 move_it_vertically (&it
, 0);
11904 xassert (IT_CHARPOS (it
) <= PT
);
11908 it
.current_x
= it
.hpos
= 0;
11910 /* Set startp here explicitly in case that helps avoid an infinite loop
11911 in case the window-scroll-functions functions get errors. */
11912 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
11914 /* Run scroll hooks. */
11915 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
11917 /* Redisplay the window. */
11918 if (!current_matrix_up_to_date_p
11919 || windows_or_buffers_changed
11920 || cursor_type_changed
11921 /* Don't use try_window_reusing_current_matrix in this case
11922 because it can have changed the buffer. */
11923 || !NILP (Vwindow_scroll_functions
)
11924 || !just_this_one_p
11925 || MINI_WINDOW_P (w
)
11926 || !(used_current_matrix_p
=
11927 try_window_reusing_current_matrix (w
)))
11928 try_window (window
, startp
);
11930 /* If new fonts have been loaded (due to fontsets), give up. We
11931 have to start a new redisplay since we need to re-adjust glyph
11933 if (fonts_changed_p
)
11934 goto need_larger_matrices
;
11936 /* If cursor did not appear assume that the middle of the window is
11937 in the first line of the window. Do it again with the next line.
11938 (Imagine a window of height 100, displaying two lines of height
11939 60. Moving back 50 from it->last_visible_y will end in the first
11941 if (w
->cursor
.vpos
< 0)
11943 if (!NILP (w
->window_end_valid
)
11944 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
11946 clear_glyph_matrix (w
->desired_matrix
);
11947 move_it_by_lines (&it
, 1, 0);
11948 try_window (window
, it
.current
.pos
);
11950 else if (PT
< IT_CHARPOS (it
))
11952 clear_glyph_matrix (w
->desired_matrix
);
11953 move_it_by_lines (&it
, -1, 0);
11954 try_window (window
, it
.current
.pos
);
11958 /* Not much we can do about it. */
11962 /* Consider the following case: Window starts at BEGV, there is
11963 invisible, intangible text at BEGV, so that display starts at
11964 some point START > BEGV. It can happen that we are called with
11965 PT somewhere between BEGV and START. Try to handle that case. */
11966 if (w
->cursor
.vpos
< 0)
11968 struct glyph_row
*row
= w
->current_matrix
->rows
;
11969 if (row
->mode_line_p
)
11971 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11974 if (!make_cursor_line_fully_visible (w
, centering_position
> 0))
11976 /* If vscroll is enabled, disable it and try again. */
11980 clear_glyph_matrix (w
->desired_matrix
);
11984 /* If centering point failed to make the whole line visible,
11985 put point at the top instead. That has to make the whole line
11986 visible, if it can be done. */
11987 clear_glyph_matrix (w
->desired_matrix
);
11988 centering_position
= 0;
11994 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11995 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
11996 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
11999 /* Display the mode line, if we must. */
12000 if ((update_mode_line
12001 /* If window not full width, must redo its mode line
12002 if (a) the window to its side is being redone and
12003 (b) we do a frame-based redisplay. This is a consequence
12004 of how inverted lines are drawn in frame-based redisplay. */
12005 || (!just_this_one_p
12006 && !FRAME_WINDOW_P (f
)
12007 && !WINDOW_FULL_WIDTH_P (w
))
12008 /* Line number to display. */
12009 || INTEGERP (w
->base_line_pos
)
12010 /* Column number is displayed and different from the one displayed. */
12011 || (!NILP (w
->column_number_displayed
)
12012 && (XFASTINT (w
->column_number_displayed
)
12013 != (int) current_column ()))) /* iftc */
12014 /* This means that the window has a mode line. */
12015 && (WINDOW_WANTS_MODELINE_P (w
)
12016 || WINDOW_WANTS_HEADER_LINE_P (w
)))
12018 display_mode_lines (w
);
12020 /* If mode line height has changed, arrange for a thorough
12021 immediate redisplay using the correct mode line height. */
12022 if (WINDOW_WANTS_MODELINE_P (w
)
12023 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12025 fonts_changed_p
= 1;
12026 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12027 = DESIRED_MODE_LINE_HEIGHT (w
);
12030 /* If top line height has changed, arrange for a thorough
12031 immediate redisplay using the correct mode line height. */
12032 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12033 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
12035 fonts_changed_p
= 1;
12036 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
12037 = DESIRED_HEADER_LINE_HEIGHT (w
);
12040 if (fonts_changed_p
)
12041 goto need_larger_matrices
;
12044 if (!line_number_displayed
12045 && !BUFFERP (w
->base_line_pos
))
12047 w
->base_line_pos
= Qnil
;
12048 w
->base_line_number
= Qnil
;
12053 /* When we reach a frame's selected window, redo the frame's menu bar. */
12054 if (update_mode_line
12055 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
12057 int redisplay_menu_p
= 0;
12058 int redisplay_tool_bar_p
= 0;
12060 if (FRAME_WINDOW_P (f
))
12062 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
12063 || defined (USE_GTK)
12064 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
12066 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12070 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12072 if (redisplay_menu_p
)
12073 display_menu_bar (w
);
12075 #ifdef HAVE_WINDOW_SYSTEM
12077 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
12079 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
12080 && (FRAME_TOOL_BAR_LINES (f
) > 0
12081 || auto_resize_tool_bars_p
);
12085 if (redisplay_tool_bar_p
)
12086 redisplay_tool_bar (f
);
12090 #ifdef HAVE_WINDOW_SYSTEM
12091 if (update_window_fringes (w
, 0)
12092 && !just_this_one_p
12093 && (used_current_matrix_p
|| overlay_arrow_seen
)
12094 && !w
->pseudo_window_p
)
12098 draw_window_fringes (w
);
12102 #endif /* HAVE_WINDOW_SYSTEM */
12104 /* We go to this label, with fonts_changed_p nonzero,
12105 if it is necessary to try again using larger glyph matrices.
12106 We have to redeem the scroll bar even in this case,
12107 because the loop in redisplay_internal expects that. */
12108 need_larger_matrices
:
12110 finish_scroll_bars
:
12112 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
12114 /* Set the thumb's position and size. */
12115 set_vertical_scroll_bar (w
);
12117 /* Note that we actually used the scroll bar attached to this
12118 window, so it shouldn't be deleted at the end of redisplay. */
12119 redeem_scroll_bar_hook (w
);
12122 /* Restore current_buffer and value of point in it. */
12123 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
12124 set_buffer_internal_1 (old
);
12125 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12127 unbind_to (count
, Qnil
);
12131 /* Build the complete desired matrix of WINDOW with a window start
12132 buffer position POS. Value is non-zero if successful. It is zero
12133 if fonts were loaded during redisplay which makes re-adjusting
12134 glyph matrices necessary. */
12137 try_window (window
, pos
)
12138 Lisp_Object window
;
12139 struct text_pos pos
;
12141 struct window
*w
= XWINDOW (window
);
12143 struct glyph_row
*last_text_row
= NULL
;
12145 /* Make POS the new window start. */
12146 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
12148 /* Mark cursor position as unknown. No overlay arrow seen. */
12149 w
->cursor
.vpos
= -1;
12150 overlay_arrow_seen
= 0;
12152 /* Initialize iterator and info to start at POS. */
12153 start_display (&it
, w
, pos
);
12155 /* Display all lines of W. */
12156 while (it
.current_y
< it
.last_visible_y
)
12158 if (display_line (&it
))
12159 last_text_row
= it
.glyph_row
- 1;
12160 if (fonts_changed_p
)
12164 /* If bottom moved off end of frame, change mode line percentage. */
12165 if (XFASTINT (w
->window_end_pos
) <= 0
12166 && Z
!= IT_CHARPOS (it
))
12167 w
->update_mode_line
= Qt
;
12169 /* Set window_end_pos to the offset of the last character displayed
12170 on the window from the end of current_buffer. Set
12171 window_end_vpos to its row number. */
12174 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
12175 w
->window_end_bytepos
12176 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12178 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12180 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12181 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12182 ->displays_text_p
);
12186 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12187 w
->window_end_pos
= make_number (Z
- ZV
);
12188 w
->window_end_vpos
= make_number (0);
12191 /* But that is not valid info until redisplay finishes. */
12192 w
->window_end_valid
= Qnil
;
12198 /************************************************************************
12199 Window redisplay reusing current matrix when buffer has not changed
12200 ************************************************************************/
12202 /* Try redisplay of window W showing an unchanged buffer with a
12203 different window start than the last time it was displayed by
12204 reusing its current matrix. Value is non-zero if successful.
12205 W->start is the new window start. */
12208 try_window_reusing_current_matrix (w
)
12211 struct frame
*f
= XFRAME (w
->frame
);
12212 struct glyph_row
*row
, *bottom_row
;
12215 struct text_pos start
, new_start
;
12216 int nrows_scrolled
, i
;
12217 struct glyph_row
*last_text_row
;
12218 struct glyph_row
*last_reused_text_row
;
12219 struct glyph_row
*start_row
;
12220 int start_vpos
, min_y
, max_y
;
12223 if (inhibit_try_window_reusing
)
12227 if (/* This function doesn't handle terminal frames. */
12228 !FRAME_WINDOW_P (f
)
12229 /* Don't try to reuse the display if windows have been split
12231 || windows_or_buffers_changed
12232 || cursor_type_changed
)
12235 /* Can't do this if region may have changed. */
12236 if ((!NILP (Vtransient_mark_mode
)
12237 && !NILP (current_buffer
->mark_active
))
12238 || !NILP (w
->region_showing
)
12239 || !NILP (Vshow_trailing_whitespace
))
12242 /* If top-line visibility has changed, give up. */
12243 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12244 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12247 /* Give up if old or new display is scrolled vertically. We could
12248 make this function handle this, but right now it doesn't. */
12249 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12250 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
12253 /* The variable new_start now holds the new window start. The old
12254 start `start' can be determined from the current matrix. */
12255 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
12256 start
= start_row
->start
.pos
;
12257 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12259 /* Clear the desired matrix for the display below. */
12260 clear_glyph_matrix (w
->desired_matrix
);
12262 if (CHARPOS (new_start
) <= CHARPOS (start
))
12266 /* Don't use this method if the display starts with an ellipsis
12267 displayed for invisible text. It's not easy to handle that case
12268 below, and it's certainly not worth the effort since this is
12269 not a frequent case. */
12270 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
12273 IF_DEBUG (debug_method_add (w
, "twu1"));
12275 /* Display up to a row that can be reused. The variable
12276 last_text_row is set to the last row displayed that displays
12277 text. Note that it.vpos == 0 if or if not there is a
12278 header-line; it's not the same as the MATRIX_ROW_VPOS! */
12279 start_display (&it
, w
, new_start
);
12280 first_row_y
= it
.current_y
;
12281 w
->cursor
.vpos
= -1;
12282 last_text_row
= last_reused_text_row
= NULL
;
12284 while (it
.current_y
< it
.last_visible_y
12285 && IT_CHARPOS (it
) < CHARPOS (start
)
12286 && !fonts_changed_p
)
12287 if (display_line (&it
))
12288 last_text_row
= it
.glyph_row
- 1;
12290 /* A value of current_y < last_visible_y means that we stopped
12291 at the previous window start, which in turn means that we
12292 have at least one reusable row. */
12293 if (it
.current_y
< it
.last_visible_y
)
12295 /* IT.vpos always starts from 0; it counts text lines. */
12296 nrows_scrolled
= it
.vpos
;
12298 /* Find PT if not already found in the lines displayed. */
12299 if (w
->cursor
.vpos
< 0)
12301 int dy
= it
.current_y
- first_row_y
;
12303 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12304 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
12306 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
12307 dy
, nrows_scrolled
);
12310 clear_glyph_matrix (w
->desired_matrix
);
12315 /* Scroll the display. Do it before the current matrix is
12316 changed. The problem here is that update has not yet
12317 run, i.e. part of the current matrix is not up to date.
12318 scroll_run_hook will clear the cursor, and use the
12319 current matrix to get the height of the row the cursor is
12321 run
.current_y
= first_row_y
;
12322 run
.desired_y
= it
.current_y
;
12323 run
.height
= it
.last_visible_y
- it
.current_y
;
12325 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
12328 rif
->update_window_begin_hook (w
);
12329 rif
->clear_window_mouse_face (w
);
12330 rif
->scroll_run_hook (w
, &run
);
12331 rif
->update_window_end_hook (w
, 0, 0);
12335 /* Shift current matrix down by nrows_scrolled lines. */
12336 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12337 rotate_matrix (w
->current_matrix
,
12339 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12342 /* Disable lines that must be updated. */
12343 for (i
= 0; i
< it
.vpos
; ++i
)
12344 (start_row
+ i
)->enabled_p
= 0;
12346 /* Re-compute Y positions. */
12347 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12348 max_y
= it
.last_visible_y
;
12349 for (row
= start_row
+ nrows_scrolled
;
12353 row
->y
= it
.current_y
;
12354 row
->visible_height
= row
->height
;
12356 if (row
->y
< min_y
)
12357 row
->visible_height
-= min_y
- row
->y
;
12358 if (row
->y
+ row
->height
> max_y
)
12359 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12360 row
->redraw_fringe_bitmaps_p
= 1;
12362 it
.current_y
+= row
->height
;
12364 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12365 last_reused_text_row
= row
;
12366 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
12370 /* Disable lines in the current matrix which are now
12371 below the window. */
12372 for (++row
; row
< bottom_row
; ++row
)
12373 row
->enabled_p
= 0;
12376 /* Update window_end_pos etc.; last_reused_text_row is the last
12377 reused row from the current matrix containing text, if any.
12378 The value of last_text_row is the last displayed line
12379 containing text. */
12380 if (last_reused_text_row
)
12382 w
->window_end_bytepos
12383 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
12385 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
12387 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
12388 w
->current_matrix
));
12390 else if (last_text_row
)
12392 w
->window_end_bytepos
12393 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12395 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12397 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12401 /* This window must be completely empty. */
12402 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12403 w
->window_end_pos
= make_number (Z
- ZV
);
12404 w
->window_end_vpos
= make_number (0);
12406 w
->window_end_valid
= Qnil
;
12408 /* Update hint: don't try scrolling again in update_window. */
12409 w
->desired_matrix
->no_scrolling_p
= 1;
12412 debug_method_add (w
, "try_window_reusing_current_matrix 1");
12416 else if (CHARPOS (new_start
) > CHARPOS (start
))
12418 struct glyph_row
*pt_row
, *row
;
12419 struct glyph_row
*first_reusable_row
;
12420 struct glyph_row
*first_row_to_display
;
12422 int yb
= window_text_bottom_y (w
);
12424 /* Find the row starting at new_start, if there is one. Don't
12425 reuse a partially visible line at the end. */
12426 first_reusable_row
= start_row
;
12427 while (first_reusable_row
->enabled_p
12428 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
12429 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12430 < CHARPOS (new_start
)))
12431 ++first_reusable_row
;
12433 /* Give up if there is no row to reuse. */
12434 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
12435 || !first_reusable_row
->enabled_p
12436 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12437 != CHARPOS (new_start
)))
12440 /* We can reuse fully visible rows beginning with
12441 first_reusable_row to the end of the window. Set
12442 first_row_to_display to the first row that cannot be reused.
12443 Set pt_row to the row containing point, if there is any. */
12445 for (first_row_to_display
= first_reusable_row
;
12446 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
12447 ++first_row_to_display
)
12449 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
12450 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
12451 pt_row
= first_row_to_display
;
12454 /* Start displaying at the start of first_row_to_display. */
12455 xassert (first_row_to_display
->y
< yb
);
12456 init_to_row_start (&it
, w
, first_row_to_display
);
12458 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
12460 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
12462 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
12463 + WINDOW_HEADER_LINE_HEIGHT (w
));
12465 /* Display lines beginning with first_row_to_display in the
12466 desired matrix. Set last_text_row to the last row displayed
12467 that displays text. */
12468 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
12469 if (pt_row
== NULL
)
12470 w
->cursor
.vpos
= -1;
12471 last_text_row
= NULL
;
12472 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
12473 if (display_line (&it
))
12474 last_text_row
= it
.glyph_row
- 1;
12476 /* Give up If point isn't in a row displayed or reused. */
12477 if (w
->cursor
.vpos
< 0)
12479 clear_glyph_matrix (w
->desired_matrix
);
12483 /* If point is in a reused row, adjust y and vpos of the cursor
12487 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
12488 w
->current_matrix
);
12489 w
->cursor
.y
-= first_reusable_row
->y
;
12492 /* Scroll the display. */
12493 run
.current_y
= first_reusable_row
->y
;
12494 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12495 run
.height
= it
.last_visible_y
- run
.current_y
;
12496 dy
= run
.current_y
- run
.desired_y
;
12501 rif
->update_window_begin_hook (w
);
12502 rif
->clear_window_mouse_face (w
);
12503 rif
->scroll_run_hook (w
, &run
);
12504 rif
->update_window_end_hook (w
, 0, 0);
12508 /* Adjust Y positions of reused rows. */
12509 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12510 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12511 max_y
= it
.last_visible_y
;
12512 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
12515 row
->visible_height
= row
->height
;
12516 if (row
->y
< min_y
)
12517 row
->visible_height
-= min_y
- row
->y
;
12518 if (row
->y
+ row
->height
> max_y
)
12519 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12520 row
->redraw_fringe_bitmaps_p
= 1;
12523 /* Scroll the current matrix. */
12524 xassert (nrows_scrolled
> 0);
12525 rotate_matrix (w
->current_matrix
,
12527 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12530 /* Disable rows not reused. */
12531 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
12532 row
->enabled_p
= 0;
12534 /* Adjust window end. A null value of last_text_row means that
12535 the window end is in reused rows which in turn means that
12536 only its vpos can have changed. */
12539 w
->window_end_bytepos
12540 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12542 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12544 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12549 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
12552 w
->window_end_valid
= Qnil
;
12553 w
->desired_matrix
->no_scrolling_p
= 1;
12556 debug_method_add (w
, "try_window_reusing_current_matrix 2");
12566 /************************************************************************
12567 Window redisplay reusing current matrix when buffer has changed
12568 ************************************************************************/
12570 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
12571 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
12573 static struct glyph_row
*
12574 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
12575 struct glyph_row
*));
12578 /* Return the last row in MATRIX displaying text. If row START is
12579 non-null, start searching with that row. IT gives the dimensions
12580 of the display. Value is null if matrix is empty; otherwise it is
12581 a pointer to the row found. */
12583 static struct glyph_row
*
12584 find_last_row_displaying_text (matrix
, it
, start
)
12585 struct glyph_matrix
*matrix
;
12587 struct glyph_row
*start
;
12589 struct glyph_row
*row
, *row_found
;
12591 /* Set row_found to the last row in IT->w's current matrix
12592 displaying text. The loop looks funny but think of partially
12595 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
12596 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12598 xassert (row
->enabled_p
);
12600 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
12609 /* Return the last row in the current matrix of W that is not affected
12610 by changes at the start of current_buffer that occurred since W's
12611 current matrix was built. Value is null if no such row exists.
12613 BEG_UNCHANGED us the number of characters unchanged at the start of
12614 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
12615 first changed character in current_buffer. Characters at positions <
12616 BEG + BEG_UNCHANGED are at the same buffer positions as they were
12617 when the current matrix was built. */
12619 static struct glyph_row
*
12620 find_last_unchanged_at_beg_row (w
)
12623 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
12624 struct glyph_row
*row
;
12625 struct glyph_row
*row_found
= NULL
;
12626 int yb
= window_text_bottom_y (w
);
12628 /* Find the last row displaying unchanged text. */
12629 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12630 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12631 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
12633 if (/* If row ends before first_changed_pos, it is unchanged,
12634 except in some case. */
12635 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
12636 /* When row ends in ZV and we write at ZV it is not
12638 && !row
->ends_at_zv_p
12639 /* When first_changed_pos is the end of a continued line,
12640 row is not unchanged because it may be no longer
12642 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
12643 && (row
->continued_p
12644 || row
->exact_window_width_line_p
)))
12647 /* Stop if last visible row. */
12648 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
12658 /* Find the first glyph row in the current matrix of W that is not
12659 affected by changes at the end of current_buffer since the
12660 time W's current matrix was built.
12662 Return in *DELTA the number of chars by which buffer positions in
12663 unchanged text at the end of current_buffer must be adjusted.
12665 Return in *DELTA_BYTES the corresponding number of bytes.
12667 Value is null if no such row exists, i.e. all rows are affected by
12670 static struct glyph_row
*
12671 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
12673 int *delta
, *delta_bytes
;
12675 struct glyph_row
*row
;
12676 struct glyph_row
*row_found
= NULL
;
12678 *delta
= *delta_bytes
= 0;
12680 /* Display must not have been paused, otherwise the current matrix
12681 is not up to date. */
12682 if (NILP (w
->window_end_valid
))
12685 /* A value of window_end_pos >= END_UNCHANGED means that the window
12686 end is in the range of changed text. If so, there is no
12687 unchanged row at the end of W's current matrix. */
12688 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
12691 /* Set row to the last row in W's current matrix displaying text. */
12692 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
12694 /* If matrix is entirely empty, no unchanged row exists. */
12695 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12697 /* The value of row is the last glyph row in the matrix having a
12698 meaningful buffer position in it. The end position of row
12699 corresponds to window_end_pos. This allows us to translate
12700 buffer positions in the current matrix to current buffer
12701 positions for characters not in changed text. */
12702 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
12703 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
12704 int last_unchanged_pos
, last_unchanged_pos_old
;
12705 struct glyph_row
*first_text_row
12706 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12708 *delta
= Z
- Z_old
;
12709 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
12711 /* Set last_unchanged_pos to the buffer position of the last
12712 character in the buffer that has not been changed. Z is the
12713 index + 1 of the last character in current_buffer, i.e. by
12714 subtracting END_UNCHANGED we get the index of the last
12715 unchanged character, and we have to add BEG to get its buffer
12717 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
12718 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
12720 /* Search backward from ROW for a row displaying a line that
12721 starts at a minimum position >= last_unchanged_pos_old. */
12722 for (; row
> first_text_row
; --row
)
12724 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12727 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
12732 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
12739 /* Make sure that glyph rows in the current matrix of window W
12740 reference the same glyph memory as corresponding rows in the
12741 frame's frame matrix. This function is called after scrolling W's
12742 current matrix on a terminal frame in try_window_id and
12743 try_window_reusing_current_matrix. */
12746 sync_frame_with_window_matrix_rows (w
)
12749 struct frame
*f
= XFRAME (w
->frame
);
12750 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
12752 /* Preconditions: W must be a leaf window and full-width. Its frame
12753 must have a frame matrix. */
12754 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
12755 xassert (WINDOW_FULL_WIDTH_P (w
));
12756 xassert (!FRAME_WINDOW_P (f
));
12758 /* If W is a full-width window, glyph pointers in W's current matrix
12759 have, by definition, to be the same as glyph pointers in the
12760 corresponding frame matrix. Note that frame matrices have no
12761 marginal areas (see build_frame_matrix). */
12762 window_row
= w
->current_matrix
->rows
;
12763 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
12764 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
12765 while (window_row
< window_row_end
)
12767 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
12768 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
12770 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
12771 frame_row
->glyphs
[TEXT_AREA
] = start
;
12772 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
12773 frame_row
->glyphs
[LAST_AREA
] = end
;
12775 /* Disable frame rows whose corresponding window rows have
12776 been disabled in try_window_id. */
12777 if (!window_row
->enabled_p
)
12778 frame_row
->enabled_p
= 0;
12780 ++window_row
, ++frame_row
;
12785 /* Find the glyph row in window W containing CHARPOS. Consider all
12786 rows between START and END (not inclusive). END null means search
12787 all rows to the end of the display area of W. Value is the row
12788 containing CHARPOS or null. */
12791 row_containing_pos (w
, charpos
, start
, end
, dy
)
12794 struct glyph_row
*start
, *end
;
12797 struct glyph_row
*row
= start
;
12800 /* If we happen to start on a header-line, skip that. */
12801 if (row
->mode_line_p
)
12804 if ((end
&& row
>= end
) || !row
->enabled_p
)
12807 last_y
= window_text_bottom_y (w
) - dy
;
12811 /* Give up if we have gone too far. */
12812 if (end
&& row
>= end
)
12814 /* This formerly returned if they were equal.
12815 I think that both quantities are of a "last plus one" type;
12816 if so, when they are equal, the row is within the screen. -- rms. */
12817 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
12820 /* If it is in this row, return this row. */
12821 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
12822 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
12823 /* The end position of a row equals the start
12824 position of the next row. If CHARPOS is there, we
12825 would rather display it in the next line, except
12826 when this line ends in ZV. */
12827 && !row
->ends_at_zv_p
12828 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12829 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
12836 /* Try to redisplay window W by reusing its existing display. W's
12837 current matrix must be up to date when this function is called,
12838 i.e. window_end_valid must not be nil.
12842 1 if display has been updated
12843 0 if otherwise unsuccessful
12844 -1 if redisplay with same window start is known not to succeed
12846 The following steps are performed:
12848 1. Find the last row in the current matrix of W that is not
12849 affected by changes at the start of current_buffer. If no such row
12852 2. Find the first row in W's current matrix that is not affected by
12853 changes at the end of current_buffer. Maybe there is no such row.
12855 3. Display lines beginning with the row + 1 found in step 1 to the
12856 row found in step 2 or, if step 2 didn't find a row, to the end of
12859 4. If cursor is not known to appear on the window, give up.
12861 5. If display stopped at the row found in step 2, scroll the
12862 display and current matrix as needed.
12864 6. Maybe display some lines at the end of W, if we must. This can
12865 happen under various circumstances, like a partially visible line
12866 becoming fully visible, or because newly displayed lines are displayed
12867 in smaller font sizes.
12869 7. Update W's window end information. */
12875 struct frame
*f
= XFRAME (w
->frame
);
12876 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
12877 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
12878 struct glyph_row
*last_unchanged_at_beg_row
;
12879 struct glyph_row
*first_unchanged_at_end_row
;
12880 struct glyph_row
*row
;
12881 struct glyph_row
*bottom_row
;
12884 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
12885 struct text_pos start_pos
;
12887 int first_unchanged_at_end_vpos
= 0;
12888 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
12889 struct text_pos start
;
12890 int first_changed_charpos
, last_changed_charpos
;
12893 if (inhibit_try_window_id
)
12897 /* This is handy for debugging. */
12899 #define GIVE_UP(X) \
12901 fprintf (stderr, "try_window_id give up %d\n", (X)); \
12905 #define GIVE_UP(X) return 0
12908 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
12910 /* Don't use this for mini-windows because these can show
12911 messages and mini-buffers, and we don't handle that here. */
12912 if (MINI_WINDOW_P (w
))
12915 /* This flag is used to prevent redisplay optimizations. */
12916 if (windows_or_buffers_changed
|| cursor_type_changed
)
12919 /* Verify that narrowing has not changed.
12920 Also verify that we were not told to prevent redisplay optimizations.
12921 It would be nice to further
12922 reduce the number of cases where this prevents try_window_id. */
12923 if (current_buffer
->clip_changed
12924 || current_buffer
->prevent_redisplay_optimizations_p
)
12927 /* Window must either use window-based redisplay or be full width. */
12928 if (!FRAME_WINDOW_P (f
)
12929 && (!line_ins_del_ok
12930 || !WINDOW_FULL_WIDTH_P (w
)))
12933 /* Give up if point is not known NOT to appear in W. */
12934 if (PT
< CHARPOS (start
))
12937 /* Another way to prevent redisplay optimizations. */
12938 if (XFASTINT (w
->last_modified
) == 0)
12941 /* Verify that window is not hscrolled. */
12942 if (XFASTINT (w
->hscroll
) != 0)
12945 /* Verify that display wasn't paused. */
12946 if (NILP (w
->window_end_valid
))
12949 /* Can't use this if highlighting a region because a cursor movement
12950 will do more than just set the cursor. */
12951 if (!NILP (Vtransient_mark_mode
)
12952 && !NILP (current_buffer
->mark_active
))
12955 /* Likewise if highlighting trailing whitespace. */
12956 if (!NILP (Vshow_trailing_whitespace
))
12959 /* Likewise if showing a region. */
12960 if (!NILP (w
->region_showing
))
12963 /* Can use this if overlay arrow position and or string have changed. */
12964 if (overlay_arrows_changed_p ())
12968 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
12969 only if buffer has really changed. The reason is that the gap is
12970 initially at Z for freshly visited files. The code below would
12971 set end_unchanged to 0 in that case. */
12972 if (MODIFF
> SAVE_MODIFF
12973 /* This seems to happen sometimes after saving a buffer. */
12974 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
12976 if (GPT
- BEG
< BEG_UNCHANGED
)
12977 BEG_UNCHANGED
= GPT
- BEG
;
12978 if (Z
- GPT
< END_UNCHANGED
)
12979 END_UNCHANGED
= Z
- GPT
;
12982 /* The position of the first and last character that has been changed. */
12983 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
12984 last_changed_charpos
= Z
- END_UNCHANGED
;
12986 /* If window starts after a line end, and the last change is in
12987 front of that newline, then changes don't affect the display.
12988 This case happens with stealth-fontification. Note that although
12989 the display is unchanged, glyph positions in the matrix have to
12990 be adjusted, of course. */
12991 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
12992 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12993 && ((last_changed_charpos
< CHARPOS (start
)
12994 && CHARPOS (start
) == BEGV
)
12995 || (last_changed_charpos
< CHARPOS (start
) - 1
12996 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
12998 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
12999 struct glyph_row
*r0
;
13001 /* Compute how many chars/bytes have been added to or removed
13002 from the buffer. */
13003 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13004 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13006 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13008 /* Give up if PT is not in the window. Note that it already has
13009 been checked at the start of try_window_id that PT is not in
13010 front of the window start. */
13011 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
13014 /* If window start is unchanged, we can reuse the whole matrix
13015 as is, after adjusting glyph positions. No need to compute
13016 the window end again, since its offset from Z hasn't changed. */
13017 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13018 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
13019 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
13020 /* PT must not be in a partially visible line. */
13021 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
13022 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13024 /* Adjust positions in the glyph matrix. */
13025 if (delta
|| delta_bytes
)
13027 struct glyph_row
*r1
13028 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13029 increment_matrix_positions (w
->current_matrix
,
13030 MATRIX_ROW_VPOS (r0
, current_matrix
),
13031 MATRIX_ROW_VPOS (r1
, current_matrix
),
13032 delta
, delta_bytes
);
13035 /* Set the cursor. */
13036 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13038 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13045 /* Handle the case that changes are all below what is displayed in
13046 the window, and that PT is in the window. This shortcut cannot
13047 be taken if ZV is visible in the window, and text has been added
13048 there that is visible in the window. */
13049 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
13050 /* ZV is not visible in the window, or there are no
13051 changes at ZV, actually. */
13052 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
13053 || first_changed_charpos
== last_changed_charpos
))
13055 struct glyph_row
*r0
;
13057 /* Give up if PT is not in the window. Note that it already has
13058 been checked at the start of try_window_id that PT is not in
13059 front of the window start. */
13060 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
13063 /* If window start is unchanged, we can reuse the whole matrix
13064 as is, without changing glyph positions since no text has
13065 been added/removed in front of the window end. */
13066 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13067 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
13068 /* PT must not be in a partially visible line. */
13069 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
13070 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13072 /* We have to compute the window end anew since text
13073 can have been added/removed after it. */
13075 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13076 w
->window_end_bytepos
13077 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13079 /* Set the cursor. */
13080 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13082 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13089 /* Give up if window start is in the changed area.
13091 The condition used to read
13093 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
13095 but why that was tested escapes me at the moment. */
13096 if (CHARPOS (start
) >= first_changed_charpos
13097 && CHARPOS (start
) <= last_changed_charpos
)
13100 /* Check that window start agrees with the start of the first glyph
13101 row in its current matrix. Check this after we know the window
13102 start is not in changed text, otherwise positions would not be
13104 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13105 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
13108 /* Give up if the window ends in strings. Overlay strings
13109 at the end are difficult to handle, so don't try. */
13110 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
13111 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
13114 /* Compute the position at which we have to start displaying new
13115 lines. Some of the lines at the top of the window might be
13116 reusable because they are not displaying changed text. Find the
13117 last row in W's current matrix not affected by changes at the
13118 start of current_buffer. Value is null if changes start in the
13119 first line of window. */
13120 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
13121 if (last_unchanged_at_beg_row
)
13123 /* Avoid starting to display in the moddle of a character, a TAB
13124 for instance. This is easier than to set up the iterator
13125 exactly, and it's not a frequent case, so the additional
13126 effort wouldn't really pay off. */
13127 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
13128 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
13129 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
13130 --last_unchanged_at_beg_row
;
13132 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
13135 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
13137 start_pos
= it
.current
.pos
;
13139 /* Start displaying new lines in the desired matrix at the same
13140 vpos we would use in the current matrix, i.e. below
13141 last_unchanged_at_beg_row. */
13142 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
13144 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13145 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
13147 xassert (it
.hpos
== 0 && it
.current_x
== 0);
13151 /* There are no reusable lines at the start of the window.
13152 Start displaying in the first text line. */
13153 start_display (&it
, w
, start
);
13154 it
.vpos
= it
.first_vpos
;
13155 start_pos
= it
.current
.pos
;
13158 /* Find the first row that is not affected by changes at the end of
13159 the buffer. Value will be null if there is no unchanged row, in
13160 which case we must redisplay to the end of the window. delta
13161 will be set to the value by which buffer positions beginning with
13162 first_unchanged_at_end_row have to be adjusted due to text
13164 first_unchanged_at_end_row
13165 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
13166 IF_DEBUG (debug_delta
= delta
);
13167 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
13169 /* Set stop_pos to the buffer position up to which we will have to
13170 display new lines. If first_unchanged_at_end_row != NULL, this
13171 is the buffer position of the start of the line displayed in that
13172 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
13173 that we don't stop at a buffer position. */
13175 if (first_unchanged_at_end_row
)
13177 xassert (last_unchanged_at_beg_row
== NULL
13178 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
13180 /* If this is a continuation line, move forward to the next one
13181 that isn't. Changes in lines above affect this line.
13182 Caution: this may move first_unchanged_at_end_row to a row
13183 not displaying text. */
13184 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
13185 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13186 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13187 < it
.last_visible_y
))
13188 ++first_unchanged_at_end_row
;
13190 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13191 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13192 >= it
.last_visible_y
))
13193 first_unchanged_at_end_row
= NULL
;
13196 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13198 first_unchanged_at_end_vpos
13199 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13200 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13203 else if (last_unchanged_at_beg_row
== NULL
)
13209 /* Either there is no unchanged row at the end, or the one we have
13210 now displays text. This is a necessary condition for the window
13211 end pos calculation at the end of this function. */
13212 xassert (first_unchanged_at_end_row
== NULL
13213 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
13215 debug_last_unchanged_at_beg_vpos
13216 = (last_unchanged_at_beg_row
13217 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
13219 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
13221 #endif /* GLYPH_DEBUG != 0 */
13224 /* Display new lines. Set last_text_row to the last new line
13225 displayed which has text on it, i.e. might end up as being the
13226 line where the window_end_vpos is. */
13227 w
->cursor
.vpos
= -1;
13228 last_text_row
= NULL
;
13229 overlay_arrow_seen
= 0;
13230 while (it
.current_y
< it
.last_visible_y
13231 && !fonts_changed_p
13232 && (first_unchanged_at_end_row
== NULL
13233 || IT_CHARPOS (it
) < stop_pos
))
13235 if (display_line (&it
))
13236 last_text_row
= it
.glyph_row
- 1;
13239 if (fonts_changed_p
)
13243 /* Compute differences in buffer positions, y-positions etc. for
13244 lines reused at the bottom of the window. Compute what we can
13246 if (first_unchanged_at_end_row
13247 /* No lines reused because we displayed everything up to the
13248 bottom of the window. */
13249 && it
.current_y
< it
.last_visible_y
)
13252 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
13254 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
13255 run
.current_y
= first_unchanged_at_end_row
->y
;
13256 run
.desired_y
= run
.current_y
+ dy
;
13257 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
13261 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
13262 first_unchanged_at_end_row
= NULL
;
13264 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
13267 /* Find the cursor if not already found. We have to decide whether
13268 PT will appear on this window (it sometimes doesn't, but this is
13269 not a very frequent case.) This decision has to be made before
13270 the current matrix is altered. A value of cursor.vpos < 0 means
13271 that PT is either in one of the lines beginning at
13272 first_unchanged_at_end_row or below the window. Don't care for
13273 lines that might be displayed later at the window end; as
13274 mentioned, this is not a frequent case. */
13275 if (w
->cursor
.vpos
< 0)
13277 /* Cursor in unchanged rows at the top? */
13278 if (PT
< CHARPOS (start_pos
)
13279 && last_unchanged_at_beg_row
)
13281 row
= row_containing_pos (w
, PT
,
13282 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
13283 last_unchanged_at_beg_row
+ 1, 0);
13285 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13288 /* Start from first_unchanged_at_end_row looking for PT. */
13289 else if (first_unchanged_at_end_row
)
13291 row
= row_containing_pos (w
, PT
- delta
,
13292 first_unchanged_at_end_row
, NULL
, 0);
13294 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
13295 delta_bytes
, dy
, dvpos
);
13298 /* Give up if cursor was not found. */
13299 if (w
->cursor
.vpos
< 0)
13301 clear_glyph_matrix (w
->desired_matrix
);
13306 /* Don't let the cursor end in the scroll margins. */
13308 int this_scroll_margin
, cursor_height
;
13310 this_scroll_margin
= max (0, scroll_margin
);
13311 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13312 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13313 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
13315 if ((w
->cursor
.y
< this_scroll_margin
13316 && CHARPOS (start
) > BEGV
)
13317 /* Don't take scroll margin into account at the bottom because
13318 old redisplay didn't do it either. */
13319 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
13321 w
->cursor
.vpos
= -1;
13322 clear_glyph_matrix (w
->desired_matrix
);
13327 /* Scroll the display. Do it before changing the current matrix so
13328 that xterm.c doesn't get confused about where the cursor glyph is
13330 if (dy
&& run
.height
)
13334 if (FRAME_WINDOW_P (f
))
13336 rif
->update_window_begin_hook (w
);
13337 rif
->clear_window_mouse_face (w
);
13338 rif
->scroll_run_hook (w
, &run
);
13339 rif
->update_window_end_hook (w
, 0, 0);
13343 /* Terminal frame. In this case, dvpos gives the number of
13344 lines to scroll by; dvpos < 0 means scroll up. */
13345 int first_unchanged_at_end_vpos
13346 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
13347 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
13348 int end
= (WINDOW_TOP_EDGE_LINE (w
)
13349 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
13350 + window_internal_height (w
));
13352 /* Perform the operation on the screen. */
13355 /* Scroll last_unchanged_at_beg_row to the end of the
13356 window down dvpos lines. */
13357 set_terminal_window (end
);
13359 /* On dumb terminals delete dvpos lines at the end
13360 before inserting dvpos empty lines. */
13361 if (!scroll_region_ok
)
13362 ins_del_lines (end
- dvpos
, -dvpos
);
13364 /* Insert dvpos empty lines in front of
13365 last_unchanged_at_beg_row. */
13366 ins_del_lines (from
, dvpos
);
13368 else if (dvpos
< 0)
13370 /* Scroll up last_unchanged_at_beg_vpos to the end of
13371 the window to last_unchanged_at_beg_vpos - |dvpos|. */
13372 set_terminal_window (end
);
13374 /* Delete dvpos lines in front of
13375 last_unchanged_at_beg_vpos. ins_del_lines will set
13376 the cursor to the given vpos and emit |dvpos| delete
13378 ins_del_lines (from
+ dvpos
, dvpos
);
13380 /* On a dumb terminal insert dvpos empty lines at the
13382 if (!scroll_region_ok
)
13383 ins_del_lines (end
+ dvpos
, -dvpos
);
13386 set_terminal_window (0);
13392 /* Shift reused rows of the current matrix to the right position.
13393 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
13395 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13396 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
13399 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
13400 bottom_vpos
, dvpos
);
13401 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
13404 else if (dvpos
> 0)
13406 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
13407 bottom_vpos
, dvpos
);
13408 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
13409 first_unchanged_at_end_vpos
+ dvpos
, 0);
13412 /* For frame-based redisplay, make sure that current frame and window
13413 matrix are in sync with respect to glyph memory. */
13414 if (!FRAME_WINDOW_P (f
))
13415 sync_frame_with_window_matrix_rows (w
);
13417 /* Adjust buffer positions in reused rows. */
13419 increment_matrix_positions (current_matrix
,
13420 first_unchanged_at_end_vpos
+ dvpos
,
13421 bottom_vpos
, delta
, delta_bytes
);
13423 /* Adjust Y positions. */
13425 shift_glyph_matrix (w
, current_matrix
,
13426 first_unchanged_at_end_vpos
+ dvpos
,
13429 if (first_unchanged_at_end_row
)
13430 first_unchanged_at_end_row
+= dvpos
;
13432 /* If scrolling up, there may be some lines to display at the end of
13434 last_text_row_at_end
= NULL
;
13437 /* Scrolling up can leave for example a partially visible line
13438 at the end of the window to be redisplayed. */
13439 /* Set last_row to the glyph row in the current matrix where the
13440 window end line is found. It has been moved up or down in
13441 the matrix by dvpos. */
13442 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
13443 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
13445 /* If last_row is the window end line, it should display text. */
13446 xassert (last_row
->displays_text_p
);
13448 /* If window end line was partially visible before, begin
13449 displaying at that line. Otherwise begin displaying with the
13450 line following it. */
13451 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
13453 init_to_row_start (&it
, w
, last_row
);
13454 it
.vpos
= last_vpos
;
13455 it
.current_y
= last_row
->y
;
13459 init_to_row_end (&it
, w
, last_row
);
13460 it
.vpos
= 1 + last_vpos
;
13461 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
13465 /* We may start in a continuation line. If so, we have to
13466 get the right continuation_lines_width and current_x. */
13467 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
13468 it
.hpos
= it
.current_x
= 0;
13470 /* Display the rest of the lines at the window end. */
13471 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13472 while (it
.current_y
< it
.last_visible_y
13473 && !fonts_changed_p
)
13475 /* Is it always sure that the display agrees with lines in
13476 the current matrix? I don't think so, so we mark rows
13477 displayed invalid in the current matrix by setting their
13478 enabled_p flag to zero. */
13479 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
13480 if (display_line (&it
))
13481 last_text_row_at_end
= it
.glyph_row
- 1;
13485 /* Update window_end_pos and window_end_vpos. */
13486 if (first_unchanged_at_end_row
13487 && first_unchanged_at_end_row
->y
< it
.last_visible_y
13488 && !last_text_row_at_end
)
13490 /* Window end line if one of the preserved rows from the current
13491 matrix. Set row to the last row displaying text in current
13492 matrix starting at first_unchanged_at_end_row, after
13494 xassert (first_unchanged_at_end_row
->displays_text_p
);
13495 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
13496 first_unchanged_at_end_row
);
13497 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
13499 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13500 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13502 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
13503 xassert (w
->window_end_bytepos
>= 0);
13504 IF_DEBUG (debug_method_add (w
, "A"));
13506 else if (last_text_row_at_end
)
13509 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
13510 w
->window_end_bytepos
13511 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
13513 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
13514 xassert (w
->window_end_bytepos
>= 0);
13515 IF_DEBUG (debug_method_add (w
, "B"));
13517 else if (last_text_row
)
13519 /* We have displayed either to the end of the window or at the
13520 end of the window, i.e. the last row with text is to be found
13521 in the desired matrix. */
13523 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13524 w
->window_end_bytepos
13525 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13527 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
13528 xassert (w
->window_end_bytepos
>= 0);
13530 else if (first_unchanged_at_end_row
== NULL
13531 && last_text_row
== NULL
13532 && last_text_row_at_end
== NULL
)
13534 /* Displayed to end of window, but no line containing text was
13535 displayed. Lines were deleted at the end of the window. */
13536 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
13537 int vpos
= XFASTINT (w
->window_end_vpos
);
13538 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
13539 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
13542 row
== NULL
&& vpos
>= first_vpos
;
13543 --vpos
, --current_row
, --desired_row
)
13545 if (desired_row
->enabled_p
)
13547 if (desired_row
->displays_text_p
)
13550 else if (current_row
->displays_text_p
)
13554 xassert (row
!= NULL
);
13555 w
->window_end_vpos
= make_number (vpos
+ 1);
13556 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13557 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13558 xassert (w
->window_end_bytepos
>= 0);
13559 IF_DEBUG (debug_method_add (w
, "C"));
13564 #if 0 /* This leads to problems, for instance when the cursor is
13565 at ZV, and the cursor line displays no text. */
13566 /* Disable rows below what's displayed in the window. This makes
13567 debugging easier. */
13568 enable_glyph_matrix_rows (current_matrix
,
13569 XFASTINT (w
->window_end_vpos
) + 1,
13573 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
13574 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
13576 /* Record that display has not been completed. */
13577 w
->window_end_valid
= Qnil
;
13578 w
->desired_matrix
->no_scrolling_p
= 1;
13586 /***********************************************************************
13587 More debugging support
13588 ***********************************************************************/
13592 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
13593 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
13594 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
13597 /* Dump the contents of glyph matrix MATRIX on stderr.
13599 GLYPHS 0 means don't show glyph contents.
13600 GLYPHS 1 means show glyphs in short form
13601 GLYPHS > 1 means show glyphs in long form. */
13604 dump_glyph_matrix (matrix
, glyphs
)
13605 struct glyph_matrix
*matrix
;
13609 for (i
= 0; i
< matrix
->nrows
; ++i
)
13610 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
13614 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
13615 the glyph row and area where the glyph comes from. */
13618 dump_glyph (row
, glyph
, area
)
13619 struct glyph_row
*row
;
13620 struct glyph
*glyph
;
13623 if (glyph
->type
== CHAR_GLYPH
)
13626 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13627 glyph
- row
->glyphs
[TEXT_AREA
],
13630 (BUFFERP (glyph
->object
)
13632 : (STRINGP (glyph
->object
)
13635 glyph
->pixel_width
,
13637 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
13641 glyph
->left_box_line_p
,
13642 glyph
->right_box_line_p
);
13644 else if (glyph
->type
== STRETCH_GLYPH
)
13647 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13648 glyph
- row
->glyphs
[TEXT_AREA
],
13651 (BUFFERP (glyph
->object
)
13653 : (STRINGP (glyph
->object
)
13656 glyph
->pixel_width
,
13660 glyph
->left_box_line_p
,
13661 glyph
->right_box_line_p
);
13663 else if (glyph
->type
== IMAGE_GLYPH
)
13666 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13667 glyph
- row
->glyphs
[TEXT_AREA
],
13670 (BUFFERP (glyph
->object
)
13672 : (STRINGP (glyph
->object
)
13675 glyph
->pixel_width
,
13679 glyph
->left_box_line_p
,
13680 glyph
->right_box_line_p
);
13685 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
13686 GLYPHS 0 means don't show glyph contents.
13687 GLYPHS 1 means show glyphs in short form
13688 GLYPHS > 1 means show glyphs in long form. */
13691 dump_glyph_row (row
, vpos
, glyphs
)
13692 struct glyph_row
*row
;
13697 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
13698 fprintf (stderr
, "=======================================================================\n");
13700 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
13701 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
13703 MATRIX_ROW_START_CHARPOS (row
),
13704 MATRIX_ROW_END_CHARPOS (row
),
13705 row
->used
[TEXT_AREA
],
13706 row
->contains_overlapping_glyphs_p
,
13708 row
->truncated_on_left_p
,
13709 row
->truncated_on_right_p
,
13710 row
->overlay_arrow_p
,
13712 MATRIX_ROW_CONTINUATION_LINE_P (row
),
13713 row
->displays_text_p
,
13716 row
->ends_in_middle_of_char_p
,
13717 row
->starts_in_middle_of_char_p
,
13723 row
->visible_height
,
13726 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
13727 row
->end
.overlay_string_index
,
13728 row
->continuation_lines_width
);
13729 fprintf (stderr
, "%9d %5d\n",
13730 CHARPOS (row
->start
.string_pos
),
13731 CHARPOS (row
->end
.string_pos
));
13732 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
13733 row
->end
.dpvec_index
);
13740 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
13742 struct glyph
*glyph
= row
->glyphs
[area
];
13743 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
13745 /* Glyph for a line end in text. */
13746 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
13749 if (glyph
< glyph_end
)
13750 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
13752 for (; glyph
< glyph_end
; ++glyph
)
13753 dump_glyph (row
, glyph
, area
);
13756 else if (glyphs
== 1)
13760 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
13762 char *s
= (char *) alloca (row
->used
[area
] + 1);
13765 for (i
= 0; i
< row
->used
[area
]; ++i
)
13767 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
13768 if (glyph
->type
== CHAR_GLYPH
13769 && glyph
->u
.ch
< 0x80
13770 && glyph
->u
.ch
>= ' ')
13771 s
[i
] = glyph
->u
.ch
;
13777 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
13783 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
13784 Sdump_glyph_matrix
, 0, 1, "p",
13785 doc
: /* Dump the current matrix of the selected window to stderr.
13786 Shows contents of glyph row structures. With non-nil
13787 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
13788 glyphs in short form, otherwise show glyphs in long form. */)
13790 Lisp_Object glyphs
;
13792 struct window
*w
= XWINDOW (selected_window
);
13793 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13795 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
13796 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
13797 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
13798 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
13799 fprintf (stderr
, "=============================================\n");
13800 dump_glyph_matrix (w
->current_matrix
,
13801 NILP (glyphs
) ? 0 : XINT (glyphs
));
13806 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
13807 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
13810 struct frame
*f
= XFRAME (selected_frame
);
13811 dump_glyph_matrix (f
->current_matrix
, 1);
13816 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
13817 doc
: /* Dump glyph row ROW to stderr.
13818 GLYPH 0 means don't dump glyphs.
13819 GLYPH 1 means dump glyphs in short form.
13820 GLYPH > 1 or omitted means dump glyphs in long form. */)
13822 Lisp_Object row
, glyphs
;
13824 struct glyph_matrix
*matrix
;
13827 CHECK_NUMBER (row
);
13828 matrix
= XWINDOW (selected_window
)->current_matrix
;
13830 if (vpos
>= 0 && vpos
< matrix
->nrows
)
13831 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
13833 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
13838 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
13839 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
13840 GLYPH 0 means don't dump glyphs.
13841 GLYPH 1 means dump glyphs in short form.
13842 GLYPH > 1 or omitted means dump glyphs in long form. */)
13844 Lisp_Object row
, glyphs
;
13846 struct frame
*sf
= SELECTED_FRAME ();
13847 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
13850 CHECK_NUMBER (row
);
13852 if (vpos
>= 0 && vpos
< m
->nrows
)
13853 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
13854 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
13859 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
13860 doc
: /* Toggle tracing of redisplay.
13861 With ARG, turn tracing on if and only if ARG is positive. */)
13866 trace_redisplay_p
= !trace_redisplay_p
;
13869 arg
= Fprefix_numeric_value (arg
);
13870 trace_redisplay_p
= XINT (arg
) > 0;
13877 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
13878 doc
: /* Like `format', but print result to stderr.
13879 usage: (trace-to-stderr STRING &rest OBJECTS) */)
13884 Lisp_Object s
= Fformat (nargs
, args
);
13885 fprintf (stderr
, "%s", SDATA (s
));
13889 #endif /* GLYPH_DEBUG */
13893 /***********************************************************************
13894 Building Desired Matrix Rows
13895 ***********************************************************************/
13897 /* Return a temporary glyph row holding the glyphs of an overlay
13898 arrow. Only used for non-window-redisplay windows. */
13900 static struct glyph_row
*
13901 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
13903 Lisp_Object overlay_arrow_string
;
13905 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13906 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13907 struct buffer
*old
= current_buffer
;
13908 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
13909 int arrow_len
= SCHARS (overlay_arrow_string
);
13910 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
13911 const unsigned char *p
;
13914 int n_glyphs_before
;
13916 set_buffer_temp (buffer
);
13917 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
13918 it
.glyph_row
->used
[TEXT_AREA
] = 0;
13919 SET_TEXT_POS (it
.position
, 0, 0);
13921 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
13923 while (p
< arrow_end
)
13925 Lisp_Object face
, ilisp
;
13927 /* Get the next character. */
13929 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
13931 it
.c
= *p
, it
.len
= 1;
13934 /* Get its face. */
13935 ilisp
= make_number (p
- arrow_string
);
13936 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
13937 it
.face_id
= compute_char_face (f
, it
.c
, face
);
13939 /* Compute its width, get its glyphs. */
13940 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
13941 SET_TEXT_POS (it
.position
, -1, -1);
13942 PRODUCE_GLYPHS (&it
);
13944 /* If this character doesn't fit any more in the line, we have
13945 to remove some glyphs. */
13946 if (it
.current_x
> it
.last_visible_x
)
13948 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
13953 set_buffer_temp (old
);
13954 return it
.glyph_row
;
13958 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
13959 glyphs are only inserted for terminal frames since we can't really
13960 win with truncation glyphs when partially visible glyphs are
13961 involved. Which glyphs to insert is determined by
13962 produce_special_glyphs. */
13965 insert_left_trunc_glyphs (it
)
13968 struct it truncate_it
;
13969 struct glyph
*from
, *end
, *to
, *toend
;
13971 xassert (!FRAME_WINDOW_P (it
->f
));
13973 /* Get the truncation glyphs. */
13975 truncate_it
.current_x
= 0;
13976 truncate_it
.face_id
= DEFAULT_FACE_ID
;
13977 truncate_it
.glyph_row
= &scratch_glyph_row
;
13978 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
13979 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
13980 truncate_it
.object
= make_number (0);
13981 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
13983 /* Overwrite glyphs from IT with truncation glyphs. */
13984 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
13985 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
13986 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
13987 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
13992 /* There may be padding glyphs left over. Overwrite them too. */
13993 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
13995 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14001 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
14005 /* Compute the pixel height and width of IT->glyph_row.
14007 Most of the time, ascent and height of a display line will be equal
14008 to the max_ascent and max_height values of the display iterator
14009 structure. This is not the case if
14011 1. We hit ZV without displaying anything. In this case, max_ascent
14012 and max_height will be zero.
14014 2. We have some glyphs that don't contribute to the line height.
14015 (The glyph row flag contributes_to_line_height_p is for future
14016 pixmap extensions).
14018 The first case is easily covered by using default values because in
14019 these cases, the line height does not really matter, except that it
14020 must not be zero. */
14023 compute_line_metrics (it
)
14026 struct glyph_row
*row
= it
->glyph_row
;
14029 if (FRAME_WINDOW_P (it
->f
))
14031 int i
, min_y
, max_y
;
14033 /* The line may consist of one space only, that was added to
14034 place the cursor on it. If so, the row's height hasn't been
14036 if (row
->height
== 0)
14038 if (it
->max_ascent
+ it
->max_descent
== 0)
14039 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
14040 row
->ascent
= it
->max_ascent
;
14041 row
->height
= it
->max_ascent
+ it
->max_descent
;
14042 row
->phys_ascent
= it
->max_phys_ascent
;
14043 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14046 /* Compute the width of this line. */
14047 row
->pixel_width
= row
->x
;
14048 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
14049 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
14051 xassert (row
->pixel_width
>= 0);
14052 xassert (row
->ascent
>= 0 && row
->height
> 0);
14054 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
14055 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
14057 /* If first line's physical ascent is larger than its logical
14058 ascent, use the physical ascent, and make the row taller.
14059 This makes accented characters fully visible. */
14060 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
14061 && row
->phys_ascent
> row
->ascent
)
14063 row
->height
+= row
->phys_ascent
- row
->ascent
;
14064 row
->ascent
= row
->phys_ascent
;
14067 /* Compute how much of the line is visible. */
14068 row
->visible_height
= row
->height
;
14070 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
14071 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
14073 if (row
->y
< min_y
)
14074 row
->visible_height
-= min_y
- row
->y
;
14075 if (row
->y
+ row
->height
> max_y
)
14076 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14080 row
->pixel_width
= row
->used
[TEXT_AREA
];
14081 if (row
->continued_p
)
14082 row
->pixel_width
-= it
->continuation_pixel_width
;
14083 else if (row
->truncated_on_right_p
)
14084 row
->pixel_width
-= it
->truncation_pixel_width
;
14085 row
->ascent
= row
->phys_ascent
= 0;
14086 row
->height
= row
->phys_height
= row
->visible_height
= 1;
14089 /* Compute a hash code for this row. */
14091 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14092 for (i
= 0; i
< row
->used
[area
]; ++i
)
14093 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
14094 + row
->glyphs
[area
][i
].u
.val
14095 + row
->glyphs
[area
][i
].face_id
14096 + row
->glyphs
[area
][i
].padding_p
14097 + (row
->glyphs
[area
][i
].type
<< 2));
14099 it
->max_ascent
= it
->max_descent
= 0;
14100 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
14104 /* Append one space to the glyph row of iterator IT if doing a
14105 window-based redisplay. DEFAULT_FACE_P non-zero means let the
14106 space have the default face, otherwise let it have the same face as
14107 IT->face_id. Value is non-zero if a space was added.
14109 This function is called to make sure that there is always one glyph
14110 at the end of a glyph row that the cursor can be set on under
14111 window-systems. (If there weren't such a glyph we would not know
14112 how wide and tall a box cursor should be displayed).
14114 At the same time this space let's a nicely handle clearing to the
14115 end of the line if the row ends in italic text. */
14118 append_space (it
, default_face_p
)
14120 int default_face_p
;
14122 if (FRAME_WINDOW_P (it
->f
))
14124 int n
= it
->glyph_row
->used
[TEXT_AREA
];
14126 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
14127 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
14129 /* Save some values that must not be changed.
14130 Must save IT->c and IT->len because otherwise
14131 ITERATOR_AT_END_P wouldn't work anymore after
14132 append_space has been called. */
14133 enum display_element_type saved_what
= it
->what
;
14134 int saved_c
= it
->c
, saved_len
= it
->len
;
14135 int saved_x
= it
->current_x
;
14136 int saved_face_id
= it
->face_id
;
14137 struct text_pos saved_pos
;
14138 Lisp_Object saved_object
;
14141 saved_object
= it
->object
;
14142 saved_pos
= it
->position
;
14144 it
->what
= IT_CHARACTER
;
14145 bzero (&it
->position
, sizeof it
->position
);
14146 it
->object
= make_number (0);
14150 if (default_face_p
)
14151 it
->face_id
= DEFAULT_FACE_ID
;
14152 else if (it
->face_before_selective_p
)
14153 it
->face_id
= it
->saved_face_id
;
14154 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14155 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
14157 PRODUCE_GLYPHS (it
);
14159 it
->current_x
= saved_x
;
14160 it
->object
= saved_object
;
14161 it
->position
= saved_pos
;
14162 it
->what
= saved_what
;
14163 it
->face_id
= saved_face_id
;
14164 it
->len
= saved_len
;
14174 /* Extend the face of the last glyph in the text area of IT->glyph_row
14175 to the end of the display line. Called from display_line.
14176 If the glyph row is empty, add a space glyph to it so that we
14177 know the face to draw. Set the glyph row flag fill_line_p. */
14180 extend_face_to_end_of_line (it
)
14184 struct frame
*f
= it
->f
;
14186 /* If line is already filled, do nothing. */
14187 if (it
->current_x
>= it
->last_visible_x
)
14190 /* Face extension extends the background and box of IT->face_id
14191 to the end of the line. If the background equals the background
14192 of the frame, we don't have to do anything. */
14193 if (it
->face_before_selective_p
)
14194 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14196 face
= FACE_FROM_ID (f
, it
->face_id
);
14198 if (FRAME_WINDOW_P (f
)
14199 && face
->box
== FACE_NO_BOX
14200 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
14204 /* Set the glyph row flag indicating that the face of the last glyph
14205 in the text area has to be drawn to the end of the text area. */
14206 it
->glyph_row
->fill_line_p
= 1;
14208 /* If current character of IT is not ASCII, make sure we have the
14209 ASCII face. This will be automatically undone the next time
14210 get_next_display_element returns a multibyte character. Note
14211 that the character will always be single byte in unibyte text. */
14212 if (!SINGLE_BYTE_CHAR_P (it
->c
))
14214 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
14217 if (FRAME_WINDOW_P (f
))
14219 /* If the row is empty, add a space with the current face of IT,
14220 so that we know which face to draw. */
14221 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
14223 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
14224 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
14225 it
->glyph_row
->used
[TEXT_AREA
] = 1;
14230 /* Save some values that must not be changed. */
14231 int saved_x
= it
->current_x
;
14232 struct text_pos saved_pos
;
14233 Lisp_Object saved_object
;
14234 enum display_element_type saved_what
= it
->what
;
14235 int saved_face_id
= it
->face_id
;
14237 saved_object
= it
->object
;
14238 saved_pos
= it
->position
;
14240 it
->what
= IT_CHARACTER
;
14241 bzero (&it
->position
, sizeof it
->position
);
14242 it
->object
= make_number (0);
14245 it
->face_id
= face
->id
;
14247 PRODUCE_GLYPHS (it
);
14249 while (it
->current_x
<= it
->last_visible_x
)
14250 PRODUCE_GLYPHS (it
);
14252 /* Don't count these blanks really. It would let us insert a left
14253 truncation glyph below and make us set the cursor on them, maybe. */
14254 it
->current_x
= saved_x
;
14255 it
->object
= saved_object
;
14256 it
->position
= saved_pos
;
14257 it
->what
= saved_what
;
14258 it
->face_id
= saved_face_id
;
14263 /* Value is non-zero if text starting at CHARPOS in current_buffer is
14264 trailing whitespace. */
14267 trailing_whitespace_p (charpos
)
14270 int bytepos
= CHAR_TO_BYTE (charpos
);
14273 while (bytepos
< ZV_BYTE
14274 && (c
= FETCH_CHAR (bytepos
),
14275 c
== ' ' || c
== '\t'))
14278 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
14280 if (bytepos
!= PT_BYTE
)
14287 /* Highlight trailing whitespace, if any, in ROW. */
14290 highlight_trailing_whitespace (f
, row
)
14292 struct glyph_row
*row
;
14294 int used
= row
->used
[TEXT_AREA
];
14298 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
14299 struct glyph
*glyph
= start
+ used
- 1;
14301 /* Skip over glyphs inserted to display the cursor at the
14302 end of a line, for extending the face of the last glyph
14303 to the end of the line on terminals, and for truncation
14304 and continuation glyphs. */
14305 while (glyph
>= start
14306 && glyph
->type
== CHAR_GLYPH
14307 && INTEGERP (glyph
->object
))
14310 /* If last glyph is a space or stretch, and it's trailing
14311 whitespace, set the face of all trailing whitespace glyphs in
14312 IT->glyph_row to `trailing-whitespace'. */
14314 && BUFFERP (glyph
->object
)
14315 && (glyph
->type
== STRETCH_GLYPH
14316 || (glyph
->type
== CHAR_GLYPH
14317 && glyph
->u
.ch
== ' '))
14318 && trailing_whitespace_p (glyph
->charpos
))
14320 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
14322 while (glyph
>= start
14323 && BUFFERP (glyph
->object
)
14324 && (glyph
->type
== STRETCH_GLYPH
14325 || (glyph
->type
== CHAR_GLYPH
14326 && glyph
->u
.ch
== ' ')))
14327 (glyph
--)->face_id
= face_id
;
14333 /* Value is non-zero if glyph row ROW in window W should be
14334 used to hold the cursor. */
14337 cursor_row_p (w
, row
)
14339 struct glyph_row
*row
;
14341 int cursor_row_p
= 1;
14343 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
14345 /* If the row ends with a newline from a string, we don't want
14346 the cursor there (if the row is continued it doesn't end in a
14348 if (CHARPOS (row
->end
.string_pos
) >= 0
14349 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14350 cursor_row_p
= row
->continued_p
;
14352 /* If the row ends at ZV, display the cursor at the end of that
14353 row instead of at the start of the row below. */
14354 else if (row
->ends_at_zv_p
)
14360 return cursor_row_p
;
14364 /* Construct the glyph row IT->glyph_row in the desired matrix of
14365 IT->w from text at the current position of IT. See dispextern.h
14366 for an overview of struct it. Value is non-zero if
14367 IT->glyph_row displays text, as opposed to a line displaying ZV
14374 struct glyph_row
*row
= it
->glyph_row
;
14375 int overlay_arrow_bitmap
;
14376 Lisp_Object overlay_arrow_string
;
14378 /* We always start displaying at hpos zero even if hscrolled. */
14379 xassert (it
->hpos
== 0 && it
->current_x
== 0);
14381 /* We must not display in a row that's not a text row. */
14382 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
14383 < it
->w
->desired_matrix
->nrows
);
14385 /* Is IT->w showing the region? */
14386 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
14388 /* Clear the result glyph row and enable it. */
14389 prepare_desired_row (row
);
14391 row
->y
= it
->current_y
;
14392 row
->start
= it
->start
;
14393 row
->continuation_lines_width
= it
->continuation_lines_width
;
14394 row
->displays_text_p
= 1;
14395 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
14396 it
->starts_in_middle_of_char_p
= 0;
14398 /* Arrange the overlays nicely for our purposes. Usually, we call
14399 display_line on only one line at a time, in which case this
14400 can't really hurt too much, or we call it on lines which appear
14401 one after another in the buffer, in which case all calls to
14402 recenter_overlay_lists but the first will be pretty cheap. */
14403 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
14405 /* Move over display elements that are not visible because we are
14406 hscrolled. This may stop at an x-position < IT->first_visible_x
14407 if the first glyph is partially visible or if we hit a line end. */
14408 if (it
->current_x
< it
->first_visible_x
)
14409 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
14410 MOVE_TO_POS
| MOVE_TO_X
);
14412 /* Get the initial row height. This is either the height of the
14413 text hscrolled, if there is any, or zero. */
14414 row
->ascent
= it
->max_ascent
;
14415 row
->height
= it
->max_ascent
+ it
->max_descent
;
14416 row
->phys_ascent
= it
->max_phys_ascent
;
14417 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14419 /* Loop generating characters. The loop is left with IT on the next
14420 character to display. */
14423 int n_glyphs_before
, hpos_before
, x_before
;
14425 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
14427 /* Retrieve the next thing to display. Value is zero if end of
14429 if (!get_next_display_element (it
))
14431 /* Maybe add a space at the end of this line that is used to
14432 display the cursor there under X. Set the charpos of the
14433 first glyph of blank lines not corresponding to any text
14435 #ifdef HAVE_WINDOW_SYSTEM
14436 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14437 row
->exact_window_width_line_p
= 1;
14439 #endif /* HAVE_WINDOW_SYSTEM */
14440 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
14441 || row
->used
[TEXT_AREA
] == 0)
14443 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
14444 row
->displays_text_p
= 0;
14446 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
14447 && (!MINI_WINDOW_P (it
->w
)
14448 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
14449 row
->indicate_empty_line_p
= 1;
14452 it
->continuation_lines_width
= 0;
14453 row
->ends_at_zv_p
= 1;
14457 /* Now, get the metrics of what we want to display. This also
14458 generates glyphs in `row' (which is IT->glyph_row). */
14459 n_glyphs_before
= row
->used
[TEXT_AREA
];
14462 /* Remember the line height so far in case the next element doesn't
14463 fit on the line. */
14464 if (!it
->truncate_lines_p
)
14466 ascent
= it
->max_ascent
;
14467 descent
= it
->max_descent
;
14468 phys_ascent
= it
->max_phys_ascent
;
14469 phys_descent
= it
->max_phys_descent
;
14472 PRODUCE_GLYPHS (it
);
14474 /* If this display element was in marginal areas, continue with
14476 if (it
->area
!= TEXT_AREA
)
14478 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14479 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14480 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14481 row
->phys_height
= max (row
->phys_height
,
14482 it
->max_phys_ascent
+ it
->max_phys_descent
);
14483 set_iterator_to_next (it
, 1);
14487 /* Does the display element fit on the line? If we truncate
14488 lines, we should draw past the right edge of the window. If
14489 we don't truncate, we want to stop so that we can display the
14490 continuation glyph before the right margin. If lines are
14491 continued, there are two possible strategies for characters
14492 resulting in more than 1 glyph (e.g. tabs): Display as many
14493 glyphs as possible in this line and leave the rest for the
14494 continuation line, or display the whole element in the next
14495 line. Original redisplay did the former, so we do it also. */
14496 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
14497 hpos_before
= it
->hpos
;
14500 if (/* Not a newline. */
14502 /* Glyphs produced fit entirely in the line. */
14503 && it
->current_x
< it
->last_visible_x
)
14505 it
->hpos
+= nglyphs
;
14506 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14507 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14508 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14509 row
->phys_height
= max (row
->phys_height
,
14510 it
->max_phys_ascent
+ it
->max_phys_descent
);
14511 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
14512 row
->x
= x
- it
->first_visible_x
;
14517 struct glyph
*glyph
;
14519 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
14521 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14522 new_x
= x
+ glyph
->pixel_width
;
14524 if (/* Lines are continued. */
14525 !it
->truncate_lines_p
14526 && (/* Glyph doesn't fit on the line. */
14527 new_x
> it
->last_visible_x
14528 /* Or it fits exactly on a window system frame. */
14529 || (new_x
== it
->last_visible_x
14530 && FRAME_WINDOW_P (it
->f
))))
14532 /* End of a continued line. */
14535 || (new_x
== it
->last_visible_x
14536 && FRAME_WINDOW_P (it
->f
)))
14538 /* Current glyph is the only one on the line or
14539 fits exactly on the line. We must continue
14540 the line because we can't draw the cursor
14541 after the glyph. */
14542 row
->continued_p
= 1;
14543 it
->current_x
= new_x
;
14544 it
->continuation_lines_width
+= new_x
;
14546 if (i
== nglyphs
- 1)
14548 set_iterator_to_next (it
, 1);
14549 #ifdef HAVE_WINDOW_SYSTEM
14550 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14552 if (!get_next_display_element (it
))
14554 row
->exact_window_width_line_p
= 1;
14555 it
->continuation_lines_width
= 0;
14556 row
->continued_p
= 0;
14557 row
->ends_at_zv_p
= 1;
14559 else if (ITERATOR_AT_END_OF_LINE_P (it
))
14561 row
->continued_p
= 0;
14562 row
->exact_window_width_line_p
= 1;
14565 #endif /* HAVE_WINDOW_SYSTEM */
14568 else if (CHAR_GLYPH_PADDING_P (*glyph
)
14569 && !FRAME_WINDOW_P (it
->f
))
14571 /* A padding glyph that doesn't fit on this line.
14572 This means the whole character doesn't fit
14574 row
->used
[TEXT_AREA
] = n_glyphs_before
;
14576 /* Fill the rest of the row with continuation
14577 glyphs like in 20.x. */
14578 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
14579 < row
->glyphs
[1 + TEXT_AREA
])
14580 produce_special_glyphs (it
, IT_CONTINUATION
);
14582 row
->continued_p
= 1;
14583 it
->current_x
= x_before
;
14584 it
->continuation_lines_width
+= x_before
;
14586 /* Restore the height to what it was before the
14587 element not fitting on the line. */
14588 it
->max_ascent
= ascent
;
14589 it
->max_descent
= descent
;
14590 it
->max_phys_ascent
= phys_ascent
;
14591 it
->max_phys_descent
= phys_descent
;
14593 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
14595 /* A TAB that extends past the right edge of the
14596 window. This produces a single glyph on
14597 window system frames. We leave the glyph in
14598 this row and let it fill the row, but don't
14599 consume the TAB. */
14600 it
->continuation_lines_width
+= it
->last_visible_x
;
14601 row
->ends_in_middle_of_char_p
= 1;
14602 row
->continued_p
= 1;
14603 glyph
->pixel_width
= it
->last_visible_x
- x
;
14604 it
->starts_in_middle_of_char_p
= 1;
14608 /* Something other than a TAB that draws past
14609 the right edge of the window. Restore
14610 positions to values before the element. */
14611 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14613 /* Display continuation glyphs. */
14614 if (!FRAME_WINDOW_P (it
->f
))
14615 produce_special_glyphs (it
, IT_CONTINUATION
);
14616 row
->continued_p
= 1;
14618 it
->continuation_lines_width
+= x
;
14620 if (nglyphs
> 1 && i
> 0)
14622 row
->ends_in_middle_of_char_p
= 1;
14623 it
->starts_in_middle_of_char_p
= 1;
14626 /* Restore the height to what it was before the
14627 element not fitting on the line. */
14628 it
->max_ascent
= ascent
;
14629 it
->max_descent
= descent
;
14630 it
->max_phys_ascent
= phys_ascent
;
14631 it
->max_phys_descent
= phys_descent
;
14636 else if (new_x
> it
->first_visible_x
)
14638 /* Increment number of glyphs actually displayed. */
14641 if (x
< it
->first_visible_x
)
14642 /* Glyph is partially visible, i.e. row starts at
14643 negative X position. */
14644 row
->x
= x
- it
->first_visible_x
;
14648 /* Glyph is completely off the left margin of the
14649 window. This should not happen because of the
14650 move_it_in_display_line at the start of this
14651 function, unless the text display area of the
14652 window is empty. */
14653 xassert (it
->first_visible_x
<= it
->last_visible_x
);
14657 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14658 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14659 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14660 row
->phys_height
= max (row
->phys_height
,
14661 it
->max_phys_ascent
+ it
->max_phys_descent
);
14663 /* End of this display line if row is continued. */
14664 if (row
->continued_p
|| row
->ends_at_zv_p
)
14669 /* Is this a line end? If yes, we're also done, after making
14670 sure that a non-default face is extended up to the right
14671 margin of the window. */
14672 if (ITERATOR_AT_END_OF_LINE_P (it
))
14674 int used_before
= row
->used
[TEXT_AREA
];
14676 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
14678 #ifdef HAVE_WINDOW_SYSTEM
14679 /* Add a space at the end of the line that is used to
14680 display the cursor there. */
14681 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14682 append_space (it
, 0);
14683 #endif /* HAVE_WINDOW_SYSTEM */
14685 /* Extend the face to the end of the line. */
14686 extend_face_to_end_of_line (it
);
14688 /* Make sure we have the position. */
14689 if (used_before
== 0)
14690 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
14692 /* Consume the line end. This skips over invisible lines. */
14693 set_iterator_to_next (it
, 1);
14694 it
->continuation_lines_width
= 0;
14698 /* Proceed with next display element. Note that this skips
14699 over lines invisible because of selective display. */
14700 set_iterator_to_next (it
, 1);
14702 /* If we truncate lines, we are done when the last displayed
14703 glyphs reach past the right margin of the window. */
14704 if (it
->truncate_lines_p
14705 && (FRAME_WINDOW_P (it
->f
)
14706 ? (it
->current_x
>= it
->last_visible_x
)
14707 : (it
->current_x
> it
->last_visible_x
)))
14709 /* Maybe add truncation glyphs. */
14710 if (!FRAME_WINDOW_P (it
->f
))
14714 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14715 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14718 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14720 row
->used
[TEXT_AREA
] = i
;
14721 produce_special_glyphs (it
, IT_TRUNCATION
);
14724 #ifdef HAVE_WINDOW_SYSTEM
14727 /* Don't truncate if we can overflow newline into fringe. */
14728 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14730 if (!get_next_display_element (it
))
14732 #ifdef HAVE_WINDOW_SYSTEM
14733 it
->continuation_lines_width
= 0;
14734 row
->ends_at_zv_p
= 1;
14735 row
->exact_window_width_line_p
= 1;
14737 #endif /* HAVE_WINDOW_SYSTEM */
14739 if (ITERATOR_AT_END_OF_LINE_P (it
))
14741 row
->exact_window_width_line_p
= 1;
14742 goto at_end_of_line
;
14746 #endif /* HAVE_WINDOW_SYSTEM */
14748 row
->truncated_on_right_p
= 1;
14749 it
->continuation_lines_width
= 0;
14750 reseat_at_next_visible_line_start (it
, 0);
14751 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
14752 it
->hpos
= hpos_before
;
14753 it
->current_x
= x_before
;
14758 /* If line is not empty and hscrolled, maybe insert truncation glyphs
14759 at the left window margin. */
14760 if (it
->first_visible_x
14761 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
14763 if (!FRAME_WINDOW_P (it
->f
))
14764 insert_left_trunc_glyphs (it
);
14765 row
->truncated_on_left_p
= 1;
14768 /* If the start of this line is the overlay arrow-position, then
14769 mark this glyph row as the one containing the overlay arrow.
14770 This is clearly a mess with variable size fonts. It would be
14771 better to let it be displayed like cursors under X. */
14772 if (! overlay_arrow_seen
14773 && (overlay_arrow_string
14774 = overlay_arrow_at_row (it
->f
, row
, &overlay_arrow_bitmap
),
14775 !NILP (overlay_arrow_string
)))
14777 /* Overlay arrow in window redisplay is a fringe bitmap. */
14778 if (!FRAME_WINDOW_P (it
->f
))
14780 struct glyph_row
*arrow_row
14781 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
14782 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
14783 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
14784 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
14785 struct glyph
*p2
, *end
;
14787 /* Copy the arrow glyphs. */
14788 while (glyph
< arrow_end
)
14791 /* Throw away padding glyphs. */
14793 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
14794 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
14800 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
14804 overlay_arrow_seen
= 1;
14805 it
->w
->overlay_arrow_bitmap
= overlay_arrow_bitmap
;
14806 row
->overlay_arrow_p
= 1;
14809 /* Compute pixel dimensions of this line. */
14810 compute_line_metrics (it
);
14812 /* Remember the position at which this line ends. */
14813 row
->end
= it
->current
;
14815 /* Save fringe bitmaps in this row. */
14816 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
14817 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
14818 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
14819 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
14821 it
->left_user_fringe_bitmap
= 0;
14822 it
->left_user_fringe_face_id
= 0;
14823 it
->right_user_fringe_bitmap
= 0;
14824 it
->right_user_fringe_face_id
= 0;
14826 /* Maybe set the cursor. */
14827 if (it
->w
->cursor
.vpos
< 0
14828 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
14829 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
14830 && cursor_row_p (it
->w
, row
))
14831 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
14833 /* Highlight trailing whitespace. */
14834 if (!NILP (Vshow_trailing_whitespace
))
14835 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
14837 /* Prepare for the next line. This line starts horizontally at (X
14838 HPOS) = (0 0). Vertical positions are incremented. As a
14839 convenience for the caller, IT->glyph_row is set to the next
14841 it
->current_x
= it
->hpos
= 0;
14842 it
->current_y
+= row
->height
;
14845 it
->start
= it
->current
;
14846 return row
->displays_text_p
;
14851 /***********************************************************************
14853 ***********************************************************************/
14855 /* Redisplay the menu bar in the frame for window W.
14857 The menu bar of X frames that don't have X toolkit support is
14858 displayed in a special window W->frame->menu_bar_window.
14860 The menu bar of terminal frames is treated specially as far as
14861 glyph matrices are concerned. Menu bar lines are not part of
14862 windows, so the update is done directly on the frame matrix rows
14863 for the menu bar. */
14866 display_menu_bar (w
)
14869 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14874 /* Don't do all this for graphical frames. */
14876 if (!NILP (Vwindow_system
))
14879 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
14884 if (FRAME_MAC_P (f
))
14888 #ifdef USE_X_TOOLKIT
14889 xassert (!FRAME_WINDOW_P (f
));
14890 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
14891 it
.first_visible_x
= 0;
14892 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
14893 #else /* not USE_X_TOOLKIT */
14894 if (FRAME_WINDOW_P (f
))
14896 /* Menu bar lines are displayed in the desired matrix of the
14897 dummy window menu_bar_window. */
14898 struct window
*menu_w
;
14899 xassert (WINDOWP (f
->menu_bar_window
));
14900 menu_w
= XWINDOW (f
->menu_bar_window
);
14901 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
14903 it
.first_visible_x
= 0;
14904 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
14908 /* This is a TTY frame, i.e. character hpos/vpos are used as
14910 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
14912 it
.first_visible_x
= 0;
14913 it
.last_visible_x
= FRAME_COLS (f
);
14915 #endif /* not USE_X_TOOLKIT */
14917 if (! mode_line_inverse_video
)
14918 /* Force the menu-bar to be displayed in the default face. */
14919 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
14921 /* Clear all rows of the menu bar. */
14922 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
14924 struct glyph_row
*row
= it
.glyph_row
+ i
;
14925 clear_glyph_row (row
);
14926 row
->enabled_p
= 1;
14927 row
->full_width_p
= 1;
14930 /* Display all items of the menu bar. */
14931 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
14932 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
14934 Lisp_Object string
;
14936 /* Stop at nil string. */
14937 string
= AREF (items
, i
+ 1);
14941 /* Remember where item was displayed. */
14942 AREF (items
, i
+ 3) = make_number (it
.hpos
);
14944 /* Display the item, pad with one space. */
14945 if (it
.current_x
< it
.last_visible_x
)
14946 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
14947 SCHARS (string
) + 1, 0, 0, -1);
14950 /* Fill out the line with spaces. */
14951 if (it
.current_x
< it
.last_visible_x
)
14952 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
14954 /* Compute the total height of the lines. */
14955 compute_line_metrics (&it
);
14960 /***********************************************************************
14962 ***********************************************************************/
14964 /* Redisplay mode lines in the window tree whose root is WINDOW. If
14965 FORCE is non-zero, redisplay mode lines unconditionally.
14966 Otherwise, redisplay only mode lines that are garbaged. Value is
14967 the number of windows whose mode lines were redisplayed. */
14970 redisplay_mode_lines (window
, force
)
14971 Lisp_Object window
;
14976 while (!NILP (window
))
14978 struct window
*w
= XWINDOW (window
);
14980 if (WINDOWP (w
->hchild
))
14981 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
14982 else if (WINDOWP (w
->vchild
))
14983 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
14985 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
14986 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
14988 struct text_pos lpoint
;
14989 struct buffer
*old
= current_buffer
;
14991 /* Set the window's buffer for the mode line display. */
14992 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14993 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14995 /* Point refers normally to the selected window. For any
14996 other window, set up appropriate value. */
14997 if (!EQ (window
, selected_window
))
14999 struct text_pos pt
;
15001 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
15002 if (CHARPOS (pt
) < BEGV
)
15003 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15004 else if (CHARPOS (pt
) > (ZV
- 1))
15005 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
15007 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
15010 /* Display mode lines. */
15011 clear_glyph_matrix (w
->desired_matrix
);
15012 if (display_mode_lines (w
))
15015 w
->must_be_updated_p
= 1;
15018 /* Restore old settings. */
15019 set_buffer_internal_1 (old
);
15020 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15030 /* Display the mode and/or top line of window W. Value is the number
15031 of mode lines displayed. */
15034 display_mode_lines (w
)
15037 Lisp_Object old_selected_window
, old_selected_frame
;
15040 old_selected_frame
= selected_frame
;
15041 selected_frame
= w
->frame
;
15042 old_selected_window
= selected_window
;
15043 XSETWINDOW (selected_window
, w
);
15045 /* These will be set while the mode line specs are processed. */
15046 line_number_displayed
= 0;
15047 w
->column_number_displayed
= Qnil
;
15049 if (WINDOW_WANTS_MODELINE_P (w
))
15051 struct window
*sel_w
= XWINDOW (old_selected_window
);
15053 /* Select mode line face based on the real selected window. */
15054 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
15055 current_buffer
->mode_line_format
);
15059 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15061 display_mode_line (w
, HEADER_LINE_FACE_ID
,
15062 current_buffer
->header_line_format
);
15066 selected_frame
= old_selected_frame
;
15067 selected_window
= old_selected_window
;
15072 /* Display mode or top line of window W. FACE_ID specifies which line
15073 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
15074 FORMAT is the mode line format to display. Value is the pixel
15075 height of the mode line displayed. */
15078 display_mode_line (w
, face_id
, format
)
15080 enum face_id face_id
;
15081 Lisp_Object format
;
15086 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15087 prepare_desired_row (it
.glyph_row
);
15089 it
.glyph_row
->mode_line_p
= 1;
15091 if (! mode_line_inverse_video
)
15092 /* Force the mode-line to be displayed in the default face. */
15093 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15095 /* Temporarily make frame's keyboard the current kboard so that
15096 kboard-local variables in the mode_line_format will get the right
15098 push_frame_kboard (it
.f
);
15099 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15100 pop_frame_kboard ();
15102 /* Fill up with spaces. */
15103 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
15105 compute_line_metrics (&it
);
15106 it
.glyph_row
->full_width_p
= 1;
15107 it
.glyph_row
->continued_p
= 0;
15108 it
.glyph_row
->truncated_on_left_p
= 0;
15109 it
.glyph_row
->truncated_on_right_p
= 0;
15111 /* Make a 3D mode-line have a shadow at its right end. */
15112 face
= FACE_FROM_ID (it
.f
, face_id
);
15113 extend_face_to_end_of_line (&it
);
15114 if (face
->box
!= FACE_NO_BOX
)
15116 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
15117 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
15118 last
->right_box_line_p
= 1;
15121 return it
.glyph_row
->height
;
15124 /* Alist that caches the results of :propertize.
15125 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
15126 Lisp_Object mode_line_proptrans_alist
;
15128 /* List of strings making up the mode-line. */
15129 Lisp_Object mode_line_string_list
;
15131 /* Base face property when building propertized mode line string. */
15132 static Lisp_Object mode_line_string_face
;
15133 static Lisp_Object mode_line_string_face_prop
;
15136 /* Contribute ELT to the mode line for window IT->w. How it
15137 translates into text depends on its data type.
15139 IT describes the display environment in which we display, as usual.
15141 DEPTH is the depth in recursion. It is used to prevent
15142 infinite recursion here.
15144 FIELD_WIDTH is the number of characters the display of ELT should
15145 occupy in the mode line, and PRECISION is the maximum number of
15146 characters to display from ELT's representation. See
15147 display_string for details.
15149 Returns the hpos of the end of the text generated by ELT.
15151 PROPS is a property list to add to any string we encounter.
15153 If RISKY is nonzero, remove (disregard) any properties in any string
15154 we encounter, and ignore :eval and :propertize.
15156 If the global variable `frame_title_ptr' is non-NULL, then the output
15157 is passed to `store_frame_title' instead of `display_string'. */
15160 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
15163 int field_width
, precision
;
15164 Lisp_Object elt
, props
;
15167 int n
= 0, field
, prec
;
15172 elt
= build_string ("*too-deep*");
15176 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
15180 /* A string: output it and check for %-constructs within it. */
15182 const unsigned char *this, *lisp_string
;
15184 if (!NILP (props
) || risky
)
15186 Lisp_Object oprops
, aelt
;
15187 oprops
= Ftext_properties_at (make_number (0), elt
);
15189 if (NILP (Fequal (props
, oprops
)) || risky
)
15191 /* If the starting string has properties,
15192 merge the specified ones onto the existing ones. */
15193 if (! NILP (oprops
) && !risky
)
15197 oprops
= Fcopy_sequence (oprops
);
15199 while (CONSP (tem
))
15201 oprops
= Fplist_put (oprops
, XCAR (tem
),
15202 XCAR (XCDR (tem
)));
15203 tem
= XCDR (XCDR (tem
));
15208 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
15209 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
15211 mode_line_proptrans_alist
15212 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
15219 elt
= Fcopy_sequence (elt
);
15220 Fset_text_properties (make_number (0), Flength (elt
),
15222 /* Add this item to mode_line_proptrans_alist. */
15223 mode_line_proptrans_alist
15224 = Fcons (Fcons (elt
, props
),
15225 mode_line_proptrans_alist
);
15226 /* Truncate mode_line_proptrans_alist
15227 to at most 50 elements. */
15228 tem
= Fnthcdr (make_number (50),
15229 mode_line_proptrans_alist
);
15231 XSETCDR (tem
, Qnil
);
15236 this = SDATA (elt
);
15237 lisp_string
= this;
15241 prec
= precision
- n
;
15242 if (frame_title_ptr
)
15243 n
+= store_frame_title (SDATA (elt
), -1, prec
);
15244 else if (!NILP (mode_line_string_list
))
15245 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
15247 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
15248 0, prec
, 0, STRING_MULTIBYTE (elt
));
15253 while ((precision
<= 0 || n
< precision
)
15255 && (frame_title_ptr
15256 || !NILP (mode_line_string_list
)
15257 || it
->current_x
< it
->last_visible_x
))
15259 const unsigned char *last
= this;
15261 /* Advance to end of string or next format specifier. */
15262 while ((c
= *this++) != '\0' && c
!= '%')
15265 if (this - 1 != last
)
15267 /* Output to end of string or up to '%'. Field width
15268 is length of string. Don't output more than
15269 PRECISION allows us. */
15272 prec
= chars_in_text (last
, this - last
);
15273 if (precision
> 0 && prec
> precision
- n
)
15274 prec
= precision
- n
;
15276 if (frame_title_ptr
)
15277 n
+= store_frame_title (last
, 0, prec
);
15278 else if (!NILP (mode_line_string_list
))
15280 int bytepos
= last
- lisp_string
;
15281 int charpos
= string_byte_to_char (elt
, bytepos
);
15282 n
+= store_mode_line_string (NULL
,
15283 Fsubstring (elt
, make_number (charpos
),
15284 make_number (charpos
+ prec
)),
15289 int bytepos
= last
- lisp_string
;
15290 int charpos
= string_byte_to_char (elt
, bytepos
);
15291 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
15293 STRING_MULTIBYTE (elt
));
15296 else /* c == '%' */
15298 const unsigned char *percent_position
= this;
15300 /* Get the specified minimum width. Zero means
15303 while ((c
= *this++) >= '0' && c
<= '9')
15304 field
= field
* 10 + c
- '0';
15306 /* Don't pad beyond the total padding allowed. */
15307 if (field_width
- n
> 0 && field
> field_width
- n
)
15308 field
= field_width
- n
;
15310 /* Note that either PRECISION <= 0 or N < PRECISION. */
15311 prec
= precision
- n
;
15314 n
+= display_mode_element (it
, depth
, field
, prec
,
15315 Vglobal_mode_string
, props
,
15320 int bytepos
, charpos
;
15321 unsigned char *spec
;
15323 bytepos
= percent_position
- lisp_string
;
15324 charpos
= (STRING_MULTIBYTE (elt
)
15325 ? string_byte_to_char (elt
, bytepos
)
15329 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
15331 if (frame_title_ptr
)
15332 n
+= store_frame_title (spec
, field
, prec
);
15333 else if (!NILP (mode_line_string_list
))
15335 int len
= strlen (spec
);
15336 Lisp_Object tem
= make_string (spec
, len
);
15337 props
= Ftext_properties_at (make_number (charpos
), elt
);
15338 /* Should only keep face property in props */
15339 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
15343 int nglyphs_before
, nwritten
;
15345 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
15346 nwritten
= display_string (spec
, Qnil
, elt
,
15351 /* Assign to the glyphs written above the
15352 string where the `%x' came from, position
15356 struct glyph
*glyph
15357 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
15361 for (i
= 0; i
< nwritten
; ++i
)
15363 glyph
[i
].object
= elt
;
15364 glyph
[i
].charpos
= charpos
;
15379 /* A symbol: process the value of the symbol recursively
15380 as if it appeared here directly. Avoid error if symbol void.
15381 Special case: if value of symbol is a string, output the string
15384 register Lisp_Object tem
;
15386 /* If the variable is not marked as risky to set
15387 then its contents are risky to use. */
15388 if (NILP (Fget (elt
, Qrisky_local_variable
)))
15391 tem
= Fboundp (elt
);
15394 tem
= Fsymbol_value (elt
);
15395 /* If value is a string, output that string literally:
15396 don't check for % within it. */
15400 if (!EQ (tem
, elt
))
15402 /* Give up right away for nil or t. */
15412 register Lisp_Object car
, tem
;
15414 /* A cons cell: five distinct cases.
15415 If first element is :eval or :propertize, do something special.
15416 If first element is a string or a cons, process all the elements
15417 and effectively concatenate them.
15418 If first element is a negative number, truncate displaying cdr to
15419 at most that many characters. If positive, pad (with spaces)
15420 to at least that many characters.
15421 If first element is a symbol, process the cadr or caddr recursively
15422 according to whether the symbol's value is non-nil or nil. */
15424 if (EQ (car
, QCeval
))
15426 /* An element of the form (:eval FORM) means evaluate FORM
15427 and use the result as mode line elements. */
15432 if (CONSP (XCDR (elt
)))
15435 spec
= safe_eval (XCAR (XCDR (elt
)));
15436 n
+= display_mode_element (it
, depth
, field_width
- n
,
15437 precision
- n
, spec
, props
,
15441 else if (EQ (car
, QCpropertize
))
15443 /* An element of the form (:propertize ELT PROPS...)
15444 means display ELT but applying properties PROPS. */
15449 if (CONSP (XCDR (elt
)))
15450 n
+= display_mode_element (it
, depth
, field_width
- n
,
15451 precision
- n
, XCAR (XCDR (elt
)),
15452 XCDR (XCDR (elt
)), risky
);
15454 else if (SYMBOLP (car
))
15456 tem
= Fboundp (car
);
15460 /* elt is now the cdr, and we know it is a cons cell.
15461 Use its car if CAR has a non-nil value. */
15464 tem
= Fsymbol_value (car
);
15471 /* Symbol's value is nil (or symbol is unbound)
15472 Get the cddr of the original list
15473 and if possible find the caddr and use that. */
15477 else if (!CONSP (elt
))
15482 else if (INTEGERP (car
))
15484 register int lim
= XINT (car
);
15488 /* Negative int means reduce maximum width. */
15489 if (precision
<= 0)
15492 precision
= min (precision
, -lim
);
15496 /* Padding specified. Don't let it be more than
15497 current maximum. */
15499 lim
= min (precision
, lim
);
15501 /* If that's more padding than already wanted, queue it.
15502 But don't reduce padding already specified even if
15503 that is beyond the current truncation point. */
15504 field_width
= max (lim
, field_width
);
15508 else if (STRINGP (car
) || CONSP (car
))
15510 register int limit
= 50;
15511 /* Limit is to protect against circular lists. */
15514 && (precision
<= 0 || n
< precision
))
15516 n
+= display_mode_element (it
, depth
, field_width
- n
,
15517 precision
- n
, XCAR (elt
),
15527 elt
= build_string ("*invalid*");
15531 /* Pad to FIELD_WIDTH. */
15532 if (field_width
> 0 && n
< field_width
)
15534 if (frame_title_ptr
)
15535 n
+= store_frame_title ("", field_width
- n
, 0);
15536 else if (!NILP (mode_line_string_list
))
15537 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
15539 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
15546 /* Store a mode-line string element in mode_line_string_list.
15548 If STRING is non-null, display that C string. Otherwise, the Lisp
15549 string LISP_STRING is displayed.
15551 FIELD_WIDTH is the minimum number of output glyphs to produce.
15552 If STRING has fewer characters than FIELD_WIDTH, pad to the right
15553 with spaces. FIELD_WIDTH <= 0 means don't pad.
15555 PRECISION is the maximum number of characters to output from
15556 STRING. PRECISION <= 0 means don't truncate the string.
15558 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
15559 properties to the string.
15561 PROPS are the properties to add to the string.
15562 The mode_line_string_face face property is always added to the string.
15565 static int store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
15567 Lisp_Object lisp_string
;
15576 if (string
!= NULL
)
15578 len
= strlen (string
);
15579 if (precision
> 0 && len
> precision
)
15581 lisp_string
= make_string (string
, len
);
15583 props
= mode_line_string_face_prop
;
15584 else if (!NILP (mode_line_string_face
))
15586 Lisp_Object face
= Fplist_get (props
, Qface
);
15587 props
= Fcopy_sequence (props
);
15589 face
= mode_line_string_face
;
15591 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15592 props
= Fplist_put (props
, Qface
, face
);
15594 Fadd_text_properties (make_number (0), make_number (len
),
15595 props
, lisp_string
);
15599 len
= XFASTINT (Flength (lisp_string
));
15600 if (precision
> 0 && len
> precision
)
15603 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
15606 if (!NILP (mode_line_string_face
))
15610 props
= Ftext_properties_at (make_number (0), lisp_string
);
15611 face
= Fplist_get (props
, Qface
);
15613 face
= mode_line_string_face
;
15615 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15616 props
= Fcons (Qface
, Fcons (face
, Qnil
));
15618 lisp_string
= Fcopy_sequence (lisp_string
);
15621 Fadd_text_properties (make_number (0), make_number (len
),
15622 props
, lisp_string
);
15627 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15631 if (field_width
> len
)
15633 field_width
-= len
;
15634 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
15636 Fadd_text_properties (make_number (0), make_number (field_width
),
15637 props
, lisp_string
);
15638 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15646 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
15648 doc
: /* Return the mode-line of selected window as a string.
15649 First optional arg FORMAT specifies a different format string (see
15650 `mode-line-format' for details) to use. If FORMAT is t, return
15651 the buffer's header-line. Second optional arg WINDOW specifies a
15652 different window to use as the context for the formatting.
15653 If third optional arg NO-PROPS is non-nil, string is not propertized. */)
15654 (format
, window
, no_props
)
15655 Lisp_Object format
, window
, no_props
;
15660 struct buffer
*old_buffer
= NULL
;
15661 enum face_id face_id
= DEFAULT_FACE_ID
;
15664 window
= selected_window
;
15665 CHECK_WINDOW (window
);
15666 w
= XWINDOW (window
);
15667 CHECK_BUFFER (w
->buffer
);
15669 if (XBUFFER (w
->buffer
) != current_buffer
)
15671 old_buffer
= current_buffer
;
15672 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15675 if (NILP (format
) || EQ (format
, Qt
))
15677 face_id
= NILP (format
)
15678 ? CURRENT_MODE_LINE_FACE_ID (w
) :
15679 HEADER_LINE_FACE_ID
;
15680 format
= NILP (format
)
15681 ? current_buffer
->mode_line_format
15682 : current_buffer
->header_line_format
;
15685 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15687 if (NILP (no_props
))
15689 mode_line_string_face
=
15690 (face_id
== MODE_LINE_FACE_ID
? Qmode_line
:
15691 face_id
== MODE_LINE_INACTIVE_FACE_ID
? Qmode_line_inactive
:
15692 face_id
== HEADER_LINE_FACE_ID
? Qheader_line
: Qnil
);
15694 mode_line_string_face_prop
=
15695 NILP (mode_line_string_face
) ? Qnil
:
15696 Fcons (Qface
, Fcons (mode_line_string_face
, Qnil
));
15698 /* We need a dummy last element in mode_line_string_list to
15699 indicate we are building the propertized mode-line string.
15700 Using mode_line_string_face_prop here GC protects it. */
15701 mode_line_string_list
=
15702 Fcons (mode_line_string_face_prop
, Qnil
);
15703 frame_title_ptr
= NULL
;
15707 mode_line_string_face_prop
= Qnil
;
15708 mode_line_string_list
= Qnil
;
15709 frame_title_ptr
= frame_title_buf
;
15712 push_frame_kboard (it
.f
);
15713 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15714 pop_frame_kboard ();
15717 set_buffer_internal_1 (old_buffer
);
15719 if (NILP (no_props
))
15722 mode_line_string_list
= Fnreverse (mode_line_string_list
);
15723 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
15724 make_string ("", 0));
15725 mode_line_string_face_prop
= Qnil
;
15726 mode_line_string_list
= Qnil
;
15730 len
= frame_title_ptr
- frame_title_buf
;
15731 if (len
> 0 && frame_title_ptr
[-1] == '-')
15733 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
15734 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
15736 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
15737 if (len
> frame_title_ptr
- frame_title_buf
)
15738 len
= frame_title_ptr
- frame_title_buf
;
15741 frame_title_ptr
= NULL
;
15742 return make_string (frame_title_buf
, len
);
15745 /* Write a null-terminated, right justified decimal representation of
15746 the positive integer D to BUF using a minimal field width WIDTH. */
15749 pint2str (buf
, width
, d
)
15750 register char *buf
;
15751 register int width
;
15754 register char *p
= buf
;
15762 *p
++ = d
% 10 + '0';
15767 for (width
-= (int) (p
- buf
); width
> 0; --width
)
15778 /* Write a null-terminated, right justified decimal and "human
15779 readable" representation of the nonnegative integer D to BUF using
15780 a minimal field width WIDTH. D should be smaller than 999.5e24. */
15782 static const char power_letter
[] =
15796 pint2hrstr (buf
, width
, d
)
15801 /* We aim to represent the nonnegative integer D as
15802 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
15805 /* -1 means: do not use TENTHS. */
15809 /* Length of QUOTIENT.TENTHS as a string. */
15815 if (1000 <= quotient
)
15817 /* Scale to the appropriate EXPONENT. */
15820 remainder
= quotient
% 1000;
15824 while (1000 <= quotient
);
15826 /* Round to nearest and decide whether to use TENTHS or not. */
15829 tenths
= remainder
/ 100;
15830 if (50 <= remainder
% 100)
15836 if (quotient
== 10)
15843 if (500 <= remainder
)
15844 if (quotient
< 999)
15854 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
15855 if (tenths
== -1 && quotient
<= 99)
15862 p
= psuffix
= buf
+ max (width
, length
);
15864 /* Print EXPONENT. */
15866 *psuffix
++ = power_letter
[exponent
];
15869 /* Print TENTHS. */
15872 *--p
= '0' + tenths
;
15876 /* Print QUOTIENT. */
15879 int digit
= quotient
% 10;
15880 *--p
= '0' + digit
;
15882 while ((quotient
/= 10) != 0);
15884 /* Print leading spaces. */
15889 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
15890 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
15891 type of CODING_SYSTEM. Return updated pointer into BUF. */
15893 static unsigned char invalid_eol_type
[] = "(*invalid*)";
15896 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
15897 Lisp_Object coding_system
;
15898 register char *buf
;
15902 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
15903 const unsigned char *eol_str
;
15905 /* The EOL conversion we are using. */
15906 Lisp_Object eoltype
;
15908 val
= Fget (coding_system
, Qcoding_system
);
15911 if (!VECTORP (val
)) /* Not yet decided. */
15916 eoltype
= eol_mnemonic_undecided
;
15917 /* Don't mention EOL conversion if it isn't decided. */
15921 Lisp_Object eolvalue
;
15923 eolvalue
= Fget (coding_system
, Qeol_type
);
15926 *buf
++ = XFASTINT (AREF (val
, 1));
15930 /* The EOL conversion that is normal on this system. */
15932 if (NILP (eolvalue
)) /* Not yet decided. */
15933 eoltype
= eol_mnemonic_undecided
;
15934 else if (VECTORP (eolvalue
)) /* Not yet decided. */
15935 eoltype
= eol_mnemonic_undecided
;
15936 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
15937 eoltype
= (XFASTINT (eolvalue
) == 0
15938 ? eol_mnemonic_unix
15939 : (XFASTINT (eolvalue
) == 1
15940 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
15946 /* Mention the EOL conversion if it is not the usual one. */
15947 if (STRINGP (eoltype
))
15949 eol_str
= SDATA (eoltype
);
15950 eol_str_len
= SBYTES (eoltype
);
15952 else if (INTEGERP (eoltype
)
15953 && CHAR_VALID_P (XINT (eoltype
), 0))
15955 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
15956 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
15961 eol_str
= invalid_eol_type
;
15962 eol_str_len
= sizeof (invalid_eol_type
) - 1;
15964 bcopy (eol_str
, buf
, eol_str_len
);
15965 buf
+= eol_str_len
;
15971 /* Return a string for the output of a mode line %-spec for window W,
15972 generated by character C. PRECISION >= 0 means don't return a
15973 string longer than that value. FIELD_WIDTH > 0 means pad the
15974 string returned with spaces to that value. Return 1 in *MULTIBYTE
15975 if the result is multibyte text. */
15977 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
15980 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
15983 int field_width
, precision
;
15987 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15988 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
15989 struct buffer
*b
= XBUFFER (w
->buffer
);
15997 if (!NILP (b
->read_only
))
15999 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16004 /* This differs from %* only for a modified read-only buffer. */
16005 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16007 if (!NILP (b
->read_only
))
16012 /* This differs from %* in ignoring read-only-ness. */
16013 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16025 if (command_loop_level
> 5)
16027 p
= decode_mode_spec_buf
;
16028 for (i
= 0; i
< command_loop_level
; i
++)
16031 return decode_mode_spec_buf
;
16039 if (command_loop_level
> 5)
16041 p
= decode_mode_spec_buf
;
16042 for (i
= 0; i
< command_loop_level
; i
++)
16045 return decode_mode_spec_buf
;
16052 /* Let lots_of_dashes be a string of infinite length. */
16053 if (!NILP (mode_line_string_list
))
16055 if (field_width
<= 0
16056 || field_width
> sizeof (lots_of_dashes
))
16058 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
16059 decode_mode_spec_buf
[i
] = '-';
16060 decode_mode_spec_buf
[i
] = '\0';
16061 return decode_mode_spec_buf
;
16064 return lots_of_dashes
;
16073 int col
= (int) current_column (); /* iftc */
16074 w
->column_number_displayed
= make_number (col
);
16075 pint2str (decode_mode_spec_buf
, field_width
, col
);
16076 return decode_mode_spec_buf
;
16080 /* %F displays the frame name. */
16081 if (!NILP (f
->title
))
16082 return (char *) SDATA (f
->title
);
16083 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
16084 return (char *) SDATA (f
->name
);
16093 int size
= ZV
- BEGV
;
16094 pint2str (decode_mode_spec_buf
, field_width
, size
);
16095 return decode_mode_spec_buf
;
16100 int size
= ZV
- BEGV
;
16101 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
16102 return decode_mode_spec_buf
;
16107 int startpos
= XMARKER (w
->start
)->charpos
;
16108 int startpos_byte
= marker_byte_position (w
->start
);
16109 int line
, linepos
, linepos_byte
, topline
;
16111 int height
= WINDOW_TOTAL_LINES (w
);
16113 /* If we decided that this buffer isn't suitable for line numbers,
16114 don't forget that too fast. */
16115 if (EQ (w
->base_line_pos
, w
->buffer
))
16117 /* But do forget it, if the window shows a different buffer now. */
16118 else if (BUFFERP (w
->base_line_pos
))
16119 w
->base_line_pos
= Qnil
;
16121 /* If the buffer is very big, don't waste time. */
16122 if (INTEGERP (Vline_number_display_limit
)
16123 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
16125 w
->base_line_pos
= Qnil
;
16126 w
->base_line_number
= Qnil
;
16130 if (!NILP (w
->base_line_number
)
16131 && !NILP (w
->base_line_pos
)
16132 && XFASTINT (w
->base_line_pos
) <= startpos
)
16134 line
= XFASTINT (w
->base_line_number
);
16135 linepos
= XFASTINT (w
->base_line_pos
);
16136 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
16141 linepos
= BUF_BEGV (b
);
16142 linepos_byte
= BUF_BEGV_BYTE (b
);
16145 /* Count lines from base line to window start position. */
16146 nlines
= display_count_lines (linepos
, linepos_byte
,
16150 topline
= nlines
+ line
;
16152 /* Determine a new base line, if the old one is too close
16153 or too far away, or if we did not have one.
16154 "Too close" means it's plausible a scroll-down would
16155 go back past it. */
16156 if (startpos
== BUF_BEGV (b
))
16158 w
->base_line_number
= make_number (topline
);
16159 w
->base_line_pos
= make_number (BUF_BEGV (b
));
16161 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
16162 || linepos
== BUF_BEGV (b
))
16164 int limit
= BUF_BEGV (b
);
16165 int limit_byte
= BUF_BEGV_BYTE (b
);
16167 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
16169 if (startpos
- distance
> limit
)
16171 limit
= startpos
- distance
;
16172 limit_byte
= CHAR_TO_BYTE (limit
);
16175 nlines
= display_count_lines (startpos
, startpos_byte
,
16177 - (height
* 2 + 30),
16179 /* If we couldn't find the lines we wanted within
16180 line_number_display_limit_width chars per line,
16181 give up on line numbers for this window. */
16182 if (position
== limit_byte
&& limit
== startpos
- distance
)
16184 w
->base_line_pos
= w
->buffer
;
16185 w
->base_line_number
= Qnil
;
16189 w
->base_line_number
= make_number (topline
- nlines
);
16190 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
16193 /* Now count lines from the start pos to point. */
16194 nlines
= display_count_lines (startpos
, startpos_byte
,
16195 PT_BYTE
, PT
, &junk
);
16197 /* Record that we did display the line number. */
16198 line_number_displayed
= 1;
16200 /* Make the string to show. */
16201 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
16202 return decode_mode_spec_buf
;
16205 char* p
= decode_mode_spec_buf
;
16206 int pad
= field_width
- 2;
16212 return decode_mode_spec_buf
;
16218 obj
= b
->mode_name
;
16222 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
16228 int pos
= marker_position (w
->start
);
16229 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16231 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
16233 if (pos
<= BUF_BEGV (b
))
16238 else if (pos
<= BUF_BEGV (b
))
16242 if (total
> 1000000)
16243 /* Do it differently for a large value, to avoid overflow. */
16244 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16246 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16247 /* We can't normally display a 3-digit number,
16248 so get us a 2-digit number that is close. */
16251 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16252 return decode_mode_spec_buf
;
16256 /* Display percentage of size above the bottom of the screen. */
16259 int toppos
= marker_position (w
->start
);
16260 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
16261 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16263 if (botpos
>= BUF_ZV (b
))
16265 if (toppos
<= BUF_BEGV (b
))
16272 if (total
> 1000000)
16273 /* Do it differently for a large value, to avoid overflow. */
16274 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16276 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16277 /* We can't normally display a 3-digit number,
16278 so get us a 2-digit number that is close. */
16281 if (toppos
<= BUF_BEGV (b
))
16282 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
16284 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16285 return decode_mode_spec_buf
;
16290 /* status of process */
16291 obj
= Fget_buffer_process (w
->buffer
);
16293 return "no process";
16294 #ifdef subprocesses
16295 obj
= Fsymbol_name (Fprocess_status (obj
));
16299 case 't': /* indicate TEXT or BINARY */
16300 #ifdef MODE_LINE_BINARY_TEXT
16301 return MODE_LINE_BINARY_TEXT (b
);
16307 /* coding-system (not including end-of-line format) */
16309 /* coding-system (including end-of-line type) */
16311 int eol_flag
= (c
== 'Z');
16312 char *p
= decode_mode_spec_buf
;
16314 if (! FRAME_WINDOW_P (f
))
16316 /* No need to mention EOL here--the terminal never needs
16317 to do EOL conversion. */
16318 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
16319 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
16321 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
16324 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
16325 #ifdef subprocesses
16326 obj
= Fget_buffer_process (Fcurrent_buffer ());
16327 if (PROCESSP (obj
))
16329 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
16331 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
16334 #endif /* subprocesses */
16337 return decode_mode_spec_buf
;
16343 *multibyte
= STRING_MULTIBYTE (obj
);
16344 return (char *) SDATA (obj
);
16351 /* Count up to COUNT lines starting from START / START_BYTE.
16352 But don't go beyond LIMIT_BYTE.
16353 Return the number of lines thus found (always nonnegative).
16355 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
16358 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
16359 int start
, start_byte
, limit_byte
, count
;
16362 register unsigned char *cursor
;
16363 unsigned char *base
;
16365 register int ceiling
;
16366 register unsigned char *ceiling_addr
;
16367 int orig_count
= count
;
16369 /* If we are not in selective display mode,
16370 check only for newlines. */
16371 int selective_display
= (!NILP (current_buffer
->selective_display
)
16372 && !INTEGERP (current_buffer
->selective_display
));
16376 while (start_byte
< limit_byte
)
16378 ceiling
= BUFFER_CEILING_OF (start_byte
);
16379 ceiling
= min (limit_byte
- 1, ceiling
);
16380 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
16381 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
16384 if (selective_display
)
16385 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
16388 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
16391 if (cursor
!= ceiling_addr
)
16395 start_byte
+= cursor
- base
+ 1;
16396 *byte_pos_ptr
= start_byte
;
16400 if (++cursor
== ceiling_addr
)
16406 start_byte
+= cursor
- base
;
16411 while (start_byte
> limit_byte
)
16413 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
16414 ceiling
= max (limit_byte
, ceiling
);
16415 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
16416 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
16419 if (selective_display
)
16420 while (--cursor
!= ceiling_addr
16421 && *cursor
!= '\n' && *cursor
!= 015)
16424 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
16427 if (cursor
!= ceiling_addr
)
16431 start_byte
+= cursor
- base
+ 1;
16432 *byte_pos_ptr
= start_byte
;
16433 /* When scanning backwards, we should
16434 not count the newline posterior to which we stop. */
16435 return - orig_count
- 1;
16441 /* Here we add 1 to compensate for the last decrement
16442 of CURSOR, which took it past the valid range. */
16443 start_byte
+= cursor
- base
+ 1;
16447 *byte_pos_ptr
= limit_byte
;
16450 return - orig_count
+ count
;
16451 return orig_count
- count
;
16457 /***********************************************************************
16459 ***********************************************************************/
16461 /* Display a NUL-terminated string, starting with index START.
16463 If STRING is non-null, display that C string. Otherwise, the Lisp
16464 string LISP_STRING is displayed.
16466 If FACE_STRING is not nil, FACE_STRING_POS is a position in
16467 FACE_STRING. Display STRING or LISP_STRING with the face at
16468 FACE_STRING_POS in FACE_STRING:
16470 Display the string in the environment given by IT, but use the
16471 standard display table, temporarily.
16473 FIELD_WIDTH is the minimum number of output glyphs to produce.
16474 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16475 with spaces. If STRING has more characters, more than FIELD_WIDTH
16476 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
16478 PRECISION is the maximum number of characters to output from
16479 STRING. PRECISION < 0 means don't truncate the string.
16481 This is roughly equivalent to printf format specifiers:
16483 FIELD_WIDTH PRECISION PRINTF
16484 ----------------------------------------
16490 MULTIBYTE zero means do not display multibyte chars, > 0 means do
16491 display them, and < 0 means obey the current buffer's value of
16492 enable_multibyte_characters.
16494 Value is the number of glyphs produced. */
16497 display_string (string
, lisp_string
, face_string
, face_string_pos
,
16498 start
, it
, field_width
, precision
, max_x
, multibyte
)
16499 unsigned char *string
;
16500 Lisp_Object lisp_string
;
16501 Lisp_Object face_string
;
16502 int face_string_pos
;
16505 int field_width
, precision
, max_x
;
16508 int hpos_at_start
= it
->hpos
;
16509 int saved_face_id
= it
->face_id
;
16510 struct glyph_row
*row
= it
->glyph_row
;
16512 /* Initialize the iterator IT for iteration over STRING beginning
16513 with index START. */
16514 reseat_to_string (it
, string
, lisp_string
, start
,
16515 precision
, field_width
, multibyte
);
16517 /* If displaying STRING, set up the face of the iterator
16518 from LISP_STRING, if that's given. */
16519 if (STRINGP (face_string
))
16525 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
16526 0, it
->region_beg_charpos
,
16527 it
->region_end_charpos
,
16528 &endptr
, it
->base_face_id
, 0);
16529 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16530 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
16533 /* Set max_x to the maximum allowed X position. Don't let it go
16534 beyond the right edge of the window. */
16536 max_x
= it
->last_visible_x
;
16538 max_x
= min (max_x
, it
->last_visible_x
);
16540 /* Skip over display elements that are not visible. because IT->w is
16542 if (it
->current_x
< it
->first_visible_x
)
16543 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
16544 MOVE_TO_POS
| MOVE_TO_X
);
16546 row
->ascent
= it
->max_ascent
;
16547 row
->height
= it
->max_ascent
+ it
->max_descent
;
16548 row
->phys_ascent
= it
->max_phys_ascent
;
16549 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16551 /* This condition is for the case that we are called with current_x
16552 past last_visible_x. */
16553 while (it
->current_x
< max_x
)
16555 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
16557 /* Get the next display element. */
16558 if (!get_next_display_element (it
))
16561 /* Produce glyphs. */
16562 x_before
= it
->current_x
;
16563 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16564 PRODUCE_GLYPHS (it
);
16566 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
16569 while (i
< nglyphs
)
16571 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16573 if (!it
->truncate_lines_p
16574 && x
+ glyph
->pixel_width
> max_x
)
16576 /* End of continued line or max_x reached. */
16577 if (CHAR_GLYPH_PADDING_P (*glyph
))
16579 /* A wide character is unbreakable. */
16580 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16581 it
->current_x
= x_before
;
16585 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16590 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
16592 /* Glyph is at least partially visible. */
16594 if (x
< it
->first_visible_x
)
16595 it
->glyph_row
->x
= x
- it
->first_visible_x
;
16599 /* Glyph is off the left margin of the display area.
16600 Should not happen. */
16604 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16605 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16606 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16607 row
->phys_height
= max (row
->phys_height
,
16608 it
->max_phys_ascent
+ it
->max_phys_descent
);
16609 x
+= glyph
->pixel_width
;
16613 /* Stop if max_x reached. */
16617 /* Stop at line ends. */
16618 if (ITERATOR_AT_END_OF_LINE_P (it
))
16620 it
->continuation_lines_width
= 0;
16624 set_iterator_to_next (it
, 1);
16626 /* Stop if truncating at the right edge. */
16627 if (it
->truncate_lines_p
16628 && it
->current_x
>= it
->last_visible_x
)
16630 /* Add truncation mark, but don't do it if the line is
16631 truncated at a padding space. */
16632 if (IT_CHARPOS (*it
) < it
->string_nchars
)
16634 if (!FRAME_WINDOW_P (it
->f
))
16638 if (it
->current_x
> it
->last_visible_x
)
16640 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16641 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16643 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16645 row
->used
[TEXT_AREA
] = i
;
16646 produce_special_glyphs (it
, IT_TRUNCATION
);
16649 produce_special_glyphs (it
, IT_TRUNCATION
);
16651 it
->glyph_row
->truncated_on_right_p
= 1;
16657 /* Maybe insert a truncation at the left. */
16658 if (it
->first_visible_x
16659 && IT_CHARPOS (*it
) > 0)
16661 if (!FRAME_WINDOW_P (it
->f
))
16662 insert_left_trunc_glyphs (it
);
16663 it
->glyph_row
->truncated_on_left_p
= 1;
16666 it
->face_id
= saved_face_id
;
16668 /* Value is number of columns displayed. */
16669 return it
->hpos
- hpos_at_start
;
16674 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
16675 appears as an element of LIST or as the car of an element of LIST.
16676 If PROPVAL is a list, compare each element against LIST in that
16677 way, and return 1/2 if any element of PROPVAL is found in LIST.
16678 Otherwise return 0. This function cannot quit.
16679 The return value is 2 if the text is invisible but with an ellipsis
16680 and 1 if it's invisible and without an ellipsis. */
16683 invisible_p (propval
, list
)
16684 register Lisp_Object propval
;
16687 register Lisp_Object tail
, proptail
;
16689 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
16691 register Lisp_Object tem
;
16693 if (EQ (propval
, tem
))
16695 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
16696 return NILP (XCDR (tem
)) ? 1 : 2;
16699 if (CONSP (propval
))
16701 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
16703 Lisp_Object propelt
;
16704 propelt
= XCAR (proptail
);
16705 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
16707 register Lisp_Object tem
;
16709 if (EQ (propelt
, tem
))
16711 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
16712 return NILP (XCDR (tem
)) ? 1 : 2;
16720 /* Calculate a width or height in pixels from a specification using
16721 the following elements:
16724 NUM - a (fractional) multiple of the default font width/height
16725 (NUM) - specifies exactly NUM pixels
16726 UNIT - a fixed number of pixels, see below.
16727 ELEMENT - size of a display element in pixels, see below.
16728 (NUM . SPEC) - equals NUM * SPEC
16729 (+ SPEC SPEC ...) - add pixel values
16730 (- SPEC SPEC ...) - subtract pixel values
16731 (- SPEC) - negate pixel value
16734 INT or FLOAT - a number constant
16735 SYMBOL - use symbol's (buffer local) variable binding.
16738 in - pixels per inch *)
16739 mm - pixels per 1/1000 meter *)
16740 cm - pixels per 1/100 meter *)
16741 width - width of current font in pixels.
16742 height - height of current font in pixels.
16744 *) using the ratio(s) defined in display-pixels-per-inch.
16748 left-fringe - left fringe width in pixels
16749 right-fringe - right fringe width in pixels
16751 left-margin - left margin width in pixels
16752 right-margin - right margin width in pixels
16754 scroll-bar - scroll-bar area width in pixels
16758 Pixels corresponding to 5 inches:
16761 Total width of non-text areas on left side of window (if scroll-bar is on left):
16762 '(space :width (+ left-fringe left-margin scroll-bar))
16764 Align to first text column (in header line):
16765 '(space :align-to 0)
16767 Align to middle of text area minus half the width of variable `my-image'
16768 containing a loaded image:
16769 '(space :align-to (0.5 . (- text my-image)))
16771 Width of left margin minus width of 1 character in the default font:
16772 '(space :width (- left-margin 1))
16774 Width of left margin minus width of 2 characters in the current font:
16775 '(space :width (- left-margin (2 . width)))
16777 Center 1 character over left-margin (in header line):
16778 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
16780 Different ways to express width of left fringe plus left margin minus one pixel:
16781 '(space :width (- (+ left-fringe left-margin) (1)))
16782 '(space :width (+ left-fringe left-margin (- (1))))
16783 '(space :width (+ left-fringe left-margin (-1)))
16787 #define NUMVAL(X) \
16788 ((INTEGERP (X) || FLOATP (X)) \
16793 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
16798 int width_p
, *align_to
;
16802 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
16803 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
16806 return OK_PIXELS (0);
16808 if (SYMBOLP (prop
))
16810 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
16812 char *unit
= SDATA (SYMBOL_NAME (prop
));
16814 if (unit
[0] == 'i' && unit
[1] == 'n')
16816 else if (unit
[0] == 'm' && unit
[1] == 'm')
16818 else if (unit
[0] == 'c' && unit
[1] == 'm')
16825 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
16826 || (CONSP (Vdisplay_pixels_per_inch
)
16828 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
16829 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
16831 return OK_PIXELS (ppi
/ pixels
);
16837 #ifdef HAVE_WINDOW_SYSTEM
16838 if (EQ (prop
, Qheight
))
16839 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
16840 if (EQ (prop
, Qwidth
))
16841 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
16843 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
16844 return OK_PIXELS (1);
16847 if (EQ (prop
, Qtext
))
16848 return OK_PIXELS (width_p
16849 ? window_box_width (it
->w
, TEXT_AREA
)
16850 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
16852 if (align_to
&& *align_to
< 0)
16855 if (EQ (prop
, Qleft
))
16856 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
16857 if (EQ (prop
, Qright
))
16858 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
16859 if (EQ (prop
, Qcenter
))
16860 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
16861 + window_box_width (it
->w
, TEXT_AREA
) / 2);
16862 if (EQ (prop
, Qleft_fringe
))
16863 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
16864 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
16865 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
16866 if (EQ (prop
, Qright_fringe
))
16867 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
16868 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
16869 : window_box_right_offset (it
->w
, TEXT_AREA
));
16870 if (EQ (prop
, Qleft_margin
))
16871 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
16872 if (EQ (prop
, Qright_margin
))
16873 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
16874 if (EQ (prop
, Qscroll_bar
))
16875 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
16877 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
16878 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
16879 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
16884 if (EQ (prop
, Qleft_fringe
))
16885 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
16886 if (EQ (prop
, Qright_fringe
))
16887 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
16888 if (EQ (prop
, Qleft_margin
))
16889 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
16890 if (EQ (prop
, Qright_margin
))
16891 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
16892 if (EQ (prop
, Qscroll_bar
))
16893 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
16896 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
16899 if (INTEGERP (prop
) || FLOATP (prop
))
16901 int base_unit
= (width_p
16902 ? FRAME_COLUMN_WIDTH (it
->f
)
16903 : FRAME_LINE_HEIGHT (it
->f
));
16904 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
16909 Lisp_Object car
= XCAR (prop
);
16910 Lisp_Object cdr
= XCDR (prop
);
16914 #ifdef HAVE_WINDOW_SYSTEM
16915 if (valid_image_p (prop
))
16917 int id
= lookup_image (it
->f
, prop
);
16918 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
16920 return OK_PIXELS (width_p
? img
->width
: img
->height
);
16923 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
16929 while (CONSP (cdr
))
16931 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
16932 font
, width_p
, align_to
))
16935 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
16940 if (EQ (car
, Qminus
))
16942 return OK_PIXELS (pixels
);
16945 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
16948 if (INTEGERP (car
) || FLOATP (car
))
16951 pixels
= XFLOATINT (car
);
16953 return OK_PIXELS (pixels
);
16954 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
16955 font
, width_p
, align_to
))
16956 return OK_PIXELS (pixels
* fact
);
16967 /***********************************************************************
16969 ***********************************************************************/
16971 #ifdef HAVE_WINDOW_SYSTEM
16976 dump_glyph_string (s
)
16977 struct glyph_string
*s
;
16979 fprintf (stderr
, "glyph string\n");
16980 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
16981 s
->x
, s
->y
, s
->width
, s
->height
);
16982 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
16983 fprintf (stderr
, " hl = %d\n", s
->hl
);
16984 fprintf (stderr
, " left overhang = %d, right = %d\n",
16985 s
->left_overhang
, s
->right_overhang
);
16986 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
16987 fprintf (stderr
, " extends to end of line = %d\n",
16988 s
->extends_to_end_of_line_p
);
16989 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
16990 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
16993 #endif /* GLYPH_DEBUG */
16995 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
16996 of XChar2b structures for S; it can't be allocated in
16997 init_glyph_string because it must be allocated via `alloca'. W
16998 is the window on which S is drawn. ROW and AREA are the glyph row
16999 and area within the row from which S is constructed. START is the
17000 index of the first glyph structure covered by S. HL is a
17001 face-override for drawing S. */
17004 #define OPTIONAL_HDC(hdc) hdc,
17005 #define DECLARE_HDC(hdc) HDC hdc;
17006 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
17007 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
17010 #ifndef OPTIONAL_HDC
17011 #define OPTIONAL_HDC(hdc)
17012 #define DECLARE_HDC(hdc)
17013 #define ALLOCATE_HDC(hdc, f)
17014 #define RELEASE_HDC(hdc, f)
17018 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
17019 struct glyph_string
*s
;
17023 struct glyph_row
*row
;
17024 enum glyph_row_area area
;
17026 enum draw_glyphs_face hl
;
17028 bzero (s
, sizeof *s
);
17030 s
->f
= XFRAME (w
->frame
);
17034 s
->display
= FRAME_X_DISPLAY (s
->f
);
17035 s
->window
= FRAME_X_WINDOW (s
->f
);
17036 s
->char2b
= char2b
;
17040 s
->first_glyph
= row
->glyphs
[area
] + start
;
17041 s
->height
= row
->height
;
17042 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
17044 /* Display the internal border below the tool-bar window. */
17045 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
17046 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
17048 s
->ybase
= s
->y
+ row
->ascent
;
17052 /* Append the list of glyph strings with head H and tail T to the list
17053 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
17056 append_glyph_string_lists (head
, tail
, h
, t
)
17057 struct glyph_string
**head
, **tail
;
17058 struct glyph_string
*h
, *t
;
17072 /* Prepend the list of glyph strings with head H and tail T to the
17073 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
17077 prepend_glyph_string_lists (head
, tail
, h
, t
)
17078 struct glyph_string
**head
, **tail
;
17079 struct glyph_string
*h
, *t
;
17093 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
17094 Set *HEAD and *TAIL to the resulting list. */
17097 append_glyph_string (head
, tail
, s
)
17098 struct glyph_string
**head
, **tail
;
17099 struct glyph_string
*s
;
17101 s
->next
= s
->prev
= NULL
;
17102 append_glyph_string_lists (head
, tail
, s
, s
);
17106 /* Get face and two-byte form of character glyph GLYPH on frame F.
17107 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
17108 a pointer to a realized face that is ready for display. */
17110 static INLINE
struct face
*
17111 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
17113 struct glyph
*glyph
;
17119 xassert (glyph
->type
== CHAR_GLYPH
);
17120 face
= FACE_FROM_ID (f
, glyph
->face_id
);
17125 if (!glyph
->multibyte_p
)
17127 /* Unibyte case. We don't have to encode, but we have to make
17128 sure to use a face suitable for unibyte. */
17129 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17131 else if (glyph
->u
.ch
< 128
17132 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
17134 /* Case of ASCII in a face known to fit ASCII. */
17135 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17139 int c1
, c2
, charset
;
17141 /* Split characters into bytes. If c2 is -1 afterwards, C is
17142 really a one-byte character so that byte1 is zero. */
17143 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
17145 STORE_XCHAR2B (char2b
, c1
, c2
);
17147 STORE_XCHAR2B (char2b
, 0, c1
);
17149 /* Maybe encode the character in *CHAR2B. */
17150 if (charset
!= CHARSET_ASCII
)
17152 struct font_info
*font_info
17153 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17156 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
17160 /* Make sure X resources of the face are allocated. */
17161 xassert (face
!= NULL
);
17162 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17167 /* Fill glyph string S with composition components specified by S->cmp.
17169 FACES is an array of faces for all components of this composition.
17170 S->gidx is the index of the first component for S.
17171 OVERLAPS_P non-zero means S should draw the foreground only, and
17172 use its physical height for clipping.
17174 Value is the index of a component not in S. */
17177 fill_composite_glyph_string (s
, faces
, overlaps_p
)
17178 struct glyph_string
*s
;
17179 struct face
**faces
;
17186 s
->for_overlaps_p
= overlaps_p
;
17188 s
->face
= faces
[s
->gidx
];
17189 s
->font
= s
->face
->font
;
17190 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17192 /* For all glyphs of this composition, starting at the offset
17193 S->gidx, until we reach the end of the definition or encounter a
17194 glyph that requires the different face, add it to S. */
17196 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
17199 /* All glyph strings for the same composition has the same width,
17200 i.e. the width set for the first component of the composition. */
17202 s
->width
= s
->first_glyph
->pixel_width
;
17204 /* If the specified font could not be loaded, use the frame's
17205 default font, but record the fact that we couldn't load it in
17206 the glyph string so that we can draw rectangles for the
17207 characters of the glyph string. */
17208 if (s
->font
== NULL
)
17210 s
->font_not_found_p
= 1;
17211 s
->font
= FRAME_FONT (s
->f
);
17214 /* Adjust base line for subscript/superscript text. */
17215 s
->ybase
+= s
->first_glyph
->voffset
;
17217 xassert (s
->face
&& s
->face
->gc
);
17219 /* This glyph string must always be drawn with 16-bit functions. */
17222 return s
->gidx
+ s
->nchars
;
17226 /* Fill glyph string S from a sequence of character glyphs.
17228 FACE_ID is the face id of the string. START is the index of the
17229 first glyph to consider, END is the index of the last + 1.
17230 OVERLAPS_P non-zero means S should draw the foreground only, and
17231 use its physical height for clipping.
17233 Value is the index of the first glyph not in S. */
17236 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
17237 struct glyph_string
*s
;
17239 int start
, end
, overlaps_p
;
17241 struct glyph
*glyph
, *last
;
17243 int glyph_not_available_p
;
17245 xassert (s
->f
== XFRAME (s
->w
->frame
));
17246 xassert (s
->nchars
== 0);
17247 xassert (start
>= 0 && end
> start
);
17249 s
->for_overlaps_p
= overlaps_p
,
17250 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17251 last
= s
->row
->glyphs
[s
->area
] + end
;
17252 voffset
= glyph
->voffset
;
17254 glyph_not_available_p
= glyph
->glyph_not_available_p
;
17256 while (glyph
< last
17257 && glyph
->type
== CHAR_GLYPH
17258 && glyph
->voffset
== voffset
17259 /* Same face id implies same font, nowadays. */
17260 && glyph
->face_id
== face_id
17261 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
17265 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
17266 s
->char2b
+ s
->nchars
,
17268 s
->two_byte_p
= two_byte_p
;
17270 xassert (s
->nchars
<= end
- start
);
17271 s
->width
+= glyph
->pixel_width
;
17275 s
->font
= s
->face
->font
;
17276 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17278 /* If the specified font could not be loaded, use the frame's font,
17279 but record the fact that we couldn't load it in
17280 S->font_not_found_p so that we can draw rectangles for the
17281 characters of the glyph string. */
17282 if (s
->font
== NULL
|| glyph_not_available_p
)
17284 s
->font_not_found_p
= 1;
17285 s
->font
= FRAME_FONT (s
->f
);
17288 /* Adjust base line for subscript/superscript text. */
17289 s
->ybase
+= voffset
;
17291 xassert (s
->face
&& s
->face
->gc
);
17292 return glyph
- s
->row
->glyphs
[s
->area
];
17296 /* Fill glyph string S from image glyph S->first_glyph. */
17299 fill_image_glyph_string (s
)
17300 struct glyph_string
*s
;
17302 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
17303 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
17305 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
17306 s
->font
= s
->face
->font
;
17307 s
->width
= s
->first_glyph
->pixel_width
;
17309 /* Adjust base line for subscript/superscript text. */
17310 s
->ybase
+= s
->first_glyph
->voffset
;
17314 /* Fill glyph string S from a sequence of stretch glyphs.
17316 ROW is the glyph row in which the glyphs are found, AREA is the
17317 area within the row. START is the index of the first glyph to
17318 consider, END is the index of the last + 1.
17320 Value is the index of the first glyph not in S. */
17323 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
17324 struct glyph_string
*s
;
17325 struct glyph_row
*row
;
17326 enum glyph_row_area area
;
17329 struct glyph
*glyph
, *last
;
17330 int voffset
, face_id
;
17332 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
17334 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17335 last
= s
->row
->glyphs
[s
->area
] + end
;
17336 face_id
= glyph
->face_id
;
17337 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
17338 s
->font
= s
->face
->font
;
17339 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17340 s
->width
= glyph
->pixel_width
;
17341 voffset
= glyph
->voffset
;
17345 && glyph
->type
== STRETCH_GLYPH
17346 && glyph
->voffset
== voffset
17347 && glyph
->face_id
== face_id
);
17349 s
->width
+= glyph
->pixel_width
;
17351 /* Adjust base line for subscript/superscript text. */
17352 s
->ybase
+= voffset
;
17354 /* The case that face->gc == 0 is handled when drawing the glyph
17355 string by calling PREPARE_FACE_FOR_DISPLAY. */
17357 return glyph
- s
->row
->glyphs
[s
->area
];
17362 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
17363 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
17364 assumed to be zero. */
17367 x_get_glyph_overhangs (glyph
, f
, left
, right
)
17368 struct glyph
*glyph
;
17372 *left
= *right
= 0;
17374 if (glyph
->type
== CHAR_GLYPH
)
17378 struct font_info
*font_info
;
17382 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
17384 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17385 if (font
/* ++KFS: Should this be font_info ? */
17386 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
17388 if (pcm
->rbearing
> pcm
->width
)
17389 *right
= pcm
->rbearing
- pcm
->width
;
17390 if (pcm
->lbearing
< 0)
17391 *left
= -pcm
->lbearing
;
17397 /* Return the index of the first glyph preceding glyph string S that
17398 is overwritten by S because of S's left overhang. Value is -1
17399 if no glyphs are overwritten. */
17402 left_overwritten (s
)
17403 struct glyph_string
*s
;
17407 if (s
->left_overhang
)
17410 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17411 int first
= s
->first_glyph
- glyphs
;
17413 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
17414 x
-= glyphs
[i
].pixel_width
;
17425 /* Return the index of the first glyph preceding glyph string S that
17426 is overwriting S because of its right overhang. Value is -1 if no
17427 glyph in front of S overwrites S. */
17430 left_overwriting (s
)
17431 struct glyph_string
*s
;
17434 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17435 int first
= s
->first_glyph
- glyphs
;
17439 for (i
= first
- 1; i
>= 0; --i
)
17442 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17445 x
-= glyphs
[i
].pixel_width
;
17452 /* Return the index of the last glyph following glyph string S that is
17453 not overwritten by S because of S's right overhang. Value is -1 if
17454 no such glyph is found. */
17457 right_overwritten (s
)
17458 struct glyph_string
*s
;
17462 if (s
->right_overhang
)
17465 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17466 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17467 int end
= s
->row
->used
[s
->area
];
17469 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
17470 x
+= glyphs
[i
].pixel_width
;
17479 /* Return the index of the last glyph following glyph string S that
17480 overwrites S because of its left overhang. Value is negative
17481 if no such glyph is found. */
17484 right_overwriting (s
)
17485 struct glyph_string
*s
;
17488 int end
= s
->row
->used
[s
->area
];
17489 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17490 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17494 for (i
= first
; i
< end
; ++i
)
17497 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17500 x
+= glyphs
[i
].pixel_width
;
17507 /* Get face and two-byte form of character C in face FACE_ID on frame
17508 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
17509 means we want to display multibyte text. DISPLAY_P non-zero means
17510 make sure that X resources for the face returned are allocated.
17511 Value is a pointer to a realized face that is ready for display if
17512 DISPLAY_P is non-zero. */
17514 static INLINE
struct face
*
17515 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
17519 int multibyte_p
, display_p
;
17521 struct face
*face
= FACE_FROM_ID (f
, face_id
);
17525 /* Unibyte case. We don't have to encode, but we have to make
17526 sure to use a face suitable for unibyte. */
17527 STORE_XCHAR2B (char2b
, 0, c
);
17528 face_id
= FACE_FOR_CHAR (f
, face
, c
);
17529 face
= FACE_FROM_ID (f
, face_id
);
17531 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
17533 /* Case of ASCII in a face known to fit ASCII. */
17534 STORE_XCHAR2B (char2b
, 0, c
);
17538 int c1
, c2
, charset
;
17540 /* Split characters into bytes. If c2 is -1 afterwards, C is
17541 really a one-byte character so that byte1 is zero. */
17542 SPLIT_CHAR (c
, charset
, c1
, c2
);
17544 STORE_XCHAR2B (char2b
, c1
, c2
);
17546 STORE_XCHAR2B (char2b
, 0, c1
);
17548 /* Maybe encode the character in *CHAR2B. */
17549 if (face
->font
!= NULL
)
17551 struct font_info
*font_info
17552 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17554 rif
->encode_char (c
, char2b
, font_info
, 0);
17558 /* Make sure X resources of the face are allocated. */
17559 #ifdef HAVE_X_WINDOWS
17563 xassert (face
!= NULL
);
17564 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17571 /* Set background width of glyph string S. START is the index of the
17572 first glyph following S. LAST_X is the right-most x-position + 1
17573 in the drawing area. */
17576 set_glyph_string_background_width (s
, start
, last_x
)
17577 struct glyph_string
*s
;
17581 /* If the face of this glyph string has to be drawn to the end of
17582 the drawing area, set S->extends_to_end_of_line_p. */
17583 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
17585 if (start
== s
->row
->used
[s
->area
]
17586 && s
->area
== TEXT_AREA
17587 && ((s
->hl
== DRAW_NORMAL_TEXT
17588 && (s
->row
->fill_line_p
17589 || s
->face
->background
!= default_face
->background
17590 || s
->face
->stipple
!= default_face
->stipple
17591 || s
->row
->mouse_face_p
))
17592 || s
->hl
== DRAW_MOUSE_FACE
17593 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
17594 && s
->row
->fill_line_p
)))
17595 s
->extends_to_end_of_line_p
= 1;
17597 /* If S extends its face to the end of the line, set its
17598 background_width to the distance to the right edge of the drawing
17600 if (s
->extends_to_end_of_line_p
)
17601 s
->background_width
= last_x
- s
->x
+ 1;
17603 s
->background_width
= s
->width
;
17607 /* Compute overhangs and x-positions for glyph string S and its
17608 predecessors, or successors. X is the starting x-position for S.
17609 BACKWARD_P non-zero means process predecessors. */
17612 compute_overhangs_and_x (s
, x
, backward_p
)
17613 struct glyph_string
*s
;
17621 if (rif
->compute_glyph_string_overhangs
)
17622 rif
->compute_glyph_string_overhangs (s
);
17632 if (rif
->compute_glyph_string_overhangs
)
17633 rif
->compute_glyph_string_overhangs (s
);
17643 /* The following macros are only called from draw_glyphs below.
17644 They reference the following parameters of that function directly:
17645 `w', `row', `area', and `overlap_p'
17646 as well as the following local variables:
17647 `s', `f', and `hdc' (in W32) */
17650 /* On W32, silently add local `hdc' variable to argument list of
17651 init_glyph_string. */
17652 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17653 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
17655 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17656 init_glyph_string (s, char2b, w, row, area, start, hl)
17659 /* Add a glyph string for a stretch glyph to the list of strings
17660 between HEAD and TAIL. START is the index of the stretch glyph in
17661 row area AREA of glyph row ROW. END is the index of the last glyph
17662 in that glyph row area. X is the current output position assigned
17663 to the new glyph string constructed. HL overrides that face of the
17664 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17665 is the right-most x-position of the drawing area. */
17667 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
17668 and below -- keep them on one line. */
17669 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17672 s = (struct glyph_string *) alloca (sizeof *s); \
17673 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17674 START = fill_stretch_glyph_string (s, row, area, START, END); \
17675 append_glyph_string (&HEAD, &TAIL, s); \
17681 /* Add a glyph string for an image glyph to the list of strings
17682 between HEAD and TAIL. START is the index of the image glyph in
17683 row area AREA of glyph row ROW. END is the index of the last glyph
17684 in that glyph row area. X is the current output position assigned
17685 to the new glyph string constructed. HL overrides that face of the
17686 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17687 is the right-most x-position of the drawing area. */
17689 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17692 s = (struct glyph_string *) alloca (sizeof *s); \
17693 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17694 fill_image_glyph_string (s); \
17695 append_glyph_string (&HEAD, &TAIL, s); \
17702 /* Add a glyph string for a sequence of character glyphs to the list
17703 of strings between HEAD and TAIL. START is the index of the first
17704 glyph in row area AREA of glyph row ROW that is part of the new
17705 glyph string. END is the index of the last glyph in that glyph row
17706 area. X is the current output position assigned to the new glyph
17707 string constructed. HL overrides that face of the glyph; e.g. it
17708 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
17709 right-most x-position of the drawing area. */
17711 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
17717 c = (row)->glyphs[area][START].u.ch; \
17718 face_id = (row)->glyphs[area][START].face_id; \
17720 s = (struct glyph_string *) alloca (sizeof *s); \
17721 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
17722 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
17723 append_glyph_string (&HEAD, &TAIL, s); \
17725 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
17730 /* Add a glyph string for a composite sequence to the list of strings
17731 between HEAD and TAIL. START is the index of the first glyph in
17732 row area AREA of glyph row ROW that is part of the new glyph
17733 string. END is the index of the last glyph in that glyph row area.
17734 X is the current output position assigned to the new glyph string
17735 constructed. HL overrides that face of the glyph; e.g. it is
17736 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
17737 x-position of the drawing area. */
17739 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17741 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
17742 int face_id = (row)->glyphs[area][START].face_id; \
17743 struct face *base_face = FACE_FROM_ID (f, face_id); \
17744 struct composition *cmp = composition_table[cmp_id]; \
17745 int glyph_len = cmp->glyph_len; \
17747 struct face **faces; \
17748 struct glyph_string *first_s = NULL; \
17751 base_face = base_face->ascii_face; \
17752 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
17753 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
17754 /* At first, fill in `char2b' and `faces'. */ \
17755 for (n = 0; n < glyph_len; n++) \
17757 int c = COMPOSITION_GLYPH (cmp, n); \
17758 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
17759 faces[n] = FACE_FROM_ID (f, this_face_id); \
17760 get_char_face_and_encoding (f, c, this_face_id, \
17761 char2b + n, 1, 1); \
17764 /* Make glyph_strings for each glyph sequence that is drawable by \
17765 the same face, and append them to HEAD/TAIL. */ \
17766 for (n = 0; n < cmp->glyph_len;) \
17768 s = (struct glyph_string *) alloca (sizeof *s); \
17769 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
17770 append_glyph_string (&(HEAD), &(TAIL), s); \
17778 n = fill_composite_glyph_string (s, faces, overlaps_p); \
17786 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
17787 of AREA of glyph row ROW on window W between indices START and END.
17788 HL overrides the face for drawing glyph strings, e.g. it is
17789 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
17790 x-positions of the drawing area.
17792 This is an ugly monster macro construct because we must use alloca
17793 to allocate glyph strings (because draw_glyphs can be called
17794 asynchronously). */
17796 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
17799 HEAD = TAIL = NULL; \
17800 while (START < END) \
17802 struct glyph *first_glyph = (row)->glyphs[area] + START; \
17803 switch (first_glyph->type) \
17806 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
17810 case COMPOSITE_GLYPH: \
17811 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
17815 case STRETCH_GLYPH: \
17816 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
17820 case IMAGE_GLYPH: \
17821 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
17829 set_glyph_string_background_width (s, START, LAST_X); \
17836 /* Draw glyphs between START and END in AREA of ROW on window W,
17837 starting at x-position X. X is relative to AREA in W. HL is a
17838 face-override with the following meaning:
17840 DRAW_NORMAL_TEXT draw normally
17841 DRAW_CURSOR draw in cursor face
17842 DRAW_MOUSE_FACE draw in mouse face.
17843 DRAW_INVERSE_VIDEO draw in mode line face
17844 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
17845 DRAW_IMAGE_RAISED draw an image with a raised relief around it
17847 If OVERLAPS_P is non-zero, draw only the foreground of characters
17848 and clip to the physical height of ROW.
17850 Value is the x-position reached, relative to AREA of W. */
17853 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
17856 struct glyph_row
*row
;
17857 enum glyph_row_area area
;
17859 enum draw_glyphs_face hl
;
17862 struct glyph_string
*head
, *tail
;
17863 struct glyph_string
*s
;
17864 int last_x
, area_width
;
17867 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17870 ALLOCATE_HDC (hdc
, f
);
17872 /* Let's rather be paranoid than getting a SEGV. */
17873 end
= min (end
, row
->used
[area
]);
17874 start
= max (0, start
);
17875 start
= min (end
, start
);
17877 /* Translate X to frame coordinates. Set last_x to the right
17878 end of the drawing area. */
17879 if (row
->full_width_p
)
17881 /* X is relative to the left edge of W, without scroll bars
17883 x
+= WINDOW_LEFT_EDGE_X (w
);
17884 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
17888 int area_left
= window_box_left (w
, area
);
17890 area_width
= window_box_width (w
, area
);
17891 last_x
= area_left
+ area_width
;
17894 /* Build a doubly-linked list of glyph_string structures between
17895 head and tail from what we have to draw. Note that the macro
17896 BUILD_GLYPH_STRINGS will modify its start parameter. That's
17897 the reason we use a separate variable `i'. */
17899 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
17901 x_reached
= tail
->x
+ tail
->background_width
;
17905 /* If there are any glyphs with lbearing < 0 or rbearing > width in
17906 the row, redraw some glyphs in front or following the glyph
17907 strings built above. */
17908 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
17911 struct glyph_string
*h
, *t
;
17913 /* Compute overhangs for all glyph strings. */
17914 if (rif
->compute_glyph_string_overhangs
)
17915 for (s
= head
; s
; s
= s
->next
)
17916 rif
->compute_glyph_string_overhangs (s
);
17918 /* Prepend glyph strings for glyphs in front of the first glyph
17919 string that are overwritten because of the first glyph
17920 string's left overhang. The background of all strings
17921 prepended must be drawn because the first glyph string
17923 i
= left_overwritten (head
);
17927 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
17928 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
17930 compute_overhangs_and_x (t
, head
->x
, 1);
17931 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
17934 /* Prepend glyph strings for glyphs in front of the first glyph
17935 string that overwrite that glyph string because of their
17936 right overhang. For these strings, only the foreground must
17937 be drawn, because it draws over the glyph string at `head'.
17938 The background must not be drawn because this would overwrite
17939 right overhangs of preceding glyphs for which no glyph
17941 i
= left_overwriting (head
);
17944 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
17945 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
17946 for (s
= h
; s
; s
= s
->next
)
17947 s
->background_filled_p
= 1;
17948 compute_overhangs_and_x (t
, head
->x
, 1);
17949 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
17952 /* Append glyphs strings for glyphs following the last glyph
17953 string tail that are overwritten by tail. The background of
17954 these strings has to be drawn because tail's foreground draws
17956 i
= right_overwritten (tail
);
17959 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
17960 DRAW_NORMAL_TEXT
, x
, last_x
);
17961 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
17962 append_glyph_string_lists (&head
, &tail
, h
, t
);
17965 /* Append glyph strings for glyphs following the last glyph
17966 string tail that overwrite tail. The foreground of such
17967 glyphs has to be drawn because it writes into the background
17968 of tail. The background must not be drawn because it could
17969 paint over the foreground of following glyphs. */
17970 i
= right_overwriting (tail
);
17973 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
17974 DRAW_NORMAL_TEXT
, x
, last_x
);
17975 for (s
= h
; s
; s
= s
->next
)
17976 s
->background_filled_p
= 1;
17977 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
17978 append_glyph_string_lists (&head
, &tail
, h
, t
);
17982 /* Draw all strings. */
17983 for (s
= head
; s
; s
= s
->next
)
17984 rif
->draw_glyph_string (s
);
17986 if (area
== TEXT_AREA
17987 && !row
->full_width_p
17988 /* When drawing overlapping rows, only the glyph strings'
17989 foreground is drawn, which doesn't erase a cursor
17993 int x0
= head
? head
->x
: x
;
17994 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
17996 int text_left
= window_box_left (w
, TEXT_AREA
);
18000 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
18001 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
18004 /* Value is the x-position up to which drawn, relative to AREA of W.
18005 This doesn't include parts drawn because of overhangs. */
18006 if (row
->full_width_p
)
18007 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
18009 x_reached
-= window_box_left (w
, area
);
18011 RELEASE_HDC (hdc
, f
);
18017 /* Store one glyph for IT->char_to_display in IT->glyph_row.
18018 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18024 struct glyph
*glyph
;
18025 enum glyph_row_area area
= it
->area
;
18027 xassert (it
->glyph_row
);
18028 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
18030 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18031 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18033 glyph
->charpos
= CHARPOS (it
->position
);
18034 glyph
->object
= it
->object
;
18035 glyph
->pixel_width
= it
->pixel_width
;
18036 glyph
->ascent
= it
->ascent
;
18037 glyph
->descent
= it
->descent
;
18038 glyph
->voffset
= it
->voffset
;
18039 glyph
->type
= CHAR_GLYPH
;
18040 glyph
->multibyte_p
= it
->multibyte_p
;
18041 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18042 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18043 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18044 || it
->phys_descent
> it
->descent
);
18045 glyph
->padding_p
= 0;
18046 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
18047 glyph
->face_id
= it
->face_id
;
18048 glyph
->u
.ch
= it
->char_to_display
;
18049 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18050 ++it
->glyph_row
->used
[area
];
18054 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
18055 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18058 append_composite_glyph (it
)
18061 struct glyph
*glyph
;
18062 enum glyph_row_area area
= it
->area
;
18064 xassert (it
->glyph_row
);
18066 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18067 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18069 glyph
->charpos
= CHARPOS (it
->position
);
18070 glyph
->object
= it
->object
;
18071 glyph
->pixel_width
= it
->pixel_width
;
18072 glyph
->ascent
= it
->ascent
;
18073 glyph
->descent
= it
->descent
;
18074 glyph
->voffset
= it
->voffset
;
18075 glyph
->type
= COMPOSITE_GLYPH
;
18076 glyph
->multibyte_p
= it
->multibyte_p
;
18077 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18078 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18079 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18080 || it
->phys_descent
> it
->descent
);
18081 glyph
->padding_p
= 0;
18082 glyph
->glyph_not_available_p
= 0;
18083 glyph
->face_id
= it
->face_id
;
18084 glyph
->u
.cmp_id
= it
->cmp_id
;
18085 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18086 ++it
->glyph_row
->used
[area
];
18091 /* Change IT->ascent and IT->height according to the setting of
18095 take_vertical_position_into_account (it
)
18100 if (it
->voffset
< 0)
18101 /* Increase the ascent so that we can display the text higher
18103 it
->ascent
+= abs (it
->voffset
);
18105 /* Increase the descent so that we can display the text lower
18107 it
->descent
+= it
->voffset
;
18112 /* Produce glyphs/get display metrics for the image IT is loaded with.
18113 See the description of struct display_iterator in dispextern.h for
18114 an overview of struct display_iterator. */
18117 produce_image_glyph (it
)
18122 int face_ascent
, glyph_ascent
;
18124 xassert (it
->what
== IT_IMAGE
);
18126 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18128 /* Make sure X resources of the face is loaded. */
18129 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18131 if (it
->image_id
< 0)
18133 /* Fringe bitmap. */
18134 it
->ascent
= it
->phys_ascent
= 0;
18135 it
->descent
= it
->phys_descent
= 0;
18136 it
->pixel_width
= 0;
18141 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
18143 /* Make sure X resources of the image is loaded. */
18144 prepare_image_for_display (it
->f
, img
);
18146 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
);
18147 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
18148 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
18150 /* It's quite possible for images to have an ascent greater than
18151 their height, so don't get confused in that case. */
18152 if (it
->descent
< 0)
18155 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
18156 face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
18157 if (face_ascent
> it
->ascent
)
18158 it
->ascent
= it
->phys_ascent
= face_ascent
;
18162 if (face
->box
!= FACE_NO_BOX
)
18164 if (face
->box_line_width
> 0)
18166 it
->ascent
+= face
->box_line_width
;
18167 it
->descent
+= face
->box_line_width
;
18170 if (it
->start_of_box_run_p
)
18171 it
->pixel_width
+= abs (face
->box_line_width
);
18172 if (it
->end_of_box_run_p
)
18173 it
->pixel_width
+= abs (face
->box_line_width
);
18176 take_vertical_position_into_account (it
);
18180 struct glyph
*glyph
;
18181 enum glyph_row_area area
= it
->area
;
18183 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18184 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18186 glyph
->charpos
= CHARPOS (it
->position
);
18187 glyph
->object
= it
->object
;
18188 glyph
->pixel_width
= it
->pixel_width
;
18189 glyph
->ascent
= glyph_ascent
;
18190 glyph
->descent
= it
->descent
;
18191 glyph
->voffset
= it
->voffset
;
18192 glyph
->type
= IMAGE_GLYPH
;
18193 glyph
->multibyte_p
= it
->multibyte_p
;
18194 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18195 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18196 glyph
->overlaps_vertically_p
= 0;
18197 glyph
->padding_p
= 0;
18198 glyph
->glyph_not_available_p
= 0;
18199 glyph
->face_id
= it
->face_id
;
18200 glyph
->u
.img_id
= img
->id
;
18201 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18202 ++it
->glyph_row
->used
[area
];
18208 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
18209 of the glyph, WIDTH and HEIGHT are the width and height of the
18210 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
18213 append_stretch_glyph (it
, object
, width
, height
, ascent
)
18215 Lisp_Object object
;
18219 struct glyph
*glyph
;
18220 enum glyph_row_area area
= it
->area
;
18222 xassert (ascent
>= 0 && ascent
<= height
);
18224 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18225 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18227 glyph
->charpos
= CHARPOS (it
->position
);
18228 glyph
->object
= object
;
18229 glyph
->pixel_width
= width
;
18230 glyph
->ascent
= ascent
;
18231 glyph
->descent
= height
- ascent
;
18232 glyph
->voffset
= it
->voffset
;
18233 glyph
->type
= STRETCH_GLYPH
;
18234 glyph
->multibyte_p
= it
->multibyte_p
;
18235 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18236 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18237 glyph
->overlaps_vertically_p
= 0;
18238 glyph
->padding_p
= 0;
18239 glyph
->glyph_not_available_p
= 0;
18240 glyph
->face_id
= it
->face_id
;
18241 glyph
->u
.stretch
.ascent
= ascent
;
18242 glyph
->u
.stretch
.height
= height
;
18243 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18244 ++it
->glyph_row
->used
[area
];
18249 /* Produce a stretch glyph for iterator IT. IT->object is the value
18250 of the glyph property displayed. The value must be a list
18251 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
18254 1. `:width WIDTH' specifies that the space should be WIDTH *
18255 canonical char width wide. WIDTH may be an integer or floating
18258 2. `:relative-width FACTOR' specifies that the width of the stretch
18259 should be computed from the width of the first character having the
18260 `glyph' property, and should be FACTOR times that width.
18262 3. `:align-to HPOS' specifies that the space should be wide enough
18263 to reach HPOS, a value in canonical character units.
18265 Exactly one of the above pairs must be present.
18267 4. `:height HEIGHT' specifies that the height of the stretch produced
18268 should be HEIGHT, measured in canonical character units.
18270 5. `:relative-height FACTOR' specifies that the height of the
18271 stretch should be FACTOR times the height of the characters having
18272 the glyph property.
18274 Either none or exactly one of 4 or 5 must be present.
18276 6. `:ascent ASCENT' specifies that ASCENT percent of the height
18277 of the stretch should be used for the ascent of the stretch.
18278 ASCENT must be in the range 0 <= ASCENT <= 100. */
18281 produce_stretch_glyph (it
)
18284 /* (space :width WIDTH :height HEIGHT ...) */
18285 Lisp_Object prop
, plist
;
18286 int width
= 0, height
= 0, align_to
= -1;
18287 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
18290 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18291 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
18293 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18295 /* List should start with `space'. */
18296 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
18297 plist
= XCDR (it
->object
);
18299 /* Compute the width of the stretch. */
18300 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
18301 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
18303 /* Absolute width `:width WIDTH' specified and valid. */
18304 zero_width_ok_p
= 1;
18307 else if (prop
= Fplist_get (plist
, QCrelative_width
),
18310 /* Relative width `:relative-width FACTOR' specified and valid.
18311 Compute the width of the characters having the `glyph'
18314 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
18317 if (it
->multibyte_p
)
18319 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
18320 - IT_BYTEPOS (*it
));
18321 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
18324 it2
.c
= *p
, it2
.len
= 1;
18326 it2
.glyph_row
= NULL
;
18327 it2
.what
= IT_CHARACTER
;
18328 x_produce_glyphs (&it2
);
18329 width
= NUMVAL (prop
) * it2
.pixel_width
;
18331 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
18332 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
18334 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
18335 align_to
= (align_to
< 0
18337 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
18338 else if (align_to
< 0)
18339 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
18340 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
18341 zero_width_ok_p
= 1;
18344 /* Nothing specified -> width defaults to canonical char width. */
18345 width
= FRAME_COLUMN_WIDTH (it
->f
);
18347 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
18350 /* Compute height. */
18351 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
18352 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
18355 zero_height_ok_p
= 1;
18357 else if (prop
= Fplist_get (plist
, QCrelative_height
),
18359 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
18361 height
= FONT_HEIGHT (font
);
18363 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
18366 /* Compute percentage of height used for ascent. If
18367 `:ascent ASCENT' is present and valid, use that. Otherwise,
18368 derive the ascent from the font in use. */
18369 if (prop
= Fplist_get (plist
, QCascent
),
18370 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
18371 ascent
= height
* NUMVAL (prop
) / 100.0;
18372 else if (!NILP (prop
)
18373 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
18374 ascent
= min (max (0, (int)tem
), height
);
18376 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
18378 if (width
> 0 && height
> 0 && it
->glyph_row
)
18380 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
18381 if (!STRINGP (object
))
18382 object
= it
->w
->buffer
;
18383 append_stretch_glyph (it
, object
, width
, height
, ascent
);
18386 it
->pixel_width
= width
;
18387 it
->ascent
= it
->phys_ascent
= ascent
;
18388 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
18389 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
18391 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
18393 if (face
->box_line_width
> 0)
18395 it
->ascent
+= face
->box_line_width
;
18396 it
->descent
+= face
->box_line_width
;
18399 if (it
->start_of_box_run_p
)
18400 it
->pixel_width
+= abs (face
->box_line_width
);
18401 if (it
->end_of_box_run_p
)
18402 it
->pixel_width
+= abs (face
->box_line_width
);
18405 take_vertical_position_into_account (it
);
18409 Produce glyphs/get display metrics for the display element IT is
18410 loaded with. See the description of struct display_iterator in
18411 dispextern.h for an overview of struct display_iterator. */
18414 x_produce_glyphs (it
)
18417 it
->glyph_not_available_p
= 0;
18419 if (it
->what
== IT_CHARACTER
)
18423 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18425 int font_not_found_p
;
18426 struct font_info
*font_info
;
18427 int boff
; /* baseline offset */
18428 /* We may change it->multibyte_p upon unibyte<->multibyte
18429 conversion. So, save the current value now and restore it
18432 Note: It seems that we don't have to record multibyte_p in
18433 struct glyph because the character code itself tells if or
18434 not the character is multibyte. Thus, in the future, we must
18435 consider eliminating the field `multibyte_p' in the struct
18437 int saved_multibyte_p
= it
->multibyte_p
;
18439 /* Maybe translate single-byte characters to multibyte, or the
18441 it
->char_to_display
= it
->c
;
18442 if (!ASCII_BYTE_P (it
->c
))
18444 if (unibyte_display_via_language_environment
18445 && SINGLE_BYTE_CHAR_P (it
->c
)
18447 || !NILP (Vnonascii_translation_table
)))
18449 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
18450 it
->multibyte_p
= 1;
18451 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18452 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18454 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
18455 && !it
->multibyte_p
)
18457 it
->multibyte_p
= 1;
18458 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18459 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18463 /* Get font to use. Encode IT->char_to_display. */
18464 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
18465 &char2b
, it
->multibyte_p
, 0);
18468 /* When no suitable font found, use the default font. */
18469 font_not_found_p
= font
== NULL
;
18470 if (font_not_found_p
)
18472 font
= FRAME_FONT (it
->f
);
18473 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18478 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18479 boff
= font_info
->baseline_offset
;
18480 if (font_info
->vertical_centering
)
18481 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18484 if (it
->char_to_display
>= ' '
18485 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
18487 /* Either unibyte or ASCII. */
18492 pcm
= rif
->per_char_metric (font
, &char2b
,
18493 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
18494 it
->ascent
= FONT_BASE (font
) + boff
;
18495 it
->descent
= FONT_DESCENT (font
) - boff
;
18499 it
->phys_ascent
= pcm
->ascent
+ boff
;
18500 it
->phys_descent
= pcm
->descent
- boff
;
18501 it
->pixel_width
= pcm
->width
;
18505 it
->glyph_not_available_p
= 1;
18506 it
->phys_ascent
= FONT_BASE (font
) + boff
;
18507 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18508 it
->pixel_width
= FONT_WIDTH (font
);
18511 /* If this is a space inside a region of text with
18512 `space-width' property, change its width. */
18513 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
18515 it
->pixel_width
*= XFLOATINT (it
->space_width
);
18517 /* If face has a box, add the box thickness to the character
18518 height. If character has a box line to the left and/or
18519 right, add the box line width to the character's width. */
18520 if (face
->box
!= FACE_NO_BOX
)
18522 int thick
= face
->box_line_width
;
18526 it
->ascent
+= thick
;
18527 it
->descent
+= thick
;
18532 if (it
->start_of_box_run_p
)
18533 it
->pixel_width
+= thick
;
18534 if (it
->end_of_box_run_p
)
18535 it
->pixel_width
+= thick
;
18538 /* If face has an overline, add the height of the overline
18539 (1 pixel) and a 1 pixel margin to the character height. */
18540 if (face
->overline_p
)
18543 take_vertical_position_into_account (it
);
18545 /* If we have to actually produce glyphs, do it. */
18550 /* Translate a space with a `space-width' property
18551 into a stretch glyph. */
18552 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
18553 / FONT_HEIGHT (font
));
18554 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
18555 it
->ascent
+ it
->descent
, ascent
);
18560 /* If characters with lbearing or rbearing are displayed
18561 in this line, record that fact in a flag of the
18562 glyph row. This is used to optimize X output code. */
18563 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
18564 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
18567 else if (it
->char_to_display
== '\n')
18569 /* A newline has no width but we need the height of the line. */
18570 it
->pixel_width
= 0;
18572 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
18573 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18575 if (face
->box
!= FACE_NO_BOX
18576 && face
->box_line_width
> 0)
18578 it
->ascent
+= face
->box_line_width
;
18579 it
->descent
+= face
->box_line_width
;
18582 else if (it
->char_to_display
== '\t')
18584 int tab_width
= it
->tab_width
* FRAME_COLUMN_WIDTH (it
->f
);
18585 int x
= it
->current_x
+ it
->continuation_lines_width
;
18586 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
18588 /* If the distance from the current position to the next tab
18589 stop is less than a canonical character width, use the
18590 tab stop after that. */
18591 if (next_tab_x
- x
< FRAME_COLUMN_WIDTH (it
->f
))
18592 next_tab_x
+= tab_width
;
18594 it
->pixel_width
= next_tab_x
- x
;
18596 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
18597 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18601 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
18602 it
->ascent
+ it
->descent
, it
->ascent
);
18607 /* A multi-byte character. Assume that the display width of the
18608 character is the width of the character multiplied by the
18609 width of the font. */
18611 /* If we found a font, this font should give us the right
18612 metrics. If we didn't find a font, use the frame's
18613 default font and calculate the width of the character
18614 from the charset width; this is what old redisplay code
18617 pcm
= rif
->per_char_metric (font
, &char2b
,
18618 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
18620 if (font_not_found_p
|| !pcm
)
18622 int charset
= CHAR_CHARSET (it
->char_to_display
);
18624 it
->glyph_not_available_p
= 1;
18625 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
18626 * CHARSET_WIDTH (charset
));
18627 it
->phys_ascent
= FONT_BASE (font
) + boff
;
18628 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18632 it
->pixel_width
= pcm
->width
;
18633 it
->phys_ascent
= pcm
->ascent
+ boff
;
18634 it
->phys_descent
= pcm
->descent
- boff
;
18636 && (pcm
->lbearing
< 0
18637 || pcm
->rbearing
> pcm
->width
))
18638 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
18641 it
->ascent
= FONT_BASE (font
) + boff
;
18642 it
->descent
= FONT_DESCENT (font
) - boff
;
18643 if (face
->box
!= FACE_NO_BOX
)
18645 int thick
= face
->box_line_width
;
18649 it
->ascent
+= thick
;
18650 it
->descent
+= thick
;
18655 if (it
->start_of_box_run_p
)
18656 it
->pixel_width
+= thick
;
18657 if (it
->end_of_box_run_p
)
18658 it
->pixel_width
+= thick
;
18661 /* If face has an overline, add the height of the overline
18662 (1 pixel) and a 1 pixel margin to the character height. */
18663 if (face
->overline_p
)
18666 take_vertical_position_into_account (it
);
18671 it
->multibyte_p
= saved_multibyte_p
;
18673 else if (it
->what
== IT_COMPOSITION
)
18675 /* Note: A composition is represented as one glyph in the
18676 glyph matrix. There are no padding glyphs. */
18679 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18681 int font_not_found_p
;
18682 struct font_info
*font_info
;
18683 int boff
; /* baseline offset */
18684 struct composition
*cmp
= composition_table
[it
->cmp_id
];
18686 /* Maybe translate single-byte characters to multibyte. */
18687 it
->char_to_display
= it
->c
;
18688 if (unibyte_display_via_language_environment
18689 && SINGLE_BYTE_CHAR_P (it
->c
)
18692 && !NILP (Vnonascii_translation_table
))))
18694 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
18697 /* Get face and font to use. Encode IT->char_to_display. */
18698 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18699 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18700 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
18701 &char2b
, it
->multibyte_p
, 0);
18704 /* When no suitable font found, use the default font. */
18705 font_not_found_p
= font
== NULL
;
18706 if (font_not_found_p
)
18708 font
= FRAME_FONT (it
->f
);
18709 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18714 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18715 boff
= font_info
->baseline_offset
;
18716 if (font_info
->vertical_centering
)
18717 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18720 /* There are no padding glyphs, so there is only one glyph to
18721 produce for the composition. Important is that pixel_width,
18722 ascent and descent are the values of what is drawn by
18723 draw_glyphs (i.e. the values of the overall glyphs composed). */
18726 /* If we have not yet calculated pixel size data of glyphs of
18727 the composition for the current face font, calculate them
18728 now. Theoretically, we have to check all fonts for the
18729 glyphs, but that requires much time and memory space. So,
18730 here we check only the font of the first glyph. This leads
18731 to incorrect display very rarely, and C-l (recenter) can
18732 correct the display anyway. */
18733 if (cmp
->font
!= (void *) font
)
18735 /* Ascent and descent of the font of the first character of
18736 this composition (adjusted by baseline offset). Ascent
18737 and descent of overall glyphs should not be less than
18738 them respectively. */
18739 int font_ascent
= FONT_BASE (font
) + boff
;
18740 int font_descent
= FONT_DESCENT (font
) - boff
;
18741 /* Bounding box of the overall glyphs. */
18742 int leftmost
, rightmost
, lowest
, highest
;
18743 int i
, width
, ascent
, descent
;
18745 cmp
->font
= (void *) font
;
18747 /* Initialize the bounding box. */
18749 && (pcm
= rif
->per_char_metric (font
, &char2b
,
18750 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
18752 width
= pcm
->width
;
18753 ascent
= pcm
->ascent
;
18754 descent
= pcm
->descent
;
18758 width
= FONT_WIDTH (font
);
18759 ascent
= FONT_BASE (font
);
18760 descent
= FONT_DESCENT (font
);
18764 lowest
= - descent
+ boff
;
18765 highest
= ascent
+ boff
;
18769 && font_info
->default_ascent
18770 && CHAR_TABLE_P (Vuse_default_ascent
)
18771 && !NILP (Faref (Vuse_default_ascent
,
18772 make_number (it
->char_to_display
))))
18773 highest
= font_info
->default_ascent
+ boff
;
18775 /* Draw the first glyph at the normal position. It may be
18776 shifted to right later if some other glyphs are drawn at
18778 cmp
->offsets
[0] = 0;
18779 cmp
->offsets
[1] = boff
;
18781 /* Set cmp->offsets for the remaining glyphs. */
18782 for (i
= 1; i
< cmp
->glyph_len
; i
++)
18784 int left
, right
, btm
, top
;
18785 int ch
= COMPOSITION_GLYPH (cmp
, i
);
18786 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
18788 face
= FACE_FROM_ID (it
->f
, face_id
);
18789 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
18790 &char2b
, it
->multibyte_p
, 0);
18794 font
= FRAME_FONT (it
->f
);
18795 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18801 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18802 boff
= font_info
->baseline_offset
;
18803 if (font_info
->vertical_centering
)
18804 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18808 && (pcm
= rif
->per_char_metric (font
, &char2b
,
18809 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
18811 width
= pcm
->width
;
18812 ascent
= pcm
->ascent
;
18813 descent
= pcm
->descent
;
18817 width
= FONT_WIDTH (font
);
18822 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
18824 /* Relative composition with or without
18825 alternate chars. */
18826 left
= (leftmost
+ rightmost
- width
) / 2;
18827 btm
= - descent
+ boff
;
18828 if (font_info
&& font_info
->relative_compose
18829 && (! CHAR_TABLE_P (Vignore_relative_composition
)
18830 || NILP (Faref (Vignore_relative_composition
,
18831 make_number (ch
)))))
18834 if (- descent
>= font_info
->relative_compose
)
18835 /* One extra pixel between two glyphs. */
18837 else if (ascent
<= 0)
18838 /* One extra pixel between two glyphs. */
18839 btm
= lowest
- 1 - ascent
- descent
;
18844 /* A composition rule is specified by an integer
18845 value that encodes global and new reference
18846 points (GREF and NREF). GREF and NREF are
18847 specified by numbers as below:
18849 0---1---2 -- ascent
18853 9--10--11 -- center
18855 ---3---4---5--- baseline
18857 6---7---8 -- descent
18859 int rule
= COMPOSITION_RULE (cmp
, i
);
18860 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
18862 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
18863 grefx
= gref
% 3, nrefx
= nref
% 3;
18864 grefy
= gref
/ 3, nrefy
= nref
/ 3;
18867 + grefx
* (rightmost
- leftmost
) / 2
18868 - nrefx
* width
/ 2);
18869 btm
= ((grefy
== 0 ? highest
18871 : grefy
== 2 ? lowest
18872 : (highest
+ lowest
) / 2)
18873 - (nrefy
== 0 ? ascent
+ descent
18874 : nrefy
== 1 ? descent
- boff
18876 : (ascent
+ descent
) / 2));
18879 cmp
->offsets
[i
* 2] = left
;
18880 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
18882 /* Update the bounding box of the overall glyphs. */
18883 right
= left
+ width
;
18884 top
= btm
+ descent
+ ascent
;
18885 if (left
< leftmost
)
18887 if (right
> rightmost
)
18895 /* If there are glyphs whose x-offsets are negative,
18896 shift all glyphs to the right and make all x-offsets
18900 for (i
= 0; i
< cmp
->glyph_len
; i
++)
18901 cmp
->offsets
[i
* 2] -= leftmost
;
18902 rightmost
-= leftmost
;
18905 cmp
->pixel_width
= rightmost
;
18906 cmp
->ascent
= highest
;
18907 cmp
->descent
= - lowest
;
18908 if (cmp
->ascent
< font_ascent
)
18909 cmp
->ascent
= font_ascent
;
18910 if (cmp
->descent
< font_descent
)
18911 cmp
->descent
= font_descent
;
18914 it
->pixel_width
= cmp
->pixel_width
;
18915 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
18916 it
->descent
= it
->phys_descent
= cmp
->descent
;
18918 if (face
->box
!= FACE_NO_BOX
)
18920 int thick
= face
->box_line_width
;
18924 it
->ascent
+= thick
;
18925 it
->descent
+= thick
;
18930 if (it
->start_of_box_run_p
)
18931 it
->pixel_width
+= thick
;
18932 if (it
->end_of_box_run_p
)
18933 it
->pixel_width
+= thick
;
18936 /* If face has an overline, add the height of the overline
18937 (1 pixel) and a 1 pixel margin to the character height. */
18938 if (face
->overline_p
)
18941 take_vertical_position_into_account (it
);
18944 append_composite_glyph (it
);
18946 else if (it
->what
== IT_IMAGE
)
18947 produce_image_glyph (it
);
18948 else if (it
->what
== IT_STRETCH
)
18949 produce_stretch_glyph (it
);
18951 /* Accumulate dimensions. Note: can't assume that it->descent > 0
18952 because this isn't true for images with `:ascent 100'. */
18953 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
18954 if (it
->area
== TEXT_AREA
)
18955 it
->current_x
+= it
->pixel_width
;
18957 it
->descent
+= it
->extra_line_spacing
;
18959 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
18960 it
->max_descent
= max (it
->max_descent
, it
->descent
);
18961 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
18962 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
18966 Output LEN glyphs starting at START at the nominal cursor position.
18967 Advance the nominal cursor over the text. The global variable
18968 updated_window contains the window being updated, updated_row is
18969 the glyph row being updated, and updated_area is the area of that
18970 row being updated. */
18973 x_write_glyphs (start
, len
)
18974 struct glyph
*start
;
18979 xassert (updated_window
&& updated_row
);
18982 /* Write glyphs. */
18984 hpos
= start
- updated_row
->glyphs
[updated_area
];
18985 x
= draw_glyphs (updated_window
, output_cursor
.x
,
18986 updated_row
, updated_area
,
18988 DRAW_NORMAL_TEXT
, 0);
18990 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
18991 if (updated_area
== TEXT_AREA
18992 && updated_window
->phys_cursor_on_p
18993 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
18994 && updated_window
->phys_cursor
.hpos
>= hpos
18995 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
18996 updated_window
->phys_cursor_on_p
= 0;
19000 /* Advance the output cursor. */
19001 output_cursor
.hpos
+= len
;
19002 output_cursor
.x
= x
;
19007 Insert LEN glyphs from START at the nominal cursor position. */
19010 x_insert_glyphs (start
, len
)
19011 struct glyph
*start
;
19016 int line_height
, shift_by_width
, shifted_region_width
;
19017 struct glyph_row
*row
;
19018 struct glyph
*glyph
;
19019 int frame_x
, frame_y
, hpos
;
19021 xassert (updated_window
&& updated_row
);
19023 w
= updated_window
;
19024 f
= XFRAME (WINDOW_FRAME (w
));
19026 /* Get the height of the line we are in. */
19028 line_height
= row
->height
;
19030 /* Get the width of the glyphs to insert. */
19031 shift_by_width
= 0;
19032 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
19033 shift_by_width
+= glyph
->pixel_width
;
19035 /* Get the width of the region to shift right. */
19036 shifted_region_width
= (window_box_width (w
, updated_area
)
19041 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
19042 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
19044 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
19045 line_height
, shift_by_width
);
19047 /* Write the glyphs. */
19048 hpos
= start
- row
->glyphs
[updated_area
];
19049 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
19051 DRAW_NORMAL_TEXT
, 0);
19053 /* Advance the output cursor. */
19054 output_cursor
.hpos
+= len
;
19055 output_cursor
.x
+= shift_by_width
;
19061 Erase the current text line from the nominal cursor position
19062 (inclusive) to pixel column TO_X (exclusive). The idea is that
19063 everything from TO_X onward is already erased.
19065 TO_X is a pixel position relative to updated_area of
19066 updated_window. TO_X == -1 means clear to the end of this area. */
19069 x_clear_end_of_line (to_x
)
19073 struct window
*w
= updated_window
;
19074 int max_x
, min_y
, max_y
;
19075 int from_x
, from_y
, to_y
;
19077 xassert (updated_window
&& updated_row
);
19078 f
= XFRAME (w
->frame
);
19080 if (updated_row
->full_width_p
)
19081 max_x
= WINDOW_TOTAL_WIDTH (w
);
19083 max_x
= window_box_width (w
, updated_area
);
19084 max_y
= window_text_bottom_y (w
);
19086 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
19087 of window. For TO_X > 0, truncate to end of drawing area. */
19093 to_x
= min (to_x
, max_x
);
19095 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
19097 /* Notice if the cursor will be cleared by this operation. */
19098 if (!updated_row
->full_width_p
)
19099 notice_overwritten_cursor (w
, updated_area
,
19100 output_cursor
.x
, -1,
19102 MATRIX_ROW_BOTTOM_Y (updated_row
));
19104 from_x
= output_cursor
.x
;
19106 /* Translate to frame coordinates. */
19107 if (updated_row
->full_width_p
)
19109 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
19110 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
19114 int area_left
= window_box_left (w
, updated_area
);
19115 from_x
+= area_left
;
19119 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
19120 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
19121 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
19123 /* Prevent inadvertently clearing to end of the X window. */
19124 if (to_x
> from_x
&& to_y
> from_y
)
19127 rif
->clear_frame_area (f
, from_x
, from_y
,
19128 to_x
- from_x
, to_y
- from_y
);
19133 #endif /* HAVE_WINDOW_SYSTEM */
19137 /***********************************************************************
19139 ***********************************************************************/
19141 /* Value is the internal representation of the specified cursor type
19142 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
19143 of the bar cursor. */
19145 static enum text_cursor_kinds
19146 get_specified_cursor_type (arg
, width
)
19150 enum text_cursor_kinds type
;
19155 if (EQ (arg
, Qbox
))
19156 return FILLED_BOX_CURSOR
;
19158 if (EQ (arg
, Qhollow
))
19159 return HOLLOW_BOX_CURSOR
;
19161 if (EQ (arg
, Qbar
))
19168 && EQ (XCAR (arg
), Qbar
)
19169 && INTEGERP (XCDR (arg
))
19170 && XINT (XCDR (arg
)) >= 0)
19172 *width
= XINT (XCDR (arg
));
19176 if (EQ (arg
, Qhbar
))
19179 return HBAR_CURSOR
;
19183 && EQ (XCAR (arg
), Qhbar
)
19184 && INTEGERP (XCDR (arg
))
19185 && XINT (XCDR (arg
)) >= 0)
19187 *width
= XINT (XCDR (arg
));
19188 return HBAR_CURSOR
;
19191 /* Treat anything unknown as "hollow box cursor".
19192 It was bad to signal an error; people have trouble fixing
19193 .Xdefaults with Emacs, when it has something bad in it. */
19194 type
= HOLLOW_BOX_CURSOR
;
19199 /* Set the default cursor types for specified frame. */
19201 set_frame_cursor_types (f
, arg
)
19208 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
19209 FRAME_CURSOR_WIDTH (f
) = width
;
19211 /* By default, set up the blink-off state depending on the on-state. */
19213 tem
= Fassoc (arg
, Vblink_cursor_alist
);
19216 FRAME_BLINK_OFF_CURSOR (f
)
19217 = get_specified_cursor_type (XCDR (tem
), &width
);
19218 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
19221 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
19225 /* Return the cursor we want to be displayed in window W. Return
19226 width of bar/hbar cursor through WIDTH arg. Return with
19227 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
19228 (i.e. if the `system caret' should track this cursor).
19230 In a mini-buffer window, we want the cursor only to appear if we
19231 are reading input from this window. For the selected window, we
19232 want the cursor type given by the frame parameter or buffer local
19233 setting of cursor-type. If explicitly marked off, draw no cursor.
19234 In all other cases, we want a hollow box cursor. */
19236 static enum text_cursor_kinds
19237 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
19239 struct glyph
*glyph
;
19241 int *active_cursor
;
19243 struct frame
*f
= XFRAME (w
->frame
);
19244 struct buffer
*b
= XBUFFER (w
->buffer
);
19245 int cursor_type
= DEFAULT_CURSOR
;
19246 Lisp_Object alt_cursor
;
19247 int non_selected
= 0;
19249 *active_cursor
= 1;
19252 if (cursor_in_echo_area
19253 && FRAME_HAS_MINIBUF_P (f
)
19254 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
19256 if (w
== XWINDOW (echo_area_window
))
19258 *width
= FRAME_CURSOR_WIDTH (f
);
19259 return FRAME_DESIRED_CURSOR (f
);
19262 *active_cursor
= 0;
19266 /* Nonselected window or nonselected frame. */
19267 else if (w
!= XWINDOW (f
->selected_window
)
19268 #ifdef HAVE_WINDOW_SYSTEM
19269 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
19273 *active_cursor
= 0;
19275 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
19281 /* Never display a cursor in a window in which cursor-type is nil. */
19282 if (NILP (b
->cursor_type
))
19285 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
19288 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
19289 return get_specified_cursor_type (alt_cursor
, width
);
19292 /* Get the normal cursor type for this window. */
19293 if (EQ (b
->cursor_type
, Qt
))
19295 cursor_type
= FRAME_DESIRED_CURSOR (f
);
19296 *width
= FRAME_CURSOR_WIDTH (f
);
19299 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
19301 /* Use normal cursor if not blinked off. */
19302 if (!w
->cursor_off_p
)
19304 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
19305 if (cursor_type
== FILLED_BOX_CURSOR
)
19306 cursor_type
= HOLLOW_BOX_CURSOR
;
19308 return cursor_type
;
19311 /* Cursor is blinked off, so determine how to "toggle" it. */
19313 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
19314 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
19315 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
19317 /* Then see if frame has specified a specific blink off cursor type. */
19318 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
19320 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
19321 return FRAME_BLINK_OFF_CURSOR (f
);
19325 /* Some people liked having a permanently visible blinking cursor,
19326 while others had very strong opinions against it. So it was
19327 decided to remove it. KFS 2003-09-03 */
19329 /* Finally perform built-in cursor blinking:
19330 filled box <-> hollow box
19331 wide [h]bar <-> narrow [h]bar
19332 narrow [h]bar <-> no cursor
19333 other type <-> no cursor */
19335 if (cursor_type
== FILLED_BOX_CURSOR
)
19336 return HOLLOW_BOX_CURSOR
;
19338 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
19341 return cursor_type
;
19349 #ifdef HAVE_WINDOW_SYSTEM
19351 /* Notice when the text cursor of window W has been completely
19352 overwritten by a drawing operation that outputs glyphs in AREA
19353 starting at X0 and ending at X1 in the line starting at Y0 and
19354 ending at Y1. X coordinates are area-relative. X1 < 0 means all
19355 the rest of the line after X0 has been written. Y coordinates
19356 are window-relative. */
19359 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
19361 enum glyph_row_area area
;
19362 int x0
, y0
, x1
, y1
;
19364 int cx0
, cx1
, cy0
, cy1
;
19365 struct glyph_row
*row
;
19367 if (!w
->phys_cursor_on_p
)
19369 if (area
!= TEXT_AREA
)
19372 row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
;
19373 if (!row
->displays_text_p
)
19376 if (row
->cursor_in_fringe_p
)
19378 row
->cursor_in_fringe_p
= 0;
19379 draw_fringe_bitmap (w
, row
, 0);
19380 w
->phys_cursor_on_p
= 0;
19384 cx0
= w
->phys_cursor
.x
;
19385 cx1
= cx0
+ w
->phys_cursor_width
;
19386 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
19389 /* The cursor image will be completely removed from the
19390 screen if the output area intersects the cursor area in
19391 y-direction. When we draw in [y0 y1[, and some part of
19392 the cursor is at y < y0, that part must have been drawn
19393 before. When scrolling, the cursor is erased before
19394 actually scrolling, so we don't come here. When not
19395 scrolling, the rows above the old cursor row must have
19396 changed, and in this case these rows must have written
19397 over the cursor image.
19399 Likewise if part of the cursor is below y1, with the
19400 exception of the cursor being in the first blank row at
19401 the buffer and window end because update_text_area
19402 doesn't draw that row. (Except when it does, but
19403 that's handled in update_text_area.) */
19405 cy0
= w
->phys_cursor
.y
;
19406 cy1
= cy0
+ w
->phys_cursor_height
;
19407 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
19410 w
->phys_cursor_on_p
= 0;
19413 #endif /* HAVE_WINDOW_SYSTEM */
19416 /************************************************************************
19418 ************************************************************************/
19420 #ifdef HAVE_WINDOW_SYSTEM
19423 Fix the display of area AREA of overlapping row ROW in window W. */
19426 x_fix_overlapping_area (w
, row
, area
)
19428 struct glyph_row
*row
;
19429 enum glyph_row_area area
;
19436 for (i
= 0; i
< row
->used
[area
];)
19438 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
19440 int start
= i
, start_x
= x
;
19444 x
+= row
->glyphs
[area
][i
].pixel_width
;
19447 while (i
< row
->used
[area
]
19448 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
19450 draw_glyphs (w
, start_x
, row
, area
,
19452 DRAW_NORMAL_TEXT
, 1);
19456 x
+= row
->glyphs
[area
][i
].pixel_width
;
19466 Draw the cursor glyph of window W in glyph row ROW. See the
19467 comment of draw_glyphs for the meaning of HL. */
19470 draw_phys_cursor_glyph (w
, row
, hl
)
19472 struct glyph_row
*row
;
19473 enum draw_glyphs_face hl
;
19475 /* If cursor hpos is out of bounds, don't draw garbage. This can
19476 happen in mini-buffer windows when switching between echo area
19477 glyphs and mini-buffer. */
19478 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
19480 int on_p
= w
->phys_cursor_on_p
;
19482 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
19483 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
19485 w
->phys_cursor_on_p
= on_p
;
19487 if (hl
== DRAW_CURSOR
)
19488 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
19489 /* When we erase the cursor, and ROW is overlapped by other
19490 rows, make sure that these overlapping parts of other rows
19492 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
19494 if (row
> w
->current_matrix
->rows
19495 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
19496 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
19498 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
19499 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
19500 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
19507 Erase the image of a cursor of window W from the screen. */
19510 erase_phys_cursor (w
)
19513 struct frame
*f
= XFRAME (w
->frame
);
19514 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
19515 int hpos
= w
->phys_cursor
.hpos
;
19516 int vpos
= w
->phys_cursor
.vpos
;
19517 int mouse_face_here_p
= 0;
19518 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
19519 struct glyph_row
*cursor_row
;
19520 struct glyph
*cursor_glyph
;
19521 enum draw_glyphs_face hl
;
19523 /* No cursor displayed or row invalidated => nothing to do on the
19525 if (w
->phys_cursor_type
== NO_CURSOR
)
19526 goto mark_cursor_off
;
19528 /* VPOS >= active_glyphs->nrows means that window has been resized.
19529 Don't bother to erase the cursor. */
19530 if (vpos
>= active_glyphs
->nrows
)
19531 goto mark_cursor_off
;
19533 /* If row containing cursor is marked invalid, there is nothing we
19535 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
19536 if (!cursor_row
->enabled_p
)
19537 goto mark_cursor_off
;
19539 /* If row is completely invisible, don't attempt to delete a cursor which
19540 isn't there. This can happen if cursor is at top of a window, and
19541 we switch to a buffer with a header line in that window. */
19542 if (cursor_row
->visible_height
<= 0)
19543 goto mark_cursor_off
;
19545 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
19546 if (cursor_row
->cursor_in_fringe_p
)
19548 cursor_row
->cursor_in_fringe_p
= 0;
19549 draw_fringe_bitmap (w
, cursor_row
, 0);
19550 goto mark_cursor_off
;
19553 /* This can happen when the new row is shorter than the old one.
19554 In this case, either draw_glyphs or clear_end_of_line
19555 should have cleared the cursor. Note that we wouldn't be
19556 able to erase the cursor in this case because we don't have a
19557 cursor glyph at hand. */
19558 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
19559 goto mark_cursor_off
;
19561 /* If the cursor is in the mouse face area, redisplay that when
19562 we clear the cursor. */
19563 if (! NILP (dpyinfo
->mouse_face_window
)
19564 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
19565 && (vpos
> dpyinfo
->mouse_face_beg_row
19566 || (vpos
== dpyinfo
->mouse_face_beg_row
19567 && hpos
>= dpyinfo
->mouse_face_beg_col
))
19568 && (vpos
< dpyinfo
->mouse_face_end_row
19569 || (vpos
== dpyinfo
->mouse_face_end_row
19570 && hpos
< dpyinfo
->mouse_face_end_col
))
19571 /* Don't redraw the cursor's spot in mouse face if it is at the
19572 end of a line (on a newline). The cursor appears there, but
19573 mouse highlighting does not. */
19574 && cursor_row
->used
[TEXT_AREA
] > hpos
)
19575 mouse_face_here_p
= 1;
19577 /* Maybe clear the display under the cursor. */
19578 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
19581 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
19583 cursor_glyph
= get_phys_cursor_glyph (w
);
19584 if (cursor_glyph
== NULL
)
19585 goto mark_cursor_off
;
19587 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
19588 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
19590 rif
->clear_frame_area (f
, x
, y
,
19591 cursor_glyph
->pixel_width
, cursor_row
->visible_height
);
19594 /* Erase the cursor by redrawing the character underneath it. */
19595 if (mouse_face_here_p
)
19596 hl
= DRAW_MOUSE_FACE
;
19598 hl
= DRAW_NORMAL_TEXT
;
19599 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
19602 w
->phys_cursor_on_p
= 0;
19603 w
->phys_cursor_type
= NO_CURSOR
;
19608 Display or clear cursor of window W. If ON is zero, clear the
19609 cursor. If it is non-zero, display the cursor. If ON is nonzero,
19610 where to put the cursor is specified by HPOS, VPOS, X and Y. */
19613 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
19615 int on
, hpos
, vpos
, x
, y
;
19617 struct frame
*f
= XFRAME (w
->frame
);
19618 int new_cursor_type
;
19619 int new_cursor_width
;
19621 struct glyph_row
*glyph_row
;
19622 struct glyph
*glyph
;
19624 /* This is pointless on invisible frames, and dangerous on garbaged
19625 windows and frames; in the latter case, the frame or window may
19626 be in the midst of changing its size, and x and y may be off the
19628 if (! FRAME_VISIBLE_P (f
)
19629 || FRAME_GARBAGED_P (f
)
19630 || vpos
>= w
->current_matrix
->nrows
19631 || hpos
>= w
->current_matrix
->matrix_w
)
19634 /* If cursor is off and we want it off, return quickly. */
19635 if (!on
&& !w
->phys_cursor_on_p
)
19638 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
19639 /* If cursor row is not enabled, we don't really know where to
19640 display the cursor. */
19641 if (!glyph_row
->enabled_p
)
19643 w
->phys_cursor_on_p
= 0;
19648 if (!glyph_row
->exact_window_width_line_p
19649 || hpos
< glyph_row
->used
[TEXT_AREA
])
19650 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
19652 xassert (interrupt_input_blocked
);
19654 /* Set new_cursor_type to the cursor we want to be displayed. */
19655 new_cursor_type
= get_window_cursor_type (w
, glyph
,
19656 &new_cursor_width
, &active_cursor
);
19658 /* If cursor is currently being shown and we don't want it to be or
19659 it is in the wrong place, or the cursor type is not what we want,
19661 if (w
->phys_cursor_on_p
19663 || w
->phys_cursor
.x
!= x
19664 || w
->phys_cursor
.y
!= y
19665 || new_cursor_type
!= w
->phys_cursor_type
19666 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
19667 && new_cursor_width
!= w
->phys_cursor_width
)))
19668 erase_phys_cursor (w
);
19670 /* Don't check phys_cursor_on_p here because that flag is only set
19671 to zero in some cases where we know that the cursor has been
19672 completely erased, to avoid the extra work of erasing the cursor
19673 twice. In other words, phys_cursor_on_p can be 1 and the cursor
19674 still not be visible, or it has only been partly erased. */
19677 w
->phys_cursor_ascent
= glyph_row
->ascent
;
19678 w
->phys_cursor_height
= glyph_row
->height
;
19680 /* Set phys_cursor_.* before x_draw_.* is called because some
19681 of them may need the information. */
19682 w
->phys_cursor
.x
= x
;
19683 w
->phys_cursor
.y
= glyph_row
->y
;
19684 w
->phys_cursor
.hpos
= hpos
;
19685 w
->phys_cursor
.vpos
= vpos
;
19688 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
19689 new_cursor_type
, new_cursor_width
,
19690 on
, active_cursor
);
19694 /* Switch the display of W's cursor on or off, according to the value
19698 update_window_cursor (w
, on
)
19702 /* Don't update cursor in windows whose frame is in the process
19703 of being deleted. */
19704 if (w
->current_matrix
)
19707 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
19708 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
19714 /* Call update_window_cursor with parameter ON_P on all leaf windows
19715 in the window tree rooted at W. */
19718 update_cursor_in_window_tree (w
, on_p
)
19724 if (!NILP (w
->hchild
))
19725 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
19726 else if (!NILP (w
->vchild
))
19727 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
19729 update_window_cursor (w
, on_p
);
19731 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
19737 Display the cursor on window W, or clear it, according to ON_P.
19738 Don't change the cursor's position. */
19741 x_update_cursor (f
, on_p
)
19745 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
19750 Clear the cursor of window W to background color, and mark the
19751 cursor as not shown. This is used when the text where the cursor
19752 is is about to be rewritten. */
19758 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
19759 update_window_cursor (w
, 0);
19764 Display the active region described by mouse_face_* according to DRAW. */
19767 show_mouse_face (dpyinfo
, draw
)
19768 Display_Info
*dpyinfo
;
19769 enum draw_glyphs_face draw
;
19771 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
19772 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19774 if (/* If window is in the process of being destroyed, don't bother
19776 w
->current_matrix
!= NULL
19777 /* Don't update mouse highlight if hidden */
19778 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
19779 /* Recognize when we are called to operate on rows that don't exist
19780 anymore. This can happen when a window is split. */
19781 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
19783 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
19784 struct glyph_row
*row
, *first
, *last
;
19786 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
19787 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
19789 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
19791 int start_hpos
, end_hpos
, start_x
;
19793 /* For all but the first row, the highlight starts at column 0. */
19796 start_hpos
= dpyinfo
->mouse_face_beg_col
;
19797 start_x
= dpyinfo
->mouse_face_beg_x
;
19806 end_hpos
= dpyinfo
->mouse_face_end_col
;
19808 end_hpos
= row
->used
[TEXT_AREA
];
19810 if (end_hpos
> start_hpos
)
19812 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
19813 start_hpos
, end_hpos
,
19817 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
19821 /* When we've written over the cursor, arrange for it to
19822 be displayed again. */
19823 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
19826 display_and_set_cursor (w
, 1,
19827 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
19828 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
19833 /* Change the mouse cursor. */
19834 if (draw
== DRAW_NORMAL_TEXT
)
19835 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
19836 else if (draw
== DRAW_MOUSE_FACE
)
19837 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
19839 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
19843 Clear out the mouse-highlighted active region.
19844 Redraw it un-highlighted first. Value is non-zero if mouse
19845 face was actually drawn unhighlighted. */
19848 clear_mouse_face (dpyinfo
)
19849 Display_Info
*dpyinfo
;
19853 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
19855 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
19859 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
19860 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
19861 dpyinfo
->mouse_face_window
= Qnil
;
19862 dpyinfo
->mouse_face_overlay
= Qnil
;
19868 Non-zero if physical cursor of window W is within mouse face. */
19871 cursor_in_mouse_face_p (w
)
19874 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
19875 int in_mouse_face
= 0;
19877 if (WINDOWP (dpyinfo
->mouse_face_window
)
19878 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
19880 int hpos
= w
->phys_cursor
.hpos
;
19881 int vpos
= w
->phys_cursor
.vpos
;
19883 if (vpos
>= dpyinfo
->mouse_face_beg_row
19884 && vpos
<= dpyinfo
->mouse_face_end_row
19885 && (vpos
> dpyinfo
->mouse_face_beg_row
19886 || hpos
>= dpyinfo
->mouse_face_beg_col
)
19887 && (vpos
< dpyinfo
->mouse_face_end_row
19888 || hpos
< dpyinfo
->mouse_face_end_col
19889 || dpyinfo
->mouse_face_past_end
))
19893 return in_mouse_face
;
19899 /* Find the glyph matrix position of buffer position CHARPOS in window
19900 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
19901 current glyphs must be up to date. If CHARPOS is above window
19902 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
19903 of last line in W. In the row containing CHARPOS, stop before glyphs
19904 having STOP as object. */
19906 #if 1 /* This is a version of fast_find_position that's more correct
19907 in the presence of hscrolling, for example. I didn't install
19908 it right away because the problem fixed is minor, it failed
19909 in 20.x as well, and I think it's too risky to install
19910 so near the release of 21.1. 2001-09-25 gerd. */
19913 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
19916 int *hpos
, *vpos
, *x
, *y
;
19919 struct glyph_row
*row
, *first
;
19920 struct glyph
*glyph
, *end
;
19923 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
19924 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
19927 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
19929 *x
= *y
= *hpos
= *vpos
= 0;
19934 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
19941 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
19943 glyph
= row
->glyphs
[TEXT_AREA
];
19944 end
= glyph
+ row
->used
[TEXT_AREA
];
19946 /* Skip over glyphs not having an object at the start of the row.
19947 These are special glyphs like truncation marks on terminal
19949 if (row
->displays_text_p
)
19951 && INTEGERP (glyph
->object
)
19952 && !EQ (stop
, glyph
->object
)
19953 && glyph
->charpos
< 0)
19955 *x
+= glyph
->pixel_width
;
19960 && !INTEGERP (glyph
->object
)
19961 && !EQ (stop
, glyph
->object
)
19962 && (!BUFFERP (glyph
->object
)
19963 || glyph
->charpos
< charpos
))
19965 *x
+= glyph
->pixel_width
;
19969 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
19976 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
19979 int *hpos
, *vpos
, *x
, *y
;
19984 int maybe_next_line_p
= 0;
19985 int line_start_position
;
19986 int yb
= window_text_bottom_y (w
);
19987 struct glyph_row
*row
, *best_row
;
19988 int row_vpos
, best_row_vpos
;
19991 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
19992 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
19994 while (row
->y
< yb
)
19996 if (row
->used
[TEXT_AREA
])
19997 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
19999 line_start_position
= 0;
20001 if (line_start_position
> pos
)
20003 /* If the position sought is the end of the buffer,
20004 don't include the blank lines at the bottom of the window. */
20005 else if (line_start_position
== pos
20006 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
20008 maybe_next_line_p
= 1;
20011 else if (line_start_position
> 0)
20014 best_row_vpos
= row_vpos
;
20017 if (row
->y
+ row
->height
>= yb
)
20024 /* Find the right column within BEST_ROW. */
20026 current_x
= best_row
->x
;
20027 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
20029 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
20030 int charpos
= glyph
->charpos
;
20032 if (BUFFERP (glyph
->object
))
20034 if (charpos
== pos
)
20037 *vpos
= best_row_vpos
;
20042 else if (charpos
> pos
)
20045 else if (EQ (glyph
->object
, stop
))
20050 current_x
+= glyph
->pixel_width
;
20053 /* If we're looking for the end of the buffer,
20054 and we didn't find it in the line we scanned,
20055 use the start of the following line. */
20056 if (maybe_next_line_p
)
20061 current_x
= best_row
->x
;
20064 *vpos
= best_row_vpos
;
20065 *hpos
= lastcol
+ 1;
20074 /* Find the position of the glyph for position POS in OBJECT in
20075 window W's current matrix, and return in *X, *Y the pixel
20076 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
20078 RIGHT_P non-zero means return the position of the right edge of the
20079 glyph, RIGHT_P zero means return the left edge position.
20081 If no glyph for POS exists in the matrix, return the position of
20082 the glyph with the next smaller position that is in the matrix, if
20083 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
20084 exists in the matrix, return the position of the glyph with the
20085 next larger position in OBJECT.
20087 Value is non-zero if a glyph was found. */
20090 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
20093 Lisp_Object object
;
20094 int *hpos
, *vpos
, *x
, *y
;
20097 int yb
= window_text_bottom_y (w
);
20098 struct glyph_row
*r
;
20099 struct glyph
*best_glyph
= NULL
;
20100 struct glyph_row
*best_row
= NULL
;
20103 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20104 r
->enabled_p
&& r
->y
< yb
;
20107 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
20108 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
20111 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
20112 if (EQ (g
->object
, object
))
20114 if (g
->charpos
== pos
)
20121 else if (best_glyph
== NULL
20122 || ((abs (g
->charpos
- pos
)
20123 < abs (best_glyph
->charpos
- pos
))
20126 : g
->charpos
> pos
)))
20140 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
20144 *x
+= best_glyph
->pixel_width
;
20149 *vpos
= best_row
- w
->current_matrix
->rows
;
20152 return best_glyph
!= NULL
;
20156 /* See if position X, Y is within a hot-spot of an image. */
20159 on_hot_spot_p (hot_spot
, x
, y
)
20160 Lisp_Object hot_spot
;
20163 if (!CONSP (hot_spot
))
20166 if (EQ (XCAR (hot_spot
), Qrect
))
20168 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
20169 Lisp_Object rect
= XCDR (hot_spot
);
20173 if (!CONSP (XCAR (rect
)))
20175 if (!CONSP (XCDR (rect
)))
20177 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
20179 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
20181 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
20183 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
20187 else if (EQ (XCAR (hot_spot
), Qcircle
))
20189 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
20190 Lisp_Object circ
= XCDR (hot_spot
);
20191 Lisp_Object lr
, lx0
, ly0
;
20193 && CONSP (XCAR (circ
))
20194 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
20195 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
20196 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
20198 double r
= XFLOATINT (lr
);
20199 double dx
= XINT (lx0
) - x
;
20200 double dy
= XINT (ly0
) - y
;
20201 return (dx
* dx
+ dy
* dy
<= r
* r
);
20204 else if (EQ (XCAR (hot_spot
), Qpoly
))
20206 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
20207 if (VECTORP (XCDR (hot_spot
)))
20209 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
20210 Lisp_Object
*poly
= v
->contents
;
20214 Lisp_Object lx
, ly
;
20217 /* Need an even number of coordinates, and at least 3 edges. */
20218 if (n
< 6 || n
& 1)
20221 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
20222 If count is odd, we are inside polygon. Pixels on edges
20223 may or may not be included depending on actual geometry of the
20225 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
20226 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
20228 x0
= XINT (lx
), y0
= XINT (ly
);
20229 for (i
= 0; i
< n
; i
+= 2)
20231 int x1
= x0
, y1
= y0
;
20232 if ((lx
= poly
[i
], !INTEGERP (lx
))
20233 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
20235 x0
= XINT (lx
), y0
= XINT (ly
);
20237 /* Does this segment cross the X line? */
20245 if (y
> y0
&& y
> y1
)
20247 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
20258 find_hot_spot (map
, x
, y
)
20262 while (CONSP (map
))
20264 if (CONSP (XCAR (map
))
20265 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
20273 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
20275 doc
: /* Lookup in image map MAP coordinates X and Y.
20276 An image map is an alist where each element has the format (AREA ID PLIST).
20277 An AREA is specified as either a rectangle, a circle, or a polygon:
20278 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
20279 pixel coordinates of the upper left and bottom right corners.
20280 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
20281 and the radius of the circle; r may be a float or integer.
20282 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
20283 vector describes one corner in the polygon.
20284 Returns the alist element for the first matching AREA in MAP. */)
20296 return find_hot_spot (map
, XINT (x
), XINT (y
));
20300 /* Display frame CURSOR, optionally using shape defined by POINTER. */
20302 define_frame_cursor1 (f
, cursor
, pointer
)
20305 Lisp_Object pointer
;
20307 if (!NILP (pointer
))
20309 if (EQ (pointer
, Qarrow
))
20310 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20311 else if (EQ (pointer
, Qhand
))
20312 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
20313 else if (EQ (pointer
, Qtext
))
20314 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
20315 else if (EQ (pointer
, intern ("hdrag")))
20316 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
20317 #ifdef HAVE_X_WINDOWS
20318 else if (EQ (pointer
, intern ("vdrag")))
20319 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
20321 else if (EQ (pointer
, intern ("hourglass")))
20322 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
20323 else if (EQ (pointer
, Qmodeline
))
20324 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
20326 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20329 #ifndef HAVE_CARBON
20330 if (cursor
!= No_Cursor
)
20332 if (bcmp (&cursor
, &No_Cursor
, sizeof (Cursor
)))
20334 rif
->define_frame_cursor (f
, cursor
);
20337 /* Take proper action when mouse has moved to the mode or header line
20338 or marginal area AREA of window W, x-position X and y-position Y.
20339 X is relative to the start of the text display area of W, so the
20340 width of bitmap areas and scroll bars must be subtracted to get a
20341 position relative to the start of the mode line. */
20344 note_mode_line_or_margin_highlight (w
, x
, y
, area
)
20347 enum window_part area
;
20349 struct frame
*f
= XFRAME (w
->frame
);
20350 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20351 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20352 Lisp_Object pointer
= Qnil
;
20353 int charpos
, dx
, dy
, width
, height
;
20354 Lisp_Object string
, object
= Qnil
;
20355 Lisp_Object pos
, help
, image
;
20357 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
20358 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
20359 &object
, &dx
, &dy
, &width
, &height
);
20362 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
20363 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
20364 &object
, &dx
, &dy
, &width
, &height
);
20369 if (IMAGEP (object
))
20371 Lisp_Object image_map
, hotspot
;
20372 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
20374 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
20376 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
20378 Lisp_Object area_id
, plist
;
20380 area_id
= XCAR (hotspot
);
20381 /* Could check AREA_ID to see if we enter/leave this hot-spot.
20382 If so, we could look for mouse-enter, mouse-leave
20383 properties in PLIST (and do something...). */
20384 if ((plist
= XCDR (hotspot
), CONSP (plist
)))
20386 pointer
= Fplist_get (plist
, Qpointer
);
20387 if (NILP (pointer
))
20389 help
= Fplist_get (plist
, Qhelp_echo
);
20392 help_echo_string
= help
;
20393 /* Is this correct? ++kfs */
20394 XSETWINDOW (help_echo_window
, w
);
20395 help_echo_object
= w
->buffer
;
20396 help_echo_pos
= charpos
;
20399 if (NILP (pointer
))
20400 pointer
= Fplist_get (XCDR (object
), QCpointer
);
20404 if (STRINGP (string
))
20406 pos
= make_number (charpos
);
20407 /* If we're on a string with `help-echo' text property, arrange
20408 for the help to be displayed. This is done by setting the
20409 global variable help_echo_string to the help string. */
20410 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
20413 help_echo_string
= help
;
20414 XSETWINDOW (help_echo_window
, w
);
20415 help_echo_object
= string
;
20416 help_echo_pos
= charpos
;
20419 if (NILP (pointer
))
20420 pointer
= Fget_text_property (pos
, Qpointer
, string
);
20422 /* Change the mouse pointer according to what is under X/Y. */
20423 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
20426 map
= Fget_text_property (pos
, Qlocal_map
, string
);
20427 if (!KEYMAPP (map
))
20428 map
= Fget_text_property (pos
, Qkeymap
, string
);
20429 if (!KEYMAPP (map
))
20430 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
20434 define_frame_cursor1 (f
, cursor
, pointer
);
20439 Take proper action when the mouse has moved to position X, Y on
20440 frame F as regards highlighting characters that have mouse-face
20441 properties. Also de-highlighting chars where the mouse was before.
20442 X and Y can be negative or out of range. */
20445 note_mouse_highlight (f
, x
, y
)
20449 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20450 enum window_part part
;
20451 Lisp_Object window
;
20453 Cursor cursor
= No_Cursor
;
20454 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
20457 /* When a menu is active, don't highlight because this looks odd. */
20458 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
20459 if (popup_activated ())
20463 if (NILP (Vmouse_highlight
)
20464 || !f
->glyphs_initialized_p
)
20467 dpyinfo
->mouse_face_mouse_x
= x
;
20468 dpyinfo
->mouse_face_mouse_y
= y
;
20469 dpyinfo
->mouse_face_mouse_frame
= f
;
20471 if (dpyinfo
->mouse_face_defer
)
20474 if (gc_in_progress
)
20476 dpyinfo
->mouse_face_deferred_gc
= 1;
20480 /* Which window is that in? */
20481 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
20483 /* If we were displaying active text in another window, clear that. */
20484 if (! EQ (window
, dpyinfo
->mouse_face_window
))
20485 clear_mouse_face (dpyinfo
);
20487 /* Not on a window -> return. */
20488 if (!WINDOWP (window
))
20491 /* Reset help_echo_string. It will get recomputed below. */
20492 help_echo_string
= Qnil
;
20494 /* Convert to window-relative pixel coordinates. */
20495 w
= XWINDOW (window
);
20496 frame_to_window_pixel_xy (w
, &x
, &y
);
20498 /* Handle tool-bar window differently since it doesn't display a
20500 if (EQ (window
, f
->tool_bar_window
))
20502 note_tool_bar_highlight (f
, x
, y
);
20506 /* Mouse is on the mode, header line or margin? */
20507 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
20508 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
20510 note_mode_line_or_margin_highlight (w
, x
, y
, part
);
20514 if (part
== ON_VERTICAL_BORDER
)
20515 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
20516 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
)
20517 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20519 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
20521 /* Are we in a window whose display is up to date?
20522 And verify the buffer's text has not changed. */
20523 b
= XBUFFER (w
->buffer
);
20524 if (part
== ON_TEXT
20525 && EQ (w
->window_end_valid
, w
->buffer
)
20526 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
20527 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
20529 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
20530 struct glyph
*glyph
;
20531 Lisp_Object object
;
20532 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
20533 Lisp_Object
*overlay_vec
= NULL
;
20534 int len
, noverlays
;
20535 struct buffer
*obuf
;
20536 int obegv
, ozv
, same_region
;
20538 /* Find the glyph under X/Y. */
20539 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
20541 /* Look for :pointer property on image. */
20542 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
20544 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
20545 if (img
!= NULL
&& IMAGEP (img
->spec
))
20547 Lisp_Object image_map
, hotspot
;
20548 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
20550 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
20552 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
20554 Lisp_Object area_id
, plist
;
20556 area_id
= XCAR (hotspot
);
20557 /* Could check AREA_ID to see if we enter/leave this hot-spot.
20558 If so, we could look for mouse-enter, mouse-leave
20559 properties in PLIST (and do something...). */
20560 if ((plist
= XCDR (hotspot
), CONSP (plist
)))
20562 pointer
= Fplist_get (plist
, Qpointer
);
20563 if (NILP (pointer
))
20565 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
20566 if (!NILP (help_echo_string
))
20568 help_echo_window
= window
;
20569 help_echo_object
= glyph
->object
;
20570 help_echo_pos
= glyph
->charpos
;
20574 if (NILP (pointer
))
20575 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
20579 /* Clear mouse face if X/Y not over text. */
20581 || area
!= TEXT_AREA
20582 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
20584 if (clear_mouse_face (dpyinfo
))
20585 cursor
= No_Cursor
;
20586 if (NILP (pointer
))
20588 if (area
!= TEXT_AREA
)
20589 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20591 pointer
= Vvoid_text_area_pointer
;
20596 pos
= glyph
->charpos
;
20597 object
= glyph
->object
;
20598 if (!STRINGP (object
) && !BUFFERP (object
))
20601 /* If we get an out-of-range value, return now; avoid an error. */
20602 if (BUFFERP (object
) && pos
> BUF_Z (b
))
20605 /* Make the window's buffer temporarily current for
20606 overlays_at and compute_char_face. */
20607 obuf
= current_buffer
;
20608 current_buffer
= b
;
20614 /* Is this char mouse-active or does it have help-echo? */
20615 position
= make_number (pos
);
20617 if (BUFFERP (object
))
20619 /* Put all the overlays we want in a vector in overlay_vec.
20620 Store the length in len. If there are more than 10, make
20621 enough space for all, and try again. */
20623 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
20624 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
20625 if (noverlays
> len
)
20628 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
20629 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
20632 /* Sort overlays into increasing priority order. */
20633 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
20638 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
20639 && vpos
>= dpyinfo
->mouse_face_beg_row
20640 && vpos
<= dpyinfo
->mouse_face_end_row
20641 && (vpos
> dpyinfo
->mouse_face_beg_row
20642 || hpos
>= dpyinfo
->mouse_face_beg_col
)
20643 && (vpos
< dpyinfo
->mouse_face_end_row
20644 || hpos
< dpyinfo
->mouse_face_end_col
20645 || dpyinfo
->mouse_face_past_end
));
20648 cursor
= No_Cursor
;
20650 /* Check mouse-face highlighting. */
20652 /* If there exists an overlay with mouse-face overlapping
20653 the one we are currently highlighting, we have to
20654 check if we enter the overlapping overlay, and then
20655 highlight only that. */
20656 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
20657 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
20659 /* Find the highest priority overlay that has a mouse-face
20662 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
20664 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
20665 if (!NILP (mouse_face
))
20666 overlay
= overlay_vec
[i
];
20669 /* If we're actually highlighting the same overlay as
20670 before, there's no need to do that again. */
20671 if (!NILP (overlay
)
20672 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
20673 goto check_help_echo
;
20675 dpyinfo
->mouse_face_overlay
= overlay
;
20677 /* Clear the display of the old active region, if any. */
20678 if (clear_mouse_face (dpyinfo
))
20679 cursor
= No_Cursor
;
20681 /* If no overlay applies, get a text property. */
20682 if (NILP (overlay
))
20683 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
20685 /* Handle the overlay case. */
20686 if (!NILP (overlay
))
20688 /* Find the range of text around this char that
20689 should be active. */
20690 Lisp_Object before
, after
;
20693 before
= Foverlay_start (overlay
);
20694 after
= Foverlay_end (overlay
);
20695 /* Record this as the current active region. */
20696 fast_find_position (w
, XFASTINT (before
),
20697 &dpyinfo
->mouse_face_beg_col
,
20698 &dpyinfo
->mouse_face_beg_row
,
20699 &dpyinfo
->mouse_face_beg_x
,
20700 &dpyinfo
->mouse_face_beg_y
, Qnil
);
20702 dpyinfo
->mouse_face_past_end
20703 = !fast_find_position (w
, XFASTINT (after
),
20704 &dpyinfo
->mouse_face_end_col
,
20705 &dpyinfo
->mouse_face_end_row
,
20706 &dpyinfo
->mouse_face_end_x
,
20707 &dpyinfo
->mouse_face_end_y
, Qnil
);
20708 dpyinfo
->mouse_face_window
= window
;
20710 dpyinfo
->mouse_face_face_id
20711 = face_at_buffer_position (w
, pos
, 0, 0,
20713 !dpyinfo
->mouse_face_hidden
);
20715 /* Display it as active. */
20716 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
20717 cursor
= No_Cursor
;
20719 /* Handle the text property case. */
20720 else if (!NILP (mouse_face
) && BUFFERP (object
))
20722 /* Find the range of text around this char that
20723 should be active. */
20724 Lisp_Object before
, after
, beginning
, end
;
20727 beginning
= Fmarker_position (w
->start
);
20728 end
= make_number (BUF_Z (XBUFFER (object
))
20729 - XFASTINT (w
->window_end_pos
));
20731 = Fprevious_single_property_change (make_number (pos
+ 1),
20733 object
, beginning
);
20735 = Fnext_single_property_change (position
, Qmouse_face
,
20738 /* Record this as the current active region. */
20739 fast_find_position (w
, XFASTINT (before
),
20740 &dpyinfo
->mouse_face_beg_col
,
20741 &dpyinfo
->mouse_face_beg_row
,
20742 &dpyinfo
->mouse_face_beg_x
,
20743 &dpyinfo
->mouse_face_beg_y
, Qnil
);
20744 dpyinfo
->mouse_face_past_end
20745 = !fast_find_position (w
, XFASTINT (after
),
20746 &dpyinfo
->mouse_face_end_col
,
20747 &dpyinfo
->mouse_face_end_row
,
20748 &dpyinfo
->mouse_face_end_x
,
20749 &dpyinfo
->mouse_face_end_y
, Qnil
);
20750 dpyinfo
->mouse_face_window
= window
;
20752 if (BUFFERP (object
))
20753 dpyinfo
->mouse_face_face_id
20754 = face_at_buffer_position (w
, pos
, 0, 0,
20756 !dpyinfo
->mouse_face_hidden
);
20758 /* Display it as active. */
20759 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
20760 cursor
= No_Cursor
;
20762 else if (!NILP (mouse_face
) && STRINGP (object
))
20767 b
= Fprevious_single_property_change (make_number (pos
+ 1),
20770 e
= Fnext_single_property_change (position
, Qmouse_face
,
20773 b
= make_number (0);
20775 e
= make_number (SCHARS (object
) - 1);
20776 fast_find_string_pos (w
, XINT (b
), object
,
20777 &dpyinfo
->mouse_face_beg_col
,
20778 &dpyinfo
->mouse_face_beg_row
,
20779 &dpyinfo
->mouse_face_beg_x
,
20780 &dpyinfo
->mouse_face_beg_y
, 0);
20781 fast_find_string_pos (w
, XINT (e
), object
,
20782 &dpyinfo
->mouse_face_end_col
,
20783 &dpyinfo
->mouse_face_end_row
,
20784 &dpyinfo
->mouse_face_end_x
,
20785 &dpyinfo
->mouse_face_end_y
, 1);
20786 dpyinfo
->mouse_face_past_end
= 0;
20787 dpyinfo
->mouse_face_window
= window
;
20788 dpyinfo
->mouse_face_face_id
20789 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
20790 glyph
->face_id
, 1);
20791 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
20792 cursor
= No_Cursor
;
20794 else if (STRINGP (object
) && NILP (mouse_face
))
20796 /* A string which doesn't have mouse-face, but
20797 the text ``under'' it might have. */
20798 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
20799 int start
= MATRIX_ROW_START_CHARPOS (r
);
20801 pos
= string_buffer_position (w
, object
, start
);
20803 mouse_face
= get_char_property_and_overlay (make_number (pos
),
20807 if (!NILP (mouse_face
) && !NILP (overlay
))
20809 Lisp_Object before
= Foverlay_start (overlay
);
20810 Lisp_Object after
= Foverlay_end (overlay
);
20813 /* Note that we might not be able to find position
20814 BEFORE in the glyph matrix if the overlay is
20815 entirely covered by a `display' property. In
20816 this case, we overshoot. So let's stop in
20817 the glyph matrix before glyphs for OBJECT. */
20818 fast_find_position (w
, XFASTINT (before
),
20819 &dpyinfo
->mouse_face_beg_col
,
20820 &dpyinfo
->mouse_face_beg_row
,
20821 &dpyinfo
->mouse_face_beg_x
,
20822 &dpyinfo
->mouse_face_beg_y
,
20825 dpyinfo
->mouse_face_past_end
20826 = !fast_find_position (w
, XFASTINT (after
),
20827 &dpyinfo
->mouse_face_end_col
,
20828 &dpyinfo
->mouse_face_end_row
,
20829 &dpyinfo
->mouse_face_end_x
,
20830 &dpyinfo
->mouse_face_end_y
,
20832 dpyinfo
->mouse_face_window
= window
;
20833 dpyinfo
->mouse_face_face_id
20834 = face_at_buffer_position (w
, pos
, 0, 0,
20836 !dpyinfo
->mouse_face_hidden
);
20838 /* Display it as active. */
20839 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
20840 cursor
= No_Cursor
;
20847 /* Look for a `help-echo' property. */
20848 if (NILP (help_echo_string
)) {
20849 Lisp_Object help
, overlay
;
20851 /* Check overlays first. */
20852 help
= overlay
= Qnil
;
20853 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
20855 overlay
= overlay_vec
[i
];
20856 help
= Foverlay_get (overlay
, Qhelp_echo
);
20861 help_echo_string
= help
;
20862 help_echo_window
= window
;
20863 help_echo_object
= overlay
;
20864 help_echo_pos
= pos
;
20868 Lisp_Object object
= glyph
->object
;
20869 int charpos
= glyph
->charpos
;
20871 /* Try text properties. */
20872 if (STRINGP (object
)
20874 && charpos
< SCHARS (object
))
20876 help
= Fget_text_property (make_number (charpos
),
20877 Qhelp_echo
, object
);
20880 /* If the string itself doesn't specify a help-echo,
20881 see if the buffer text ``under'' it does. */
20882 struct glyph_row
*r
20883 = MATRIX_ROW (w
->current_matrix
, vpos
);
20884 int start
= MATRIX_ROW_START_CHARPOS (r
);
20885 int pos
= string_buffer_position (w
, object
, start
);
20888 help
= Fget_char_property (make_number (pos
),
20889 Qhelp_echo
, w
->buffer
);
20893 object
= w
->buffer
;
20898 else if (BUFFERP (object
)
20901 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
20906 help_echo_string
= help
;
20907 help_echo_window
= window
;
20908 help_echo_object
= object
;
20909 help_echo_pos
= charpos
;
20914 /* Look for a `pointer' property. */
20915 if (NILP (pointer
))
20917 /* Check overlays first. */
20918 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
20919 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
20921 if (NILP (pointer
))
20923 Lisp_Object object
= glyph
->object
;
20924 int charpos
= glyph
->charpos
;
20926 /* Try text properties. */
20927 if (STRINGP (object
)
20929 && charpos
< SCHARS (object
))
20931 pointer
= Fget_text_property (make_number (charpos
),
20933 if (NILP (pointer
))
20935 /* If the string itself doesn't specify a pointer,
20936 see if the buffer text ``under'' it does. */
20937 struct glyph_row
*r
20938 = MATRIX_ROW (w
->current_matrix
, vpos
);
20939 int start
= MATRIX_ROW_START_CHARPOS (r
);
20940 int pos
= string_buffer_position (w
, object
, start
);
20942 pointer
= Fget_char_property (make_number (pos
),
20943 Qpointer
, w
->buffer
);
20946 else if (BUFFERP (object
)
20949 pointer
= Fget_text_property (make_number (charpos
),
20956 current_buffer
= obuf
;
20961 define_frame_cursor1 (f
, cursor
, pointer
);
20966 Clear any mouse-face on window W. This function is part of the
20967 redisplay interface, and is called from try_window_id and similar
20968 functions to ensure the mouse-highlight is off. */
20971 x_clear_window_mouse_face (w
)
20974 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
20975 Lisp_Object window
;
20978 XSETWINDOW (window
, w
);
20979 if (EQ (window
, dpyinfo
->mouse_face_window
))
20980 clear_mouse_face (dpyinfo
);
20986 Just discard the mouse face information for frame F, if any.
20987 This is used when the size of F is changed. */
20990 cancel_mouse_face (f
)
20993 Lisp_Object window
;
20994 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20996 window
= dpyinfo
->mouse_face_window
;
20997 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
20999 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21000 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21001 dpyinfo
->mouse_face_window
= Qnil
;
21006 #endif /* HAVE_WINDOW_SYSTEM */
21009 /***********************************************************************
21011 ***********************************************************************/
21013 #ifdef HAVE_WINDOW_SYSTEM
21015 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
21016 which intersects rectangle R. R is in window-relative coordinates. */
21019 expose_area (w
, row
, r
, area
)
21021 struct glyph_row
*row
;
21023 enum glyph_row_area area
;
21025 struct glyph
*first
= row
->glyphs
[area
];
21026 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
21027 struct glyph
*last
;
21028 int first_x
, start_x
, x
;
21030 if (area
== TEXT_AREA
&& row
->fill_line_p
)
21031 /* If row extends face to end of line write the whole line. */
21032 draw_glyphs (w
, 0, row
, area
,
21033 0, row
->used
[area
],
21034 DRAW_NORMAL_TEXT
, 0);
21037 /* Set START_X to the window-relative start position for drawing glyphs of
21038 AREA. The first glyph of the text area can be partially visible.
21039 The first glyphs of other areas cannot. */
21040 start_x
= window_box_left_offset (w
, area
);
21042 if (area
== TEXT_AREA
)
21045 /* Find the first glyph that must be redrawn. */
21047 && x
+ first
->pixel_width
< r
->x
)
21049 x
+= first
->pixel_width
;
21053 /* Find the last one. */
21057 && x
< r
->x
+ r
->width
)
21059 x
+= last
->pixel_width
;
21065 draw_glyphs (w
, first_x
- start_x
, row
, area
,
21066 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
21067 DRAW_NORMAL_TEXT
, 0);
21072 /* Redraw the parts of the glyph row ROW on window W intersecting
21073 rectangle R. R is in window-relative coordinates. Value is
21074 non-zero if mouse-face was overwritten. */
21077 expose_line (w
, row
, r
)
21079 struct glyph_row
*row
;
21082 xassert (row
->enabled_p
);
21084 if (row
->mode_line_p
|| w
->pseudo_window_p
)
21085 draw_glyphs (w
, 0, row
, TEXT_AREA
,
21086 0, row
->used
[TEXT_AREA
],
21087 DRAW_NORMAL_TEXT
, 0);
21090 if (row
->used
[LEFT_MARGIN_AREA
])
21091 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
21092 if (row
->used
[TEXT_AREA
])
21093 expose_area (w
, row
, r
, TEXT_AREA
);
21094 if (row
->used
[RIGHT_MARGIN_AREA
])
21095 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
21096 draw_row_fringe_bitmaps (w
, row
);
21099 return row
->mouse_face_p
;
21103 /* Redraw those parts of glyphs rows during expose event handling that
21104 overlap other rows. Redrawing of an exposed line writes over parts
21105 of lines overlapping that exposed line; this function fixes that.
21107 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
21108 row in W's current matrix that is exposed and overlaps other rows.
21109 LAST_OVERLAPPING_ROW is the last such row. */
21112 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
21114 struct glyph_row
*first_overlapping_row
;
21115 struct glyph_row
*last_overlapping_row
;
21117 struct glyph_row
*row
;
21119 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
21120 if (row
->overlapping_p
)
21122 xassert (row
->enabled_p
&& !row
->mode_line_p
);
21124 if (row
->used
[LEFT_MARGIN_AREA
])
21125 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
21127 if (row
->used
[TEXT_AREA
])
21128 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
21130 if (row
->used
[RIGHT_MARGIN_AREA
])
21131 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
21136 /* Return non-zero if W's cursor intersects rectangle R. */
21139 phys_cursor_in_rect_p (w
, r
)
21143 XRectangle cr
, result
;
21144 struct glyph
*cursor_glyph
;
21146 cursor_glyph
= get_phys_cursor_glyph (w
);
21149 /* r is relative to W's box, but w->phys_cursor.x is relative
21150 to left edge of W's TEXT area. Adjust it. */
21151 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
21152 cr
.y
= w
->phys_cursor
.y
;
21153 cr
.width
= cursor_glyph
->pixel_width
;
21154 cr
.height
= w
->phys_cursor_height
;
21155 /* ++KFS: W32 version used W32-specific IntersectRect here, but
21156 I assume the effect is the same -- and this is portable. */
21157 return x_intersect_rectangles (&cr
, r
, &result
);
21165 Draw a vertical window border to the right of window W if W doesn't
21166 have vertical scroll bars. */
21169 x_draw_vertical_border (w
)
21172 /* We could do better, if we knew what type of scroll-bar the adjacent
21173 windows (on either side) have... But we don't :-(
21174 However, I think this works ok. ++KFS 2003-04-25 */
21176 /* Redraw borders between horizontally adjacent windows. Don't
21177 do it for frames with vertical scroll bars because either the
21178 right scroll bar of a window, or the left scroll bar of its
21179 neighbor will suffice as a border. */
21180 if (!WINDOW_RIGHTMOST_P (w
)
21181 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
21183 int x0
, x1
, y0
, y1
;
21185 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21188 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
21190 else if (!WINDOW_LEFTMOST_P (w
)
21191 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
21193 int x0
, x1
, y0
, y1
;
21195 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21198 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
21203 /* Redraw the part of window W intersection rectangle FR. Pixel
21204 coordinates in FR are frame-relative. Call this function with
21205 input blocked. Value is non-zero if the exposure overwrites
21209 expose_window (w
, fr
)
21213 struct frame
*f
= XFRAME (w
->frame
);
21215 int mouse_face_overwritten_p
= 0;
21217 /* If window is not yet fully initialized, do nothing. This can
21218 happen when toolkit scroll bars are used and a window is split.
21219 Reconfiguring the scroll bar will generate an expose for a newly
21221 if (w
->current_matrix
== NULL
)
21224 /* When we're currently updating the window, display and current
21225 matrix usually don't agree. Arrange for a thorough display
21227 if (w
== updated_window
)
21229 SET_FRAME_GARBAGED (f
);
21233 /* Frame-relative pixel rectangle of W. */
21234 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
21235 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
21236 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
21237 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
21239 if (x_intersect_rectangles (fr
, &wr
, &r
))
21241 int yb
= window_text_bottom_y (w
);
21242 struct glyph_row
*row
;
21243 int cursor_cleared_p
;
21244 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
21246 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
21247 r
.x
, r
.y
, r
.width
, r
.height
));
21249 /* Convert to window coordinates. */
21250 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
21251 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
21253 /* Turn off the cursor. */
21254 if (!w
->pseudo_window_p
21255 && phys_cursor_in_rect_p (w
, &r
))
21257 x_clear_cursor (w
);
21258 cursor_cleared_p
= 1;
21261 cursor_cleared_p
= 0;
21263 /* Update lines intersecting rectangle R. */
21264 first_overlapping_row
= last_overlapping_row
= NULL
;
21265 for (row
= w
->current_matrix
->rows
;
21270 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
21272 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
21273 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
21274 || (r
.y
>= y0
&& r
.y
< y1
)
21275 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
21277 if (row
->overlapping_p
)
21279 if (first_overlapping_row
== NULL
)
21280 first_overlapping_row
= row
;
21281 last_overlapping_row
= row
;
21284 if (expose_line (w
, row
, &r
))
21285 mouse_face_overwritten_p
= 1;
21292 /* Display the mode line if there is one. */
21293 if (WINDOW_WANTS_MODELINE_P (w
)
21294 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
21296 && row
->y
< r
.y
+ r
.height
)
21298 if (expose_line (w
, row
, &r
))
21299 mouse_face_overwritten_p
= 1;
21302 if (!w
->pseudo_window_p
)
21304 /* Fix the display of overlapping rows. */
21305 if (first_overlapping_row
)
21306 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
21308 /* Draw border between windows. */
21309 x_draw_vertical_border (w
);
21311 /* Turn the cursor on again. */
21312 if (cursor_cleared_p
)
21313 update_window_cursor (w
, 1);
21318 /* Display scroll bar for this window. */
21319 if (!NILP (w
->vertical_scroll_bar
))
21322 If this doesn't work here (maybe some header files are missing),
21323 make a function in macterm.c and call it to do the job! */
21325 = SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (w
->vertical_scroll_bar
));
21331 return mouse_face_overwritten_p
;
21336 /* Redraw (parts) of all windows in the window tree rooted at W that
21337 intersect R. R contains frame pixel coordinates. Value is
21338 non-zero if the exposure overwrites mouse-face. */
21341 expose_window_tree (w
, r
)
21345 struct frame
*f
= XFRAME (w
->frame
);
21346 int mouse_face_overwritten_p
= 0;
21348 while (w
&& !FRAME_GARBAGED_P (f
))
21350 if (!NILP (w
->hchild
))
21351 mouse_face_overwritten_p
21352 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
21353 else if (!NILP (w
->vchild
))
21354 mouse_face_overwritten_p
21355 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
21357 mouse_face_overwritten_p
|= expose_window (w
, r
);
21359 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
21362 return mouse_face_overwritten_p
;
21367 Redisplay an exposed area of frame F. X and Y are the upper-left
21368 corner of the exposed rectangle. W and H are width and height of
21369 the exposed area. All are pixel values. W or H zero means redraw
21370 the entire frame. */
21373 expose_frame (f
, x
, y
, w
, h
)
21378 int mouse_face_overwritten_p
= 0;
21380 TRACE ((stderr
, "expose_frame "));
21382 /* No need to redraw if frame will be redrawn soon. */
21383 if (FRAME_GARBAGED_P (f
))
21385 TRACE ((stderr
, " garbaged\n"));
21390 /* MAC_TODO: this is a kludge, but if scroll bars are not activated
21391 or deactivated here, for unknown reasons, activated scroll bars
21392 are shown in deactivated frames in some instances. */
21393 if (f
== FRAME_MAC_DISPLAY_INFO (f
)->x_focus_frame
)
21394 activate_scroll_bars (f
);
21396 deactivate_scroll_bars (f
);
21399 /* If basic faces haven't been realized yet, there is no point in
21400 trying to redraw anything. This can happen when we get an expose
21401 event while Emacs is starting, e.g. by moving another window. */
21402 if (FRAME_FACE_CACHE (f
) == NULL
21403 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
21405 TRACE ((stderr
, " no faces\n"));
21409 if (w
== 0 || h
== 0)
21412 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
21413 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
21423 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
21424 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
21426 if (WINDOWP (f
->tool_bar_window
))
21427 mouse_face_overwritten_p
21428 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
21430 #ifdef HAVE_X_WINDOWS
21432 #ifndef USE_X_TOOLKIT
21433 if (WINDOWP (f
->menu_bar_window
))
21434 mouse_face_overwritten_p
21435 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
21436 #endif /* not USE_X_TOOLKIT */
21440 /* Some window managers support a focus-follows-mouse style with
21441 delayed raising of frames. Imagine a partially obscured frame,
21442 and moving the mouse into partially obscured mouse-face on that
21443 frame. The visible part of the mouse-face will be highlighted,
21444 then the WM raises the obscured frame. With at least one WM, KDE
21445 2.1, Emacs is not getting any event for the raising of the frame
21446 (even tried with SubstructureRedirectMask), only Expose events.
21447 These expose events will draw text normally, i.e. not
21448 highlighted. Which means we must redo the highlight here.
21449 Subsume it under ``we love X''. --gerd 2001-08-15 */
21450 /* Included in Windows version because Windows most likely does not
21451 do the right thing if any third party tool offers
21452 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
21453 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
21455 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21456 if (f
== dpyinfo
->mouse_face_mouse_frame
)
21458 int x
= dpyinfo
->mouse_face_mouse_x
;
21459 int y
= dpyinfo
->mouse_face_mouse_y
;
21460 clear_mouse_face (dpyinfo
);
21461 note_mouse_highlight (f
, x
, y
);
21468 Determine the intersection of two rectangles R1 and R2. Return
21469 the intersection in *RESULT. Value is non-zero if RESULT is not
21473 x_intersect_rectangles (r1
, r2
, result
)
21474 XRectangle
*r1
, *r2
, *result
;
21476 XRectangle
*left
, *right
;
21477 XRectangle
*upper
, *lower
;
21478 int intersection_p
= 0;
21480 /* Rearrange so that R1 is the left-most rectangle. */
21482 left
= r1
, right
= r2
;
21484 left
= r2
, right
= r1
;
21486 /* X0 of the intersection is right.x0, if this is inside R1,
21487 otherwise there is no intersection. */
21488 if (right
->x
<= left
->x
+ left
->width
)
21490 result
->x
= right
->x
;
21492 /* The right end of the intersection is the minimum of the
21493 the right ends of left and right. */
21494 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
21497 /* Same game for Y. */
21499 upper
= r1
, lower
= r2
;
21501 upper
= r2
, lower
= r1
;
21503 /* The upper end of the intersection is lower.y0, if this is inside
21504 of upper. Otherwise, there is no intersection. */
21505 if (lower
->y
<= upper
->y
+ upper
->height
)
21507 result
->y
= lower
->y
;
21509 /* The lower end of the intersection is the minimum of the lower
21510 ends of upper and lower. */
21511 result
->height
= (min (lower
->y
+ lower
->height
,
21512 upper
->y
+ upper
->height
)
21514 intersection_p
= 1;
21518 return intersection_p
;
21521 #endif /* HAVE_WINDOW_SYSTEM */
21524 /***********************************************************************
21526 ***********************************************************************/
21531 Vwith_echo_area_save_vector
= Qnil
;
21532 staticpro (&Vwith_echo_area_save_vector
);
21534 Vmessage_stack
= Qnil
;
21535 staticpro (&Vmessage_stack
);
21537 Qinhibit_redisplay
= intern ("inhibit-redisplay");
21538 staticpro (&Qinhibit_redisplay
);
21540 message_dolog_marker1
= Fmake_marker ();
21541 staticpro (&message_dolog_marker1
);
21542 message_dolog_marker2
= Fmake_marker ();
21543 staticpro (&message_dolog_marker2
);
21544 message_dolog_marker3
= Fmake_marker ();
21545 staticpro (&message_dolog_marker3
);
21548 defsubr (&Sdump_frame_glyph_matrix
);
21549 defsubr (&Sdump_glyph_matrix
);
21550 defsubr (&Sdump_glyph_row
);
21551 defsubr (&Sdump_tool_bar_row
);
21552 defsubr (&Strace_redisplay
);
21553 defsubr (&Strace_to_stderr
);
21555 #ifdef HAVE_WINDOW_SYSTEM
21556 defsubr (&Stool_bar_lines_needed
);
21557 defsubr (&Slookup_image_map
);
21559 defsubr (&Sformat_mode_line
);
21561 staticpro (&Qmenu_bar_update_hook
);
21562 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
21564 staticpro (&Qoverriding_terminal_local_map
);
21565 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
21567 staticpro (&Qoverriding_local_map
);
21568 Qoverriding_local_map
= intern ("overriding-local-map");
21570 staticpro (&Qwindow_scroll_functions
);
21571 Qwindow_scroll_functions
= intern ("window-scroll-functions");
21573 staticpro (&Qredisplay_end_trigger_functions
);
21574 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
21576 staticpro (&Qinhibit_point_motion_hooks
);
21577 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
21579 QCdata
= intern (":data");
21580 staticpro (&QCdata
);
21581 Qdisplay
= intern ("display");
21582 staticpro (&Qdisplay
);
21583 Qspace_width
= intern ("space-width");
21584 staticpro (&Qspace_width
);
21585 Qraise
= intern ("raise");
21586 staticpro (&Qraise
);
21587 Qspace
= intern ("space");
21588 staticpro (&Qspace
);
21589 Qmargin
= intern ("margin");
21590 staticpro (&Qmargin
);
21591 Qpointer
= intern ("pointer");
21592 staticpro (&Qpointer
);
21593 Qleft_margin
= intern ("left-margin");
21594 staticpro (&Qleft_margin
);
21595 Qright_margin
= intern ("right-margin");
21596 staticpro (&Qright_margin
);
21597 Qcenter
= intern ("center");
21598 staticpro (&Qcenter
);
21599 QCalign_to
= intern (":align-to");
21600 staticpro (&QCalign_to
);
21601 QCrelative_width
= intern (":relative-width");
21602 staticpro (&QCrelative_width
);
21603 QCrelative_height
= intern (":relative-height");
21604 staticpro (&QCrelative_height
);
21605 QCeval
= intern (":eval");
21606 staticpro (&QCeval
);
21607 QCpropertize
= intern (":propertize");
21608 staticpro (&QCpropertize
);
21609 QCfile
= intern (":file");
21610 staticpro (&QCfile
);
21611 Qfontified
= intern ("fontified");
21612 staticpro (&Qfontified
);
21613 Qfontification_functions
= intern ("fontification-functions");
21614 staticpro (&Qfontification_functions
);
21615 Qtrailing_whitespace
= intern ("trailing-whitespace");
21616 staticpro (&Qtrailing_whitespace
);
21617 Qimage
= intern ("image");
21618 staticpro (&Qimage
);
21619 QCmap
= intern (":map");
21620 staticpro (&QCmap
);
21621 QCpointer
= intern (":pointer");
21622 staticpro (&QCpointer
);
21623 Qrect
= intern ("rect");
21624 staticpro (&Qrect
);
21625 Qcircle
= intern ("circle");
21626 staticpro (&Qcircle
);
21627 Qpoly
= intern ("poly");
21628 staticpro (&Qpoly
);
21629 Qmessage_truncate_lines
= intern ("message-truncate-lines");
21630 staticpro (&Qmessage_truncate_lines
);
21631 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
21632 staticpro (&Qcursor_in_non_selected_windows
);
21633 Qgrow_only
= intern ("grow-only");
21634 staticpro (&Qgrow_only
);
21635 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
21636 staticpro (&Qinhibit_menubar_update
);
21637 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
21638 staticpro (&Qinhibit_eval_during_redisplay
);
21639 Qposition
= intern ("position");
21640 staticpro (&Qposition
);
21641 Qbuffer_position
= intern ("buffer-position");
21642 staticpro (&Qbuffer_position
);
21643 Qobject
= intern ("object");
21644 staticpro (&Qobject
);
21645 Qbar
= intern ("bar");
21647 Qhbar
= intern ("hbar");
21648 staticpro (&Qhbar
);
21649 Qbox
= intern ("box");
21651 Qhollow
= intern ("hollow");
21652 staticpro (&Qhollow
);
21653 Qhand
= intern ("hand");
21654 staticpro (&Qhand
);
21655 Qarrow
= intern ("arrow");
21656 staticpro (&Qarrow
);
21657 Qtext
= intern ("text");
21658 staticpro (&Qtext
);
21659 Qrisky_local_variable
= intern ("risky-local-variable");
21660 staticpro (&Qrisky_local_variable
);
21661 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
21662 staticpro (&Qinhibit_free_realized_faces
);
21664 list_of_error
= Fcons (Fcons (intern ("error"),
21665 Fcons (intern ("void-variable"), Qnil
)),
21667 staticpro (&list_of_error
);
21669 Qlast_arrow_position
= intern ("last-arrow-position");
21670 staticpro (&Qlast_arrow_position
);
21671 Qlast_arrow_string
= intern ("last-arrow-string");
21672 staticpro (&Qlast_arrow_string
);
21674 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
21675 staticpro (&Qoverlay_arrow_string
);
21676 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
21677 staticpro (&Qoverlay_arrow_bitmap
);
21679 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
21680 staticpro (&echo_buffer
[0]);
21681 staticpro (&echo_buffer
[1]);
21683 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
21684 staticpro (&echo_area_buffer
[0]);
21685 staticpro (&echo_area_buffer
[1]);
21687 Vmessages_buffer_name
= build_string ("*Messages*");
21688 staticpro (&Vmessages_buffer_name
);
21690 mode_line_proptrans_alist
= Qnil
;
21691 staticpro (&mode_line_proptrans_alist
);
21693 mode_line_string_list
= Qnil
;
21694 staticpro (&mode_line_string_list
);
21696 help_echo_string
= Qnil
;
21697 staticpro (&help_echo_string
);
21698 help_echo_object
= Qnil
;
21699 staticpro (&help_echo_object
);
21700 help_echo_window
= Qnil
;
21701 staticpro (&help_echo_window
);
21702 previous_help_echo_string
= Qnil
;
21703 staticpro (&previous_help_echo_string
);
21704 help_echo_pos
= -1;
21706 #ifdef HAVE_WINDOW_SYSTEM
21707 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
21708 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
21709 For example, if a block cursor is over a tab, it will be drawn as
21710 wide as that tab on the display. */);
21711 x_stretch_cursor_p
= 0;
21714 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
21715 doc
: /* *Non-nil means highlight trailing whitespace.
21716 The face used for trailing whitespace is `trailing-whitespace'. */);
21717 Vshow_trailing_whitespace
= Qnil
;
21719 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
21720 doc
: /* *The pointer shape to show in void text areas.
21721 Nil means to show the text pointer. Other options are `arrow', `text',
21722 `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
21723 Vvoid_text_area_pointer
= Qarrow
;
21725 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
21726 doc
: /* Non-nil means don't actually do any redisplay.
21727 This is used for internal purposes. */);
21728 Vinhibit_redisplay
= Qnil
;
21730 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
21731 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
21732 Vglobal_mode_string
= Qnil
;
21734 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
21735 doc
: /* Marker for where to display an arrow on top of the buffer text.
21736 This must be the beginning of a line in order to work.
21737 See also `overlay-arrow-string'. */);
21738 Voverlay_arrow_position
= Qnil
;
21740 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
21741 doc
: /* String to display as an arrow in non-window frames.
21742 See also `overlay-arrow-position'. */);
21743 Voverlay_arrow_string
= Qnil
;
21745 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
21746 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
21747 The symbols on this list are examined during redisplay to determine
21748 where to display overlay arrows. */);
21749 Voverlay_arrow_variable_list
21750 = Fcons (intern ("overlay-arrow-position"), Qnil
);
21752 DEFVAR_INT ("scroll-step", &scroll_step
,
21753 doc
: /* *The number of lines to try scrolling a window by when point moves out.
21754 If that fails to bring point back on frame, point is centered instead.
21755 If this is zero, point is always centered after it moves off frame.
21756 If you want scrolling to always be a line at a time, you should set
21757 `scroll-conservatively' to a large value rather than set this to 1. */);
21759 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
21760 doc
: /* *Scroll up to this many lines, to bring point back on screen.
21761 A value of zero means to scroll the text to center point vertically
21762 in the window. */);
21763 scroll_conservatively
= 0;
21765 DEFVAR_INT ("scroll-margin", &scroll_margin
,
21766 doc
: /* *Number of lines of margin at the top and bottom of a window.
21767 Recenter the window whenever point gets within this many lines
21768 of the top or bottom of the window. */);
21771 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
21772 doc
: /* Pixels per inch on current display.
21773 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
21774 Vdisplay_pixels_per_inch
= make_float (72.0);
21777 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
21780 DEFVAR_BOOL ("truncate-partial-width-windows",
21781 &truncate_partial_width_windows
,
21782 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
21783 truncate_partial_width_windows
= 1;
21785 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
21786 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
21787 Any other value means to use the appropriate face, `mode-line',
21788 `header-line', or `menu' respectively. */);
21789 mode_line_inverse_video
= 1;
21791 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
21792 doc
: /* *Maximum buffer size for which line number should be displayed.
21793 If the buffer is bigger than this, the line number does not appear
21794 in the mode line. A value of nil means no limit. */);
21795 Vline_number_display_limit
= Qnil
;
21797 DEFVAR_INT ("line-number-display-limit-width",
21798 &line_number_display_limit_width
,
21799 doc
: /* *Maximum line width (in characters) for line number display.
21800 If the average length of the lines near point is bigger than this, then the
21801 line number may be omitted from the mode line. */);
21802 line_number_display_limit_width
= 200;
21804 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
21805 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
21806 highlight_nonselected_windows
= 0;
21808 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
21809 doc
: /* Non-nil if more than one frame is visible on this display.
21810 Minibuffer-only frames don't count, but iconified frames do.
21811 This variable is not guaranteed to be accurate except while processing
21812 `frame-title-format' and `icon-title-format'. */);
21814 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
21815 doc
: /* Template for displaying the title bar of visible frames.
21816 \(Assuming the window manager supports this feature.)
21817 This variable has the same structure as `mode-line-format' (which see),
21818 and is used only on frames for which no explicit name has been set
21819 \(see `modify-frame-parameters'). */);
21821 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
21822 doc
: /* Template for displaying the title bar of an iconified frame.
21823 \(Assuming the window manager supports this feature.)
21824 This variable has the same structure as `mode-line-format' (which see),
21825 and is used only on frames for which no explicit name has been set
21826 \(see `modify-frame-parameters'). */);
21828 = Vframe_title_format
21829 = Fcons (intern ("multiple-frames"),
21830 Fcons (build_string ("%b"),
21831 Fcons (Fcons (empty_string
,
21832 Fcons (intern ("invocation-name"),
21833 Fcons (build_string ("@"),
21834 Fcons (intern ("system-name"),
21838 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
21839 doc
: /* Maximum number of lines to keep in the message log buffer.
21840 If nil, disable message logging. If t, log messages but don't truncate
21841 the buffer when it becomes large. */);
21842 Vmessage_log_max
= make_number (50);
21844 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
21845 doc
: /* Functions called before redisplay, if window sizes have changed.
21846 The value should be a list of functions that take one argument.
21847 Just before redisplay, for each frame, if any of its windows have changed
21848 size since the last redisplay, or have been split or deleted,
21849 all the functions in the list are called, with the frame as argument. */);
21850 Vwindow_size_change_functions
= Qnil
;
21852 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
21853 doc
: /* List of Functions to call before redisplaying a window with scrolling.
21854 Each function is called with two arguments, the window
21855 and its new display-start position. Note that the value of `window-end'
21856 is not valid when these functions are called. */);
21857 Vwindow_scroll_functions
= Qnil
;
21859 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
21860 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
21861 mouse_autoselect_window
= 0;
21863 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
21864 doc
: /* *Non-nil means automatically resize tool-bars.
21865 This increases a tool-bar's height if not all tool-bar items are visible.
21866 It decreases a tool-bar's height when it would display blank lines
21868 auto_resize_tool_bars_p
= 1;
21870 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
21871 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
21872 auto_raise_tool_bar_buttons_p
= 1;
21874 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
21875 doc
: /* *Margin around tool-bar buttons in pixels.
21876 If an integer, use that for both horizontal and vertical margins.
21877 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
21878 HORZ specifying the horizontal margin, and VERT specifying the
21879 vertical margin. */);
21880 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
21882 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
21883 doc
: /* *Relief thickness of tool-bar buttons. */);
21884 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
21886 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
21887 doc
: /* List of functions to call to fontify regions of text.
21888 Each function is called with one argument POS. Functions must
21889 fontify a region starting at POS in the current buffer, and give
21890 fontified regions the property `fontified'. */);
21891 Vfontification_functions
= Qnil
;
21892 Fmake_variable_buffer_local (Qfontification_functions
);
21894 DEFVAR_BOOL ("unibyte-display-via-language-environment",
21895 &unibyte_display_via_language_environment
,
21896 doc
: /* *Non-nil means display unibyte text according to language environment.
21897 Specifically this means that unibyte non-ASCII characters
21898 are displayed by converting them to the equivalent multibyte characters
21899 according to the current language environment. As a result, they are
21900 displayed according to the current fontset. */);
21901 unibyte_display_via_language_environment
= 0;
21903 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
21904 doc
: /* *Maximum height for resizing mini-windows.
21905 If a float, it specifies a fraction of the mini-window frame's height.
21906 If an integer, it specifies a number of lines. */);
21907 Vmax_mini_window_height
= make_float (0.25);
21909 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
21910 doc
: /* *How to resize mini-windows.
21911 A value of nil means don't automatically resize mini-windows.
21912 A value of t means resize them to fit the text displayed in them.
21913 A value of `grow-only', the default, means let mini-windows grow
21914 only, until their display becomes empty, at which point the windows
21915 go back to their normal size. */);
21916 Vresize_mini_windows
= Qgrow_only
;
21918 DEFVAR_LISP ("cursor-in-non-selected-windows",
21919 &Vcursor_in_non_selected_windows
,
21920 doc
: /* *Cursor type to display in non-selected windows.
21921 t means to use hollow box cursor. See `cursor-type' for other values. */);
21922 Vcursor_in_non_selected_windows
= Qt
;
21924 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
21925 doc
: /* Alist specifying how to blink the cursor off.
21926 Each element has the form (ON-STATE . OFF-STATE). Whenever the
21927 `cursor-type' frame-parameter or variable equals ON-STATE,
21928 comparing using `equal', Emacs uses OFF-STATE to specify
21929 how to blink it off. */);
21930 Vblink_cursor_alist
= Qnil
;
21932 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
21933 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
21934 automatic_hscrolling_p
= 1;
21936 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
21937 doc
: /* *How many columns away from the window edge point is allowed to get
21938 before automatic hscrolling will horizontally scroll the window. */);
21939 hscroll_margin
= 5;
21941 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
21942 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
21943 When point is less than `automatic-hscroll-margin' columns from the window
21944 edge, automatic hscrolling will scroll the window by the amount of columns
21945 determined by this variable. If its value is a positive integer, scroll that
21946 many columns. If it's a positive floating-point number, it specifies the
21947 fraction of the window's width to scroll. If it's nil or zero, point will be
21948 centered horizontally after the scroll. Any other value, including negative
21949 numbers, are treated as if the value were zero.
21951 Automatic hscrolling always moves point outside the scroll margin, so if
21952 point was more than scroll step columns inside the margin, the window will
21953 scroll more than the value given by the scroll step.
21955 Note that the lower bound for automatic hscrolling specified by `scroll-left'
21956 and `scroll-right' overrides this variable's effect. */);
21957 Vhscroll_step
= make_number (0);
21959 DEFVAR_LISP ("image-types", &Vimage_types
,
21960 doc
: /* List of supported image types.
21961 Each element of the list is a symbol for a supported image type. */);
21962 Vimage_types
= Qnil
;
21964 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
21965 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
21966 Bind this around calls to `message' to let it take effect. */);
21967 message_truncate_lines
= 0;
21969 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
21970 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
21971 Can be used to update submenus whose contents should vary. */);
21972 Vmenu_bar_update_hook
= Qnil
;
21974 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
21975 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
21976 inhibit_menubar_update
= 0;
21978 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
21979 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
21980 inhibit_eval_during_redisplay
= 0;
21982 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
21983 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
21984 inhibit_free_realized_faces
= 0;
21987 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
21988 doc
: /* Inhibit try_window_id display optimization. */);
21989 inhibit_try_window_id
= 0;
21991 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
21992 doc
: /* Inhibit try_window_reusing display optimization. */);
21993 inhibit_try_window_reusing
= 0;
21995 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
21996 doc
: /* Inhibit try_cursor_movement display optimization. */);
21997 inhibit_try_cursor_movement
= 0;
21998 #endif /* GLYPH_DEBUG */
22002 /* Initialize this module when Emacs starts. */
22007 Lisp_Object root_window
;
22008 struct window
*mini_w
;
22010 current_header_line_height
= current_mode_line_height
= -1;
22012 CHARPOS (this_line_start_pos
) = 0;
22014 mini_w
= XWINDOW (minibuf_window
);
22015 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
22017 if (!noninteractive
)
22019 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
22022 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
22023 set_window_height (root_window
,
22024 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
22026 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
22027 set_window_height (minibuf_window
, 1, 0);
22029 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
22030 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
22032 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
22033 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
22034 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
22036 /* The default ellipsis glyphs `...'. */
22037 for (i
= 0; i
< 3; ++i
)
22038 default_invis_vector
[i
] = make_number ('.');
22042 /* Allocate the buffer for frame titles.
22043 Also used for `format-mode-line'. */
22045 frame_title_buf
= (char *) xmalloc (size
);
22046 frame_title_buf_end
= frame_title_buf
+ size
;
22047 frame_title_ptr
= NULL
;
22050 help_echo_showing_p
= 0;
22054 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
22055 (do not change this comment) */