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
*));
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 r
.y
= s
->ybase
+ glyph
->descent
- height
;
1801 #ifdef CONVERT_FROM_XRECT
1802 CONVERT_FROM_XRECT (r
, *nr
);
1808 #endif /* HAVE_WINDOW_SYSTEM */
1811 /***********************************************************************
1812 Lisp form evaluation
1813 ***********************************************************************/
1815 /* Error handler for safe_eval and safe_call. */
1818 safe_eval_handler (arg
)
1821 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1826 /* Evaluate SEXPR and return the result, or nil if something went
1827 wrong. Prevent redisplay during the evaluation. */
1835 if (inhibit_eval_during_redisplay
)
1839 int count
= SPECPDL_INDEX ();
1840 struct gcpro gcpro1
;
1843 specbind (Qinhibit_redisplay
, Qt
);
1844 /* Use Qt to ensure debugger does not run,
1845 so there is no possibility of wanting to redisplay. */
1846 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1849 val
= unbind_to (count
, val
);
1856 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1857 Return the result, or nil if something went wrong. Prevent
1858 redisplay during the evaluation. */
1861 safe_call (nargs
, args
)
1867 if (inhibit_eval_during_redisplay
)
1871 int count
= SPECPDL_INDEX ();
1872 struct gcpro gcpro1
;
1875 gcpro1
.nvars
= nargs
;
1876 specbind (Qinhibit_redisplay
, Qt
);
1877 /* Use Qt to ensure debugger does not run,
1878 so there is no possibility of wanting to redisplay. */
1879 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
1882 val
= unbind_to (count
, val
);
1889 /* Call function FN with one argument ARG.
1890 Return the result, or nil if something went wrong. */
1893 safe_call1 (fn
, arg
)
1894 Lisp_Object fn
, arg
;
1896 Lisp_Object args
[2];
1899 return safe_call (2, args
);
1904 /***********************************************************************
1906 ***********************************************************************/
1910 /* Define CHECK_IT to perform sanity checks on iterators.
1911 This is for debugging. It is too slow to do unconditionally. */
1917 if (it
->method
== next_element_from_string
)
1919 xassert (STRINGP (it
->string
));
1920 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1924 xassert (IT_STRING_CHARPOS (*it
) < 0);
1925 if (it
->method
== next_element_from_buffer
)
1927 /* Check that character and byte positions agree. */
1928 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1933 xassert (it
->current
.dpvec_index
>= 0);
1935 xassert (it
->current
.dpvec_index
< 0);
1938 #define CHECK_IT(IT) check_it ((IT))
1942 #define CHECK_IT(IT) (void) 0
1949 /* Check that the window end of window W is what we expect it
1950 to be---the last row in the current matrix displaying text. */
1953 check_window_end (w
)
1956 if (!MINI_WINDOW_P (w
)
1957 && !NILP (w
->window_end_valid
))
1959 struct glyph_row
*row
;
1960 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1961 XFASTINT (w
->window_end_vpos
)),
1963 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1964 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1968 #define CHECK_WINDOW_END(W) check_window_end ((W))
1970 #else /* not GLYPH_DEBUG */
1972 #define CHECK_WINDOW_END(W) (void) 0
1974 #endif /* not GLYPH_DEBUG */
1978 /***********************************************************************
1979 Iterator initialization
1980 ***********************************************************************/
1982 /* Initialize IT for displaying current_buffer in window W, starting
1983 at character position CHARPOS. CHARPOS < 0 means that no buffer
1984 position is specified which is useful when the iterator is assigned
1985 a position later. BYTEPOS is the byte position corresponding to
1986 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
1988 If ROW is not null, calls to produce_glyphs with IT as parameter
1989 will produce glyphs in that row.
1991 BASE_FACE_ID is the id of a base face to use. It must be one of
1992 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
1993 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
1994 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
1996 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
1997 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
1998 will be initialized to use the corresponding mode line glyph row of
1999 the desired matrix of W. */
2002 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2005 int charpos
, bytepos
;
2006 struct glyph_row
*row
;
2007 enum face_id base_face_id
;
2009 int highlight_region_p
;
2011 /* Some precondition checks. */
2012 xassert (w
!= NULL
&& it
!= NULL
);
2013 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2016 /* If face attributes have been changed since the last redisplay,
2017 free realized faces now because they depend on face definitions
2018 that might have changed. Don't free faces while there might be
2019 desired matrices pending which reference these faces. */
2020 if (face_change_count
&& !inhibit_free_realized_faces
)
2022 face_change_count
= 0;
2023 free_all_realized_faces (Qnil
);
2026 /* Use one of the mode line rows of W's desired matrix if
2030 if (base_face_id
== MODE_LINE_FACE_ID
2031 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2032 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2033 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2034 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2038 bzero (it
, sizeof *it
);
2039 it
->current
.overlay_string_index
= -1;
2040 it
->current
.dpvec_index
= -1;
2041 it
->base_face_id
= base_face_id
;
2043 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2045 /* The window in which we iterate over current_buffer: */
2046 XSETWINDOW (it
->window
, w
);
2048 it
->f
= XFRAME (w
->frame
);
2050 /* Extra space between lines (on window systems only). */
2051 if (base_face_id
== DEFAULT_FACE_ID
2052 && FRAME_WINDOW_P (it
->f
))
2054 if (NATNUMP (current_buffer
->extra_line_spacing
))
2055 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2056 else if (it
->f
->extra_line_spacing
> 0)
2057 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2060 /* If realized faces have been removed, e.g. because of face
2061 attribute changes of named faces, recompute them. When running
2062 in batch mode, the face cache of Vterminal_frame is null. If
2063 we happen to get called, make a dummy face cache. */
2064 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2065 init_frame_faces (it
->f
);
2066 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2067 recompute_basic_faces (it
->f
);
2069 /* Current value of the `space-width', and 'height' properties. */
2070 it
->space_width
= Qnil
;
2071 it
->font_height
= Qnil
;
2073 /* Are control characters displayed as `^C'? */
2074 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2076 /* -1 means everything between a CR and the following line end
2077 is invisible. >0 means lines indented more than this value are
2079 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2080 ? XFASTINT (current_buffer
->selective_display
)
2081 : (!NILP (current_buffer
->selective_display
)
2083 it
->selective_display_ellipsis_p
2084 = !NILP (current_buffer
->selective_display_ellipses
);
2086 /* Display table to use. */
2087 it
->dp
= window_display_table (w
);
2089 /* Are multibyte characters enabled in current_buffer? */
2090 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2092 /* Non-zero if we should highlight the region. */
2094 = (!NILP (Vtransient_mark_mode
)
2095 && !NILP (current_buffer
->mark_active
)
2096 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2098 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2099 start and end of a visible region in window IT->w. Set both to
2100 -1 to indicate no region. */
2101 if (highlight_region_p
2102 /* Maybe highlight only in selected window. */
2103 && (/* Either show region everywhere. */
2104 highlight_nonselected_windows
2105 /* Or show region in the selected window. */
2106 || w
== XWINDOW (selected_window
)
2107 /* Or show the region if we are in the mini-buffer and W is
2108 the window the mini-buffer refers to. */
2109 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2110 && WINDOWP (minibuf_selected_window
)
2111 && w
== XWINDOW (minibuf_selected_window
))))
2113 int charpos
= marker_position (current_buffer
->mark
);
2114 it
->region_beg_charpos
= min (PT
, charpos
);
2115 it
->region_end_charpos
= max (PT
, charpos
);
2118 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2120 /* Get the position at which the redisplay_end_trigger hook should
2121 be run, if it is to be run at all. */
2122 if (MARKERP (w
->redisplay_end_trigger
)
2123 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2124 it
->redisplay_end_trigger_charpos
2125 = marker_position (w
->redisplay_end_trigger
);
2126 else if (INTEGERP (w
->redisplay_end_trigger
))
2127 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2129 /* Correct bogus values of tab_width. */
2130 it
->tab_width
= XINT (current_buffer
->tab_width
);
2131 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2134 /* Are lines in the display truncated? */
2135 it
->truncate_lines_p
2136 = (base_face_id
!= DEFAULT_FACE_ID
2137 || XINT (it
->w
->hscroll
)
2138 || (truncate_partial_width_windows
2139 && !WINDOW_FULL_WIDTH_P (it
->w
))
2140 || !NILP (current_buffer
->truncate_lines
));
2142 /* Get dimensions of truncation and continuation glyphs. These are
2143 displayed as fringe bitmaps under X, so we don't need them for such
2145 if (!FRAME_WINDOW_P (it
->f
))
2147 if (it
->truncate_lines_p
)
2149 /* We will need the truncation glyph. */
2150 xassert (it
->glyph_row
== NULL
);
2151 produce_special_glyphs (it
, IT_TRUNCATION
);
2152 it
->truncation_pixel_width
= it
->pixel_width
;
2156 /* We will need the continuation glyph. */
2157 xassert (it
->glyph_row
== NULL
);
2158 produce_special_glyphs (it
, IT_CONTINUATION
);
2159 it
->continuation_pixel_width
= it
->pixel_width
;
2162 /* Reset these values to zero because the produce_special_glyphs
2163 above has changed them. */
2164 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2165 it
->phys_ascent
= it
->phys_descent
= 0;
2168 /* Set this after getting the dimensions of truncation and
2169 continuation glyphs, so that we don't produce glyphs when calling
2170 produce_special_glyphs, above. */
2171 it
->glyph_row
= row
;
2172 it
->area
= TEXT_AREA
;
2174 /* Get the dimensions of the display area. The display area
2175 consists of the visible window area plus a horizontally scrolled
2176 part to the left of the window. All x-values are relative to the
2177 start of this total display area. */
2178 if (base_face_id
!= DEFAULT_FACE_ID
)
2180 /* Mode lines, menu bar in terminal frames. */
2181 it
->first_visible_x
= 0;
2182 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2187 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2188 it
->last_visible_x
= (it
->first_visible_x
2189 + window_box_width (w
, TEXT_AREA
));
2191 /* If we truncate lines, leave room for the truncator glyph(s) at
2192 the right margin. Otherwise, leave room for the continuation
2193 glyph(s). Truncation and continuation glyphs are not inserted
2194 for window-based redisplay. */
2195 if (!FRAME_WINDOW_P (it
->f
))
2197 if (it
->truncate_lines_p
)
2198 it
->last_visible_x
-= it
->truncation_pixel_width
;
2200 it
->last_visible_x
-= it
->continuation_pixel_width
;
2203 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2204 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2207 /* Leave room for a border glyph. */
2208 if (!FRAME_WINDOW_P (it
->f
)
2209 && !WINDOW_RIGHTMOST_P (it
->w
))
2210 it
->last_visible_x
-= 1;
2212 it
->last_visible_y
= window_text_bottom_y (w
);
2214 /* For mode lines and alike, arrange for the first glyph having a
2215 left box line if the face specifies a box. */
2216 if (base_face_id
!= DEFAULT_FACE_ID
)
2220 it
->face_id
= base_face_id
;
2222 /* If we have a boxed mode line, make the first character appear
2223 with a left box line. */
2224 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2225 if (face
->box
!= FACE_NO_BOX
)
2226 it
->start_of_box_run_p
= 1;
2229 /* If a buffer position was specified, set the iterator there,
2230 getting overlays and face properties from that position. */
2231 if (charpos
>= BUF_BEG (current_buffer
))
2233 it
->end_charpos
= ZV
;
2235 IT_CHARPOS (*it
) = charpos
;
2237 /* Compute byte position if not specified. */
2238 if (bytepos
< charpos
)
2239 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2241 IT_BYTEPOS (*it
) = bytepos
;
2243 it
->start
= it
->current
;
2245 /* Compute faces etc. */
2246 reseat (it
, it
->current
.pos
, 1);
2253 /* Initialize IT for the display of window W with window start POS. */
2256 start_display (it
, w
, pos
)
2259 struct text_pos pos
;
2261 struct glyph_row
*row
;
2262 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2264 row
= w
->desired_matrix
->rows
+ first_vpos
;
2265 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2266 it
->first_vpos
= first_vpos
;
2268 if (!it
->truncate_lines_p
)
2270 int start_at_line_beg_p
;
2271 int first_y
= it
->current_y
;
2273 /* If window start is not at a line start, skip forward to POS to
2274 get the correct continuation lines width. */
2275 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2276 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2277 if (!start_at_line_beg_p
)
2281 reseat_at_previous_visible_line_start (it
);
2282 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2284 new_x
= it
->current_x
+ it
->pixel_width
;
2286 /* If lines are continued, this line may end in the middle
2287 of a multi-glyph character (e.g. a control character
2288 displayed as \003, or in the middle of an overlay
2289 string). In this case move_it_to above will not have
2290 taken us to the start of the continuation line but to the
2291 end of the continued line. */
2292 if (it
->current_x
> 0
2293 && !it
->truncate_lines_p
/* Lines are continued. */
2294 && (/* And glyph doesn't fit on the line. */
2295 new_x
> it
->last_visible_x
2296 /* Or it fits exactly and we're on a window
2298 || (new_x
== it
->last_visible_x
2299 && FRAME_WINDOW_P (it
->f
))))
2301 if (it
->current
.dpvec_index
>= 0
2302 || it
->current
.overlay_string_index
>= 0)
2304 set_iterator_to_next (it
, 1);
2305 move_it_in_display_line_to (it
, -1, -1, 0);
2308 it
->continuation_lines_width
+= it
->current_x
;
2311 /* We're starting a new display line, not affected by the
2312 height of the continued line, so clear the appropriate
2313 fields in the iterator structure. */
2314 it
->max_ascent
= it
->max_descent
= 0;
2315 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2317 it
->current_y
= first_y
;
2319 it
->current_x
= it
->hpos
= 0;
2323 #if 0 /* Don't assert the following because start_display is sometimes
2324 called intentionally with a window start that is not at a
2325 line start. Please leave this code in as a comment. */
2327 /* Window start should be on a line start, now. */
2328 xassert (it
->continuation_lines_width
2329 || IT_CHARPOS (it
) == BEGV
2330 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2335 /* Return 1 if POS is a position in ellipses displayed for invisible
2336 text. W is the window we display, for text property lookup. */
2339 in_ellipses_for_invisible_text_p (pos
, w
)
2340 struct display_pos
*pos
;
2343 Lisp_Object prop
, window
;
2345 int charpos
= CHARPOS (pos
->pos
);
2347 /* If POS specifies a position in a display vector, this might
2348 be for an ellipsis displayed for invisible text. We won't
2349 get the iterator set up for delivering that ellipsis unless
2350 we make sure that it gets aware of the invisible text. */
2351 if (pos
->dpvec_index
>= 0
2352 && pos
->overlay_string_index
< 0
2353 && CHARPOS (pos
->string_pos
) < 0
2355 && (XSETWINDOW (window
, w
),
2356 prop
= Fget_char_property (make_number (charpos
),
2357 Qinvisible
, window
),
2358 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2360 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2362 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2369 /* Initialize IT for stepping through current_buffer in window W,
2370 starting at position POS that includes overlay string and display
2371 vector/ control character translation position information. Value
2372 is zero if there are overlay strings with newlines at POS. */
2375 init_from_display_pos (it
, w
, pos
)
2378 struct display_pos
*pos
;
2380 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2381 int i
, overlay_strings_with_newlines
= 0;
2383 /* If POS specifies a position in a display vector, this might
2384 be for an ellipsis displayed for invisible text. We won't
2385 get the iterator set up for delivering that ellipsis unless
2386 we make sure that it gets aware of the invisible text. */
2387 if (in_ellipses_for_invisible_text_p (pos
, w
))
2393 /* Keep in mind: the call to reseat in init_iterator skips invisible
2394 text, so we might end up at a position different from POS. This
2395 is only a problem when POS is a row start after a newline and an
2396 overlay starts there with an after-string, and the overlay has an
2397 invisible property. Since we don't skip invisible text in
2398 display_line and elsewhere immediately after consuming the
2399 newline before the row start, such a POS will not be in a string,
2400 but the call to init_iterator below will move us to the
2402 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2404 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
2406 const char *s
= SDATA (it
->overlay_strings
[i
]);
2407 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2409 while (s
< e
&& *s
!= '\n')
2414 overlay_strings_with_newlines
= 1;
2419 /* If position is within an overlay string, set up IT to the right
2421 if (pos
->overlay_string_index
>= 0)
2425 /* If the first overlay string happens to have a `display'
2426 property for an image, the iterator will be set up for that
2427 image, and we have to undo that setup first before we can
2428 correct the overlay string index. */
2429 if (it
->method
== next_element_from_image
)
2432 /* We already have the first chunk of overlay strings in
2433 IT->overlay_strings. Load more until the one for
2434 pos->overlay_string_index is in IT->overlay_strings. */
2435 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2437 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2438 it
->current
.overlay_string_index
= 0;
2441 load_overlay_strings (it
, 0);
2442 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2446 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2447 relative_index
= (it
->current
.overlay_string_index
2448 % OVERLAY_STRING_CHUNK_SIZE
);
2449 it
->string
= it
->overlay_strings
[relative_index
];
2450 xassert (STRINGP (it
->string
));
2451 it
->current
.string_pos
= pos
->string_pos
;
2452 it
->method
= next_element_from_string
;
2455 #if 0 /* This is bogus because POS not having an overlay string
2456 position does not mean it's after the string. Example: A
2457 line starting with a before-string and initialization of IT
2458 to the previous row's end position. */
2459 else if (it
->current
.overlay_string_index
>= 0)
2461 /* If POS says we're already after an overlay string ending at
2462 POS, make sure to pop the iterator because it will be in
2463 front of that overlay string. When POS is ZV, we've thereby
2464 also ``processed'' overlay strings at ZV. */
2467 it
->current
.overlay_string_index
= -1;
2468 it
->method
= next_element_from_buffer
;
2469 if (CHARPOS (pos
->pos
) == ZV
)
2470 it
->overlay_strings_at_end_processed_p
= 1;
2474 if (CHARPOS (pos
->string_pos
) >= 0)
2476 /* Recorded position is not in an overlay string, but in another
2477 string. This can only be a string from a `display' property.
2478 IT should already be filled with that string. */
2479 it
->current
.string_pos
= pos
->string_pos
;
2480 xassert (STRINGP (it
->string
));
2483 /* Restore position in display vector translations, control
2484 character translations or ellipses. */
2485 if (pos
->dpvec_index
>= 0)
2487 if (it
->dpvec
== NULL
)
2488 get_next_display_element (it
);
2489 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2490 it
->current
.dpvec_index
= pos
->dpvec_index
;
2494 return !overlay_strings_with_newlines
;
2498 /* Initialize IT for stepping through current_buffer in window W
2499 starting at ROW->start. */
2502 init_to_row_start (it
, w
, row
)
2505 struct glyph_row
*row
;
2507 init_from_display_pos (it
, w
, &row
->start
);
2508 it
->start
= row
->start
;
2509 it
->continuation_lines_width
= row
->continuation_lines_width
;
2514 /* Initialize IT for stepping through current_buffer in window W
2515 starting in the line following ROW, i.e. starting at ROW->end.
2516 Value is zero if there are overlay strings with newlines at ROW's
2520 init_to_row_end (it
, w
, row
)
2523 struct glyph_row
*row
;
2527 if (init_from_display_pos (it
, w
, &row
->end
))
2529 if (row
->continued_p
)
2530 it
->continuation_lines_width
2531 = row
->continuation_lines_width
+ row
->pixel_width
;
2542 /***********************************************************************
2544 ***********************************************************************/
2546 /* Called when IT reaches IT->stop_charpos. Handle text property and
2547 overlay changes. Set IT->stop_charpos to the next position where
2554 enum prop_handled handled
;
2555 int handle_overlay_change_p
= 1;
2559 it
->current
.dpvec_index
= -1;
2563 handled
= HANDLED_NORMALLY
;
2565 /* Call text property handlers. */
2566 for (p
= it_props
; p
->handler
; ++p
)
2568 handled
= p
->handler (it
);
2570 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2572 else if (handled
== HANDLED_RETURN
)
2574 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2575 handle_overlay_change_p
= 0;
2578 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2580 /* Don't check for overlay strings below when set to deliver
2581 characters from a display vector. */
2582 if (it
->method
== next_element_from_display_vector
)
2583 handle_overlay_change_p
= 0;
2585 /* Handle overlay changes. */
2586 if (handle_overlay_change_p
)
2587 handled
= handle_overlay_change (it
);
2589 /* Determine where to stop next. */
2590 if (handled
== HANDLED_NORMALLY
)
2591 compute_stop_pos (it
);
2594 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2598 /* Compute IT->stop_charpos from text property and overlay change
2599 information for IT's current position. */
2602 compute_stop_pos (it
)
2605 register INTERVAL iv
, next_iv
;
2606 Lisp_Object object
, limit
, position
;
2608 /* If nowhere else, stop at the end. */
2609 it
->stop_charpos
= it
->end_charpos
;
2611 if (STRINGP (it
->string
))
2613 /* Strings are usually short, so don't limit the search for
2615 object
= it
->string
;
2617 position
= make_number (IT_STRING_CHARPOS (*it
));
2623 /* If next overlay change is in front of the current stop pos
2624 (which is IT->end_charpos), stop there. Note: value of
2625 next_overlay_change is point-max if no overlay change
2627 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2628 if (charpos
< it
->stop_charpos
)
2629 it
->stop_charpos
= charpos
;
2631 /* If showing the region, we have to stop at the region
2632 start or end because the face might change there. */
2633 if (it
->region_beg_charpos
> 0)
2635 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2636 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2637 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2638 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2641 /* Set up variables for computing the stop position from text
2642 property changes. */
2643 XSETBUFFER (object
, current_buffer
);
2644 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2645 position
= make_number (IT_CHARPOS (*it
));
2649 /* Get the interval containing IT's position. Value is a null
2650 interval if there isn't such an interval. */
2651 iv
= validate_interval_range (object
, &position
, &position
, 0);
2652 if (!NULL_INTERVAL_P (iv
))
2654 Lisp_Object values_here
[LAST_PROP_IDX
];
2657 /* Get properties here. */
2658 for (p
= it_props
; p
->handler
; ++p
)
2659 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2661 /* Look for an interval following iv that has different
2663 for (next_iv
= next_interval (iv
);
2664 (!NULL_INTERVAL_P (next_iv
)
2666 || XFASTINT (limit
) > next_iv
->position
));
2667 next_iv
= next_interval (next_iv
))
2669 for (p
= it_props
; p
->handler
; ++p
)
2671 Lisp_Object new_value
;
2673 new_value
= textget (next_iv
->plist
, *p
->name
);
2674 if (!EQ (values_here
[p
->idx
], new_value
))
2682 if (!NULL_INTERVAL_P (next_iv
))
2684 if (INTEGERP (limit
)
2685 && next_iv
->position
>= XFASTINT (limit
))
2686 /* No text property change up to limit. */
2687 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2689 /* Text properties change in next_iv. */
2690 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2694 xassert (STRINGP (it
->string
)
2695 || (it
->stop_charpos
>= BEGV
2696 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2700 /* Return the position of the next overlay change after POS in
2701 current_buffer. Value is point-max if no overlay change
2702 follows. This is like `next-overlay-change' but doesn't use
2706 next_overlay_change (pos
)
2711 Lisp_Object
*overlays
;
2715 /* Get all overlays at the given position. */
2717 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2718 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2719 if (noverlays
> len
)
2722 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2723 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2726 /* If any of these overlays ends before endpos,
2727 use its ending point instead. */
2728 for (i
= 0; i
< noverlays
; ++i
)
2733 oend
= OVERLAY_END (overlays
[i
]);
2734 oendpos
= OVERLAY_POSITION (oend
);
2735 endpos
= min (endpos
, oendpos
);
2743 /***********************************************************************
2745 ***********************************************************************/
2747 /* Handle changes in the `fontified' property of the current buffer by
2748 calling hook functions from Qfontification_functions to fontify
2751 static enum prop_handled
2752 handle_fontified_prop (it
)
2755 Lisp_Object prop
, pos
;
2756 enum prop_handled handled
= HANDLED_NORMALLY
;
2758 /* Get the value of the `fontified' property at IT's current buffer
2759 position. (The `fontified' property doesn't have a special
2760 meaning in strings.) If the value is nil, call functions from
2761 Qfontification_functions. */
2762 if (!STRINGP (it
->string
)
2764 && !NILP (Vfontification_functions
)
2765 && !NILP (Vrun_hooks
)
2766 && (pos
= make_number (IT_CHARPOS (*it
)),
2767 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2770 int count
= SPECPDL_INDEX ();
2773 val
= Vfontification_functions
;
2774 specbind (Qfontification_functions
, Qnil
);
2776 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2777 safe_call1 (val
, pos
);
2780 Lisp_Object globals
, fn
;
2781 struct gcpro gcpro1
, gcpro2
;
2784 GCPRO2 (val
, globals
);
2786 for (; CONSP (val
); val
= XCDR (val
))
2792 /* A value of t indicates this hook has a local
2793 binding; it means to run the global binding too.
2794 In a global value, t should not occur. If it
2795 does, we must ignore it to avoid an endless
2797 for (globals
= Fdefault_value (Qfontification_functions
);
2799 globals
= XCDR (globals
))
2801 fn
= XCAR (globals
);
2803 safe_call1 (fn
, pos
);
2807 safe_call1 (fn
, pos
);
2813 unbind_to (count
, Qnil
);
2815 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2816 something. This avoids an endless loop if they failed to
2817 fontify the text for which reason ever. */
2818 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2819 handled
= HANDLED_RECOMPUTE_PROPS
;
2827 /***********************************************************************
2829 ***********************************************************************/
2831 /* Set up iterator IT from face properties at its current position.
2832 Called from handle_stop. */
2834 static enum prop_handled
2835 handle_face_prop (it
)
2838 int new_face_id
, next_stop
;
2840 if (!STRINGP (it
->string
))
2843 = face_at_buffer_position (it
->w
,
2845 it
->region_beg_charpos
,
2846 it
->region_end_charpos
,
2849 + TEXT_PROP_DISTANCE_LIMIT
),
2852 /* Is this a start of a run of characters with box face?
2853 Caveat: this can be called for a freshly initialized
2854 iterator; face_id is -1 in this case. We know that the new
2855 face will not change until limit, i.e. if the new face has a
2856 box, all characters up to limit will have one. But, as
2857 usual, we don't know whether limit is really the end. */
2858 if (new_face_id
!= it
->face_id
)
2860 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2862 /* If new face has a box but old face has not, this is
2863 the start of a run of characters with box, i.e. it has
2864 a shadow on the left side. The value of face_id of the
2865 iterator will be -1 if this is the initial call that gets
2866 the face. In this case, we have to look in front of IT's
2867 position and see whether there is a face != new_face_id. */
2868 it
->start_of_box_run_p
2869 = (new_face
->box
!= FACE_NO_BOX
2870 && (it
->face_id
>= 0
2871 || IT_CHARPOS (*it
) == BEG
2872 || new_face_id
!= face_before_it_pos (it
)));
2873 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2878 int base_face_id
, bufpos
;
2880 if (it
->current
.overlay_string_index
>= 0)
2881 bufpos
= IT_CHARPOS (*it
);
2885 /* For strings from a buffer, i.e. overlay strings or strings
2886 from a `display' property, use the face at IT's current
2887 buffer position as the base face to merge with, so that
2888 overlay strings appear in the same face as surrounding
2889 text, unless they specify their own faces. */
2890 base_face_id
= underlying_face_id (it
);
2892 new_face_id
= face_at_string_position (it
->w
,
2894 IT_STRING_CHARPOS (*it
),
2896 it
->region_beg_charpos
,
2897 it
->region_end_charpos
,
2901 #if 0 /* This shouldn't be neccessary. Let's check it. */
2902 /* If IT is used to display a mode line we would really like to
2903 use the mode line face instead of the frame's default face. */
2904 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2905 && new_face_id
== DEFAULT_FACE_ID
)
2906 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
2909 /* Is this a start of a run of characters with box? Caveat:
2910 this can be called for a freshly allocated iterator; face_id
2911 is -1 is this case. We know that the new face will not
2912 change until the next check pos, i.e. if the new face has a
2913 box, all characters up to that position will have a
2914 box. But, as usual, we don't know whether that position
2915 is really the end. */
2916 if (new_face_id
!= it
->face_id
)
2918 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2919 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2921 /* If new face has a box but old face hasn't, this is the
2922 start of a run of characters with box, i.e. it has a
2923 shadow on the left side. */
2924 it
->start_of_box_run_p
2925 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2926 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2930 it
->face_id
= new_face_id
;
2931 return HANDLED_NORMALLY
;
2935 /* Return the ID of the face ``underlying'' IT's current position,
2936 which is in a string. If the iterator is associated with a
2937 buffer, return the face at IT's current buffer position.
2938 Otherwise, use the iterator's base_face_id. */
2941 underlying_face_id (it
)
2944 int face_id
= it
->base_face_id
, i
;
2946 xassert (STRINGP (it
->string
));
2948 for (i
= it
->sp
- 1; i
>= 0; --i
)
2949 if (NILP (it
->stack
[i
].string
))
2950 face_id
= it
->stack
[i
].face_id
;
2956 /* Compute the face one character before or after the current position
2957 of IT. BEFORE_P non-zero means get the face in front of IT's
2958 position. Value is the id of the face. */
2961 face_before_or_after_it_pos (it
, before_p
)
2966 int next_check_charpos
;
2967 struct text_pos pos
;
2969 xassert (it
->s
== NULL
);
2971 if (STRINGP (it
->string
))
2973 int bufpos
, base_face_id
;
2975 /* No face change past the end of the string (for the case
2976 we are padding with spaces). No face change before the
2978 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
2979 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2982 /* Set pos to the position before or after IT's current position. */
2984 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2986 /* For composition, we must check the character after the
2988 pos
= (it
->what
== IT_COMPOSITION
2989 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2990 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2992 if (it
->current
.overlay_string_index
>= 0)
2993 bufpos
= IT_CHARPOS (*it
);
2997 base_face_id
= underlying_face_id (it
);
2999 /* Get the face for ASCII, or unibyte. */
3000 face_id
= face_at_string_position (it
->w
,
3004 it
->region_beg_charpos
,
3005 it
->region_end_charpos
,
3006 &next_check_charpos
,
3009 /* Correct the face for charsets different from ASCII. Do it
3010 for the multibyte case only. The face returned above is
3011 suitable for unibyte text if IT->string is unibyte. */
3012 if (STRING_MULTIBYTE (it
->string
))
3014 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3015 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3017 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3019 c
= string_char_and_length (p
, rest
, &len
);
3020 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3025 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3026 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3029 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3030 pos
= it
->current
.pos
;
3033 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3036 if (it
->what
== IT_COMPOSITION
)
3037 /* For composition, we must check the position after the
3039 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3041 INC_TEXT_POS (pos
, it
->multibyte_p
);
3044 /* Determine face for CHARSET_ASCII, or unibyte. */
3045 face_id
= face_at_buffer_position (it
->w
,
3047 it
->region_beg_charpos
,
3048 it
->region_end_charpos
,
3049 &next_check_charpos
,
3052 /* Correct the face for charsets different from ASCII. Do it
3053 for the multibyte case only. The face returned above is
3054 suitable for unibyte text if current_buffer is unibyte. */
3055 if (it
->multibyte_p
)
3057 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3058 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3059 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3068 /***********************************************************************
3070 ***********************************************************************/
3072 /* Set up iterator IT from invisible properties at its current
3073 position. Called from handle_stop. */
3075 static enum prop_handled
3076 handle_invisible_prop (it
)
3079 enum prop_handled handled
= HANDLED_NORMALLY
;
3081 if (STRINGP (it
->string
))
3083 extern Lisp_Object Qinvisible
;
3084 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3086 /* Get the value of the invisible text property at the
3087 current position. Value will be nil if there is no such
3089 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3090 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3093 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3095 handled
= HANDLED_RECOMPUTE_PROPS
;
3097 /* Get the position at which the next change of the
3098 invisible text property can be found in IT->string.
3099 Value will be nil if the property value is the same for
3100 all the rest of IT->string. */
3101 XSETINT (limit
, SCHARS (it
->string
));
3102 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3105 /* Text at current position is invisible. The next
3106 change in the property is at position end_charpos.
3107 Move IT's current position to that position. */
3108 if (INTEGERP (end_charpos
)
3109 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3111 struct text_pos old
;
3112 old
= it
->current
.string_pos
;
3113 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3114 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3118 /* The rest of the string is invisible. If this is an
3119 overlay string, proceed with the next overlay string
3120 or whatever comes and return a character from there. */
3121 if (it
->current
.overlay_string_index
>= 0)
3123 next_overlay_string (it
);
3124 /* Don't check for overlay strings when we just
3125 finished processing them. */
3126 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3130 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3131 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3138 int invis_p
, newpos
, next_stop
, start_charpos
;
3139 Lisp_Object pos
, prop
, overlay
;
3141 /* First of all, is there invisible text at this position? */
3142 start_charpos
= IT_CHARPOS (*it
);
3143 pos
= make_number (IT_CHARPOS (*it
));
3144 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3146 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3148 /* If we are on invisible text, skip over it. */
3149 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3151 /* Record whether we have to display an ellipsis for the
3153 int display_ellipsis_p
= invis_p
== 2;
3155 handled
= HANDLED_RECOMPUTE_PROPS
;
3157 /* Loop skipping over invisible text. The loop is left at
3158 ZV or with IT on the first char being visible again. */
3161 /* Try to skip some invisible text. Return value is the
3162 position reached which can be equal to IT's position
3163 if there is nothing invisible here. This skips both
3164 over invisible text properties and overlays with
3165 invisible property. */
3166 newpos
= skip_invisible (IT_CHARPOS (*it
),
3167 &next_stop
, ZV
, it
->window
);
3169 /* If we skipped nothing at all we weren't at invisible
3170 text in the first place. If everything to the end of
3171 the buffer was skipped, end the loop. */
3172 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3176 /* We skipped some characters but not necessarily
3177 all there are. Check if we ended up on visible
3178 text. Fget_char_property returns the property of
3179 the char before the given position, i.e. if we
3180 get invis_p = 0, this means that the char at
3181 newpos is visible. */
3182 pos
= make_number (newpos
);
3183 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3184 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3187 /* If we ended up on invisible text, proceed to
3188 skip starting with next_stop. */
3190 IT_CHARPOS (*it
) = next_stop
;
3194 /* The position newpos is now either ZV or on visible text. */
3195 IT_CHARPOS (*it
) = newpos
;
3196 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3198 /* If there are before-strings at the start of invisible
3199 text, and the text is invisible because of a text
3200 property, arrange to show before-strings because 20.x did
3201 it that way. (If the text is invisible because of an
3202 overlay property instead of a text property, this is
3203 already handled in the overlay code.) */
3205 && get_overlay_strings (it
, start_charpos
))
3207 handled
= HANDLED_RECOMPUTE_PROPS
;
3208 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3210 else if (display_ellipsis_p
)
3211 setup_for_ellipsis (it
);
3219 /* Make iterator IT return `...' next. */
3222 setup_for_ellipsis (it
)
3226 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3228 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3229 it
->dpvec
= v
->contents
;
3230 it
->dpend
= v
->contents
+ v
->size
;
3234 /* Default `...'. */
3235 it
->dpvec
= default_invis_vector
;
3236 it
->dpend
= default_invis_vector
+ 3;
3239 /* The ellipsis display does not replace the display of the
3240 character at the new position. Indicate this by setting
3241 IT->dpvec_char_len to zero. */
3242 it
->dpvec_char_len
= 0;
3244 it
->current
.dpvec_index
= 0;
3245 it
->method
= next_element_from_display_vector
;
3250 /***********************************************************************
3252 ***********************************************************************/
3254 /* Set up iterator IT from `display' property at its current position.
3255 Called from handle_stop. */
3257 static enum prop_handled
3258 handle_display_prop (it
)
3261 Lisp_Object prop
, object
;
3262 struct text_pos
*position
;
3263 int display_replaced_p
= 0;
3265 if (STRINGP (it
->string
))
3267 object
= it
->string
;
3268 position
= &it
->current
.string_pos
;
3272 object
= it
->w
->buffer
;
3273 position
= &it
->current
.pos
;
3276 /* Reset those iterator values set from display property values. */
3277 it
->font_height
= Qnil
;
3278 it
->space_width
= Qnil
;
3281 /* We don't support recursive `display' properties, i.e. string
3282 values that have a string `display' property, that have a string
3283 `display' property etc. */
3284 if (!it
->string_from_display_prop_p
)
3285 it
->area
= TEXT_AREA
;
3287 prop
= Fget_char_property (make_number (position
->charpos
),
3290 return HANDLED_NORMALLY
;
3293 /* Simple properties. */
3294 && !EQ (XCAR (prop
), Qimage
)
3295 && !EQ (XCAR (prop
), Qspace
)
3296 && !EQ (XCAR (prop
), Qwhen
)
3297 && !EQ (XCAR (prop
), Qspace_width
)
3298 && !EQ (XCAR (prop
), Qheight
)
3299 && !EQ (XCAR (prop
), Qraise
)
3300 /* Marginal area specifications. */
3301 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3302 && !EQ (XCAR (prop
), Qleft_fringe
)
3303 && !EQ (XCAR (prop
), Qright_fringe
)
3304 && !NILP (XCAR (prop
)))
3306 for (; CONSP (prop
); prop
= XCDR (prop
))
3308 if (handle_single_display_prop (it
, XCAR (prop
), object
,
3309 position
, display_replaced_p
))
3310 display_replaced_p
= 1;
3313 else if (VECTORP (prop
))
3316 for (i
= 0; i
< ASIZE (prop
); ++i
)
3317 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
3318 position
, display_replaced_p
))
3319 display_replaced_p
= 1;
3323 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
3324 display_replaced_p
= 1;
3327 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3331 /* Value is the position of the end of the `display' property starting
3332 at START_POS in OBJECT. */
3334 static struct text_pos
3335 display_prop_end (it
, object
, start_pos
)
3338 struct text_pos start_pos
;
3341 struct text_pos end_pos
;
3343 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3344 Qdisplay
, object
, Qnil
);
3345 CHARPOS (end_pos
) = XFASTINT (end
);
3346 if (STRINGP (object
))
3347 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3349 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3355 /* Set up IT from a single `display' sub-property value PROP. OBJECT
3356 is the object in which the `display' property was found. *POSITION
3357 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3358 means that we previously saw a display sub-property which already
3359 replaced text display with something else, for example an image;
3360 ignore such properties after the first one has been processed.
3362 If PROP is a `space' or `image' sub-property, set *POSITION to the
3363 end position of the `display' property.
3365 Value is non-zero if something was found which replaces the display
3366 of buffer or string text. */
3369 handle_single_display_prop (it
, prop
, object
, position
,
3370 display_replaced_before_p
)
3374 struct text_pos
*position
;
3375 int display_replaced_before_p
;
3378 int replaces_text_display_p
= 0;
3381 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
3382 evaluated. If the result is nil, VALUE is ignored. */
3384 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3393 if (!NILP (form
) && !EQ (form
, Qt
))
3395 int count
= SPECPDL_INDEX ();
3396 struct gcpro gcpro1
;
3398 /* Bind `object' to the object having the `display' property, a
3399 buffer or string. Bind `position' to the position in the
3400 object where the property was found, and `buffer-position'
3401 to the current position in the buffer. */
3402 specbind (Qobject
, object
);
3403 specbind (Qposition
, make_number (CHARPOS (*position
)));
3404 specbind (Qbuffer_position
,
3405 make_number (STRINGP (object
)
3406 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3408 form
= safe_eval (form
);
3410 unbind_to (count
, Qnil
);
3417 && EQ (XCAR (prop
), Qheight
)
3418 && CONSP (XCDR (prop
)))
3420 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3423 /* `(height HEIGHT)'. */
3424 it
->font_height
= XCAR (XCDR (prop
));
3425 if (!NILP (it
->font_height
))
3427 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3428 int new_height
= -1;
3430 if (CONSP (it
->font_height
)
3431 && (EQ (XCAR (it
->font_height
), Qplus
)
3432 || EQ (XCAR (it
->font_height
), Qminus
))
3433 && CONSP (XCDR (it
->font_height
))
3434 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3436 /* `(+ N)' or `(- N)' where N is an integer. */
3437 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3438 if (EQ (XCAR (it
->font_height
), Qplus
))
3440 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3442 else if (FUNCTIONP (it
->font_height
))
3444 /* Call function with current height as argument.
3445 Value is the new height. */
3447 height
= safe_call1 (it
->font_height
,
3448 face
->lface
[LFACE_HEIGHT_INDEX
]);
3449 if (NUMBERP (height
))
3450 new_height
= XFLOATINT (height
);
3452 else if (NUMBERP (it
->font_height
))
3454 /* Value is a multiple of the canonical char height. */
3457 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3458 new_height
= (XFLOATINT (it
->font_height
)
3459 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3463 /* Evaluate IT->font_height with `height' bound to the
3464 current specified height to get the new height. */
3466 int count
= SPECPDL_INDEX ();
3468 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3469 value
= safe_eval (it
->font_height
);
3470 unbind_to (count
, Qnil
);
3472 if (NUMBERP (value
))
3473 new_height
= XFLOATINT (value
);
3477 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3480 else if (CONSP (prop
)
3481 && EQ (XCAR (prop
), Qspace_width
)
3482 && CONSP (XCDR (prop
)))
3484 /* `(space_width WIDTH)'. */
3485 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3488 value
= XCAR (XCDR (prop
));
3489 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3490 it
->space_width
= value
;
3492 else if (CONSP (prop
)
3493 && EQ (XCAR (prop
), Qraise
)
3494 && CONSP (XCDR (prop
)))
3496 /* `(raise FACTOR)'. */
3497 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3500 #ifdef HAVE_WINDOW_SYSTEM
3501 value
= XCAR (XCDR (prop
));
3502 if (NUMBERP (value
))
3504 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3505 it
->voffset
= - (XFLOATINT (value
)
3506 * (FONT_HEIGHT (face
->font
)));
3508 #endif /* HAVE_WINDOW_SYSTEM */
3510 else if (!it
->string_from_display_prop_p
)
3512 /* `((margin left-margin) VALUE)' or `((margin right-margin)
3513 VALUE) or `((margin nil) VALUE)' or VALUE. */
3514 Lisp_Object location
, value
;
3515 struct text_pos start_pos
;
3518 /* Characters having this form of property are not displayed, so
3519 we have to find the end of the property. */
3520 start_pos
= *position
;
3521 *position
= display_prop_end (it
, object
, start_pos
);
3524 /* Let's stop at the new position and assume that all
3525 text properties change there. */
3526 it
->stop_charpos
= position
->charpos
;
3529 && (EQ (XCAR (prop
), Qleft_fringe
)
3530 || EQ (XCAR (prop
), Qright_fringe
))
3531 && CONSP (XCDR (prop
)))
3533 unsigned face_id
= DEFAULT_FACE_ID
;
3535 /* Save current settings of IT so that we can restore them
3536 when we are finished with the glyph property value. */
3538 /* `(left-fringe BITMAP FACE)'. */
3539 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3542 #ifdef HAVE_WINDOW_SYSTEM
3543 value
= XCAR (XCDR (prop
));
3544 if (!NUMBERP (value
)
3545 || !valid_fringe_bitmap_id_p (XINT (value
)))
3548 if (CONSP (XCDR (XCDR (prop
))))
3550 Lisp_Object face_name
= XCAR (XCDR (XCDR (prop
)));
3552 face_id
= lookup_named_face (it
->f
, face_name
, 'A');
3559 it
->area
= TEXT_AREA
;
3560 it
->what
= IT_IMAGE
;
3561 it
->image_id
= -1; /* no image */
3562 it
->position
= start_pos
;
3563 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3564 it
->method
= next_element_from_image
;
3565 it
->face_id
= face_id
;
3567 /* Say that we haven't consumed the characters with
3568 `display' property yet. The call to pop_it in
3569 set_iterator_to_next will clean this up. */
3570 *position
= start_pos
;
3572 if (EQ (XCAR (prop
), Qleft_fringe
))
3574 it
->left_user_fringe_bitmap
= XINT (value
);
3575 it
->left_user_fringe_face_id
= face_id
;
3579 it
->right_user_fringe_bitmap
= XINT (value
);
3580 it
->right_user_fringe_face_id
= face_id
;
3582 #endif /* HAVE_WINDOW_SYSTEM */
3586 location
= Qunbound
;
3587 if (CONSP (prop
) && CONSP (XCAR (prop
)))
3591 value
= XCDR (prop
);
3593 value
= XCAR (value
);
3596 if (EQ (XCAR (tem
), Qmargin
)
3597 && (tem
= XCDR (tem
),
3598 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3600 || EQ (tem
, Qleft_margin
)
3601 || EQ (tem
, Qright_margin
))))
3605 if (EQ (location
, Qunbound
))
3611 valid_p
= (STRINGP (value
)
3612 #ifdef HAVE_WINDOW_SYSTEM
3613 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
3614 #endif /* not HAVE_WINDOW_SYSTEM */
3615 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
3617 if ((EQ (location
, Qleft_margin
)
3618 || EQ (location
, Qright_margin
)
3621 && !display_replaced_before_p
)
3623 replaces_text_display_p
= 1;
3625 /* Save current settings of IT so that we can restore them
3626 when we are finished with the glyph property value. */
3629 if (NILP (location
))
3630 it
->area
= TEXT_AREA
;
3631 else if (EQ (location
, Qleft_margin
))
3632 it
->area
= LEFT_MARGIN_AREA
;
3634 it
->area
= RIGHT_MARGIN_AREA
;
3636 if (STRINGP (value
))
3639 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3640 it
->current
.overlay_string_index
= -1;
3641 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3642 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3643 it
->method
= next_element_from_string
;
3644 it
->stop_charpos
= 0;
3645 it
->string_from_display_prop_p
= 1;
3646 /* Say that we haven't consumed the characters with
3647 `display' property yet. The call to pop_it in
3648 set_iterator_to_next will clean this up. */
3649 *position
= start_pos
;
3651 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3653 it
->method
= next_element_from_stretch
;
3655 it
->current
.pos
= it
->position
= start_pos
;
3657 #ifdef HAVE_WINDOW_SYSTEM
3660 it
->what
= IT_IMAGE
;
3661 it
->image_id
= lookup_image (it
->f
, value
);
3662 it
->position
= start_pos
;
3663 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3664 it
->method
= next_element_from_image
;
3666 /* Say that we haven't consumed the characters with
3667 `display' property yet. The call to pop_it in
3668 set_iterator_to_next will clean this up. */
3669 *position
= start_pos
;
3671 #endif /* HAVE_WINDOW_SYSTEM */
3674 /* Invalid property or property not supported. Restore
3675 the position to what it was before. */
3676 *position
= start_pos
;
3679 return replaces_text_display_p
;
3683 /* Check if PROP is a display sub-property value whose text should be
3684 treated as intangible. */
3687 single_display_prop_intangible_p (prop
)
3690 /* Skip over `when FORM'. */
3691 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3705 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3706 we don't need to treat text as intangible. */
3707 if (EQ (XCAR (prop
), Qmargin
))
3715 || EQ (XCAR (prop
), Qleft_margin
)
3716 || EQ (XCAR (prop
), Qright_margin
))
3720 return (CONSP (prop
)
3721 && (EQ (XCAR (prop
), Qimage
)
3722 || EQ (XCAR (prop
), Qspace
)));
3726 /* Check if PROP is a display property value whose text should be
3727 treated as intangible. */
3730 display_prop_intangible_p (prop
)
3734 && CONSP (XCAR (prop
))
3735 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3737 /* A list of sub-properties. */
3738 while (CONSP (prop
))
3740 if (single_display_prop_intangible_p (XCAR (prop
)))
3745 else if (VECTORP (prop
))
3747 /* A vector of sub-properties. */
3749 for (i
= 0; i
< ASIZE (prop
); ++i
)
3750 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3754 return single_display_prop_intangible_p (prop
);
3760 /* Return 1 if PROP is a display sub-property value containing STRING. */
3763 single_display_prop_string_p (prop
, string
)
3764 Lisp_Object prop
, string
;
3766 if (EQ (string
, prop
))
3769 /* Skip over `when FORM'. */
3770 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3779 /* Skip over `margin LOCATION'. */
3780 if (EQ (XCAR (prop
), Qmargin
))
3791 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3795 /* Return 1 if STRING appears in the `display' property PROP. */
3798 display_prop_string_p (prop
, string
)
3799 Lisp_Object prop
, string
;
3802 && CONSP (XCAR (prop
))
3803 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3805 /* A list of sub-properties. */
3806 while (CONSP (prop
))
3808 if (single_display_prop_string_p (XCAR (prop
), string
))
3813 else if (VECTORP (prop
))
3815 /* A vector of sub-properties. */
3817 for (i
= 0; i
< ASIZE (prop
); ++i
)
3818 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3822 return single_display_prop_string_p (prop
, string
);
3828 /* Determine from which buffer position in W's buffer STRING comes
3829 from. AROUND_CHARPOS is an approximate position where it could
3830 be from. Value is the buffer position or 0 if it couldn't be
3833 W's buffer must be current.
3835 This function is necessary because we don't record buffer positions
3836 in glyphs generated from strings (to keep struct glyph small).
3837 This function may only use code that doesn't eval because it is
3838 called asynchronously from note_mouse_highlight. */
3841 string_buffer_position (w
, string
, around_charpos
)
3846 Lisp_Object limit
, prop
, pos
;
3847 const int MAX_DISTANCE
= 1000;
3850 pos
= make_number (around_charpos
);
3851 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3852 while (!found
&& !EQ (pos
, limit
))
3854 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3855 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3858 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3863 pos
= make_number (around_charpos
);
3864 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3865 while (!found
&& !EQ (pos
, limit
))
3867 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3868 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3871 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3876 return found
? XINT (pos
) : 0;
3881 /***********************************************************************
3882 `composition' property
3883 ***********************************************************************/
3885 /* Set up iterator IT from `composition' property at its current
3886 position. Called from handle_stop. */
3888 static enum prop_handled
3889 handle_composition_prop (it
)
3892 Lisp_Object prop
, string
;
3893 int pos
, pos_byte
, end
;
3894 enum prop_handled handled
= HANDLED_NORMALLY
;
3896 if (STRINGP (it
->string
))
3898 pos
= IT_STRING_CHARPOS (*it
);
3899 pos_byte
= IT_STRING_BYTEPOS (*it
);
3900 string
= it
->string
;
3904 pos
= IT_CHARPOS (*it
);
3905 pos_byte
= IT_BYTEPOS (*it
);
3909 /* If there's a valid composition and point is not inside of the
3910 composition (in the case that the composition is from the current
3911 buffer), draw a glyph composed from the composition components. */
3912 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3913 && COMPOSITION_VALID_P (pos
, end
, prop
)
3914 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3916 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3920 it
->method
= next_element_from_composition
;
3922 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3923 /* For a terminal, draw only the first character of the
3925 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3926 it
->len
= (STRINGP (it
->string
)
3927 ? string_char_to_byte (it
->string
, end
)
3928 : CHAR_TO_BYTE (end
)) - pos_byte
;
3929 it
->stop_charpos
= end
;
3930 handled
= HANDLED_RETURN
;
3939 /***********************************************************************
3941 ***********************************************************************/
3943 /* The following structure is used to record overlay strings for
3944 later sorting in load_overlay_strings. */
3946 struct overlay_entry
3948 Lisp_Object overlay
;
3955 /* Set up iterator IT from overlay strings at its current position.
3956 Called from handle_stop. */
3958 static enum prop_handled
3959 handle_overlay_change (it
)
3962 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
3963 return HANDLED_RECOMPUTE_PROPS
;
3965 return HANDLED_NORMALLY
;
3969 /* Set up the next overlay string for delivery by IT, if there is an
3970 overlay string to deliver. Called by set_iterator_to_next when the
3971 end of the current overlay string is reached. If there are more
3972 overlay strings to display, IT->string and
3973 IT->current.overlay_string_index are set appropriately here.
3974 Otherwise IT->string is set to nil. */
3977 next_overlay_string (it
)
3980 ++it
->current
.overlay_string_index
;
3981 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3983 /* No more overlay strings. Restore IT's settings to what
3984 they were before overlay strings were processed, and
3985 continue to deliver from current_buffer. */
3986 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
3989 xassert (it
->stop_charpos
>= BEGV
3990 && it
->stop_charpos
<= it
->end_charpos
);
3992 it
->current
.overlay_string_index
= -1;
3993 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3994 it
->n_overlay_strings
= 0;
3995 it
->method
= next_element_from_buffer
;
3997 /* If we're at the end of the buffer, record that we have
3998 processed the overlay strings there already, so that
3999 next_element_from_buffer doesn't try it again. */
4000 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4001 it
->overlay_strings_at_end_processed_p
= 1;
4003 /* If we have to display `...' for invisible text, set
4004 the iterator up for that. */
4005 if (display_ellipsis_p
)
4006 setup_for_ellipsis (it
);
4010 /* There are more overlay strings to process. If
4011 IT->current.overlay_string_index has advanced to a position
4012 where we must load IT->overlay_strings with more strings, do
4014 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4016 if (it
->current
.overlay_string_index
&& i
== 0)
4017 load_overlay_strings (it
, 0);
4019 /* Initialize IT to deliver display elements from the overlay
4021 it
->string
= it
->overlay_strings
[i
];
4022 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4023 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4024 it
->method
= next_element_from_string
;
4025 it
->stop_charpos
= 0;
4032 /* Compare two overlay_entry structures E1 and E2. Used as a
4033 comparison function for qsort in load_overlay_strings. Overlay
4034 strings for the same position are sorted so that
4036 1. All after-strings come in front of before-strings, except
4037 when they come from the same overlay.
4039 2. Within after-strings, strings are sorted so that overlay strings
4040 from overlays with higher priorities come first.
4042 2. Within before-strings, strings are sorted so that overlay
4043 strings from overlays with higher priorities come last.
4045 Value is analogous to strcmp. */
4049 compare_overlay_entries (e1
, e2
)
4052 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4053 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4056 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4058 /* Let after-strings appear in front of before-strings if
4059 they come from different overlays. */
4060 if (EQ (entry1
->overlay
, entry2
->overlay
))
4061 result
= entry1
->after_string_p
? 1 : -1;
4063 result
= entry1
->after_string_p
? -1 : 1;
4065 else if (entry1
->after_string_p
)
4066 /* After-strings sorted in order of decreasing priority. */
4067 result
= entry2
->priority
- entry1
->priority
;
4069 /* Before-strings sorted in order of increasing priority. */
4070 result
= entry1
->priority
- entry2
->priority
;
4076 /* Load the vector IT->overlay_strings with overlay strings from IT's
4077 current buffer position, or from CHARPOS if that is > 0. Set
4078 IT->n_overlays to the total number of overlay strings found.
4080 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4081 a time. On entry into load_overlay_strings,
4082 IT->current.overlay_string_index gives the number of overlay
4083 strings that have already been loaded by previous calls to this
4086 IT->add_overlay_start contains an additional overlay start
4087 position to consider for taking overlay strings from, if non-zero.
4088 This position comes into play when the overlay has an `invisible'
4089 property, and both before and after-strings. When we've skipped to
4090 the end of the overlay, because of its `invisible' property, we
4091 nevertheless want its before-string to appear.
4092 IT->add_overlay_start will contain the overlay start position
4095 Overlay strings are sorted so that after-string strings come in
4096 front of before-string strings. Within before and after-strings,
4097 strings are sorted by overlay priority. See also function
4098 compare_overlay_entries. */
4101 load_overlay_strings (it
, charpos
)
4105 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4106 Lisp_Object overlay
, window
, str
, invisible
;
4107 struct Lisp_Overlay
*ov
;
4110 int n
= 0, i
, j
, invis_p
;
4111 struct overlay_entry
*entries
4112 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4115 charpos
= IT_CHARPOS (*it
);
4117 /* Append the overlay string STRING of overlay OVERLAY to vector
4118 `entries' which has size `size' and currently contains `n'
4119 elements. AFTER_P non-zero means STRING is an after-string of
4121 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4124 Lisp_Object priority; \
4128 int new_size = 2 * size; \
4129 struct overlay_entry *old = entries; \
4131 (struct overlay_entry *) alloca (new_size \
4132 * sizeof *entries); \
4133 bcopy (old, entries, size * sizeof *entries); \
4137 entries[n].string = (STRING); \
4138 entries[n].overlay = (OVERLAY); \
4139 priority = Foverlay_get ((OVERLAY), Qpriority); \
4140 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4141 entries[n].after_string_p = (AFTER_P); \
4146 /* Process overlay before the overlay center. */
4147 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4149 XSETMISC (overlay
, ov
);
4150 xassert (OVERLAYP (overlay
));
4151 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4152 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4157 /* Skip this overlay if it doesn't start or end at IT's current
4159 if (end
!= charpos
&& start
!= charpos
)
4162 /* Skip this overlay if it doesn't apply to IT->w. */
4163 window
= Foverlay_get (overlay
, Qwindow
);
4164 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4167 /* If the text ``under'' the overlay is invisible, both before-
4168 and after-strings from this overlay are visible; start and
4169 end position are indistinguishable. */
4170 invisible
= Foverlay_get (overlay
, Qinvisible
);
4171 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4173 /* If overlay has a non-empty before-string, record it. */
4174 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4175 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4177 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4179 /* If overlay has a non-empty after-string, record it. */
4180 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4181 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4183 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4186 /* Process overlays after the overlay center. */
4187 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4189 XSETMISC (overlay
, ov
);
4190 xassert (OVERLAYP (overlay
));
4191 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4192 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4194 if (start
> charpos
)
4197 /* Skip this overlay if it doesn't start or end at IT's current
4199 if (end
!= charpos
&& start
!= charpos
)
4202 /* Skip this overlay if it doesn't apply to IT->w. */
4203 window
= Foverlay_get (overlay
, Qwindow
);
4204 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4207 /* If the text ``under'' the overlay is invisible, it has a zero
4208 dimension, and both before- and after-strings apply. */
4209 invisible
= Foverlay_get (overlay
, Qinvisible
);
4210 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4212 /* If overlay has a non-empty before-string, record it. */
4213 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4214 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4216 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4218 /* If overlay has a non-empty after-string, record it. */
4219 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4220 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4222 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4225 #undef RECORD_OVERLAY_STRING
4229 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4231 /* Record the total number of strings to process. */
4232 it
->n_overlay_strings
= n
;
4234 /* IT->current.overlay_string_index is the number of overlay strings
4235 that have already been consumed by IT. Copy some of the
4236 remaining overlay strings to IT->overlay_strings. */
4238 j
= it
->current
.overlay_string_index
;
4239 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4240 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4246 /* Get the first chunk of overlay strings at IT's current buffer
4247 position, or at CHARPOS if that is > 0. Value is non-zero if at
4248 least one overlay string was found. */
4251 get_overlay_strings (it
, charpos
)
4255 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4256 process. This fills IT->overlay_strings with strings, and sets
4257 IT->n_overlay_strings to the total number of strings to process.
4258 IT->pos.overlay_string_index has to be set temporarily to zero
4259 because load_overlay_strings needs this; it must be set to -1
4260 when no overlay strings are found because a zero value would
4261 indicate a position in the first overlay string. */
4262 it
->current
.overlay_string_index
= 0;
4263 load_overlay_strings (it
, charpos
);
4265 /* If we found overlay strings, set up IT to deliver display
4266 elements from the first one. Otherwise set up IT to deliver
4267 from current_buffer. */
4268 if (it
->n_overlay_strings
)
4270 /* Make sure we know settings in current_buffer, so that we can
4271 restore meaningful values when we're done with the overlay
4273 compute_stop_pos (it
);
4274 xassert (it
->face_id
>= 0);
4276 /* Save IT's settings. They are restored after all overlay
4277 strings have been processed. */
4278 xassert (it
->sp
== 0);
4281 /* Set up IT to deliver display elements from the first overlay
4283 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4284 it
->string
= it
->overlay_strings
[0];
4285 it
->stop_charpos
= 0;
4286 xassert (STRINGP (it
->string
));
4287 it
->end_charpos
= SCHARS (it
->string
);
4288 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4289 it
->method
= next_element_from_string
;
4294 it
->current
.overlay_string_index
= -1;
4295 it
->method
= next_element_from_buffer
;
4300 /* Value is non-zero if we found at least one overlay string. */
4301 return STRINGP (it
->string
);
4306 /***********************************************************************
4307 Saving and restoring state
4308 ***********************************************************************/
4310 /* Save current settings of IT on IT->stack. Called, for example,
4311 before setting up IT for an overlay string, to be able to restore
4312 IT's settings to what they were after the overlay string has been
4319 struct iterator_stack_entry
*p
;
4321 xassert (it
->sp
< 2);
4322 p
= it
->stack
+ it
->sp
;
4324 p
->stop_charpos
= it
->stop_charpos
;
4325 xassert (it
->face_id
>= 0);
4326 p
->face_id
= it
->face_id
;
4327 p
->string
= it
->string
;
4328 p
->pos
= it
->current
;
4329 p
->end_charpos
= it
->end_charpos
;
4330 p
->string_nchars
= it
->string_nchars
;
4332 p
->multibyte_p
= it
->multibyte_p
;
4333 p
->space_width
= it
->space_width
;
4334 p
->font_height
= it
->font_height
;
4335 p
->voffset
= it
->voffset
;
4336 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4337 p
->display_ellipsis_p
= 0;
4342 /* Restore IT's settings from IT->stack. Called, for example, when no
4343 more overlay strings must be processed, and we return to delivering
4344 display elements from a buffer, or when the end of a string from a
4345 `display' property is reached and we return to delivering display
4346 elements from an overlay string, or from a buffer. */
4352 struct iterator_stack_entry
*p
;
4354 xassert (it
->sp
> 0);
4356 p
= it
->stack
+ it
->sp
;
4357 it
->stop_charpos
= p
->stop_charpos
;
4358 it
->face_id
= p
->face_id
;
4359 it
->string
= p
->string
;
4360 it
->current
= p
->pos
;
4361 it
->end_charpos
= p
->end_charpos
;
4362 it
->string_nchars
= p
->string_nchars
;
4364 it
->multibyte_p
= p
->multibyte_p
;
4365 it
->space_width
= p
->space_width
;
4366 it
->font_height
= p
->font_height
;
4367 it
->voffset
= p
->voffset
;
4368 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4373 /***********************************************************************
4375 ***********************************************************************/
4377 /* Set IT's current position to the previous line start. */
4380 back_to_previous_line_start (it
)
4383 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4384 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4388 /* Move IT to the next line start.
4390 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4391 we skipped over part of the text (as opposed to moving the iterator
4392 continuously over the text). Otherwise, don't change the value
4395 Newlines may come from buffer text, overlay strings, or strings
4396 displayed via the `display' property. That's the reason we can't
4397 simply use find_next_newline_no_quit.
4399 Note that this function may not skip over invisible text that is so
4400 because of text properties and immediately follows a newline. If
4401 it would, function reseat_at_next_visible_line_start, when called
4402 from set_iterator_to_next, would effectively make invisible
4403 characters following a newline part of the wrong glyph row, which
4404 leads to wrong cursor motion. */
4407 forward_to_next_line_start (it
, skipped_p
)
4411 int old_selective
, newline_found_p
, n
;
4412 const int MAX_NEWLINE_DISTANCE
= 500;
4414 /* If already on a newline, just consume it to avoid unintended
4415 skipping over invisible text below. */
4416 if (it
->what
== IT_CHARACTER
4418 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4420 set_iterator_to_next (it
, 0);
4425 /* Don't handle selective display in the following. It's (a)
4426 unnecessary because it's done by the caller, and (b) leads to an
4427 infinite recursion because next_element_from_ellipsis indirectly
4428 calls this function. */
4429 old_selective
= it
->selective
;
4432 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4433 from buffer text. */
4434 for (n
= newline_found_p
= 0;
4435 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4436 n
+= STRINGP (it
->string
) ? 0 : 1)
4438 if (!get_next_display_element (it
))
4440 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4441 set_iterator_to_next (it
, 0);
4444 /* If we didn't find a newline near enough, see if we can use a
4446 if (!newline_found_p
)
4448 int start
= IT_CHARPOS (*it
);
4449 int limit
= find_next_newline_no_quit (start
, 1);
4452 xassert (!STRINGP (it
->string
));
4454 /* If there isn't any `display' property in sight, and no
4455 overlays, we can just use the position of the newline in
4457 if (it
->stop_charpos
>= limit
4458 || ((pos
= Fnext_single_property_change (make_number (start
),
4460 Qnil
, make_number (limit
)),
4462 && next_overlay_change (start
) == ZV
))
4464 IT_CHARPOS (*it
) = limit
;
4465 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4466 *skipped_p
= newline_found_p
= 1;
4470 while (get_next_display_element (it
)
4471 && !newline_found_p
)
4473 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4474 set_iterator_to_next (it
, 0);
4479 it
->selective
= old_selective
;
4480 return newline_found_p
;
4484 /* Set IT's current position to the previous visible line start. Skip
4485 invisible text that is so either due to text properties or due to
4486 selective display. Caution: this does not change IT->current_x and
4490 back_to_previous_visible_line_start (it
)
4495 /* Go back one newline if not on BEGV already. */
4496 if (IT_CHARPOS (*it
) > BEGV
)
4497 back_to_previous_line_start (it
);
4499 /* Move over lines that are invisible because of selective display
4500 or text properties. */
4501 while (IT_CHARPOS (*it
) > BEGV
4506 /* If selective > 0, then lines indented more than that values
4508 if (it
->selective
> 0
4509 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4510 (double) it
->selective
)) /* iftc */
4516 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
4517 Qinvisible
, it
->window
);
4518 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4522 /* Back one more newline if the current one is invisible. */
4524 back_to_previous_line_start (it
);
4527 xassert (IT_CHARPOS (*it
) >= BEGV
);
4528 xassert (IT_CHARPOS (*it
) == BEGV
4529 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4534 /* Reseat iterator IT at the previous visible line start. Skip
4535 invisible text that is so either due to text properties or due to
4536 selective display. At the end, update IT's overlay information,
4537 face information etc. */
4540 reseat_at_previous_visible_line_start (it
)
4543 back_to_previous_visible_line_start (it
);
4544 reseat (it
, it
->current
.pos
, 1);
4549 /* Reseat iterator IT on the next visible line start in the current
4550 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4551 preceding the line start. Skip over invisible text that is so
4552 because of selective display. Compute faces, overlays etc at the
4553 new position. Note that this function does not skip over text that
4554 is invisible because of text properties. */
4557 reseat_at_next_visible_line_start (it
, on_newline_p
)
4561 int newline_found_p
, skipped_p
= 0;
4563 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4565 /* Skip over lines that are invisible because they are indented
4566 more than the value of IT->selective. */
4567 if (it
->selective
> 0)
4568 while (IT_CHARPOS (*it
) < ZV
4569 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4570 (double) it
->selective
)) /* iftc */
4572 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4573 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4576 /* Position on the newline if that's what's requested. */
4577 if (on_newline_p
&& newline_found_p
)
4579 if (STRINGP (it
->string
))
4581 if (IT_STRING_CHARPOS (*it
) > 0)
4583 --IT_STRING_CHARPOS (*it
);
4584 --IT_STRING_BYTEPOS (*it
);
4587 else if (IT_CHARPOS (*it
) > BEGV
)
4591 reseat (it
, it
->current
.pos
, 0);
4595 reseat (it
, it
->current
.pos
, 0);
4602 /***********************************************************************
4603 Changing an iterator's position
4604 ***********************************************************************/
4606 /* Change IT's current position to POS in current_buffer. If FORCE_P
4607 is non-zero, always check for text properties at the new position.
4608 Otherwise, text properties are only looked up if POS >=
4609 IT->check_charpos of a property. */
4612 reseat (it
, pos
, force_p
)
4614 struct text_pos pos
;
4617 int original_pos
= IT_CHARPOS (*it
);
4619 reseat_1 (it
, pos
, 0);
4621 /* Determine where to check text properties. Avoid doing it
4622 where possible because text property lookup is very expensive. */
4624 || CHARPOS (pos
) > it
->stop_charpos
4625 || CHARPOS (pos
) < original_pos
)
4632 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4633 IT->stop_pos to POS, also. */
4636 reseat_1 (it
, pos
, set_stop_p
)
4638 struct text_pos pos
;
4641 /* Don't call this function when scanning a C string. */
4642 xassert (it
->s
== NULL
);
4644 /* POS must be a reasonable value. */
4645 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4647 it
->current
.pos
= it
->position
= pos
;
4648 XSETBUFFER (it
->object
, current_buffer
);
4649 it
->end_charpos
= ZV
;
4651 it
->current
.dpvec_index
= -1;
4652 it
->current
.overlay_string_index
= -1;
4653 IT_STRING_CHARPOS (*it
) = -1;
4654 IT_STRING_BYTEPOS (*it
) = -1;
4656 it
->method
= next_element_from_buffer
;
4657 /* RMS: I added this to fix a bug in move_it_vertically_backward
4658 where it->area continued to relate to the starting point
4659 for the backward motion. Bug report from
4660 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
4661 However, I am not sure whether reseat still does the right thing
4662 in general after this change. */
4663 it
->area
= TEXT_AREA
;
4664 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4666 it
->face_before_selective_p
= 0;
4669 it
->stop_charpos
= CHARPOS (pos
);
4673 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4674 If S is non-null, it is a C string to iterate over. Otherwise,
4675 STRING gives a Lisp string to iterate over.
4677 If PRECISION > 0, don't return more then PRECISION number of
4678 characters from the string.
4680 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4681 characters have been returned. FIELD_WIDTH < 0 means an infinite
4684 MULTIBYTE = 0 means disable processing of multibyte characters,
4685 MULTIBYTE > 0 means enable it,
4686 MULTIBYTE < 0 means use IT->multibyte_p.
4688 IT must be initialized via a prior call to init_iterator before
4689 calling this function. */
4692 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4697 int precision
, field_width
, multibyte
;
4699 /* No region in strings. */
4700 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4702 /* No text property checks performed by default, but see below. */
4703 it
->stop_charpos
= -1;
4705 /* Set iterator position and end position. */
4706 bzero (&it
->current
, sizeof it
->current
);
4707 it
->current
.overlay_string_index
= -1;
4708 it
->current
.dpvec_index
= -1;
4709 xassert (charpos
>= 0);
4711 /* If STRING is specified, use its multibyteness, otherwise use the
4712 setting of MULTIBYTE, if specified. */
4714 it
->multibyte_p
= multibyte
> 0;
4718 xassert (STRINGP (string
));
4719 it
->string
= string
;
4721 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4722 it
->method
= next_element_from_string
;
4723 it
->current
.string_pos
= string_pos (charpos
, string
);
4730 /* Note that we use IT->current.pos, not it->current.string_pos,
4731 for displaying C strings. */
4732 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4733 if (it
->multibyte_p
)
4735 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4736 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4740 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4741 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4744 it
->method
= next_element_from_c_string
;
4747 /* PRECISION > 0 means don't return more than PRECISION characters
4749 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4750 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4752 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4753 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4754 FIELD_WIDTH < 0 means infinite field width. This is useful for
4755 padding with `-' at the end of a mode line. */
4756 if (field_width
< 0)
4757 field_width
= INFINITY
;
4758 if (field_width
> it
->end_charpos
- charpos
)
4759 it
->end_charpos
= charpos
+ field_width
;
4761 /* Use the standard display table for displaying strings. */
4762 if (DISP_TABLE_P (Vstandard_display_table
))
4763 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4765 it
->stop_charpos
= charpos
;
4771 /***********************************************************************
4773 ***********************************************************************/
4775 /* Load IT's display element fields with information about the next
4776 display element from the current position of IT. Value is zero if
4777 end of buffer (or C string) is reached. */
4780 get_next_display_element (it
)
4783 /* Non-zero means that we found a display element. Zero means that
4784 we hit the end of what we iterate over. Performance note: the
4785 function pointer `method' used here turns out to be faster than
4786 using a sequence of if-statements. */
4787 int success_p
= (*it
->method
) (it
);
4789 if (it
->what
== IT_CHARACTER
)
4791 /* Map via display table or translate control characters.
4792 IT->c, IT->len etc. have been set to the next character by
4793 the function call above. If we have a display table, and it
4794 contains an entry for IT->c, translate it. Don't do this if
4795 IT->c itself comes from a display table, otherwise we could
4796 end up in an infinite recursion. (An alternative could be to
4797 count the recursion depth of this function and signal an
4798 error when a certain maximum depth is reached.) Is it worth
4800 if (success_p
&& it
->dpvec
== NULL
)
4805 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4808 struct Lisp_Vector
*v
= XVECTOR (dv
);
4810 /* Return the first character from the display table
4811 entry, if not empty. If empty, don't display the
4812 current character. */
4815 it
->dpvec_char_len
= it
->len
;
4816 it
->dpvec
= v
->contents
;
4817 it
->dpend
= v
->contents
+ v
->size
;
4818 it
->current
.dpvec_index
= 0;
4819 it
->method
= next_element_from_display_vector
;
4820 success_p
= get_next_display_element (it
);
4824 set_iterator_to_next (it
, 0);
4825 success_p
= get_next_display_element (it
);
4829 /* Translate control characters into `\003' or `^C' form.
4830 Control characters coming from a display table entry are
4831 currently not translated because we use IT->dpvec to hold
4832 the translation. This could easily be changed but I
4833 don't believe that it is worth doing.
4835 If it->multibyte_p is nonzero, eight-bit characters and
4836 non-printable multibyte characters are also translated to
4839 If it->multibyte_p is zero, eight-bit characters that
4840 don't have corresponding multibyte char code are also
4841 translated to octal form. */
4842 else if ((it
->c
< ' '
4843 && (it
->area
!= TEXT_AREA
4844 || (it
->c
!= '\n' && it
->c
!= '\t')))
4848 || !CHAR_PRINTABLE_P (it
->c
))
4850 && it
->c
== unibyte_char_to_multibyte (it
->c
))))
4852 /* IT->c is a control character which must be displayed
4853 either as '\003' or as `^C' where the '\\' and '^'
4854 can be defined in the display table. Fill
4855 IT->ctl_chars with glyphs for what we have to
4856 display. Then, set IT->dpvec to these glyphs. */
4859 if (it
->c
< 128 && it
->ctl_arrow_p
)
4861 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4863 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4864 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4865 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4867 g
= FAST_MAKE_GLYPH ('^', 0);
4868 XSETINT (it
->ctl_chars
[0], g
);
4870 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4871 XSETINT (it
->ctl_chars
[1], g
);
4873 /* Set up IT->dpvec and return first character from it. */
4874 it
->dpvec_char_len
= it
->len
;
4875 it
->dpvec
= it
->ctl_chars
;
4876 it
->dpend
= it
->dpvec
+ 2;
4877 it
->current
.dpvec_index
= 0;
4878 it
->method
= next_element_from_display_vector
;
4879 get_next_display_element (it
);
4883 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4888 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4890 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4891 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4892 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4894 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4896 if (SINGLE_BYTE_CHAR_P (it
->c
))
4897 str
[0] = it
->c
, len
= 1;
4900 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4903 /* It's an invalid character, which
4904 shouldn't happen actually, but due to
4905 bugs it may happen. Let's print the char
4906 as is, there's not much meaningful we can
4909 str
[1] = it
->c
>> 8;
4910 str
[2] = it
->c
>> 16;
4911 str
[3] = it
->c
>> 24;
4916 for (i
= 0; i
< len
; i
++)
4918 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4919 /* Insert three more glyphs into IT->ctl_chars for
4920 the octal display of the character. */
4921 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4922 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4923 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4924 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4925 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4926 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4929 /* Set up IT->dpvec and return the first character
4931 it
->dpvec_char_len
= it
->len
;
4932 it
->dpvec
= it
->ctl_chars
;
4933 it
->dpend
= it
->dpvec
+ len
* 4;
4934 it
->current
.dpvec_index
= 0;
4935 it
->method
= next_element_from_display_vector
;
4936 get_next_display_element (it
);
4941 /* Adjust face id for a multibyte character. There are no
4942 multibyte character in unibyte text. */
4945 && FRAME_WINDOW_P (it
->f
))
4947 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4948 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4952 /* Is this character the last one of a run of characters with
4953 box? If yes, set IT->end_of_box_run_p to 1. */
4960 it
->end_of_box_run_p
4961 = ((face_id
= face_after_it_pos (it
),
4962 face_id
!= it
->face_id
)
4963 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4964 face
->box
== FACE_NO_BOX
));
4967 /* Value is 0 if end of buffer or string reached. */
4972 /* Move IT to the next display element.
4974 RESEAT_P non-zero means if called on a newline in buffer text,
4975 skip to the next visible line start.
4977 Functions get_next_display_element and set_iterator_to_next are
4978 separate because I find this arrangement easier to handle than a
4979 get_next_display_element function that also increments IT's
4980 position. The way it is we can first look at an iterator's current
4981 display element, decide whether it fits on a line, and if it does,
4982 increment the iterator position. The other way around we probably
4983 would either need a flag indicating whether the iterator has to be
4984 incremented the next time, or we would have to implement a
4985 decrement position function which would not be easy to write. */
4988 set_iterator_to_next (it
, reseat_p
)
4992 /* Reset flags indicating start and end of a sequence of characters
4993 with box. Reset them at the start of this function because
4994 moving the iterator to a new position might set them. */
4995 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4997 if (it
->method
== next_element_from_buffer
)
4999 /* The current display element of IT is a character from
5000 current_buffer. Advance in the buffer, and maybe skip over
5001 invisible lines that are so because of selective display. */
5002 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5003 reseat_at_next_visible_line_start (it
, 0);
5006 xassert (it
->len
!= 0);
5007 IT_BYTEPOS (*it
) += it
->len
;
5008 IT_CHARPOS (*it
) += 1;
5009 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5012 else if (it
->method
== next_element_from_composition
)
5014 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5015 if (STRINGP (it
->string
))
5017 IT_STRING_BYTEPOS (*it
) += it
->len
;
5018 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5019 it
->method
= next_element_from_string
;
5020 goto consider_string_end
;
5024 IT_BYTEPOS (*it
) += it
->len
;
5025 IT_CHARPOS (*it
) += it
->cmp_len
;
5026 it
->method
= next_element_from_buffer
;
5029 else if (it
->method
== next_element_from_c_string
)
5031 /* Current display element of IT is from a C string. */
5032 IT_BYTEPOS (*it
) += it
->len
;
5033 IT_CHARPOS (*it
) += 1;
5035 else if (it
->method
== next_element_from_display_vector
)
5037 /* Current display element of IT is from a display table entry.
5038 Advance in the display table definition. Reset it to null if
5039 end reached, and continue with characters from buffers/
5041 ++it
->current
.dpvec_index
;
5043 /* Restore face of the iterator to what they were before the
5044 display vector entry (these entries may contain faces). */
5045 it
->face_id
= it
->saved_face_id
;
5047 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5050 it
->method
= next_element_from_c_string
;
5051 else if (STRINGP (it
->string
))
5052 it
->method
= next_element_from_string
;
5054 it
->method
= next_element_from_buffer
;
5057 it
->current
.dpvec_index
= -1;
5059 /* Skip over characters which were displayed via IT->dpvec. */
5060 if (it
->dpvec_char_len
< 0)
5061 reseat_at_next_visible_line_start (it
, 1);
5062 else if (it
->dpvec_char_len
> 0)
5064 it
->len
= it
->dpvec_char_len
;
5065 set_iterator_to_next (it
, reseat_p
);
5069 else if (it
->method
== next_element_from_string
)
5071 /* Current display element is a character from a Lisp string. */
5072 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5073 IT_STRING_BYTEPOS (*it
) += it
->len
;
5074 IT_STRING_CHARPOS (*it
) += 1;
5076 consider_string_end
:
5078 if (it
->current
.overlay_string_index
>= 0)
5080 /* IT->string is an overlay string. Advance to the
5081 next, if there is one. */
5082 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5083 next_overlay_string (it
);
5087 /* IT->string is not an overlay string. If we reached
5088 its end, and there is something on IT->stack, proceed
5089 with what is on the stack. This can be either another
5090 string, this time an overlay string, or a buffer. */
5091 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5095 if (!STRINGP (it
->string
))
5096 it
->method
= next_element_from_buffer
;
5098 goto consider_string_end
;
5102 else if (it
->method
== next_element_from_image
5103 || it
->method
== next_element_from_stretch
)
5105 /* The position etc with which we have to proceed are on
5106 the stack. The position may be at the end of a string,
5107 if the `display' property takes up the whole string. */
5110 if (STRINGP (it
->string
))
5112 it
->method
= next_element_from_string
;
5113 goto consider_string_end
;
5116 it
->method
= next_element_from_buffer
;
5119 /* There are no other methods defined, so this should be a bug. */
5122 xassert (it
->method
!= next_element_from_string
5123 || (STRINGP (it
->string
)
5124 && IT_STRING_CHARPOS (*it
) >= 0));
5128 /* Load IT's display element fields with information about the next
5129 display element which comes from a display table entry or from the
5130 result of translating a control character to one of the forms `^C'
5131 or `\003'. IT->dpvec holds the glyphs to return as characters. */
5134 next_element_from_display_vector (it
)
5138 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5140 /* Remember the current face id in case glyphs specify faces.
5141 IT's face is restored in set_iterator_to_next. */
5142 it
->saved_face_id
= it
->face_id
;
5144 if (INTEGERP (*it
->dpvec
)
5145 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5150 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5151 it
->c
= FAST_GLYPH_CHAR (g
);
5152 it
->len
= CHAR_BYTES (it
->c
);
5154 /* The entry may contain a face id to use. Such a face id is
5155 the id of a Lisp face, not a realized face. A face id of
5156 zero means no face is specified. */
5157 lface_id
= FAST_GLYPH_FACE (g
);
5160 /* The function returns -1 if lface_id is invalid. */
5161 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
5163 it
->face_id
= face_id
;
5167 /* Display table entry is invalid. Return a space. */
5168 it
->c
= ' ', it
->len
= 1;
5170 /* Don't change position and object of the iterator here. They are
5171 still the values of the character that had this display table
5172 entry or was translated, and that's what we want. */
5173 it
->what
= IT_CHARACTER
;
5178 /* Load IT with the next display element from Lisp string IT->string.
5179 IT->current.string_pos is the current position within the string.
5180 If IT->current.overlay_string_index >= 0, the Lisp string is an
5184 next_element_from_string (it
)
5187 struct text_pos position
;
5189 xassert (STRINGP (it
->string
));
5190 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5191 position
= it
->current
.string_pos
;
5193 /* Time to check for invisible text? */
5194 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5195 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5199 /* Since a handler may have changed IT->method, we must
5201 return get_next_display_element (it
);
5204 if (it
->current
.overlay_string_index
>= 0)
5206 /* Get the next character from an overlay string. In overlay
5207 strings, There is no field width or padding with spaces to
5209 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5214 else if (STRING_MULTIBYTE (it
->string
))
5216 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5217 const unsigned char *s
= (SDATA (it
->string
)
5218 + IT_STRING_BYTEPOS (*it
));
5219 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5223 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5229 /* Get the next character from a Lisp string that is not an
5230 overlay string. Such strings come from the mode line, for
5231 example. We may have to pad with spaces, or truncate the
5232 string. See also next_element_from_c_string. */
5233 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5238 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5240 /* Pad with spaces. */
5241 it
->c
= ' ', it
->len
= 1;
5242 CHARPOS (position
) = BYTEPOS (position
) = -1;
5244 else if (STRING_MULTIBYTE (it
->string
))
5246 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5247 const unsigned char *s
= (SDATA (it
->string
)
5248 + IT_STRING_BYTEPOS (*it
));
5249 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5253 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5258 /* Record what we have and where it came from. Note that we store a
5259 buffer position in IT->position although it could arguably be a
5261 it
->what
= IT_CHARACTER
;
5262 it
->object
= it
->string
;
5263 it
->position
= position
;
5268 /* Load IT with next display element from C string IT->s.
5269 IT->string_nchars is the maximum number of characters to return
5270 from the string. IT->end_charpos may be greater than
5271 IT->string_nchars when this function is called, in which case we
5272 may have to return padding spaces. Value is zero if end of string
5273 reached, including padding spaces. */
5276 next_element_from_c_string (it
)
5282 it
->what
= IT_CHARACTER
;
5283 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5286 /* IT's position can be greater IT->string_nchars in case a field
5287 width or precision has been specified when the iterator was
5289 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5291 /* End of the game. */
5295 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5297 /* Pad with spaces. */
5298 it
->c
= ' ', it
->len
= 1;
5299 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5301 else if (it
->multibyte_p
)
5303 /* Implementation note: The calls to strlen apparently aren't a
5304 performance problem because there is no noticeable performance
5305 difference between Emacs running in unibyte or multibyte mode. */
5306 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5307 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5311 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5317 /* Set up IT to return characters from an ellipsis, if appropriate.
5318 The definition of the ellipsis glyphs may come from a display table
5319 entry. This function Fills IT with the first glyph from the
5320 ellipsis if an ellipsis is to be displayed. */
5323 next_element_from_ellipsis (it
)
5326 if (it
->selective_display_ellipsis_p
)
5328 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
5330 /* Use the display table definition for `...'. Invalid glyphs
5331 will be handled by the method returning elements from dpvec. */
5332 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
5333 it
->dpvec_char_len
= it
->len
;
5334 it
->dpvec
= v
->contents
;
5335 it
->dpend
= v
->contents
+ v
->size
;
5336 it
->current
.dpvec_index
= 0;
5337 it
->method
= next_element_from_display_vector
;
5341 /* Use default `...' which is stored in default_invis_vector. */
5342 it
->dpvec_char_len
= it
->len
;
5343 it
->dpvec
= default_invis_vector
;
5344 it
->dpend
= default_invis_vector
+ 3;
5345 it
->current
.dpvec_index
= 0;
5346 it
->method
= next_element_from_display_vector
;
5351 /* The face at the current position may be different from the
5352 face we find after the invisible text. Remember what it
5353 was in IT->saved_face_id, and signal that it's there by
5354 setting face_before_selective_p. */
5355 it
->saved_face_id
= it
->face_id
;
5356 it
->method
= next_element_from_buffer
;
5357 reseat_at_next_visible_line_start (it
, 1);
5358 it
->face_before_selective_p
= 1;
5361 return get_next_display_element (it
);
5365 /* Deliver an image display element. The iterator IT is already
5366 filled with image information (done in handle_display_prop). Value
5371 next_element_from_image (it
)
5374 it
->what
= IT_IMAGE
;
5379 /* Fill iterator IT with next display element from a stretch glyph
5380 property. IT->object is the value of the text property. Value is
5384 next_element_from_stretch (it
)
5387 it
->what
= IT_STRETCH
;
5392 /* Load IT with the next display element from current_buffer. Value
5393 is zero if end of buffer reached. IT->stop_charpos is the next
5394 position at which to stop and check for text properties or buffer
5398 next_element_from_buffer (it
)
5403 /* Check this assumption, otherwise, we would never enter the
5404 if-statement, below. */
5405 xassert (IT_CHARPOS (*it
) >= BEGV
5406 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
5408 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
5410 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5412 int overlay_strings_follow_p
;
5414 /* End of the game, except when overlay strings follow that
5415 haven't been returned yet. */
5416 if (it
->overlay_strings_at_end_processed_p
)
5417 overlay_strings_follow_p
= 0;
5420 it
->overlay_strings_at_end_processed_p
= 1;
5421 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
5424 if (overlay_strings_follow_p
)
5425 success_p
= get_next_display_element (it
);
5429 it
->position
= it
->current
.pos
;
5436 return get_next_display_element (it
);
5441 /* No face changes, overlays etc. in sight, so just return a
5442 character from current_buffer. */
5445 /* Maybe run the redisplay end trigger hook. Performance note:
5446 This doesn't seem to cost measurable time. */
5447 if (it
->redisplay_end_trigger_charpos
5449 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
5450 run_redisplay_end_trigger_hook (it
);
5452 /* Get the next character, maybe multibyte. */
5453 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
5454 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
5456 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
5457 - IT_BYTEPOS (*it
));
5458 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
5461 it
->c
= *p
, it
->len
= 1;
5463 /* Record what we have and where it came from. */
5464 it
->what
= IT_CHARACTER
;;
5465 it
->object
= it
->w
->buffer
;
5466 it
->position
= it
->current
.pos
;
5468 /* Normally we return the character found above, except when we
5469 really want to return an ellipsis for selective display. */
5474 /* A value of selective > 0 means hide lines indented more
5475 than that number of columns. */
5476 if (it
->selective
> 0
5477 && IT_CHARPOS (*it
) + 1 < ZV
5478 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
5479 IT_BYTEPOS (*it
) + 1,
5480 (double) it
->selective
)) /* iftc */
5482 success_p
= next_element_from_ellipsis (it
);
5483 it
->dpvec_char_len
= -1;
5486 else if (it
->c
== '\r' && it
->selective
== -1)
5488 /* A value of selective == -1 means that everything from the
5489 CR to the end of the line is invisible, with maybe an
5490 ellipsis displayed for it. */
5491 success_p
= next_element_from_ellipsis (it
);
5492 it
->dpvec_char_len
= -1;
5497 /* Value is zero if end of buffer reached. */
5498 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
5503 /* Run the redisplay end trigger hook for IT. */
5506 run_redisplay_end_trigger_hook (it
)
5509 Lisp_Object args
[3];
5511 /* IT->glyph_row should be non-null, i.e. we should be actually
5512 displaying something, or otherwise we should not run the hook. */
5513 xassert (it
->glyph_row
);
5515 /* Set up hook arguments. */
5516 args
[0] = Qredisplay_end_trigger_functions
;
5517 args
[1] = it
->window
;
5518 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
5519 it
->redisplay_end_trigger_charpos
= 0;
5521 /* Since we are *trying* to run these functions, don't try to run
5522 them again, even if they get an error. */
5523 it
->w
->redisplay_end_trigger
= Qnil
;
5524 Frun_hook_with_args (3, args
);
5526 /* Notice if it changed the face of the character we are on. */
5527 handle_face_prop (it
);
5531 /* Deliver a composition display element. The iterator IT is already
5532 filled with composition information (done in
5533 handle_composition_prop). Value is always 1. */
5536 next_element_from_composition (it
)
5539 it
->what
= IT_COMPOSITION
;
5540 it
->position
= (STRINGP (it
->string
)
5541 ? it
->current
.string_pos
5548 /***********************************************************************
5549 Moving an iterator without producing glyphs
5550 ***********************************************************************/
5552 /* Move iterator IT to a specified buffer or X position within one
5553 line on the display without producing glyphs.
5555 OP should be a bit mask including some or all of these bits:
5556 MOVE_TO_X: Stop on reaching x-position TO_X.
5557 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5558 Regardless of OP's value, stop in reaching the end of the display line.
5560 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5561 This means, in particular, that TO_X includes window's horizontal
5564 The return value has several possible values that
5565 say what condition caused the scan to stop:
5567 MOVE_POS_MATCH_OR_ZV
5568 - when TO_POS or ZV was reached.
5571 -when TO_X was reached before TO_POS or ZV were reached.
5574 - when we reached the end of the display area and the line must
5578 - when we reached the end of the display area and the line is
5582 - when we stopped at a line end, i.e. a newline or a CR and selective
5585 static enum move_it_result
5586 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5588 int to_charpos
, to_x
, op
;
5590 enum move_it_result result
= MOVE_UNDEFINED
;
5591 struct glyph_row
*saved_glyph_row
;
5593 /* Don't produce glyphs in produce_glyphs. */
5594 saved_glyph_row
= it
->glyph_row
;
5595 it
->glyph_row
= NULL
;
5597 #define BUFFER_POS_REACHED_P() \
5598 ((op & MOVE_TO_POS) != 0 \
5599 && BUFFERP (it->object) \
5600 && IT_CHARPOS (*it) >= to_charpos)
5604 int x
, i
, ascent
= 0, descent
= 0;
5606 /* Stop when ZV or TO_CHARPOS reached. */
5607 if (!get_next_display_element (it
)
5608 || BUFFER_POS_REACHED_P ())
5610 result
= MOVE_POS_MATCH_OR_ZV
;
5614 /* The call to produce_glyphs will get the metrics of the
5615 display element IT is loaded with. We record in x the
5616 x-position before this display element in case it does not
5620 /* Remember the line height so far in case the next element doesn't
5622 if (!it
->truncate_lines_p
)
5624 ascent
= it
->max_ascent
;
5625 descent
= it
->max_descent
;
5628 PRODUCE_GLYPHS (it
);
5630 if (it
->area
!= TEXT_AREA
)
5632 set_iterator_to_next (it
, 1);
5636 /* The number of glyphs we get back in IT->nglyphs will normally
5637 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5638 character on a terminal frame, or (iii) a line end. For the
5639 second case, IT->nglyphs - 1 padding glyphs will be present
5640 (on X frames, there is only one glyph produced for a
5641 composite character.
5643 The behavior implemented below means, for continuation lines,
5644 that as many spaces of a TAB as fit on the current line are
5645 displayed there. For terminal frames, as many glyphs of a
5646 multi-glyph character are displayed in the current line, too.
5647 This is what the old redisplay code did, and we keep it that
5648 way. Under X, the whole shape of a complex character must
5649 fit on the line or it will be completely displayed in the
5652 Note that both for tabs and padding glyphs, all glyphs have
5656 /* More than one glyph or glyph doesn't fit on line. All
5657 glyphs have the same width. */
5658 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5661 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5663 new_x
= x
+ single_glyph_width
;
5665 /* We want to leave anything reaching TO_X to the caller. */
5666 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5669 result
= MOVE_X_REACHED
;
5672 else if (/* Lines are continued. */
5673 !it
->truncate_lines_p
5674 && (/* And glyph doesn't fit on the line. */
5675 new_x
> it
->last_visible_x
5676 /* Or it fits exactly and we're on a window
5678 || (new_x
== it
->last_visible_x
5679 && FRAME_WINDOW_P (it
->f
))))
5681 if (/* IT->hpos == 0 means the very first glyph
5682 doesn't fit on the line, e.g. a wide image. */
5684 || (new_x
== it
->last_visible_x
5685 && FRAME_WINDOW_P (it
->f
)))
5688 it
->current_x
= new_x
;
5689 if (i
== it
->nglyphs
- 1)
5691 set_iterator_to_next (it
, 1);
5692 #ifdef HAVE_WINDOW_SYSTEM
5693 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
5695 if (!get_next_display_element (it
)
5696 || BUFFER_POS_REACHED_P ())
5698 result
= MOVE_POS_MATCH_OR_ZV
;
5701 if (ITERATOR_AT_END_OF_LINE_P (it
))
5703 result
= MOVE_NEWLINE_OR_CR
;
5707 #endif /* HAVE_WINDOW_SYSTEM */
5713 it
->max_ascent
= ascent
;
5714 it
->max_descent
= descent
;
5717 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5719 result
= MOVE_LINE_CONTINUED
;
5722 else if (new_x
> it
->first_visible_x
)
5724 /* Glyph is visible. Increment number of glyphs that
5725 would be displayed. */
5730 /* Glyph is completely off the left margin of the display
5731 area. Nothing to do. */
5735 if (result
!= MOVE_UNDEFINED
)
5738 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5740 /* Stop when TO_X specified and reached. This check is
5741 necessary here because of lines consisting of a line end,
5742 only. The line end will not produce any glyphs and we
5743 would never get MOVE_X_REACHED. */
5744 xassert (it
->nglyphs
== 0);
5745 result
= MOVE_X_REACHED
;
5749 /* Is this a line end? If yes, we're done. */
5750 if (ITERATOR_AT_END_OF_LINE_P (it
))
5752 result
= MOVE_NEWLINE_OR_CR
;
5756 /* The current display element has been consumed. Advance
5758 set_iterator_to_next (it
, 1);
5760 /* Stop if lines are truncated and IT's current x-position is
5761 past the right edge of the window now. */
5762 if (it
->truncate_lines_p
5763 && it
->current_x
>= it
->last_visible_x
)
5765 #ifdef HAVE_WINDOW_SYSTEM
5766 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
5768 if (!get_next_display_element (it
)
5769 || BUFFER_POS_REACHED_P ())
5771 result
= MOVE_POS_MATCH_OR_ZV
;
5774 if (ITERATOR_AT_END_OF_LINE_P (it
))
5776 result
= MOVE_NEWLINE_OR_CR
;
5780 #endif /* HAVE_WINDOW_SYSTEM */
5781 result
= MOVE_LINE_TRUNCATED
;
5786 #undef BUFFER_POS_REACHED_P
5788 /* Restore the iterator settings altered at the beginning of this
5790 it
->glyph_row
= saved_glyph_row
;
5795 /* Move IT forward until it satisfies one or more of the criteria in
5796 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
5798 OP is a bit-mask that specifies where to stop, and in particular,
5799 which of those four position arguments makes a difference. See the
5800 description of enum move_operation_enum.
5802 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5803 screen line, this function will set IT to the next position >
5807 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5809 int to_charpos
, to_x
, to_y
, to_vpos
;
5812 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5818 if (op
& MOVE_TO_VPOS
)
5820 /* If no TO_CHARPOS and no TO_X specified, stop at the
5821 start of the line TO_VPOS. */
5822 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5824 if (it
->vpos
== to_vpos
)
5830 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5834 /* TO_VPOS >= 0 means stop at TO_X in the line at
5835 TO_VPOS, or at TO_POS, whichever comes first. */
5836 if (it
->vpos
== to_vpos
)
5842 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5844 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5849 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5851 /* We have reached TO_X but not in the line we want. */
5852 skip
= move_it_in_display_line_to (it
, to_charpos
,
5854 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5862 else if (op
& MOVE_TO_Y
)
5864 struct it it_backup
;
5866 /* TO_Y specified means stop at TO_X in the line containing
5867 TO_Y---or at TO_CHARPOS if this is reached first. The
5868 problem is that we can't really tell whether the line
5869 contains TO_Y before we have completely scanned it, and
5870 this may skip past TO_X. What we do is to first scan to
5873 If TO_X is not specified, use a TO_X of zero. The reason
5874 is to make the outcome of this function more predictable.
5875 If we didn't use TO_X == 0, we would stop at the end of
5876 the line which is probably not what a caller would expect
5878 skip
= move_it_in_display_line_to (it
, to_charpos
,
5882 | (op
& MOVE_TO_POS
)));
5884 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5885 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5891 /* If TO_X was reached, we would like to know whether TO_Y
5892 is in the line. This can only be said if we know the
5893 total line height which requires us to scan the rest of
5895 if (skip
== MOVE_X_REACHED
)
5898 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5899 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5901 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5904 /* Now, decide whether TO_Y is in this line. */
5905 line_height
= it
->max_ascent
+ it
->max_descent
;
5906 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5908 if (to_y
>= it
->current_y
5909 && to_y
< it
->current_y
+ line_height
)
5911 if (skip
== MOVE_X_REACHED
)
5912 /* If TO_Y is in this line and TO_X was reached above,
5913 we scanned too far. We have to restore IT's settings
5914 to the ones before skipping. */
5918 else if (skip
== MOVE_X_REACHED
)
5921 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5929 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5933 case MOVE_POS_MATCH_OR_ZV
:
5937 case MOVE_NEWLINE_OR_CR
:
5938 set_iterator_to_next (it
, 1);
5939 it
->continuation_lines_width
= 0;
5942 case MOVE_LINE_TRUNCATED
:
5943 it
->continuation_lines_width
= 0;
5944 reseat_at_next_visible_line_start (it
, 0);
5945 if ((op
& MOVE_TO_POS
) != 0
5946 && IT_CHARPOS (*it
) > to_charpos
)
5953 case MOVE_LINE_CONTINUED
:
5954 it
->continuation_lines_width
+= it
->current_x
;
5961 /* Reset/increment for the next run. */
5962 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5963 it
->current_x
= it
->hpos
= 0;
5964 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5966 last_height
= it
->max_ascent
+ it
->max_descent
;
5967 last_max_ascent
= it
->max_ascent
;
5968 it
->max_ascent
= it
->max_descent
= 0;
5973 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5977 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5979 If DY > 0, move IT backward at least that many pixels. DY = 0
5980 means move IT backward to the preceding line start or BEGV. This
5981 function may move over more than DY pixels if IT->current_y - DY
5982 ends up in the middle of a line; in this case IT->current_y will be
5983 set to the top of the line moved to. */
5986 move_it_vertically_backward (it
, dy
)
5992 int start_pos
= IT_CHARPOS (*it
);
5996 /* Estimate how many newlines we must move back. */
5997 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
5999 /* Set the iterator's position that many lines back. */
6000 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6001 back_to_previous_visible_line_start (it
);
6003 /* Reseat the iterator here. When moving backward, we don't want
6004 reseat to skip forward over invisible text, set up the iterator
6005 to deliver from overlay strings at the new position etc. So,
6006 use reseat_1 here. */
6007 reseat_1 (it
, it
->current
.pos
, 1);
6009 /* We are now surely at a line start. */
6010 it
->current_x
= it
->hpos
= 0;
6011 it
->continuation_lines_width
= 0;
6013 /* Move forward and see what y-distance we moved. First move to the
6014 start of the next line so that we get its height. We need this
6015 height to be able to tell whether we reached the specified
6018 it2
.max_ascent
= it2
.max_descent
= 0;
6019 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6020 MOVE_TO_POS
| MOVE_TO_VPOS
);
6021 xassert (IT_CHARPOS (*it
) >= BEGV
);
6024 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6025 xassert (IT_CHARPOS (*it
) >= BEGV
);
6026 /* H is the actual vertical distance from the position in *IT
6027 and the starting position. */
6028 h
= it2
.current_y
- it
->current_y
;
6029 /* NLINES is the distance in number of lines. */
6030 nlines
= it2
.vpos
- it
->vpos
;
6032 /* Correct IT's y and vpos position
6033 so that they are relative to the starting point. */
6039 /* DY == 0 means move to the start of the screen line. The
6040 value of nlines is > 0 if continuation lines were involved. */
6042 move_it_by_lines (it
, nlines
, 1);
6043 xassert (IT_CHARPOS (*it
) <= start_pos
);
6047 /* The y-position we try to reach, relative to *IT.
6048 Note that H has been subtracted in front of the if-statement. */
6049 int target_y
= it
->current_y
+ h
- dy
;
6050 int y0
= it3
.current_y
;
6051 int y1
= line_bottom_y (&it3
);
6052 int line_height
= y1
- y0
;
6054 /* If we did not reach target_y, try to move further backward if
6055 we can. If we moved too far backward, try to move forward. */
6056 if (target_y
< it
->current_y
6057 /* This is heuristic. In a window that's 3 lines high, with
6058 a line height of 13 pixels each, recentering with point
6059 on the bottom line will try to move -39/2 = 19 pixels
6060 backward. Try to avoid moving into the first line. */
6061 && it
->current_y
- target_y
> line_height
/ 3 * 2
6062 && IT_CHARPOS (*it
) > BEGV
)
6064 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6065 target_y
- it
->current_y
));
6066 move_it_vertically (it
, target_y
- it
->current_y
);
6067 xassert (IT_CHARPOS (*it
) >= BEGV
);
6069 else if (target_y
>= it
->current_y
+ line_height
6070 && IT_CHARPOS (*it
) < ZV
)
6072 /* Should move forward by at least one line, maybe more.
6074 Note: Calling move_it_by_lines can be expensive on
6075 terminal frames, where compute_motion is used (via
6076 vmotion) to do the job, when there are very long lines
6077 and truncate-lines is nil. That's the reason for
6078 treating terminal frames specially here. */
6080 if (!FRAME_WINDOW_P (it
->f
))
6081 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6086 move_it_by_lines (it
, 1, 1);
6088 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6091 xassert (IT_CHARPOS (*it
) >= BEGV
);
6097 /* Move IT by a specified amount of pixel lines DY. DY negative means
6098 move backwards. DY = 0 means move to start of screen line. At the
6099 end, IT will be on the start of a screen line. */
6102 move_it_vertically (it
, dy
)
6107 move_it_vertically_backward (it
, -dy
);
6110 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6111 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6112 MOVE_TO_POS
| MOVE_TO_Y
);
6113 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6115 /* If buffer ends in ZV without a newline, move to the start of
6116 the line to satisfy the post-condition. */
6117 if (IT_CHARPOS (*it
) == ZV
6118 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6119 move_it_by_lines (it
, 0, 0);
6124 /* Move iterator IT past the end of the text line it is in. */
6127 move_it_past_eol (it
)
6130 enum move_it_result rc
;
6132 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6133 if (rc
== MOVE_NEWLINE_OR_CR
)
6134 set_iterator_to_next (it
, 0);
6138 #if 0 /* Currently not used. */
6140 /* Return non-zero if some text between buffer positions START_CHARPOS
6141 and END_CHARPOS is invisible. IT->window is the window for text
6145 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6147 int start_charpos
, end_charpos
;
6149 Lisp_Object prop
, limit
;
6150 int invisible_found_p
;
6152 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6154 /* Is text at START invisible? */
6155 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6157 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6158 invisible_found_p
= 1;
6161 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6163 make_number (end_charpos
));
6164 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6167 return invisible_found_p
;
6173 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6174 negative means move up. DVPOS == 0 means move to the start of the
6175 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6176 NEED_Y_P is zero, IT->current_y will be left unchanged.
6178 Further optimization ideas: If we would know that IT->f doesn't use
6179 a face with proportional font, we could be faster for
6180 truncate-lines nil. */
6183 move_it_by_lines (it
, dvpos
, need_y_p
)
6185 int dvpos
, need_y_p
;
6187 struct position pos
;
6189 if (!FRAME_WINDOW_P (it
->f
))
6191 struct text_pos textpos
;
6193 /* We can use vmotion on frames without proportional fonts. */
6194 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6195 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6196 reseat (it
, textpos
, 1);
6197 it
->vpos
+= pos
.vpos
;
6198 it
->current_y
+= pos
.vpos
;
6200 else if (dvpos
== 0)
6202 /* DVPOS == 0 means move to the start of the screen line. */
6203 move_it_vertically_backward (it
, 0);
6204 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6207 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6211 int start_charpos
, i
;
6213 /* Start at the beginning of the screen line containing IT's
6215 move_it_vertically_backward (it
, 0);
6217 /* Go back -DVPOS visible lines and reseat the iterator there. */
6218 start_charpos
= IT_CHARPOS (*it
);
6219 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
6220 back_to_previous_visible_line_start (it
);
6221 reseat (it
, it
->current
.pos
, 1);
6222 it
->current_x
= it
->hpos
= 0;
6224 /* Above call may have moved too far if continuation lines
6225 are involved. Scan forward and see if it did. */
6227 it2
.vpos
= it2
.current_y
= 0;
6228 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6229 it
->vpos
-= it2
.vpos
;
6230 it
->current_y
-= it2
.current_y
;
6231 it
->current_x
= it
->hpos
= 0;
6233 /* If we moved too far, move IT some lines forward. */
6234 if (it2
.vpos
> -dvpos
)
6236 int delta
= it2
.vpos
+ dvpos
;
6237 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6242 /* Return 1 if IT points into the middle of a display vector. */
6245 in_display_vector_p (it
)
6248 return (it
->method
== next_element_from_display_vector
6249 && it
->current
.dpvec_index
> 0
6250 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6254 /***********************************************************************
6256 ***********************************************************************/
6259 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6263 add_to_log (format
, arg1
, arg2
)
6265 Lisp_Object arg1
, arg2
;
6267 Lisp_Object args
[3];
6268 Lisp_Object msg
, fmt
;
6271 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6273 /* Do nothing if called asynchronously. Inserting text into
6274 a buffer may call after-change-functions and alike and
6275 that would means running Lisp asynchronously. */
6276 if (handling_signal
)
6280 GCPRO4 (fmt
, msg
, arg1
, arg2
);
6282 args
[0] = fmt
= build_string (format
);
6285 msg
= Fformat (3, args
);
6287 len
= SBYTES (msg
) + 1;
6288 buffer
= (char *) alloca (len
);
6289 bcopy (SDATA (msg
), buffer
, len
);
6291 message_dolog (buffer
, len
- 1, 1, 0);
6296 /* Output a newline in the *Messages* buffer if "needs" one. */
6299 message_log_maybe_newline ()
6301 if (message_log_need_newline
)
6302 message_dolog ("", 0, 1, 0);
6306 /* Add a string M of length NBYTES to the message log, optionally
6307 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
6308 nonzero, means interpret the contents of M as multibyte. This
6309 function calls low-level routines in order to bypass text property
6310 hooks, etc. which might not be safe to run. */
6313 message_dolog (m
, nbytes
, nlflag
, multibyte
)
6315 int nbytes
, nlflag
, multibyte
;
6317 if (!NILP (Vmemory_full
))
6320 if (!NILP (Vmessage_log_max
))
6322 struct buffer
*oldbuf
;
6323 Lisp_Object oldpoint
, oldbegv
, oldzv
;
6324 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6325 int point_at_end
= 0;
6327 Lisp_Object old_deactivate_mark
, tem
;
6328 struct gcpro gcpro1
;
6330 old_deactivate_mark
= Vdeactivate_mark
;
6331 oldbuf
= current_buffer
;
6332 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
6333 current_buffer
->undo_list
= Qt
;
6335 oldpoint
= message_dolog_marker1
;
6336 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
6337 oldbegv
= message_dolog_marker2
;
6338 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
6339 oldzv
= message_dolog_marker3
;
6340 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
6341 GCPRO1 (old_deactivate_mark
);
6349 BEGV_BYTE
= BEG_BYTE
;
6352 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6354 /* Insert the string--maybe converting multibyte to single byte
6355 or vice versa, so that all the text fits the buffer. */
6357 && NILP (current_buffer
->enable_multibyte_characters
))
6359 int i
, c
, char_bytes
;
6360 unsigned char work
[1];
6362 /* Convert a multibyte string to single-byte
6363 for the *Message* buffer. */
6364 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
6366 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
6367 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6369 : multibyte_char_to_unibyte (c
, Qnil
));
6370 insert_1_both (work
, 1, 1, 1, 0, 0);
6373 else if (! multibyte
6374 && ! NILP (current_buffer
->enable_multibyte_characters
))
6376 int i
, c
, char_bytes
;
6377 unsigned char *msg
= (unsigned char *) m
;
6378 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6379 /* Convert a single-byte string to multibyte
6380 for the *Message* buffer. */
6381 for (i
= 0; i
< nbytes
; i
++)
6383 c
= unibyte_char_to_multibyte (msg
[i
]);
6384 char_bytes
= CHAR_STRING (c
, str
);
6385 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
6389 insert_1 (m
, nbytes
, 1, 0, 0);
6393 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
6394 insert_1 ("\n", 1, 1, 0, 0);
6396 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6398 this_bol_byte
= PT_BYTE
;
6400 /* See if this line duplicates the previous one.
6401 If so, combine duplicates. */
6404 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6406 prev_bol_byte
= PT_BYTE
;
6408 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
6409 this_bol
, this_bol_byte
);
6412 del_range_both (prev_bol
, prev_bol_byte
,
6413 this_bol
, this_bol_byte
, 0);
6419 /* If you change this format, don't forget to also
6420 change message_log_check_duplicate. */
6421 sprintf (dupstr
, " [%d times]", dup
);
6422 duplen
= strlen (dupstr
);
6423 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
6424 insert_1 (dupstr
, duplen
, 1, 0, 1);
6429 /* If we have more than the desired maximum number of lines
6430 in the *Messages* buffer now, delete the oldest ones.
6431 This is safe because we don't have undo in this buffer. */
6433 if (NATNUMP (Vmessage_log_max
))
6435 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
6436 -XFASTINT (Vmessage_log_max
) - 1, 0);
6437 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
6440 BEGV
= XMARKER (oldbegv
)->charpos
;
6441 BEGV_BYTE
= marker_byte_position (oldbegv
);
6450 ZV
= XMARKER (oldzv
)->charpos
;
6451 ZV_BYTE
= marker_byte_position (oldzv
);
6455 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6457 /* We can't do Fgoto_char (oldpoint) because it will run some
6459 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
6460 XMARKER (oldpoint
)->bytepos
);
6463 unchain_marker (XMARKER (oldpoint
));
6464 unchain_marker (XMARKER (oldbegv
));
6465 unchain_marker (XMARKER (oldzv
));
6467 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
6468 set_buffer_internal (oldbuf
);
6470 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6471 message_log_need_newline
= !nlflag
;
6472 Vdeactivate_mark
= old_deactivate_mark
;
6477 /* We are at the end of the buffer after just having inserted a newline.
6478 (Note: We depend on the fact we won't be crossing the gap.)
6479 Check to see if the most recent message looks a lot like the previous one.
6480 Return 0 if different, 1 if the new one should just replace it, or a
6481 value N > 1 if we should also append " [N times]". */
6484 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
6485 int prev_bol
, this_bol
;
6486 int prev_bol_byte
, this_bol_byte
;
6489 int len
= Z_BYTE
- 1 - this_bol_byte
;
6491 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
6492 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
6494 for (i
= 0; i
< len
; i
++)
6496 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
6504 if (*p1
++ == ' ' && *p1
++ == '[')
6507 while (*p1
>= '0' && *p1
<= '9')
6508 n
= n
* 10 + *p1
++ - '0';
6509 if (strncmp (p1
, " times]\n", 8) == 0)
6516 /* Display an echo area message M with a specified length of NBYTES
6517 bytes. The string may include null characters. If M is 0, clear
6518 out any existing message, and let the mini-buffer text show
6521 The buffer M must continue to exist until after the echo area gets
6522 cleared or some other message gets displayed there. This means do
6523 not pass text that is stored in a Lisp string; do not pass text in
6524 a buffer that was alloca'd. */
6527 message2 (m
, nbytes
, multibyte
)
6532 /* First flush out any partial line written with print. */
6533 message_log_maybe_newline ();
6535 message_dolog (m
, nbytes
, 1, multibyte
);
6536 message2_nolog (m
, nbytes
, multibyte
);
6540 /* The non-logging counterpart of message2. */
6543 message2_nolog (m
, nbytes
, multibyte
)
6545 int nbytes
, multibyte
;
6547 struct frame
*sf
= SELECTED_FRAME ();
6548 message_enable_multibyte
= multibyte
;
6552 if (noninteractive_need_newline
)
6553 putc ('\n', stderr
);
6554 noninteractive_need_newline
= 0;
6556 fwrite (m
, nbytes
, 1, stderr
);
6557 if (cursor_in_echo_area
== 0)
6558 fprintf (stderr
, "\n");
6561 /* A null message buffer means that the frame hasn't really been
6562 initialized yet. Error messages get reported properly by
6563 cmd_error, so this must be just an informative message; toss it. */
6564 else if (INTERACTIVE
6565 && sf
->glyphs_initialized_p
6566 && FRAME_MESSAGE_BUF (sf
))
6568 Lisp_Object mini_window
;
6571 /* Get the frame containing the mini-buffer
6572 that the selected frame is using. */
6573 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6574 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6576 FRAME_SAMPLE_VISIBILITY (f
);
6577 if (FRAME_VISIBLE_P (sf
)
6578 && ! FRAME_VISIBLE_P (f
))
6579 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
6583 set_message (m
, Qnil
, nbytes
, multibyte
);
6584 if (minibuffer_auto_raise
)
6585 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6588 clear_message (1, 1);
6590 do_pending_window_change (0);
6591 echo_area_display (1);
6592 do_pending_window_change (0);
6593 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6594 (*frame_up_to_date_hook
) (f
);
6599 /* Display an echo area message M with a specified length of NBYTES
6600 bytes. The string may include null characters. If M is not a
6601 string, clear out any existing message, and let the mini-buffer
6602 text show through. */
6605 message3 (m
, nbytes
, multibyte
)
6610 struct gcpro gcpro1
;
6614 /* First flush out any partial line written with print. */
6615 message_log_maybe_newline ();
6617 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
6618 message3_nolog (m
, nbytes
, multibyte
);
6624 /* The non-logging version of message3. */
6627 message3_nolog (m
, nbytes
, multibyte
)
6629 int nbytes
, multibyte
;
6631 struct frame
*sf
= SELECTED_FRAME ();
6632 message_enable_multibyte
= multibyte
;
6636 if (noninteractive_need_newline
)
6637 putc ('\n', stderr
);
6638 noninteractive_need_newline
= 0;
6640 fwrite (SDATA (m
), nbytes
, 1, stderr
);
6641 if (cursor_in_echo_area
== 0)
6642 fprintf (stderr
, "\n");
6645 /* A null message buffer means that the frame hasn't really been
6646 initialized yet. Error messages get reported properly by
6647 cmd_error, so this must be just an informative message; toss it. */
6648 else if (INTERACTIVE
6649 && sf
->glyphs_initialized_p
6650 && FRAME_MESSAGE_BUF (sf
))
6652 Lisp_Object mini_window
;
6656 /* Get the frame containing the mini-buffer
6657 that the selected frame is using. */
6658 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6659 frame
= XWINDOW (mini_window
)->frame
;
6662 FRAME_SAMPLE_VISIBILITY (f
);
6663 if (FRAME_VISIBLE_P (sf
)
6664 && !FRAME_VISIBLE_P (f
))
6665 Fmake_frame_visible (frame
);
6667 if (STRINGP (m
) && SCHARS (m
) > 0)
6669 set_message (NULL
, m
, nbytes
, multibyte
);
6670 if (minibuffer_auto_raise
)
6671 Fraise_frame (frame
);
6674 clear_message (1, 1);
6676 do_pending_window_change (0);
6677 echo_area_display (1);
6678 do_pending_window_change (0);
6679 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6680 (*frame_up_to_date_hook
) (f
);
6685 /* Display a null-terminated echo area message M. If M is 0, clear
6686 out any existing message, and let the mini-buffer text show through.
6688 The buffer M must continue to exist until after the echo area gets
6689 cleared or some other message gets displayed there. Do not pass
6690 text that is stored in a Lisp string. Do not pass text in a buffer
6691 that was alloca'd. */
6697 message2 (m
, (m
? strlen (m
) : 0), 0);
6701 /* The non-logging counterpart of message1. */
6707 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6710 /* Display a message M which contains a single %s
6711 which gets replaced with STRING. */
6714 message_with_string (m
, string
, log
)
6719 CHECK_STRING (string
);
6725 if (noninteractive_need_newline
)
6726 putc ('\n', stderr
);
6727 noninteractive_need_newline
= 0;
6728 fprintf (stderr
, m
, SDATA (string
));
6729 if (cursor_in_echo_area
== 0)
6730 fprintf (stderr
, "\n");
6734 else if (INTERACTIVE
)
6736 /* The frame whose minibuffer we're going to display the message on.
6737 It may be larger than the selected frame, so we need
6738 to use its buffer, not the selected frame's buffer. */
6739 Lisp_Object mini_window
;
6740 struct frame
*f
, *sf
= SELECTED_FRAME ();
6742 /* Get the frame containing the minibuffer
6743 that the selected frame is using. */
6744 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6745 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6747 /* A null message buffer means that the frame hasn't really been
6748 initialized yet. Error messages get reported properly by
6749 cmd_error, so this must be just an informative message; toss it. */
6750 if (FRAME_MESSAGE_BUF (f
))
6752 Lisp_Object args
[2], message
;
6753 struct gcpro gcpro1
, gcpro2
;
6755 args
[0] = build_string (m
);
6756 args
[1] = message
= string
;
6757 GCPRO2 (args
[0], message
);
6760 message
= Fformat (2, args
);
6763 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6765 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6769 /* Print should start at the beginning of the message
6770 buffer next time. */
6771 message_buf_print
= 0;
6777 /* Dump an informative message to the minibuf. If M is 0, clear out
6778 any existing message, and let the mini-buffer text show through. */
6782 message (m
, a1
, a2
, a3
)
6784 EMACS_INT a1
, a2
, a3
;
6790 if (noninteractive_need_newline
)
6791 putc ('\n', stderr
);
6792 noninteractive_need_newline
= 0;
6793 fprintf (stderr
, m
, a1
, a2
, a3
);
6794 if (cursor_in_echo_area
== 0)
6795 fprintf (stderr
, "\n");
6799 else if (INTERACTIVE
)
6801 /* The frame whose mini-buffer we're going to display the message
6802 on. It may be larger than the selected frame, so we need to
6803 use its buffer, not the selected frame's buffer. */
6804 Lisp_Object mini_window
;
6805 struct frame
*f
, *sf
= SELECTED_FRAME ();
6807 /* Get the frame containing the mini-buffer
6808 that the selected frame is using. */
6809 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6810 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6812 /* A null message buffer means that the frame hasn't really been
6813 initialized yet. Error messages get reported properly by
6814 cmd_error, so this must be just an informative message; toss
6816 if (FRAME_MESSAGE_BUF (f
))
6827 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6828 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6830 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6831 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6833 #endif /* NO_ARG_ARRAY */
6835 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6840 /* Print should start at the beginning of the message
6841 buffer next time. */
6842 message_buf_print
= 0;
6848 /* The non-logging version of message. */
6851 message_nolog (m
, a1
, a2
, a3
)
6853 EMACS_INT a1
, a2
, a3
;
6855 Lisp_Object old_log_max
;
6856 old_log_max
= Vmessage_log_max
;
6857 Vmessage_log_max
= Qnil
;
6858 message (m
, a1
, a2
, a3
);
6859 Vmessage_log_max
= old_log_max
;
6863 /* Display the current message in the current mini-buffer. This is
6864 only called from error handlers in process.c, and is not time
6870 if (!NILP (echo_area_buffer
[0]))
6873 string
= Fcurrent_message ();
6874 message3 (string
, SBYTES (string
),
6875 !NILP (current_buffer
->enable_multibyte_characters
));
6880 /* Make sure echo area buffers in `echo_buffers' are live.
6881 If they aren't, make new ones. */
6884 ensure_echo_area_buffers ()
6888 for (i
= 0; i
< 2; ++i
)
6889 if (!BUFFERP (echo_buffer
[i
])
6890 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6893 Lisp_Object old_buffer
;
6896 old_buffer
= echo_buffer
[i
];
6897 sprintf (name
, " *Echo Area %d*", i
);
6898 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6899 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6901 for (j
= 0; j
< 2; ++j
)
6902 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6903 echo_area_buffer
[j
] = echo_buffer
[i
];
6908 /* Call FN with args A1..A4 with either the current or last displayed
6909 echo_area_buffer as current buffer.
6911 WHICH zero means use the current message buffer
6912 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6913 from echo_buffer[] and clear it.
6915 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6916 suitable buffer from echo_buffer[] and clear it.
6918 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6919 that the current message becomes the last displayed one, make
6920 choose a suitable buffer for echo_area_buffer[0], and clear it.
6922 Value is what FN returns. */
6925 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6928 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6934 int this_one
, the_other
, clear_buffer_p
, rc
;
6935 int count
= SPECPDL_INDEX ();
6937 /* If buffers aren't live, make new ones. */
6938 ensure_echo_area_buffers ();
6943 this_one
= 0, the_other
= 1;
6945 this_one
= 1, the_other
= 0;
6948 this_one
= 0, the_other
= 1;
6951 /* We need a fresh one in case the current echo buffer equals
6952 the one containing the last displayed echo area message. */
6953 if (!NILP (echo_area_buffer
[this_one
])
6954 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6955 echo_area_buffer
[this_one
] = Qnil
;
6958 /* Choose a suitable buffer from echo_buffer[] is we don't
6960 if (NILP (echo_area_buffer
[this_one
]))
6962 echo_area_buffer
[this_one
]
6963 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6964 ? echo_buffer
[the_other
]
6965 : echo_buffer
[this_one
]);
6969 buffer
= echo_area_buffer
[this_one
];
6971 /* Don't get confused by reusing the buffer used for echoing
6972 for a different purpose. */
6973 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
6976 record_unwind_protect (unwind_with_echo_area_buffer
,
6977 with_echo_area_buffer_unwind_data (w
));
6979 /* Make the echo area buffer current. Note that for display
6980 purposes, it is not necessary that the displayed window's buffer
6981 == current_buffer, except for text property lookup. So, let's
6982 only set that buffer temporarily here without doing a full
6983 Fset_window_buffer. We must also change w->pointm, though,
6984 because otherwise an assertions in unshow_buffer fails, and Emacs
6986 set_buffer_internal_1 (XBUFFER (buffer
));
6990 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6993 current_buffer
->undo_list
= Qt
;
6994 current_buffer
->read_only
= Qnil
;
6995 specbind (Qinhibit_read_only
, Qt
);
6996 specbind (Qinhibit_modification_hooks
, Qt
);
6998 if (clear_buffer_p
&& Z
> BEG
)
7001 xassert (BEGV
>= BEG
);
7002 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7004 rc
= fn (a1
, a2
, a3
, a4
);
7006 xassert (BEGV
>= BEG
);
7007 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7009 unbind_to (count
, Qnil
);
7014 /* Save state that should be preserved around the call to the function
7015 FN called in with_echo_area_buffer. */
7018 with_echo_area_buffer_unwind_data (w
)
7024 /* Reduce consing by keeping one vector in
7025 Vwith_echo_area_save_vector. */
7026 vector
= Vwith_echo_area_save_vector
;
7027 Vwith_echo_area_save_vector
= Qnil
;
7030 vector
= Fmake_vector (make_number (7), Qnil
);
7032 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7033 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7034 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7038 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7039 AREF (vector
, i
) = w
->buffer
; ++i
;
7040 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7041 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7046 for (; i
< end
; ++i
)
7047 AREF (vector
, i
) = Qnil
;
7050 xassert (i
== ASIZE (vector
));
7055 /* Restore global state from VECTOR which was created by
7056 with_echo_area_buffer_unwind_data. */
7059 unwind_with_echo_area_buffer (vector
)
7062 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7063 Vdeactivate_mark
= AREF (vector
, 1);
7064 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7066 if (WINDOWP (AREF (vector
, 3)))
7069 Lisp_Object buffer
, charpos
, bytepos
;
7071 w
= XWINDOW (AREF (vector
, 3));
7072 buffer
= AREF (vector
, 4);
7073 charpos
= AREF (vector
, 5);
7074 bytepos
= AREF (vector
, 6);
7077 set_marker_both (w
->pointm
, buffer
,
7078 XFASTINT (charpos
), XFASTINT (bytepos
));
7081 Vwith_echo_area_save_vector
= vector
;
7086 /* Set up the echo area for use by print functions. MULTIBYTE_P
7087 non-zero means we will print multibyte. */
7090 setup_echo_area_for_printing (multibyte_p
)
7093 /* If we can't find an echo area any more, exit. */
7094 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7097 ensure_echo_area_buffers ();
7099 if (!message_buf_print
)
7101 /* A message has been output since the last time we printed.
7102 Choose a fresh echo area buffer. */
7103 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7104 echo_area_buffer
[0] = echo_buffer
[1];
7106 echo_area_buffer
[0] = echo_buffer
[0];
7108 /* Switch to that buffer and clear it. */
7109 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7110 current_buffer
->truncate_lines
= Qnil
;
7114 int count
= SPECPDL_INDEX ();
7115 specbind (Qinhibit_read_only
, Qt
);
7116 /* Note that undo recording is always disabled. */
7118 unbind_to (count
, Qnil
);
7120 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7122 /* Set up the buffer for the multibyteness we need. */
7124 != !NILP (current_buffer
->enable_multibyte_characters
))
7125 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7127 /* Raise the frame containing the echo area. */
7128 if (minibuffer_auto_raise
)
7130 struct frame
*sf
= SELECTED_FRAME ();
7131 Lisp_Object mini_window
;
7132 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7133 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7136 message_log_maybe_newline ();
7137 message_buf_print
= 1;
7141 if (NILP (echo_area_buffer
[0]))
7143 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7144 echo_area_buffer
[0] = echo_buffer
[1];
7146 echo_area_buffer
[0] = echo_buffer
[0];
7149 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7151 /* Someone switched buffers between print requests. */
7152 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7153 current_buffer
->truncate_lines
= Qnil
;
7159 /* Display an echo area message in window W. Value is non-zero if W's
7160 height is changed. If display_last_displayed_message_p is
7161 non-zero, display the message that was last displayed, otherwise
7162 display the current message. */
7165 display_echo_area (w
)
7168 int i
, no_message_p
, window_height_changed_p
, count
;
7170 /* Temporarily disable garbage collections while displaying the echo
7171 area. This is done because a GC can print a message itself.
7172 That message would modify the echo area buffer's contents while a
7173 redisplay of the buffer is going on, and seriously confuse
7175 count
= inhibit_garbage_collection ();
7177 /* If there is no message, we must call display_echo_area_1
7178 nevertheless because it resizes the window. But we will have to
7179 reset the echo_area_buffer in question to nil at the end because
7180 with_echo_area_buffer will sets it to an empty buffer. */
7181 i
= display_last_displayed_message_p
? 1 : 0;
7182 no_message_p
= NILP (echo_area_buffer
[i
]);
7184 window_height_changed_p
7185 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7186 display_echo_area_1
,
7187 (EMACS_INT
) w
, Qnil
, 0, 0);
7190 echo_area_buffer
[i
] = Qnil
;
7192 unbind_to (count
, Qnil
);
7193 return window_height_changed_p
;
7197 /* Helper for display_echo_area. Display the current buffer which
7198 contains the current echo area message in window W, a mini-window,
7199 a pointer to which is passed in A1. A2..A4 are currently not used.
7200 Change the height of W so that all of the message is displayed.
7201 Value is non-zero if height of W was changed. */
7204 display_echo_area_1 (a1
, a2
, a3
, a4
)
7209 struct window
*w
= (struct window
*) a1
;
7211 struct text_pos start
;
7212 int window_height_changed_p
= 0;
7214 /* Do this before displaying, so that we have a large enough glyph
7215 matrix for the display. */
7216 window_height_changed_p
= resize_mini_window (w
, 0);
7219 clear_glyph_matrix (w
->desired_matrix
);
7220 XSETWINDOW (window
, w
);
7221 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
7222 try_window (window
, start
);
7224 return window_height_changed_p
;
7228 /* Resize the echo area window to exactly the size needed for the
7229 currently displayed message, if there is one. If a mini-buffer
7230 is active, don't shrink it. */
7233 resize_echo_area_exactly ()
7235 if (BUFFERP (echo_area_buffer
[0])
7236 && WINDOWP (echo_area_window
))
7238 struct window
*w
= XWINDOW (echo_area_window
);
7240 Lisp_Object resize_exactly
;
7242 if (minibuf_level
== 0)
7243 resize_exactly
= Qt
;
7245 resize_exactly
= Qnil
;
7247 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7248 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7251 ++windows_or_buffers_changed
;
7252 ++update_mode_lines
;
7253 redisplay_internal (0);
7259 /* Callback function for with_echo_area_buffer, when used from
7260 resize_echo_area_exactly. A1 contains a pointer to the window to
7261 resize, EXACTLY non-nil means resize the mini-window exactly to the
7262 size of the text displayed. A3 and A4 are not used. Value is what
7263 resize_mini_window returns. */
7266 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
7268 Lisp_Object exactly
;
7271 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
7275 /* Resize mini-window W to fit the size of its contents. EXACT:P
7276 means size the window exactly to the size needed. Otherwise, it's
7277 only enlarged until W's buffer is empty. Value is non-zero if
7278 the window height has been changed. */
7281 resize_mini_window (w
, exact_p
)
7285 struct frame
*f
= XFRAME (w
->frame
);
7286 int window_height_changed_p
= 0;
7288 xassert (MINI_WINDOW_P (w
));
7290 /* Don't resize windows while redisplaying a window; it would
7291 confuse redisplay functions when the size of the window they are
7292 displaying changes from under them. Such a resizing can happen,
7293 for instance, when which-func prints a long message while
7294 we are running fontification-functions. We're running these
7295 functions with safe_call which binds inhibit-redisplay to t. */
7296 if (!NILP (Vinhibit_redisplay
))
7299 /* Nil means don't try to resize. */
7300 if (NILP (Vresize_mini_windows
)
7301 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
7304 if (!FRAME_MINIBUF_ONLY_P (f
))
7307 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7308 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
7309 int height
, max_height
;
7310 int unit
= FRAME_LINE_HEIGHT (f
);
7311 struct text_pos start
;
7312 struct buffer
*old_current_buffer
= NULL
;
7314 if (current_buffer
!= XBUFFER (w
->buffer
))
7316 old_current_buffer
= current_buffer
;
7317 set_buffer_internal (XBUFFER (w
->buffer
));
7320 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
7322 /* Compute the max. number of lines specified by the user. */
7323 if (FLOATP (Vmax_mini_window_height
))
7324 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
7325 else if (INTEGERP (Vmax_mini_window_height
))
7326 max_height
= XINT (Vmax_mini_window_height
);
7328 max_height
= total_height
/ 4;
7330 /* Correct that max. height if it's bogus. */
7331 max_height
= max (1, max_height
);
7332 max_height
= min (total_height
, max_height
);
7334 /* Find out the height of the text in the window. */
7335 if (it
.truncate_lines_p
)
7340 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
7341 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
7342 height
= it
.current_y
+ last_height
;
7344 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
7345 height
-= it
.extra_line_spacing
;
7346 height
= (height
+ unit
- 1) / unit
;
7349 /* Compute a suitable window start. */
7350 if (height
> max_height
)
7352 height
= max_height
;
7353 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
7354 move_it_vertically_backward (&it
, (height
- 1) * unit
);
7355 start
= it
.current
.pos
;
7358 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
7359 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
7361 if (EQ (Vresize_mini_windows
, Qgrow_only
))
7363 /* Let it grow only, until we display an empty message, in which
7364 case the window shrinks again. */
7365 if (height
> WINDOW_TOTAL_LINES (w
))
7367 int old_height
= WINDOW_TOTAL_LINES (w
);
7368 freeze_window_starts (f
, 1);
7369 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7370 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7372 else if (height
< WINDOW_TOTAL_LINES (w
)
7373 && (exact_p
|| BEGV
== ZV
))
7375 int old_height
= WINDOW_TOTAL_LINES (w
);
7376 freeze_window_starts (f
, 0);
7377 shrink_mini_window (w
);
7378 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7383 /* Always resize to exact size needed. */
7384 if (height
> WINDOW_TOTAL_LINES (w
))
7386 int old_height
= WINDOW_TOTAL_LINES (w
);
7387 freeze_window_starts (f
, 1);
7388 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7389 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7391 else if (height
< WINDOW_TOTAL_LINES (w
))
7393 int old_height
= WINDOW_TOTAL_LINES (w
);
7394 freeze_window_starts (f
, 0);
7395 shrink_mini_window (w
);
7399 freeze_window_starts (f
, 1);
7400 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7403 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7407 if (old_current_buffer
)
7408 set_buffer_internal (old_current_buffer
);
7411 return window_height_changed_p
;
7415 /* Value is the current message, a string, or nil if there is no
7423 if (NILP (echo_area_buffer
[0]))
7427 with_echo_area_buffer (0, 0, current_message_1
,
7428 (EMACS_INT
) &msg
, Qnil
, 0, 0);
7430 echo_area_buffer
[0] = Qnil
;
7438 current_message_1 (a1
, a2
, a3
, a4
)
7443 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
7446 *msg
= make_buffer_string (BEG
, Z
, 1);
7453 /* Push the current message on Vmessage_stack for later restauration
7454 by restore_message. Value is non-zero if the current message isn't
7455 empty. This is a relatively infrequent operation, so it's not
7456 worth optimizing. */
7462 msg
= current_message ();
7463 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
7464 return STRINGP (msg
);
7468 /* Restore message display from the top of Vmessage_stack. */
7475 xassert (CONSP (Vmessage_stack
));
7476 msg
= XCAR (Vmessage_stack
);
7478 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
7480 message3_nolog (msg
, 0, 0);
7484 /* Handler for record_unwind_protect calling pop_message. */
7487 pop_message_unwind (dummy
)
7494 /* Pop the top-most entry off Vmessage_stack. */
7499 xassert (CONSP (Vmessage_stack
));
7500 Vmessage_stack
= XCDR (Vmessage_stack
);
7504 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
7505 exits. If the stack is not empty, we have a missing pop_message
7509 check_message_stack ()
7511 if (!NILP (Vmessage_stack
))
7516 /* Truncate to NCHARS what will be displayed in the echo area the next
7517 time we display it---but don't redisplay it now. */
7520 truncate_echo_area (nchars
)
7524 echo_area_buffer
[0] = Qnil
;
7525 /* A null message buffer means that the frame hasn't really been
7526 initialized yet. Error messages get reported properly by
7527 cmd_error, so this must be just an informative message; toss it. */
7528 else if (!noninteractive
7530 && !NILP (echo_area_buffer
[0]))
7532 struct frame
*sf
= SELECTED_FRAME ();
7533 if (FRAME_MESSAGE_BUF (sf
))
7534 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
7539 /* Helper function for truncate_echo_area. Truncate the current
7540 message to at most NCHARS characters. */
7543 truncate_message_1 (nchars
, a2
, a3
, a4
)
7548 if (BEG
+ nchars
< Z
)
7549 del_range (BEG
+ nchars
, Z
);
7551 echo_area_buffer
[0] = Qnil
;
7556 /* Set the current message to a substring of S or STRING.
7558 If STRING is a Lisp string, set the message to the first NBYTES
7559 bytes from STRING. NBYTES zero means use the whole string. If
7560 STRING is multibyte, the message will be displayed multibyte.
7562 If S is not null, set the message to the first LEN bytes of S. LEN
7563 zero means use the whole string. MULTIBYTE_P non-zero means S is
7564 multibyte. Display the message multibyte in that case. */
7567 set_message (s
, string
, nbytes
, multibyte_p
)
7570 int nbytes
, multibyte_p
;
7572 message_enable_multibyte
7573 = ((s
&& multibyte_p
)
7574 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
7576 with_echo_area_buffer (0, -1, set_message_1
,
7577 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
7578 message_buf_print
= 0;
7579 help_echo_showing_p
= 0;
7583 /* Helper function for set_message. Arguments have the same meaning
7584 as there, with A1 corresponding to S and A2 corresponding to STRING
7585 This function is called with the echo area buffer being
7589 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
7592 EMACS_INT nbytes
, multibyte_p
;
7594 const char *s
= (const char *) a1
;
7595 Lisp_Object string
= a2
;
7599 /* Change multibyteness of the echo buffer appropriately. */
7600 if (message_enable_multibyte
7601 != !NILP (current_buffer
->enable_multibyte_characters
))
7602 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
7604 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
7606 /* Insert new message at BEG. */
7607 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7609 if (STRINGP (string
))
7614 nbytes
= SBYTES (string
);
7615 nchars
= string_byte_to_char (string
, nbytes
);
7617 /* This function takes care of single/multibyte conversion. We
7618 just have to ensure that the echo area buffer has the right
7619 setting of enable_multibyte_characters. */
7620 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7625 nbytes
= strlen (s
);
7627 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
7629 /* Convert from multi-byte to single-byte. */
7631 unsigned char work
[1];
7633 /* Convert a multibyte string to single-byte. */
7634 for (i
= 0; i
< nbytes
; i
+= n
)
7636 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
7637 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7639 : multibyte_char_to_unibyte (c
, Qnil
));
7640 insert_1_both (work
, 1, 1, 1, 0, 0);
7643 else if (!multibyte_p
7644 && !NILP (current_buffer
->enable_multibyte_characters
))
7646 /* Convert from single-byte to multi-byte. */
7648 const unsigned char *msg
= (const unsigned char *) s
;
7649 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7651 /* Convert a single-byte string to multibyte. */
7652 for (i
= 0; i
< nbytes
; i
++)
7654 c
= unibyte_char_to_multibyte (msg
[i
]);
7655 n
= CHAR_STRING (c
, str
);
7656 insert_1_both (str
, 1, n
, 1, 0, 0);
7660 insert_1 (s
, nbytes
, 1, 0, 0);
7667 /* Clear messages. CURRENT_P non-zero means clear the current
7668 message. LAST_DISPLAYED_P non-zero means clear the message
7672 clear_message (current_p
, last_displayed_p
)
7673 int current_p
, last_displayed_p
;
7677 echo_area_buffer
[0] = Qnil
;
7678 message_cleared_p
= 1;
7681 if (last_displayed_p
)
7682 echo_area_buffer
[1] = Qnil
;
7684 message_buf_print
= 0;
7687 /* Clear garbaged frames.
7689 This function is used where the old redisplay called
7690 redraw_garbaged_frames which in turn called redraw_frame which in
7691 turn called clear_frame. The call to clear_frame was a source of
7692 flickering. I believe a clear_frame is not necessary. It should
7693 suffice in the new redisplay to invalidate all current matrices,
7694 and ensure a complete redisplay of all windows. */
7697 clear_garbaged_frames ()
7701 Lisp_Object tail
, frame
;
7702 int changed_count
= 0;
7704 FOR_EACH_FRAME (tail
, frame
)
7706 struct frame
*f
= XFRAME (frame
);
7708 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7712 Fredraw_frame (frame
);
7713 f
->force_flush_display_p
= 1;
7715 clear_current_matrices (f
);
7724 ++windows_or_buffers_changed
;
7729 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7730 is non-zero update selected_frame. Value is non-zero if the
7731 mini-windows height has been changed. */
7734 echo_area_display (update_frame_p
)
7737 Lisp_Object mini_window
;
7740 int window_height_changed_p
= 0;
7741 struct frame
*sf
= SELECTED_FRAME ();
7743 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7744 w
= XWINDOW (mini_window
);
7745 f
= XFRAME (WINDOW_FRAME (w
));
7747 /* Don't display if frame is invisible or not yet initialized. */
7748 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7751 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7753 #ifdef HAVE_WINDOW_SYSTEM
7754 /* When Emacs starts, selected_frame may be a visible terminal
7755 frame, even if we run under a window system. If we let this
7756 through, a message would be displayed on the terminal. */
7757 if (EQ (selected_frame
, Vterminal_frame
)
7758 && !NILP (Vwindow_system
))
7760 #endif /* HAVE_WINDOW_SYSTEM */
7763 /* Redraw garbaged frames. */
7765 clear_garbaged_frames ();
7767 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7769 echo_area_window
= mini_window
;
7770 window_height_changed_p
= display_echo_area (w
);
7771 w
->must_be_updated_p
= 1;
7773 /* Update the display, unless called from redisplay_internal.
7774 Also don't update the screen during redisplay itself. The
7775 update will happen at the end of redisplay, and an update
7776 here could cause confusion. */
7777 if (update_frame_p
&& !redisplaying_p
)
7781 /* If the display update has been interrupted by pending
7782 input, update mode lines in the frame. Due to the
7783 pending input, it might have been that redisplay hasn't
7784 been called, so that mode lines above the echo area are
7785 garbaged. This looks odd, so we prevent it here. */
7786 if (!display_completed
)
7787 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7789 if (window_height_changed_p
7790 /* Don't do this if Emacs is shutting down. Redisplay
7791 needs to run hooks. */
7792 && !NILP (Vrun_hooks
))
7794 /* Must update other windows. Likewise as in other
7795 cases, don't let this update be interrupted by
7797 int count
= SPECPDL_INDEX ();
7798 specbind (Qredisplay_dont_pause
, Qt
);
7799 windows_or_buffers_changed
= 1;
7800 redisplay_internal (0);
7801 unbind_to (count
, Qnil
);
7803 else if (FRAME_WINDOW_P (f
) && n
== 0)
7805 /* Window configuration is the same as before.
7806 Can do with a display update of the echo area,
7807 unless we displayed some mode lines. */
7808 update_single_window (w
, 1);
7809 rif
->flush_display (f
);
7812 update_frame (f
, 1, 1);
7814 /* If cursor is in the echo area, make sure that the next
7815 redisplay displays the minibuffer, so that the cursor will
7816 be replaced with what the minibuffer wants. */
7817 if (cursor_in_echo_area
)
7818 ++windows_or_buffers_changed
;
7821 else if (!EQ (mini_window
, selected_window
))
7822 windows_or_buffers_changed
++;
7824 /* Last displayed message is now the current message. */
7825 echo_area_buffer
[1] = echo_area_buffer
[0];
7827 /* Prevent redisplay optimization in redisplay_internal by resetting
7828 this_line_start_pos. This is done because the mini-buffer now
7829 displays the message instead of its buffer text. */
7830 if (EQ (mini_window
, selected_window
))
7831 CHARPOS (this_line_start_pos
) = 0;
7833 return window_height_changed_p
;
7838 /***********************************************************************
7840 ***********************************************************************/
7843 /* The frame title buffering code is also used by Fformat_mode_line.
7844 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
7846 /* A buffer for constructing frame titles in it; allocated from the
7847 heap in init_xdisp and resized as needed in store_frame_title_char. */
7849 static char *frame_title_buf
;
7851 /* The buffer's end, and a current output position in it. */
7853 static char *frame_title_buf_end
;
7854 static char *frame_title_ptr
;
7857 /* Store a single character C for the frame title in frame_title_buf.
7858 Re-allocate frame_title_buf if necessary. */
7862 store_frame_title_char (char c
)
7864 store_frame_title_char (c
)
7868 /* If output position has reached the end of the allocated buffer,
7869 double the buffer's size. */
7870 if (frame_title_ptr
== frame_title_buf_end
)
7872 int len
= frame_title_ptr
- frame_title_buf
;
7873 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7874 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7875 frame_title_buf_end
= frame_title_buf
+ new_size
;
7876 frame_title_ptr
= frame_title_buf
+ len
;
7879 *frame_title_ptr
++ = c
;
7883 /* Store part of a frame title in frame_title_buf, beginning at
7884 frame_title_ptr. STR is the string to store. Do not copy
7885 characters that yield more columns than PRECISION; PRECISION <= 0
7886 means copy the whole string. Pad with spaces until FIELD_WIDTH
7887 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7888 pad. Called from display_mode_element when it is used to build a
7892 store_frame_title (str
, field_width
, precision
)
7893 const unsigned char *str
;
7894 int field_width
, precision
;
7899 /* Copy at most PRECISION chars from STR. */
7900 nbytes
= strlen (str
);
7901 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7903 store_frame_title_char (*str
++);
7905 /* Fill up with spaces until FIELD_WIDTH reached. */
7906 while (field_width
> 0
7909 store_frame_title_char (' ');
7916 #ifdef HAVE_WINDOW_SYSTEM
7918 /* Set the title of FRAME, if it has changed. The title format is
7919 Vicon_title_format if FRAME is iconified, otherwise it is
7920 frame_title_format. */
7923 x_consider_frame_title (frame
)
7926 struct frame
*f
= XFRAME (frame
);
7928 if (FRAME_WINDOW_P (f
)
7929 || FRAME_MINIBUF_ONLY_P (f
)
7930 || f
->explicit_name
)
7932 /* Do we have more than one visible frame on this X display? */
7935 struct buffer
*obuf
;
7939 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7941 Lisp_Object other_frame
= XCAR (tail
);
7942 struct frame
*tf
= XFRAME (other_frame
);
7945 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7946 && !FRAME_MINIBUF_ONLY_P (tf
)
7947 && !EQ (other_frame
, tip_frame
)
7948 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7952 /* Set global variable indicating that multiple frames exist. */
7953 multiple_frames
= CONSP (tail
);
7955 /* Switch to the buffer of selected window of the frame. Set up
7956 frame_title_ptr so that display_mode_element will output into it;
7957 then display the title. */
7958 obuf
= current_buffer
;
7959 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
7960 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7961 frame_title_ptr
= frame_title_buf
;
7962 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7963 NULL
, DEFAULT_FACE_ID
);
7964 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
7965 len
= frame_title_ptr
- frame_title_buf
;
7966 frame_title_ptr
= NULL
;
7967 set_buffer_internal_1 (obuf
);
7969 /* Set the title only if it's changed. This avoids consing in
7970 the common case where it hasn't. (If it turns out that we've
7971 already wasted too much time by walking through the list with
7972 display_mode_element, then we might need to optimize at a
7973 higher level than this.) */
7974 if (! STRINGP (f
->name
)
7975 || SBYTES (f
->name
) != len
7976 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
7977 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7981 #endif /* not HAVE_WINDOW_SYSTEM */
7986 /***********************************************************************
7988 ***********************************************************************/
7991 /* Prepare for redisplay by updating menu-bar item lists when
7992 appropriate. This can call eval. */
7995 prepare_menu_bars ()
7998 struct gcpro gcpro1
, gcpro2
;
8000 Lisp_Object tooltip_frame
;
8002 #ifdef HAVE_WINDOW_SYSTEM
8003 tooltip_frame
= tip_frame
;
8005 tooltip_frame
= Qnil
;
8008 /* Update all frame titles based on their buffer names, etc. We do
8009 this before the menu bars so that the buffer-menu will show the
8010 up-to-date frame titles. */
8011 #ifdef HAVE_WINDOW_SYSTEM
8012 if (windows_or_buffers_changed
|| update_mode_lines
)
8014 Lisp_Object tail
, frame
;
8016 FOR_EACH_FRAME (tail
, frame
)
8019 if (!EQ (frame
, tooltip_frame
)
8020 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8021 x_consider_frame_title (frame
);
8024 #endif /* HAVE_WINDOW_SYSTEM */
8026 /* Update the menu bar item lists, if appropriate. This has to be
8027 done before any actual redisplay or generation of display lines. */
8028 all_windows
= (update_mode_lines
8029 || buffer_shared
> 1
8030 || windows_or_buffers_changed
);
8033 Lisp_Object tail
, frame
;
8034 int count
= SPECPDL_INDEX ();
8036 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8038 FOR_EACH_FRAME (tail
, frame
)
8042 /* Ignore tooltip frame. */
8043 if (EQ (frame
, tooltip_frame
))
8046 /* If a window on this frame changed size, report that to
8047 the user and clear the size-change flag. */
8048 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8050 Lisp_Object functions
;
8052 /* Clear flag first in case we get an error below. */
8053 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8054 functions
= Vwindow_size_change_functions
;
8055 GCPRO2 (tail
, functions
);
8057 while (CONSP (functions
))
8059 call1 (XCAR (functions
), frame
);
8060 functions
= XCDR (functions
);
8066 update_menu_bar (f
, 0);
8067 #ifdef HAVE_WINDOW_SYSTEM
8068 update_tool_bar (f
, 0);
8073 unbind_to (count
, Qnil
);
8077 struct frame
*sf
= SELECTED_FRAME ();
8078 update_menu_bar (sf
, 1);
8079 #ifdef HAVE_WINDOW_SYSTEM
8080 update_tool_bar (sf
, 1);
8084 /* Motif needs this. See comment in xmenu.c. Turn it off when
8085 pending_menu_activation is not defined. */
8086 #ifdef USE_X_TOOLKIT
8087 pending_menu_activation
= 0;
8092 /* Update the menu bar item list for frame F. This has to be done
8093 before we start to fill in any display lines, because it can call
8096 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8099 update_menu_bar (f
, save_match_data
)
8101 int save_match_data
;
8104 register struct window
*w
;
8106 /* If called recursively during a menu update, do nothing. This can
8107 happen when, for instance, an activate-menubar-hook causes a
8109 if (inhibit_menubar_update
)
8112 window
= FRAME_SELECTED_WINDOW (f
);
8113 w
= XWINDOW (window
);
8115 #if 0 /* The if statement below this if statement used to include the
8116 condition !NILP (w->update_mode_line), rather than using
8117 update_mode_lines directly, and this if statement may have
8118 been added to make that condition work. Now the if
8119 statement below matches its comment, this isn't needed. */
8120 if (update_mode_lines
)
8121 w
->update_mode_line
= Qt
;
8124 if (FRAME_WINDOW_P (f
)
8126 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8127 || defined (USE_GTK)
8128 FRAME_EXTERNAL_MENU_BAR (f
)
8130 FRAME_MENU_BAR_LINES (f
) > 0
8132 : FRAME_MENU_BAR_LINES (f
) > 0)
8134 /* If the user has switched buffers or windows, we need to
8135 recompute to reflect the new bindings. But we'll
8136 recompute when update_mode_lines is set too; that means
8137 that people can use force-mode-line-update to request
8138 that the menu bar be recomputed. The adverse effect on
8139 the rest of the redisplay algorithm is about the same as
8140 windows_or_buffers_changed anyway. */
8141 if (windows_or_buffers_changed
8142 /* This used to test w->update_mode_line, but we believe
8143 there is no need to recompute the menu in that case. */
8144 || update_mode_lines
8145 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8146 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8147 != !NILP (w
->last_had_star
))
8148 || ((!NILP (Vtransient_mark_mode
)
8149 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8150 != !NILP (w
->region_showing
)))
8152 struct buffer
*prev
= current_buffer
;
8153 int count
= SPECPDL_INDEX ();
8155 specbind (Qinhibit_menubar_update
, Qt
);
8157 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8158 if (save_match_data
)
8159 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8160 if (NILP (Voverriding_local_map_menu_flag
))
8162 specbind (Qoverriding_terminal_local_map
, Qnil
);
8163 specbind (Qoverriding_local_map
, Qnil
);
8166 /* Run the Lucid hook. */
8167 safe_run_hooks (Qactivate_menubar_hook
);
8169 /* If it has changed current-menubar from previous value,
8170 really recompute the menu-bar from the value. */
8171 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8172 call0 (Qrecompute_lucid_menubar
);
8174 safe_run_hooks (Qmenu_bar_update_hook
);
8175 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
8177 /* Redisplay the menu bar in case we changed it. */
8178 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8179 || defined (USE_GTK)
8180 if (FRAME_WINDOW_P (f
)
8181 #if defined (MAC_OS)
8182 /* All frames on Mac OS share the same menubar. So only the
8183 selected frame should be allowed to set it. */
8184 && f
== SELECTED_FRAME ()
8187 set_frame_menubar (f
, 0, 0);
8189 /* On a terminal screen, the menu bar is an ordinary screen
8190 line, and this makes it get updated. */
8191 w
->update_mode_line
= Qt
;
8192 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8193 /* In the non-toolkit version, the menu bar is an ordinary screen
8194 line, and this makes it get updated. */
8195 w
->update_mode_line
= Qt
;
8196 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8198 unbind_to (count
, Qnil
);
8199 set_buffer_internal_1 (prev
);
8206 /***********************************************************************
8208 ***********************************************************************/
8210 #ifdef HAVE_WINDOW_SYSTEM
8213 Nominal cursor position -- where to draw output.
8214 HPOS and VPOS are window relative glyph matrix coordinates.
8215 X and Y are window relative pixel coordinates. */
8217 struct cursor_pos output_cursor
;
8221 Set the global variable output_cursor to CURSOR. All cursor
8222 positions are relative to updated_window. */
8225 set_output_cursor (cursor
)
8226 struct cursor_pos
*cursor
;
8228 output_cursor
.hpos
= cursor
->hpos
;
8229 output_cursor
.vpos
= cursor
->vpos
;
8230 output_cursor
.x
= cursor
->x
;
8231 output_cursor
.y
= cursor
->y
;
8236 Set a nominal cursor position.
8238 HPOS and VPOS are column/row positions in a window glyph matrix. X
8239 and Y are window text area relative pixel positions.
8241 If this is done during an update, updated_window will contain the
8242 window that is being updated and the position is the future output
8243 cursor position for that window. If updated_window is null, use
8244 selected_window and display the cursor at the given position. */
8247 x_cursor_to (vpos
, hpos
, y
, x
)
8248 int vpos
, hpos
, y
, x
;
8252 /* If updated_window is not set, work on selected_window. */
8256 w
= XWINDOW (selected_window
);
8258 /* Set the output cursor. */
8259 output_cursor
.hpos
= hpos
;
8260 output_cursor
.vpos
= vpos
;
8261 output_cursor
.x
= x
;
8262 output_cursor
.y
= y
;
8264 /* If not called as part of an update, really display the cursor.
8265 This will also set the cursor position of W. */
8266 if (updated_window
== NULL
)
8269 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8270 if (rif
->flush_display_optional
)
8271 rif
->flush_display_optional (SELECTED_FRAME ());
8276 #endif /* HAVE_WINDOW_SYSTEM */
8279 /***********************************************************************
8281 ***********************************************************************/
8283 #ifdef HAVE_WINDOW_SYSTEM
8285 /* Where the mouse was last time we reported a mouse event. */
8287 FRAME_PTR last_mouse_frame
;
8289 /* Tool-bar item index of the item on which a mouse button was pressed
8292 int last_tool_bar_item
;
8295 /* Update the tool-bar item list for frame F. This has to be done
8296 before we start to fill in any display lines. Called from
8297 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8298 and restore it here. */
8301 update_tool_bar (f
, save_match_data
)
8303 int save_match_data
;
8306 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
8308 int do_update
= WINDOWP (f
->tool_bar_window
)
8309 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
8317 window
= FRAME_SELECTED_WINDOW (f
);
8318 w
= XWINDOW (window
);
8320 /* If the user has switched buffers or windows, we need to
8321 recompute to reflect the new bindings. But we'll
8322 recompute when update_mode_lines is set too; that means
8323 that people can use force-mode-line-update to request
8324 that the menu bar be recomputed. The adverse effect on
8325 the rest of the redisplay algorithm is about the same as
8326 windows_or_buffers_changed anyway. */
8327 if (windows_or_buffers_changed
8328 || !NILP (w
->update_mode_line
)
8329 || update_mode_lines
8330 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8331 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8332 != !NILP (w
->last_had_star
))
8333 || ((!NILP (Vtransient_mark_mode
)
8334 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8335 != !NILP (w
->region_showing
)))
8337 struct buffer
*prev
= current_buffer
;
8338 int count
= SPECPDL_INDEX ();
8339 Lisp_Object old_tool_bar
;
8340 struct gcpro gcpro1
;
8342 /* Set current_buffer to the buffer of the selected
8343 window of the frame, so that we get the right local
8345 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8347 /* Save match data, if we must. */
8348 if (save_match_data
)
8349 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8351 /* Make sure that we don't accidentally use bogus keymaps. */
8352 if (NILP (Voverriding_local_map_menu_flag
))
8354 specbind (Qoverriding_terminal_local_map
, Qnil
);
8355 specbind (Qoverriding_local_map
, Qnil
);
8358 old_tool_bar
= f
->tool_bar_items
;
8359 GCPRO1 (old_tool_bar
);
8361 /* Build desired tool-bar items from keymaps. */
8364 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
8367 /* Redisplay the tool-bar if we changed it. */
8368 if (! NILP (Fequal (old_tool_bar
, f
->tool_bar_items
)))
8369 w
->update_mode_line
= Qt
;
8373 unbind_to (count
, Qnil
);
8374 set_buffer_internal_1 (prev
);
8380 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8381 F's desired tool-bar contents. F->tool_bar_items must have
8382 been set up previously by calling prepare_menu_bars. */
8385 build_desired_tool_bar_string (f
)
8388 int i
, size
, size_needed
;
8389 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8390 Lisp_Object image
, plist
, props
;
8392 image
= plist
= props
= Qnil
;
8393 GCPRO3 (image
, plist
, props
);
8395 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
8396 Otherwise, make a new string. */
8398 /* The size of the string we might be able to reuse. */
8399 size
= (STRINGP (f
->desired_tool_bar_string
)
8400 ? SCHARS (f
->desired_tool_bar_string
)
8403 /* We need one space in the string for each image. */
8404 size_needed
= f
->n_tool_bar_items
;
8406 /* Reuse f->desired_tool_bar_string, if possible. */
8407 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
8408 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
8412 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
8413 Fremove_text_properties (make_number (0), make_number (size
),
8414 props
, f
->desired_tool_bar_string
);
8417 /* Put a `display' property on the string for the images to display,
8418 put a `menu_item' property on tool-bar items with a value that
8419 is the index of the item in F's tool-bar item vector. */
8420 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
8422 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
8424 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8425 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8426 int hmargin
, vmargin
, relief
, idx
, end
;
8427 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
8429 /* If image is a vector, choose the image according to the
8431 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
8432 if (VECTORP (image
))
8436 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
8437 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
8440 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
8441 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
8443 xassert (ASIZE (image
) >= idx
);
8444 image
= AREF (image
, idx
);
8449 /* Ignore invalid image specifications. */
8450 if (!valid_image_p (image
))
8453 /* Display the tool-bar button pressed, or depressed. */
8454 plist
= Fcopy_sequence (XCDR (image
));
8456 /* Compute margin and relief to draw. */
8457 relief
= (tool_bar_button_relief
>= 0
8458 ? tool_bar_button_relief
8459 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
8460 hmargin
= vmargin
= relief
;
8462 if (INTEGERP (Vtool_bar_button_margin
)
8463 && XINT (Vtool_bar_button_margin
) > 0)
8465 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
8466 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
8468 else if (CONSP (Vtool_bar_button_margin
))
8470 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
8471 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
8472 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
8474 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
8475 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
8476 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
8479 if (auto_raise_tool_bar_buttons_p
)
8481 /* Add a `:relief' property to the image spec if the item is
8485 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
8492 /* If image is selected, display it pressed, i.e. with a
8493 negative relief. If it's not selected, display it with a
8495 plist
= Fplist_put (plist
, QCrelief
,
8497 ? make_number (-relief
)
8498 : make_number (relief
)));
8503 /* Put a margin around the image. */
8504 if (hmargin
|| vmargin
)
8506 if (hmargin
== vmargin
)
8507 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
8509 plist
= Fplist_put (plist
, QCmargin
,
8510 Fcons (make_number (hmargin
),
8511 make_number (vmargin
)));
8514 /* If button is not enabled, and we don't have special images
8515 for the disabled state, make the image appear disabled by
8516 applying an appropriate algorithm to it. */
8517 if (!enabled_p
&& idx
< 0)
8518 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
8520 /* Put a `display' text property on the string for the image to
8521 display. Put a `menu-item' property on the string that gives
8522 the start of this item's properties in the tool-bar items
8524 image
= Fcons (Qimage
, plist
);
8525 props
= list4 (Qdisplay
, image
,
8526 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
8528 /* Let the last image hide all remaining spaces in the tool bar
8529 string. The string can be longer than needed when we reuse a
8531 if (i
+ 1 == f
->n_tool_bar_items
)
8532 end
= SCHARS (f
->desired_tool_bar_string
);
8535 Fadd_text_properties (make_number (i
), make_number (end
),
8536 props
, f
->desired_tool_bar_string
);
8544 /* Display one line of the tool-bar of frame IT->f. */
8547 display_tool_bar_line (it
)
8550 struct glyph_row
*row
= it
->glyph_row
;
8551 int max_x
= it
->last_visible_x
;
8554 prepare_desired_row (row
);
8555 row
->y
= it
->current_y
;
8557 /* Note that this isn't made use of if the face hasn't a box,
8558 so there's no need to check the face here. */
8559 it
->start_of_box_run_p
= 1;
8561 while (it
->current_x
< max_x
)
8563 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
8565 /* Get the next display element. */
8566 if (!get_next_display_element (it
))
8569 /* Produce glyphs. */
8570 x_before
= it
->current_x
;
8571 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
8572 PRODUCE_GLYPHS (it
);
8574 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
8579 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
8581 if (x
+ glyph
->pixel_width
> max_x
)
8583 /* Glyph doesn't fit on line. */
8584 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
8590 x
+= glyph
->pixel_width
;
8594 /* Stop at line ends. */
8595 if (ITERATOR_AT_END_OF_LINE_P (it
))
8598 set_iterator_to_next (it
, 1);
8603 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
8604 extend_face_to_end_of_line (it
);
8605 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
8606 last
->right_box_line_p
= 1;
8607 if (last
== row
->glyphs
[TEXT_AREA
])
8608 last
->left_box_line_p
= 1;
8609 compute_line_metrics (it
);
8611 /* If line is empty, make it occupy the rest of the tool-bar. */
8612 if (!row
->displays_text_p
)
8614 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
8615 row
->ascent
= row
->phys_ascent
= 0;
8618 row
->full_width_p
= 1;
8619 row
->continued_p
= 0;
8620 row
->truncated_on_left_p
= 0;
8621 row
->truncated_on_right_p
= 0;
8623 it
->current_x
= it
->hpos
= 0;
8624 it
->current_y
+= row
->height
;
8630 /* Value is the number of screen lines needed to make all tool-bar
8631 items of frame F visible. */
8634 tool_bar_lines_needed (f
)
8637 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8640 /* Initialize an iterator for iteration over
8641 F->desired_tool_bar_string in the tool-bar window of frame F. */
8642 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8643 it
.first_visible_x
= 0;
8644 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8645 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8647 while (!ITERATOR_AT_END_P (&it
))
8649 it
.glyph_row
= w
->desired_matrix
->rows
;
8650 clear_glyph_row (it
.glyph_row
);
8651 display_tool_bar_line (&it
);
8654 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
8658 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
8660 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
8669 frame
= selected_frame
;
8671 CHECK_FRAME (frame
);
8674 if (WINDOWP (f
->tool_bar_window
)
8675 || (w
= XWINDOW (f
->tool_bar_window
),
8676 WINDOW_TOTAL_LINES (w
) > 0))
8678 update_tool_bar (f
, 1);
8679 if (f
->n_tool_bar_items
)
8681 build_desired_tool_bar_string (f
);
8682 nlines
= tool_bar_lines_needed (f
);
8686 return make_number (nlines
);
8690 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
8691 height should be changed. */
8694 redisplay_tool_bar (f
)
8699 struct glyph_row
*row
;
8700 int change_height_p
= 0;
8703 if (FRAME_EXTERNAL_TOOL_BAR (f
))
8704 update_frame_tool_bar (f
);
8708 /* If frame hasn't a tool-bar window or if it is zero-height, don't
8709 do anything. This means you must start with tool-bar-lines
8710 non-zero to get the auto-sizing effect. Or in other words, you
8711 can turn off tool-bars by specifying tool-bar-lines zero. */
8712 if (!WINDOWP (f
->tool_bar_window
)
8713 || (w
= XWINDOW (f
->tool_bar_window
),
8714 WINDOW_TOTAL_LINES (w
) == 0))
8717 /* Set up an iterator for the tool-bar window. */
8718 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8719 it
.first_visible_x
= 0;
8720 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8723 /* Build a string that represents the contents of the tool-bar. */
8724 build_desired_tool_bar_string (f
);
8725 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8727 /* Display as many lines as needed to display all tool-bar items. */
8728 while (it
.current_y
< it
.last_visible_y
)
8729 display_tool_bar_line (&it
);
8731 /* It doesn't make much sense to try scrolling in the tool-bar
8732 window, so don't do it. */
8733 w
->desired_matrix
->no_scrolling_p
= 1;
8734 w
->must_be_updated_p
= 1;
8736 if (auto_resize_tool_bars_p
)
8740 /* If we couldn't display everything, change the tool-bar's
8742 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
8743 change_height_p
= 1;
8745 /* If there are blank lines at the end, except for a partially
8746 visible blank line at the end that is smaller than
8747 FRAME_LINE_HEIGHT, change the tool-bar's height. */
8748 row
= it
.glyph_row
- 1;
8749 if (!row
->displays_text_p
8750 && row
->height
>= FRAME_LINE_HEIGHT (f
))
8751 change_height_p
= 1;
8753 /* If row displays tool-bar items, but is partially visible,
8754 change the tool-bar's height. */
8755 if (row
->displays_text_p
8756 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
8757 change_height_p
= 1;
8759 /* Resize windows as needed by changing the `tool-bar-lines'
8762 && (nlines
= tool_bar_lines_needed (f
),
8763 nlines
!= WINDOW_TOTAL_LINES (w
)))
8765 extern Lisp_Object Qtool_bar_lines
;
8767 int old_height
= WINDOW_TOTAL_LINES (w
);
8769 XSETFRAME (frame
, f
);
8770 clear_glyph_matrix (w
->desired_matrix
);
8771 Fmodify_frame_parameters (frame
,
8772 Fcons (Fcons (Qtool_bar_lines
,
8773 make_number (nlines
)),
8775 if (WINDOW_TOTAL_LINES (w
) != old_height
)
8776 fonts_changed_p
= 1;
8780 return change_height_p
;
8784 /* Get information about the tool-bar item which is displayed in GLYPH
8785 on frame F. Return in *PROP_IDX the index where tool-bar item
8786 properties start in F->tool_bar_items. Value is zero if
8787 GLYPH doesn't display a tool-bar item. */
8790 tool_bar_item_info (f
, glyph
, prop_idx
)
8792 struct glyph
*glyph
;
8799 /* This function can be called asynchronously, which means we must
8800 exclude any possibility that Fget_text_property signals an
8802 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
8803 charpos
= max (0, charpos
);
8805 /* Get the text property `menu-item' at pos. The value of that
8806 property is the start index of this item's properties in
8807 F->tool_bar_items. */
8808 prop
= Fget_text_property (make_number (charpos
),
8809 Qmenu_item
, f
->current_tool_bar_string
);
8810 if (INTEGERP (prop
))
8812 *prop_idx
= XINT (prop
);
8822 /* Get information about the tool-bar item at position X/Y on frame F.
8823 Return in *GLYPH a pointer to the glyph of the tool-bar item in
8824 the current matrix of the tool-bar window of F, or NULL if not
8825 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
8826 item in F->tool_bar_items. Value is
8828 -1 if X/Y is not on a tool-bar item
8829 0 if X/Y is on the same item that was highlighted before.
8833 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
8836 struct glyph
**glyph
;
8837 int *hpos
, *vpos
, *prop_idx
;
8839 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8840 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8843 /* Find the glyph under X/Y. */
8844 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
8848 /* Get the start of this tool-bar item's properties in
8849 f->tool_bar_items. */
8850 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
8853 /* Is mouse on the highlighted item? */
8854 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
8855 && *vpos
>= dpyinfo
->mouse_face_beg_row
8856 && *vpos
<= dpyinfo
->mouse_face_end_row
8857 && (*vpos
> dpyinfo
->mouse_face_beg_row
8858 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
8859 && (*vpos
< dpyinfo
->mouse_face_end_row
8860 || *hpos
< dpyinfo
->mouse_face_end_col
8861 || dpyinfo
->mouse_face_past_end
))
8869 Handle mouse button event on the tool-bar of frame F, at
8870 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
8871 0 for button release. MODIFIERS is event modifiers for button
8875 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
8878 unsigned int modifiers
;
8880 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8881 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8882 int hpos
, vpos
, prop_idx
;
8883 struct glyph
*glyph
;
8884 Lisp_Object enabled_p
;
8886 /* If not on the highlighted tool-bar item, return. */
8887 frame_to_window_pixel_xy (w
, &x
, &y
);
8888 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
8891 /* If item is disabled, do nothing. */
8892 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
8893 if (NILP (enabled_p
))
8898 /* Show item in pressed state. */
8899 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
8900 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
8901 last_tool_bar_item
= prop_idx
;
8905 Lisp_Object key
, frame
;
8906 struct input_event event
;
8909 /* Show item in released state. */
8910 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
8911 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
8913 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
8915 XSETFRAME (frame
, f
);
8916 event
.kind
= TOOL_BAR_EVENT
;
8917 event
.frame_or_window
= frame
;
8919 kbd_buffer_store_event (&event
);
8921 event
.kind
= TOOL_BAR_EVENT
;
8922 event
.frame_or_window
= frame
;
8924 event
.modifiers
= modifiers
;
8925 kbd_buffer_store_event (&event
);
8926 last_tool_bar_item
= -1;
8931 /* Possibly highlight a tool-bar item on frame F when mouse moves to
8932 tool-bar window-relative coordinates X/Y. Called from
8933 note_mouse_highlight. */
8936 note_tool_bar_highlight (f
, x
, y
)
8940 Lisp_Object window
= f
->tool_bar_window
;
8941 struct window
*w
= XWINDOW (window
);
8942 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8944 struct glyph
*glyph
;
8945 struct glyph_row
*row
;
8947 Lisp_Object enabled_p
;
8949 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
8950 int mouse_down_p
, rc
;
8952 /* Function note_mouse_highlight is called with negative x(y
8953 values when mouse moves outside of the frame. */
8954 if (x
<= 0 || y
<= 0)
8956 clear_mouse_face (dpyinfo
);
8960 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
8963 /* Not on tool-bar item. */
8964 clear_mouse_face (dpyinfo
);
8968 /* On same tool-bar item as before. */
8971 clear_mouse_face (dpyinfo
);
8973 /* Mouse is down, but on different tool-bar item? */
8974 mouse_down_p
= (dpyinfo
->grabbed
8975 && f
== last_mouse_frame
8976 && FRAME_LIVE_P (f
));
8978 && last_tool_bar_item
!= prop_idx
)
8981 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
8982 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
8984 /* If tool-bar item is not enabled, don't highlight it. */
8985 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
8986 if (!NILP (enabled_p
))
8988 /* Compute the x-position of the glyph. In front and past the
8989 image is a space. We include this in the highlighted area. */
8990 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
8991 for (i
= x
= 0; i
< hpos
; ++i
)
8992 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
8994 /* Record this as the current active region. */
8995 dpyinfo
->mouse_face_beg_col
= hpos
;
8996 dpyinfo
->mouse_face_beg_row
= vpos
;
8997 dpyinfo
->mouse_face_beg_x
= x
;
8998 dpyinfo
->mouse_face_beg_y
= row
->y
;
8999 dpyinfo
->mouse_face_past_end
= 0;
9001 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9002 dpyinfo
->mouse_face_end_row
= vpos
;
9003 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9004 dpyinfo
->mouse_face_end_y
= row
->y
;
9005 dpyinfo
->mouse_face_window
= window
;
9006 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9008 /* Display it as active. */
9009 show_mouse_face (dpyinfo
, draw
);
9010 dpyinfo
->mouse_face_image_state
= draw
;
9015 /* Set help_echo_string to a help string to display for this tool-bar item.
9016 XTread_socket does the rest. */
9017 help_echo_object
= help_echo_window
= Qnil
;
9019 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9020 if (NILP (help_echo_string
))
9021 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9024 #endif /* HAVE_WINDOW_SYSTEM */
9028 /************************************************************************
9029 Horizontal scrolling
9030 ************************************************************************/
9032 static int hscroll_window_tree
P_ ((Lisp_Object
));
9033 static int hscroll_windows
P_ ((Lisp_Object
));
9035 /* For all leaf windows in the window tree rooted at WINDOW, set their
9036 hscroll value so that PT is (i) visible in the window, and (ii) so
9037 that it is not within a certain margin at the window's left and
9038 right border. Value is non-zero if any window's hscroll has been
9042 hscroll_window_tree (window
)
9045 int hscrolled_p
= 0;
9046 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9047 int hscroll_step_abs
= 0;
9048 double hscroll_step_rel
= 0;
9050 if (hscroll_relative_p
)
9052 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9053 if (hscroll_step_rel
< 0)
9055 hscroll_relative_p
= 0;
9056 hscroll_step_abs
= 0;
9059 else if (INTEGERP (Vhscroll_step
))
9061 hscroll_step_abs
= XINT (Vhscroll_step
);
9062 if (hscroll_step_abs
< 0)
9063 hscroll_step_abs
= 0;
9066 hscroll_step_abs
= 0;
9068 while (WINDOWP (window
))
9070 struct window
*w
= XWINDOW (window
);
9072 if (WINDOWP (w
->hchild
))
9073 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9074 else if (WINDOWP (w
->vchild
))
9075 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9076 else if (w
->cursor
.vpos
>= 0)
9079 int text_area_width
;
9080 struct glyph_row
*current_cursor_row
9081 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9082 struct glyph_row
*desired_cursor_row
9083 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9084 struct glyph_row
*cursor_row
9085 = (desired_cursor_row
->enabled_p
9086 ? desired_cursor_row
9087 : current_cursor_row
);
9089 text_area_width
= window_box_width (w
, TEXT_AREA
);
9091 /* Scroll when cursor is inside this scroll margin. */
9092 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9094 if ((XFASTINT (w
->hscroll
)
9095 && w
->cursor
.x
<= h_margin
)
9096 || (cursor_row
->enabled_p
9097 && cursor_row
->truncated_on_right_p
9098 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9102 struct buffer
*saved_current_buffer
;
9106 /* Find point in a display of infinite width. */
9107 saved_current_buffer
= current_buffer
;
9108 current_buffer
= XBUFFER (w
->buffer
);
9110 if (w
== XWINDOW (selected_window
))
9111 pt
= BUF_PT (current_buffer
);
9114 pt
= marker_position (w
->pointm
);
9115 pt
= max (BEGV
, pt
);
9119 /* Move iterator to pt starting at cursor_row->start in
9120 a line with infinite width. */
9121 init_to_row_start (&it
, w
, cursor_row
);
9122 it
.last_visible_x
= INFINITY
;
9123 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9124 current_buffer
= saved_current_buffer
;
9126 /* Position cursor in window. */
9127 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9128 hscroll
= max (0, (it
.current_x
9129 - (ITERATOR_AT_END_OF_LINE_P (&it
)
9130 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
9131 : (text_area_width
/ 2))))
9132 / FRAME_COLUMN_WIDTH (it
.f
);
9133 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9135 if (hscroll_relative_p
)
9136 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9139 wanted_x
= text_area_width
9140 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9143 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9147 if (hscroll_relative_p
)
9148 wanted_x
= text_area_width
* hscroll_step_rel
9151 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9154 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9156 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9158 /* Don't call Fset_window_hscroll if value hasn't
9159 changed because it will prevent redisplay
9161 if (XFASTINT (w
->hscroll
) != hscroll
)
9163 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9164 w
->hscroll
= make_number (hscroll
);
9173 /* Value is non-zero if hscroll of any leaf window has been changed. */
9178 /* Set hscroll so that cursor is visible and not inside horizontal
9179 scroll margins for all windows in the tree rooted at WINDOW. See
9180 also hscroll_window_tree above. Value is non-zero if any window's
9181 hscroll has been changed. If it has, desired matrices on the frame
9182 of WINDOW are cleared. */
9185 hscroll_windows (window
)
9190 if (automatic_hscrolling_p
)
9192 hscrolled_p
= hscroll_window_tree (window
);
9194 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9203 /************************************************************************
9205 ************************************************************************/
9207 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9208 to a non-zero value. This is sometimes handy to have in a debugger
9213 /* First and last unchanged row for try_window_id. */
9215 int debug_first_unchanged_at_end_vpos
;
9216 int debug_last_unchanged_at_beg_vpos
;
9218 /* Delta vpos and y. */
9220 int debug_dvpos
, debug_dy
;
9222 /* Delta in characters and bytes for try_window_id. */
9224 int debug_delta
, debug_delta_bytes
;
9226 /* Values of window_end_pos and window_end_vpos at the end of
9229 EMACS_INT debug_end_pos
, debug_end_vpos
;
9231 /* Append a string to W->desired_matrix->method. FMT is a printf
9232 format string. A1...A9 are a supplement for a variable-length
9233 argument list. If trace_redisplay_p is non-zero also printf the
9234 resulting string to stderr. */
9237 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9240 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9243 char *method
= w
->desired_matrix
->method
;
9244 int len
= strlen (method
);
9245 int size
= sizeof w
->desired_matrix
->method
;
9246 int remaining
= size
- len
- 1;
9248 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9249 if (len
&& remaining
)
9255 strncpy (method
+ len
, buffer
, remaining
);
9257 if (trace_redisplay_p
)
9258 fprintf (stderr
, "%p (%s): %s\n",
9260 ((BUFFERP (w
->buffer
)
9261 && STRINGP (XBUFFER (w
->buffer
)->name
))
9262 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9267 #endif /* GLYPH_DEBUG */
9270 /* Value is non-zero if all changes in window W, which displays
9271 current_buffer, are in the text between START and END. START is a
9272 buffer position, END is given as a distance from Z. Used in
9273 redisplay_internal for display optimization. */
9276 text_outside_line_unchanged_p (w
, start
, end
)
9280 int unchanged_p
= 1;
9282 /* If text or overlays have changed, see where. */
9283 if (XFASTINT (w
->last_modified
) < MODIFF
9284 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9286 /* Gap in the line? */
9287 if (GPT
< start
|| Z
- GPT
< end
)
9290 /* Changes start in front of the line, or end after it? */
9292 && (BEG_UNCHANGED
< start
- 1
9293 || END_UNCHANGED
< end
))
9296 /* If selective display, can't optimize if changes start at the
9297 beginning of the line. */
9299 && INTEGERP (current_buffer
->selective_display
)
9300 && XINT (current_buffer
->selective_display
) > 0
9301 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9304 /* If there are overlays at the start or end of the line, these
9305 may have overlay strings with newlines in them. A change at
9306 START, for instance, may actually concern the display of such
9307 overlay strings as well, and they are displayed on different
9308 lines. So, quickly rule out this case. (For the future, it
9309 might be desirable to implement something more telling than
9310 just BEG/END_UNCHANGED.) */
9313 if (BEG
+ BEG_UNCHANGED
== start
9314 && overlay_touches_p (start
))
9316 if (END_UNCHANGED
== end
9317 && overlay_touches_p (Z
- end
))
9326 /* Do a frame update, taking possible shortcuts into account. This is
9327 the main external entry point for redisplay.
9329 If the last redisplay displayed an echo area message and that message
9330 is no longer requested, we clear the echo area or bring back the
9331 mini-buffer if that is in use. */
9336 redisplay_internal (0);
9341 overlay_arrow_string_or_property (var
, pbitmap
)
9345 Lisp_Object pstr
= Fget (var
, Qoverlay_arrow_string
);
9351 if (bitmap
= Fget (var
, Qoverlay_arrow_bitmap
), INTEGERP (bitmap
))
9352 *pbitmap
= XINT (bitmap
);
9357 return Voverlay_arrow_string
;
9360 /* Return 1 if there are any overlay-arrows in current_buffer. */
9362 overlay_arrow_in_current_buffer_p ()
9366 for (vlist
= Voverlay_arrow_variable_list
;
9368 vlist
= XCDR (vlist
))
9370 Lisp_Object var
= XCAR (vlist
);
9375 val
= find_symbol_value (var
);
9377 && current_buffer
== XMARKER (val
)->buffer
)
9384 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
9388 overlay_arrows_changed_p ()
9392 for (vlist
= Voverlay_arrow_variable_list
;
9394 vlist
= XCDR (vlist
))
9396 Lisp_Object var
= XCAR (vlist
);
9397 Lisp_Object val
, pstr
;
9401 val
= find_symbol_value (var
);
9404 if (! EQ (COERCE_MARKER (val
),
9405 Fget (var
, Qlast_arrow_position
))
9406 || ! (pstr
= overlay_arrow_string_or_property (var
, 0),
9407 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
9413 /* Mark overlay arrows to be updated on next redisplay. */
9416 update_overlay_arrows (up_to_date
)
9421 for (vlist
= Voverlay_arrow_variable_list
;
9423 vlist
= XCDR (vlist
))
9425 Lisp_Object var
= XCAR (vlist
);
9432 Lisp_Object val
= find_symbol_value (var
);
9433 Fput (var
, Qlast_arrow_position
,
9434 COERCE_MARKER (val
));
9435 Fput (var
, Qlast_arrow_string
,
9436 overlay_arrow_string_or_property (var
, 0));
9438 else if (up_to_date
< 0
9439 || !NILP (Fget (var
, Qlast_arrow_position
)))
9441 Fput (var
, Qlast_arrow_position
, Qt
);
9442 Fput (var
, Qlast_arrow_string
, Qt
);
9448 /* Return overlay arrow string at row, or nil. */
9451 overlay_arrow_at_row (f
, row
, pbitmap
)
9453 struct glyph_row
*row
;
9458 for (vlist
= Voverlay_arrow_variable_list
;
9460 vlist
= XCDR (vlist
))
9462 Lisp_Object var
= XCAR (vlist
);
9468 val
= find_symbol_value (var
);
9471 && current_buffer
== XMARKER (val
)->buffer
9472 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
9474 val
= overlay_arrow_string_or_property (var
, pbitmap
);
9475 if (FRAME_WINDOW_P (f
))
9477 else if (STRINGP (val
))
9487 /* Return 1 if point moved out of or into a composition. Otherwise
9488 return 0. PREV_BUF and PREV_PT are the last point buffer and
9489 position. BUF and PT are the current point buffer and position. */
9492 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
9493 struct buffer
*prev_buf
, *buf
;
9500 XSETBUFFER (buffer
, buf
);
9501 /* Check a composition at the last point if point moved within the
9503 if (prev_buf
== buf
)
9506 /* Point didn't move. */
9509 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
9510 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
9511 && COMPOSITION_VALID_P (start
, end
, prop
)
9512 && start
< prev_pt
&& end
> prev_pt
)
9513 /* The last point was within the composition. Return 1 iff
9514 point moved out of the composition. */
9515 return (pt
<= start
|| pt
>= end
);
9518 /* Check a composition at the current point. */
9519 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
9520 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
9521 && COMPOSITION_VALID_P (start
, end
, prop
)
9522 && start
< pt
&& end
> pt
);
9526 /* Reconsider the setting of B->clip_changed which is displayed
9530 reconsider_clip_changes (w
, b
)
9535 && !NILP (w
->window_end_valid
)
9536 && w
->current_matrix
->buffer
== b
9537 && w
->current_matrix
->zv
== BUF_ZV (b
)
9538 && w
->current_matrix
->begv
== BUF_BEGV (b
))
9539 b
->clip_changed
= 0;
9541 /* If display wasn't paused, and W is not a tool bar window, see if
9542 point has been moved into or out of a composition. In that case,
9543 we set b->clip_changed to 1 to force updating the screen. If
9544 b->clip_changed has already been set to 1, we can skip this
9546 if (!b
->clip_changed
9547 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
9551 if (w
== XWINDOW (selected_window
))
9552 pt
= BUF_PT (current_buffer
);
9554 pt
= marker_position (w
->pointm
);
9556 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
9557 || pt
!= XINT (w
->last_point
))
9558 && check_point_in_composition (w
->current_matrix
->buffer
,
9559 XINT (w
->last_point
),
9560 XBUFFER (w
->buffer
), pt
))
9561 b
->clip_changed
= 1;
9566 /* Select FRAME to forward the values of frame-local variables into C
9567 variables so that the redisplay routines can access those values
9571 select_frame_for_redisplay (frame
)
9574 Lisp_Object tail
, sym
, val
;
9575 Lisp_Object old
= selected_frame
;
9577 selected_frame
= frame
;
9579 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9580 if (CONSP (XCAR (tail
))
9581 && (sym
= XCAR (XCAR (tail
)),
9583 && (sym
= indirect_variable (sym
),
9584 val
= SYMBOL_VALUE (sym
),
9585 (BUFFER_LOCAL_VALUEP (val
)
9586 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9587 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9588 Fsymbol_value (sym
);
9590 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9591 if (CONSP (XCAR (tail
))
9592 && (sym
= XCAR (XCAR (tail
)),
9594 && (sym
= indirect_variable (sym
),
9595 val
= SYMBOL_VALUE (sym
),
9596 (BUFFER_LOCAL_VALUEP (val
)
9597 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9598 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9599 Fsymbol_value (sym
);
9603 #define STOP_POLLING \
9604 do { if (! polling_stopped_here) stop_polling (); \
9605 polling_stopped_here = 1; } while (0)
9607 #define RESUME_POLLING \
9608 do { if (polling_stopped_here) start_polling (); \
9609 polling_stopped_here = 0; } while (0)
9612 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
9613 response to any user action; therefore, we should preserve the echo
9614 area. (Actually, our caller does that job.) Perhaps in the future
9615 avoid recentering windows if it is not necessary; currently that
9616 causes some problems. */
9619 redisplay_internal (preserve_echo_area
)
9620 int preserve_echo_area
;
9622 struct window
*w
= XWINDOW (selected_window
);
9623 struct frame
*f
= XFRAME (w
->frame
);
9625 int must_finish
= 0;
9626 struct text_pos tlbufpos
, tlendpos
;
9627 int number_of_visible_frames
;
9629 struct frame
*sf
= SELECTED_FRAME ();
9630 int polling_stopped_here
= 0;
9632 /* Non-zero means redisplay has to consider all windows on all
9633 frames. Zero means, only selected_window is considered. */
9634 int consider_all_windows_p
;
9636 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
9638 /* No redisplay if running in batch mode or frame is not yet fully
9639 initialized, or redisplay is explicitly turned off by setting
9640 Vinhibit_redisplay. */
9642 || !NILP (Vinhibit_redisplay
)
9643 || !f
->glyphs_initialized_p
)
9646 /* The flag redisplay_performed_directly_p is set by
9647 direct_output_for_insert when it already did the whole screen
9648 update necessary. */
9649 if (redisplay_performed_directly_p
)
9651 redisplay_performed_directly_p
= 0;
9652 if (!hscroll_windows (selected_window
))
9656 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
9657 if (popup_activated ())
9661 /* I don't think this happens but let's be paranoid. */
9665 /* Record a function that resets redisplaying_p to its old value
9666 when we leave this function. */
9667 count
= SPECPDL_INDEX ();
9668 record_unwind_protect (unwind_redisplay
,
9669 Fcons (make_number (redisplaying_p
), selected_frame
));
9671 specbind (Qinhibit_free_realized_faces
, Qnil
);
9675 reconsider_clip_changes (w
, current_buffer
);
9677 /* If new fonts have been loaded that make a glyph matrix adjustment
9678 necessary, do it. */
9679 if (fonts_changed_p
)
9681 adjust_glyphs (NULL
);
9682 ++windows_or_buffers_changed
;
9683 fonts_changed_p
= 0;
9686 /* If face_change_count is non-zero, init_iterator will free all
9687 realized faces, which includes the faces referenced from current
9688 matrices. So, we can't reuse current matrices in this case. */
9689 if (face_change_count
)
9690 ++windows_or_buffers_changed
;
9692 if (! FRAME_WINDOW_P (sf
)
9693 && previous_terminal_frame
!= sf
)
9695 /* Since frames on an ASCII terminal share the same display
9696 area, displaying a different frame means redisplay the whole
9698 windows_or_buffers_changed
++;
9699 SET_FRAME_GARBAGED (sf
);
9700 XSETFRAME (Vterminal_frame
, sf
);
9702 previous_terminal_frame
= sf
;
9704 /* Set the visible flags for all frames. Do this before checking
9705 for resized or garbaged frames; they want to know if their frames
9706 are visible. See the comment in frame.h for
9707 FRAME_SAMPLE_VISIBILITY. */
9709 Lisp_Object tail
, frame
;
9711 number_of_visible_frames
= 0;
9713 FOR_EACH_FRAME (tail
, frame
)
9715 struct frame
*f
= XFRAME (frame
);
9717 FRAME_SAMPLE_VISIBILITY (f
);
9718 if (FRAME_VISIBLE_P (f
))
9719 ++number_of_visible_frames
;
9720 clear_desired_matrices (f
);
9724 /* Notice any pending interrupt request to change frame size. */
9725 do_pending_window_change (1);
9727 /* Clear frames marked as garbaged. */
9729 clear_garbaged_frames ();
9731 /* Build menubar and tool-bar items. */
9732 prepare_menu_bars ();
9734 if (windows_or_buffers_changed
)
9735 update_mode_lines
++;
9737 /* Detect case that we need to write or remove a star in the mode line. */
9738 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
9740 w
->update_mode_line
= Qt
;
9741 if (buffer_shared
> 1)
9742 update_mode_lines
++;
9745 /* If %c is in the mode line, update it if needed. */
9746 if (!NILP (w
->column_number_displayed
)
9747 /* This alternative quickly identifies a common case
9748 where no change is needed. */
9749 && !(PT
== XFASTINT (w
->last_point
)
9750 && XFASTINT (w
->last_modified
) >= MODIFF
9751 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9752 && (XFASTINT (w
->column_number_displayed
)
9753 != (int) current_column ())) /* iftc */
9754 w
->update_mode_line
= Qt
;
9756 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
9758 /* The variable buffer_shared is set in redisplay_window and
9759 indicates that we redisplay a buffer in different windows. See
9761 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
9762 || cursor_type_changed
);
9764 /* If specs for an arrow have changed, do thorough redisplay
9765 to ensure we remove any arrow that should no longer exist. */
9766 if (overlay_arrows_changed_p ())
9767 consider_all_windows_p
= windows_or_buffers_changed
= 1;
9769 /* Normally the message* functions will have already displayed and
9770 updated the echo area, but the frame may have been trashed, or
9771 the update may have been preempted, so display the echo area
9772 again here. Checking message_cleared_p captures the case that
9773 the echo area should be cleared. */
9774 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
9775 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
9776 || (message_cleared_p
9777 && minibuf_level
== 0
9778 /* If the mini-window is currently selected, this means the
9779 echo-area doesn't show through. */
9780 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
9782 int window_height_changed_p
= echo_area_display (0);
9785 /* If we don't display the current message, don't clear the
9786 message_cleared_p flag, because, if we did, we wouldn't clear
9787 the echo area in the next redisplay which doesn't preserve
9789 if (!display_last_displayed_message_p
)
9790 message_cleared_p
= 0;
9792 if (fonts_changed_p
)
9794 else if (window_height_changed_p
)
9796 consider_all_windows_p
= 1;
9797 ++update_mode_lines
;
9798 ++windows_or_buffers_changed
;
9800 /* If window configuration was changed, frames may have been
9801 marked garbaged. Clear them or we will experience
9802 surprises wrt scrolling. */
9804 clear_garbaged_frames ();
9807 else if (EQ (selected_window
, minibuf_window
)
9808 && (current_buffer
->clip_changed
9809 || XFASTINT (w
->last_modified
) < MODIFF
9810 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9811 && resize_mini_window (w
, 0))
9813 /* Resized active mini-window to fit the size of what it is
9814 showing if its contents might have changed. */
9816 consider_all_windows_p
= 1;
9817 ++windows_or_buffers_changed
;
9818 ++update_mode_lines
;
9820 /* If window configuration was changed, frames may have been
9821 marked garbaged. Clear them or we will experience
9822 surprises wrt scrolling. */
9824 clear_garbaged_frames ();
9828 /* If showing the region, and mark has changed, we must redisplay
9829 the whole window. The assignment to this_line_start_pos prevents
9830 the optimization directly below this if-statement. */
9831 if (((!NILP (Vtransient_mark_mode
)
9832 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9833 != !NILP (w
->region_showing
))
9834 || (!NILP (w
->region_showing
)
9835 && !EQ (w
->region_showing
,
9836 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
9837 CHARPOS (this_line_start_pos
) = 0;
9839 /* Optimize the case that only the line containing the cursor in the
9840 selected window has changed. Variables starting with this_ are
9841 set in display_line and record information about the line
9842 containing the cursor. */
9843 tlbufpos
= this_line_start_pos
;
9844 tlendpos
= this_line_end_pos
;
9845 if (!consider_all_windows_p
9846 && CHARPOS (tlbufpos
) > 0
9847 && NILP (w
->update_mode_line
)
9848 && !current_buffer
->clip_changed
9849 && !current_buffer
->prevent_redisplay_optimizations_p
9850 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
9851 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
9852 /* Make sure recorded data applies to current buffer, etc. */
9853 && this_line_buffer
== current_buffer
9854 && current_buffer
== XBUFFER (w
->buffer
)
9855 && NILP (w
->force_start
)
9856 && NILP (w
->optional_new_start
)
9857 /* Point must be on the line that we have info recorded about. */
9858 && PT
>= CHARPOS (tlbufpos
)
9859 && PT
<= Z
- CHARPOS (tlendpos
)
9860 /* All text outside that line, including its final newline,
9861 must be unchanged */
9862 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
9863 CHARPOS (tlendpos
)))
9865 if (CHARPOS (tlbufpos
) > BEGV
9866 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
9867 && (CHARPOS (tlbufpos
) == ZV
9868 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
9869 /* Former continuation line has disappeared by becoming empty */
9871 else if (XFASTINT (w
->last_modified
) < MODIFF
9872 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
9873 || MINI_WINDOW_P (w
))
9875 /* We have to handle the case of continuation around a
9876 wide-column character (See the comment in indent.c around
9879 For instance, in the following case:
9881 -------- Insert --------
9882 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
9883 J_I_ ==> J_I_ `^^' are cursors.
9887 As we have to redraw the line above, we should goto cancel. */
9890 int line_height_before
= this_line_pixel_height
;
9892 /* Note that start_display will handle the case that the
9893 line starting at tlbufpos is a continuation lines. */
9894 start_display (&it
, w
, tlbufpos
);
9896 /* Implementation note: It this still necessary? */
9897 if (it
.current_x
!= this_line_start_x
)
9900 TRACE ((stderr
, "trying display optimization 1\n"));
9901 w
->cursor
.vpos
= -1;
9902 overlay_arrow_seen
= 0;
9903 it
.vpos
= this_line_vpos
;
9904 it
.current_y
= this_line_y
;
9905 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
9908 /* If line contains point, is not continued,
9909 and ends at same distance from eob as before, we win */
9910 if (w
->cursor
.vpos
>= 0
9911 /* Line is not continued, otherwise this_line_start_pos
9912 would have been set to 0 in display_line. */
9913 && CHARPOS (this_line_start_pos
)
9914 /* Line ends as before. */
9915 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
9916 /* Line has same height as before. Otherwise other lines
9917 would have to be shifted up or down. */
9918 && this_line_pixel_height
== line_height_before
)
9920 /* If this is not the window's last line, we must adjust
9921 the charstarts of the lines below. */
9922 if (it
.current_y
< it
.last_visible_y
)
9924 struct glyph_row
*row
9925 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
9926 int delta
, delta_bytes
;
9928 if (Z
- CHARPOS (tlendpos
) == ZV
)
9930 /* This line ends at end of (accessible part of)
9931 buffer. There is no newline to count. */
9933 - CHARPOS (tlendpos
)
9934 - MATRIX_ROW_START_CHARPOS (row
));
9935 delta_bytes
= (Z_BYTE
9936 - BYTEPOS (tlendpos
)
9937 - MATRIX_ROW_START_BYTEPOS (row
));
9941 /* This line ends in a newline. Must take
9942 account of the newline and the rest of the
9943 text that follows. */
9945 - CHARPOS (tlendpos
)
9946 - MATRIX_ROW_START_CHARPOS (row
));
9947 delta_bytes
= (Z_BYTE
9948 - BYTEPOS (tlendpos
)
9949 - MATRIX_ROW_START_BYTEPOS (row
));
9952 increment_matrix_positions (w
->current_matrix
,
9954 w
->current_matrix
->nrows
,
9955 delta
, delta_bytes
);
9958 /* If this row displays text now but previously didn't,
9959 or vice versa, w->window_end_vpos may have to be
9961 if ((it
.glyph_row
- 1)->displays_text_p
)
9963 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
9964 XSETINT (w
->window_end_vpos
, this_line_vpos
);
9966 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
9967 && this_line_vpos
> 0)
9968 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
9969 w
->window_end_valid
= Qnil
;
9971 /* Update hint: No need to try to scroll in update_window. */
9972 w
->desired_matrix
->no_scrolling_p
= 1;
9975 *w
->desired_matrix
->method
= 0;
9976 debug_method_add (w
, "optimization 1");
9978 #ifdef HAVE_WINDOW_SYSTEM
9979 update_window_fringes (w
, 0);
9986 else if (/* Cursor position hasn't changed. */
9987 PT
== XFASTINT (w
->last_point
)
9988 /* Make sure the cursor was last displayed
9989 in this window. Otherwise we have to reposition it. */
9990 && 0 <= w
->cursor
.vpos
9991 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
9995 do_pending_window_change (1);
9997 /* We used to always goto end_of_redisplay here, but this
9998 isn't enough if we have a blinking cursor. */
9999 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10000 goto end_of_redisplay
;
10004 /* If highlighting the region, or if the cursor is in the echo area,
10005 then we can't just move the cursor. */
10006 else if (! (!NILP (Vtransient_mark_mode
)
10007 && !NILP (current_buffer
->mark_active
))
10008 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10009 || highlight_nonselected_windows
)
10010 && NILP (w
->region_showing
)
10011 && NILP (Vshow_trailing_whitespace
)
10012 && !cursor_in_echo_area
)
10015 struct glyph_row
*row
;
10017 /* Skip from tlbufpos to PT and see where it is. Note that
10018 PT may be in invisible text. If so, we will end at the
10019 next visible position. */
10020 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10021 NULL
, DEFAULT_FACE_ID
);
10022 it
.current_x
= this_line_start_x
;
10023 it
.current_y
= this_line_y
;
10024 it
.vpos
= this_line_vpos
;
10026 /* The call to move_it_to stops in front of PT, but
10027 moves over before-strings. */
10028 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10030 if (it
.vpos
== this_line_vpos
10031 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10034 xassert (this_line_vpos
== it
.vpos
);
10035 xassert (this_line_y
== it
.current_y
);
10036 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10038 *w
->desired_matrix
->method
= 0;
10039 debug_method_add (w
, "optimization 3");
10048 /* Text changed drastically or point moved off of line. */
10049 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10052 CHARPOS (this_line_start_pos
) = 0;
10053 consider_all_windows_p
|= buffer_shared
> 1;
10054 ++clear_face_cache_count
;
10057 /* Build desired matrices, and update the display. If
10058 consider_all_windows_p is non-zero, do it for all windows on all
10059 frames. Otherwise do it for selected_window, only. */
10061 if (consider_all_windows_p
)
10063 Lisp_Object tail
, frame
;
10064 int i
, n
= 0, size
= 50;
10065 struct frame
**updated
10066 = (struct frame
**) alloca (size
* sizeof *updated
);
10068 /* Clear the face cache eventually. */
10069 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
10071 clear_face_cache (0);
10072 clear_face_cache_count
= 0;
10075 /* Recompute # windows showing selected buffer. This will be
10076 incremented each time such a window is displayed. */
10079 FOR_EACH_FRAME (tail
, frame
)
10081 struct frame
*f
= XFRAME (frame
);
10083 if (FRAME_WINDOW_P (f
) || f
== sf
)
10085 if (! EQ (frame
, selected_frame
))
10086 /* Select the frame, for the sake of frame-local
10088 select_frame_for_redisplay (frame
);
10090 #ifdef HAVE_WINDOW_SYSTEM
10091 if (clear_face_cache_count
% 50 == 0
10092 && FRAME_WINDOW_P (f
))
10093 clear_image_cache (f
, 0);
10094 #endif /* HAVE_WINDOW_SYSTEM */
10096 /* Mark all the scroll bars to be removed; we'll redeem
10097 the ones we want when we redisplay their windows. */
10098 if (condemn_scroll_bars_hook
)
10099 condemn_scroll_bars_hook (f
);
10101 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10102 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10104 /* Any scroll bars which redisplay_windows should have
10105 nuked should now go away. */
10106 if (judge_scroll_bars_hook
)
10107 judge_scroll_bars_hook (f
);
10109 /* If fonts changed, display again. */
10110 /* ??? rms: I suspect it is a mistake to jump all the way
10111 back to retry here. It should just retry this frame. */
10112 if (fonts_changed_p
)
10115 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10117 /* See if we have to hscroll. */
10118 if (hscroll_windows (f
->root_window
))
10121 /* Prevent various kinds of signals during display
10122 update. stdio is not robust about handling
10123 signals, which can cause an apparent I/O
10125 if (interrupt_input
)
10126 unrequest_sigio ();
10129 /* Update the display. */
10130 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10131 pause
|= update_frame (f
, 0, 0);
10132 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10139 int nbytes
= size
* sizeof *updated
;
10140 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
10141 bcopy (updated
, p
, nbytes
);
10152 /* Do the mark_window_display_accurate after all windows have
10153 been redisplayed because this call resets flags in buffers
10154 which are needed for proper redisplay. */
10155 for (i
= 0; i
< n
; ++i
)
10157 struct frame
*f
= updated
[i
];
10158 mark_window_display_accurate (f
->root_window
, 1);
10159 if (frame_up_to_date_hook
)
10160 frame_up_to_date_hook (f
);
10164 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10166 Lisp_Object mini_window
;
10167 struct frame
*mini_frame
;
10169 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10170 /* Use list_of_error, not Qerror, so that
10171 we catch only errors and don't run the debugger. */
10172 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10174 redisplay_window_error
);
10176 /* Compare desired and current matrices, perform output. */
10179 /* If fonts changed, display again. */
10180 if (fonts_changed_p
)
10183 /* Prevent various kinds of signals during display update.
10184 stdio is not robust about handling signals,
10185 which can cause an apparent I/O error. */
10186 if (interrupt_input
)
10187 unrequest_sigio ();
10190 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10192 if (hscroll_windows (selected_window
))
10195 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10196 pause
= update_frame (sf
, 0, 0);
10199 /* We may have called echo_area_display at the top of this
10200 function. If the echo area is on another frame, that may
10201 have put text on a frame other than the selected one, so the
10202 above call to update_frame would not have caught it. Catch
10204 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10205 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10207 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10209 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10210 pause
|= update_frame (mini_frame
, 0, 0);
10211 if (!pause
&& hscroll_windows (mini_window
))
10216 /* If display was paused because of pending input, make sure we do a
10217 thorough update the next time. */
10220 /* Prevent the optimization at the beginning of
10221 redisplay_internal that tries a single-line update of the
10222 line containing the cursor in the selected window. */
10223 CHARPOS (this_line_start_pos
) = 0;
10225 /* Let the overlay arrow be updated the next time. */
10226 update_overlay_arrows (0);
10228 /* If we pause after scrolling, some rows in the current
10229 matrices of some windows are not valid. */
10230 if (!WINDOW_FULL_WIDTH_P (w
)
10231 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10232 update_mode_lines
= 1;
10236 if (!consider_all_windows_p
)
10238 /* This has already been done above if
10239 consider_all_windows_p is set. */
10240 mark_window_display_accurate_1 (w
, 1);
10242 /* Say overlay arrows are up to date. */
10243 update_overlay_arrows (1);
10245 if (frame_up_to_date_hook
!= 0)
10246 frame_up_to_date_hook (sf
);
10249 update_mode_lines
= 0;
10250 windows_or_buffers_changed
= 0;
10251 cursor_type_changed
= 0;
10254 /* Start SIGIO interrupts coming again. Having them off during the
10255 code above makes it less likely one will discard output, but not
10256 impossible, since there might be stuff in the system buffer here.
10257 But it is much hairier to try to do anything about that. */
10258 if (interrupt_input
)
10262 /* If a frame has become visible which was not before, redisplay
10263 again, so that we display it. Expose events for such a frame
10264 (which it gets when becoming visible) don't call the parts of
10265 redisplay constructing glyphs, so simply exposing a frame won't
10266 display anything in this case. So, we have to display these
10267 frames here explicitly. */
10270 Lisp_Object tail
, frame
;
10273 FOR_EACH_FRAME (tail
, frame
)
10275 int this_is_visible
= 0;
10277 if (XFRAME (frame
)->visible
)
10278 this_is_visible
= 1;
10279 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10280 if (XFRAME (frame
)->visible
)
10281 this_is_visible
= 1;
10283 if (this_is_visible
)
10287 if (new_count
!= number_of_visible_frames
)
10288 windows_or_buffers_changed
++;
10291 /* Change frame size now if a change is pending. */
10292 do_pending_window_change (1);
10294 /* If we just did a pending size change, or have additional
10295 visible frames, redisplay again. */
10296 if (windows_or_buffers_changed
&& !pause
)
10300 unbind_to (count
, Qnil
);
10305 /* Redisplay, but leave alone any recent echo area message unless
10306 another message has been requested in its place.
10308 This is useful in situations where you need to redisplay but no
10309 user action has occurred, making it inappropriate for the message
10310 area to be cleared. See tracking_off and
10311 wait_reading_process_input for examples of these situations.
10313 FROM_WHERE is an integer saying from where this function was
10314 called. This is useful for debugging. */
10317 redisplay_preserve_echo_area (from_where
)
10320 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10322 if (!NILP (echo_area_buffer
[1]))
10324 /* We have a previously displayed message, but no current
10325 message. Redisplay the previous message. */
10326 display_last_displayed_message_p
= 1;
10327 redisplay_internal (1);
10328 display_last_displayed_message_p
= 0;
10331 redisplay_internal (1);
10335 /* Function registered with record_unwind_protect in
10336 redisplay_internal. Reset redisplaying_p to the value it had
10337 before redisplay_internal was called, and clear
10338 prevent_freeing_realized_faces_p. It also selects the previously
10342 unwind_redisplay (val
)
10345 Lisp_Object old_redisplaying_p
, old_frame
;
10347 old_redisplaying_p
= XCAR (val
);
10348 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10349 old_frame
= XCDR (val
);
10350 if (! EQ (old_frame
, selected_frame
))
10351 select_frame_for_redisplay (old_frame
);
10356 /* Mark the display of window W as accurate or inaccurate. If
10357 ACCURATE_P is non-zero mark display of W as accurate. If
10358 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10359 redisplay_internal is called. */
10362 mark_window_display_accurate_1 (w
, accurate_p
)
10366 if (BUFFERP (w
->buffer
))
10368 struct buffer
*b
= XBUFFER (w
->buffer
);
10371 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
10372 w
->last_overlay_modified
10373 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
10375 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
10379 b
->clip_changed
= 0;
10380 b
->prevent_redisplay_optimizations_p
= 0;
10382 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
10383 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
10384 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
10385 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
10387 w
->current_matrix
->buffer
= b
;
10388 w
->current_matrix
->begv
= BUF_BEGV (b
);
10389 w
->current_matrix
->zv
= BUF_ZV (b
);
10391 w
->last_cursor
= w
->cursor
;
10392 w
->last_cursor_off_p
= w
->cursor_off_p
;
10394 if (w
== XWINDOW (selected_window
))
10395 w
->last_point
= make_number (BUF_PT (b
));
10397 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
10403 w
->window_end_valid
= w
->buffer
;
10404 #if 0 /* This is incorrect with variable-height lines. */
10405 xassert (XINT (w
->window_end_vpos
)
10406 < (WINDOW_TOTAL_LINES (w
)
10407 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
10409 w
->update_mode_line
= Qnil
;
10414 /* Mark the display of windows in the window tree rooted at WINDOW as
10415 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
10416 windows as accurate. If ACCURATE_P is zero, arrange for windows to
10417 be redisplayed the next time redisplay_internal is called. */
10420 mark_window_display_accurate (window
, accurate_p
)
10421 Lisp_Object window
;
10426 for (; !NILP (window
); window
= w
->next
)
10428 w
= XWINDOW (window
);
10429 mark_window_display_accurate_1 (w
, accurate_p
);
10431 if (!NILP (w
->vchild
))
10432 mark_window_display_accurate (w
->vchild
, accurate_p
);
10433 if (!NILP (w
->hchild
))
10434 mark_window_display_accurate (w
->hchild
, accurate_p
);
10439 update_overlay_arrows (1);
10443 /* Force a thorough redisplay the next time by setting
10444 last_arrow_position and last_arrow_string to t, which is
10445 unequal to any useful value of Voverlay_arrow_... */
10446 update_overlay_arrows (-1);
10451 /* Return value in display table DP (Lisp_Char_Table *) for character
10452 C. Since a display table doesn't have any parent, we don't have to
10453 follow parent. Do not call this function directly but use the
10454 macro DISP_CHAR_VECTOR. */
10457 disp_char_vector (dp
, c
)
10458 struct Lisp_Char_Table
*dp
;
10464 if (SINGLE_BYTE_CHAR_P (c
))
10465 return (dp
->contents
[c
]);
10467 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
10470 else if (code
[2] < 32)
10473 /* Here, the possible range of code[0] (== charset ID) is
10474 128..max_charset. Since the top level char table contains data
10475 for multibyte characters after 256th element, we must increment
10476 code[0] by 128 to get a correct index. */
10478 code
[3] = -1; /* anchor */
10480 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
10482 val
= dp
->contents
[code
[i
]];
10483 if (!SUB_CHAR_TABLE_P (val
))
10484 return (NILP (val
) ? dp
->defalt
: val
);
10487 /* Here, val is a sub char table. We return the default value of
10489 return (dp
->defalt
);
10494 /***********************************************************************
10496 ***********************************************************************/
10498 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
10501 redisplay_windows (window
)
10502 Lisp_Object window
;
10504 while (!NILP (window
))
10506 struct window
*w
= XWINDOW (window
);
10508 if (!NILP (w
->hchild
))
10509 redisplay_windows (w
->hchild
);
10510 else if (!NILP (w
->vchild
))
10511 redisplay_windows (w
->vchild
);
10514 displayed_buffer
= XBUFFER (w
->buffer
);
10515 /* Use list_of_error, not Qerror, so that
10516 we catch only errors and don't run the debugger. */
10517 internal_condition_case_1 (redisplay_window_0
, window
,
10519 redisplay_window_error
);
10527 redisplay_window_error ()
10529 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
10534 redisplay_window_0 (window
)
10535 Lisp_Object window
;
10537 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10538 redisplay_window (window
, 0);
10543 redisplay_window_1 (window
)
10544 Lisp_Object window
;
10546 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10547 redisplay_window (window
, 1);
10552 /* Increment GLYPH until it reaches END or CONDITION fails while
10553 adding (GLYPH)->pixel_width to X. */
10555 #define SKIP_GLYPHS(glyph, end, x, condition) \
10558 (x) += (glyph)->pixel_width; \
10561 while ((glyph) < (end) && (condition))
10564 /* Set cursor position of W. PT is assumed to be displayed in ROW.
10565 DELTA is the number of bytes by which positions recorded in ROW
10566 differ from current buffer positions. */
10569 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
10571 struct glyph_row
*row
;
10572 struct glyph_matrix
*matrix
;
10573 int delta
, delta_bytes
, dy
, dvpos
;
10575 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
10576 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
10577 /* The first glyph that starts a sequence of glyphs from string. */
10578 struct glyph
*string_start
;
10579 /* The X coordinate of string_start. */
10580 int string_start_x
;
10581 /* The last known character position. */
10582 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
10583 /* The last known character position before string_start. */
10584 int string_before_pos
;
10586 int pt_old
= PT
- delta
;
10588 /* Skip over glyphs not having an object at the start of the row.
10589 These are special glyphs like truncation marks on terminal
10591 if (row
->displays_text_p
)
10593 && INTEGERP (glyph
->object
)
10594 && glyph
->charpos
< 0)
10596 x
+= glyph
->pixel_width
;
10600 string_start
= NULL
;
10602 && !INTEGERP (glyph
->object
)
10603 && (!BUFFERP (glyph
->object
)
10604 || (last_pos
= glyph
->charpos
) < pt_old
))
10606 if (! STRINGP (glyph
->object
))
10608 string_start
= NULL
;
10609 x
+= glyph
->pixel_width
;
10614 string_before_pos
= last_pos
;
10615 string_start
= glyph
;
10616 string_start_x
= x
;
10617 /* Skip all glyphs from string. */
10618 SKIP_GLYPHS (glyph
, end
, x
, STRINGP (glyph
->object
));
10623 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
10625 /* We may have skipped over point because the previous glyphs
10626 are from string. As there's no easy way to know the
10627 character position of the current glyph, find the correct
10628 glyph on point by scanning from string_start again. */
10630 Lisp_Object string
;
10633 limit
= make_number (pt_old
+ 1);
10635 glyph
= string_start
;
10636 x
= string_start_x
;
10637 string
= glyph
->object
;
10638 pos
= string_buffer_position (w
, string
, string_before_pos
);
10639 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
10640 because we always put cursor after overlay strings. */
10641 while (pos
== 0 && glyph
< end
)
10643 string
= glyph
->object
;
10644 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10646 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
10649 while (glyph
< end
)
10651 pos
= XINT (Fnext_single_char_property_change
10652 (make_number (pos
), Qdisplay
, Qnil
, limit
));
10655 /* Skip glyphs from the same string. */
10656 string
= glyph
->object
;
10657 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10658 /* Skip glyphs from an overlay. */
10660 && ! string_buffer_position (w
, glyph
->object
, pos
))
10662 string
= glyph
->object
;
10663 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10668 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
10670 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
10671 w
->cursor
.y
= row
->y
+ dy
;
10673 if (w
== XWINDOW (selected_window
))
10675 if (!row
->continued_p
10676 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
10679 this_line_buffer
= XBUFFER (w
->buffer
);
10681 CHARPOS (this_line_start_pos
)
10682 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
10683 BYTEPOS (this_line_start_pos
)
10684 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
10686 CHARPOS (this_line_end_pos
)
10687 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
10688 BYTEPOS (this_line_end_pos
)
10689 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
10691 this_line_y
= w
->cursor
.y
;
10692 this_line_pixel_height
= row
->height
;
10693 this_line_vpos
= w
->cursor
.vpos
;
10694 this_line_start_x
= row
->x
;
10697 CHARPOS (this_line_start_pos
) = 0;
10702 /* Run window scroll functions, if any, for WINDOW with new window
10703 start STARTP. Sets the window start of WINDOW to that position.
10705 We assume that the window's buffer is really current. */
10707 static INLINE
struct text_pos
10708 run_window_scroll_functions (window
, startp
)
10709 Lisp_Object window
;
10710 struct text_pos startp
;
10712 struct window
*w
= XWINDOW (window
);
10713 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
10715 if (current_buffer
!= XBUFFER (w
->buffer
))
10718 if (!NILP (Vwindow_scroll_functions
))
10720 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
10721 make_number (CHARPOS (startp
)));
10722 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10723 /* In case the hook functions switch buffers. */
10724 if (current_buffer
!= XBUFFER (w
->buffer
))
10725 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10732 /* Make sure the line containing the cursor is fully visible.
10733 A value of 1 means there is nothing to be done.
10734 (Either the line is fully visible, or it cannot be made so,
10735 or we cannot tell.)
10736 A value of 0 means the caller should do scrolling
10737 as if point had gone off the screen. */
10740 make_cursor_line_fully_visible (w
)
10743 struct glyph_matrix
*matrix
;
10744 struct glyph_row
*row
;
10747 /* It's not always possible to find the cursor, e.g, when a window
10748 is full of overlay strings. Don't do anything in that case. */
10749 if (w
->cursor
.vpos
< 0)
10752 matrix
= w
->desired_matrix
;
10753 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
10755 /* If the cursor row is not partially visible, there's nothing to do. */
10756 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
10759 /* If the row the cursor is in is taller than the window's height,
10760 it's not clear what to do, so do nothing. */
10761 window_height
= window_box_height (w
);
10762 if (row
->height
>= window_height
)
10768 /* This code used to try to scroll the window just enough to make
10769 the line visible. It returned 0 to say that the caller should
10770 allocate larger glyph matrices. */
10772 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
10774 int dy
= row
->height
- row
->visible_height
;
10777 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
10779 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
10781 int dy
= - (row
->height
- row
->visible_height
);
10784 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
10787 /* When we change the cursor y-position of the selected window,
10788 change this_line_y as well so that the display optimization for
10789 the cursor line of the selected window in redisplay_internal uses
10790 the correct y-position. */
10791 if (w
== XWINDOW (selected_window
))
10792 this_line_y
= w
->cursor
.y
;
10794 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
10795 redisplay with larger matrices. */
10796 if (matrix
->nrows
< required_matrix_height (w
))
10798 fonts_changed_p
= 1;
10807 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
10808 non-zero means only WINDOW is redisplayed in redisplay_internal.
10809 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
10810 in redisplay_window to bring a partially visible line into view in
10811 the case that only the cursor has moved.
10813 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
10814 last screen line's vertical height extends past the end of the screen.
10818 1 if scrolling succeeded
10820 0 if scrolling didn't find point.
10822 -1 if new fonts have been loaded so that we must interrupt
10823 redisplay, adjust glyph matrices, and try again. */
10829 SCROLLING_NEED_LARGER_MATRICES
10833 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
10834 scroll_step
, temp_scroll_step
, last_line_misfit
)
10835 Lisp_Object window
;
10836 int just_this_one_p
;
10837 EMACS_INT scroll_conservatively
, scroll_step
;
10838 int temp_scroll_step
;
10839 int last_line_misfit
;
10841 struct window
*w
= XWINDOW (window
);
10842 struct frame
*f
= XFRAME (w
->frame
);
10843 struct text_pos scroll_margin_pos
;
10844 struct text_pos pos
;
10845 struct text_pos startp
;
10847 Lisp_Object window_end
;
10848 int this_scroll_margin
;
10852 int amount_to_scroll
= 0;
10853 Lisp_Object aggressive
;
10855 int end_scroll_margin
;
10858 debug_method_add (w
, "try_scrolling");
10861 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10863 /* Compute scroll margin height in pixels. We scroll when point is
10864 within this distance from the top or bottom of the window. */
10865 if (scroll_margin
> 0)
10867 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
10868 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
10871 this_scroll_margin
= 0;
10873 /* Compute how much we should try to scroll maximally to bring point
10875 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
10876 scroll_max
= max (scroll_step
,
10877 max (scroll_conservatively
, temp_scroll_step
));
10878 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
10879 || NUMBERP (current_buffer
->scroll_up_aggressively
))
10880 /* We're trying to scroll because of aggressive scrolling
10881 but no scroll_step is set. Choose an arbitrary one. Maybe
10882 there should be a variable for this. */
10886 scroll_max
*= FRAME_LINE_HEIGHT (f
);
10888 /* Decide whether we have to scroll down. Start at the window end
10889 and move this_scroll_margin up to find the position of the scroll
10891 window_end
= Fwindow_end (window
, Qt
);
10895 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
10896 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
10898 end_scroll_margin
= this_scroll_margin
+ !!last_line_misfit
;
10899 if (end_scroll_margin
)
10901 start_display (&it
, w
, scroll_margin_pos
);
10902 move_it_vertically (&it
, - end_scroll_margin
);
10903 scroll_margin_pos
= it
.current
.pos
;
10906 if (PT
>= CHARPOS (scroll_margin_pos
))
10910 /* Point is in the scroll margin at the bottom of the window, or
10911 below. Compute a new window start that makes point visible. */
10913 /* Compute the distance from the scroll margin to PT.
10914 Give up if the distance is greater than scroll_max. */
10915 start_display (&it
, w
, scroll_margin_pos
);
10917 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10918 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10920 /* To make point visible, we have to move the window start
10921 down so that the line the cursor is in is visible, which
10922 means we have to add in the height of the cursor line. */
10923 dy
= line_bottom_y (&it
) - y0
;
10925 if (dy
> scroll_max
)
10926 return SCROLLING_FAILED
;
10928 /* Move the window start down. If scrolling conservatively,
10929 move it just enough down to make point visible. If
10930 scroll_step is set, move it down by scroll_step. */
10931 start_display (&it
, w
, startp
);
10933 if (scroll_conservatively
)
10934 /* Set AMOUNT_TO_SCROLL to at least one line,
10935 and at most scroll_conservatively lines. */
10937 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
10938 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
10939 else if (scroll_step
|| temp_scroll_step
)
10940 amount_to_scroll
= scroll_max
;
10943 aggressive
= current_buffer
->scroll_up_aggressively
;
10944 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
10945 if (NUMBERP (aggressive
))
10946 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
10949 if (amount_to_scroll
<= 0)
10950 return SCROLLING_FAILED
;
10952 /* If moving by amount_to_scroll leaves STARTP unchanged,
10953 move it down one screen line. */
10955 move_it_vertically (&it
, amount_to_scroll
);
10956 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
10957 move_it_by_lines (&it
, 1, 1);
10958 startp
= it
.current
.pos
;
10962 /* See if point is inside the scroll margin at the top of the
10964 scroll_margin_pos
= startp
;
10965 if (this_scroll_margin
)
10967 start_display (&it
, w
, startp
);
10968 move_it_vertically (&it
, this_scroll_margin
);
10969 scroll_margin_pos
= it
.current
.pos
;
10972 if (PT
< CHARPOS (scroll_margin_pos
))
10974 /* Point is in the scroll margin at the top of the window or
10975 above what is displayed in the window. */
10978 /* Compute the vertical distance from PT to the scroll
10979 margin position. Give up if distance is greater than
10981 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
10982 start_display (&it
, w
, pos
);
10984 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
10985 it
.last_visible_y
, -1,
10986 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10987 dy
= it
.current_y
- y0
;
10988 if (dy
> scroll_max
)
10989 return SCROLLING_FAILED
;
10991 /* Compute new window start. */
10992 start_display (&it
, w
, startp
);
10994 if (scroll_conservatively
)
10996 max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
10997 else if (scroll_step
|| temp_scroll_step
)
10998 amount_to_scroll
= scroll_max
;
11001 aggressive
= current_buffer
->scroll_down_aggressively
;
11002 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11003 if (NUMBERP (aggressive
))
11004 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
11007 if (amount_to_scroll
<= 0)
11008 return SCROLLING_FAILED
;
11010 move_it_vertically (&it
, - amount_to_scroll
);
11011 startp
= it
.current
.pos
;
11015 /* Run window scroll functions. */
11016 startp
= run_window_scroll_functions (window
, startp
);
11018 /* Display the window. Give up if new fonts are loaded, or if point
11020 if (!try_window (window
, startp
))
11021 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11022 else if (w
->cursor
.vpos
< 0)
11024 clear_glyph_matrix (w
->desired_matrix
);
11025 rc
= SCROLLING_FAILED
;
11029 /* Maybe forget recorded base line for line number display. */
11030 if (!just_this_one_p
11031 || current_buffer
->clip_changed
11032 || BEG_UNCHANGED
< CHARPOS (startp
))
11033 w
->base_line_number
= Qnil
;
11035 /* If cursor ends up on a partially visible line,
11036 treat that as being off the bottom of the screen. */
11037 if (! make_cursor_line_fully_visible (w
))
11039 clear_glyph_matrix (w
->desired_matrix
);
11040 last_line_misfit
= 1;
11043 rc
= SCROLLING_SUCCESS
;
11050 /* Compute a suitable window start for window W if display of W starts
11051 on a continuation line. Value is non-zero if a new window start
11054 The new window start will be computed, based on W's width, starting
11055 from the start of the continued line. It is the start of the
11056 screen line with the minimum distance from the old start W->start. */
11059 compute_window_start_on_continuation_line (w
)
11062 struct text_pos pos
, start_pos
;
11063 int window_start_changed_p
= 0;
11065 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
11067 /* If window start is on a continuation line... Window start may be
11068 < BEGV in case there's invisible text at the start of the
11069 buffer (M-x rmail, for example). */
11070 if (CHARPOS (start_pos
) > BEGV
11071 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
11074 struct glyph_row
*row
;
11076 /* Handle the case that the window start is out of range. */
11077 if (CHARPOS (start_pos
) < BEGV
)
11078 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
11079 else if (CHARPOS (start_pos
) > ZV
)
11080 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
11082 /* Find the start of the continued line. This should be fast
11083 because scan_buffer is fast (newline cache). */
11084 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
11085 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
11086 row
, DEFAULT_FACE_ID
);
11087 reseat_at_previous_visible_line_start (&it
);
11089 /* If the line start is "too far" away from the window start,
11090 say it takes too much time to compute a new window start. */
11091 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
11092 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
11094 int min_distance
, distance
;
11096 /* Move forward by display lines to find the new window
11097 start. If window width was enlarged, the new start can
11098 be expected to be > the old start. If window width was
11099 decreased, the new window start will be < the old start.
11100 So, we're looking for the display line start with the
11101 minimum distance from the old window start. */
11102 pos
= it
.current
.pos
;
11103 min_distance
= INFINITY
;
11104 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
11105 distance
< min_distance
)
11107 min_distance
= distance
;
11108 pos
= it
.current
.pos
;
11109 move_it_by_lines (&it
, 1, 0);
11112 /* Set the window start there. */
11113 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
11114 window_start_changed_p
= 1;
11118 return window_start_changed_p
;
11122 /* Try cursor movement in case text has not changed in window WINDOW,
11123 with window start STARTP. Value is
11125 CURSOR_MOVEMENT_SUCCESS if successful
11127 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
11129 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
11130 display. *SCROLL_STEP is set to 1, under certain circumstances, if
11131 we want to scroll as if scroll-step were set to 1. See the code.
11133 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
11134 which case we have to abort this redisplay, and adjust matrices
11139 CURSOR_MOVEMENT_SUCCESS
,
11140 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11141 CURSOR_MOVEMENT_MUST_SCROLL
,
11142 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11146 try_cursor_movement (window
, startp
, scroll_step
)
11147 Lisp_Object window
;
11148 struct text_pos startp
;
11151 struct window
*w
= XWINDOW (window
);
11152 struct frame
*f
= XFRAME (w
->frame
);
11153 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11156 if (inhibit_try_cursor_movement
)
11160 /* Handle case where text has not changed, only point, and it has
11161 not moved off the frame. */
11162 if (/* Point may be in this window. */
11163 PT
>= CHARPOS (startp
)
11164 /* Selective display hasn't changed. */
11165 && !current_buffer
->clip_changed
11166 /* Function force-mode-line-update is used to force a thorough
11167 redisplay. It sets either windows_or_buffers_changed or
11168 update_mode_lines. So don't take a shortcut here for these
11170 && !update_mode_lines
11171 && !windows_or_buffers_changed
11172 && !cursor_type_changed
11173 /* Can't use this case if highlighting a region. When a
11174 region exists, cursor movement has to do more than just
11176 && !(!NILP (Vtransient_mark_mode
)
11177 && !NILP (current_buffer
->mark_active
))
11178 && NILP (w
->region_showing
)
11179 && NILP (Vshow_trailing_whitespace
)
11180 /* Right after splitting windows, last_point may be nil. */
11181 && INTEGERP (w
->last_point
)
11182 /* This code is not used for mini-buffer for the sake of the case
11183 of redisplaying to replace an echo area message; since in
11184 that case the mini-buffer contents per se are usually
11185 unchanged. This code is of no real use in the mini-buffer
11186 since the handling of this_line_start_pos, etc., in redisplay
11187 handles the same cases. */
11188 && !EQ (window
, minibuf_window
)
11189 /* When splitting windows or for new windows, it happens that
11190 redisplay is called with a nil window_end_vpos or one being
11191 larger than the window. This should really be fixed in
11192 window.c. I don't have this on my list, now, so we do
11193 approximately the same as the old redisplay code. --gerd. */
11194 && INTEGERP (w
->window_end_vpos
)
11195 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11196 && (FRAME_WINDOW_P (f
)
11197 || !overlay_arrow_in_current_buffer_p ()))
11199 int this_scroll_margin
;
11200 struct glyph_row
*row
= NULL
;
11203 debug_method_add (w
, "cursor movement");
11206 /* Scroll if point within this distance from the top or bottom
11207 of the window. This is a pixel value. */
11208 this_scroll_margin
= max (0, scroll_margin
);
11209 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11210 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11212 /* Start with the row the cursor was displayed during the last
11213 not paused redisplay. Give up if that row is not valid. */
11214 if (w
->last_cursor
.vpos
< 0
11215 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11216 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11219 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11220 if (row
->mode_line_p
)
11222 if (!row
->enabled_p
)
11223 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11226 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11229 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11231 if (PT
> XFASTINT (w
->last_point
))
11233 /* Point has moved forward. */
11234 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11235 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11237 xassert (row
->enabled_p
);
11241 /* The end position of a row equals the start position
11242 of the next row. If PT is there, we would rather
11243 display it in the next line. */
11244 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11245 && MATRIX_ROW_END_CHARPOS (row
) == PT
11246 && !cursor_row_p (w
, row
))
11249 /* If within the scroll margin, scroll. Note that
11250 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11251 the next line would be drawn, and that
11252 this_scroll_margin can be zero. */
11253 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11254 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11255 /* Line is completely visible last line in window
11256 and PT is to be set in the next line. */
11257 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11258 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11259 && !row
->ends_at_zv_p
11260 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11263 else if (PT
< XFASTINT (w
->last_point
))
11265 /* Cursor has to be moved backward. Note that PT >=
11266 CHARPOS (startp) because of the outer
11268 while (!row
->mode_line_p
11269 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11270 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11271 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
11272 && (row
->y
> this_scroll_margin
11273 || CHARPOS (startp
) == BEGV
))
11275 xassert (row
->enabled_p
);
11279 /* Consider the following case: Window starts at BEGV,
11280 there is invisible, intangible text at BEGV, so that
11281 display starts at some point START > BEGV. It can
11282 happen that we are called with PT somewhere between
11283 BEGV and START. Try to handle that case. */
11284 if (row
< w
->current_matrix
->rows
11285 || row
->mode_line_p
)
11287 row
= w
->current_matrix
->rows
;
11288 if (row
->mode_line_p
)
11292 /* Due to newlines in overlay strings, we may have to
11293 skip forward over overlay strings. */
11294 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11295 && MATRIX_ROW_END_CHARPOS (row
) == PT
11296 && !cursor_row_p (w
, row
))
11299 /* If within the scroll margin, scroll. */
11300 if (row
->y
< this_scroll_margin
11301 && CHARPOS (startp
) != BEGV
)
11305 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
11306 || PT
> MATRIX_ROW_END_CHARPOS (row
))
11308 /* if PT is not in the glyph row, give up. */
11309 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11311 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
11313 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
11314 && !row
->ends_at_zv_p
11315 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11316 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11317 else if (row
->height
> window_box_height (w
))
11319 /* If we end up in a partially visible line, let's
11320 make it fully visible, except when it's taller
11321 than the window, in which case we can't do much
11324 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11328 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11329 if (!make_cursor_line_fully_visible (w
))
11330 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11332 rc
= CURSOR_MOVEMENT_SUCCESS
;
11336 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11339 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11340 rc
= CURSOR_MOVEMENT_SUCCESS
;
11349 set_vertical_scroll_bar (w
)
11352 int start
, end
, whole
;
11354 /* Calculate the start and end positions for the current window.
11355 At some point, it would be nice to choose between scrollbars
11356 which reflect the whole buffer size, with special markers
11357 indicating narrowing, and scrollbars which reflect only the
11360 Note that mini-buffers sometimes aren't displaying any text. */
11361 if (!MINI_WINDOW_P (w
)
11362 || (w
== XWINDOW (minibuf_window
)
11363 && NILP (echo_area_buffer
[0])))
11365 struct buffer
*buf
= XBUFFER (w
->buffer
);
11366 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
11367 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
11368 /* I don't think this is guaranteed to be right. For the
11369 moment, we'll pretend it is. */
11370 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
11374 if (whole
< (end
- start
))
11375 whole
= end
- start
;
11378 start
= end
= whole
= 0;
11380 /* Indicate what this scroll bar ought to be displaying now. */
11381 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
11385 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
11386 selected_window is redisplayed.
11388 We can return without actually redisplaying the window if
11389 fonts_changed_p is nonzero. In that case, redisplay_internal will
11393 redisplay_window (window
, just_this_one_p
)
11394 Lisp_Object window
;
11395 int just_this_one_p
;
11397 struct window
*w
= XWINDOW (window
);
11398 struct frame
*f
= XFRAME (w
->frame
);
11399 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11400 struct buffer
*old
= current_buffer
;
11401 struct text_pos lpoint
, opoint
, startp
;
11402 int update_mode_line
;
11405 /* Record it now because it's overwritten. */
11406 int current_matrix_up_to_date_p
= 0;
11407 int used_current_matrix_p
= 0;
11408 /* This is less strict than current_matrix_up_to_date_p.
11409 It indictes that the buffer contents and narrowing are unchanged. */
11410 int buffer_unchanged_p
= 0;
11411 int temp_scroll_step
= 0;
11412 int count
= SPECPDL_INDEX ();
11414 int centering_position
;
11415 int last_line_misfit
= 0;
11417 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11420 /* W must be a leaf window here. */
11421 xassert (!NILP (w
->buffer
));
11423 *w
->desired_matrix
->method
= 0;
11426 specbind (Qinhibit_point_motion_hooks
, Qt
);
11428 reconsider_clip_changes (w
, buffer
);
11430 /* Has the mode line to be updated? */
11431 update_mode_line
= (!NILP (w
->update_mode_line
)
11432 || update_mode_lines
11433 || buffer
->clip_changed
11434 || buffer
->prevent_redisplay_optimizations_p
);
11436 if (MINI_WINDOW_P (w
))
11438 if (w
== XWINDOW (echo_area_window
)
11439 && !NILP (echo_area_buffer
[0]))
11441 if (update_mode_line
)
11442 /* We may have to update a tty frame's menu bar or a
11443 tool-bar. Example `M-x C-h C-h C-g'. */
11444 goto finish_menu_bars
;
11446 /* We've already displayed the echo area glyphs in this window. */
11447 goto finish_scroll_bars
;
11449 else if ((w
!= XWINDOW (minibuf_window
)
11450 || minibuf_level
== 0)
11451 /* When buffer is nonempty, redisplay window normally. */
11452 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
11453 /* Quail displays non-mini buffers in minibuffer window.
11454 In that case, redisplay the window normally. */
11455 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
11457 /* W is a mini-buffer window, but it's not active, so clear
11459 int yb
= window_text_bottom_y (w
);
11460 struct glyph_row
*row
;
11463 for (y
= 0, row
= w
->desired_matrix
->rows
;
11465 y
+= row
->height
, ++row
)
11466 blank_row (w
, row
, y
);
11467 goto finish_scroll_bars
;
11470 clear_glyph_matrix (w
->desired_matrix
);
11473 /* Otherwise set up data on this window; select its buffer and point
11475 /* Really select the buffer, for the sake of buffer-local
11477 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11478 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
11480 current_matrix_up_to_date_p
11481 = (!NILP (w
->window_end_valid
)
11482 && !current_buffer
->clip_changed
11483 && !current_buffer
->prevent_redisplay_optimizations_p
11484 && XFASTINT (w
->last_modified
) >= MODIFF
11485 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11488 = (!NILP (w
->window_end_valid
)
11489 && !current_buffer
->clip_changed
11490 && XFASTINT (w
->last_modified
) >= MODIFF
11491 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11493 /* When windows_or_buffers_changed is non-zero, we can't rely on
11494 the window end being valid, so set it to nil there. */
11495 if (windows_or_buffers_changed
)
11497 /* If window starts on a continuation line, maybe adjust the
11498 window start in case the window's width changed. */
11499 if (XMARKER (w
->start
)->buffer
== current_buffer
)
11500 compute_window_start_on_continuation_line (w
);
11502 w
->window_end_valid
= Qnil
;
11505 /* Some sanity checks. */
11506 CHECK_WINDOW_END (w
);
11507 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
11509 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
11512 /* If %c is in mode line, update it if needed. */
11513 if (!NILP (w
->column_number_displayed
)
11514 /* This alternative quickly identifies a common case
11515 where no change is needed. */
11516 && !(PT
== XFASTINT (w
->last_point
)
11517 && XFASTINT (w
->last_modified
) >= MODIFF
11518 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11519 && (XFASTINT (w
->column_number_displayed
)
11520 != (int) current_column ())) /* iftc */
11521 update_mode_line
= 1;
11523 /* Count number of windows showing the selected buffer. An indirect
11524 buffer counts as its base buffer. */
11525 if (!just_this_one_p
)
11527 struct buffer
*current_base
, *window_base
;
11528 current_base
= current_buffer
;
11529 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11530 if (current_base
->base_buffer
)
11531 current_base
= current_base
->base_buffer
;
11532 if (window_base
->base_buffer
)
11533 window_base
= window_base
->base_buffer
;
11534 if (current_base
== window_base
)
11538 /* Point refers normally to the selected window. For any other
11539 window, set up appropriate value. */
11540 if (!EQ (window
, selected_window
))
11542 int new_pt
= XMARKER (w
->pointm
)->charpos
;
11543 int new_pt_byte
= marker_byte_position (w
->pointm
);
11547 new_pt_byte
= BEGV_BYTE
;
11548 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
11550 else if (new_pt
> (ZV
- 1))
11553 new_pt_byte
= ZV_BYTE
;
11554 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
11557 /* We don't use SET_PT so that the point-motion hooks don't run. */
11558 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
11561 /* If any of the character widths specified in the display table
11562 have changed, invalidate the width run cache. It's true that
11563 this may be a bit late to catch such changes, but the rest of
11564 redisplay goes (non-fatally) haywire when the display table is
11565 changed, so why should we worry about doing any better? */
11566 if (current_buffer
->width_run_cache
)
11568 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
11570 if (! disptab_matches_widthtab (disptab
,
11571 XVECTOR (current_buffer
->width_table
)))
11573 invalidate_region_cache (current_buffer
,
11574 current_buffer
->width_run_cache
,
11576 recompute_width_table (current_buffer
, disptab
);
11580 /* If window-start is screwed up, choose a new one. */
11581 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
11584 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11586 /* If someone specified a new starting point but did not insist,
11587 check whether it can be used. */
11588 if (!NILP (w
->optional_new_start
)
11589 && CHARPOS (startp
) >= BEGV
11590 && CHARPOS (startp
) <= ZV
)
11592 w
->optional_new_start
= Qnil
;
11593 start_display (&it
, w
, startp
);
11594 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11595 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11596 if (IT_CHARPOS (it
) == PT
)
11597 w
->force_start
= Qt
;
11598 /* IT may overshoot PT if text at PT is invisible. */
11599 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
11600 w
->force_start
= Qt
;
11605 /* Handle case where place to start displaying has been specified,
11606 unless the specified location is outside the accessible range. */
11607 if (!NILP (w
->force_start
)
11608 || w
->frozen_window_start_p
)
11610 /* We set this later on if we have to adjust point. */
11613 w
->force_start
= Qnil
;
11615 w
->window_end_valid
= Qnil
;
11617 /* Forget any recorded base line for line number display. */
11618 if (!buffer_unchanged_p
)
11619 w
->base_line_number
= Qnil
;
11621 /* Redisplay the mode line. Select the buffer properly for that.
11622 Also, run the hook window-scroll-functions
11623 because we have scrolled. */
11624 /* Note, we do this after clearing force_start because
11625 if there's an error, it is better to forget about force_start
11626 than to get into an infinite loop calling the hook functions
11627 and having them get more errors. */
11628 if (!update_mode_line
11629 || ! NILP (Vwindow_scroll_functions
))
11631 update_mode_line
= 1;
11632 w
->update_mode_line
= Qt
;
11633 startp
= run_window_scroll_functions (window
, startp
);
11636 w
->last_modified
= make_number (0);
11637 w
->last_overlay_modified
= make_number (0);
11638 if (CHARPOS (startp
) < BEGV
)
11639 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
11640 else if (CHARPOS (startp
) > ZV
)
11641 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
11643 /* Redisplay, then check if cursor has been set during the
11644 redisplay. Give up if new fonts were loaded. */
11645 if (!try_window (window
, startp
))
11647 w
->force_start
= Qt
;
11648 clear_glyph_matrix (w
->desired_matrix
);
11649 goto need_larger_matrices
;
11652 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
11654 /* If point does not appear, try to move point so it does
11655 appear. The desired matrix has been built above, so we
11656 can use it here. */
11657 new_vpos
= window_box_height (w
) / 2;
11660 if (!make_cursor_line_fully_visible (w
))
11662 /* Point does appear, but on a line partly visible at end of window.
11663 Move it back to a fully-visible line. */
11664 new_vpos
= window_box_height (w
);
11667 /* If we need to move point for either of the above reasons,
11668 now actually do it. */
11671 struct glyph_row
*row
;
11673 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
11674 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
11677 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
11678 MATRIX_ROW_START_BYTEPOS (row
));
11680 if (w
!= XWINDOW (selected_window
))
11681 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
11682 else if (current_buffer
== old
)
11683 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11685 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
11687 /* If we are highlighting the region, then we just changed
11688 the region, so redisplay to show it. */
11689 if (!NILP (Vtransient_mark_mode
)
11690 && !NILP (current_buffer
->mark_active
))
11692 clear_glyph_matrix (w
->desired_matrix
);
11693 if (!try_window (window
, startp
))
11694 goto need_larger_matrices
;
11699 debug_method_add (w
, "forced window start");
11704 /* Handle case where text has not changed, only point, and it has
11705 not moved off the frame, and we are not retrying after hscroll.
11706 (current_matrix_up_to_date_p is nonzero when retrying.) */
11707 if (current_matrix_up_to_date_p
11708 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
11709 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
11713 case CURSOR_MOVEMENT_SUCCESS
:
11714 used_current_matrix_p
= 1;
11717 #if 0 /* try_cursor_movement never returns this value. */
11718 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
11719 goto need_larger_matrices
;
11722 case CURSOR_MOVEMENT_MUST_SCROLL
:
11723 goto try_to_scroll
;
11729 /* If current starting point was originally the beginning of a line
11730 but no longer is, find a new starting point. */
11731 else if (!NILP (w
->start_at_line_beg
)
11732 && !(CHARPOS (startp
) <= BEGV
11733 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
11736 debug_method_add (w
, "recenter 1");
11741 /* Try scrolling with try_window_id. Value is > 0 if update has
11742 been done, it is -1 if we know that the same window start will
11743 not work. It is 0 if unsuccessful for some other reason. */
11744 else if ((tem
= try_window_id (w
)) != 0)
11747 debug_method_add (w
, "try_window_id %d", tem
);
11750 if (fonts_changed_p
)
11751 goto need_larger_matrices
;
11755 /* Otherwise try_window_id has returned -1 which means that we
11756 don't want the alternative below this comment to execute. */
11758 else if (CHARPOS (startp
) >= BEGV
11759 && CHARPOS (startp
) <= ZV
11760 && PT
>= CHARPOS (startp
)
11761 && (CHARPOS (startp
) < ZV
11762 /* Avoid starting at end of buffer. */
11763 || CHARPOS (startp
) == BEGV
11764 || (XFASTINT (w
->last_modified
) >= MODIFF
11765 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
11768 debug_method_add (w
, "same window start");
11771 /* Try to redisplay starting at same place as before.
11772 If point has not moved off frame, accept the results. */
11773 if (!current_matrix_up_to_date_p
11774 /* Don't use try_window_reusing_current_matrix in this case
11775 because a window scroll function can have changed the
11777 || !NILP (Vwindow_scroll_functions
)
11778 || MINI_WINDOW_P (w
)
11779 || !(used_current_matrix_p
=
11780 try_window_reusing_current_matrix (w
)))
11782 IF_DEBUG (debug_method_add (w
, "1"));
11783 try_window (window
, startp
);
11786 if (fonts_changed_p
)
11787 goto need_larger_matrices
;
11789 if (w
->cursor
.vpos
>= 0)
11791 if (!just_this_one_p
11792 || current_buffer
->clip_changed
11793 || BEG_UNCHANGED
< CHARPOS (startp
))
11794 /* Forget any recorded base line for line number display. */
11795 w
->base_line_number
= Qnil
;
11797 if (!make_cursor_line_fully_visible (w
))
11799 clear_glyph_matrix (w
->desired_matrix
);
11800 last_line_misfit
= 1;
11802 /* Drop through and scroll. */
11807 clear_glyph_matrix (w
->desired_matrix
);
11812 w
->last_modified
= make_number (0);
11813 w
->last_overlay_modified
= make_number (0);
11815 /* Redisplay the mode line. Select the buffer properly for that. */
11816 if (!update_mode_line
)
11818 update_mode_line
= 1;
11819 w
->update_mode_line
= Qt
;
11822 /* Try to scroll by specified few lines. */
11823 if ((scroll_conservatively
11825 || temp_scroll_step
11826 || NUMBERP (current_buffer
->scroll_up_aggressively
)
11827 || NUMBERP (current_buffer
->scroll_down_aggressively
))
11828 && !current_buffer
->clip_changed
11829 && CHARPOS (startp
) >= BEGV
11830 && CHARPOS (startp
) <= ZV
)
11832 /* The function returns -1 if new fonts were loaded, 1 if
11833 successful, 0 if not successful. */
11834 int rc
= try_scrolling (window
, just_this_one_p
,
11835 scroll_conservatively
,
11837 temp_scroll_step
, last_line_misfit
);
11840 case SCROLLING_SUCCESS
:
11843 case SCROLLING_NEED_LARGER_MATRICES
:
11844 goto need_larger_matrices
;
11846 case SCROLLING_FAILED
:
11854 /* Finally, just choose place to start which centers point */
11857 centering_position
= window_box_height (w
) / 2;
11860 /* Jump here with centering_position already set to 0. */
11863 debug_method_add (w
, "recenter");
11866 /* w->vscroll = 0; */
11868 /* Forget any previously recorded base line for line number display. */
11869 if (!buffer_unchanged_p
)
11870 w
->base_line_number
= Qnil
;
11872 /* Move backward half the height of the window. */
11873 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
11874 it
.current_y
= it
.last_visible_y
;
11875 move_it_vertically_backward (&it
, centering_position
);
11876 xassert (IT_CHARPOS (it
) >= BEGV
);
11878 /* The function move_it_vertically_backward may move over more
11879 than the specified y-distance. If it->w is small, e.g. a
11880 mini-buffer window, we may end up in front of the window's
11881 display area. Start displaying at the start of the line
11882 containing PT in this case. */
11883 if (it
.current_y
<= 0)
11885 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
11886 move_it_vertically (&it
, 0);
11887 xassert (IT_CHARPOS (it
) <= PT
);
11891 it
.current_x
= it
.hpos
= 0;
11893 /* Set startp here explicitly in case that helps avoid an infinite loop
11894 in case the window-scroll-functions functions get errors. */
11895 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
11897 /* Run scroll hooks. */
11898 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
11900 /* Redisplay the window. */
11901 if (!current_matrix_up_to_date_p
11902 || windows_or_buffers_changed
11903 || cursor_type_changed
11904 /* Don't use try_window_reusing_current_matrix in this case
11905 because it can have changed the buffer. */
11906 || !NILP (Vwindow_scroll_functions
)
11907 || !just_this_one_p
11908 || MINI_WINDOW_P (w
)
11909 || !(used_current_matrix_p
=
11910 try_window_reusing_current_matrix (w
)))
11911 try_window (window
, startp
);
11913 /* If new fonts have been loaded (due to fontsets), give up. We
11914 have to start a new redisplay since we need to re-adjust glyph
11916 if (fonts_changed_p
)
11917 goto need_larger_matrices
;
11919 /* If cursor did not appear assume that the middle of the window is
11920 in the first line of the window. Do it again with the next line.
11921 (Imagine a window of height 100, displaying two lines of height
11922 60. Moving back 50 from it->last_visible_y will end in the first
11924 if (w
->cursor
.vpos
< 0)
11926 if (!NILP (w
->window_end_valid
)
11927 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
11929 clear_glyph_matrix (w
->desired_matrix
);
11930 move_it_by_lines (&it
, 1, 0);
11931 try_window (window
, it
.current
.pos
);
11933 else if (PT
< IT_CHARPOS (it
))
11935 clear_glyph_matrix (w
->desired_matrix
);
11936 move_it_by_lines (&it
, -1, 0);
11937 try_window (window
, it
.current
.pos
);
11941 /* Not much we can do about it. */
11945 /* Consider the following case: Window starts at BEGV, there is
11946 invisible, intangible text at BEGV, so that display starts at
11947 some point START > BEGV. It can happen that we are called with
11948 PT somewhere between BEGV and START. Try to handle that case. */
11949 if (w
->cursor
.vpos
< 0)
11951 struct glyph_row
*row
= w
->current_matrix
->rows
;
11952 if (row
->mode_line_p
)
11954 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11957 if (!make_cursor_line_fully_visible (w
))
11959 /* If vscroll is enabled, disable it and try again. */
11963 clear_glyph_matrix (w
->desired_matrix
);
11967 /* If centering point failed to make the whole line visible,
11968 put point at the top instead. That has to make the whole line
11969 visible, if it can be done. */
11970 centering_position
= 0;
11976 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11977 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
11978 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
11981 /* Display the mode line, if we must. */
11982 if ((update_mode_line
11983 /* If window not full width, must redo its mode line
11984 if (a) the window to its side is being redone and
11985 (b) we do a frame-based redisplay. This is a consequence
11986 of how inverted lines are drawn in frame-based redisplay. */
11987 || (!just_this_one_p
11988 && !FRAME_WINDOW_P (f
)
11989 && !WINDOW_FULL_WIDTH_P (w
))
11990 /* Line number to display. */
11991 || INTEGERP (w
->base_line_pos
)
11992 /* Column number is displayed and different from the one displayed. */
11993 || (!NILP (w
->column_number_displayed
)
11994 && (XFASTINT (w
->column_number_displayed
)
11995 != (int) current_column ()))) /* iftc */
11996 /* This means that the window has a mode line. */
11997 && (WINDOW_WANTS_MODELINE_P (w
)
11998 || WINDOW_WANTS_HEADER_LINE_P (w
)))
12000 display_mode_lines (w
);
12002 /* If mode line height has changed, arrange for a thorough
12003 immediate redisplay using the correct mode line height. */
12004 if (WINDOW_WANTS_MODELINE_P (w
)
12005 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12007 fonts_changed_p
= 1;
12008 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12009 = DESIRED_MODE_LINE_HEIGHT (w
);
12012 /* If top line height has changed, arrange for a thorough
12013 immediate redisplay using the correct mode line height. */
12014 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12015 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
12017 fonts_changed_p
= 1;
12018 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
12019 = DESIRED_HEADER_LINE_HEIGHT (w
);
12022 if (fonts_changed_p
)
12023 goto need_larger_matrices
;
12026 if (!line_number_displayed
12027 && !BUFFERP (w
->base_line_pos
))
12029 w
->base_line_pos
= Qnil
;
12030 w
->base_line_number
= Qnil
;
12035 /* When we reach a frame's selected window, redo the frame's menu bar. */
12036 if (update_mode_line
12037 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
12039 int redisplay_menu_p
= 0;
12040 int redisplay_tool_bar_p
= 0;
12042 if (FRAME_WINDOW_P (f
))
12044 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
12045 || defined (USE_GTK)
12046 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
12048 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12052 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12054 if (redisplay_menu_p
)
12055 display_menu_bar (w
);
12057 #ifdef HAVE_WINDOW_SYSTEM
12059 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
12061 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
12062 && (FRAME_TOOL_BAR_LINES (f
) > 0
12063 || auto_resize_tool_bars_p
);
12067 if (redisplay_tool_bar_p
)
12068 redisplay_tool_bar (f
);
12072 #ifdef HAVE_WINDOW_SYSTEM
12073 if (update_window_fringes (w
, 0)
12074 && !just_this_one_p
12075 && (used_current_matrix_p
|| overlay_arrow_seen
)
12076 && !w
->pseudo_window_p
)
12080 draw_window_fringes (w
);
12084 #endif /* HAVE_WINDOW_SYSTEM */
12086 /* We go to this label, with fonts_changed_p nonzero,
12087 if it is necessary to try again using larger glyph matrices.
12088 We have to redeem the scroll bar even in this case,
12089 because the loop in redisplay_internal expects that. */
12090 need_larger_matrices
:
12092 finish_scroll_bars
:
12094 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
12096 /* Set the thumb's position and size. */
12097 set_vertical_scroll_bar (w
);
12099 /* Note that we actually used the scroll bar attached to this
12100 window, so it shouldn't be deleted at the end of redisplay. */
12101 redeem_scroll_bar_hook (w
);
12104 /* Restore current_buffer and value of point in it. */
12105 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
12106 set_buffer_internal_1 (old
);
12107 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12109 unbind_to (count
, Qnil
);
12113 /* Build the complete desired matrix of WINDOW with a window start
12114 buffer position POS. Value is non-zero if successful. It is zero
12115 if fonts were loaded during redisplay which makes re-adjusting
12116 glyph matrices necessary. */
12119 try_window (window
, pos
)
12120 Lisp_Object window
;
12121 struct text_pos pos
;
12123 struct window
*w
= XWINDOW (window
);
12125 struct glyph_row
*last_text_row
= NULL
;
12127 /* Make POS the new window start. */
12128 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
12130 /* Mark cursor position as unknown. No overlay arrow seen. */
12131 w
->cursor
.vpos
= -1;
12132 overlay_arrow_seen
= 0;
12134 /* Initialize iterator and info to start at POS. */
12135 start_display (&it
, w
, pos
);
12137 /* Display all lines of W. */
12138 while (it
.current_y
< it
.last_visible_y
)
12140 if (display_line (&it
))
12141 last_text_row
= it
.glyph_row
- 1;
12142 if (fonts_changed_p
)
12146 /* If bottom moved off end of frame, change mode line percentage. */
12147 if (XFASTINT (w
->window_end_pos
) <= 0
12148 && Z
!= IT_CHARPOS (it
))
12149 w
->update_mode_line
= Qt
;
12151 /* Set window_end_pos to the offset of the last character displayed
12152 on the window from the end of current_buffer. Set
12153 window_end_vpos to its row number. */
12156 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
12157 w
->window_end_bytepos
12158 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12160 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12162 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12163 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12164 ->displays_text_p
);
12168 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12169 w
->window_end_pos
= make_number (Z
- ZV
);
12170 w
->window_end_vpos
= make_number (0);
12173 /* But that is not valid info until redisplay finishes. */
12174 w
->window_end_valid
= Qnil
;
12180 /************************************************************************
12181 Window redisplay reusing current matrix when buffer has not changed
12182 ************************************************************************/
12184 /* Try redisplay of window W showing an unchanged buffer with a
12185 different window start than the last time it was displayed by
12186 reusing its current matrix. Value is non-zero if successful.
12187 W->start is the new window start. */
12190 try_window_reusing_current_matrix (w
)
12193 struct frame
*f
= XFRAME (w
->frame
);
12194 struct glyph_row
*row
, *bottom_row
;
12197 struct text_pos start
, new_start
;
12198 int nrows_scrolled
, i
;
12199 struct glyph_row
*last_text_row
;
12200 struct glyph_row
*last_reused_text_row
;
12201 struct glyph_row
*start_row
;
12202 int start_vpos
, min_y
, max_y
;
12205 if (inhibit_try_window_reusing
)
12209 if (/* This function doesn't handle terminal frames. */
12210 !FRAME_WINDOW_P (f
)
12211 /* Don't try to reuse the display if windows have been split
12213 || windows_or_buffers_changed
12214 || cursor_type_changed
)
12217 /* Can't do this if region may have changed. */
12218 if ((!NILP (Vtransient_mark_mode
)
12219 && !NILP (current_buffer
->mark_active
))
12220 || !NILP (w
->region_showing
)
12221 || !NILP (Vshow_trailing_whitespace
))
12224 /* If top-line visibility has changed, give up. */
12225 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12226 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12229 /* Give up if old or new display is scrolled vertically. We could
12230 make this function handle this, but right now it doesn't. */
12231 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12232 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
12235 /* The variable new_start now holds the new window start. The old
12236 start `start' can be determined from the current matrix. */
12237 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
12238 start
= start_row
->start
.pos
;
12239 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12241 /* Clear the desired matrix for the display below. */
12242 clear_glyph_matrix (w
->desired_matrix
);
12244 if (CHARPOS (new_start
) <= CHARPOS (start
))
12248 /* Don't use this method if the display starts with an ellipsis
12249 displayed for invisible text. It's not easy to handle that case
12250 below, and it's certainly not worth the effort since this is
12251 not a frequent case. */
12252 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
12255 IF_DEBUG (debug_method_add (w
, "twu1"));
12257 /* Display up to a row that can be reused. The variable
12258 last_text_row is set to the last row displayed that displays
12259 text. Note that it.vpos == 0 if or if not there is a
12260 header-line; it's not the same as the MATRIX_ROW_VPOS! */
12261 start_display (&it
, w
, new_start
);
12262 first_row_y
= it
.current_y
;
12263 w
->cursor
.vpos
= -1;
12264 last_text_row
= last_reused_text_row
= NULL
;
12266 while (it
.current_y
< it
.last_visible_y
12267 && IT_CHARPOS (it
) < CHARPOS (start
)
12268 && !fonts_changed_p
)
12269 if (display_line (&it
))
12270 last_text_row
= it
.glyph_row
- 1;
12272 /* A value of current_y < last_visible_y means that we stopped
12273 at the previous window start, which in turn means that we
12274 have at least one reusable row. */
12275 if (it
.current_y
< it
.last_visible_y
)
12277 /* IT.vpos always starts from 0; it counts text lines. */
12278 nrows_scrolled
= it
.vpos
;
12280 /* Find PT if not already found in the lines displayed. */
12281 if (w
->cursor
.vpos
< 0)
12283 int dy
= it
.current_y
- first_row_y
;
12285 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12286 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
12288 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
12289 dy
, nrows_scrolled
);
12292 clear_glyph_matrix (w
->desired_matrix
);
12297 /* Scroll the display. Do it before the current matrix is
12298 changed. The problem here is that update has not yet
12299 run, i.e. part of the current matrix is not up to date.
12300 scroll_run_hook will clear the cursor, and use the
12301 current matrix to get the height of the row the cursor is
12303 run
.current_y
= first_row_y
;
12304 run
.desired_y
= it
.current_y
;
12305 run
.height
= it
.last_visible_y
- it
.current_y
;
12307 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
12310 rif
->update_window_begin_hook (w
);
12311 rif
->clear_window_mouse_face (w
);
12312 rif
->scroll_run_hook (w
, &run
);
12313 rif
->update_window_end_hook (w
, 0, 0);
12317 /* Shift current matrix down by nrows_scrolled lines. */
12318 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12319 rotate_matrix (w
->current_matrix
,
12321 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12324 /* Disable lines that must be updated. */
12325 for (i
= 0; i
< it
.vpos
; ++i
)
12326 (start_row
+ i
)->enabled_p
= 0;
12328 /* Re-compute Y positions. */
12329 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12330 max_y
= it
.last_visible_y
;
12331 for (row
= start_row
+ nrows_scrolled
;
12335 row
->y
= it
.current_y
;
12336 row
->visible_height
= row
->height
;
12338 if (row
->y
< min_y
)
12339 row
->visible_height
-= min_y
- row
->y
;
12340 if (row
->y
+ row
->height
> max_y
)
12341 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12342 row
->redraw_fringe_bitmaps_p
= 1;
12344 it
.current_y
+= row
->height
;
12346 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12347 last_reused_text_row
= row
;
12348 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
12352 /* Disable lines in the current matrix which are now
12353 below the window. */
12354 for (++row
; row
< bottom_row
; ++row
)
12355 row
->enabled_p
= 0;
12358 /* Update window_end_pos etc.; last_reused_text_row is the last
12359 reused row from the current matrix containing text, if any.
12360 The value of last_text_row is the last displayed line
12361 containing text. */
12362 if (last_reused_text_row
)
12364 w
->window_end_bytepos
12365 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
12367 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
12369 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
12370 w
->current_matrix
));
12372 else if (last_text_row
)
12374 w
->window_end_bytepos
12375 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12377 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12379 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12383 /* This window must be completely empty. */
12384 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12385 w
->window_end_pos
= make_number (Z
- ZV
);
12386 w
->window_end_vpos
= make_number (0);
12388 w
->window_end_valid
= Qnil
;
12390 /* Update hint: don't try scrolling again in update_window. */
12391 w
->desired_matrix
->no_scrolling_p
= 1;
12394 debug_method_add (w
, "try_window_reusing_current_matrix 1");
12398 else if (CHARPOS (new_start
) > CHARPOS (start
))
12400 struct glyph_row
*pt_row
, *row
;
12401 struct glyph_row
*first_reusable_row
;
12402 struct glyph_row
*first_row_to_display
;
12404 int yb
= window_text_bottom_y (w
);
12406 /* Find the row starting at new_start, if there is one. Don't
12407 reuse a partially visible line at the end. */
12408 first_reusable_row
= start_row
;
12409 while (first_reusable_row
->enabled_p
12410 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
12411 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12412 < CHARPOS (new_start
)))
12413 ++first_reusable_row
;
12415 /* Give up if there is no row to reuse. */
12416 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
12417 || !first_reusable_row
->enabled_p
12418 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12419 != CHARPOS (new_start
)))
12422 /* We can reuse fully visible rows beginning with
12423 first_reusable_row to the end of the window. Set
12424 first_row_to_display to the first row that cannot be reused.
12425 Set pt_row to the row containing point, if there is any. */
12427 for (first_row_to_display
= first_reusable_row
;
12428 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
12429 ++first_row_to_display
)
12431 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
12432 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
12433 pt_row
= first_row_to_display
;
12436 /* Start displaying at the start of first_row_to_display. */
12437 xassert (first_row_to_display
->y
< yb
);
12438 init_to_row_start (&it
, w
, first_row_to_display
);
12440 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
12442 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
12444 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
12445 + WINDOW_HEADER_LINE_HEIGHT (w
));
12447 /* Display lines beginning with first_row_to_display in the
12448 desired matrix. Set last_text_row to the last row displayed
12449 that displays text. */
12450 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
12451 if (pt_row
== NULL
)
12452 w
->cursor
.vpos
= -1;
12453 last_text_row
= NULL
;
12454 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
12455 if (display_line (&it
))
12456 last_text_row
= it
.glyph_row
- 1;
12458 /* Give up If point isn't in a row displayed or reused. */
12459 if (w
->cursor
.vpos
< 0)
12461 clear_glyph_matrix (w
->desired_matrix
);
12465 /* If point is in a reused row, adjust y and vpos of the cursor
12469 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
12470 w
->current_matrix
);
12471 w
->cursor
.y
-= first_reusable_row
->y
;
12474 /* Scroll the display. */
12475 run
.current_y
= first_reusable_row
->y
;
12476 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12477 run
.height
= it
.last_visible_y
- run
.current_y
;
12478 dy
= run
.current_y
- run
.desired_y
;
12483 rif
->update_window_begin_hook (w
);
12484 rif
->clear_window_mouse_face (w
);
12485 rif
->scroll_run_hook (w
, &run
);
12486 rif
->update_window_end_hook (w
, 0, 0);
12490 /* Adjust Y positions of reused rows. */
12491 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12492 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12493 max_y
= it
.last_visible_y
;
12494 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
12497 row
->visible_height
= row
->height
;
12498 if (row
->y
< min_y
)
12499 row
->visible_height
-= min_y
- row
->y
;
12500 if (row
->y
+ row
->height
> max_y
)
12501 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12502 row
->redraw_fringe_bitmaps_p
= 1;
12505 /* Scroll the current matrix. */
12506 xassert (nrows_scrolled
> 0);
12507 rotate_matrix (w
->current_matrix
,
12509 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12512 /* Disable rows not reused. */
12513 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
12514 row
->enabled_p
= 0;
12516 /* Adjust window end. A null value of last_text_row means that
12517 the window end is in reused rows which in turn means that
12518 only its vpos can have changed. */
12521 w
->window_end_bytepos
12522 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12524 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12526 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12531 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
12534 w
->window_end_valid
= Qnil
;
12535 w
->desired_matrix
->no_scrolling_p
= 1;
12538 debug_method_add (w
, "try_window_reusing_current_matrix 2");
12548 /************************************************************************
12549 Window redisplay reusing current matrix when buffer has changed
12550 ************************************************************************/
12552 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
12553 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
12555 static struct glyph_row
*
12556 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
12557 struct glyph_row
*));
12560 /* Return the last row in MATRIX displaying text. If row START is
12561 non-null, start searching with that row. IT gives the dimensions
12562 of the display. Value is null if matrix is empty; otherwise it is
12563 a pointer to the row found. */
12565 static struct glyph_row
*
12566 find_last_row_displaying_text (matrix
, it
, start
)
12567 struct glyph_matrix
*matrix
;
12569 struct glyph_row
*start
;
12571 struct glyph_row
*row
, *row_found
;
12573 /* Set row_found to the last row in IT->w's current matrix
12574 displaying text. The loop looks funny but think of partially
12577 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
12578 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12580 xassert (row
->enabled_p
);
12582 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
12591 /* Return the last row in the current matrix of W that is not affected
12592 by changes at the start of current_buffer that occurred since W's
12593 current matrix was built. Value is null if no such row exists.
12595 BEG_UNCHANGED us the number of characters unchanged at the start of
12596 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
12597 first changed character in current_buffer. Characters at positions <
12598 BEG + BEG_UNCHANGED are at the same buffer positions as they were
12599 when the current matrix was built. */
12601 static struct glyph_row
*
12602 find_last_unchanged_at_beg_row (w
)
12605 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
12606 struct glyph_row
*row
;
12607 struct glyph_row
*row_found
= NULL
;
12608 int yb
= window_text_bottom_y (w
);
12610 /* Find the last row displaying unchanged text. */
12611 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12612 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12613 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
12615 if (/* If row ends before first_changed_pos, it is unchanged,
12616 except in some case. */
12617 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
12618 /* When row ends in ZV and we write at ZV it is not
12620 && !row
->ends_at_zv_p
12621 /* When first_changed_pos is the end of a continued line,
12622 row is not unchanged because it may be no longer
12624 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
12625 && (row
->continued_p
12626 || row
->exact_window_width_line_p
)))
12629 /* Stop if last visible row. */
12630 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
12640 /* Find the first glyph row in the current matrix of W that is not
12641 affected by changes at the end of current_buffer since the
12642 time W's current matrix was built.
12644 Return in *DELTA the number of chars by which buffer positions in
12645 unchanged text at the end of current_buffer must be adjusted.
12647 Return in *DELTA_BYTES the corresponding number of bytes.
12649 Value is null if no such row exists, i.e. all rows are affected by
12652 static struct glyph_row
*
12653 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
12655 int *delta
, *delta_bytes
;
12657 struct glyph_row
*row
;
12658 struct glyph_row
*row_found
= NULL
;
12660 *delta
= *delta_bytes
= 0;
12662 /* Display must not have been paused, otherwise the current matrix
12663 is not up to date. */
12664 if (NILP (w
->window_end_valid
))
12667 /* A value of window_end_pos >= END_UNCHANGED means that the window
12668 end is in the range of changed text. If so, there is no
12669 unchanged row at the end of W's current matrix. */
12670 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
12673 /* Set row to the last row in W's current matrix displaying text. */
12674 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
12676 /* If matrix is entirely empty, no unchanged row exists. */
12677 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12679 /* The value of row is the last glyph row in the matrix having a
12680 meaningful buffer position in it. The end position of row
12681 corresponds to window_end_pos. This allows us to translate
12682 buffer positions in the current matrix to current buffer
12683 positions for characters not in changed text. */
12684 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
12685 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
12686 int last_unchanged_pos
, last_unchanged_pos_old
;
12687 struct glyph_row
*first_text_row
12688 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12690 *delta
= Z
- Z_old
;
12691 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
12693 /* Set last_unchanged_pos to the buffer position of the last
12694 character in the buffer that has not been changed. Z is the
12695 index + 1 of the last character in current_buffer, i.e. by
12696 subtracting END_UNCHANGED we get the index of the last
12697 unchanged character, and we have to add BEG to get its buffer
12699 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
12700 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
12702 /* Search backward from ROW for a row displaying a line that
12703 starts at a minimum position >= last_unchanged_pos_old. */
12704 for (; row
> first_text_row
; --row
)
12706 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12709 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
12714 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
12721 /* Make sure that glyph rows in the current matrix of window W
12722 reference the same glyph memory as corresponding rows in the
12723 frame's frame matrix. This function is called after scrolling W's
12724 current matrix on a terminal frame in try_window_id and
12725 try_window_reusing_current_matrix. */
12728 sync_frame_with_window_matrix_rows (w
)
12731 struct frame
*f
= XFRAME (w
->frame
);
12732 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
12734 /* Preconditions: W must be a leaf window and full-width. Its frame
12735 must have a frame matrix. */
12736 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
12737 xassert (WINDOW_FULL_WIDTH_P (w
));
12738 xassert (!FRAME_WINDOW_P (f
));
12740 /* If W is a full-width window, glyph pointers in W's current matrix
12741 have, by definition, to be the same as glyph pointers in the
12742 corresponding frame matrix. Note that frame matrices have no
12743 marginal areas (see build_frame_matrix). */
12744 window_row
= w
->current_matrix
->rows
;
12745 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
12746 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
12747 while (window_row
< window_row_end
)
12749 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
12750 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
12752 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
12753 frame_row
->glyphs
[TEXT_AREA
] = start
;
12754 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
12755 frame_row
->glyphs
[LAST_AREA
] = end
;
12757 /* Disable frame rows whose corresponding window rows have
12758 been disabled in try_window_id. */
12759 if (!window_row
->enabled_p
)
12760 frame_row
->enabled_p
= 0;
12762 ++window_row
, ++frame_row
;
12767 /* Find the glyph row in window W containing CHARPOS. Consider all
12768 rows between START and END (not inclusive). END null means search
12769 all rows to the end of the display area of W. Value is the row
12770 containing CHARPOS or null. */
12773 row_containing_pos (w
, charpos
, start
, end
, dy
)
12776 struct glyph_row
*start
, *end
;
12779 struct glyph_row
*row
= start
;
12782 /* If we happen to start on a header-line, skip that. */
12783 if (row
->mode_line_p
)
12786 if ((end
&& row
>= end
) || !row
->enabled_p
)
12789 last_y
= window_text_bottom_y (w
) - dy
;
12793 /* Give up if we have gone too far. */
12794 if (end
&& row
>= end
)
12796 /* This formerly returned if they were equal.
12797 I think that both quantities are of a "last plus one" type;
12798 if so, when they are equal, the row is within the screen. -- rms. */
12799 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
12802 /* If it is in this row, return this row. */
12803 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
12804 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
12805 /* The end position of a row equals the start
12806 position of the next row. If CHARPOS is there, we
12807 would rather display it in the next line, except
12808 when this line ends in ZV. */
12809 && !row
->ends_at_zv_p
12810 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12811 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
12818 /* Try to redisplay window W by reusing its existing display. W's
12819 current matrix must be up to date when this function is called,
12820 i.e. window_end_valid must not be nil.
12824 1 if display has been updated
12825 0 if otherwise unsuccessful
12826 -1 if redisplay with same window start is known not to succeed
12828 The following steps are performed:
12830 1. Find the last row in the current matrix of W that is not
12831 affected by changes at the start of current_buffer. If no such row
12834 2. Find the first row in W's current matrix that is not affected by
12835 changes at the end of current_buffer. Maybe there is no such row.
12837 3. Display lines beginning with the row + 1 found in step 1 to the
12838 row found in step 2 or, if step 2 didn't find a row, to the end of
12841 4. If cursor is not known to appear on the window, give up.
12843 5. If display stopped at the row found in step 2, scroll the
12844 display and current matrix as needed.
12846 6. Maybe display some lines at the end of W, if we must. This can
12847 happen under various circumstances, like a partially visible line
12848 becoming fully visible, or because newly displayed lines are displayed
12849 in smaller font sizes.
12851 7. Update W's window end information. */
12857 struct frame
*f
= XFRAME (w
->frame
);
12858 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
12859 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
12860 struct glyph_row
*last_unchanged_at_beg_row
;
12861 struct glyph_row
*first_unchanged_at_end_row
;
12862 struct glyph_row
*row
;
12863 struct glyph_row
*bottom_row
;
12866 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
12867 struct text_pos start_pos
;
12869 int first_unchanged_at_end_vpos
= 0;
12870 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
12871 struct text_pos start
;
12872 int first_changed_charpos
, last_changed_charpos
;
12875 if (inhibit_try_window_id
)
12879 /* This is handy for debugging. */
12881 #define GIVE_UP(X) \
12883 fprintf (stderr, "try_window_id give up %d\n", (X)); \
12887 #define GIVE_UP(X) return 0
12890 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
12892 /* Don't use this for mini-windows because these can show
12893 messages and mini-buffers, and we don't handle that here. */
12894 if (MINI_WINDOW_P (w
))
12897 /* This flag is used to prevent redisplay optimizations. */
12898 if (windows_or_buffers_changed
|| cursor_type_changed
)
12901 /* Verify that narrowing has not changed.
12902 Also verify that we were not told to prevent redisplay optimizations.
12903 It would be nice to further
12904 reduce the number of cases where this prevents try_window_id. */
12905 if (current_buffer
->clip_changed
12906 || current_buffer
->prevent_redisplay_optimizations_p
)
12909 /* Window must either use window-based redisplay or be full width. */
12910 if (!FRAME_WINDOW_P (f
)
12911 && (!line_ins_del_ok
12912 || !WINDOW_FULL_WIDTH_P (w
)))
12915 /* Give up if point is not known NOT to appear in W. */
12916 if (PT
< CHARPOS (start
))
12919 /* Another way to prevent redisplay optimizations. */
12920 if (XFASTINT (w
->last_modified
) == 0)
12923 /* Verify that window is not hscrolled. */
12924 if (XFASTINT (w
->hscroll
) != 0)
12927 /* Verify that display wasn't paused. */
12928 if (NILP (w
->window_end_valid
))
12931 /* Can't use this if highlighting a region because a cursor movement
12932 will do more than just set the cursor. */
12933 if (!NILP (Vtransient_mark_mode
)
12934 && !NILP (current_buffer
->mark_active
))
12937 /* Likewise if highlighting trailing whitespace. */
12938 if (!NILP (Vshow_trailing_whitespace
))
12941 /* Likewise if showing a region. */
12942 if (!NILP (w
->region_showing
))
12945 /* Can use this if overlay arrow position and or string have changed. */
12946 if (overlay_arrows_changed_p ())
12950 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
12951 only if buffer has really changed. The reason is that the gap is
12952 initially at Z for freshly visited files. The code below would
12953 set end_unchanged to 0 in that case. */
12954 if (MODIFF
> SAVE_MODIFF
12955 /* This seems to happen sometimes after saving a buffer. */
12956 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
12958 if (GPT
- BEG
< BEG_UNCHANGED
)
12959 BEG_UNCHANGED
= GPT
- BEG
;
12960 if (Z
- GPT
< END_UNCHANGED
)
12961 END_UNCHANGED
= Z
- GPT
;
12964 /* The position of the first and last character that has been changed. */
12965 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
12966 last_changed_charpos
= Z
- END_UNCHANGED
;
12968 /* If window starts after a line end, and the last change is in
12969 front of that newline, then changes don't affect the display.
12970 This case happens with stealth-fontification. Note that although
12971 the display is unchanged, glyph positions in the matrix have to
12972 be adjusted, of course. */
12973 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
12974 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12975 && ((last_changed_charpos
< CHARPOS (start
)
12976 && CHARPOS (start
) == BEGV
)
12977 || (last_changed_charpos
< CHARPOS (start
) - 1
12978 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
12980 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
12981 struct glyph_row
*r0
;
12983 /* Compute how many chars/bytes have been added to or removed
12984 from the buffer. */
12985 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
12986 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
12988 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
12990 /* Give up if PT is not in the window. Note that it already has
12991 been checked at the start of try_window_id that PT is not in
12992 front of the window start. */
12993 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
12996 /* If window start is unchanged, we can reuse the whole matrix
12997 as is, after adjusting glyph positions. No need to compute
12998 the window end again, since its offset from Z hasn't changed. */
12999 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13000 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
13001 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
13002 /* PT must not be in a partially visible line. */
13003 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
13004 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13006 /* Adjust positions in the glyph matrix. */
13007 if (delta
|| delta_bytes
)
13009 struct glyph_row
*r1
13010 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13011 increment_matrix_positions (w
->current_matrix
,
13012 MATRIX_ROW_VPOS (r0
, current_matrix
),
13013 MATRIX_ROW_VPOS (r1
, current_matrix
),
13014 delta
, delta_bytes
);
13017 /* Set the cursor. */
13018 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13020 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13027 /* Handle the case that changes are all below what is displayed in
13028 the window, and that PT is in the window. This shortcut cannot
13029 be taken if ZV is visible in the window, and text has been added
13030 there that is visible in the window. */
13031 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
13032 /* ZV is not visible in the window, or there are no
13033 changes at ZV, actually. */
13034 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
13035 || first_changed_charpos
== last_changed_charpos
))
13037 struct glyph_row
*r0
;
13039 /* Give up if PT is not in the window. Note that it already has
13040 been checked at the start of try_window_id that PT is not in
13041 front of the window start. */
13042 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
13045 /* If window start is unchanged, we can reuse the whole matrix
13046 as is, without changing glyph positions since no text has
13047 been added/removed in front of the window end. */
13048 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13049 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
13050 /* PT must not be in a partially visible line. */
13051 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
13052 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13054 /* We have to compute the window end anew since text
13055 can have been added/removed after it. */
13057 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13058 w
->window_end_bytepos
13059 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13061 /* Set the cursor. */
13062 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13064 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13071 /* Give up if window start is in the changed area.
13073 The condition used to read
13075 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
13077 but why that was tested escapes me at the moment. */
13078 if (CHARPOS (start
) >= first_changed_charpos
13079 && CHARPOS (start
) <= last_changed_charpos
)
13082 /* Check that window start agrees with the start of the first glyph
13083 row in its current matrix. Check this after we know the window
13084 start is not in changed text, otherwise positions would not be
13086 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13087 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
13090 /* Give up if the window ends in strings. Overlay strings
13091 at the end are difficult to handle, so don't try. */
13092 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
13093 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
13096 /* Compute the position at which we have to start displaying new
13097 lines. Some of the lines at the top of the window might be
13098 reusable because they are not displaying changed text. Find the
13099 last row in W's current matrix not affected by changes at the
13100 start of current_buffer. Value is null if changes start in the
13101 first line of window. */
13102 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
13103 if (last_unchanged_at_beg_row
)
13105 /* Avoid starting to display in the moddle of a character, a TAB
13106 for instance. This is easier than to set up the iterator
13107 exactly, and it's not a frequent case, so the additional
13108 effort wouldn't really pay off. */
13109 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
13110 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
13111 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
13112 --last_unchanged_at_beg_row
;
13114 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
13117 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
13119 start_pos
= it
.current
.pos
;
13121 /* Start displaying new lines in the desired matrix at the same
13122 vpos we would use in the current matrix, i.e. below
13123 last_unchanged_at_beg_row. */
13124 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
13126 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13127 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
13129 xassert (it
.hpos
== 0 && it
.current_x
== 0);
13133 /* There are no reusable lines at the start of the window.
13134 Start displaying in the first text line. */
13135 start_display (&it
, w
, start
);
13136 it
.vpos
= it
.first_vpos
;
13137 start_pos
= it
.current
.pos
;
13140 /* Find the first row that is not affected by changes at the end of
13141 the buffer. Value will be null if there is no unchanged row, in
13142 which case we must redisplay to the end of the window. delta
13143 will be set to the value by which buffer positions beginning with
13144 first_unchanged_at_end_row have to be adjusted due to text
13146 first_unchanged_at_end_row
13147 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
13148 IF_DEBUG (debug_delta
= delta
);
13149 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
13151 /* Set stop_pos to the buffer position up to which we will have to
13152 display new lines. If first_unchanged_at_end_row != NULL, this
13153 is the buffer position of the start of the line displayed in that
13154 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
13155 that we don't stop at a buffer position. */
13157 if (first_unchanged_at_end_row
)
13159 xassert (last_unchanged_at_beg_row
== NULL
13160 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
13162 /* If this is a continuation line, move forward to the next one
13163 that isn't. Changes in lines above affect this line.
13164 Caution: this may move first_unchanged_at_end_row to a row
13165 not displaying text. */
13166 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
13167 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13168 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13169 < it
.last_visible_y
))
13170 ++first_unchanged_at_end_row
;
13172 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13173 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13174 >= it
.last_visible_y
))
13175 first_unchanged_at_end_row
= NULL
;
13178 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13180 first_unchanged_at_end_vpos
13181 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13182 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13185 else if (last_unchanged_at_beg_row
== NULL
)
13191 /* Either there is no unchanged row at the end, or the one we have
13192 now displays text. This is a necessary condition for the window
13193 end pos calculation at the end of this function. */
13194 xassert (first_unchanged_at_end_row
== NULL
13195 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
13197 debug_last_unchanged_at_beg_vpos
13198 = (last_unchanged_at_beg_row
13199 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
13201 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
13203 #endif /* GLYPH_DEBUG != 0 */
13206 /* Display new lines. Set last_text_row to the last new line
13207 displayed which has text on it, i.e. might end up as being the
13208 line where the window_end_vpos is. */
13209 w
->cursor
.vpos
= -1;
13210 last_text_row
= NULL
;
13211 overlay_arrow_seen
= 0;
13212 while (it
.current_y
< it
.last_visible_y
13213 && !fonts_changed_p
13214 && (first_unchanged_at_end_row
== NULL
13215 || IT_CHARPOS (it
) < stop_pos
))
13217 if (display_line (&it
))
13218 last_text_row
= it
.glyph_row
- 1;
13221 if (fonts_changed_p
)
13225 /* Compute differences in buffer positions, y-positions etc. for
13226 lines reused at the bottom of the window. Compute what we can
13228 if (first_unchanged_at_end_row
13229 /* No lines reused because we displayed everything up to the
13230 bottom of the window. */
13231 && it
.current_y
< it
.last_visible_y
)
13234 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
13236 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
13237 run
.current_y
= first_unchanged_at_end_row
->y
;
13238 run
.desired_y
= run
.current_y
+ dy
;
13239 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
13243 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
13244 first_unchanged_at_end_row
= NULL
;
13246 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
13249 /* Find the cursor if not already found. We have to decide whether
13250 PT will appear on this window (it sometimes doesn't, but this is
13251 not a very frequent case.) This decision has to be made before
13252 the current matrix is altered. A value of cursor.vpos < 0 means
13253 that PT is either in one of the lines beginning at
13254 first_unchanged_at_end_row or below the window. Don't care for
13255 lines that might be displayed later at the window end; as
13256 mentioned, this is not a frequent case. */
13257 if (w
->cursor
.vpos
< 0)
13259 /* Cursor in unchanged rows at the top? */
13260 if (PT
< CHARPOS (start_pos
)
13261 && last_unchanged_at_beg_row
)
13263 row
= row_containing_pos (w
, PT
,
13264 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
13265 last_unchanged_at_beg_row
+ 1, 0);
13267 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13270 /* Start from first_unchanged_at_end_row looking for PT. */
13271 else if (first_unchanged_at_end_row
)
13273 row
= row_containing_pos (w
, PT
- delta
,
13274 first_unchanged_at_end_row
, NULL
, 0);
13276 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
13277 delta_bytes
, dy
, dvpos
);
13280 /* Give up if cursor was not found. */
13281 if (w
->cursor
.vpos
< 0)
13283 clear_glyph_matrix (w
->desired_matrix
);
13288 /* Don't let the cursor end in the scroll margins. */
13290 int this_scroll_margin
, cursor_height
;
13292 this_scroll_margin
= max (0, scroll_margin
);
13293 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13294 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13295 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
13297 if ((w
->cursor
.y
< this_scroll_margin
13298 && CHARPOS (start
) > BEGV
)
13299 /* Don't take scroll margin into account at the bottom because
13300 old redisplay didn't do it either. */
13301 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
13303 w
->cursor
.vpos
= -1;
13304 clear_glyph_matrix (w
->desired_matrix
);
13309 /* Scroll the display. Do it before changing the current matrix so
13310 that xterm.c doesn't get confused about where the cursor glyph is
13312 if (dy
&& run
.height
)
13316 if (FRAME_WINDOW_P (f
))
13318 rif
->update_window_begin_hook (w
);
13319 rif
->clear_window_mouse_face (w
);
13320 rif
->scroll_run_hook (w
, &run
);
13321 rif
->update_window_end_hook (w
, 0, 0);
13325 /* Terminal frame. In this case, dvpos gives the number of
13326 lines to scroll by; dvpos < 0 means scroll up. */
13327 int first_unchanged_at_end_vpos
13328 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
13329 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
13330 int end
= (WINDOW_TOP_EDGE_LINE (w
)
13331 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
13332 + window_internal_height (w
));
13334 /* Perform the operation on the screen. */
13337 /* Scroll last_unchanged_at_beg_row to the end of the
13338 window down dvpos lines. */
13339 set_terminal_window (end
);
13341 /* On dumb terminals delete dvpos lines at the end
13342 before inserting dvpos empty lines. */
13343 if (!scroll_region_ok
)
13344 ins_del_lines (end
- dvpos
, -dvpos
);
13346 /* Insert dvpos empty lines in front of
13347 last_unchanged_at_beg_row. */
13348 ins_del_lines (from
, dvpos
);
13350 else if (dvpos
< 0)
13352 /* Scroll up last_unchanged_at_beg_vpos to the end of
13353 the window to last_unchanged_at_beg_vpos - |dvpos|. */
13354 set_terminal_window (end
);
13356 /* Delete dvpos lines in front of
13357 last_unchanged_at_beg_vpos. ins_del_lines will set
13358 the cursor to the given vpos and emit |dvpos| delete
13360 ins_del_lines (from
+ dvpos
, dvpos
);
13362 /* On a dumb terminal insert dvpos empty lines at the
13364 if (!scroll_region_ok
)
13365 ins_del_lines (end
+ dvpos
, -dvpos
);
13368 set_terminal_window (0);
13374 /* Shift reused rows of the current matrix to the right position.
13375 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
13377 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13378 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
13381 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
13382 bottom_vpos
, dvpos
);
13383 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
13386 else if (dvpos
> 0)
13388 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
13389 bottom_vpos
, dvpos
);
13390 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
13391 first_unchanged_at_end_vpos
+ dvpos
, 0);
13394 /* For frame-based redisplay, make sure that current frame and window
13395 matrix are in sync with respect to glyph memory. */
13396 if (!FRAME_WINDOW_P (f
))
13397 sync_frame_with_window_matrix_rows (w
);
13399 /* Adjust buffer positions in reused rows. */
13401 increment_matrix_positions (current_matrix
,
13402 first_unchanged_at_end_vpos
+ dvpos
,
13403 bottom_vpos
, delta
, delta_bytes
);
13405 /* Adjust Y positions. */
13407 shift_glyph_matrix (w
, current_matrix
,
13408 first_unchanged_at_end_vpos
+ dvpos
,
13411 if (first_unchanged_at_end_row
)
13412 first_unchanged_at_end_row
+= dvpos
;
13414 /* If scrolling up, there may be some lines to display at the end of
13416 last_text_row_at_end
= NULL
;
13419 /* Scrolling up can leave for example a partially visible line
13420 at the end of the window to be redisplayed. */
13421 /* Set last_row to the glyph row in the current matrix where the
13422 window end line is found. It has been moved up or down in
13423 the matrix by dvpos. */
13424 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
13425 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
13427 /* If last_row is the window end line, it should display text. */
13428 xassert (last_row
->displays_text_p
);
13430 /* If window end line was partially visible before, begin
13431 displaying at that line. Otherwise begin displaying with the
13432 line following it. */
13433 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
13435 init_to_row_start (&it
, w
, last_row
);
13436 it
.vpos
= last_vpos
;
13437 it
.current_y
= last_row
->y
;
13441 init_to_row_end (&it
, w
, last_row
);
13442 it
.vpos
= 1 + last_vpos
;
13443 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
13447 /* We may start in a continuation line. If so, we have to
13448 get the right continuation_lines_width and current_x. */
13449 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
13450 it
.hpos
= it
.current_x
= 0;
13452 /* Display the rest of the lines at the window end. */
13453 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13454 while (it
.current_y
< it
.last_visible_y
13455 && !fonts_changed_p
)
13457 /* Is it always sure that the display agrees with lines in
13458 the current matrix? I don't think so, so we mark rows
13459 displayed invalid in the current matrix by setting their
13460 enabled_p flag to zero. */
13461 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
13462 if (display_line (&it
))
13463 last_text_row_at_end
= it
.glyph_row
- 1;
13467 /* Update window_end_pos and window_end_vpos. */
13468 if (first_unchanged_at_end_row
13469 && first_unchanged_at_end_row
->y
< it
.last_visible_y
13470 && !last_text_row_at_end
)
13472 /* Window end line if one of the preserved rows from the current
13473 matrix. Set row to the last row displaying text in current
13474 matrix starting at first_unchanged_at_end_row, after
13476 xassert (first_unchanged_at_end_row
->displays_text_p
);
13477 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
13478 first_unchanged_at_end_row
);
13479 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
13481 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13482 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13484 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
13485 xassert (w
->window_end_bytepos
>= 0);
13486 IF_DEBUG (debug_method_add (w
, "A"));
13488 else if (last_text_row_at_end
)
13491 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
13492 w
->window_end_bytepos
13493 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
13495 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
13496 xassert (w
->window_end_bytepos
>= 0);
13497 IF_DEBUG (debug_method_add (w
, "B"));
13499 else if (last_text_row
)
13501 /* We have displayed either to the end of the window or at the
13502 end of the window, i.e. the last row with text is to be found
13503 in the desired matrix. */
13505 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13506 w
->window_end_bytepos
13507 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13509 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
13510 xassert (w
->window_end_bytepos
>= 0);
13512 else if (first_unchanged_at_end_row
== NULL
13513 && last_text_row
== NULL
13514 && last_text_row_at_end
== NULL
)
13516 /* Displayed to end of window, but no line containing text was
13517 displayed. Lines were deleted at the end of the window. */
13518 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
13519 int vpos
= XFASTINT (w
->window_end_vpos
);
13520 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
13521 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
13524 row
== NULL
&& vpos
>= first_vpos
;
13525 --vpos
, --current_row
, --desired_row
)
13527 if (desired_row
->enabled_p
)
13529 if (desired_row
->displays_text_p
)
13532 else if (current_row
->displays_text_p
)
13536 xassert (row
!= NULL
);
13537 w
->window_end_vpos
= make_number (vpos
+ 1);
13538 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13539 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13540 xassert (w
->window_end_bytepos
>= 0);
13541 IF_DEBUG (debug_method_add (w
, "C"));
13546 #if 0 /* This leads to problems, for instance when the cursor is
13547 at ZV, and the cursor line displays no text. */
13548 /* Disable rows below what's displayed in the window. This makes
13549 debugging easier. */
13550 enable_glyph_matrix_rows (current_matrix
,
13551 XFASTINT (w
->window_end_vpos
) + 1,
13555 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
13556 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
13558 /* Record that display has not been completed. */
13559 w
->window_end_valid
= Qnil
;
13560 w
->desired_matrix
->no_scrolling_p
= 1;
13568 /***********************************************************************
13569 More debugging support
13570 ***********************************************************************/
13574 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
13575 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
13576 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
13579 /* Dump the contents of glyph matrix MATRIX on stderr.
13581 GLYPHS 0 means don't show glyph contents.
13582 GLYPHS 1 means show glyphs in short form
13583 GLYPHS > 1 means show glyphs in long form. */
13586 dump_glyph_matrix (matrix
, glyphs
)
13587 struct glyph_matrix
*matrix
;
13591 for (i
= 0; i
< matrix
->nrows
; ++i
)
13592 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
13596 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
13597 the glyph row and area where the glyph comes from. */
13600 dump_glyph (row
, glyph
, area
)
13601 struct glyph_row
*row
;
13602 struct glyph
*glyph
;
13605 if (glyph
->type
== CHAR_GLYPH
)
13608 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13609 glyph
- row
->glyphs
[TEXT_AREA
],
13612 (BUFFERP (glyph
->object
)
13614 : (STRINGP (glyph
->object
)
13617 glyph
->pixel_width
,
13619 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
13623 glyph
->left_box_line_p
,
13624 glyph
->right_box_line_p
);
13626 else if (glyph
->type
== STRETCH_GLYPH
)
13629 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13630 glyph
- row
->glyphs
[TEXT_AREA
],
13633 (BUFFERP (glyph
->object
)
13635 : (STRINGP (glyph
->object
)
13638 glyph
->pixel_width
,
13642 glyph
->left_box_line_p
,
13643 glyph
->right_box_line_p
);
13645 else if (glyph
->type
== IMAGE_GLYPH
)
13648 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13649 glyph
- row
->glyphs
[TEXT_AREA
],
13652 (BUFFERP (glyph
->object
)
13654 : (STRINGP (glyph
->object
)
13657 glyph
->pixel_width
,
13661 glyph
->left_box_line_p
,
13662 glyph
->right_box_line_p
);
13667 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
13668 GLYPHS 0 means don't show glyph contents.
13669 GLYPHS 1 means show glyphs in short form
13670 GLYPHS > 1 means show glyphs in long form. */
13673 dump_glyph_row (row
, vpos
, glyphs
)
13674 struct glyph_row
*row
;
13679 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
13680 fprintf (stderr
, "=======================================================================\n");
13682 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
13683 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
13685 MATRIX_ROW_START_CHARPOS (row
),
13686 MATRIX_ROW_END_CHARPOS (row
),
13687 row
->used
[TEXT_AREA
],
13688 row
->contains_overlapping_glyphs_p
,
13690 row
->truncated_on_left_p
,
13691 row
->truncated_on_right_p
,
13692 row
->overlay_arrow_p
,
13694 MATRIX_ROW_CONTINUATION_LINE_P (row
),
13695 row
->displays_text_p
,
13698 row
->ends_in_middle_of_char_p
,
13699 row
->starts_in_middle_of_char_p
,
13705 row
->visible_height
,
13708 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
13709 row
->end
.overlay_string_index
,
13710 row
->continuation_lines_width
);
13711 fprintf (stderr
, "%9d %5d\n",
13712 CHARPOS (row
->start
.string_pos
),
13713 CHARPOS (row
->end
.string_pos
));
13714 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
13715 row
->end
.dpvec_index
);
13722 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
13724 struct glyph
*glyph
= row
->glyphs
[area
];
13725 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
13727 /* Glyph for a line end in text. */
13728 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
13731 if (glyph
< glyph_end
)
13732 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
13734 for (; glyph
< glyph_end
; ++glyph
)
13735 dump_glyph (row
, glyph
, area
);
13738 else if (glyphs
== 1)
13742 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
13744 char *s
= (char *) alloca (row
->used
[area
] + 1);
13747 for (i
= 0; i
< row
->used
[area
]; ++i
)
13749 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
13750 if (glyph
->type
== CHAR_GLYPH
13751 && glyph
->u
.ch
< 0x80
13752 && glyph
->u
.ch
>= ' ')
13753 s
[i
] = glyph
->u
.ch
;
13759 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
13765 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
13766 Sdump_glyph_matrix
, 0, 1, "p",
13767 doc
: /* Dump the current matrix of the selected window to stderr.
13768 Shows contents of glyph row structures. With non-nil
13769 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
13770 glyphs in short form, otherwise show glyphs in long form. */)
13772 Lisp_Object glyphs
;
13774 struct window
*w
= XWINDOW (selected_window
);
13775 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13777 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
13778 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
13779 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
13780 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
13781 fprintf (stderr
, "=============================================\n");
13782 dump_glyph_matrix (w
->current_matrix
,
13783 NILP (glyphs
) ? 0 : XINT (glyphs
));
13788 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
13789 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
13792 struct frame
*f
= XFRAME (selected_frame
);
13793 dump_glyph_matrix (f
->current_matrix
, 1);
13798 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
13799 doc
: /* Dump glyph row ROW to stderr.
13800 GLYPH 0 means don't dump glyphs.
13801 GLYPH 1 means dump glyphs in short form.
13802 GLYPH > 1 or omitted means dump glyphs in long form. */)
13804 Lisp_Object row
, glyphs
;
13806 struct glyph_matrix
*matrix
;
13809 CHECK_NUMBER (row
);
13810 matrix
= XWINDOW (selected_window
)->current_matrix
;
13812 if (vpos
>= 0 && vpos
< matrix
->nrows
)
13813 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
13815 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
13820 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
13821 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
13822 GLYPH 0 means don't dump glyphs.
13823 GLYPH 1 means dump glyphs in short form.
13824 GLYPH > 1 or omitted means dump glyphs in long form. */)
13826 Lisp_Object row
, glyphs
;
13828 struct frame
*sf
= SELECTED_FRAME ();
13829 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
13832 CHECK_NUMBER (row
);
13834 if (vpos
>= 0 && vpos
< m
->nrows
)
13835 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
13836 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
13841 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
13842 doc
: /* Toggle tracing of redisplay.
13843 With ARG, turn tracing on if and only if ARG is positive. */)
13848 trace_redisplay_p
= !trace_redisplay_p
;
13851 arg
= Fprefix_numeric_value (arg
);
13852 trace_redisplay_p
= XINT (arg
) > 0;
13859 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
13860 doc
: /* Like `format', but print result to stderr.
13861 usage: (trace-to-stderr STRING &rest OBJECTS) */)
13866 Lisp_Object s
= Fformat (nargs
, args
);
13867 fprintf (stderr
, "%s", SDATA (s
));
13871 #endif /* GLYPH_DEBUG */
13875 /***********************************************************************
13876 Building Desired Matrix Rows
13877 ***********************************************************************/
13879 /* Return a temporary glyph row holding the glyphs of an overlay
13880 arrow. Only used for non-window-redisplay windows. */
13882 static struct glyph_row
*
13883 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
13885 Lisp_Object overlay_arrow_string
;
13887 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13888 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13889 struct buffer
*old
= current_buffer
;
13890 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
13891 int arrow_len
= SCHARS (overlay_arrow_string
);
13892 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
13893 const unsigned char *p
;
13896 int n_glyphs_before
;
13898 set_buffer_temp (buffer
);
13899 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
13900 it
.glyph_row
->used
[TEXT_AREA
] = 0;
13901 SET_TEXT_POS (it
.position
, 0, 0);
13903 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
13905 while (p
< arrow_end
)
13907 Lisp_Object face
, ilisp
;
13909 /* Get the next character. */
13911 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
13913 it
.c
= *p
, it
.len
= 1;
13916 /* Get its face. */
13917 ilisp
= make_number (p
- arrow_string
);
13918 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
13919 it
.face_id
= compute_char_face (f
, it
.c
, face
);
13921 /* Compute its width, get its glyphs. */
13922 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
13923 SET_TEXT_POS (it
.position
, -1, -1);
13924 PRODUCE_GLYPHS (&it
);
13926 /* If this character doesn't fit any more in the line, we have
13927 to remove some glyphs. */
13928 if (it
.current_x
> it
.last_visible_x
)
13930 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
13935 set_buffer_temp (old
);
13936 return it
.glyph_row
;
13940 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
13941 glyphs are only inserted for terminal frames since we can't really
13942 win with truncation glyphs when partially visible glyphs are
13943 involved. Which glyphs to insert is determined by
13944 produce_special_glyphs. */
13947 insert_left_trunc_glyphs (it
)
13950 struct it truncate_it
;
13951 struct glyph
*from
, *end
, *to
, *toend
;
13953 xassert (!FRAME_WINDOW_P (it
->f
));
13955 /* Get the truncation glyphs. */
13957 truncate_it
.current_x
= 0;
13958 truncate_it
.face_id
= DEFAULT_FACE_ID
;
13959 truncate_it
.glyph_row
= &scratch_glyph_row
;
13960 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
13961 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
13962 truncate_it
.object
= make_number (0);
13963 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
13965 /* Overwrite glyphs from IT with truncation glyphs. */
13966 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
13967 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
13968 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
13969 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
13974 /* There may be padding glyphs left over. Overwrite them too. */
13975 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
13977 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
13983 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
13987 /* Compute the pixel height and width of IT->glyph_row.
13989 Most of the time, ascent and height of a display line will be equal
13990 to the max_ascent and max_height values of the display iterator
13991 structure. This is not the case if
13993 1. We hit ZV without displaying anything. In this case, max_ascent
13994 and max_height will be zero.
13996 2. We have some glyphs that don't contribute to the line height.
13997 (The glyph row flag contributes_to_line_height_p is for future
13998 pixmap extensions).
14000 The first case is easily covered by using default values because in
14001 these cases, the line height does not really matter, except that it
14002 must not be zero. */
14005 compute_line_metrics (it
)
14008 struct glyph_row
*row
= it
->glyph_row
;
14011 if (FRAME_WINDOW_P (it
->f
))
14013 int i
, min_y
, max_y
;
14015 /* The line may consist of one space only, that was added to
14016 place the cursor on it. If so, the row's height hasn't been
14018 if (row
->height
== 0)
14020 if (it
->max_ascent
+ it
->max_descent
== 0)
14021 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
14022 row
->ascent
= it
->max_ascent
;
14023 row
->height
= it
->max_ascent
+ it
->max_descent
;
14024 row
->phys_ascent
= it
->max_phys_ascent
;
14025 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14028 /* Compute the width of this line. */
14029 row
->pixel_width
= row
->x
;
14030 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
14031 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
14033 xassert (row
->pixel_width
>= 0);
14034 xassert (row
->ascent
>= 0 && row
->height
> 0);
14036 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
14037 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
14039 /* If first line's physical ascent is larger than its logical
14040 ascent, use the physical ascent, and make the row taller.
14041 This makes accented characters fully visible. */
14042 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
14043 && row
->phys_ascent
> row
->ascent
)
14045 row
->height
+= row
->phys_ascent
- row
->ascent
;
14046 row
->ascent
= row
->phys_ascent
;
14049 /* Compute how much of the line is visible. */
14050 row
->visible_height
= row
->height
;
14052 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
14053 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
14055 if (row
->y
< min_y
)
14056 row
->visible_height
-= min_y
- row
->y
;
14057 if (row
->y
+ row
->height
> max_y
)
14058 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14062 row
->pixel_width
= row
->used
[TEXT_AREA
];
14063 if (row
->continued_p
)
14064 row
->pixel_width
-= it
->continuation_pixel_width
;
14065 else if (row
->truncated_on_right_p
)
14066 row
->pixel_width
-= it
->truncation_pixel_width
;
14067 row
->ascent
= row
->phys_ascent
= 0;
14068 row
->height
= row
->phys_height
= row
->visible_height
= 1;
14071 /* Compute a hash code for this row. */
14073 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14074 for (i
= 0; i
< row
->used
[area
]; ++i
)
14075 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
14076 + row
->glyphs
[area
][i
].u
.val
14077 + row
->glyphs
[area
][i
].face_id
14078 + row
->glyphs
[area
][i
].padding_p
14079 + (row
->glyphs
[area
][i
].type
<< 2));
14081 it
->max_ascent
= it
->max_descent
= 0;
14082 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
14086 /* Append one space to the glyph row of iterator IT if doing a
14087 window-based redisplay. DEFAULT_FACE_P non-zero means let the
14088 space have the default face, otherwise let it have the same face as
14089 IT->face_id. Value is non-zero if a space was added.
14091 This function is called to make sure that there is always one glyph
14092 at the end of a glyph row that the cursor can be set on under
14093 window-systems. (If there weren't such a glyph we would not know
14094 how wide and tall a box cursor should be displayed).
14096 At the same time this space let's a nicely handle clearing to the
14097 end of the line if the row ends in italic text. */
14100 append_space (it
, default_face_p
)
14102 int default_face_p
;
14104 if (FRAME_WINDOW_P (it
->f
))
14106 int n
= it
->glyph_row
->used
[TEXT_AREA
];
14108 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
14109 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
14111 /* Save some values that must not be changed.
14112 Must save IT->c and IT->len because otherwise
14113 ITERATOR_AT_END_P wouldn't work anymore after
14114 append_space has been called. */
14115 enum display_element_type saved_what
= it
->what
;
14116 int saved_c
= it
->c
, saved_len
= it
->len
;
14117 int saved_x
= it
->current_x
;
14118 int saved_face_id
= it
->face_id
;
14119 struct text_pos saved_pos
;
14120 Lisp_Object saved_object
;
14123 saved_object
= it
->object
;
14124 saved_pos
= it
->position
;
14126 it
->what
= IT_CHARACTER
;
14127 bzero (&it
->position
, sizeof it
->position
);
14128 it
->object
= make_number (0);
14132 if (default_face_p
)
14133 it
->face_id
= DEFAULT_FACE_ID
;
14134 else if (it
->face_before_selective_p
)
14135 it
->face_id
= it
->saved_face_id
;
14136 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14137 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
14139 PRODUCE_GLYPHS (it
);
14141 it
->current_x
= saved_x
;
14142 it
->object
= saved_object
;
14143 it
->position
= saved_pos
;
14144 it
->what
= saved_what
;
14145 it
->face_id
= saved_face_id
;
14146 it
->len
= saved_len
;
14156 /* Extend the face of the last glyph in the text area of IT->glyph_row
14157 to the end of the display line. Called from display_line.
14158 If the glyph row is empty, add a space glyph to it so that we
14159 know the face to draw. Set the glyph row flag fill_line_p. */
14162 extend_face_to_end_of_line (it
)
14166 struct frame
*f
= it
->f
;
14168 /* If line is already filled, do nothing. */
14169 if (it
->current_x
>= it
->last_visible_x
)
14172 /* Face extension extends the background and box of IT->face_id
14173 to the end of the line. If the background equals the background
14174 of the frame, we don't have to do anything. */
14175 if (it
->face_before_selective_p
)
14176 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14178 face
= FACE_FROM_ID (f
, it
->face_id
);
14180 if (FRAME_WINDOW_P (f
)
14181 && face
->box
== FACE_NO_BOX
14182 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
14186 /* Set the glyph row flag indicating that the face of the last glyph
14187 in the text area has to be drawn to the end of the text area. */
14188 it
->glyph_row
->fill_line_p
= 1;
14190 /* If current character of IT is not ASCII, make sure we have the
14191 ASCII face. This will be automatically undone the next time
14192 get_next_display_element returns a multibyte character. Note
14193 that the character will always be single byte in unibyte text. */
14194 if (!SINGLE_BYTE_CHAR_P (it
->c
))
14196 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
14199 if (FRAME_WINDOW_P (f
))
14201 /* If the row is empty, add a space with the current face of IT,
14202 so that we know which face to draw. */
14203 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
14205 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
14206 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
14207 it
->glyph_row
->used
[TEXT_AREA
] = 1;
14212 /* Save some values that must not be changed. */
14213 int saved_x
= it
->current_x
;
14214 struct text_pos saved_pos
;
14215 Lisp_Object saved_object
;
14216 enum display_element_type saved_what
= it
->what
;
14217 int saved_face_id
= it
->face_id
;
14219 saved_object
= it
->object
;
14220 saved_pos
= it
->position
;
14222 it
->what
= IT_CHARACTER
;
14223 bzero (&it
->position
, sizeof it
->position
);
14224 it
->object
= make_number (0);
14227 it
->face_id
= face
->id
;
14229 PRODUCE_GLYPHS (it
);
14231 while (it
->current_x
<= it
->last_visible_x
)
14232 PRODUCE_GLYPHS (it
);
14234 /* Don't count these blanks really. It would let us insert a left
14235 truncation glyph below and make us set the cursor on them, maybe. */
14236 it
->current_x
= saved_x
;
14237 it
->object
= saved_object
;
14238 it
->position
= saved_pos
;
14239 it
->what
= saved_what
;
14240 it
->face_id
= saved_face_id
;
14245 /* Value is non-zero if text starting at CHARPOS in current_buffer is
14246 trailing whitespace. */
14249 trailing_whitespace_p (charpos
)
14252 int bytepos
= CHAR_TO_BYTE (charpos
);
14255 while (bytepos
< ZV_BYTE
14256 && (c
= FETCH_CHAR (bytepos
),
14257 c
== ' ' || c
== '\t'))
14260 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
14262 if (bytepos
!= PT_BYTE
)
14269 /* Highlight trailing whitespace, if any, in ROW. */
14272 highlight_trailing_whitespace (f
, row
)
14274 struct glyph_row
*row
;
14276 int used
= row
->used
[TEXT_AREA
];
14280 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
14281 struct glyph
*glyph
= start
+ used
- 1;
14283 /* Skip over glyphs inserted to display the cursor at the
14284 end of a line, for extending the face of the last glyph
14285 to the end of the line on terminals, and for truncation
14286 and continuation glyphs. */
14287 while (glyph
>= start
14288 && glyph
->type
== CHAR_GLYPH
14289 && INTEGERP (glyph
->object
))
14292 /* If last glyph is a space or stretch, and it's trailing
14293 whitespace, set the face of all trailing whitespace glyphs in
14294 IT->glyph_row to `trailing-whitespace'. */
14296 && BUFFERP (glyph
->object
)
14297 && (glyph
->type
== STRETCH_GLYPH
14298 || (glyph
->type
== CHAR_GLYPH
14299 && glyph
->u
.ch
== ' '))
14300 && trailing_whitespace_p (glyph
->charpos
))
14302 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
14304 while (glyph
>= start
14305 && BUFFERP (glyph
->object
)
14306 && (glyph
->type
== STRETCH_GLYPH
14307 || (glyph
->type
== CHAR_GLYPH
14308 && glyph
->u
.ch
== ' ')))
14309 (glyph
--)->face_id
= face_id
;
14315 /* Value is non-zero if glyph row ROW in window W should be
14316 used to hold the cursor. */
14319 cursor_row_p (w
, row
)
14321 struct glyph_row
*row
;
14323 int cursor_row_p
= 1;
14325 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
14327 /* If the row ends with a newline from a string, we don't want
14328 the cursor there (if the row is continued it doesn't end in a
14330 if (CHARPOS (row
->end
.string_pos
) >= 0
14331 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14332 cursor_row_p
= row
->continued_p
;
14334 /* If the row ends at ZV, display the cursor at the end of that
14335 row instead of at the start of the row below. */
14336 else if (row
->ends_at_zv_p
)
14342 return cursor_row_p
;
14346 /* Construct the glyph row IT->glyph_row in the desired matrix of
14347 IT->w from text at the current position of IT. See dispextern.h
14348 for an overview of struct it. Value is non-zero if
14349 IT->glyph_row displays text, as opposed to a line displaying ZV
14356 struct glyph_row
*row
= it
->glyph_row
;
14357 int overlay_arrow_bitmap
;
14358 Lisp_Object overlay_arrow_string
;
14360 /* We always start displaying at hpos zero even if hscrolled. */
14361 xassert (it
->hpos
== 0 && it
->current_x
== 0);
14363 /* We must not display in a row that's not a text row. */
14364 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
14365 < it
->w
->desired_matrix
->nrows
);
14367 /* Is IT->w showing the region? */
14368 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
14370 /* Clear the result glyph row and enable it. */
14371 prepare_desired_row (row
);
14373 row
->y
= it
->current_y
;
14374 row
->start
= it
->start
;
14375 row
->continuation_lines_width
= it
->continuation_lines_width
;
14376 row
->displays_text_p
= 1;
14377 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
14378 it
->starts_in_middle_of_char_p
= 0;
14380 /* Arrange the overlays nicely for our purposes. Usually, we call
14381 display_line on only one line at a time, in which case this
14382 can't really hurt too much, or we call it on lines which appear
14383 one after another in the buffer, in which case all calls to
14384 recenter_overlay_lists but the first will be pretty cheap. */
14385 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
14387 /* Move over display elements that are not visible because we are
14388 hscrolled. This may stop at an x-position < IT->first_visible_x
14389 if the first glyph is partially visible or if we hit a line end. */
14390 if (it
->current_x
< it
->first_visible_x
)
14391 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
14392 MOVE_TO_POS
| MOVE_TO_X
);
14394 /* Get the initial row height. This is either the height of the
14395 text hscrolled, if there is any, or zero. */
14396 row
->ascent
= it
->max_ascent
;
14397 row
->height
= it
->max_ascent
+ it
->max_descent
;
14398 row
->phys_ascent
= it
->max_phys_ascent
;
14399 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14401 /* Loop generating characters. The loop is left with IT on the next
14402 character to display. */
14405 int n_glyphs_before
, hpos_before
, x_before
;
14407 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
14409 /* Retrieve the next thing to display. Value is zero if end of
14411 if (!get_next_display_element (it
))
14413 /* Maybe add a space at the end of this line that is used to
14414 display the cursor there under X. Set the charpos of the
14415 first glyph of blank lines not corresponding to any text
14417 #ifdef HAVE_WINDOW_SYSTEM
14418 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14419 row
->exact_window_width_line_p
= 1;
14421 #endif /* HAVE_WINDOW_SYSTEM */
14422 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
14423 || row
->used
[TEXT_AREA
] == 0)
14425 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
14426 row
->displays_text_p
= 0;
14428 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
14429 && (!MINI_WINDOW_P (it
->w
)
14430 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
14431 row
->indicate_empty_line_p
= 1;
14434 it
->continuation_lines_width
= 0;
14435 row
->ends_at_zv_p
= 1;
14439 /* Now, get the metrics of what we want to display. This also
14440 generates glyphs in `row' (which is IT->glyph_row). */
14441 n_glyphs_before
= row
->used
[TEXT_AREA
];
14444 /* Remember the line height so far in case the next element doesn't
14445 fit on the line. */
14446 if (!it
->truncate_lines_p
)
14448 ascent
= it
->max_ascent
;
14449 descent
= it
->max_descent
;
14450 phys_ascent
= it
->max_phys_ascent
;
14451 phys_descent
= it
->max_phys_descent
;
14454 PRODUCE_GLYPHS (it
);
14456 /* If this display element was in marginal areas, continue with
14458 if (it
->area
!= TEXT_AREA
)
14460 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14461 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14462 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14463 row
->phys_height
= max (row
->phys_height
,
14464 it
->max_phys_ascent
+ it
->max_phys_descent
);
14465 set_iterator_to_next (it
, 1);
14469 /* Does the display element fit on the line? If we truncate
14470 lines, we should draw past the right edge of the window. If
14471 we don't truncate, we want to stop so that we can display the
14472 continuation glyph before the right margin. If lines are
14473 continued, there are two possible strategies for characters
14474 resulting in more than 1 glyph (e.g. tabs): Display as many
14475 glyphs as possible in this line and leave the rest for the
14476 continuation line, or display the whole element in the next
14477 line. Original redisplay did the former, so we do it also. */
14478 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
14479 hpos_before
= it
->hpos
;
14482 if (/* Not a newline. */
14484 /* Glyphs produced fit entirely in the line. */
14485 && it
->current_x
< it
->last_visible_x
)
14487 it
->hpos
+= nglyphs
;
14488 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14489 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14490 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14491 row
->phys_height
= max (row
->phys_height
,
14492 it
->max_phys_ascent
+ it
->max_phys_descent
);
14493 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
14494 row
->x
= x
- it
->first_visible_x
;
14499 struct glyph
*glyph
;
14501 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
14503 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14504 new_x
= x
+ glyph
->pixel_width
;
14506 if (/* Lines are continued. */
14507 !it
->truncate_lines_p
14508 && (/* Glyph doesn't fit on the line. */
14509 new_x
> it
->last_visible_x
14510 /* Or it fits exactly on a window system frame. */
14511 || (new_x
== it
->last_visible_x
14512 && FRAME_WINDOW_P (it
->f
))))
14514 /* End of a continued line. */
14517 || (new_x
== it
->last_visible_x
14518 && FRAME_WINDOW_P (it
->f
)))
14520 /* Current glyph is the only one on the line or
14521 fits exactly on the line. We must continue
14522 the line because we can't draw the cursor
14523 after the glyph. */
14524 row
->continued_p
= 1;
14525 it
->current_x
= new_x
;
14526 it
->continuation_lines_width
+= new_x
;
14528 if (i
== nglyphs
- 1)
14530 set_iterator_to_next (it
, 1);
14531 #ifdef HAVE_WINDOW_SYSTEM
14532 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14534 if (!get_next_display_element (it
))
14536 row
->exact_window_width_line_p
= 1;
14537 it
->continuation_lines_width
= 0;
14538 row
->continued_p
= 0;
14539 row
->ends_at_zv_p
= 1;
14541 else if (ITERATOR_AT_END_OF_LINE_P (it
))
14543 row
->continued_p
= 0;
14544 row
->exact_window_width_line_p
= 1;
14547 #endif /* HAVE_WINDOW_SYSTEM */
14550 else if (CHAR_GLYPH_PADDING_P (*glyph
)
14551 && !FRAME_WINDOW_P (it
->f
))
14553 /* A padding glyph that doesn't fit on this line.
14554 This means the whole character doesn't fit
14556 row
->used
[TEXT_AREA
] = n_glyphs_before
;
14558 /* Fill the rest of the row with continuation
14559 glyphs like in 20.x. */
14560 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
14561 < row
->glyphs
[1 + TEXT_AREA
])
14562 produce_special_glyphs (it
, IT_CONTINUATION
);
14564 row
->continued_p
= 1;
14565 it
->current_x
= x_before
;
14566 it
->continuation_lines_width
+= x_before
;
14568 /* Restore the height to what it was before the
14569 element not fitting on the line. */
14570 it
->max_ascent
= ascent
;
14571 it
->max_descent
= descent
;
14572 it
->max_phys_ascent
= phys_ascent
;
14573 it
->max_phys_descent
= phys_descent
;
14575 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
14577 /* A TAB that extends past the right edge of the
14578 window. This produces a single glyph on
14579 window system frames. We leave the glyph in
14580 this row and let it fill the row, but don't
14581 consume the TAB. */
14582 it
->continuation_lines_width
+= it
->last_visible_x
;
14583 row
->ends_in_middle_of_char_p
= 1;
14584 row
->continued_p
= 1;
14585 glyph
->pixel_width
= it
->last_visible_x
- x
;
14586 it
->starts_in_middle_of_char_p
= 1;
14590 /* Something other than a TAB that draws past
14591 the right edge of the window. Restore
14592 positions to values before the element. */
14593 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14595 /* Display continuation glyphs. */
14596 if (!FRAME_WINDOW_P (it
->f
))
14597 produce_special_glyphs (it
, IT_CONTINUATION
);
14598 row
->continued_p
= 1;
14600 it
->continuation_lines_width
+= x
;
14602 if (nglyphs
> 1 && i
> 0)
14604 row
->ends_in_middle_of_char_p
= 1;
14605 it
->starts_in_middle_of_char_p
= 1;
14608 /* Restore the height to what it was before the
14609 element not fitting on the line. */
14610 it
->max_ascent
= ascent
;
14611 it
->max_descent
= descent
;
14612 it
->max_phys_ascent
= phys_ascent
;
14613 it
->max_phys_descent
= phys_descent
;
14618 else if (new_x
> it
->first_visible_x
)
14620 /* Increment number of glyphs actually displayed. */
14623 if (x
< it
->first_visible_x
)
14624 /* Glyph is partially visible, i.e. row starts at
14625 negative X position. */
14626 row
->x
= x
- it
->first_visible_x
;
14630 /* Glyph is completely off the left margin of the
14631 window. This should not happen because of the
14632 move_it_in_display_line at the start of this
14633 function, unless the text display area of the
14634 window is empty. */
14635 xassert (it
->first_visible_x
<= it
->last_visible_x
);
14639 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14640 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14641 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14642 row
->phys_height
= max (row
->phys_height
,
14643 it
->max_phys_ascent
+ it
->max_phys_descent
);
14645 /* End of this display line if row is continued. */
14646 if (row
->continued_p
|| row
->ends_at_zv_p
)
14651 /* Is this a line end? If yes, we're also done, after making
14652 sure that a non-default face is extended up to the right
14653 margin of the window. */
14654 if (ITERATOR_AT_END_OF_LINE_P (it
))
14656 int used_before
= row
->used
[TEXT_AREA
];
14658 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
14660 #ifdef HAVE_WINDOW_SYSTEM
14661 /* Add a space at the end of the line that is used to
14662 display the cursor there. */
14663 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14664 append_space (it
, 0);
14665 #endif /* HAVE_WINDOW_SYSTEM */
14667 /* Extend the face to the end of the line. */
14668 extend_face_to_end_of_line (it
);
14670 /* Make sure we have the position. */
14671 if (used_before
== 0)
14672 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
14674 /* Consume the line end. This skips over invisible lines. */
14675 set_iterator_to_next (it
, 1);
14676 it
->continuation_lines_width
= 0;
14680 /* Proceed with next display element. Note that this skips
14681 over lines invisible because of selective display. */
14682 set_iterator_to_next (it
, 1);
14684 /* If we truncate lines, we are done when the last displayed
14685 glyphs reach past the right margin of the window. */
14686 if (it
->truncate_lines_p
14687 && (FRAME_WINDOW_P (it
->f
)
14688 ? (it
->current_x
>= it
->last_visible_x
)
14689 : (it
->current_x
> it
->last_visible_x
)))
14691 /* Maybe add truncation glyphs. */
14692 if (!FRAME_WINDOW_P (it
->f
))
14696 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14697 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14700 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14702 row
->used
[TEXT_AREA
] = i
;
14703 produce_special_glyphs (it
, IT_TRUNCATION
);
14706 #ifdef HAVE_WINDOW_SYSTEM
14709 /* Don't truncate if we can overflow newline into fringe. */
14710 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14712 if (!get_next_display_element (it
))
14714 #ifdef HAVE_WINDOW_SYSTEM
14715 it
->continuation_lines_width
= 0;
14716 row
->ends_at_zv_p
= 1;
14717 row
->exact_window_width_line_p
= 1;
14719 #endif /* HAVE_WINDOW_SYSTEM */
14721 if (ITERATOR_AT_END_OF_LINE_P (it
))
14723 row
->exact_window_width_line_p
= 1;
14724 goto at_end_of_line
;
14728 #endif /* HAVE_WINDOW_SYSTEM */
14730 row
->truncated_on_right_p
= 1;
14731 it
->continuation_lines_width
= 0;
14732 reseat_at_next_visible_line_start (it
, 0);
14733 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
14734 it
->hpos
= hpos_before
;
14735 it
->current_x
= x_before
;
14740 /* If line is not empty and hscrolled, maybe insert truncation glyphs
14741 at the left window margin. */
14742 if (it
->first_visible_x
14743 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
14745 if (!FRAME_WINDOW_P (it
->f
))
14746 insert_left_trunc_glyphs (it
);
14747 row
->truncated_on_left_p
= 1;
14750 /* If the start of this line is the overlay arrow-position, then
14751 mark this glyph row as the one containing the overlay arrow.
14752 This is clearly a mess with variable size fonts. It would be
14753 better to let it be displayed like cursors under X. */
14754 if (! overlay_arrow_seen
14755 && (overlay_arrow_string
14756 = overlay_arrow_at_row (it
->f
, row
, &overlay_arrow_bitmap
),
14757 !NILP (overlay_arrow_string
)))
14759 /* Overlay arrow in window redisplay is a fringe bitmap. */
14760 if (!FRAME_WINDOW_P (it
->f
))
14762 struct glyph_row
*arrow_row
14763 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
14764 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
14765 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
14766 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
14767 struct glyph
*p2
, *end
;
14769 /* Copy the arrow glyphs. */
14770 while (glyph
< arrow_end
)
14773 /* Throw away padding glyphs. */
14775 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
14776 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
14782 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
14786 overlay_arrow_seen
= 1;
14787 it
->w
->overlay_arrow_bitmap
= overlay_arrow_bitmap
;
14788 row
->overlay_arrow_p
= 1;
14791 /* Compute pixel dimensions of this line. */
14792 compute_line_metrics (it
);
14794 /* Remember the position at which this line ends. */
14795 row
->end
= it
->current
;
14797 /* Save fringe bitmaps in this row. */
14798 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
14799 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
14800 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
14801 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
14803 it
->left_user_fringe_bitmap
= 0;
14804 it
->left_user_fringe_face_id
= 0;
14805 it
->right_user_fringe_bitmap
= 0;
14806 it
->right_user_fringe_face_id
= 0;
14808 /* Maybe set the cursor. */
14809 if (it
->w
->cursor
.vpos
< 0
14810 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
14811 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
14812 && cursor_row_p (it
->w
, row
))
14813 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
14815 /* Highlight trailing whitespace. */
14816 if (!NILP (Vshow_trailing_whitespace
))
14817 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
14819 /* Prepare for the next line. This line starts horizontally at (X
14820 HPOS) = (0 0). Vertical positions are incremented. As a
14821 convenience for the caller, IT->glyph_row is set to the next
14823 it
->current_x
= it
->hpos
= 0;
14824 it
->current_y
+= row
->height
;
14827 it
->start
= it
->current
;
14828 return row
->displays_text_p
;
14833 /***********************************************************************
14835 ***********************************************************************/
14837 /* Redisplay the menu bar in the frame for window W.
14839 The menu bar of X frames that don't have X toolkit support is
14840 displayed in a special window W->frame->menu_bar_window.
14842 The menu bar of terminal frames is treated specially as far as
14843 glyph matrices are concerned. Menu bar lines are not part of
14844 windows, so the update is done directly on the frame matrix rows
14845 for the menu bar. */
14848 display_menu_bar (w
)
14851 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14856 /* Don't do all this for graphical frames. */
14858 if (!NILP (Vwindow_system
))
14861 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
14866 if (FRAME_MAC_P (f
))
14870 #ifdef USE_X_TOOLKIT
14871 xassert (!FRAME_WINDOW_P (f
));
14872 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
14873 it
.first_visible_x
= 0;
14874 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
14875 #else /* not USE_X_TOOLKIT */
14876 if (FRAME_WINDOW_P (f
))
14878 /* Menu bar lines are displayed in the desired matrix of the
14879 dummy window menu_bar_window. */
14880 struct window
*menu_w
;
14881 xassert (WINDOWP (f
->menu_bar_window
));
14882 menu_w
= XWINDOW (f
->menu_bar_window
);
14883 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
14885 it
.first_visible_x
= 0;
14886 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
14890 /* This is a TTY frame, i.e. character hpos/vpos are used as
14892 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
14894 it
.first_visible_x
= 0;
14895 it
.last_visible_x
= FRAME_COLS (f
);
14897 #endif /* not USE_X_TOOLKIT */
14899 if (! mode_line_inverse_video
)
14900 /* Force the menu-bar to be displayed in the default face. */
14901 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
14903 /* Clear all rows of the menu bar. */
14904 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
14906 struct glyph_row
*row
= it
.glyph_row
+ i
;
14907 clear_glyph_row (row
);
14908 row
->enabled_p
= 1;
14909 row
->full_width_p
= 1;
14912 /* Display all items of the menu bar. */
14913 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
14914 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
14916 Lisp_Object string
;
14918 /* Stop at nil string. */
14919 string
= AREF (items
, i
+ 1);
14923 /* Remember where item was displayed. */
14924 AREF (items
, i
+ 3) = make_number (it
.hpos
);
14926 /* Display the item, pad with one space. */
14927 if (it
.current_x
< it
.last_visible_x
)
14928 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
14929 SCHARS (string
) + 1, 0, 0, -1);
14932 /* Fill out the line with spaces. */
14933 if (it
.current_x
< it
.last_visible_x
)
14934 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
14936 /* Compute the total height of the lines. */
14937 compute_line_metrics (&it
);
14942 /***********************************************************************
14944 ***********************************************************************/
14946 /* Redisplay mode lines in the window tree whose root is WINDOW. If
14947 FORCE is non-zero, redisplay mode lines unconditionally.
14948 Otherwise, redisplay only mode lines that are garbaged. Value is
14949 the number of windows whose mode lines were redisplayed. */
14952 redisplay_mode_lines (window
, force
)
14953 Lisp_Object window
;
14958 while (!NILP (window
))
14960 struct window
*w
= XWINDOW (window
);
14962 if (WINDOWP (w
->hchild
))
14963 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
14964 else if (WINDOWP (w
->vchild
))
14965 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
14967 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
14968 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
14970 struct text_pos lpoint
;
14971 struct buffer
*old
= current_buffer
;
14973 /* Set the window's buffer for the mode line display. */
14974 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14975 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14977 /* Point refers normally to the selected window. For any
14978 other window, set up appropriate value. */
14979 if (!EQ (window
, selected_window
))
14981 struct text_pos pt
;
14983 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
14984 if (CHARPOS (pt
) < BEGV
)
14985 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
14986 else if (CHARPOS (pt
) > (ZV
- 1))
14987 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
14989 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
14992 /* Display mode lines. */
14993 clear_glyph_matrix (w
->desired_matrix
);
14994 if (display_mode_lines (w
))
14997 w
->must_be_updated_p
= 1;
15000 /* Restore old settings. */
15001 set_buffer_internal_1 (old
);
15002 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15012 /* Display the mode and/or top line of window W. Value is the number
15013 of mode lines displayed. */
15016 display_mode_lines (w
)
15019 Lisp_Object old_selected_window
, old_selected_frame
;
15022 old_selected_frame
= selected_frame
;
15023 selected_frame
= w
->frame
;
15024 old_selected_window
= selected_window
;
15025 XSETWINDOW (selected_window
, w
);
15027 /* These will be set while the mode line specs are processed. */
15028 line_number_displayed
= 0;
15029 w
->column_number_displayed
= Qnil
;
15031 if (WINDOW_WANTS_MODELINE_P (w
))
15033 struct window
*sel_w
= XWINDOW (old_selected_window
);
15035 /* Select mode line face based on the real selected window. */
15036 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
15037 current_buffer
->mode_line_format
);
15041 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15043 display_mode_line (w
, HEADER_LINE_FACE_ID
,
15044 current_buffer
->header_line_format
);
15048 selected_frame
= old_selected_frame
;
15049 selected_window
= old_selected_window
;
15054 /* Display mode or top line of window W. FACE_ID specifies which line
15055 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
15056 FORMAT is the mode line format to display. Value is the pixel
15057 height of the mode line displayed. */
15060 display_mode_line (w
, face_id
, format
)
15062 enum face_id face_id
;
15063 Lisp_Object format
;
15068 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15069 prepare_desired_row (it
.glyph_row
);
15071 it
.glyph_row
->mode_line_p
= 1;
15073 if (! mode_line_inverse_video
)
15074 /* Force the mode-line to be displayed in the default face. */
15075 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15077 /* Temporarily make frame's keyboard the current kboard so that
15078 kboard-local variables in the mode_line_format will get the right
15080 push_frame_kboard (it
.f
);
15081 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15082 pop_frame_kboard ();
15084 /* Fill up with spaces. */
15085 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
15087 compute_line_metrics (&it
);
15088 it
.glyph_row
->full_width_p
= 1;
15089 it
.glyph_row
->continued_p
= 0;
15090 it
.glyph_row
->truncated_on_left_p
= 0;
15091 it
.glyph_row
->truncated_on_right_p
= 0;
15093 /* Make a 3D mode-line have a shadow at its right end. */
15094 face
= FACE_FROM_ID (it
.f
, face_id
);
15095 extend_face_to_end_of_line (&it
);
15096 if (face
->box
!= FACE_NO_BOX
)
15098 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
15099 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
15100 last
->right_box_line_p
= 1;
15103 return it
.glyph_row
->height
;
15106 /* Alist that caches the results of :propertize.
15107 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
15108 Lisp_Object mode_line_proptrans_alist
;
15110 /* List of strings making up the mode-line. */
15111 Lisp_Object mode_line_string_list
;
15113 /* Base face property when building propertized mode line string. */
15114 static Lisp_Object mode_line_string_face
;
15115 static Lisp_Object mode_line_string_face_prop
;
15118 /* Contribute ELT to the mode line for window IT->w. How it
15119 translates into text depends on its data type.
15121 IT describes the display environment in which we display, as usual.
15123 DEPTH is the depth in recursion. It is used to prevent
15124 infinite recursion here.
15126 FIELD_WIDTH is the number of characters the display of ELT should
15127 occupy in the mode line, and PRECISION is the maximum number of
15128 characters to display from ELT's representation. See
15129 display_string for details.
15131 Returns the hpos of the end of the text generated by ELT.
15133 PROPS is a property list to add to any string we encounter.
15135 If RISKY is nonzero, remove (disregard) any properties in any string
15136 we encounter, and ignore :eval and :propertize.
15138 If the global variable `frame_title_ptr' is non-NULL, then the output
15139 is passed to `store_frame_title' instead of `display_string'. */
15142 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
15145 int field_width
, precision
;
15146 Lisp_Object elt
, props
;
15149 int n
= 0, field
, prec
;
15154 elt
= build_string ("*too-deep*");
15158 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
15162 /* A string: output it and check for %-constructs within it. */
15164 const unsigned char *this, *lisp_string
;
15166 if (!NILP (props
) || risky
)
15168 Lisp_Object oprops
, aelt
;
15169 oprops
= Ftext_properties_at (make_number (0), elt
);
15171 if (NILP (Fequal (props
, oprops
)) || risky
)
15173 /* If the starting string has properties,
15174 merge the specified ones onto the existing ones. */
15175 if (! NILP (oprops
) && !risky
)
15179 oprops
= Fcopy_sequence (oprops
);
15181 while (CONSP (tem
))
15183 oprops
= Fplist_put (oprops
, XCAR (tem
),
15184 XCAR (XCDR (tem
)));
15185 tem
= XCDR (XCDR (tem
));
15190 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
15191 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
15193 mode_line_proptrans_alist
15194 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
15201 elt
= Fcopy_sequence (elt
);
15202 Fset_text_properties (make_number (0), Flength (elt
),
15204 /* Add this item to mode_line_proptrans_alist. */
15205 mode_line_proptrans_alist
15206 = Fcons (Fcons (elt
, props
),
15207 mode_line_proptrans_alist
);
15208 /* Truncate mode_line_proptrans_alist
15209 to at most 50 elements. */
15210 tem
= Fnthcdr (make_number (50),
15211 mode_line_proptrans_alist
);
15213 XSETCDR (tem
, Qnil
);
15218 this = SDATA (elt
);
15219 lisp_string
= this;
15223 prec
= precision
- n
;
15224 if (frame_title_ptr
)
15225 n
+= store_frame_title (SDATA (elt
), -1, prec
);
15226 else if (!NILP (mode_line_string_list
))
15227 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
15229 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
15230 0, prec
, 0, STRING_MULTIBYTE (elt
));
15235 while ((precision
<= 0 || n
< precision
)
15237 && (frame_title_ptr
15238 || !NILP (mode_line_string_list
)
15239 || it
->current_x
< it
->last_visible_x
))
15241 const unsigned char *last
= this;
15243 /* Advance to end of string or next format specifier. */
15244 while ((c
= *this++) != '\0' && c
!= '%')
15247 if (this - 1 != last
)
15249 /* Output to end of string or up to '%'. Field width
15250 is length of string. Don't output more than
15251 PRECISION allows us. */
15254 prec
= chars_in_text (last
, this - last
);
15255 if (precision
> 0 && prec
> precision
- n
)
15256 prec
= precision
- n
;
15258 if (frame_title_ptr
)
15259 n
+= store_frame_title (last
, 0, prec
);
15260 else if (!NILP (mode_line_string_list
))
15262 int bytepos
= last
- lisp_string
;
15263 int charpos
= string_byte_to_char (elt
, bytepos
);
15264 n
+= store_mode_line_string (NULL
,
15265 Fsubstring (elt
, make_number (charpos
),
15266 make_number (charpos
+ prec
)),
15271 int bytepos
= last
- lisp_string
;
15272 int charpos
= string_byte_to_char (elt
, bytepos
);
15273 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
15275 STRING_MULTIBYTE (elt
));
15278 else /* c == '%' */
15280 const unsigned char *percent_position
= this;
15282 /* Get the specified minimum width. Zero means
15285 while ((c
= *this++) >= '0' && c
<= '9')
15286 field
= field
* 10 + c
- '0';
15288 /* Don't pad beyond the total padding allowed. */
15289 if (field_width
- n
> 0 && field
> field_width
- n
)
15290 field
= field_width
- n
;
15292 /* Note that either PRECISION <= 0 or N < PRECISION. */
15293 prec
= precision
- n
;
15296 n
+= display_mode_element (it
, depth
, field
, prec
,
15297 Vglobal_mode_string
, props
,
15302 int bytepos
, charpos
;
15303 unsigned char *spec
;
15305 bytepos
= percent_position
- lisp_string
;
15306 charpos
= (STRING_MULTIBYTE (elt
)
15307 ? string_byte_to_char (elt
, bytepos
)
15311 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
15313 if (frame_title_ptr
)
15314 n
+= store_frame_title (spec
, field
, prec
);
15315 else if (!NILP (mode_line_string_list
))
15317 int len
= strlen (spec
);
15318 Lisp_Object tem
= make_string (spec
, len
);
15319 props
= Ftext_properties_at (make_number (charpos
), elt
);
15320 /* Should only keep face property in props */
15321 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
15325 int nglyphs_before
, nwritten
;
15327 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
15328 nwritten
= display_string (spec
, Qnil
, elt
,
15333 /* Assign to the glyphs written above the
15334 string where the `%x' came from, position
15338 struct glyph
*glyph
15339 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
15343 for (i
= 0; i
< nwritten
; ++i
)
15345 glyph
[i
].object
= elt
;
15346 glyph
[i
].charpos
= charpos
;
15361 /* A symbol: process the value of the symbol recursively
15362 as if it appeared here directly. Avoid error if symbol void.
15363 Special case: if value of symbol is a string, output the string
15366 register Lisp_Object tem
;
15368 /* If the variable is not marked as risky to set
15369 then its contents are risky to use. */
15370 if (NILP (Fget (elt
, Qrisky_local_variable
)))
15373 tem
= Fboundp (elt
);
15376 tem
= Fsymbol_value (elt
);
15377 /* If value is a string, output that string literally:
15378 don't check for % within it. */
15382 if (!EQ (tem
, elt
))
15384 /* Give up right away for nil or t. */
15394 register Lisp_Object car
, tem
;
15396 /* A cons cell: five distinct cases.
15397 If first element is :eval or :propertize, do something special.
15398 If first element is a string or a cons, process all the elements
15399 and effectively concatenate them.
15400 If first element is a negative number, truncate displaying cdr to
15401 at most that many characters. If positive, pad (with spaces)
15402 to at least that many characters.
15403 If first element is a symbol, process the cadr or caddr recursively
15404 according to whether the symbol's value is non-nil or nil. */
15406 if (EQ (car
, QCeval
))
15408 /* An element of the form (:eval FORM) means evaluate FORM
15409 and use the result as mode line elements. */
15414 if (CONSP (XCDR (elt
)))
15417 spec
= safe_eval (XCAR (XCDR (elt
)));
15418 n
+= display_mode_element (it
, depth
, field_width
- n
,
15419 precision
- n
, spec
, props
,
15423 else if (EQ (car
, QCpropertize
))
15425 /* An element of the form (:propertize ELT PROPS...)
15426 means display ELT but applying properties PROPS. */
15431 if (CONSP (XCDR (elt
)))
15432 n
+= display_mode_element (it
, depth
, field_width
- n
,
15433 precision
- n
, XCAR (XCDR (elt
)),
15434 XCDR (XCDR (elt
)), risky
);
15436 else if (SYMBOLP (car
))
15438 tem
= Fboundp (car
);
15442 /* elt is now the cdr, and we know it is a cons cell.
15443 Use its car if CAR has a non-nil value. */
15446 tem
= Fsymbol_value (car
);
15453 /* Symbol's value is nil (or symbol is unbound)
15454 Get the cddr of the original list
15455 and if possible find the caddr and use that. */
15459 else if (!CONSP (elt
))
15464 else if (INTEGERP (car
))
15466 register int lim
= XINT (car
);
15470 /* Negative int means reduce maximum width. */
15471 if (precision
<= 0)
15474 precision
= min (precision
, -lim
);
15478 /* Padding specified. Don't let it be more than
15479 current maximum. */
15481 lim
= min (precision
, lim
);
15483 /* If that's more padding than already wanted, queue it.
15484 But don't reduce padding already specified even if
15485 that is beyond the current truncation point. */
15486 field_width
= max (lim
, field_width
);
15490 else if (STRINGP (car
) || CONSP (car
))
15492 register int limit
= 50;
15493 /* Limit is to protect against circular lists. */
15496 && (precision
<= 0 || n
< precision
))
15498 n
+= display_mode_element (it
, depth
, field_width
- n
,
15499 precision
- n
, XCAR (elt
),
15509 elt
= build_string ("*invalid*");
15513 /* Pad to FIELD_WIDTH. */
15514 if (field_width
> 0 && n
< field_width
)
15516 if (frame_title_ptr
)
15517 n
+= store_frame_title ("", field_width
- n
, 0);
15518 else if (!NILP (mode_line_string_list
))
15519 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
15521 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
15528 /* Store a mode-line string element in mode_line_string_list.
15530 If STRING is non-null, display that C string. Otherwise, the Lisp
15531 string LISP_STRING is displayed.
15533 FIELD_WIDTH is the minimum number of output glyphs to produce.
15534 If STRING has fewer characters than FIELD_WIDTH, pad to the right
15535 with spaces. FIELD_WIDTH <= 0 means don't pad.
15537 PRECISION is the maximum number of characters to output from
15538 STRING. PRECISION <= 0 means don't truncate the string.
15540 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
15541 properties to the string.
15543 PROPS are the properties to add to the string.
15544 The mode_line_string_face face property is always added to the string.
15547 static int store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
15549 Lisp_Object lisp_string
;
15558 if (string
!= NULL
)
15560 len
= strlen (string
);
15561 if (precision
> 0 && len
> precision
)
15563 lisp_string
= make_string (string
, len
);
15565 props
= mode_line_string_face_prop
;
15566 else if (!NILP (mode_line_string_face
))
15568 Lisp_Object face
= Fplist_get (props
, Qface
);
15569 props
= Fcopy_sequence (props
);
15571 face
= mode_line_string_face
;
15573 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15574 props
= Fplist_put (props
, Qface
, face
);
15576 Fadd_text_properties (make_number (0), make_number (len
),
15577 props
, lisp_string
);
15581 len
= XFASTINT (Flength (lisp_string
));
15582 if (precision
> 0 && len
> precision
)
15585 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
15588 if (!NILP (mode_line_string_face
))
15592 props
= Ftext_properties_at (make_number (0), lisp_string
);
15593 face
= Fplist_get (props
, Qface
);
15595 face
= mode_line_string_face
;
15597 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15598 props
= Fcons (Qface
, Fcons (face
, Qnil
));
15600 lisp_string
= Fcopy_sequence (lisp_string
);
15603 Fadd_text_properties (make_number (0), make_number (len
),
15604 props
, lisp_string
);
15609 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15613 if (field_width
> len
)
15615 field_width
-= len
;
15616 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
15618 Fadd_text_properties (make_number (0), make_number (field_width
),
15619 props
, lisp_string
);
15620 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15628 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
15630 doc
: /* Return the mode-line of selected window as a string.
15631 First optional arg FORMAT specifies a different format string (see
15632 `mode-line-format' for details) to use. If FORMAT is t, return
15633 the buffer's header-line. Second optional arg WINDOW specifies a
15634 different window to use as the context for the formatting.
15635 If third optional arg NO-PROPS is non-nil, string is not propertized. */)
15636 (format
, window
, no_props
)
15637 Lisp_Object format
, window
, no_props
;
15642 struct buffer
*old_buffer
= NULL
;
15643 enum face_id face_id
= DEFAULT_FACE_ID
;
15646 window
= selected_window
;
15647 CHECK_WINDOW (window
);
15648 w
= XWINDOW (window
);
15649 CHECK_BUFFER (w
->buffer
);
15651 if (XBUFFER (w
->buffer
) != current_buffer
)
15653 old_buffer
= current_buffer
;
15654 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15657 if (NILP (format
) || EQ (format
, Qt
))
15659 face_id
= NILP (format
)
15660 ? CURRENT_MODE_LINE_FACE_ID (w
) :
15661 HEADER_LINE_FACE_ID
;
15662 format
= NILP (format
)
15663 ? current_buffer
->mode_line_format
15664 : current_buffer
->header_line_format
;
15667 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15669 if (NILP (no_props
))
15671 mode_line_string_face
=
15672 (face_id
== MODE_LINE_FACE_ID
? Qmode_line
:
15673 face_id
== MODE_LINE_INACTIVE_FACE_ID
? Qmode_line_inactive
:
15674 face_id
== HEADER_LINE_FACE_ID
? Qheader_line
: Qnil
);
15676 mode_line_string_face_prop
=
15677 NILP (mode_line_string_face
) ? Qnil
:
15678 Fcons (Qface
, Fcons (mode_line_string_face
, Qnil
));
15680 /* We need a dummy last element in mode_line_string_list to
15681 indicate we are building the propertized mode-line string.
15682 Using mode_line_string_face_prop here GC protects it. */
15683 mode_line_string_list
=
15684 Fcons (mode_line_string_face_prop
, Qnil
);
15685 frame_title_ptr
= NULL
;
15689 mode_line_string_face_prop
= Qnil
;
15690 mode_line_string_list
= Qnil
;
15691 frame_title_ptr
= frame_title_buf
;
15694 push_frame_kboard (it
.f
);
15695 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15696 pop_frame_kboard ();
15699 set_buffer_internal_1 (old_buffer
);
15701 if (NILP (no_props
))
15704 mode_line_string_list
= Fnreverse (mode_line_string_list
);
15705 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
15706 make_string ("", 0));
15707 mode_line_string_face_prop
= Qnil
;
15708 mode_line_string_list
= Qnil
;
15712 len
= frame_title_ptr
- frame_title_buf
;
15713 if (len
> 0 && frame_title_ptr
[-1] == '-')
15715 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
15716 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
15718 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
15719 if (len
> frame_title_ptr
- frame_title_buf
)
15720 len
= frame_title_ptr
- frame_title_buf
;
15723 frame_title_ptr
= NULL
;
15724 return make_string (frame_title_buf
, len
);
15727 /* Write a null-terminated, right justified decimal representation of
15728 the positive integer D to BUF using a minimal field width WIDTH. */
15731 pint2str (buf
, width
, d
)
15732 register char *buf
;
15733 register int width
;
15736 register char *p
= buf
;
15744 *p
++ = d
% 10 + '0';
15749 for (width
-= (int) (p
- buf
); width
> 0; --width
)
15760 /* Write a null-terminated, right justified decimal and "human
15761 readable" representation of the nonnegative integer D to BUF using
15762 a minimal field width WIDTH. D should be smaller than 999.5e24. */
15764 static const char power_letter
[] =
15778 pint2hrstr (buf
, width
, d
)
15783 /* We aim to represent the nonnegative integer D as
15784 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
15787 /* -1 means: do not use TENTHS. */
15791 /* Length of QUOTIENT.TENTHS as a string. */
15797 if (1000 <= quotient
)
15799 /* Scale to the appropriate EXPONENT. */
15802 remainder
= quotient
% 1000;
15806 while (1000 <= quotient
);
15808 /* Round to nearest and decide whether to use TENTHS or not. */
15811 tenths
= remainder
/ 100;
15812 if (50 <= remainder
% 100)
15818 if (quotient
== 10)
15825 if (500 <= remainder
)
15826 if (quotient
< 999)
15836 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
15837 if (tenths
== -1 && quotient
<= 99)
15844 p
= psuffix
= buf
+ max (width
, length
);
15846 /* Print EXPONENT. */
15848 *psuffix
++ = power_letter
[exponent
];
15851 /* Print TENTHS. */
15854 *--p
= '0' + tenths
;
15858 /* Print QUOTIENT. */
15861 int digit
= quotient
% 10;
15862 *--p
= '0' + digit
;
15864 while ((quotient
/= 10) != 0);
15866 /* Print leading spaces. */
15871 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
15872 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
15873 type of CODING_SYSTEM. Return updated pointer into BUF. */
15875 static unsigned char invalid_eol_type
[] = "(*invalid*)";
15878 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
15879 Lisp_Object coding_system
;
15880 register char *buf
;
15884 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
15885 const unsigned char *eol_str
;
15887 /* The EOL conversion we are using. */
15888 Lisp_Object eoltype
;
15890 val
= Fget (coding_system
, Qcoding_system
);
15893 if (!VECTORP (val
)) /* Not yet decided. */
15898 eoltype
= eol_mnemonic_undecided
;
15899 /* Don't mention EOL conversion if it isn't decided. */
15903 Lisp_Object eolvalue
;
15905 eolvalue
= Fget (coding_system
, Qeol_type
);
15908 *buf
++ = XFASTINT (AREF (val
, 1));
15912 /* The EOL conversion that is normal on this system. */
15914 if (NILP (eolvalue
)) /* Not yet decided. */
15915 eoltype
= eol_mnemonic_undecided
;
15916 else if (VECTORP (eolvalue
)) /* Not yet decided. */
15917 eoltype
= eol_mnemonic_undecided
;
15918 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
15919 eoltype
= (XFASTINT (eolvalue
) == 0
15920 ? eol_mnemonic_unix
15921 : (XFASTINT (eolvalue
) == 1
15922 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
15928 /* Mention the EOL conversion if it is not the usual one. */
15929 if (STRINGP (eoltype
))
15931 eol_str
= SDATA (eoltype
);
15932 eol_str_len
= SBYTES (eoltype
);
15934 else if (INTEGERP (eoltype
)
15935 && CHAR_VALID_P (XINT (eoltype
), 0))
15937 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
15938 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
15943 eol_str
= invalid_eol_type
;
15944 eol_str_len
= sizeof (invalid_eol_type
) - 1;
15946 bcopy (eol_str
, buf
, eol_str_len
);
15947 buf
+= eol_str_len
;
15953 /* Return a string for the output of a mode line %-spec for window W,
15954 generated by character C. PRECISION >= 0 means don't return a
15955 string longer than that value. FIELD_WIDTH > 0 means pad the
15956 string returned with spaces to that value. Return 1 in *MULTIBYTE
15957 if the result is multibyte text. */
15959 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
15962 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
15965 int field_width
, precision
;
15969 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15970 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
15971 struct buffer
*b
= XBUFFER (w
->buffer
);
15979 if (!NILP (b
->read_only
))
15981 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
15986 /* This differs from %* only for a modified read-only buffer. */
15987 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
15989 if (!NILP (b
->read_only
))
15994 /* This differs from %* in ignoring read-only-ness. */
15995 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16007 if (command_loop_level
> 5)
16009 p
= decode_mode_spec_buf
;
16010 for (i
= 0; i
< command_loop_level
; i
++)
16013 return decode_mode_spec_buf
;
16021 if (command_loop_level
> 5)
16023 p
= decode_mode_spec_buf
;
16024 for (i
= 0; i
< command_loop_level
; i
++)
16027 return decode_mode_spec_buf
;
16034 /* Let lots_of_dashes be a string of infinite length. */
16035 if (!NILP (mode_line_string_list
))
16037 if (field_width
<= 0
16038 || field_width
> sizeof (lots_of_dashes
))
16040 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
16041 decode_mode_spec_buf
[i
] = '-';
16042 decode_mode_spec_buf
[i
] = '\0';
16043 return decode_mode_spec_buf
;
16046 return lots_of_dashes
;
16055 int col
= (int) current_column (); /* iftc */
16056 w
->column_number_displayed
= make_number (col
);
16057 pint2str (decode_mode_spec_buf
, field_width
, col
);
16058 return decode_mode_spec_buf
;
16062 /* %F displays the frame name. */
16063 if (!NILP (f
->title
))
16064 return (char *) SDATA (f
->title
);
16065 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
16066 return (char *) SDATA (f
->name
);
16075 int size
= ZV
- BEGV
;
16076 pint2str (decode_mode_spec_buf
, field_width
, size
);
16077 return decode_mode_spec_buf
;
16082 int size
= ZV
- BEGV
;
16083 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
16084 return decode_mode_spec_buf
;
16089 int startpos
= XMARKER (w
->start
)->charpos
;
16090 int startpos_byte
= marker_byte_position (w
->start
);
16091 int line
, linepos
, linepos_byte
, topline
;
16093 int height
= WINDOW_TOTAL_LINES (w
);
16095 /* If we decided that this buffer isn't suitable for line numbers,
16096 don't forget that too fast. */
16097 if (EQ (w
->base_line_pos
, w
->buffer
))
16099 /* But do forget it, if the window shows a different buffer now. */
16100 else if (BUFFERP (w
->base_line_pos
))
16101 w
->base_line_pos
= Qnil
;
16103 /* If the buffer is very big, don't waste time. */
16104 if (INTEGERP (Vline_number_display_limit
)
16105 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
16107 w
->base_line_pos
= Qnil
;
16108 w
->base_line_number
= Qnil
;
16112 if (!NILP (w
->base_line_number
)
16113 && !NILP (w
->base_line_pos
)
16114 && XFASTINT (w
->base_line_pos
) <= startpos
)
16116 line
= XFASTINT (w
->base_line_number
);
16117 linepos
= XFASTINT (w
->base_line_pos
);
16118 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
16123 linepos
= BUF_BEGV (b
);
16124 linepos_byte
= BUF_BEGV_BYTE (b
);
16127 /* Count lines from base line to window start position. */
16128 nlines
= display_count_lines (linepos
, linepos_byte
,
16132 topline
= nlines
+ line
;
16134 /* Determine a new base line, if the old one is too close
16135 or too far away, or if we did not have one.
16136 "Too close" means it's plausible a scroll-down would
16137 go back past it. */
16138 if (startpos
== BUF_BEGV (b
))
16140 w
->base_line_number
= make_number (topline
);
16141 w
->base_line_pos
= make_number (BUF_BEGV (b
));
16143 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
16144 || linepos
== BUF_BEGV (b
))
16146 int limit
= BUF_BEGV (b
);
16147 int limit_byte
= BUF_BEGV_BYTE (b
);
16149 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
16151 if (startpos
- distance
> limit
)
16153 limit
= startpos
- distance
;
16154 limit_byte
= CHAR_TO_BYTE (limit
);
16157 nlines
= display_count_lines (startpos
, startpos_byte
,
16159 - (height
* 2 + 30),
16161 /* If we couldn't find the lines we wanted within
16162 line_number_display_limit_width chars per line,
16163 give up on line numbers for this window. */
16164 if (position
== limit_byte
&& limit
== startpos
- distance
)
16166 w
->base_line_pos
= w
->buffer
;
16167 w
->base_line_number
= Qnil
;
16171 w
->base_line_number
= make_number (topline
- nlines
);
16172 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
16175 /* Now count lines from the start pos to point. */
16176 nlines
= display_count_lines (startpos
, startpos_byte
,
16177 PT_BYTE
, PT
, &junk
);
16179 /* Record that we did display the line number. */
16180 line_number_displayed
= 1;
16182 /* Make the string to show. */
16183 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
16184 return decode_mode_spec_buf
;
16187 char* p
= decode_mode_spec_buf
;
16188 int pad
= field_width
- 2;
16194 return decode_mode_spec_buf
;
16200 obj
= b
->mode_name
;
16204 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
16210 int pos
= marker_position (w
->start
);
16211 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16213 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
16215 if (pos
<= BUF_BEGV (b
))
16220 else if (pos
<= BUF_BEGV (b
))
16224 if (total
> 1000000)
16225 /* Do it differently for a large value, to avoid overflow. */
16226 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16228 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16229 /* We can't normally display a 3-digit number,
16230 so get us a 2-digit number that is close. */
16233 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16234 return decode_mode_spec_buf
;
16238 /* Display percentage of size above the bottom of the screen. */
16241 int toppos
= marker_position (w
->start
);
16242 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
16243 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16245 if (botpos
>= BUF_ZV (b
))
16247 if (toppos
<= BUF_BEGV (b
))
16254 if (total
> 1000000)
16255 /* Do it differently for a large value, to avoid overflow. */
16256 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16258 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16259 /* We can't normally display a 3-digit number,
16260 so get us a 2-digit number that is close. */
16263 if (toppos
<= BUF_BEGV (b
))
16264 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
16266 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16267 return decode_mode_spec_buf
;
16272 /* status of process */
16273 obj
= Fget_buffer_process (w
->buffer
);
16275 return "no process";
16276 #ifdef subprocesses
16277 obj
= Fsymbol_name (Fprocess_status (obj
));
16281 case 't': /* indicate TEXT or BINARY */
16282 #ifdef MODE_LINE_BINARY_TEXT
16283 return MODE_LINE_BINARY_TEXT (b
);
16289 /* coding-system (not including end-of-line format) */
16291 /* coding-system (including end-of-line type) */
16293 int eol_flag
= (c
== 'Z');
16294 char *p
= decode_mode_spec_buf
;
16296 if (! FRAME_WINDOW_P (f
))
16298 /* No need to mention EOL here--the terminal never needs
16299 to do EOL conversion. */
16300 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
16301 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
16303 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
16306 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
16307 #ifdef subprocesses
16308 obj
= Fget_buffer_process (Fcurrent_buffer ());
16309 if (PROCESSP (obj
))
16311 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
16313 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
16316 #endif /* subprocesses */
16319 return decode_mode_spec_buf
;
16325 *multibyte
= STRING_MULTIBYTE (obj
);
16326 return (char *) SDATA (obj
);
16333 /* Count up to COUNT lines starting from START / START_BYTE.
16334 But don't go beyond LIMIT_BYTE.
16335 Return the number of lines thus found (always nonnegative).
16337 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
16340 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
16341 int start
, start_byte
, limit_byte
, count
;
16344 register unsigned char *cursor
;
16345 unsigned char *base
;
16347 register int ceiling
;
16348 register unsigned char *ceiling_addr
;
16349 int orig_count
= count
;
16351 /* If we are not in selective display mode,
16352 check only for newlines. */
16353 int selective_display
= (!NILP (current_buffer
->selective_display
)
16354 && !INTEGERP (current_buffer
->selective_display
));
16358 while (start_byte
< limit_byte
)
16360 ceiling
= BUFFER_CEILING_OF (start_byte
);
16361 ceiling
= min (limit_byte
- 1, ceiling
);
16362 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
16363 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
16366 if (selective_display
)
16367 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
16370 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
16373 if (cursor
!= ceiling_addr
)
16377 start_byte
+= cursor
- base
+ 1;
16378 *byte_pos_ptr
= start_byte
;
16382 if (++cursor
== ceiling_addr
)
16388 start_byte
+= cursor
- base
;
16393 while (start_byte
> limit_byte
)
16395 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
16396 ceiling
= max (limit_byte
, ceiling
);
16397 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
16398 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
16401 if (selective_display
)
16402 while (--cursor
!= ceiling_addr
16403 && *cursor
!= '\n' && *cursor
!= 015)
16406 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
16409 if (cursor
!= ceiling_addr
)
16413 start_byte
+= cursor
- base
+ 1;
16414 *byte_pos_ptr
= start_byte
;
16415 /* When scanning backwards, we should
16416 not count the newline posterior to which we stop. */
16417 return - orig_count
- 1;
16423 /* Here we add 1 to compensate for the last decrement
16424 of CURSOR, which took it past the valid range. */
16425 start_byte
+= cursor
- base
+ 1;
16429 *byte_pos_ptr
= limit_byte
;
16432 return - orig_count
+ count
;
16433 return orig_count
- count
;
16439 /***********************************************************************
16441 ***********************************************************************/
16443 /* Display a NUL-terminated string, starting with index START.
16445 If STRING is non-null, display that C string. Otherwise, the Lisp
16446 string LISP_STRING is displayed.
16448 If FACE_STRING is not nil, FACE_STRING_POS is a position in
16449 FACE_STRING. Display STRING or LISP_STRING with the face at
16450 FACE_STRING_POS in FACE_STRING:
16452 Display the string in the environment given by IT, but use the
16453 standard display table, temporarily.
16455 FIELD_WIDTH is the minimum number of output glyphs to produce.
16456 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16457 with spaces. If STRING has more characters, more than FIELD_WIDTH
16458 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
16460 PRECISION is the maximum number of characters to output from
16461 STRING. PRECISION < 0 means don't truncate the string.
16463 This is roughly equivalent to printf format specifiers:
16465 FIELD_WIDTH PRECISION PRINTF
16466 ----------------------------------------
16472 MULTIBYTE zero means do not display multibyte chars, > 0 means do
16473 display them, and < 0 means obey the current buffer's value of
16474 enable_multibyte_characters.
16476 Value is the number of glyphs produced. */
16479 display_string (string
, lisp_string
, face_string
, face_string_pos
,
16480 start
, it
, field_width
, precision
, max_x
, multibyte
)
16481 unsigned char *string
;
16482 Lisp_Object lisp_string
;
16483 Lisp_Object face_string
;
16484 int face_string_pos
;
16487 int field_width
, precision
, max_x
;
16490 int hpos_at_start
= it
->hpos
;
16491 int saved_face_id
= it
->face_id
;
16492 struct glyph_row
*row
= it
->glyph_row
;
16494 /* Initialize the iterator IT for iteration over STRING beginning
16495 with index START. */
16496 reseat_to_string (it
, string
, lisp_string
, start
,
16497 precision
, field_width
, multibyte
);
16499 /* If displaying STRING, set up the face of the iterator
16500 from LISP_STRING, if that's given. */
16501 if (STRINGP (face_string
))
16507 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
16508 0, it
->region_beg_charpos
,
16509 it
->region_end_charpos
,
16510 &endptr
, it
->base_face_id
, 0);
16511 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16512 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
16515 /* Set max_x to the maximum allowed X position. Don't let it go
16516 beyond the right edge of the window. */
16518 max_x
= it
->last_visible_x
;
16520 max_x
= min (max_x
, it
->last_visible_x
);
16522 /* Skip over display elements that are not visible. because IT->w is
16524 if (it
->current_x
< it
->first_visible_x
)
16525 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
16526 MOVE_TO_POS
| MOVE_TO_X
);
16528 row
->ascent
= it
->max_ascent
;
16529 row
->height
= it
->max_ascent
+ it
->max_descent
;
16530 row
->phys_ascent
= it
->max_phys_ascent
;
16531 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16533 /* This condition is for the case that we are called with current_x
16534 past last_visible_x. */
16535 while (it
->current_x
< max_x
)
16537 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
16539 /* Get the next display element. */
16540 if (!get_next_display_element (it
))
16543 /* Produce glyphs. */
16544 x_before
= it
->current_x
;
16545 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16546 PRODUCE_GLYPHS (it
);
16548 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
16551 while (i
< nglyphs
)
16553 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16555 if (!it
->truncate_lines_p
16556 && x
+ glyph
->pixel_width
> max_x
)
16558 /* End of continued line or max_x reached. */
16559 if (CHAR_GLYPH_PADDING_P (*glyph
))
16561 /* A wide character is unbreakable. */
16562 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16563 it
->current_x
= x_before
;
16567 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16572 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
16574 /* Glyph is at least partially visible. */
16576 if (x
< it
->first_visible_x
)
16577 it
->glyph_row
->x
= x
- it
->first_visible_x
;
16581 /* Glyph is off the left margin of the display area.
16582 Should not happen. */
16586 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16587 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16588 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16589 row
->phys_height
= max (row
->phys_height
,
16590 it
->max_phys_ascent
+ it
->max_phys_descent
);
16591 x
+= glyph
->pixel_width
;
16595 /* Stop if max_x reached. */
16599 /* Stop at line ends. */
16600 if (ITERATOR_AT_END_OF_LINE_P (it
))
16602 it
->continuation_lines_width
= 0;
16606 set_iterator_to_next (it
, 1);
16608 /* Stop if truncating at the right edge. */
16609 if (it
->truncate_lines_p
16610 && it
->current_x
>= it
->last_visible_x
)
16612 /* Add truncation mark, but don't do it if the line is
16613 truncated at a padding space. */
16614 if (IT_CHARPOS (*it
) < it
->string_nchars
)
16616 if (!FRAME_WINDOW_P (it
->f
))
16620 if (it
->current_x
> it
->last_visible_x
)
16622 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16623 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16625 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16627 row
->used
[TEXT_AREA
] = i
;
16628 produce_special_glyphs (it
, IT_TRUNCATION
);
16631 produce_special_glyphs (it
, IT_TRUNCATION
);
16633 it
->glyph_row
->truncated_on_right_p
= 1;
16639 /* Maybe insert a truncation at the left. */
16640 if (it
->first_visible_x
16641 && IT_CHARPOS (*it
) > 0)
16643 if (!FRAME_WINDOW_P (it
->f
))
16644 insert_left_trunc_glyphs (it
);
16645 it
->glyph_row
->truncated_on_left_p
= 1;
16648 it
->face_id
= saved_face_id
;
16650 /* Value is number of columns displayed. */
16651 return it
->hpos
- hpos_at_start
;
16656 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
16657 appears as an element of LIST or as the car of an element of LIST.
16658 If PROPVAL is a list, compare each element against LIST in that
16659 way, and return 1/2 if any element of PROPVAL is found in LIST.
16660 Otherwise return 0. This function cannot quit.
16661 The return value is 2 if the text is invisible but with an ellipsis
16662 and 1 if it's invisible and without an ellipsis. */
16665 invisible_p (propval
, list
)
16666 register Lisp_Object propval
;
16669 register Lisp_Object tail
, proptail
;
16671 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
16673 register Lisp_Object tem
;
16675 if (EQ (propval
, tem
))
16677 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
16678 return NILP (XCDR (tem
)) ? 1 : 2;
16681 if (CONSP (propval
))
16683 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
16685 Lisp_Object propelt
;
16686 propelt
= XCAR (proptail
);
16687 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
16689 register Lisp_Object tem
;
16691 if (EQ (propelt
, tem
))
16693 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
16694 return NILP (XCDR (tem
)) ? 1 : 2;
16702 /* Calculate a width or height in pixels from a specification using
16703 the following elements:
16706 NUM - a (fractional) multiple of the default font width/height
16707 (NUM) - specifies exactly NUM pixels
16708 UNIT - a fixed number of pixels, see below.
16709 ELEMENT - size of a display element in pixels, see below.
16710 (NUM . SPEC) - equals NUM * SPEC
16711 (+ SPEC SPEC ...) - add pixel values
16712 (- SPEC SPEC ...) - subtract pixel values
16713 (- SPEC) - negate pixel value
16716 INT or FLOAT - a number constant
16717 SYMBOL - use symbol's (buffer local) variable binding.
16720 in - pixels per inch *)
16721 mm - pixels per 1/1000 meter *)
16722 cm - pixels per 1/100 meter *)
16723 width - width of current font in pixels.
16724 height - height of current font in pixels.
16726 *) using the ratio(s) defined in display-pixels-per-inch.
16730 left-fringe - left fringe width in pixels
16731 right-fringe - right fringe width in pixels
16733 left-margin - left margin width in pixels
16734 right-margin - right margin width in pixels
16736 scroll-bar - scroll-bar area width in pixels
16740 Pixels corresponding to 5 inches:
16743 Total width of non-text areas on left side of window (if scroll-bar is on left):
16744 '(space :width (+ left-fringe left-margin scroll-bar))
16746 Align to first text column (in header line):
16747 '(space :align-to 0)
16749 Align to middle of text area minus half the width of variable `my-image'
16750 containing a loaded image:
16751 '(space :align-to (0.5 . (- text my-image)))
16753 Width of left margin minus width of 1 character in the default font:
16754 '(space :width (- left-margin 1))
16756 Width of left margin minus width of 2 characters in the current font:
16757 '(space :width (- left-margin (2 . width)))
16759 Center 1 character over left-margin (in header line):
16760 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
16762 Different ways to express width of left fringe plus left margin minus one pixel:
16763 '(space :width (- (+ left-fringe left-margin) (1)))
16764 '(space :width (+ left-fringe left-margin (- (1))))
16765 '(space :width (+ left-fringe left-margin (-1)))
16769 #define NUMVAL(X) \
16770 ((INTEGERP (X) || FLOATP (X)) \
16775 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
16780 int width_p
, *align_to
;
16784 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
16785 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
16788 return OK_PIXELS (0);
16790 if (SYMBOLP (prop
))
16792 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
16794 char *unit
= SDATA (SYMBOL_NAME (prop
));
16796 if (unit
[0] == 'i' && unit
[1] == 'n')
16798 else if (unit
[0] == 'm' && unit
[1] == 'm')
16800 else if (unit
[0] == 'c' && unit
[1] == 'm')
16807 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
16808 || (CONSP (Vdisplay_pixels_per_inch
)
16810 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
16811 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
16813 return OK_PIXELS (ppi
/ pixels
);
16819 #ifdef HAVE_WINDOW_SYSTEM
16820 if (EQ (prop
, Qheight
))
16821 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
16822 if (EQ (prop
, Qwidth
))
16823 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
16825 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
16826 return OK_PIXELS (1);
16829 if (EQ (prop
, Qtext
))
16830 return OK_PIXELS (width_p
16831 ? window_box_width (it
->w
, TEXT_AREA
)
16832 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
16834 if (align_to
&& *align_to
< 0)
16837 if (EQ (prop
, Qleft
))
16838 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
16839 if (EQ (prop
, Qright
))
16840 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
16841 if (EQ (prop
, Qcenter
))
16842 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
16843 + window_box_width (it
->w
, TEXT_AREA
) / 2);
16844 if (EQ (prop
, Qleft_fringe
))
16845 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
16846 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
16847 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
16848 if (EQ (prop
, Qright_fringe
))
16849 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
16850 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
16851 : window_box_right_offset (it
->w
, TEXT_AREA
));
16852 if (EQ (prop
, Qleft_margin
))
16853 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
16854 if (EQ (prop
, Qright_margin
))
16855 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
16856 if (EQ (prop
, Qscroll_bar
))
16857 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
16859 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
16860 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
16861 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
16866 if (EQ (prop
, Qleft_fringe
))
16867 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
16868 if (EQ (prop
, Qright_fringe
))
16869 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
16870 if (EQ (prop
, Qleft_margin
))
16871 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
16872 if (EQ (prop
, Qright_margin
))
16873 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
16874 if (EQ (prop
, Qscroll_bar
))
16875 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
16878 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
16881 if (INTEGERP (prop
) || FLOATP (prop
))
16883 int base_unit
= (width_p
16884 ? FRAME_COLUMN_WIDTH (it
->f
)
16885 : FRAME_LINE_HEIGHT (it
->f
));
16886 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
16891 Lisp_Object car
= XCAR (prop
);
16892 Lisp_Object cdr
= XCDR (prop
);
16896 #ifdef HAVE_WINDOW_SYSTEM
16897 if (valid_image_p (prop
))
16899 int id
= lookup_image (it
->f
, prop
);
16900 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
16902 return OK_PIXELS (width_p
? img
->width
: img
->height
);
16905 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
16911 while (CONSP (cdr
))
16913 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
16914 font
, width_p
, align_to
))
16917 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
16922 if (EQ (car
, Qminus
))
16924 return OK_PIXELS (pixels
);
16927 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
16930 if (INTEGERP (car
) || FLOATP (car
))
16933 pixels
= XFLOATINT (car
);
16935 return OK_PIXELS (pixels
);
16936 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
16937 font
, width_p
, align_to
))
16938 return OK_PIXELS (pixels
* fact
);
16949 /***********************************************************************
16951 ***********************************************************************/
16953 #ifdef HAVE_WINDOW_SYSTEM
16958 dump_glyph_string (s
)
16959 struct glyph_string
*s
;
16961 fprintf (stderr
, "glyph string\n");
16962 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
16963 s
->x
, s
->y
, s
->width
, s
->height
);
16964 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
16965 fprintf (stderr
, " hl = %d\n", s
->hl
);
16966 fprintf (stderr
, " left overhang = %d, right = %d\n",
16967 s
->left_overhang
, s
->right_overhang
);
16968 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
16969 fprintf (stderr
, " extends to end of line = %d\n",
16970 s
->extends_to_end_of_line_p
);
16971 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
16972 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
16975 #endif /* GLYPH_DEBUG */
16977 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
16978 of XChar2b structures for S; it can't be allocated in
16979 init_glyph_string because it must be allocated via `alloca'. W
16980 is the window on which S is drawn. ROW and AREA are the glyph row
16981 and area within the row from which S is constructed. START is the
16982 index of the first glyph structure covered by S. HL is a
16983 face-override for drawing S. */
16986 #define OPTIONAL_HDC(hdc) hdc,
16987 #define DECLARE_HDC(hdc) HDC hdc;
16988 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
16989 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
16992 #ifndef OPTIONAL_HDC
16993 #define OPTIONAL_HDC(hdc)
16994 #define DECLARE_HDC(hdc)
16995 #define ALLOCATE_HDC(hdc, f)
16996 #define RELEASE_HDC(hdc, f)
17000 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
17001 struct glyph_string
*s
;
17005 struct glyph_row
*row
;
17006 enum glyph_row_area area
;
17008 enum draw_glyphs_face hl
;
17010 bzero (s
, sizeof *s
);
17012 s
->f
= XFRAME (w
->frame
);
17016 s
->display
= FRAME_X_DISPLAY (s
->f
);
17017 s
->window
= FRAME_X_WINDOW (s
->f
);
17018 s
->char2b
= char2b
;
17022 s
->first_glyph
= row
->glyphs
[area
] + start
;
17023 s
->height
= row
->height
;
17024 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
17026 /* Display the internal border below the tool-bar window. */
17027 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
17028 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
17030 s
->ybase
= s
->y
+ row
->ascent
;
17034 /* Append the list of glyph strings with head H and tail T to the list
17035 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
17038 append_glyph_string_lists (head
, tail
, h
, t
)
17039 struct glyph_string
**head
, **tail
;
17040 struct glyph_string
*h
, *t
;
17054 /* Prepend the list of glyph strings with head H and tail T to the
17055 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
17059 prepend_glyph_string_lists (head
, tail
, h
, t
)
17060 struct glyph_string
**head
, **tail
;
17061 struct glyph_string
*h
, *t
;
17075 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
17076 Set *HEAD and *TAIL to the resulting list. */
17079 append_glyph_string (head
, tail
, s
)
17080 struct glyph_string
**head
, **tail
;
17081 struct glyph_string
*s
;
17083 s
->next
= s
->prev
= NULL
;
17084 append_glyph_string_lists (head
, tail
, s
, s
);
17088 /* Get face and two-byte form of character glyph GLYPH on frame F.
17089 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
17090 a pointer to a realized face that is ready for display. */
17092 static INLINE
struct face
*
17093 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
17095 struct glyph
*glyph
;
17101 xassert (glyph
->type
== CHAR_GLYPH
);
17102 face
= FACE_FROM_ID (f
, glyph
->face_id
);
17107 if (!glyph
->multibyte_p
)
17109 /* Unibyte case. We don't have to encode, but we have to make
17110 sure to use a face suitable for unibyte. */
17111 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17113 else if (glyph
->u
.ch
< 128
17114 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
17116 /* Case of ASCII in a face known to fit ASCII. */
17117 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17121 int c1
, c2
, charset
;
17123 /* Split characters into bytes. If c2 is -1 afterwards, C is
17124 really a one-byte character so that byte1 is zero. */
17125 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
17127 STORE_XCHAR2B (char2b
, c1
, c2
);
17129 STORE_XCHAR2B (char2b
, 0, c1
);
17131 /* Maybe encode the character in *CHAR2B. */
17132 if (charset
!= CHARSET_ASCII
)
17134 struct font_info
*font_info
17135 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17138 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
17142 /* Make sure X resources of the face are allocated. */
17143 xassert (face
!= NULL
);
17144 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17149 /* Fill glyph string S with composition components specified by S->cmp.
17151 FACES is an array of faces for all components of this composition.
17152 S->gidx is the index of the first component for S.
17153 OVERLAPS_P non-zero means S should draw the foreground only, and
17154 use its physical height for clipping.
17156 Value is the index of a component not in S. */
17159 fill_composite_glyph_string (s
, faces
, overlaps_p
)
17160 struct glyph_string
*s
;
17161 struct face
**faces
;
17168 s
->for_overlaps_p
= overlaps_p
;
17170 s
->face
= faces
[s
->gidx
];
17171 s
->font
= s
->face
->font
;
17172 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17174 /* For all glyphs of this composition, starting at the offset
17175 S->gidx, until we reach the end of the definition or encounter a
17176 glyph that requires the different face, add it to S. */
17178 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
17181 /* All glyph strings for the same composition has the same width,
17182 i.e. the width set for the first component of the composition. */
17184 s
->width
= s
->first_glyph
->pixel_width
;
17186 /* If the specified font could not be loaded, use the frame's
17187 default font, but record the fact that we couldn't load it in
17188 the glyph string so that we can draw rectangles for the
17189 characters of the glyph string. */
17190 if (s
->font
== NULL
)
17192 s
->font_not_found_p
= 1;
17193 s
->font
= FRAME_FONT (s
->f
);
17196 /* Adjust base line for subscript/superscript text. */
17197 s
->ybase
+= s
->first_glyph
->voffset
;
17199 xassert (s
->face
&& s
->face
->gc
);
17201 /* This glyph string must always be drawn with 16-bit functions. */
17204 return s
->gidx
+ s
->nchars
;
17208 /* Fill glyph string S from a sequence of character glyphs.
17210 FACE_ID is the face id of the string. START is the index of the
17211 first glyph to consider, END is the index of the last + 1.
17212 OVERLAPS_P non-zero means S should draw the foreground only, and
17213 use its physical height for clipping.
17215 Value is the index of the first glyph not in S. */
17218 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
17219 struct glyph_string
*s
;
17221 int start
, end
, overlaps_p
;
17223 struct glyph
*glyph
, *last
;
17225 int glyph_not_available_p
;
17227 xassert (s
->f
== XFRAME (s
->w
->frame
));
17228 xassert (s
->nchars
== 0);
17229 xassert (start
>= 0 && end
> start
);
17231 s
->for_overlaps_p
= overlaps_p
,
17232 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17233 last
= s
->row
->glyphs
[s
->area
] + end
;
17234 voffset
= glyph
->voffset
;
17236 glyph_not_available_p
= glyph
->glyph_not_available_p
;
17238 while (glyph
< last
17239 && glyph
->type
== CHAR_GLYPH
17240 && glyph
->voffset
== voffset
17241 /* Same face id implies same font, nowadays. */
17242 && glyph
->face_id
== face_id
17243 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
17247 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
17248 s
->char2b
+ s
->nchars
,
17250 s
->two_byte_p
= two_byte_p
;
17252 xassert (s
->nchars
<= end
- start
);
17253 s
->width
+= glyph
->pixel_width
;
17257 s
->font
= s
->face
->font
;
17258 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17260 /* If the specified font could not be loaded, use the frame's font,
17261 but record the fact that we couldn't load it in
17262 S->font_not_found_p so that we can draw rectangles for the
17263 characters of the glyph string. */
17264 if (s
->font
== NULL
|| glyph_not_available_p
)
17266 s
->font_not_found_p
= 1;
17267 s
->font
= FRAME_FONT (s
->f
);
17270 /* Adjust base line for subscript/superscript text. */
17271 s
->ybase
+= voffset
;
17273 xassert (s
->face
&& s
->face
->gc
);
17274 return glyph
- s
->row
->glyphs
[s
->area
];
17278 /* Fill glyph string S from image glyph S->first_glyph. */
17281 fill_image_glyph_string (s
)
17282 struct glyph_string
*s
;
17284 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
17285 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
17287 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
17288 s
->font
= s
->face
->font
;
17289 s
->width
= s
->first_glyph
->pixel_width
;
17291 /* Adjust base line for subscript/superscript text. */
17292 s
->ybase
+= s
->first_glyph
->voffset
;
17296 /* Fill glyph string S from a sequence of stretch glyphs.
17298 ROW is the glyph row in which the glyphs are found, AREA is the
17299 area within the row. START is the index of the first glyph to
17300 consider, END is the index of the last + 1.
17302 Value is the index of the first glyph not in S. */
17305 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
17306 struct glyph_string
*s
;
17307 struct glyph_row
*row
;
17308 enum glyph_row_area area
;
17311 struct glyph
*glyph
, *last
;
17312 int voffset
, face_id
;
17314 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
17316 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17317 last
= s
->row
->glyphs
[s
->area
] + end
;
17318 face_id
= glyph
->face_id
;
17319 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
17320 s
->font
= s
->face
->font
;
17321 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17322 s
->width
= glyph
->pixel_width
;
17323 voffset
= glyph
->voffset
;
17327 && glyph
->type
== STRETCH_GLYPH
17328 && glyph
->voffset
== voffset
17329 && glyph
->face_id
== face_id
);
17331 s
->width
+= glyph
->pixel_width
;
17333 /* Adjust base line for subscript/superscript text. */
17334 s
->ybase
+= voffset
;
17336 /* The case that face->gc == 0 is handled when drawing the glyph
17337 string by calling PREPARE_FACE_FOR_DISPLAY. */
17339 return glyph
- s
->row
->glyphs
[s
->area
];
17344 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
17345 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
17346 assumed to be zero. */
17349 x_get_glyph_overhangs (glyph
, f
, left
, right
)
17350 struct glyph
*glyph
;
17354 *left
= *right
= 0;
17356 if (glyph
->type
== CHAR_GLYPH
)
17360 struct font_info
*font_info
;
17364 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
17366 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17367 if (font
/* ++KFS: Should this be font_info ? */
17368 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
17370 if (pcm
->rbearing
> pcm
->width
)
17371 *right
= pcm
->rbearing
- pcm
->width
;
17372 if (pcm
->lbearing
< 0)
17373 *left
= -pcm
->lbearing
;
17379 /* Return the index of the first glyph preceding glyph string S that
17380 is overwritten by S because of S's left overhang. Value is -1
17381 if no glyphs are overwritten. */
17384 left_overwritten (s
)
17385 struct glyph_string
*s
;
17389 if (s
->left_overhang
)
17392 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17393 int first
= s
->first_glyph
- glyphs
;
17395 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
17396 x
-= glyphs
[i
].pixel_width
;
17407 /* Return the index of the first glyph preceding glyph string S that
17408 is overwriting S because of its right overhang. Value is -1 if no
17409 glyph in front of S overwrites S. */
17412 left_overwriting (s
)
17413 struct glyph_string
*s
;
17416 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17417 int first
= s
->first_glyph
- glyphs
;
17421 for (i
= first
- 1; i
>= 0; --i
)
17424 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17427 x
-= glyphs
[i
].pixel_width
;
17434 /* Return the index of the last glyph following glyph string S that is
17435 not overwritten by S because of S's right overhang. Value is -1 if
17436 no such glyph is found. */
17439 right_overwritten (s
)
17440 struct glyph_string
*s
;
17444 if (s
->right_overhang
)
17447 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17448 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17449 int end
= s
->row
->used
[s
->area
];
17451 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
17452 x
+= glyphs
[i
].pixel_width
;
17461 /* Return the index of the last glyph following glyph string S that
17462 overwrites S because of its left overhang. Value is negative
17463 if no such glyph is found. */
17466 right_overwriting (s
)
17467 struct glyph_string
*s
;
17470 int end
= s
->row
->used
[s
->area
];
17471 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17472 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17476 for (i
= first
; i
< end
; ++i
)
17479 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17482 x
+= glyphs
[i
].pixel_width
;
17489 /* Get face and two-byte form of character C in face FACE_ID on frame
17490 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
17491 means we want to display multibyte text. DISPLAY_P non-zero means
17492 make sure that X resources for the face returned are allocated.
17493 Value is a pointer to a realized face that is ready for display if
17494 DISPLAY_P is non-zero. */
17496 static INLINE
struct face
*
17497 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
17501 int multibyte_p
, display_p
;
17503 struct face
*face
= FACE_FROM_ID (f
, face_id
);
17507 /* Unibyte case. We don't have to encode, but we have to make
17508 sure to use a face suitable for unibyte. */
17509 STORE_XCHAR2B (char2b
, 0, c
);
17510 face_id
= FACE_FOR_CHAR (f
, face
, c
);
17511 face
= FACE_FROM_ID (f
, face_id
);
17513 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
17515 /* Case of ASCII in a face known to fit ASCII. */
17516 STORE_XCHAR2B (char2b
, 0, c
);
17520 int c1
, c2
, charset
;
17522 /* Split characters into bytes. If c2 is -1 afterwards, C is
17523 really a one-byte character so that byte1 is zero. */
17524 SPLIT_CHAR (c
, charset
, c1
, c2
);
17526 STORE_XCHAR2B (char2b
, c1
, c2
);
17528 STORE_XCHAR2B (char2b
, 0, c1
);
17530 /* Maybe encode the character in *CHAR2B. */
17531 if (face
->font
!= NULL
)
17533 struct font_info
*font_info
17534 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17536 rif
->encode_char (c
, char2b
, font_info
, 0);
17540 /* Make sure X resources of the face are allocated. */
17541 #ifdef HAVE_X_WINDOWS
17545 xassert (face
!= NULL
);
17546 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17553 /* Set background width of glyph string S. START is the index of the
17554 first glyph following S. LAST_X is the right-most x-position + 1
17555 in the drawing area. */
17558 set_glyph_string_background_width (s
, start
, last_x
)
17559 struct glyph_string
*s
;
17563 /* If the face of this glyph string has to be drawn to the end of
17564 the drawing area, set S->extends_to_end_of_line_p. */
17565 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
17567 if (start
== s
->row
->used
[s
->area
]
17568 && s
->area
== TEXT_AREA
17569 && ((s
->hl
== DRAW_NORMAL_TEXT
17570 && (s
->row
->fill_line_p
17571 || s
->face
->background
!= default_face
->background
17572 || s
->face
->stipple
!= default_face
->stipple
17573 || s
->row
->mouse_face_p
))
17574 || s
->hl
== DRAW_MOUSE_FACE
17575 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
17576 && s
->row
->fill_line_p
)))
17577 s
->extends_to_end_of_line_p
= 1;
17579 /* If S extends its face to the end of the line, set its
17580 background_width to the distance to the right edge of the drawing
17582 if (s
->extends_to_end_of_line_p
)
17583 s
->background_width
= last_x
- s
->x
+ 1;
17585 s
->background_width
= s
->width
;
17589 /* Compute overhangs and x-positions for glyph string S and its
17590 predecessors, or successors. X is the starting x-position for S.
17591 BACKWARD_P non-zero means process predecessors. */
17594 compute_overhangs_and_x (s
, x
, backward_p
)
17595 struct glyph_string
*s
;
17603 if (rif
->compute_glyph_string_overhangs
)
17604 rif
->compute_glyph_string_overhangs (s
);
17614 if (rif
->compute_glyph_string_overhangs
)
17615 rif
->compute_glyph_string_overhangs (s
);
17625 /* The following macros are only called from draw_glyphs below.
17626 They reference the following parameters of that function directly:
17627 `w', `row', `area', and `overlap_p'
17628 as well as the following local variables:
17629 `s', `f', and `hdc' (in W32) */
17632 /* On W32, silently add local `hdc' variable to argument list of
17633 init_glyph_string. */
17634 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17635 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
17637 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17638 init_glyph_string (s, char2b, w, row, area, start, hl)
17641 /* Add a glyph string for a stretch glyph to the list of strings
17642 between HEAD and TAIL. START is the index of the stretch glyph in
17643 row area AREA of glyph row ROW. END is the index of the last glyph
17644 in that glyph row area. X is the current output position assigned
17645 to the new glyph string constructed. HL overrides that face of the
17646 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17647 is the right-most x-position of the drawing area. */
17649 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
17650 and below -- keep them on one line. */
17651 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17654 s = (struct glyph_string *) alloca (sizeof *s); \
17655 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17656 START = fill_stretch_glyph_string (s, row, area, START, END); \
17657 append_glyph_string (&HEAD, &TAIL, s); \
17663 /* Add a glyph string for an image glyph to the list of strings
17664 between HEAD and TAIL. START is the index of the image glyph in
17665 row area AREA of glyph row ROW. END is the index of the last glyph
17666 in that glyph row area. X is the current output position assigned
17667 to the new glyph string constructed. HL overrides that face of the
17668 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17669 is the right-most x-position of the drawing area. */
17671 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17674 s = (struct glyph_string *) alloca (sizeof *s); \
17675 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17676 fill_image_glyph_string (s); \
17677 append_glyph_string (&HEAD, &TAIL, s); \
17684 /* Add a glyph string for a sequence of character glyphs to the list
17685 of strings between HEAD and TAIL. START is the index of the first
17686 glyph in row area AREA of glyph row ROW that is part of the new
17687 glyph string. END is the index of the last glyph in that glyph row
17688 area. X is the current output position assigned to the new glyph
17689 string constructed. HL overrides that face of the glyph; e.g. it
17690 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
17691 right-most x-position of the drawing area. */
17693 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
17699 c = (row)->glyphs[area][START].u.ch; \
17700 face_id = (row)->glyphs[area][START].face_id; \
17702 s = (struct glyph_string *) alloca (sizeof *s); \
17703 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
17704 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
17705 append_glyph_string (&HEAD, &TAIL, s); \
17707 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
17712 /* Add a glyph string for a composite sequence to the list of strings
17713 between HEAD and TAIL. START is the index of the first glyph in
17714 row area AREA of glyph row ROW that is part of the new glyph
17715 string. END is the index of the last glyph in that glyph row area.
17716 X is the current output position assigned to the new glyph string
17717 constructed. HL overrides that face of the glyph; e.g. it is
17718 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
17719 x-position of the drawing area. */
17721 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17723 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
17724 int face_id = (row)->glyphs[area][START].face_id; \
17725 struct face *base_face = FACE_FROM_ID (f, face_id); \
17726 struct composition *cmp = composition_table[cmp_id]; \
17727 int glyph_len = cmp->glyph_len; \
17729 struct face **faces; \
17730 struct glyph_string *first_s = NULL; \
17733 base_face = base_face->ascii_face; \
17734 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
17735 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
17736 /* At first, fill in `char2b' and `faces'. */ \
17737 for (n = 0; n < glyph_len; n++) \
17739 int c = COMPOSITION_GLYPH (cmp, n); \
17740 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
17741 faces[n] = FACE_FROM_ID (f, this_face_id); \
17742 get_char_face_and_encoding (f, c, this_face_id, \
17743 char2b + n, 1, 1); \
17746 /* Make glyph_strings for each glyph sequence that is drawable by \
17747 the same face, and append them to HEAD/TAIL. */ \
17748 for (n = 0; n < cmp->glyph_len;) \
17750 s = (struct glyph_string *) alloca (sizeof *s); \
17751 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
17752 append_glyph_string (&(HEAD), &(TAIL), s); \
17760 n = fill_composite_glyph_string (s, faces, overlaps_p); \
17768 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
17769 of AREA of glyph row ROW on window W between indices START and END.
17770 HL overrides the face for drawing glyph strings, e.g. it is
17771 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
17772 x-positions of the drawing area.
17774 This is an ugly monster macro construct because we must use alloca
17775 to allocate glyph strings (because draw_glyphs can be called
17776 asynchronously). */
17778 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
17781 HEAD = TAIL = NULL; \
17782 while (START < END) \
17784 struct glyph *first_glyph = (row)->glyphs[area] + START; \
17785 switch (first_glyph->type) \
17788 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
17792 case COMPOSITE_GLYPH: \
17793 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
17797 case STRETCH_GLYPH: \
17798 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
17802 case IMAGE_GLYPH: \
17803 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
17811 set_glyph_string_background_width (s, START, LAST_X); \
17818 /* Draw glyphs between START and END in AREA of ROW on window W,
17819 starting at x-position X. X is relative to AREA in W. HL is a
17820 face-override with the following meaning:
17822 DRAW_NORMAL_TEXT draw normally
17823 DRAW_CURSOR draw in cursor face
17824 DRAW_MOUSE_FACE draw in mouse face.
17825 DRAW_INVERSE_VIDEO draw in mode line face
17826 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
17827 DRAW_IMAGE_RAISED draw an image with a raised relief around it
17829 If OVERLAPS_P is non-zero, draw only the foreground of characters
17830 and clip to the physical height of ROW.
17832 Value is the x-position reached, relative to AREA of W. */
17835 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
17838 struct glyph_row
*row
;
17839 enum glyph_row_area area
;
17841 enum draw_glyphs_face hl
;
17844 struct glyph_string
*head
, *tail
;
17845 struct glyph_string
*s
;
17846 int last_x
, area_width
;
17849 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17852 ALLOCATE_HDC (hdc
, f
);
17854 /* Let's rather be paranoid than getting a SEGV. */
17855 end
= min (end
, row
->used
[area
]);
17856 start
= max (0, start
);
17857 start
= min (end
, start
);
17859 /* Translate X to frame coordinates. Set last_x to the right
17860 end of the drawing area. */
17861 if (row
->full_width_p
)
17863 /* X is relative to the left edge of W, without scroll bars
17865 x
+= WINDOW_LEFT_EDGE_X (w
);
17866 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
17870 int area_left
= window_box_left (w
, area
);
17872 area_width
= window_box_width (w
, area
);
17873 last_x
= area_left
+ area_width
;
17876 /* Build a doubly-linked list of glyph_string structures between
17877 head and tail from what we have to draw. Note that the macro
17878 BUILD_GLYPH_STRINGS will modify its start parameter. That's
17879 the reason we use a separate variable `i'. */
17881 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
17883 x_reached
= tail
->x
+ tail
->background_width
;
17887 /* If there are any glyphs with lbearing < 0 or rbearing > width in
17888 the row, redraw some glyphs in front or following the glyph
17889 strings built above. */
17890 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
17893 struct glyph_string
*h
, *t
;
17895 /* Compute overhangs for all glyph strings. */
17896 if (rif
->compute_glyph_string_overhangs
)
17897 for (s
= head
; s
; s
= s
->next
)
17898 rif
->compute_glyph_string_overhangs (s
);
17900 /* Prepend glyph strings for glyphs in front of the first glyph
17901 string that are overwritten because of the first glyph
17902 string's left overhang. The background of all strings
17903 prepended must be drawn because the first glyph string
17905 i
= left_overwritten (head
);
17909 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
17910 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
17912 compute_overhangs_and_x (t
, head
->x
, 1);
17913 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
17916 /* Prepend glyph strings for glyphs in front of the first glyph
17917 string that overwrite that glyph string because of their
17918 right overhang. For these strings, only the foreground must
17919 be drawn, because it draws over the glyph string at `head'.
17920 The background must not be drawn because this would overwrite
17921 right overhangs of preceding glyphs for which no glyph
17923 i
= left_overwriting (head
);
17926 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
17927 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
17928 for (s
= h
; s
; s
= s
->next
)
17929 s
->background_filled_p
= 1;
17930 compute_overhangs_and_x (t
, head
->x
, 1);
17931 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
17934 /* Append glyphs strings for glyphs following the last glyph
17935 string tail that are overwritten by tail. The background of
17936 these strings has to be drawn because tail's foreground draws
17938 i
= right_overwritten (tail
);
17941 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
17942 DRAW_NORMAL_TEXT
, x
, last_x
);
17943 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
17944 append_glyph_string_lists (&head
, &tail
, h
, t
);
17947 /* Append glyph strings for glyphs following the last glyph
17948 string tail that overwrite tail. The foreground of such
17949 glyphs has to be drawn because it writes into the background
17950 of tail. The background must not be drawn because it could
17951 paint over the foreground of following glyphs. */
17952 i
= right_overwriting (tail
);
17955 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
17956 DRAW_NORMAL_TEXT
, x
, last_x
);
17957 for (s
= h
; s
; s
= s
->next
)
17958 s
->background_filled_p
= 1;
17959 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
17960 append_glyph_string_lists (&head
, &tail
, h
, t
);
17964 /* Draw all strings. */
17965 for (s
= head
; s
; s
= s
->next
)
17966 rif
->draw_glyph_string (s
);
17968 if (area
== TEXT_AREA
17969 && !row
->full_width_p
17970 /* When drawing overlapping rows, only the glyph strings'
17971 foreground is drawn, which doesn't erase a cursor
17975 int x0
= head
? head
->x
: x
;
17976 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
17978 int text_left
= window_box_left (w
, TEXT_AREA
);
17982 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
17983 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
17986 /* Value is the x-position up to which drawn, relative to AREA of W.
17987 This doesn't include parts drawn because of overhangs. */
17988 if (row
->full_width_p
)
17989 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
17991 x_reached
-= window_box_left (w
, area
);
17993 RELEASE_HDC (hdc
, f
);
17999 /* Store one glyph for IT->char_to_display in IT->glyph_row.
18000 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18006 struct glyph
*glyph
;
18007 enum glyph_row_area area
= it
->area
;
18009 xassert (it
->glyph_row
);
18010 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
18012 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18013 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18015 glyph
->charpos
= CHARPOS (it
->position
);
18016 glyph
->object
= it
->object
;
18017 glyph
->pixel_width
= it
->pixel_width
;
18018 glyph
->ascent
= it
->ascent
;
18019 glyph
->descent
= it
->descent
;
18020 glyph
->voffset
= it
->voffset
;
18021 glyph
->type
= CHAR_GLYPH
;
18022 glyph
->multibyte_p
= it
->multibyte_p
;
18023 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18024 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18025 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18026 || it
->phys_descent
> it
->descent
);
18027 glyph
->padding_p
= 0;
18028 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
18029 glyph
->face_id
= it
->face_id
;
18030 glyph
->u
.ch
= it
->char_to_display
;
18031 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18032 ++it
->glyph_row
->used
[area
];
18036 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
18037 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18040 append_composite_glyph (it
)
18043 struct glyph
*glyph
;
18044 enum glyph_row_area area
= it
->area
;
18046 xassert (it
->glyph_row
);
18048 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18049 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18051 glyph
->charpos
= CHARPOS (it
->position
);
18052 glyph
->object
= it
->object
;
18053 glyph
->pixel_width
= it
->pixel_width
;
18054 glyph
->ascent
= it
->ascent
;
18055 glyph
->descent
= it
->descent
;
18056 glyph
->voffset
= it
->voffset
;
18057 glyph
->type
= COMPOSITE_GLYPH
;
18058 glyph
->multibyte_p
= it
->multibyte_p
;
18059 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18060 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18061 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18062 || it
->phys_descent
> it
->descent
);
18063 glyph
->padding_p
= 0;
18064 glyph
->glyph_not_available_p
= 0;
18065 glyph
->face_id
= it
->face_id
;
18066 glyph
->u
.cmp_id
= it
->cmp_id
;
18067 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18068 ++it
->glyph_row
->used
[area
];
18073 /* Change IT->ascent and IT->height according to the setting of
18077 take_vertical_position_into_account (it
)
18082 if (it
->voffset
< 0)
18083 /* Increase the ascent so that we can display the text higher
18085 it
->ascent
+= abs (it
->voffset
);
18087 /* Increase the descent so that we can display the text lower
18089 it
->descent
+= it
->voffset
;
18094 /* Produce glyphs/get display metrics for the image IT is loaded with.
18095 See the description of struct display_iterator in dispextern.h for
18096 an overview of struct display_iterator. */
18099 produce_image_glyph (it
)
18104 int face_ascent
, glyph_ascent
;
18106 xassert (it
->what
== IT_IMAGE
);
18108 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18110 /* Make sure X resources of the face is loaded. */
18111 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18113 if (it
->image_id
< 0)
18115 /* Fringe bitmap. */
18116 it
->ascent
= it
->phys_ascent
= 0;
18117 it
->descent
= it
->phys_descent
= 0;
18118 it
->pixel_width
= 0;
18123 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
18125 /* Make sure X resources of the image is loaded. */
18126 prepare_image_for_display (it
->f
, img
);
18128 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
);
18129 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
18130 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
18132 /* It's quite possible for images to have an ascent greater than
18133 their height, so don't get confused in that case. */
18134 if (it
->descent
< 0)
18137 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
18138 face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
18139 if (face_ascent
> it
->ascent
)
18140 it
->ascent
= it
->phys_ascent
= face_ascent
;
18144 if (face
->box
!= FACE_NO_BOX
)
18146 if (face
->box_line_width
> 0)
18148 it
->ascent
+= face
->box_line_width
;
18149 it
->descent
+= face
->box_line_width
;
18152 if (it
->start_of_box_run_p
)
18153 it
->pixel_width
+= abs (face
->box_line_width
);
18154 if (it
->end_of_box_run_p
)
18155 it
->pixel_width
+= abs (face
->box_line_width
);
18158 take_vertical_position_into_account (it
);
18162 struct glyph
*glyph
;
18163 enum glyph_row_area area
= it
->area
;
18165 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18166 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18168 glyph
->charpos
= CHARPOS (it
->position
);
18169 glyph
->object
= it
->object
;
18170 glyph
->pixel_width
= it
->pixel_width
;
18171 glyph
->ascent
= glyph_ascent
;
18172 glyph
->descent
= it
->descent
;
18173 glyph
->voffset
= it
->voffset
;
18174 glyph
->type
= IMAGE_GLYPH
;
18175 glyph
->multibyte_p
= it
->multibyte_p
;
18176 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18177 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18178 glyph
->overlaps_vertically_p
= 0;
18179 glyph
->padding_p
= 0;
18180 glyph
->glyph_not_available_p
= 0;
18181 glyph
->face_id
= it
->face_id
;
18182 glyph
->u
.img_id
= img
->id
;
18183 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18184 ++it
->glyph_row
->used
[area
];
18190 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
18191 of the glyph, WIDTH and HEIGHT are the width and height of the
18192 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
18195 append_stretch_glyph (it
, object
, width
, height
, ascent
)
18197 Lisp_Object object
;
18201 struct glyph
*glyph
;
18202 enum glyph_row_area area
= it
->area
;
18204 xassert (ascent
>= 0 && ascent
<= height
);
18206 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18207 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18209 glyph
->charpos
= CHARPOS (it
->position
);
18210 glyph
->object
= object
;
18211 glyph
->pixel_width
= width
;
18212 glyph
->ascent
= ascent
;
18213 glyph
->descent
= height
- ascent
;
18214 glyph
->voffset
= it
->voffset
;
18215 glyph
->type
= STRETCH_GLYPH
;
18216 glyph
->multibyte_p
= it
->multibyte_p
;
18217 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18218 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18219 glyph
->overlaps_vertically_p
= 0;
18220 glyph
->padding_p
= 0;
18221 glyph
->glyph_not_available_p
= 0;
18222 glyph
->face_id
= it
->face_id
;
18223 glyph
->u
.stretch
.ascent
= ascent
;
18224 glyph
->u
.stretch
.height
= height
;
18225 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18226 ++it
->glyph_row
->used
[area
];
18231 /* Produce a stretch glyph for iterator IT. IT->object is the value
18232 of the glyph property displayed. The value must be a list
18233 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
18236 1. `:width WIDTH' specifies that the space should be WIDTH *
18237 canonical char width wide. WIDTH may be an integer or floating
18240 2. `:relative-width FACTOR' specifies that the width of the stretch
18241 should be computed from the width of the first character having the
18242 `glyph' property, and should be FACTOR times that width.
18244 3. `:align-to HPOS' specifies that the space should be wide enough
18245 to reach HPOS, a value in canonical character units.
18247 Exactly one of the above pairs must be present.
18249 4. `:height HEIGHT' specifies that the height of the stretch produced
18250 should be HEIGHT, measured in canonical character units.
18252 5. `:relative-height FACTOR' specifies that the height of the
18253 stretch should be FACTOR times the height of the characters having
18254 the glyph property.
18256 Either none or exactly one of 4 or 5 must be present.
18258 6. `:ascent ASCENT' specifies that ASCENT percent of the height
18259 of the stretch should be used for the ascent of the stretch.
18260 ASCENT must be in the range 0 <= ASCENT <= 100. */
18263 produce_stretch_glyph (it
)
18266 /* (space :width WIDTH :height HEIGHT ...) */
18267 Lisp_Object prop
, plist
;
18268 int width
= 0, height
= 0, align_to
= -1;
18269 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
18272 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18273 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
18275 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18277 /* List should start with `space'. */
18278 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
18279 plist
= XCDR (it
->object
);
18281 /* Compute the width of the stretch. */
18282 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
18283 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
18285 /* Absolute width `:width WIDTH' specified and valid. */
18286 zero_width_ok_p
= 1;
18289 else if (prop
= Fplist_get (plist
, QCrelative_width
),
18292 /* Relative width `:relative-width FACTOR' specified and valid.
18293 Compute the width of the characters having the `glyph'
18296 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
18299 if (it
->multibyte_p
)
18301 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
18302 - IT_BYTEPOS (*it
));
18303 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
18306 it2
.c
= *p
, it2
.len
= 1;
18308 it2
.glyph_row
= NULL
;
18309 it2
.what
= IT_CHARACTER
;
18310 x_produce_glyphs (&it2
);
18311 width
= NUMVAL (prop
) * it2
.pixel_width
;
18313 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
18314 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
18316 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
18317 align_to
= (align_to
< 0
18319 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
18320 else if (align_to
< 0)
18321 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
18322 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
18323 zero_width_ok_p
= 1;
18326 /* Nothing specified -> width defaults to canonical char width. */
18327 width
= FRAME_COLUMN_WIDTH (it
->f
);
18329 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
18332 /* Compute height. */
18333 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
18334 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
18337 zero_height_ok_p
= 1;
18339 else if (prop
= Fplist_get (plist
, QCrelative_height
),
18341 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
18343 height
= FONT_HEIGHT (font
);
18345 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
18348 /* Compute percentage of height used for ascent. If
18349 `:ascent ASCENT' is present and valid, use that. Otherwise,
18350 derive the ascent from the font in use. */
18351 if (prop
= Fplist_get (plist
, QCascent
),
18352 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
18353 ascent
= height
* NUMVAL (prop
) / 100.0;
18354 else if (!NILP (prop
)
18355 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
18356 ascent
= min (max (0, (int)tem
), height
);
18358 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
18360 if (width
> 0 && height
> 0 && it
->glyph_row
)
18362 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
18363 if (!STRINGP (object
))
18364 object
= it
->w
->buffer
;
18365 append_stretch_glyph (it
, object
, width
, height
, ascent
);
18368 it
->pixel_width
= width
;
18369 it
->ascent
= it
->phys_ascent
= ascent
;
18370 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
18371 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
18373 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
18375 if (face
->box_line_width
> 0)
18377 it
->ascent
+= face
->box_line_width
;
18378 it
->descent
+= face
->box_line_width
;
18381 if (it
->start_of_box_run_p
)
18382 it
->pixel_width
+= abs (face
->box_line_width
);
18383 if (it
->end_of_box_run_p
)
18384 it
->pixel_width
+= abs (face
->box_line_width
);
18387 take_vertical_position_into_account (it
);
18391 Produce glyphs/get display metrics for the display element IT is
18392 loaded with. See the description of struct display_iterator in
18393 dispextern.h for an overview of struct display_iterator. */
18396 x_produce_glyphs (it
)
18399 it
->glyph_not_available_p
= 0;
18401 if (it
->what
== IT_CHARACTER
)
18405 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18407 int font_not_found_p
;
18408 struct font_info
*font_info
;
18409 int boff
; /* baseline offset */
18410 /* We may change it->multibyte_p upon unibyte<->multibyte
18411 conversion. So, save the current value now and restore it
18414 Note: It seems that we don't have to record multibyte_p in
18415 struct glyph because the character code itself tells if or
18416 not the character is multibyte. Thus, in the future, we must
18417 consider eliminating the field `multibyte_p' in the struct
18419 int saved_multibyte_p
= it
->multibyte_p
;
18421 /* Maybe translate single-byte characters to multibyte, or the
18423 it
->char_to_display
= it
->c
;
18424 if (!ASCII_BYTE_P (it
->c
))
18426 if (unibyte_display_via_language_environment
18427 && SINGLE_BYTE_CHAR_P (it
->c
)
18429 || !NILP (Vnonascii_translation_table
)))
18431 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
18432 it
->multibyte_p
= 1;
18433 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18434 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18436 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
18437 && !it
->multibyte_p
)
18439 it
->multibyte_p
= 1;
18440 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18441 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18445 /* Get font to use. Encode IT->char_to_display. */
18446 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
18447 &char2b
, it
->multibyte_p
, 0);
18450 /* When no suitable font found, use the default font. */
18451 font_not_found_p
= font
== NULL
;
18452 if (font_not_found_p
)
18454 font
= FRAME_FONT (it
->f
);
18455 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18460 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18461 boff
= font_info
->baseline_offset
;
18462 if (font_info
->vertical_centering
)
18463 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18466 if (it
->char_to_display
>= ' '
18467 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
18469 /* Either unibyte or ASCII. */
18474 pcm
= rif
->per_char_metric (font
, &char2b
,
18475 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
18476 it
->ascent
= FONT_BASE (font
) + boff
;
18477 it
->descent
= FONT_DESCENT (font
) - boff
;
18481 it
->phys_ascent
= pcm
->ascent
+ boff
;
18482 it
->phys_descent
= pcm
->descent
- boff
;
18483 it
->pixel_width
= pcm
->width
;
18487 it
->glyph_not_available_p
= 1;
18488 it
->phys_ascent
= FONT_BASE (font
) + boff
;
18489 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18490 it
->pixel_width
= FONT_WIDTH (font
);
18493 /* If this is a space inside a region of text with
18494 `space-width' property, change its width. */
18495 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
18497 it
->pixel_width
*= XFLOATINT (it
->space_width
);
18499 /* If face has a box, add the box thickness to the character
18500 height. If character has a box line to the left and/or
18501 right, add the box line width to the character's width. */
18502 if (face
->box
!= FACE_NO_BOX
)
18504 int thick
= face
->box_line_width
;
18508 it
->ascent
+= thick
;
18509 it
->descent
+= thick
;
18514 if (it
->start_of_box_run_p
)
18515 it
->pixel_width
+= thick
;
18516 if (it
->end_of_box_run_p
)
18517 it
->pixel_width
+= thick
;
18520 /* If face has an overline, add the height of the overline
18521 (1 pixel) and a 1 pixel margin to the character height. */
18522 if (face
->overline_p
)
18525 take_vertical_position_into_account (it
);
18527 /* If we have to actually produce glyphs, do it. */
18532 /* Translate a space with a `space-width' property
18533 into a stretch glyph. */
18534 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
18535 / FONT_HEIGHT (font
));
18536 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
18537 it
->ascent
+ it
->descent
, ascent
);
18542 /* If characters with lbearing or rbearing are displayed
18543 in this line, record that fact in a flag of the
18544 glyph row. This is used to optimize X output code. */
18545 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
18546 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
18549 else if (it
->char_to_display
== '\n')
18551 /* A newline has no width but we need the height of the line. */
18552 it
->pixel_width
= 0;
18554 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
18555 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18557 if (face
->box
!= FACE_NO_BOX
18558 && face
->box_line_width
> 0)
18560 it
->ascent
+= face
->box_line_width
;
18561 it
->descent
+= face
->box_line_width
;
18564 else if (it
->char_to_display
== '\t')
18566 int tab_width
= it
->tab_width
* FRAME_COLUMN_WIDTH (it
->f
);
18567 int x
= it
->current_x
+ it
->continuation_lines_width
;
18568 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
18570 /* If the distance from the current position to the next tab
18571 stop is less than a canonical character width, use the
18572 tab stop after that. */
18573 if (next_tab_x
- x
< FRAME_COLUMN_WIDTH (it
->f
))
18574 next_tab_x
+= tab_width
;
18576 it
->pixel_width
= next_tab_x
- x
;
18578 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
18579 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18583 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
18584 it
->ascent
+ it
->descent
, it
->ascent
);
18589 /* A multi-byte character. Assume that the display width of the
18590 character is the width of the character multiplied by the
18591 width of the font. */
18593 /* If we found a font, this font should give us the right
18594 metrics. If we didn't find a font, use the frame's
18595 default font and calculate the width of the character
18596 from the charset width; this is what old redisplay code
18599 pcm
= rif
->per_char_metric (font
, &char2b
,
18600 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
18602 if (font_not_found_p
|| !pcm
)
18604 int charset
= CHAR_CHARSET (it
->char_to_display
);
18606 it
->glyph_not_available_p
= 1;
18607 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
18608 * CHARSET_WIDTH (charset
));
18609 it
->phys_ascent
= FONT_BASE (font
) + boff
;
18610 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18614 it
->pixel_width
= pcm
->width
;
18615 it
->phys_ascent
= pcm
->ascent
+ boff
;
18616 it
->phys_descent
= pcm
->descent
- boff
;
18618 && (pcm
->lbearing
< 0
18619 || pcm
->rbearing
> pcm
->width
))
18620 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
18623 it
->ascent
= FONT_BASE (font
) + boff
;
18624 it
->descent
= FONT_DESCENT (font
) - boff
;
18625 if (face
->box
!= FACE_NO_BOX
)
18627 int thick
= face
->box_line_width
;
18631 it
->ascent
+= thick
;
18632 it
->descent
+= thick
;
18637 if (it
->start_of_box_run_p
)
18638 it
->pixel_width
+= thick
;
18639 if (it
->end_of_box_run_p
)
18640 it
->pixel_width
+= thick
;
18643 /* If face has an overline, add the height of the overline
18644 (1 pixel) and a 1 pixel margin to the character height. */
18645 if (face
->overline_p
)
18648 take_vertical_position_into_account (it
);
18653 it
->multibyte_p
= saved_multibyte_p
;
18655 else if (it
->what
== IT_COMPOSITION
)
18657 /* Note: A composition is represented as one glyph in the
18658 glyph matrix. There are no padding glyphs. */
18661 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18663 int font_not_found_p
;
18664 struct font_info
*font_info
;
18665 int boff
; /* baseline offset */
18666 struct composition
*cmp
= composition_table
[it
->cmp_id
];
18668 /* Maybe translate single-byte characters to multibyte. */
18669 it
->char_to_display
= it
->c
;
18670 if (unibyte_display_via_language_environment
18671 && SINGLE_BYTE_CHAR_P (it
->c
)
18674 && !NILP (Vnonascii_translation_table
))))
18676 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
18679 /* Get face and font to use. Encode IT->char_to_display. */
18680 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18681 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18682 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
18683 &char2b
, it
->multibyte_p
, 0);
18686 /* When no suitable font found, use the default font. */
18687 font_not_found_p
= font
== NULL
;
18688 if (font_not_found_p
)
18690 font
= FRAME_FONT (it
->f
);
18691 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18696 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18697 boff
= font_info
->baseline_offset
;
18698 if (font_info
->vertical_centering
)
18699 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18702 /* There are no padding glyphs, so there is only one glyph to
18703 produce for the composition. Important is that pixel_width,
18704 ascent and descent are the values of what is drawn by
18705 draw_glyphs (i.e. the values of the overall glyphs composed). */
18708 /* If we have not yet calculated pixel size data of glyphs of
18709 the composition for the current face font, calculate them
18710 now. Theoretically, we have to check all fonts for the
18711 glyphs, but that requires much time and memory space. So,
18712 here we check only the font of the first glyph. This leads
18713 to incorrect display very rarely, and C-l (recenter) can
18714 correct the display anyway. */
18715 if (cmp
->font
!= (void *) font
)
18717 /* Ascent and descent of the font of the first character of
18718 this composition (adjusted by baseline offset). Ascent
18719 and descent of overall glyphs should not be less than
18720 them respectively. */
18721 int font_ascent
= FONT_BASE (font
) + boff
;
18722 int font_descent
= FONT_DESCENT (font
) - boff
;
18723 /* Bounding box of the overall glyphs. */
18724 int leftmost
, rightmost
, lowest
, highest
;
18725 int i
, width
, ascent
, descent
;
18727 cmp
->font
= (void *) font
;
18729 /* Initialize the bounding box. */
18731 && (pcm
= rif
->per_char_metric (font
, &char2b
,
18732 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
18734 width
= pcm
->width
;
18735 ascent
= pcm
->ascent
;
18736 descent
= pcm
->descent
;
18740 width
= FONT_WIDTH (font
);
18741 ascent
= FONT_BASE (font
);
18742 descent
= FONT_DESCENT (font
);
18746 lowest
= - descent
+ boff
;
18747 highest
= ascent
+ boff
;
18751 && font_info
->default_ascent
18752 && CHAR_TABLE_P (Vuse_default_ascent
)
18753 && !NILP (Faref (Vuse_default_ascent
,
18754 make_number (it
->char_to_display
))))
18755 highest
= font_info
->default_ascent
+ boff
;
18757 /* Draw the first glyph at the normal position. It may be
18758 shifted to right later if some other glyphs are drawn at
18760 cmp
->offsets
[0] = 0;
18761 cmp
->offsets
[1] = boff
;
18763 /* Set cmp->offsets for the remaining glyphs. */
18764 for (i
= 1; i
< cmp
->glyph_len
; i
++)
18766 int left
, right
, btm
, top
;
18767 int ch
= COMPOSITION_GLYPH (cmp
, i
);
18768 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
18770 face
= FACE_FROM_ID (it
->f
, face_id
);
18771 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
18772 &char2b
, it
->multibyte_p
, 0);
18776 font
= FRAME_FONT (it
->f
);
18777 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18783 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18784 boff
= font_info
->baseline_offset
;
18785 if (font_info
->vertical_centering
)
18786 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18790 && (pcm
= rif
->per_char_metric (font
, &char2b
,
18791 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
18793 width
= pcm
->width
;
18794 ascent
= pcm
->ascent
;
18795 descent
= pcm
->descent
;
18799 width
= FONT_WIDTH (font
);
18804 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
18806 /* Relative composition with or without
18807 alternate chars. */
18808 left
= (leftmost
+ rightmost
- width
) / 2;
18809 btm
= - descent
+ boff
;
18810 if (font_info
&& font_info
->relative_compose
18811 && (! CHAR_TABLE_P (Vignore_relative_composition
)
18812 || NILP (Faref (Vignore_relative_composition
,
18813 make_number (ch
)))))
18816 if (- descent
>= font_info
->relative_compose
)
18817 /* One extra pixel between two glyphs. */
18819 else if (ascent
<= 0)
18820 /* One extra pixel between two glyphs. */
18821 btm
= lowest
- 1 - ascent
- descent
;
18826 /* A composition rule is specified by an integer
18827 value that encodes global and new reference
18828 points (GREF and NREF). GREF and NREF are
18829 specified by numbers as below:
18831 0---1---2 -- ascent
18835 9--10--11 -- center
18837 ---3---4---5--- baseline
18839 6---7---8 -- descent
18841 int rule
= COMPOSITION_RULE (cmp
, i
);
18842 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
18844 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
18845 grefx
= gref
% 3, nrefx
= nref
% 3;
18846 grefy
= gref
/ 3, nrefy
= nref
/ 3;
18849 + grefx
* (rightmost
- leftmost
) / 2
18850 - nrefx
* width
/ 2);
18851 btm
= ((grefy
== 0 ? highest
18853 : grefy
== 2 ? lowest
18854 : (highest
+ lowest
) / 2)
18855 - (nrefy
== 0 ? ascent
+ descent
18856 : nrefy
== 1 ? descent
- boff
18858 : (ascent
+ descent
) / 2));
18861 cmp
->offsets
[i
* 2] = left
;
18862 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
18864 /* Update the bounding box of the overall glyphs. */
18865 right
= left
+ width
;
18866 top
= btm
+ descent
+ ascent
;
18867 if (left
< leftmost
)
18869 if (right
> rightmost
)
18877 /* If there are glyphs whose x-offsets are negative,
18878 shift all glyphs to the right and make all x-offsets
18882 for (i
= 0; i
< cmp
->glyph_len
; i
++)
18883 cmp
->offsets
[i
* 2] -= leftmost
;
18884 rightmost
-= leftmost
;
18887 cmp
->pixel_width
= rightmost
;
18888 cmp
->ascent
= highest
;
18889 cmp
->descent
= - lowest
;
18890 if (cmp
->ascent
< font_ascent
)
18891 cmp
->ascent
= font_ascent
;
18892 if (cmp
->descent
< font_descent
)
18893 cmp
->descent
= font_descent
;
18896 it
->pixel_width
= cmp
->pixel_width
;
18897 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
18898 it
->descent
= it
->phys_descent
= cmp
->descent
;
18900 if (face
->box
!= FACE_NO_BOX
)
18902 int thick
= face
->box_line_width
;
18906 it
->ascent
+= thick
;
18907 it
->descent
+= thick
;
18912 if (it
->start_of_box_run_p
)
18913 it
->pixel_width
+= thick
;
18914 if (it
->end_of_box_run_p
)
18915 it
->pixel_width
+= thick
;
18918 /* If face has an overline, add the height of the overline
18919 (1 pixel) and a 1 pixel margin to the character height. */
18920 if (face
->overline_p
)
18923 take_vertical_position_into_account (it
);
18926 append_composite_glyph (it
);
18928 else if (it
->what
== IT_IMAGE
)
18929 produce_image_glyph (it
);
18930 else if (it
->what
== IT_STRETCH
)
18931 produce_stretch_glyph (it
);
18933 /* Accumulate dimensions. Note: can't assume that it->descent > 0
18934 because this isn't true for images with `:ascent 100'. */
18935 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
18936 if (it
->area
== TEXT_AREA
)
18937 it
->current_x
+= it
->pixel_width
;
18939 it
->descent
+= it
->extra_line_spacing
;
18941 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
18942 it
->max_descent
= max (it
->max_descent
, it
->descent
);
18943 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
18944 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
18948 Output LEN glyphs starting at START at the nominal cursor position.
18949 Advance the nominal cursor over the text. The global variable
18950 updated_window contains the window being updated, updated_row is
18951 the glyph row being updated, and updated_area is the area of that
18952 row being updated. */
18955 x_write_glyphs (start
, len
)
18956 struct glyph
*start
;
18961 xassert (updated_window
&& updated_row
);
18964 /* Write glyphs. */
18966 hpos
= start
- updated_row
->glyphs
[updated_area
];
18967 x
= draw_glyphs (updated_window
, output_cursor
.x
,
18968 updated_row
, updated_area
,
18970 DRAW_NORMAL_TEXT
, 0);
18972 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
18973 if (updated_area
== TEXT_AREA
18974 && updated_window
->phys_cursor_on_p
18975 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
18976 && updated_window
->phys_cursor
.hpos
>= hpos
18977 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
18978 updated_window
->phys_cursor_on_p
= 0;
18982 /* Advance the output cursor. */
18983 output_cursor
.hpos
+= len
;
18984 output_cursor
.x
= x
;
18989 Insert LEN glyphs from START at the nominal cursor position. */
18992 x_insert_glyphs (start
, len
)
18993 struct glyph
*start
;
18998 int line_height
, shift_by_width
, shifted_region_width
;
18999 struct glyph_row
*row
;
19000 struct glyph
*glyph
;
19001 int frame_x
, frame_y
, hpos
;
19003 xassert (updated_window
&& updated_row
);
19005 w
= updated_window
;
19006 f
= XFRAME (WINDOW_FRAME (w
));
19008 /* Get the height of the line we are in. */
19010 line_height
= row
->height
;
19012 /* Get the width of the glyphs to insert. */
19013 shift_by_width
= 0;
19014 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
19015 shift_by_width
+= glyph
->pixel_width
;
19017 /* Get the width of the region to shift right. */
19018 shifted_region_width
= (window_box_width (w
, updated_area
)
19023 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
19024 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
19026 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
19027 line_height
, shift_by_width
);
19029 /* Write the glyphs. */
19030 hpos
= start
- row
->glyphs
[updated_area
];
19031 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
19033 DRAW_NORMAL_TEXT
, 0);
19035 /* Advance the output cursor. */
19036 output_cursor
.hpos
+= len
;
19037 output_cursor
.x
+= shift_by_width
;
19043 Erase the current text line from the nominal cursor position
19044 (inclusive) to pixel column TO_X (exclusive). The idea is that
19045 everything from TO_X onward is already erased.
19047 TO_X is a pixel position relative to updated_area of
19048 updated_window. TO_X == -1 means clear to the end of this area. */
19051 x_clear_end_of_line (to_x
)
19055 struct window
*w
= updated_window
;
19056 int max_x
, min_y
, max_y
;
19057 int from_x
, from_y
, to_y
;
19059 xassert (updated_window
&& updated_row
);
19060 f
= XFRAME (w
->frame
);
19062 if (updated_row
->full_width_p
)
19063 max_x
= WINDOW_TOTAL_WIDTH (w
);
19065 max_x
= window_box_width (w
, updated_area
);
19066 max_y
= window_text_bottom_y (w
);
19068 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
19069 of window. For TO_X > 0, truncate to end of drawing area. */
19075 to_x
= min (to_x
, max_x
);
19077 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
19079 /* Notice if the cursor will be cleared by this operation. */
19080 if (!updated_row
->full_width_p
)
19081 notice_overwritten_cursor (w
, updated_area
,
19082 output_cursor
.x
, -1,
19084 MATRIX_ROW_BOTTOM_Y (updated_row
));
19086 from_x
= output_cursor
.x
;
19088 /* Translate to frame coordinates. */
19089 if (updated_row
->full_width_p
)
19091 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
19092 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
19096 int area_left
= window_box_left (w
, updated_area
);
19097 from_x
+= area_left
;
19101 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
19102 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
19103 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
19105 /* Prevent inadvertently clearing to end of the X window. */
19106 if (to_x
> from_x
&& to_y
> from_y
)
19109 rif
->clear_frame_area (f
, from_x
, from_y
,
19110 to_x
- from_x
, to_y
- from_y
);
19115 #endif /* HAVE_WINDOW_SYSTEM */
19119 /***********************************************************************
19121 ***********************************************************************/
19123 /* Value is the internal representation of the specified cursor type
19124 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
19125 of the bar cursor. */
19127 static enum text_cursor_kinds
19128 get_specified_cursor_type (arg
, width
)
19132 enum text_cursor_kinds type
;
19137 if (EQ (arg
, Qbox
))
19138 return FILLED_BOX_CURSOR
;
19140 if (EQ (arg
, Qhollow
))
19141 return HOLLOW_BOX_CURSOR
;
19143 if (EQ (arg
, Qbar
))
19150 && EQ (XCAR (arg
), Qbar
)
19151 && INTEGERP (XCDR (arg
))
19152 && XINT (XCDR (arg
)) >= 0)
19154 *width
= XINT (XCDR (arg
));
19158 if (EQ (arg
, Qhbar
))
19161 return HBAR_CURSOR
;
19165 && EQ (XCAR (arg
), Qhbar
)
19166 && INTEGERP (XCDR (arg
))
19167 && XINT (XCDR (arg
)) >= 0)
19169 *width
= XINT (XCDR (arg
));
19170 return HBAR_CURSOR
;
19173 /* Treat anything unknown as "hollow box cursor".
19174 It was bad to signal an error; people have trouble fixing
19175 .Xdefaults with Emacs, when it has something bad in it. */
19176 type
= HOLLOW_BOX_CURSOR
;
19181 /* Set the default cursor types for specified frame. */
19183 set_frame_cursor_types (f
, arg
)
19190 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
19191 FRAME_CURSOR_WIDTH (f
) = width
;
19193 /* By default, set up the blink-off state depending on the on-state. */
19195 tem
= Fassoc (arg
, Vblink_cursor_alist
);
19198 FRAME_BLINK_OFF_CURSOR (f
)
19199 = get_specified_cursor_type (XCDR (tem
), &width
);
19200 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
19203 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
19207 /* Return the cursor we want to be displayed in window W. Return
19208 width of bar/hbar cursor through WIDTH arg. Return with
19209 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
19210 (i.e. if the `system caret' should track this cursor).
19212 In a mini-buffer window, we want the cursor only to appear if we
19213 are reading input from this window. For the selected window, we
19214 want the cursor type given by the frame parameter or buffer local
19215 setting of cursor-type. If explicitly marked off, draw no cursor.
19216 In all other cases, we want a hollow box cursor. */
19218 static enum text_cursor_kinds
19219 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
19221 struct glyph
*glyph
;
19223 int *active_cursor
;
19225 struct frame
*f
= XFRAME (w
->frame
);
19226 struct buffer
*b
= XBUFFER (w
->buffer
);
19227 int cursor_type
= DEFAULT_CURSOR
;
19228 Lisp_Object alt_cursor
;
19229 int non_selected
= 0;
19231 *active_cursor
= 1;
19234 if (cursor_in_echo_area
19235 && FRAME_HAS_MINIBUF_P (f
)
19236 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
19238 if (w
== XWINDOW (echo_area_window
))
19240 *width
= FRAME_CURSOR_WIDTH (f
);
19241 return FRAME_DESIRED_CURSOR (f
);
19244 *active_cursor
= 0;
19248 /* Nonselected window or nonselected frame. */
19249 else if (w
!= XWINDOW (f
->selected_window
)
19250 #ifdef HAVE_WINDOW_SYSTEM
19251 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
19255 *active_cursor
= 0;
19257 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
19263 /* Never display a cursor in a window in which cursor-type is nil. */
19264 if (NILP (b
->cursor_type
))
19267 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
19270 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
19271 return get_specified_cursor_type (alt_cursor
, width
);
19274 /* Get the normal cursor type for this window. */
19275 if (EQ (b
->cursor_type
, Qt
))
19277 cursor_type
= FRAME_DESIRED_CURSOR (f
);
19278 *width
= FRAME_CURSOR_WIDTH (f
);
19281 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
19283 /* Use normal cursor if not blinked off. */
19284 if (!w
->cursor_off_p
)
19286 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
19287 if (cursor_type
== FILLED_BOX_CURSOR
)
19288 cursor_type
= HOLLOW_BOX_CURSOR
;
19290 return cursor_type
;
19293 /* Cursor is blinked off, so determine how to "toggle" it. */
19295 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
19296 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
19297 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
19299 /* Then see if frame has specified a specific blink off cursor type. */
19300 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
19302 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
19303 return FRAME_BLINK_OFF_CURSOR (f
);
19307 /* Some people liked having a permanently visible blinking cursor,
19308 while others had very strong opinions against it. So it was
19309 decided to remove it. KFS 2003-09-03 */
19311 /* Finally perform built-in cursor blinking:
19312 filled box <-> hollow box
19313 wide [h]bar <-> narrow [h]bar
19314 narrow [h]bar <-> no cursor
19315 other type <-> no cursor */
19317 if (cursor_type
== FILLED_BOX_CURSOR
)
19318 return HOLLOW_BOX_CURSOR
;
19320 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
19323 return cursor_type
;
19331 #ifdef HAVE_WINDOW_SYSTEM
19333 /* Notice when the text cursor of window W has been completely
19334 overwritten by a drawing operation that outputs glyphs in AREA
19335 starting at X0 and ending at X1 in the line starting at Y0 and
19336 ending at Y1. X coordinates are area-relative. X1 < 0 means all
19337 the rest of the line after X0 has been written. Y coordinates
19338 are window-relative. */
19341 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
19343 enum glyph_row_area area
;
19344 int x0
, y0
, x1
, y1
;
19346 int cx0
, cx1
, cy0
, cy1
;
19347 struct glyph_row
*row
;
19349 if (!w
->phys_cursor_on_p
)
19351 if (area
!= TEXT_AREA
)
19354 row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
;
19355 if (!row
->displays_text_p
)
19358 if (row
->cursor_in_fringe_p
)
19360 row
->cursor_in_fringe_p
= 0;
19361 draw_fringe_bitmap (w
, row
, 0);
19362 w
->phys_cursor_on_p
= 0;
19366 cx0
= w
->phys_cursor
.x
;
19367 cx1
= cx0
+ w
->phys_cursor_width
;
19368 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
19371 /* The cursor image will be completely removed from the
19372 screen if the output area intersects the cursor area in
19373 y-direction. When we draw in [y0 y1[, and some part of
19374 the cursor is at y < y0, that part must have been drawn
19375 before. When scrolling, the cursor is erased before
19376 actually scrolling, so we don't come here. When not
19377 scrolling, the rows above the old cursor row must have
19378 changed, and in this case these rows must have written
19379 over the cursor image.
19381 Likewise if part of the cursor is below y1, with the
19382 exception of the cursor being in the first blank row at
19383 the buffer and window end because update_text_area
19384 doesn't draw that row. (Except when it does, but
19385 that's handled in update_text_area.) */
19387 cy0
= w
->phys_cursor
.y
;
19388 cy1
= cy0
+ w
->phys_cursor_height
;
19389 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
19392 w
->phys_cursor_on_p
= 0;
19395 #endif /* HAVE_WINDOW_SYSTEM */
19398 /************************************************************************
19400 ************************************************************************/
19402 #ifdef HAVE_WINDOW_SYSTEM
19405 Fix the display of area AREA of overlapping row ROW in window W. */
19408 x_fix_overlapping_area (w
, row
, area
)
19410 struct glyph_row
*row
;
19411 enum glyph_row_area area
;
19418 for (i
= 0; i
< row
->used
[area
];)
19420 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
19422 int start
= i
, start_x
= x
;
19426 x
+= row
->glyphs
[area
][i
].pixel_width
;
19429 while (i
< row
->used
[area
]
19430 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
19432 draw_glyphs (w
, start_x
, row
, area
,
19434 DRAW_NORMAL_TEXT
, 1);
19438 x
+= row
->glyphs
[area
][i
].pixel_width
;
19448 Draw the cursor glyph of window W in glyph row ROW. See the
19449 comment of draw_glyphs for the meaning of HL. */
19452 draw_phys_cursor_glyph (w
, row
, hl
)
19454 struct glyph_row
*row
;
19455 enum draw_glyphs_face hl
;
19457 /* If cursor hpos is out of bounds, don't draw garbage. This can
19458 happen in mini-buffer windows when switching between echo area
19459 glyphs and mini-buffer. */
19460 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
19462 int on_p
= w
->phys_cursor_on_p
;
19464 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
19465 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
19467 w
->phys_cursor_on_p
= on_p
;
19469 if (hl
== DRAW_CURSOR
)
19470 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
19471 /* When we erase the cursor, and ROW is overlapped by other
19472 rows, make sure that these overlapping parts of other rows
19474 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
19476 if (row
> w
->current_matrix
->rows
19477 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
19478 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
19480 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
19481 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
19482 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
19489 Erase the image of a cursor of window W from the screen. */
19492 erase_phys_cursor (w
)
19495 struct frame
*f
= XFRAME (w
->frame
);
19496 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
19497 int hpos
= w
->phys_cursor
.hpos
;
19498 int vpos
= w
->phys_cursor
.vpos
;
19499 int mouse_face_here_p
= 0;
19500 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
19501 struct glyph_row
*cursor_row
;
19502 struct glyph
*cursor_glyph
;
19503 enum draw_glyphs_face hl
;
19505 /* No cursor displayed or row invalidated => nothing to do on the
19507 if (w
->phys_cursor_type
== NO_CURSOR
)
19508 goto mark_cursor_off
;
19510 /* VPOS >= active_glyphs->nrows means that window has been resized.
19511 Don't bother to erase the cursor. */
19512 if (vpos
>= active_glyphs
->nrows
)
19513 goto mark_cursor_off
;
19515 /* If row containing cursor is marked invalid, there is nothing we
19517 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
19518 if (!cursor_row
->enabled_p
)
19519 goto mark_cursor_off
;
19521 /* If row is completely invisible, don't attempt to delete a cursor which
19522 isn't there. This can happen if cursor is at top of a window, and
19523 we switch to a buffer with a header line in that window. */
19524 if (cursor_row
->visible_height
<= 0)
19525 goto mark_cursor_off
;
19527 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
19528 if (cursor_row
->cursor_in_fringe_p
)
19530 cursor_row
->cursor_in_fringe_p
= 0;
19531 draw_fringe_bitmap (w
, cursor_row
, 0);
19532 goto mark_cursor_off
;
19535 /* This can happen when the new row is shorter than the old one.
19536 In this case, either draw_glyphs or clear_end_of_line
19537 should have cleared the cursor. Note that we wouldn't be
19538 able to erase the cursor in this case because we don't have a
19539 cursor glyph at hand. */
19540 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
19541 goto mark_cursor_off
;
19543 /* If the cursor is in the mouse face area, redisplay that when
19544 we clear the cursor. */
19545 if (! NILP (dpyinfo
->mouse_face_window
)
19546 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
19547 && (vpos
> dpyinfo
->mouse_face_beg_row
19548 || (vpos
== dpyinfo
->mouse_face_beg_row
19549 && hpos
>= dpyinfo
->mouse_face_beg_col
))
19550 && (vpos
< dpyinfo
->mouse_face_end_row
19551 || (vpos
== dpyinfo
->mouse_face_end_row
19552 && hpos
< dpyinfo
->mouse_face_end_col
))
19553 /* Don't redraw the cursor's spot in mouse face if it is at the
19554 end of a line (on a newline). The cursor appears there, but
19555 mouse highlighting does not. */
19556 && cursor_row
->used
[TEXT_AREA
] > hpos
)
19557 mouse_face_here_p
= 1;
19559 /* Maybe clear the display under the cursor. */
19560 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
19563 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
19565 cursor_glyph
= get_phys_cursor_glyph (w
);
19566 if (cursor_glyph
== NULL
)
19567 goto mark_cursor_off
;
19569 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
19570 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
19572 rif
->clear_frame_area (f
, x
, y
,
19573 cursor_glyph
->pixel_width
, cursor_row
->visible_height
);
19576 /* Erase the cursor by redrawing the character underneath it. */
19577 if (mouse_face_here_p
)
19578 hl
= DRAW_MOUSE_FACE
;
19580 hl
= DRAW_NORMAL_TEXT
;
19581 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
19584 w
->phys_cursor_on_p
= 0;
19585 w
->phys_cursor_type
= NO_CURSOR
;
19590 Display or clear cursor of window W. If ON is zero, clear the
19591 cursor. If it is non-zero, display the cursor. If ON is nonzero,
19592 where to put the cursor is specified by HPOS, VPOS, X and Y. */
19595 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
19597 int on
, hpos
, vpos
, x
, y
;
19599 struct frame
*f
= XFRAME (w
->frame
);
19600 int new_cursor_type
;
19601 int new_cursor_width
;
19603 struct glyph_row
*glyph_row
;
19604 struct glyph
*glyph
;
19606 /* This is pointless on invisible frames, and dangerous on garbaged
19607 windows and frames; in the latter case, the frame or window may
19608 be in the midst of changing its size, and x and y may be off the
19610 if (! FRAME_VISIBLE_P (f
)
19611 || FRAME_GARBAGED_P (f
)
19612 || vpos
>= w
->current_matrix
->nrows
19613 || hpos
>= w
->current_matrix
->matrix_w
)
19616 /* If cursor is off and we want it off, return quickly. */
19617 if (!on
&& !w
->phys_cursor_on_p
)
19620 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
19621 /* If cursor row is not enabled, we don't really know where to
19622 display the cursor. */
19623 if (!glyph_row
->enabled_p
)
19625 w
->phys_cursor_on_p
= 0;
19630 if (!glyph_row
->exact_window_width_line_p
19631 || hpos
< glyph_row
->used
[TEXT_AREA
])
19632 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
19634 xassert (interrupt_input_blocked
);
19636 /* Set new_cursor_type to the cursor we want to be displayed. */
19637 new_cursor_type
= get_window_cursor_type (w
, glyph
,
19638 &new_cursor_width
, &active_cursor
);
19640 /* If cursor is currently being shown and we don't want it to be or
19641 it is in the wrong place, or the cursor type is not what we want,
19643 if (w
->phys_cursor_on_p
19645 || w
->phys_cursor
.x
!= x
19646 || w
->phys_cursor
.y
!= y
19647 || new_cursor_type
!= w
->phys_cursor_type
19648 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
19649 && new_cursor_width
!= w
->phys_cursor_width
)))
19650 erase_phys_cursor (w
);
19652 /* Don't check phys_cursor_on_p here because that flag is only set
19653 to zero in some cases where we know that the cursor has been
19654 completely erased, to avoid the extra work of erasing the cursor
19655 twice. In other words, phys_cursor_on_p can be 1 and the cursor
19656 still not be visible, or it has only been partly erased. */
19659 w
->phys_cursor_ascent
= glyph_row
->ascent
;
19660 w
->phys_cursor_height
= glyph_row
->height
;
19662 /* Set phys_cursor_.* before x_draw_.* is called because some
19663 of them may need the information. */
19664 w
->phys_cursor
.x
= x
;
19665 w
->phys_cursor
.y
= glyph_row
->y
;
19666 w
->phys_cursor
.hpos
= hpos
;
19667 w
->phys_cursor
.vpos
= vpos
;
19670 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
19671 new_cursor_type
, new_cursor_width
,
19672 on
, active_cursor
);
19676 /* Switch the display of W's cursor on or off, according to the value
19680 update_window_cursor (w
, on
)
19684 /* Don't update cursor in windows whose frame is in the process
19685 of being deleted. */
19686 if (w
->current_matrix
)
19689 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
19690 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
19696 /* Call update_window_cursor with parameter ON_P on all leaf windows
19697 in the window tree rooted at W. */
19700 update_cursor_in_window_tree (w
, on_p
)
19706 if (!NILP (w
->hchild
))
19707 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
19708 else if (!NILP (w
->vchild
))
19709 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
19711 update_window_cursor (w
, on_p
);
19713 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
19719 Display the cursor on window W, or clear it, according to ON_P.
19720 Don't change the cursor's position. */
19723 x_update_cursor (f
, on_p
)
19727 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
19732 Clear the cursor of window W to background color, and mark the
19733 cursor as not shown. This is used when the text where the cursor
19734 is is about to be rewritten. */
19740 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
19741 update_window_cursor (w
, 0);
19746 Display the active region described by mouse_face_* according to DRAW. */
19749 show_mouse_face (dpyinfo
, draw
)
19750 Display_Info
*dpyinfo
;
19751 enum draw_glyphs_face draw
;
19753 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
19754 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19756 if (/* If window is in the process of being destroyed, don't bother
19758 w
->current_matrix
!= NULL
19759 /* Don't update mouse highlight if hidden */
19760 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
19761 /* Recognize when we are called to operate on rows that don't exist
19762 anymore. This can happen when a window is split. */
19763 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
19765 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
19766 struct glyph_row
*row
, *first
, *last
;
19768 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
19769 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
19771 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
19773 int start_hpos
, end_hpos
, start_x
;
19775 /* For all but the first row, the highlight starts at column 0. */
19778 start_hpos
= dpyinfo
->mouse_face_beg_col
;
19779 start_x
= dpyinfo
->mouse_face_beg_x
;
19788 end_hpos
= dpyinfo
->mouse_face_end_col
;
19790 end_hpos
= row
->used
[TEXT_AREA
];
19792 if (end_hpos
> start_hpos
)
19794 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
19795 start_hpos
, end_hpos
,
19799 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
19803 /* When we've written over the cursor, arrange for it to
19804 be displayed again. */
19805 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
19808 display_and_set_cursor (w
, 1,
19809 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
19810 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
19815 /* Change the mouse cursor. */
19816 if (draw
== DRAW_NORMAL_TEXT
)
19817 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
19818 else if (draw
== DRAW_MOUSE_FACE
)
19819 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
19821 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
19825 Clear out the mouse-highlighted active region.
19826 Redraw it un-highlighted first. Value is non-zero if mouse
19827 face was actually drawn unhighlighted. */
19830 clear_mouse_face (dpyinfo
)
19831 Display_Info
*dpyinfo
;
19835 if (!NILP (dpyinfo
->mouse_face_window
))
19837 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
19841 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
19842 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
19843 dpyinfo
->mouse_face_window
= Qnil
;
19844 dpyinfo
->mouse_face_overlay
= Qnil
;
19850 Non-zero if physical cursor of window W is within mouse face. */
19853 cursor_in_mouse_face_p (w
)
19856 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
19857 int in_mouse_face
= 0;
19859 if (WINDOWP (dpyinfo
->mouse_face_window
)
19860 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
19862 int hpos
= w
->phys_cursor
.hpos
;
19863 int vpos
= w
->phys_cursor
.vpos
;
19865 if (vpos
>= dpyinfo
->mouse_face_beg_row
19866 && vpos
<= dpyinfo
->mouse_face_end_row
19867 && (vpos
> dpyinfo
->mouse_face_beg_row
19868 || hpos
>= dpyinfo
->mouse_face_beg_col
)
19869 && (vpos
< dpyinfo
->mouse_face_end_row
19870 || hpos
< dpyinfo
->mouse_face_end_col
19871 || dpyinfo
->mouse_face_past_end
))
19875 return in_mouse_face
;
19881 /* Find the glyph matrix position of buffer position CHARPOS in window
19882 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
19883 current glyphs must be up to date. If CHARPOS is above window
19884 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
19885 of last line in W. In the row containing CHARPOS, stop before glyphs
19886 having STOP as object. */
19888 #if 1 /* This is a version of fast_find_position that's more correct
19889 in the presence of hscrolling, for example. I didn't install
19890 it right away because the problem fixed is minor, it failed
19891 in 20.x as well, and I think it's too risky to install
19892 so near the release of 21.1. 2001-09-25 gerd. */
19895 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
19898 int *hpos
, *vpos
, *x
, *y
;
19901 struct glyph_row
*row
, *first
;
19902 struct glyph
*glyph
, *end
;
19905 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
19906 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
19909 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
19911 *x
= *y
= *hpos
= *vpos
= 0;
19916 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
19923 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
19925 glyph
= row
->glyphs
[TEXT_AREA
];
19926 end
= glyph
+ row
->used
[TEXT_AREA
];
19928 /* Skip over glyphs not having an object at the start of the row.
19929 These are special glyphs like truncation marks on terminal
19931 if (row
->displays_text_p
)
19933 && INTEGERP (glyph
->object
)
19934 && !EQ (stop
, glyph
->object
)
19935 && glyph
->charpos
< 0)
19937 *x
+= glyph
->pixel_width
;
19942 && !INTEGERP (glyph
->object
)
19943 && !EQ (stop
, glyph
->object
)
19944 && (!BUFFERP (glyph
->object
)
19945 || glyph
->charpos
< charpos
))
19947 *x
+= glyph
->pixel_width
;
19951 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
19958 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
19961 int *hpos
, *vpos
, *x
, *y
;
19966 int maybe_next_line_p
= 0;
19967 int line_start_position
;
19968 int yb
= window_text_bottom_y (w
);
19969 struct glyph_row
*row
, *best_row
;
19970 int row_vpos
, best_row_vpos
;
19973 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
19974 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
19976 while (row
->y
< yb
)
19978 if (row
->used
[TEXT_AREA
])
19979 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
19981 line_start_position
= 0;
19983 if (line_start_position
> pos
)
19985 /* If the position sought is the end of the buffer,
19986 don't include the blank lines at the bottom of the window. */
19987 else if (line_start_position
== pos
19988 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
19990 maybe_next_line_p
= 1;
19993 else if (line_start_position
> 0)
19996 best_row_vpos
= row_vpos
;
19999 if (row
->y
+ row
->height
>= yb
)
20006 /* Find the right column within BEST_ROW. */
20008 current_x
= best_row
->x
;
20009 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
20011 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
20012 int charpos
= glyph
->charpos
;
20014 if (BUFFERP (glyph
->object
))
20016 if (charpos
== pos
)
20019 *vpos
= best_row_vpos
;
20024 else if (charpos
> pos
)
20027 else if (EQ (glyph
->object
, stop
))
20032 current_x
+= glyph
->pixel_width
;
20035 /* If we're looking for the end of the buffer,
20036 and we didn't find it in the line we scanned,
20037 use the start of the following line. */
20038 if (maybe_next_line_p
)
20043 current_x
= best_row
->x
;
20046 *vpos
= best_row_vpos
;
20047 *hpos
= lastcol
+ 1;
20056 /* Find the position of the glyph for position POS in OBJECT in
20057 window W's current matrix, and return in *X, *Y the pixel
20058 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
20060 RIGHT_P non-zero means return the position of the right edge of the
20061 glyph, RIGHT_P zero means return the left edge position.
20063 If no glyph for POS exists in the matrix, return the position of
20064 the glyph with the next smaller position that is in the matrix, if
20065 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
20066 exists in the matrix, return the position of the glyph with the
20067 next larger position in OBJECT.
20069 Value is non-zero if a glyph was found. */
20072 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
20075 Lisp_Object object
;
20076 int *hpos
, *vpos
, *x
, *y
;
20079 int yb
= window_text_bottom_y (w
);
20080 struct glyph_row
*r
;
20081 struct glyph
*best_glyph
= NULL
;
20082 struct glyph_row
*best_row
= NULL
;
20085 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20086 r
->enabled_p
&& r
->y
< yb
;
20089 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
20090 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
20093 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
20094 if (EQ (g
->object
, object
))
20096 if (g
->charpos
== pos
)
20103 else if (best_glyph
== NULL
20104 || ((abs (g
->charpos
- pos
)
20105 < abs (best_glyph
->charpos
- pos
))
20108 : g
->charpos
> pos
)))
20122 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
20126 *x
+= best_glyph
->pixel_width
;
20131 *vpos
= best_row
- w
->current_matrix
->rows
;
20134 return best_glyph
!= NULL
;
20138 /* See if position X, Y is within a hot-spot of an image. */
20141 on_hot_spot_p (hot_spot
, x
, y
)
20142 Lisp_Object hot_spot
;
20145 if (!CONSP (hot_spot
))
20148 if (EQ (XCAR (hot_spot
), Qrect
))
20150 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
20151 Lisp_Object rect
= XCDR (hot_spot
);
20155 if (!CONSP (XCAR (rect
)))
20157 if (!CONSP (XCDR (rect
)))
20159 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
20161 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
20163 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
20165 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
20169 else if (EQ (XCAR (hot_spot
), Qcircle
))
20171 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
20172 Lisp_Object circ
= XCDR (hot_spot
);
20173 Lisp_Object lr
, lx0
, ly0
;
20175 && CONSP (XCAR (circ
))
20176 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
20177 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
20178 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
20180 double r
= XFLOATINT (lr
);
20181 double dx
= XINT (lx0
) - x
;
20182 double dy
= XINT (ly0
) - y
;
20183 return (dx
* dx
+ dy
* dy
<= r
* r
);
20186 else if (EQ (XCAR (hot_spot
), Qpoly
))
20188 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
20189 if (VECTORP (XCDR (hot_spot
)))
20191 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
20192 Lisp_Object
*poly
= v
->contents
;
20196 Lisp_Object lx
, ly
;
20199 /* Need an even number of coordinates, and at least 3 edges. */
20200 if (n
< 6 || n
& 1)
20203 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
20204 If count is odd, we are inside polygon. Pixels on edges
20205 may or may not be included depending on actual geometry of the
20207 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
20208 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
20210 x0
= XINT (lx
), y0
= XINT (ly
);
20211 for (i
= 0; i
< n
; i
+= 2)
20213 int x1
= x0
, y1
= y0
;
20214 if ((lx
= poly
[i
], !INTEGERP (lx
))
20215 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
20217 x0
= XINT (lx
), y0
= XINT (ly
);
20219 /* Does this segment cross the X line? */
20227 if (y
> y0
&& y
> y1
)
20229 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
20240 find_hot_spot (map
, x
, y
)
20244 while (CONSP (map
))
20246 if (CONSP (XCAR (map
))
20247 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
20255 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
20257 doc
: /* Lookup in image map MAP coordinates X and Y.
20258 An image map is an alist where each element has the format (AREA ID PLIST).
20259 An AREA is specified as either a rectangle, a circle, or a polygon:
20260 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
20261 pixel coordinates of the upper left and bottom right corners.
20262 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
20263 and the radius of the circle; r may be a float or integer.
20264 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
20265 vector describes one corner in the polygon.
20266 Returns the alist element for the first matching AREA in MAP. */)
20278 return find_hot_spot (map
, XINT (x
), XINT (y
));
20282 /* Display frame CURSOR, optionally using shape defined by POINTER. */
20284 define_frame_cursor1 (f
, cursor
, pointer
)
20287 Lisp_Object pointer
;
20289 if (!NILP (pointer
))
20291 if (EQ (pointer
, Qarrow
))
20292 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20293 else if (EQ (pointer
, Qhand
))
20294 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
20295 else if (EQ (pointer
, Qtext
))
20296 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
20297 else if (EQ (pointer
, intern ("hdrag")))
20298 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
20299 #ifdef HAVE_X_WINDOWS
20300 else if (EQ (pointer
, intern ("vdrag")))
20301 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
20303 else if (EQ (pointer
, intern ("hourglass")))
20304 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
20305 else if (EQ (pointer
, Qmodeline
))
20306 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
20308 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20311 #ifndef HAVE_CARBON
20312 if (cursor
!= No_Cursor
)
20314 if (bcmp (&cursor
, &No_Cursor
, sizeof (Cursor
)))
20316 rif
->define_frame_cursor (f
, cursor
);
20319 /* Take proper action when mouse has moved to the mode or header line
20320 or marginal area AREA of window W, x-position X and y-position Y.
20321 X is relative to the start of the text display area of W, so the
20322 width of bitmap areas and scroll bars must be subtracted to get a
20323 position relative to the start of the mode line. */
20326 note_mode_line_or_margin_highlight (w
, x
, y
, area
)
20329 enum window_part area
;
20331 struct frame
*f
= XFRAME (w
->frame
);
20332 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20333 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20334 Lisp_Object pointer
= Qnil
;
20335 int charpos
, dx
, dy
, width
, height
;
20336 Lisp_Object string
, object
= Qnil
;
20337 Lisp_Object pos
, help
, image
;
20339 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
20340 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
20341 &object
, &dx
, &dy
, &width
, &height
);
20344 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
20345 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
20346 &object
, &dx
, &dy
, &width
, &height
);
20351 if (IMAGEP (object
))
20353 Lisp_Object image_map
, hotspot
;
20354 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
20356 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
20358 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
20360 Lisp_Object area_id
, plist
;
20362 area_id
= XCAR (hotspot
);
20363 /* Could check AREA_ID to see if we enter/leave this hot-spot.
20364 If so, we could look for mouse-enter, mouse-leave
20365 properties in PLIST (and do something...). */
20366 if ((plist
= XCDR (hotspot
), CONSP (plist
)))
20368 pointer
= Fplist_get (plist
, Qpointer
);
20369 if (NILP (pointer
))
20371 help
= Fplist_get (plist
, Qhelp_echo
);
20374 help_echo_string
= help
;
20375 /* Is this correct? ++kfs */
20376 XSETWINDOW (help_echo_window
, w
);
20377 help_echo_object
= w
->buffer
;
20378 help_echo_pos
= charpos
;
20381 if (NILP (pointer
))
20382 pointer
= Fplist_get (XCDR (object
), QCpointer
);
20386 if (STRINGP (string
))
20388 pos
= make_number (charpos
);
20389 /* If we're on a string with `help-echo' text property, arrange
20390 for the help to be displayed. This is done by setting the
20391 global variable help_echo_string to the help string. */
20392 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
20395 help_echo_string
= help
;
20396 XSETWINDOW (help_echo_window
, w
);
20397 help_echo_object
= string
;
20398 help_echo_pos
= charpos
;
20401 if (NILP (pointer
))
20402 pointer
= Fget_text_property (pos
, Qpointer
, string
);
20404 /* Change the mouse pointer according to what is under X/Y. */
20405 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
20408 map
= Fget_text_property (pos
, Qlocal_map
, string
);
20409 if (!KEYMAPP (map
))
20410 map
= Fget_text_property (pos
, Qkeymap
, string
);
20411 if (!KEYMAPP (map
))
20412 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
20416 define_frame_cursor1 (f
, cursor
, pointer
);
20421 Take proper action when the mouse has moved to position X, Y on
20422 frame F as regards highlighting characters that have mouse-face
20423 properties. Also de-highlighting chars where the mouse was before.
20424 X and Y can be negative or out of range. */
20427 note_mouse_highlight (f
, x
, y
)
20431 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20432 enum window_part part
;
20433 Lisp_Object window
;
20435 Cursor cursor
= No_Cursor
;
20436 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
20439 /* When a menu is active, don't highlight because this looks odd. */
20440 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
20441 if (popup_activated ())
20445 if (NILP (Vmouse_highlight
)
20446 || !f
->glyphs_initialized_p
)
20449 dpyinfo
->mouse_face_mouse_x
= x
;
20450 dpyinfo
->mouse_face_mouse_y
= y
;
20451 dpyinfo
->mouse_face_mouse_frame
= f
;
20453 if (dpyinfo
->mouse_face_defer
)
20456 if (gc_in_progress
)
20458 dpyinfo
->mouse_face_deferred_gc
= 1;
20462 /* Which window is that in? */
20463 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
20465 /* If we were displaying active text in another window, clear that. */
20466 if (! EQ (window
, dpyinfo
->mouse_face_window
))
20467 clear_mouse_face (dpyinfo
);
20469 /* Not on a window -> return. */
20470 if (!WINDOWP (window
))
20473 /* Reset help_echo_string. It will get recomputed below. */
20474 help_echo_string
= Qnil
;
20476 /* Convert to window-relative pixel coordinates. */
20477 w
= XWINDOW (window
);
20478 frame_to_window_pixel_xy (w
, &x
, &y
);
20480 /* Handle tool-bar window differently since it doesn't display a
20482 if (EQ (window
, f
->tool_bar_window
))
20484 note_tool_bar_highlight (f
, x
, y
);
20488 /* Mouse is on the mode, header line or margin? */
20489 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
20490 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
20492 note_mode_line_or_margin_highlight (w
, x
, y
, part
);
20496 if (part
== ON_VERTICAL_BORDER
)
20497 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
20498 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
)
20499 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20501 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
20503 /* Are we in a window whose display is up to date?
20504 And verify the buffer's text has not changed. */
20505 b
= XBUFFER (w
->buffer
);
20506 if (part
== ON_TEXT
20507 && EQ (w
->window_end_valid
, w
->buffer
)
20508 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
20509 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
20511 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
20512 struct glyph
*glyph
;
20513 Lisp_Object object
;
20514 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
20515 Lisp_Object
*overlay_vec
= NULL
;
20516 int len
, noverlays
;
20517 struct buffer
*obuf
;
20518 int obegv
, ozv
, same_region
;
20520 /* Find the glyph under X/Y. */
20521 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
20523 /* Look for :pointer property on image. */
20524 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
20526 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
20527 if (img
!= NULL
&& IMAGEP (img
->spec
))
20529 Lisp_Object image_map
, hotspot
;
20530 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
20532 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
20534 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
20536 Lisp_Object area_id
, plist
;
20538 area_id
= XCAR (hotspot
);
20539 /* Could check AREA_ID to see if we enter/leave this hot-spot.
20540 If so, we could look for mouse-enter, mouse-leave
20541 properties in PLIST (and do something...). */
20542 if ((plist
= XCDR (hotspot
), CONSP (plist
)))
20544 pointer
= Fplist_get (plist
, Qpointer
);
20545 if (NILP (pointer
))
20547 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
20548 if (!NILP (help_echo_string
))
20550 help_echo_window
= window
;
20551 help_echo_object
= glyph
->object
;
20552 help_echo_pos
= glyph
->charpos
;
20556 if (NILP (pointer
))
20557 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
20561 /* Clear mouse face if X/Y not over text. */
20563 || area
!= TEXT_AREA
20564 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
20566 if (clear_mouse_face (dpyinfo
))
20567 cursor
= No_Cursor
;
20568 if (NILP (pointer
))
20570 if (area
!= TEXT_AREA
)
20571 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20573 pointer
= Vvoid_text_area_pointer
;
20578 pos
= glyph
->charpos
;
20579 object
= glyph
->object
;
20580 if (!STRINGP (object
) && !BUFFERP (object
))
20583 /* If we get an out-of-range value, return now; avoid an error. */
20584 if (BUFFERP (object
) && pos
> BUF_Z (b
))
20587 /* Make the window's buffer temporarily current for
20588 overlays_at and compute_char_face. */
20589 obuf
= current_buffer
;
20590 current_buffer
= b
;
20596 /* Is this char mouse-active or does it have help-echo? */
20597 position
= make_number (pos
);
20599 if (BUFFERP (object
))
20601 /* Put all the overlays we want in a vector in overlay_vec.
20602 Store the length in len. If there are more than 10, make
20603 enough space for all, and try again. */
20605 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
20606 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
20607 if (noverlays
> len
)
20610 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
20611 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
20614 /* Sort overlays into increasing priority order. */
20615 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
20620 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
20621 && vpos
>= dpyinfo
->mouse_face_beg_row
20622 && vpos
<= dpyinfo
->mouse_face_end_row
20623 && (vpos
> dpyinfo
->mouse_face_beg_row
20624 || hpos
>= dpyinfo
->mouse_face_beg_col
)
20625 && (vpos
< dpyinfo
->mouse_face_end_row
20626 || hpos
< dpyinfo
->mouse_face_end_col
20627 || dpyinfo
->mouse_face_past_end
));
20630 cursor
= No_Cursor
;
20632 /* Check mouse-face highlighting. */
20634 /* If there exists an overlay with mouse-face overlapping
20635 the one we are currently highlighting, we have to
20636 check if we enter the overlapping overlay, and then
20637 highlight only that. */
20638 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
20639 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
20641 /* Find the highest priority overlay that has a mouse-face
20644 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
20646 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
20647 if (!NILP (mouse_face
))
20648 overlay
= overlay_vec
[i
];
20651 /* If we're actually highlighting the same overlay as
20652 before, there's no need to do that again. */
20653 if (!NILP (overlay
)
20654 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
20655 goto check_help_echo
;
20657 dpyinfo
->mouse_face_overlay
= overlay
;
20659 /* Clear the display of the old active region, if any. */
20660 if (clear_mouse_face (dpyinfo
))
20661 cursor
= No_Cursor
;
20663 /* If no overlay applies, get a text property. */
20664 if (NILP (overlay
))
20665 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
20667 /* Handle the overlay case. */
20668 if (!NILP (overlay
))
20670 /* Find the range of text around this char that
20671 should be active. */
20672 Lisp_Object before
, after
;
20675 before
= Foverlay_start (overlay
);
20676 after
= Foverlay_end (overlay
);
20677 /* Record this as the current active region. */
20678 fast_find_position (w
, XFASTINT (before
),
20679 &dpyinfo
->mouse_face_beg_col
,
20680 &dpyinfo
->mouse_face_beg_row
,
20681 &dpyinfo
->mouse_face_beg_x
,
20682 &dpyinfo
->mouse_face_beg_y
, Qnil
);
20684 dpyinfo
->mouse_face_past_end
20685 = !fast_find_position (w
, XFASTINT (after
),
20686 &dpyinfo
->mouse_face_end_col
,
20687 &dpyinfo
->mouse_face_end_row
,
20688 &dpyinfo
->mouse_face_end_x
,
20689 &dpyinfo
->mouse_face_end_y
, Qnil
);
20690 dpyinfo
->mouse_face_window
= window
;
20692 dpyinfo
->mouse_face_face_id
20693 = face_at_buffer_position (w
, pos
, 0, 0,
20695 !dpyinfo
->mouse_face_hidden
);
20697 /* Display it as active. */
20698 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
20699 cursor
= No_Cursor
;
20701 /* Handle the text property case. */
20702 else if (!NILP (mouse_face
) && BUFFERP (object
))
20704 /* Find the range of text around this char that
20705 should be active. */
20706 Lisp_Object before
, after
, beginning
, end
;
20709 beginning
= Fmarker_position (w
->start
);
20710 end
= make_number (BUF_Z (XBUFFER (object
))
20711 - XFASTINT (w
->window_end_pos
));
20713 = Fprevious_single_property_change (make_number (pos
+ 1),
20715 object
, beginning
);
20717 = Fnext_single_property_change (position
, Qmouse_face
,
20720 /* Record this as the current active region. */
20721 fast_find_position (w
, XFASTINT (before
),
20722 &dpyinfo
->mouse_face_beg_col
,
20723 &dpyinfo
->mouse_face_beg_row
,
20724 &dpyinfo
->mouse_face_beg_x
,
20725 &dpyinfo
->mouse_face_beg_y
, Qnil
);
20726 dpyinfo
->mouse_face_past_end
20727 = !fast_find_position (w
, XFASTINT (after
),
20728 &dpyinfo
->mouse_face_end_col
,
20729 &dpyinfo
->mouse_face_end_row
,
20730 &dpyinfo
->mouse_face_end_x
,
20731 &dpyinfo
->mouse_face_end_y
, Qnil
);
20732 dpyinfo
->mouse_face_window
= window
;
20734 if (BUFFERP (object
))
20735 dpyinfo
->mouse_face_face_id
20736 = face_at_buffer_position (w
, pos
, 0, 0,
20738 !dpyinfo
->mouse_face_hidden
);
20740 /* Display it as active. */
20741 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
20742 cursor
= No_Cursor
;
20744 else if (!NILP (mouse_face
) && STRINGP (object
))
20749 b
= Fprevious_single_property_change (make_number (pos
+ 1),
20752 e
= Fnext_single_property_change (position
, Qmouse_face
,
20755 b
= make_number (0);
20757 e
= make_number (SCHARS (object
) - 1);
20758 fast_find_string_pos (w
, XINT (b
), object
,
20759 &dpyinfo
->mouse_face_beg_col
,
20760 &dpyinfo
->mouse_face_beg_row
,
20761 &dpyinfo
->mouse_face_beg_x
,
20762 &dpyinfo
->mouse_face_beg_y
, 0);
20763 fast_find_string_pos (w
, XINT (e
), object
,
20764 &dpyinfo
->mouse_face_end_col
,
20765 &dpyinfo
->mouse_face_end_row
,
20766 &dpyinfo
->mouse_face_end_x
,
20767 &dpyinfo
->mouse_face_end_y
, 1);
20768 dpyinfo
->mouse_face_past_end
= 0;
20769 dpyinfo
->mouse_face_window
= window
;
20770 dpyinfo
->mouse_face_face_id
20771 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
20772 glyph
->face_id
, 1);
20773 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
20774 cursor
= No_Cursor
;
20776 else if (STRINGP (object
) && NILP (mouse_face
))
20778 /* A string which doesn't have mouse-face, but
20779 the text ``under'' it might have. */
20780 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
20781 int start
= MATRIX_ROW_START_CHARPOS (r
);
20783 pos
= string_buffer_position (w
, object
, start
);
20785 mouse_face
= get_char_property_and_overlay (make_number (pos
),
20789 if (!NILP (mouse_face
) && !NILP (overlay
))
20791 Lisp_Object before
= Foverlay_start (overlay
);
20792 Lisp_Object after
= Foverlay_end (overlay
);
20795 /* Note that we might not be able to find position
20796 BEFORE in the glyph matrix if the overlay is
20797 entirely covered by a `display' property. In
20798 this case, we overshoot. So let's stop in
20799 the glyph matrix before glyphs for OBJECT. */
20800 fast_find_position (w
, XFASTINT (before
),
20801 &dpyinfo
->mouse_face_beg_col
,
20802 &dpyinfo
->mouse_face_beg_row
,
20803 &dpyinfo
->mouse_face_beg_x
,
20804 &dpyinfo
->mouse_face_beg_y
,
20807 dpyinfo
->mouse_face_past_end
20808 = !fast_find_position (w
, XFASTINT (after
),
20809 &dpyinfo
->mouse_face_end_col
,
20810 &dpyinfo
->mouse_face_end_row
,
20811 &dpyinfo
->mouse_face_end_x
,
20812 &dpyinfo
->mouse_face_end_y
,
20814 dpyinfo
->mouse_face_window
= window
;
20815 dpyinfo
->mouse_face_face_id
20816 = face_at_buffer_position (w
, pos
, 0, 0,
20818 !dpyinfo
->mouse_face_hidden
);
20820 /* Display it as active. */
20821 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
20822 cursor
= No_Cursor
;
20829 /* Look for a `help-echo' property. */
20830 if (NILP (help_echo_string
)) {
20831 Lisp_Object help
, overlay
;
20833 /* Check overlays first. */
20834 help
= overlay
= Qnil
;
20835 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
20837 overlay
= overlay_vec
[i
];
20838 help
= Foverlay_get (overlay
, Qhelp_echo
);
20843 help_echo_string
= help
;
20844 help_echo_window
= window
;
20845 help_echo_object
= overlay
;
20846 help_echo_pos
= pos
;
20850 Lisp_Object object
= glyph
->object
;
20851 int charpos
= glyph
->charpos
;
20853 /* Try text properties. */
20854 if (STRINGP (object
)
20856 && charpos
< SCHARS (object
))
20858 help
= Fget_text_property (make_number (charpos
),
20859 Qhelp_echo
, object
);
20862 /* If the string itself doesn't specify a help-echo,
20863 see if the buffer text ``under'' it does. */
20864 struct glyph_row
*r
20865 = MATRIX_ROW (w
->current_matrix
, vpos
);
20866 int start
= MATRIX_ROW_START_CHARPOS (r
);
20867 int pos
= string_buffer_position (w
, object
, start
);
20870 help
= Fget_char_property (make_number (pos
),
20871 Qhelp_echo
, w
->buffer
);
20875 object
= w
->buffer
;
20880 else if (BUFFERP (object
)
20883 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
20888 help_echo_string
= help
;
20889 help_echo_window
= window
;
20890 help_echo_object
= object
;
20891 help_echo_pos
= charpos
;
20896 /* Look for a `pointer' property. */
20897 if (NILP (pointer
))
20899 /* Check overlays first. */
20900 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
20901 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
20903 if (NILP (pointer
))
20905 Lisp_Object object
= glyph
->object
;
20906 int charpos
= glyph
->charpos
;
20908 /* Try text properties. */
20909 if (STRINGP (object
)
20911 && charpos
< SCHARS (object
))
20913 pointer
= Fget_text_property (make_number (charpos
),
20915 if (NILP (pointer
))
20917 /* If the string itself doesn't specify a pointer,
20918 see if the buffer text ``under'' it does. */
20919 struct glyph_row
*r
20920 = MATRIX_ROW (w
->current_matrix
, vpos
);
20921 int start
= MATRIX_ROW_START_CHARPOS (r
);
20922 int pos
= string_buffer_position (w
, object
, start
);
20924 pointer
= Fget_char_property (make_number (pos
),
20925 Qpointer
, w
->buffer
);
20928 else if (BUFFERP (object
)
20931 pointer
= Fget_text_property (make_number (charpos
),
20938 current_buffer
= obuf
;
20943 define_frame_cursor1 (f
, cursor
, pointer
);
20948 Clear any mouse-face on window W. This function is part of the
20949 redisplay interface, and is called from try_window_id and similar
20950 functions to ensure the mouse-highlight is off. */
20953 x_clear_window_mouse_face (w
)
20956 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
20957 Lisp_Object window
;
20960 XSETWINDOW (window
, w
);
20961 if (EQ (window
, dpyinfo
->mouse_face_window
))
20962 clear_mouse_face (dpyinfo
);
20968 Just discard the mouse face information for frame F, if any.
20969 This is used when the size of F is changed. */
20972 cancel_mouse_face (f
)
20975 Lisp_Object window
;
20976 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20978 window
= dpyinfo
->mouse_face_window
;
20979 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
20981 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
20982 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
20983 dpyinfo
->mouse_face_window
= Qnil
;
20988 #endif /* HAVE_WINDOW_SYSTEM */
20991 /***********************************************************************
20993 ***********************************************************************/
20995 #ifdef HAVE_WINDOW_SYSTEM
20997 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
20998 which intersects rectangle R. R is in window-relative coordinates. */
21001 expose_area (w
, row
, r
, area
)
21003 struct glyph_row
*row
;
21005 enum glyph_row_area area
;
21007 struct glyph
*first
= row
->glyphs
[area
];
21008 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
21009 struct glyph
*last
;
21010 int first_x
, start_x
, x
;
21012 if (area
== TEXT_AREA
&& row
->fill_line_p
)
21013 /* If row extends face to end of line write the whole line. */
21014 draw_glyphs (w
, 0, row
, area
,
21015 0, row
->used
[area
],
21016 DRAW_NORMAL_TEXT
, 0);
21019 /* Set START_X to the window-relative start position for drawing glyphs of
21020 AREA. The first glyph of the text area can be partially visible.
21021 The first glyphs of other areas cannot. */
21022 start_x
= window_box_left_offset (w
, area
);
21024 if (area
== TEXT_AREA
)
21027 /* Find the first glyph that must be redrawn. */
21029 && x
+ first
->pixel_width
< r
->x
)
21031 x
+= first
->pixel_width
;
21035 /* Find the last one. */
21039 && x
< r
->x
+ r
->width
)
21041 x
+= last
->pixel_width
;
21047 draw_glyphs (w
, first_x
- start_x
, row
, area
,
21048 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
21049 DRAW_NORMAL_TEXT
, 0);
21054 /* Redraw the parts of the glyph row ROW on window W intersecting
21055 rectangle R. R is in window-relative coordinates. Value is
21056 non-zero if mouse-face was overwritten. */
21059 expose_line (w
, row
, r
)
21061 struct glyph_row
*row
;
21064 xassert (row
->enabled_p
);
21066 if (row
->mode_line_p
|| w
->pseudo_window_p
)
21067 draw_glyphs (w
, 0, row
, TEXT_AREA
,
21068 0, row
->used
[TEXT_AREA
],
21069 DRAW_NORMAL_TEXT
, 0);
21072 if (row
->used
[LEFT_MARGIN_AREA
])
21073 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
21074 if (row
->used
[TEXT_AREA
])
21075 expose_area (w
, row
, r
, TEXT_AREA
);
21076 if (row
->used
[RIGHT_MARGIN_AREA
])
21077 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
21078 draw_row_fringe_bitmaps (w
, row
);
21081 return row
->mouse_face_p
;
21085 /* Redraw those parts of glyphs rows during expose event handling that
21086 overlap other rows. Redrawing of an exposed line writes over parts
21087 of lines overlapping that exposed line; this function fixes that.
21089 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
21090 row in W's current matrix that is exposed and overlaps other rows.
21091 LAST_OVERLAPPING_ROW is the last such row. */
21094 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
21096 struct glyph_row
*first_overlapping_row
;
21097 struct glyph_row
*last_overlapping_row
;
21099 struct glyph_row
*row
;
21101 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
21102 if (row
->overlapping_p
)
21104 xassert (row
->enabled_p
&& !row
->mode_line_p
);
21106 if (row
->used
[LEFT_MARGIN_AREA
])
21107 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
21109 if (row
->used
[TEXT_AREA
])
21110 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
21112 if (row
->used
[RIGHT_MARGIN_AREA
])
21113 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
21118 /* Return non-zero if W's cursor intersects rectangle R. */
21121 phys_cursor_in_rect_p (w
, r
)
21125 XRectangle cr
, result
;
21126 struct glyph
*cursor_glyph
;
21128 cursor_glyph
= get_phys_cursor_glyph (w
);
21131 /* r is relative to W's box, but w->phys_cursor.x is relative
21132 to left edge of W's TEXT area. Adjust it. */
21133 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
21134 cr
.y
= w
->phys_cursor
.y
;
21135 cr
.width
= cursor_glyph
->pixel_width
;
21136 cr
.height
= w
->phys_cursor_height
;
21137 /* ++KFS: W32 version used W32-specific IntersectRect here, but
21138 I assume the effect is the same -- and this is portable. */
21139 return x_intersect_rectangles (&cr
, r
, &result
);
21147 Draw a vertical window border to the right of window W if W doesn't
21148 have vertical scroll bars. */
21151 x_draw_vertical_border (w
)
21154 /* We could do better, if we knew what type of scroll-bar the adjacent
21155 windows (on either side) have... But we don't :-(
21156 However, I think this works ok. ++KFS 2003-04-25 */
21158 /* Redraw borders between horizontally adjacent windows. Don't
21159 do it for frames with vertical scroll bars because either the
21160 right scroll bar of a window, or the left scroll bar of its
21161 neighbor will suffice as a border. */
21162 if (!WINDOW_RIGHTMOST_P (w
)
21163 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
21165 int x0
, x1
, y0
, y1
;
21167 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21170 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
21172 else if (!WINDOW_LEFTMOST_P (w
)
21173 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
21175 int x0
, x1
, y0
, y1
;
21177 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21180 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
21185 /* Redraw the part of window W intersection rectangle FR. Pixel
21186 coordinates in FR are frame-relative. Call this function with
21187 input blocked. Value is non-zero if the exposure overwrites
21191 expose_window (w
, fr
)
21195 struct frame
*f
= XFRAME (w
->frame
);
21197 int mouse_face_overwritten_p
= 0;
21199 /* If window is not yet fully initialized, do nothing. This can
21200 happen when toolkit scroll bars are used and a window is split.
21201 Reconfiguring the scroll bar will generate an expose for a newly
21203 if (w
->current_matrix
== NULL
)
21206 /* When we're currently updating the window, display and current
21207 matrix usually don't agree. Arrange for a thorough display
21209 if (w
== updated_window
)
21211 SET_FRAME_GARBAGED (f
);
21215 /* Frame-relative pixel rectangle of W. */
21216 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
21217 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
21218 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
21219 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
21221 if (x_intersect_rectangles (fr
, &wr
, &r
))
21223 int yb
= window_text_bottom_y (w
);
21224 struct glyph_row
*row
;
21225 int cursor_cleared_p
;
21226 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
21228 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
21229 r
.x
, r
.y
, r
.width
, r
.height
));
21231 /* Convert to window coordinates. */
21232 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
21233 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
21235 /* Turn off the cursor. */
21236 if (!w
->pseudo_window_p
21237 && phys_cursor_in_rect_p (w
, &r
))
21239 x_clear_cursor (w
);
21240 cursor_cleared_p
= 1;
21243 cursor_cleared_p
= 0;
21245 /* Update lines intersecting rectangle R. */
21246 first_overlapping_row
= last_overlapping_row
= NULL
;
21247 for (row
= w
->current_matrix
->rows
;
21252 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
21254 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
21255 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
21256 || (r
.y
>= y0
&& r
.y
< y1
)
21257 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
21259 if (row
->overlapping_p
)
21261 if (first_overlapping_row
== NULL
)
21262 first_overlapping_row
= row
;
21263 last_overlapping_row
= row
;
21266 if (expose_line (w
, row
, &r
))
21267 mouse_face_overwritten_p
= 1;
21274 /* Display the mode line if there is one. */
21275 if (WINDOW_WANTS_MODELINE_P (w
)
21276 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
21278 && row
->y
< r
.y
+ r
.height
)
21280 if (expose_line (w
, row
, &r
))
21281 mouse_face_overwritten_p
= 1;
21284 if (!w
->pseudo_window_p
)
21286 /* Fix the display of overlapping rows. */
21287 if (first_overlapping_row
)
21288 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
21290 /* Draw border between windows. */
21291 x_draw_vertical_border (w
);
21293 /* Turn the cursor on again. */
21294 if (cursor_cleared_p
)
21295 update_window_cursor (w
, 1);
21300 /* Display scroll bar for this window. */
21301 if (!NILP (w
->vertical_scroll_bar
))
21304 If this doesn't work here (maybe some header files are missing),
21305 make a function in macterm.c and call it to do the job! */
21307 = SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (w
->vertical_scroll_bar
));
21313 return mouse_face_overwritten_p
;
21318 /* Redraw (parts) of all windows in the window tree rooted at W that
21319 intersect R. R contains frame pixel coordinates. Value is
21320 non-zero if the exposure overwrites mouse-face. */
21323 expose_window_tree (w
, r
)
21327 struct frame
*f
= XFRAME (w
->frame
);
21328 int mouse_face_overwritten_p
= 0;
21330 while (w
&& !FRAME_GARBAGED_P (f
))
21332 if (!NILP (w
->hchild
))
21333 mouse_face_overwritten_p
21334 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
21335 else if (!NILP (w
->vchild
))
21336 mouse_face_overwritten_p
21337 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
21339 mouse_face_overwritten_p
|= expose_window (w
, r
);
21341 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
21344 return mouse_face_overwritten_p
;
21349 Redisplay an exposed area of frame F. X and Y are the upper-left
21350 corner of the exposed rectangle. W and H are width and height of
21351 the exposed area. All are pixel values. W or H zero means redraw
21352 the entire frame. */
21355 expose_frame (f
, x
, y
, w
, h
)
21360 int mouse_face_overwritten_p
= 0;
21362 TRACE ((stderr
, "expose_frame "));
21364 /* No need to redraw if frame will be redrawn soon. */
21365 if (FRAME_GARBAGED_P (f
))
21367 TRACE ((stderr
, " garbaged\n"));
21372 /* MAC_TODO: this is a kludge, but if scroll bars are not activated
21373 or deactivated here, for unknown reasons, activated scroll bars
21374 are shown in deactivated frames in some instances. */
21375 if (f
== FRAME_MAC_DISPLAY_INFO (f
)->x_focus_frame
)
21376 activate_scroll_bars (f
);
21378 deactivate_scroll_bars (f
);
21381 /* If basic faces haven't been realized yet, there is no point in
21382 trying to redraw anything. This can happen when we get an expose
21383 event while Emacs is starting, e.g. by moving another window. */
21384 if (FRAME_FACE_CACHE (f
) == NULL
21385 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
21387 TRACE ((stderr
, " no faces\n"));
21391 if (w
== 0 || h
== 0)
21394 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
21395 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
21405 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
21406 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
21408 if (WINDOWP (f
->tool_bar_window
))
21409 mouse_face_overwritten_p
21410 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
21412 #ifdef HAVE_X_WINDOWS
21414 #ifndef USE_X_TOOLKIT
21415 if (WINDOWP (f
->menu_bar_window
))
21416 mouse_face_overwritten_p
21417 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
21418 #endif /* not USE_X_TOOLKIT */
21422 /* Some window managers support a focus-follows-mouse style with
21423 delayed raising of frames. Imagine a partially obscured frame,
21424 and moving the mouse into partially obscured mouse-face on that
21425 frame. The visible part of the mouse-face will be highlighted,
21426 then the WM raises the obscured frame. With at least one WM, KDE
21427 2.1, Emacs is not getting any event for the raising of the frame
21428 (even tried with SubstructureRedirectMask), only Expose events.
21429 These expose events will draw text normally, i.e. not
21430 highlighted. Which means we must redo the highlight here.
21431 Subsume it under ``we love X''. --gerd 2001-08-15 */
21432 /* Included in Windows version because Windows most likely does not
21433 do the right thing if any third party tool offers
21434 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
21435 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
21437 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21438 if (f
== dpyinfo
->mouse_face_mouse_frame
)
21440 int x
= dpyinfo
->mouse_face_mouse_x
;
21441 int y
= dpyinfo
->mouse_face_mouse_y
;
21442 clear_mouse_face (dpyinfo
);
21443 note_mouse_highlight (f
, x
, y
);
21450 Determine the intersection of two rectangles R1 and R2. Return
21451 the intersection in *RESULT. Value is non-zero if RESULT is not
21455 x_intersect_rectangles (r1
, r2
, result
)
21456 XRectangle
*r1
, *r2
, *result
;
21458 XRectangle
*left
, *right
;
21459 XRectangle
*upper
, *lower
;
21460 int intersection_p
= 0;
21462 /* Rearrange so that R1 is the left-most rectangle. */
21464 left
= r1
, right
= r2
;
21466 left
= r2
, right
= r1
;
21468 /* X0 of the intersection is right.x0, if this is inside R1,
21469 otherwise there is no intersection. */
21470 if (right
->x
<= left
->x
+ left
->width
)
21472 result
->x
= right
->x
;
21474 /* The right end of the intersection is the minimum of the
21475 the right ends of left and right. */
21476 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
21479 /* Same game for Y. */
21481 upper
= r1
, lower
= r2
;
21483 upper
= r2
, lower
= r1
;
21485 /* The upper end of the intersection is lower.y0, if this is inside
21486 of upper. Otherwise, there is no intersection. */
21487 if (lower
->y
<= upper
->y
+ upper
->height
)
21489 result
->y
= lower
->y
;
21491 /* The lower end of the intersection is the minimum of the lower
21492 ends of upper and lower. */
21493 result
->height
= (min (lower
->y
+ lower
->height
,
21494 upper
->y
+ upper
->height
)
21496 intersection_p
= 1;
21500 return intersection_p
;
21503 #endif /* HAVE_WINDOW_SYSTEM */
21506 /***********************************************************************
21508 ***********************************************************************/
21513 Vwith_echo_area_save_vector
= Qnil
;
21514 staticpro (&Vwith_echo_area_save_vector
);
21516 Vmessage_stack
= Qnil
;
21517 staticpro (&Vmessage_stack
);
21519 Qinhibit_redisplay
= intern ("inhibit-redisplay");
21520 staticpro (&Qinhibit_redisplay
);
21522 message_dolog_marker1
= Fmake_marker ();
21523 staticpro (&message_dolog_marker1
);
21524 message_dolog_marker2
= Fmake_marker ();
21525 staticpro (&message_dolog_marker2
);
21526 message_dolog_marker3
= Fmake_marker ();
21527 staticpro (&message_dolog_marker3
);
21530 defsubr (&Sdump_frame_glyph_matrix
);
21531 defsubr (&Sdump_glyph_matrix
);
21532 defsubr (&Sdump_glyph_row
);
21533 defsubr (&Sdump_tool_bar_row
);
21534 defsubr (&Strace_redisplay
);
21535 defsubr (&Strace_to_stderr
);
21537 #ifdef HAVE_WINDOW_SYSTEM
21538 defsubr (&Stool_bar_lines_needed
);
21539 defsubr (&Slookup_image_map
);
21541 defsubr (&Sformat_mode_line
);
21543 staticpro (&Qmenu_bar_update_hook
);
21544 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
21546 staticpro (&Qoverriding_terminal_local_map
);
21547 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
21549 staticpro (&Qoverriding_local_map
);
21550 Qoverriding_local_map
= intern ("overriding-local-map");
21552 staticpro (&Qwindow_scroll_functions
);
21553 Qwindow_scroll_functions
= intern ("window-scroll-functions");
21555 staticpro (&Qredisplay_end_trigger_functions
);
21556 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
21558 staticpro (&Qinhibit_point_motion_hooks
);
21559 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
21561 QCdata
= intern (":data");
21562 staticpro (&QCdata
);
21563 Qdisplay
= intern ("display");
21564 staticpro (&Qdisplay
);
21565 Qspace_width
= intern ("space-width");
21566 staticpro (&Qspace_width
);
21567 Qraise
= intern ("raise");
21568 staticpro (&Qraise
);
21569 Qspace
= intern ("space");
21570 staticpro (&Qspace
);
21571 Qmargin
= intern ("margin");
21572 staticpro (&Qmargin
);
21573 Qpointer
= intern ("pointer");
21574 staticpro (&Qpointer
);
21575 Qleft_margin
= intern ("left-margin");
21576 staticpro (&Qleft_margin
);
21577 Qright_margin
= intern ("right-margin");
21578 staticpro (&Qright_margin
);
21579 Qcenter
= intern ("center");
21580 staticpro (&Qcenter
);
21581 QCalign_to
= intern (":align-to");
21582 staticpro (&QCalign_to
);
21583 QCrelative_width
= intern (":relative-width");
21584 staticpro (&QCrelative_width
);
21585 QCrelative_height
= intern (":relative-height");
21586 staticpro (&QCrelative_height
);
21587 QCeval
= intern (":eval");
21588 staticpro (&QCeval
);
21589 QCpropertize
= intern (":propertize");
21590 staticpro (&QCpropertize
);
21591 QCfile
= intern (":file");
21592 staticpro (&QCfile
);
21593 Qfontified
= intern ("fontified");
21594 staticpro (&Qfontified
);
21595 Qfontification_functions
= intern ("fontification-functions");
21596 staticpro (&Qfontification_functions
);
21597 Qtrailing_whitespace
= intern ("trailing-whitespace");
21598 staticpro (&Qtrailing_whitespace
);
21599 Qimage
= intern ("image");
21600 staticpro (&Qimage
);
21601 QCmap
= intern (":map");
21602 staticpro (&QCmap
);
21603 QCpointer
= intern (":pointer");
21604 staticpro (&QCpointer
);
21605 Qrect
= intern ("rect");
21606 staticpro (&Qrect
);
21607 Qcircle
= intern ("circle");
21608 staticpro (&Qcircle
);
21609 Qpoly
= intern ("poly");
21610 staticpro (&Qpoly
);
21611 Qmessage_truncate_lines
= intern ("message-truncate-lines");
21612 staticpro (&Qmessage_truncate_lines
);
21613 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
21614 staticpro (&Qcursor_in_non_selected_windows
);
21615 Qgrow_only
= intern ("grow-only");
21616 staticpro (&Qgrow_only
);
21617 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
21618 staticpro (&Qinhibit_menubar_update
);
21619 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
21620 staticpro (&Qinhibit_eval_during_redisplay
);
21621 Qposition
= intern ("position");
21622 staticpro (&Qposition
);
21623 Qbuffer_position
= intern ("buffer-position");
21624 staticpro (&Qbuffer_position
);
21625 Qobject
= intern ("object");
21626 staticpro (&Qobject
);
21627 Qbar
= intern ("bar");
21629 Qhbar
= intern ("hbar");
21630 staticpro (&Qhbar
);
21631 Qbox
= intern ("box");
21633 Qhollow
= intern ("hollow");
21634 staticpro (&Qhollow
);
21635 Qhand
= intern ("hand");
21636 staticpro (&Qhand
);
21637 Qarrow
= intern ("arrow");
21638 staticpro (&Qarrow
);
21639 Qtext
= intern ("text");
21640 staticpro (&Qtext
);
21641 Qrisky_local_variable
= intern ("risky-local-variable");
21642 staticpro (&Qrisky_local_variable
);
21643 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
21644 staticpro (&Qinhibit_free_realized_faces
);
21646 list_of_error
= Fcons (Fcons (intern ("error"),
21647 Fcons (intern ("void-variable"), Qnil
)),
21649 staticpro (&list_of_error
);
21651 Qlast_arrow_position
= intern ("last-arrow-position");
21652 staticpro (&Qlast_arrow_position
);
21653 Qlast_arrow_string
= intern ("last-arrow-string");
21654 staticpro (&Qlast_arrow_string
);
21656 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
21657 staticpro (&Qoverlay_arrow_string
);
21658 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
21659 staticpro (&Qoverlay_arrow_bitmap
);
21661 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
21662 staticpro (&echo_buffer
[0]);
21663 staticpro (&echo_buffer
[1]);
21665 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
21666 staticpro (&echo_area_buffer
[0]);
21667 staticpro (&echo_area_buffer
[1]);
21669 Vmessages_buffer_name
= build_string ("*Messages*");
21670 staticpro (&Vmessages_buffer_name
);
21672 mode_line_proptrans_alist
= Qnil
;
21673 staticpro (&mode_line_proptrans_alist
);
21675 mode_line_string_list
= Qnil
;
21676 staticpro (&mode_line_string_list
);
21678 help_echo_string
= Qnil
;
21679 staticpro (&help_echo_string
);
21680 help_echo_object
= Qnil
;
21681 staticpro (&help_echo_object
);
21682 help_echo_window
= Qnil
;
21683 staticpro (&help_echo_window
);
21684 previous_help_echo_string
= Qnil
;
21685 staticpro (&previous_help_echo_string
);
21686 help_echo_pos
= -1;
21688 #ifdef HAVE_WINDOW_SYSTEM
21689 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
21690 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
21691 For example, if a block cursor is over a tab, it will be drawn as
21692 wide as that tab on the display. */);
21693 x_stretch_cursor_p
= 0;
21696 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
21697 doc
: /* *Non-nil means highlight trailing whitespace.
21698 The face used for trailing whitespace is `trailing-whitespace'. */);
21699 Vshow_trailing_whitespace
= Qnil
;
21701 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
21702 doc
: /* *The pointer shape to show in void text areas.
21703 Nil means to show the text pointer. Other options are `arrow', `text',
21704 `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
21705 Vvoid_text_area_pointer
= Qarrow
;
21707 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
21708 doc
: /* Non-nil means don't actually do any redisplay.
21709 This is used for internal purposes. */);
21710 Vinhibit_redisplay
= Qnil
;
21712 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
21713 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
21714 Vglobal_mode_string
= Qnil
;
21716 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
21717 doc
: /* Marker for where to display an arrow on top of the buffer text.
21718 This must be the beginning of a line in order to work.
21719 See also `overlay-arrow-string'. */);
21720 Voverlay_arrow_position
= Qnil
;
21722 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
21723 doc
: /* String to display as an arrow in non-window frames.
21724 See also `overlay-arrow-position'. */);
21725 Voverlay_arrow_string
= Qnil
;
21727 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
21728 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
21729 The symbols on this list are examined during redisplay to determine
21730 where to display overlay arrows. */);
21731 Voverlay_arrow_variable_list
21732 = Fcons (intern ("overlay-arrow-position"), Qnil
);
21734 DEFVAR_INT ("scroll-step", &scroll_step
,
21735 doc
: /* *The number of lines to try scrolling a window by when point moves out.
21736 If that fails to bring point back on frame, point is centered instead.
21737 If this is zero, point is always centered after it moves off frame.
21738 If you want scrolling to always be a line at a time, you should set
21739 `scroll-conservatively' to a large value rather than set this to 1. */);
21741 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
21742 doc
: /* *Scroll up to this many lines, to bring point back on screen.
21743 A value of zero means to scroll the text to center point vertically
21744 in the window. */);
21745 scroll_conservatively
= 0;
21747 DEFVAR_INT ("scroll-margin", &scroll_margin
,
21748 doc
: /* *Number of lines of margin at the top and bottom of a window.
21749 Recenter the window whenever point gets within this many lines
21750 of the top or bottom of the window. */);
21753 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
21754 doc
: /* Pixels per inch on current display.
21755 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
21756 Vdisplay_pixels_per_inch
= make_float (72.0);
21759 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
21762 DEFVAR_BOOL ("truncate-partial-width-windows",
21763 &truncate_partial_width_windows
,
21764 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
21765 truncate_partial_width_windows
= 1;
21767 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
21768 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
21769 Any other value means to use the appropriate face, `mode-line',
21770 `header-line', or `menu' respectively. */);
21771 mode_line_inverse_video
= 1;
21773 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
21774 doc
: /* *Maximum buffer size for which line number should be displayed.
21775 If the buffer is bigger than this, the line number does not appear
21776 in the mode line. A value of nil means no limit. */);
21777 Vline_number_display_limit
= Qnil
;
21779 DEFVAR_INT ("line-number-display-limit-width",
21780 &line_number_display_limit_width
,
21781 doc
: /* *Maximum line width (in characters) for line number display.
21782 If the average length of the lines near point is bigger than this, then the
21783 line number may be omitted from the mode line. */);
21784 line_number_display_limit_width
= 200;
21786 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
21787 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
21788 highlight_nonselected_windows
= 0;
21790 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
21791 doc
: /* Non-nil if more than one frame is visible on this display.
21792 Minibuffer-only frames don't count, but iconified frames do.
21793 This variable is not guaranteed to be accurate except while processing
21794 `frame-title-format' and `icon-title-format'. */);
21796 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
21797 doc
: /* Template for displaying the title bar of visible frames.
21798 \(Assuming the window manager supports this feature.)
21799 This variable has the same structure as `mode-line-format' (which see),
21800 and is used only on frames for which no explicit name has been set
21801 \(see `modify-frame-parameters'). */);
21803 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
21804 doc
: /* Template for displaying the title bar of an iconified frame.
21805 \(Assuming the window manager supports this feature.)
21806 This variable has the same structure as `mode-line-format' (which see),
21807 and is used only on frames for which no explicit name has been set
21808 \(see `modify-frame-parameters'). */);
21810 = Vframe_title_format
21811 = Fcons (intern ("multiple-frames"),
21812 Fcons (build_string ("%b"),
21813 Fcons (Fcons (empty_string
,
21814 Fcons (intern ("invocation-name"),
21815 Fcons (build_string ("@"),
21816 Fcons (intern ("system-name"),
21820 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
21821 doc
: /* Maximum number of lines to keep in the message log buffer.
21822 If nil, disable message logging. If t, log messages but don't truncate
21823 the buffer when it becomes large. */);
21824 Vmessage_log_max
= make_number (50);
21826 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
21827 doc
: /* Functions called before redisplay, if window sizes have changed.
21828 The value should be a list of functions that take one argument.
21829 Just before redisplay, for each frame, if any of its windows have changed
21830 size since the last redisplay, or have been split or deleted,
21831 all the functions in the list are called, with the frame as argument. */);
21832 Vwindow_size_change_functions
= Qnil
;
21834 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
21835 doc
: /* List of Functions to call before redisplaying a window with scrolling.
21836 Each function is called with two arguments, the window
21837 and its new display-start position. Note that the value of `window-end'
21838 is not valid when these functions are called. */);
21839 Vwindow_scroll_functions
= Qnil
;
21841 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
21842 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
21843 mouse_autoselect_window
= 0;
21845 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
21846 doc
: /* *Non-nil means automatically resize tool-bars.
21847 This increases a tool-bar's height if not all tool-bar items are visible.
21848 It decreases a tool-bar's height when it would display blank lines
21850 auto_resize_tool_bars_p
= 1;
21852 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
21853 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
21854 auto_raise_tool_bar_buttons_p
= 1;
21856 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
21857 doc
: /* *Margin around tool-bar buttons in pixels.
21858 If an integer, use that for both horizontal and vertical margins.
21859 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
21860 HORZ specifying the horizontal margin, and VERT specifying the
21861 vertical margin. */);
21862 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
21864 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
21865 doc
: /* *Relief thickness of tool-bar buttons. */);
21866 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
21868 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
21869 doc
: /* List of functions to call to fontify regions of text.
21870 Each function is called with one argument POS. Functions must
21871 fontify a region starting at POS in the current buffer, and give
21872 fontified regions the property `fontified'. */);
21873 Vfontification_functions
= Qnil
;
21874 Fmake_variable_buffer_local (Qfontification_functions
);
21876 DEFVAR_BOOL ("unibyte-display-via-language-environment",
21877 &unibyte_display_via_language_environment
,
21878 doc
: /* *Non-nil means display unibyte text according to language environment.
21879 Specifically this means that unibyte non-ASCII characters
21880 are displayed by converting them to the equivalent multibyte characters
21881 according to the current language environment. As a result, they are
21882 displayed according to the current fontset. */);
21883 unibyte_display_via_language_environment
= 0;
21885 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
21886 doc
: /* *Maximum height for resizing mini-windows.
21887 If a float, it specifies a fraction of the mini-window frame's height.
21888 If an integer, it specifies a number of lines. */);
21889 Vmax_mini_window_height
= make_float (0.25);
21891 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
21892 doc
: /* *How to resize mini-windows.
21893 A value of nil means don't automatically resize mini-windows.
21894 A value of t means resize them to fit the text displayed in them.
21895 A value of `grow-only', the default, means let mini-windows grow
21896 only, until their display becomes empty, at which point the windows
21897 go back to their normal size. */);
21898 Vresize_mini_windows
= Qgrow_only
;
21900 DEFVAR_LISP ("cursor-in-non-selected-windows",
21901 &Vcursor_in_non_selected_windows
,
21902 doc
: /* *Cursor type to display in non-selected windows.
21903 t means to use hollow box cursor. See `cursor-type' for other values. */);
21904 Vcursor_in_non_selected_windows
= Qt
;
21906 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
21907 doc
: /* Alist specifying how to blink the cursor off.
21908 Each element has the form (ON-STATE . OFF-STATE). Whenever the
21909 `cursor-type' frame-parameter or variable equals ON-STATE,
21910 comparing using `equal', Emacs uses OFF-STATE to specify
21911 how to blink it off. */);
21912 Vblink_cursor_alist
= Qnil
;
21914 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
21915 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
21916 automatic_hscrolling_p
= 1;
21918 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
21919 doc
: /* *How many columns away from the window edge point is allowed to get
21920 before automatic hscrolling will horizontally scroll the window. */);
21921 hscroll_margin
= 5;
21923 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
21924 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
21925 When point is less than `automatic-hscroll-margin' columns from the window
21926 edge, automatic hscrolling will scroll the window by the amount of columns
21927 determined by this variable. If its value is a positive integer, scroll that
21928 many columns. If it's a positive floating-point number, it specifies the
21929 fraction of the window's width to scroll. If it's nil or zero, point will be
21930 centered horizontally after the scroll. Any other value, including negative
21931 numbers, are treated as if the value were zero.
21933 Automatic hscrolling always moves point outside the scroll margin, so if
21934 point was more than scroll step columns inside the margin, the window will
21935 scroll more than the value given by the scroll step.
21937 Note that the lower bound for automatic hscrolling specified by `scroll-left'
21938 and `scroll-right' overrides this variable's effect. */);
21939 Vhscroll_step
= make_number (0);
21941 DEFVAR_LISP ("image-types", &Vimage_types
,
21942 doc
: /* List of supported image types.
21943 Each element of the list is a symbol for a supported image type. */);
21944 Vimage_types
= Qnil
;
21946 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
21947 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
21948 Bind this around calls to `message' to let it take effect. */);
21949 message_truncate_lines
= 0;
21951 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
21952 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
21953 Can be used to update submenus whose contents should vary. */);
21954 Vmenu_bar_update_hook
= Qnil
;
21956 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
21957 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
21958 inhibit_menubar_update
= 0;
21960 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
21961 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
21962 inhibit_eval_during_redisplay
= 0;
21964 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
21965 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
21966 inhibit_free_realized_faces
= 0;
21969 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
21970 doc
: /* Inhibit try_window_id display optimization. */);
21971 inhibit_try_window_id
= 0;
21973 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
21974 doc
: /* Inhibit try_window_reusing display optimization. */);
21975 inhibit_try_window_reusing
= 0;
21977 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
21978 doc
: /* Inhibit try_cursor_movement display optimization. */);
21979 inhibit_try_cursor_movement
= 0;
21980 #endif /* GLYPH_DEBUG */
21984 /* Initialize this module when Emacs starts. */
21989 Lisp_Object root_window
;
21990 struct window
*mini_w
;
21992 current_header_line_height
= current_mode_line_height
= -1;
21994 CHARPOS (this_line_start_pos
) = 0;
21996 mini_w
= XWINDOW (minibuf_window
);
21997 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
21999 if (!noninteractive
)
22001 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
22004 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
22005 set_window_height (root_window
,
22006 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
22008 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
22009 set_window_height (minibuf_window
, 1, 0);
22011 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
22012 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
22014 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
22015 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
22016 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
22018 /* The default ellipsis glyphs `...'. */
22019 for (i
= 0; i
< 3; ++i
)
22020 default_invis_vector
[i
] = make_number ('.');
22024 /* Allocate the buffer for frame titles.
22025 Also used for `format-mode-line'. */
22027 frame_title_buf
= (char *) xmalloc (size
);
22028 frame_title_buf_end
= frame_title_buf
+ size
;
22029 frame_title_ptr
= NULL
;
22032 help_echo_showing_p
= 0;
22036 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
22037 (do not change this comment) */